Skip to content

Instantly share code, notes, and snippets.

@alexytiger
Created September 29, 2019 01:51
Show Gist options
  • Save alexytiger/9e6541df21f284fd1f1321aefa8f55fa to your computer and use it in GitHub Desktop.
Save alexytiger/9e6541df21f284fd1f1321aefa8f55fa to your computer and use it in GitHub Desktop.
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);
return dialogRef.afterClosed();
}),
exhaustMap(result => {
if (result === undefined) {
return of(SpinnerActions.hide());
}
return this.purchaseSrv.confirmPurchase(result.address, result.eth).pipe(
tap(address => console.log(`Purchase confirmed successfully for the contract: ${address} `)),
concatMapTo(
[PurchaseContractActions.confirmBuySuccess(),
// update ballance
Web3ProviderActions.getBalance()]
),
catchError((err: Error) =>
of(ErrorActions.errorMessage({ errorMsg: err.message }), SpinnerActions.hide(),
// update ballance
Web3ProviderActions.getBalance())
)
)
})
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment