Skip to content

Commit 7b78563

Browse files
fix: do not display refund target error for transparent ibc withdrawals (#2220)
1 parent 4965bfc commit 7b78563

File tree

5 files changed

+76
-54
lines changed

5 files changed

+76
-54
lines changed

apps/namadillo/src/App/Ibc/IbcWithdraw.tsx

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -121,20 +121,26 @@ export const IbcWithdraw = (): JSX.Element => {
121121
connectToChainId(defaultChainId);
122122
};
123123

124-
useTransactionEventListener("IbcWithdraw.Success", async (e) => {
125-
if (txHash && e.detail.hash === txHash) {
126-
setCompletedAt(new Date());
127-
// We are clearing the disposable signer only if the transaction was successful on the target chain
128-
if (shielded && refundTarget) {
129-
await clearDisposableSigner(refundTarget);
124+
useTransactionEventListener(
125+
["IbcWithdraw.Success", "ShieldedIbcWithdraw.Success"],
126+
async (e) => {
127+
if (txHash && e.detail.hash === txHash) {
128+
setCompletedAt(new Date());
129+
// We are clearing the disposable signer only if the transaction was successful on the target chain
130+
if (shielded && refundTarget) {
131+
await clearDisposableSigner(refundTarget);
132+
}
133+
trackEvent(`${shielded ? "Shielded " : ""}IbcWithdraw: tx complete`);
130134
}
131-
trackEvent(`${shielded ? "Shielded " : ""}IbcWithdraw: tx complete`);
132135
}
133-
});
136+
);
134137

135-
useTransactionEventListener("IbcWithdraw.Error", () => {
136-
trackEvent(`${shielded ? "Shielded " : ""}IbcWithdraw: tx error`);
137-
});
138+
useTransactionEventListener(
139+
["IbcWithdraw.Error", "ShieldedIbcWithdraw.Error"],
140+
() => {
141+
trackEvent(`${shielded ? "Shielded " : ""}IbcWithdraw: tx error`);
142+
}
143+
);
138144

139145
const redirectToTimeline = (): void => {
140146
if (txHash) {

apps/namadillo/src/atoms/integrations/services.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,8 @@ export const transactionTypeToEventName = (
397397
return "TransparentTransfer";
398398

399399
case "ShieldedToIbc":
400+
return "ShieldedIbcWithdraw";
401+
400402
case "TransparentToIbc":
401403
return "IbcWithdraw";
402404

apps/namadillo/src/hooks/useTransactionCallbacks.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,13 @@ export const useTransactionCallback = (): void => {
7272
useTransactionEventListener("UnshieldingTransfer.Success", onTransferSuccess);
7373
useTransactionEventListener("IbcTransfer.Success", onTransferSuccess);
7474
useTransactionEventListener("IbcWithdraw.Success", onTransferSuccess);
75+
useTransactionEventListener("ShieldedIbcWithdraw.Success", onTransferSuccess);
7576

7677
useTransactionEventListener("TransparentTransfer.Error", onTransferError);
7778
useTransactionEventListener("ShieldedTransfer.Error", onTransferError);
7879
useTransactionEventListener("ShieldingTransfer.Error", onTransferError);
7980
useTransactionEventListener("UnshieldingTransfer.Error", onTransferError);
8081
useTransactionEventListener("IbcTransfer.Error", onTransferError);
8182
useTransactionEventListener("IbcWithdraw.Error", onTransferError);
83+
useTransactionEventListener("ShieldedIbcWithdraw.Error", onTransferError);
8284
};

apps/namadillo/src/hooks/useTransactionNotifications.tsx

Lines changed: 53 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,11 @@ export const useTransactionNotifications = (): void => {
468468
useTransactionEventListener("UnshieldingTransfer.Success", onTransferSuccess);
469469

470470
useTransactionEventListener(
471-
["IbcTransfer.Success", "IbcWithdraw.Success"],
471+
[
472+
"IbcTransfer.Success",
473+
"IbcWithdraw.Success",
474+
"ShieldedIbcWithdraw.Success",
475+
],
472476
({ detail: tx }) => {
473477
if (!tx.hash) return;
474478
invariant(tx.hash, "Notification error: Invalid Tx hash");
@@ -494,51 +498,57 @@ export const useTransactionNotifications = (): void => {
494498
}
495499
);
496500

497-
useTransactionEventListener("IbcTransfer.Error", ({ detail: tx }) => {
498-
if (!tx) return;
501+
useTransactionEventListener(
502+
["IbcTransfer.Error", "IbcWithdraw.Error"],
503+
({ detail: tx }) => {
504+
if (!tx) return;
499505

500-
invariant(tx.hash, "Notification error: Invalid Tx provider");
501-
const id = createNotificationId([tx.hash]);
502-
const title =
503-
tx.type === "ShieldedToIbc" || tx.type === "TransparentToIbc" ?
504-
"IBC withdraw transaction failed"
505-
: "IBC transfer transaction failed";
506+
invariant(tx.hash, "Notification error: Invalid Tx provider");
507+
const id = createNotificationId([tx.hash]);
508+
const title =
509+
tx.type === "ShieldedToIbc" || tx.type === "TransparentToIbc" ?
510+
"IBC withdraw transaction failed"
511+
: "IBC transfer transaction failed";
506512

507-
dispatchNotification({
508-
id,
509-
title,
510-
description: (
511-
<>
512-
Your transaction of{" "}
513-
<TokenCurrency amount={tx.displayAmount} symbol={tx.asset.symbol} />{" "}
514-
has failed.
515-
</>
516-
),
517-
details: tx.errorMessage,
518-
type: "error",
519-
});
520-
});
513+
dispatchNotification({
514+
id,
515+
title,
516+
description: (
517+
<>
518+
Your transaction of{" "}
519+
<TokenCurrency amount={tx.displayAmount} symbol={tx.asset.symbol} />{" "}
520+
has failed.
521+
</>
522+
),
523+
details: tx.errorMessage,
524+
type: "error",
525+
});
526+
}
527+
);
521528

522-
useTransactionEventListener("IbcWithdraw.Error", ({ detail: tx }) => {
523-
if (!tx) return;
529+
useTransactionEventListener(
530+
["ShieldedIbcWithdraw.Error"],
531+
({ detail: tx }) => {
532+
if (!tx) return;
524533

525-
invariant(tx.hash, "Notification error: Invalid Tx provider");
526-
const id = createNotificationId([tx.hash]);
527-
const title = "IBC withdraw transaction failed";
534+
invariant(tx.hash, "Notification error: Invalid Tx provider");
535+
const id = createNotificationId([tx.hash]);
536+
const title = "IBC withdraw transaction failed";
528537

529-
dispatchNotification({
530-
id,
531-
title,
532-
description: (
533-
<>
534-
Your transaction of{" "}
535-
<TokenCurrency amount={tx.displayAmount} symbol={tx.asset.symbol} />{" "}
536-
has failed.{" "}
537-
<b>Open the Namada extension to access the refund account.</b>
538-
</>
539-
),
540-
details: tx.errorMessage,
541-
type: "error",
542-
});
543-
});
538+
dispatchNotification({
539+
id,
540+
title,
541+
description: (
542+
<>
543+
Your transaction of{" "}
544+
<TokenCurrency amount={tx.displayAmount} symbol={tx.asset.symbol} />{" "}
545+
has failed.{" "}
546+
<b>Open the Namada extension to access the refund account.</b>
547+
</>
548+
),
549+
details: tx.errorMessage,
550+
type: "error",
551+
});
552+
}
553+
);
544554
};

apps/namadillo/src/types/events.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,5 +68,7 @@ declare global {
6868
"IbcTransfer.Error": CustomEvent<TransferTransactionData>;
6969
"IbcWithdraw.Success": CustomEvent<TransferTransactionData>;
7070
"IbcWithdraw.Error": CustomEvent<TransferTransactionData>;
71+
"ShieldedIbcWithdraw.Success": CustomEvent<TransferTransactionData>;
72+
"ShieldedIbcWithdraw.Error": CustomEvent<TransferTransactionData>;
7173
}
7274
}

0 commit comments

Comments
 (0)