Skip to content

Instantly share code, notes, and snippets.

@alexytiger
Created September 29, 2019 20:21
Show Gist options
  • Save alexytiger/56fa78ec80e54bc10ee4bee6c727dc4d to your computer and use it in GitHub Desktop.
Save alexytiger/56fa78ec80e54bc10ee4bee6c727dc4d to your computer and use it in GitHub Desktop.
confirmDelivery$ = createEffect(
() =>
this.actions$.pipe(
ofType(PurchaseContractActions.confirmDelivery),
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 Delivery',
content: `Are you sure you want to confirm that you received the purchase item ${contract.title}`,
output: contract.contractAddress
};
const dialogRef = this.dialog.open(ConfirmDialogComponent, dialogConfig);
// * Gets an observable that is notified when the dialog is finished closing.
return dialogRef.afterClosed();
}),
exhaustMap(result => {
if (result === undefined) {
return of(SpinnerActions.hide());
}
return this.purchaseSrv.confirmDelivery(result).pipe(
tap(address => console.log(`Delivery confirmed successfully for the contract: ${address} `)),
concatMapTo(
[PurchaseContractActions.confirmDeliverySuccess(),
// 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