Skip to content

Instantly share code, notes, and snippets.

@alexytiger
Created September 22, 2019 18:12
Show Gist options
  • Save alexytiger/566f5bfb2e35be8121afdca8a24d8489 to your computer and use it in GitHub Desktop.
Save alexytiger/566f5bfb2e35be8121afdca8a24d8489 to your computer and use it in GitHub Desktop.
abortContract$ = createEffect(
() =>
this.actions$.pipe(
ofType(PurchaseContractActions.abortSelectedPurchaseContract),
withLatestFrom(this.store$.pipe(select(fromStore.getSelectedPurchaseContract))),
switchMap(([action, contract]) => {
const dialogConfig = new MatDialogConfig();
dialogConfig.width = '420px';
dialogConfig.disableClose = true;
dialogConfig.autoFocus = true;
dialogConfig.data = {
title: 'Confirm Abort',
content: `Are you sure to deactivate contract: ${contract.productKey}?`,
output: contract.contractAddress
};
const dialogRef = this.dialog.open(ConfirmDialogComponent, dialogConfig);
return dialogRef.afterClosed();
}),
exhaustMap(result => {
if (result === undefined) {
return of(SpinnerActions.hide());
}
return this.purchaseSrv.abortPurchaseContract(result).pipe(
tap(address => console.log(`Successfully canceled contract: ${address} `)),
concatMapTo(
[PurchaseContractActions.abortSelectedPurchaseContractSuccess(),
// 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