Skip to content

Commit

Permalink
fix: CompleteTransferToL1 toast remains on display after tx is done (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
dan-ziv authored May 8, 2022
1 parent f81d11e commit 219b860
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/components/Features/ToastProvider/ToastProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,27 +40,36 @@ export const ToastProvider = () => {
}, [breakpoint]);

useDeepCompareEffect(() => {
transfers.forEach(transfer => {
const prevTransfer = prevTransfers?.find(prevTransfer => prevTransfer.id === transfer.id);
handleToast(transfer, prevTransfer);
});
renderToasts();
}, [transfers]);

useEffect(() => {
return () => clearToasts();
}, []);

const renderToasts = () => {
transfers.forEach(transfer => {
const prevTransfer = prevTransfers?.find(prevTransfer => prevTransfer.id === transfer.id);
handleToast(transfer, prevTransfer);
});
};

const handleToast = (transfer, prevTransfer) => {
const {status, type} = transfer;
const {status, type, l1hash} = transfer;
const isChanged = prevTransfer && status !== prevTransfer.status;
if (isChanged && isConsumed(status)) {
return showConsumedTransferToast(transfer);
}
if (isChanged && isRejected(status)) {
return showRejectedTransferToast(transfer);
}
if (!transfer.l1hash && type === ActionType.TRANSFER_TO_L1 && isOnChain(status)) {
return showCompleteTransferToL1Toast(transfer);
if (type === ActionType.TRANSFER_TO_L1) {
if (!l1hash && isOnChain(status)) {
return showCompleteTransferToL1Toast(transfer);
}
if (l1hash && isToastRendered(transfer.id, ToastType.COMPLETE_TRANSFER_TO_L1)) {
return dismissToast(transfer.id, ToastType.COMPLETE_TRANSFER_TO_L1);
}
}
};

Expand Down

0 comments on commit 219b860

Please sign in to comment.