Skip to content

Instantly share code, notes, and snippets.

@alexytiger
Created September 28, 2019 12:56
Show Gist options
  • Save alexytiger/74467b5c36d585e79901cedb1a3d32d5 to your computer and use it in GitHub Desktop.
Save alexytiger/74467b5c36d585e79901cedb1a3d32d5 to your computer and use it in GitHub Desktop.
removeProduct$ = createEffect(
() =>
this.actions$.pipe(
ofType(PurchaseContractActions.removePurchaseContract),
map(payload => payload.key),
switchMap(key => {
const dialogConfig = new MatDialogConfig();
dialogConfig.width = '420px';
dialogConfig.disableClose = true;
dialogConfig.autoFocus = true;
dialogConfig.data = {
title: 'Confirm Remove',
content: `Are you sure to remove contract ${key} from market?`,
output: key
};
const dialogRef = this.dialog.open(ConfirmDialogComponent, dialogConfig);
return dialogRef.afterClosed();
}),
exhaustMap(result => {
if (result === undefined) {
return of(SpinnerActions.hide());
}
return this.fleaSrv.removePurchaseContract(result).pipe(
tap(productKey => console.log(`Contract has been removed: ${productKey}`)),
concatMap(productKey =>
[PurchaseContractActions.removePurchaseContractSuccess({ key: productKey }),
// 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