Skip to content

Instantly share code, notes, and snippets.

@alexytiger
Last active January 28, 2020 03:54
Show Gist options
  • Save alexytiger/7faae76369e214a70926c81722b75a8c to your computer and use it in GitHub Desktop.
Save alexytiger/7faae76369e214a70926c81722b75a8c to your computer and use it in GitHub Desktop.
e-book
getAccountInfo$ = createEffect(() =>
this.actions$.pipe(
ofType(Web3ProviderActions.metamaskConnectSuccess),
switchMap(() => {
return [Web3ProviderActions.getNetwork(), Web3ProviderActions.getAddress(), Web3ProviderActions.getBalance()];
})
)
);
getAddress$ = createEffect(() =>
this.actions$.pipe(
ofType(Web3ProviderActions.getAddress),
switchMap(() =>
this.providerSrv.getSelectedAddress().pipe(
map((address: string) => Web3ProviderActions.addressSuccess({ address })),
catchError((err: Error) => of(this.handleError(err)))
)
)
)
);
getBalance$ = createEffect(() =>
this.actions$.pipe(
ofType(Web3ProviderActions.getBalance),
switchMap(() =>
this.providerSrv.getBalance().pipe(
map((balance: string) =>
Web3ProviderActions.balanceSuccess({ balance })
),
catchError((err: Error) => of(this.handleError(err)))
)
)
)
);
getNetwork$ = createEffect(() =>
this.actions$.pipe(
ofType(Web3ProviderActions.getNetwork),
switchMap(() =>
this.providerSrv.getNetwork().pipe(
map((network: string) =>
Web3ProviderActions.networkSuccess({ network })
),
catchError((err: Error) => of(this.handleError(err)))
)
)
)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment