Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: transfer error notification #1460

Merged
merged 3 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 64 additions & 36 deletions apps/namadillo/src/hooks/useTransactionNotifications.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ import {
import { searchAllStoredTxByHash } from "atoms/transactions";
import BigNumber from "bignumber.js";
import { useSetAtom } from "jotai";
import { useTransactionEventListener } from "utils";
import {
useTransactionEventListener,
useTransactionEventListListener,
} from "utils";

type TxWithAmount = { amount: BigNumber };

Expand Down Expand Up @@ -344,45 +347,70 @@ export const useTransactionNotifications = (): void => {
});
});

const handleTransferNotification = (
tx: TxProps,
data: TxWithAmount[]
): void => {
const { id } = parseTxsData(tx, data);
clearPendingNotifications(id);
const storedTx = searchAllStoredTxByHash(tx.hash);
if (storedTx) {
useTransactionEventListListener(
[
"TransparentTransfer.Error",
"ShieldedTransfer.Error",
"ShieldingTransfer.Error",
"UnshieldingTransfer.Error",
],
(e) => {
const tx = e.detail.tx;
const data: TxWithAmount[] = e.detail.data[0].data;
const { id } = parseTxsData(tx, data);
clearPendingNotifications(id);
const storedTx = searchAllStoredTxByHash(tx.hash);
dispatchNotification({
id,
type: "error",
title: "Transfer transaction failed",
description:
storedTx ?
<>
Your transfer transaction of{" "}
<TokenCurrency
symbol={storedTx.asset.symbol}
amount={storedTx.displayAmount}
/>{" "}
to {shortenAddress(storedTx.destinationAddress, 8, 8)} has failed
</>
: "Your transfer transaction has failed",
details:
e.detail.error?.message && failureDetails(e.detail.error.message),
});
}
);

useTransactionEventListListener(
[
"TransparentTransfer.Success",
"ShieldedTransfer.Success",
"ShieldingTransfer.Success",
"UnshieldingTransfer.Success",
],
(e) => {
const tx = e.detail.tx;
const data: TxWithAmount[] = e.detail.data[0].data;
const { id } = parseTxsData(tx, data);
clearPendingNotifications(id);
const storedTx = searchAllStoredTxByHash(tx.hash);
dispatchNotification({
id,
title: "Transfer transaction succeeded",
description: (
<>
Your transfer transaction of{" "}
<TokenCurrency
symbol={storedTx.asset.symbol}
amount={storedTx.displayAmount}
/>{" "}
to {shortenAddress(storedTx.destinationAddress, 8, 8)} has succeeded
</>
),
description:
storedTx ?
<>
Your transfer transaction of{" "}
<TokenCurrency
symbol={storedTx.asset.symbol}
amount={storedTx.displayAmount}
/>{" "}
to {shortenAddress(storedTx.destinationAddress, 8, 8)} has
succeeded
</>
: "Your transfer transaction has succeeded",
type: "success",
});
}
};

useTransactionEventListener("TransparentTransfer.Success", (e) => {
handleTransferNotification(e.detail.tx, e.detail.data[0].data);
});

useTransactionEventListener("ShieldedTransfer.Success", (e) => {
handleTransferNotification(e.detail.tx, e.detail.data[0].data);
});

useTransactionEventListener("ShieldingTransfer.Success", (e) => {
handleTransferNotification(e.detail.tx, e.detail.data[0].data);
});

useTransactionEventListener("UnshieldingTransfer.Success", (e) => {
handleTransferNotification(e.detail.tx, e.detail.data[0].data);
});
);
};
4 changes: 4 additions & 0 deletions apps/namadillo/src/types/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,13 @@ declare global {
"VoteProposal.Success": EventData<VoteProposalProps>;
"VoteProposal.Error": EventData<VoteProposalProps>;
"TransparentTransfer.Success": EventData<TransparentTransferProps>;
"TransparentTransfer.Error": EventData<TransparentTransferProps>;
"ShieldedTransfer.Success": EventData<ShieldedTransferProps>;
"ShieldedTransfer.Error": EventData<ShieldedTransferProps>;
"ShieldingTransfer.Success": EventData<ShieldingTransferProps>;
"ShieldingTransfer.Error": EventData<ShieldingTransferProps>;
"UnshieldingTransfer.Success": EventData<UnshieldingTransferProps>;
"UnshieldingTransfer.Error": EventData<UnshieldingTransferProps>;
"IbcTransfer.Success": EventData<IbcTransferProps>;
"IbcTransfer.Error": EventData<IbcTransferProps>;
}
Expand Down
Loading