Skip to content

Commit 7c67883

Browse files
fix: use tx wrapper hashes in history and notification toasts for ledger (#2129)
1 parent 3706a68 commit 7c67883

File tree

12 files changed

+55
-39
lines changed

12 files changed

+55
-39
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,8 @@ export const IbcWithdraw = (): JSX.Element => {
272272
invariant(props, "Invalid transaction data");
273273

274274
const transferTransaction: IbcTransferTransactionData = {
275-
hash: tx.encodedTxData.txs[0].innerTxHashes[0].toLowerCase(),
275+
hash: tx.encodedTxData.txs[0].hash,
276+
innerHash: tx.encodedTxData.txs[0].innerTxHashes[0].toLowerCase(),
276277
currentStep: TransferStep.WaitingConfirmation,
277278
rpc: "",
278279
type: shielded ? "ShieldedToIbc" : "TransparentToIbc",

apps/namadillo/src/App/Staking/StakingRewards.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export const StakingRewards = (): JSX.Element => {
7272
params: rewardsToClaim,
7373
eventType: ["ClaimRewards", "Bond"],
7474
parsePendingTxNotification: () => ({
75-
title: "Claim rewards transaction is in progress",
75+
title: "Claim and stake rewards transaction is in progress",
7676
description: (
7777
<>
7878
Your rewards claim is being processed and will be staked to the same

apps/namadillo/src/App/Transactions/TransactionCard.tsx

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export function getToken(
3939
txn: Tx["tx"],
4040
nativeToken: string
4141
): string | undefined {
42-
if (txn?.kind === "bond") return nativeToken;
42+
if (txn?.kind === "bond" || txn?.kind === "unbond") return nativeToken;
4343
let parsed;
4444
try {
4545
parsed = txn?.data ? JSON.parse(txn.data) : undefined;
@@ -62,7 +62,7 @@ export function getToken(
6262
return undefined;
6363
}
6464

65-
const getBondTransactionInfo = (
65+
const getBondOrUnbondTransactionInfo = (
6666
tx: Tx["tx"]
6767
): { amount: BigNumber; sender?: string; receiver?: string } | undefined => {
6868
if (!tx?.data) return undefined;
@@ -118,10 +118,12 @@ export const TransactionCard = ({
118118
const token = getToken(transaction, nativeToken ?? "");
119119
const chainAssetsMap = useAtomValue(chainAssetsMapAtom);
120120
const asset = token ? chainAssetsMap[token] : undefined;
121-
const isBondingTransaction = transactionTopLevel?.tx?.kind === "bond";
121+
const isBondingOrUnbondingTransaction = ["bond", "unbond"].includes(
122+
transactionTopLevel?.tx?.kind ?? ""
123+
);
122124
const txnInfo =
123-
isBondingTransaction ?
124-
getBondTransactionInfo(transaction)
125+
isBondingOrUnbondingTransaction ?
126+
getBondOrUnbondTransactionInfo(transaction)
125127
: getTransactionInfo(transaction);
126128
const receiver = txnInfo?.receiver;
127129
const sender = txnInfo?.sender;
@@ -134,7 +136,8 @@ export const TransactionCard = ({
134136

135137
const getBaseAmount = (): BigNumber | undefined => {
136138
if (asset && txnInfo?.amount) {
137-
if (isBondingTransaction) return toDisplayAmount(asset, txnInfo.amount);
139+
if (isBondingOrUnbondingTransaction)
140+
return toDisplayAmount(asset, txnInfo.amount);
138141
if (isNamadaAsset(asset)) return txnInfo.amount;
139142
return toDisplayAmount(asset, txnInfo.amount);
140143
} else return undefined;
@@ -154,6 +157,7 @@ export const TransactionCard = ({
154157
if (isReceived) return "Receive";
155158
if (kind.startsWith("ibc")) return "IBC Transfer";
156159
if (kind === "bond") return "Stake";
160+
if (kind === "unbond") return "Unstake";
157161
if (kind === "claimRewards") return "Claim Rewards";
158162
if (kind === "transparentTransfer") return "Transparent Transfer";
159163
if (kind === "shieldingTransfer") return "Shielding Transfer";
@@ -171,7 +175,9 @@ export const TransactionCard = ({
171175
"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 items-center my-1 font-semibold",
172176
"gap-5 bg-neutral-800 rounded-sm px-5 text-white border border-transparent",
173177
"transition-colors duration-200 hover:border-neutral-500",
174-
isBondingTransaction && validator?.imageUrl ? "py-3" : "py-5"
178+
isBondingOrUnbondingTransaction && validator?.imageUrl ?
179+
"py-3"
180+
: "py-5"
175181
)
176182
)}
177183
>
@@ -205,7 +211,7 @@ export const TransactionCard = ({
205211
<div className="relative group/tooltip">
206212
<CopyToClipboardControl
207213
className="ml-1.5 text-neutral-400"
208-
value={transaction?.txId ?? ""}
214+
value={transaction?.wrapperId ?? ""}
209215
/>
210216
<Tooltip position="right" className="p-2 -mr-3 w-[150px] z-10">
211217
Copy transaction hash
@@ -239,7 +245,7 @@ export const TransactionCard = ({
239245
/>
240246
</div>
241247

242-
{!isBondingTransaction && (
248+
{!isBondingOrUnbondingTransaction && (
243249
<div className="flex flex-col">
244250
<h4 className={isShieldedAddress(sender ?? "") ? "text-yellow" : ""}>
245251
From
@@ -260,14 +266,14 @@ export const TransactionCard = ({
260266

261267
<div className="flex flex-col">
262268
<h4 className={isShieldedAddress(receiver ?? "") ? "text-yellow" : ""}>
263-
{isBondingTransaction ? "Validator" : "To"}
269+
{isBondingOrUnbondingTransaction ? "Validator" : "To"}
264270
</h4>
265271
<h4 className={isShieldedAddress(receiver ?? "") ? "text-yellow" : ""}>
266272
{isShieldedAddress(receiver ?? "") ?
267273
<span className="flex items-center gap-1">
268274
<FaLock className="w-4 h-4" /> Shielded
269275
</span>
270-
: isBondingTransaction ?
276+
: isBondingOrUnbondingTransaction ?
271277
validator?.imageUrl ?
272278
<img
273279
src={validator?.imageUrl}

apps/namadillo/src/App/Transactions/TransactionHistory.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export const transferKindOptions = [
2828
"ibcUnshieldingTransfer",
2929
"ibcShieldedTransfer",
3030
"bond",
31+
"unbond",
3132
"received",
3233
];
3334

@@ -195,6 +196,11 @@ export const TransactionHistory = (): JSX.Element => {
195196
value: "Stake",
196197
ariaLabel: "Stake",
197198
},
199+
{
200+
id: "unbond",
201+
value: "Unstake",
202+
ariaLabel: "Unstake",
203+
},
198204
]}
199205
/>
200206
<div className="flex items-center bg-yellow/10 border border-yellow/30 rounded-sm px-3 py-2 mr-3 text-xs text-yellow-600 dark:text-yellow-400">

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,8 @@ export const updateIbcWithdrawalStatus = async (
272272
if (!tx.hash) throw new Error("Transaction hash not defined");
273273

274274
const api = getIndexerApi();
275-
const response = await api.apiV1IbcTxIdStatusGet(tx.hash);
275+
// We have to pass inner hash here to get specific transaction status
276+
const response = await api.apiV1IbcTxIdStatusGet(tx.innerHash);
276277
const { status } = response.data;
277278

278279
if (status === "success") {
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
export const notificationIdSeparator = ";";
22
import { TxProps } from "@namada/types";
33

4-
export const createNotificationId = (
5-
data?: TxProps["hash"] | TxProps["hash"][]
6-
): string => {
4+
export const createNotificationId = (data?: TxProps["hash"][]): string => {
75
if (!data) return Date.now().toString();
8-
if (typeof data === "string") return data;
96
if (Array.isArray(data)) return data.join(notificationIdSeparator);
107
return data;
118
};

apps/namadillo/src/hooks/useIbcTransaction.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ export const useIbcTransaction = ({
113113
const dispatchPendingTxNotification = (tx: TransferTransactionData): void => {
114114
invariant(tx.hash, "Error: Transaction hash not provided");
115115
dispatchNotification({
116-
id: createNotificationId(tx.hash),
116+
id: createNotificationId([tx.hash]),
117117
title: "IBC transfer transaction in progress",
118118
description: (
119119
<>
@@ -129,7 +129,7 @@ export const useIbcTransaction = ({
129129
const dispatchErrorTxNotification = (error: unknown): void => {
130130
if (!txHash) return;
131131
dispatchNotification({
132-
id: createNotificationId(txHash),
132+
id: createNotificationId([txHash]),
133133
title: "IBC transfer transaction failed",
134134
description: "",
135135
details: error instanceof Error ? error.message : undefined,

apps/namadillo/src/hooks/useTransaction.tsx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@ export type UseTransactionOutput<T> = {
6161
unknown
6262
>;
6363

64+
const getNotificationId = <T,>(tx: TransactionPair<T>): string => {
65+
const notificationId = createNotificationId(
66+
tx.encodedTxData.txs.map((tx) => tx.hash)
67+
);
68+
69+
return notificationId;
70+
};
71+
6472
export const useTransaction = <T,>({
6573
params,
6674
createTxAtom,
@@ -101,10 +109,8 @@ export const useTransaction = <T,>({
101109
tx: TransactionPair<T>,
102110
notification: PartialNotification
103111
): void => {
104-
const notificationId =
105-
tx.encodedTxData.type === "buildIbcTransfer" ?
106-
createNotificationId(tx.encodedTxData.txs[0].innerTxHashes)
107-
: createNotificationId(tx.encodedTxData.txs[0].hash);
112+
const notificationId = getNotificationId(tx);
113+
108114
dispatchNotification({
109115
...notification,
110116
id: notificationId,
@@ -118,10 +124,7 @@ export const useTransaction = <T,>({
118124
notification: PartialNotification,
119125
tx: TransactionPair<T>
120126
): void => {
121-
const notificationId =
122-
tx.encodedTxData.type === "buildIbcTransfer" ?
123-
createNotificationId(tx.encodedTxData.txs[0].innerTxHashes)
124-
: createNotificationId(tx.encodedTxData.txs[0].hash);
127+
const notificationId = getNotificationId(tx);
125128
dispatchNotification({
126129
...notification,
127130
id: notificationId,

apps/namadillo/src/hooks/useTransactionNotifications.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const parseTxsData = <T extends TxWithAmount>(
2828
data: T[]
2929
): { id: string; total: BigNumber } => {
3030
const id = createNotificationId(
31-
Array.isArray(tx) ? tx.map((t) => t.hash) : tx.hash
31+
Array.isArray(tx) ? tx.map((t) => t.hash) : [tx.hash]
3232
);
3333
const total = getTotalAmountFromTransactionList(data);
3434
return { total, id };
@@ -414,7 +414,7 @@ export const useTransactionNotifications = (): void => {
414414
detail: tx,
415415
}: CustomEvent<TransferTransactionData>): void => {
416416
if (!tx.hash) return;
417-
const id = createNotificationId(tx.hash);
417+
const id = createNotificationId([tx.hash]);
418418
const storedTx = searchAllStoredTxByHash(tx.hash);
419419
dispatchNotification({
420420
id,
@@ -443,7 +443,7 @@ export const useTransactionNotifications = (): void => {
443443
detail: tx,
444444
}: CustomEvent<TransferTransactionData>): void => {
445445
if (!tx.hash) return;
446-
const id = createNotificationId(tx.hash);
446+
const id = createNotificationId([tx.hash]);
447447
const storedTx = searchAllStoredTxByHash(tx.hash);
448448
dispatchNotification({
449449
id,
@@ -473,7 +473,7 @@ export const useTransactionNotifications = (): void => {
473473
if (!tx.hash) return;
474474
invariant(tx.hash, "Notification error: Invalid Tx hash");
475475

476-
const id = createNotificationId(tx.hash);
476+
const id = createNotificationId([tx.hash]);
477477
const title =
478478
tx.type === "ShieldedToIbc" || tx.type === "TransparentToIbc" ?
479479
"IBC withdraw transaction succeeded"
@@ -498,7 +498,7 @@ export const useTransactionNotifications = (): void => {
498498
if (!tx) return;
499499

500500
invariant(tx.hash, "Notification error: Invalid Tx provider");
501-
const id = createNotificationId(tx.hash);
501+
const id = createNotificationId([tx.hash]);
502502
const title =
503503
tx.type === "ShieldedToIbc" || tx.type === "TransparentToIbc" ?
504504
"IBC withdraw transaction failed"
@@ -523,7 +523,7 @@ export const useTransactionNotifications = (): void => {
523523
if (!tx) return;
524524

525525
invariant(tx.hash, "Notification error: Invalid Tx provider");
526-
const id = createNotificationId(tx.hash);
526+
const id = createNotificationId([tx.hash]);
527527
const title = "IBC withdraw transaction failed";
528528

529529
dispatchNotification({

apps/namadillo/src/lib/query.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,9 @@ export type TransactionPair<T> = {
2727

2828
export type EncodedTxData<T> = {
2929
type: string;
30-
txs: TxProps[] &
31-
{
32-
innerTxHashes: string[];
33-
}[];
30+
txs: (TxProps & {
31+
innerTxHashes: string[];
32+
})[];
3433
wrapperTxProps: WrapperTxProps;
3534
meta?: {
3635
props: T[];

apps/namadillo/src/lib/transactions.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ export const createTransferDataFromIbc = (
162162
const transferTx: IbcTransferTransactionData = {
163163
...details,
164164
hash: tx.transactionHash,
165+
// For IBC transfers(deposits), the innerHash is the same as the transaction hash
166+
innerHash: tx.transactionHash,
165167
rpc,
166168
asset,
167169
feePaid,

apps/namadillo/src/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,8 @@ export type TransferStage = IbcTransferStage | NamadaTransferStage;
341341
export type BaseTransferTransaction = TransferStage & {
342342
rpc: string;
343343
asset: Asset;
344-
hash?: string;
344+
hash: string;
345+
innerHash: string;
345346
displayAmount: BigNumber;
346347
chainId: string;
347348
sourceAddress: string;

0 commit comments

Comments
 (0)