Created
September 29, 2019 01:51
-
-
Save alexytiger/9e6541df21f284fd1f1321aefa8f55fa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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