Skip to content

Commit

Permalink
feat: transfer error notification (#1460)
Browse files Browse the repository at this point in the history
  • Loading branch information
euharrison authored Jan 3, 2025
1 parent cb742eb commit 1945c61
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 37 deletions.
2 changes: 1 addition & 1 deletion apps/namadillo/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@namada/namadillo",
"version": "1.1.7",
"version": "1.1.8",
"description": "Namadillo",
"repository": "https://github.com/anoma/namada-interface/",
"author": "Heliax Dev <[email protected]>",
Expand Down
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

1 comment on commit 1945c61

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.