Skip to content

Instantly share code, notes, and snippets.

@alexytiger
Last active February 19, 2020 01:15
Show Gist options
  • Save alexytiger/1e95dc91d0b7c2e81c768f6d07d2bcd8 to your computer and use it in GitHub Desktop.
Save alexytiger/1e95dc91d0b7c2e81c768f6d07d2bcd8 to your computer and use it in GitHub Desktop.
e-book
confirmBuy$ = createEffect(
() =>
this.actions$.pipe(
ofType(PurchaseContractActions.confirmBuy),
withLatestFrom(
this.store$.pipe(select(fromStore.getSelectedPurchaseContract))),
switchMap(([payload, contract]) => {
const dialogConfig = new MatDialogConfig();
dialogConfig.width = '420px';
dialogConfig.disableClose = true;
dialogConfig.autoFocus = true;
dialogConfig.data = {
title: 'Confirm Purchase',
content: `Please confirm to deposit ${payload.eth} ETH into
the contract: ${contract.productKey}`,
output: {
address: contract.contractAddress,
eth: payload.eth
}
};
const dialogRef =
this.dialog.open(ConfirmDialogComponent, dialogConfig);
// Gets an observable that is notified
// when the dialog is finished closing.
return dialogRef.afterClosed();
}),
filter(result => !!result),
exhaustMap(result => concat(
of(SpinnerActions.show()),
this.purchaseSrv.confirmPurchase(result.address, result.eth).pipe(
tap(address =>
console.log(`Purchase confirmed successfully for
the contract: ${address} `)),
concatMapTo(
[PurchaseContractActions.confirmBuySuccess(),
Web3ProviderActions.getBalance()]
),
catchError((err: Error) =>
of(this.handleError(err), Web3ProviderActions.getBalance()))
),
of(SpinnerActions.hide())
))
));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment