Skip to content

Commit 2348d03

Browse files
authored
fix: Unshielding Transfer showing wrong amount in History (#2155)
1 parent 75b24cb commit 2348d03

File tree

3 files changed

+67
-20
lines changed

3 files changed

+67
-20
lines changed

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

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
isShieldedAddress,
88
isTransparentAddress,
99
} from "App/Transfer/common";
10+
import { allDefaultAccountsAtom } from "atoms/accounts";
1011
import { chainAssetsMapAtom, nativeTokenAddressAtom } from "atoms/chain";
1112
import { TransactionHistory as TransactionHistoryType } from "atoms/transactions/atoms";
1213
import { allValidatorsAtom } from "atoms/validators";
@@ -25,9 +26,9 @@ import keplrSvg from "../../integrations/assets/keplr.svg";
2526
type Tx = TransactionHistoryType;
2627
type Props = { tx: Tx };
2728
type RawDataSection = {
28-
amount?: string;
29-
sources?: Array<{ amount: string; owner: string }>;
30-
targets?: Array<{ amount: string; owner: string }>;
29+
amount: string;
30+
sources: Array<{ amount: string; owner: string }>;
31+
targets: Array<{ amount: string; owner: string }>;
3132
};
3233
type BondData = {
3334
amount: string;
@@ -80,7 +81,8 @@ const getBondOrUnbondTransactionInfo = (
8081
};
8182
};
8283
const getTransactionInfo = (
83-
tx: Tx["tx"]
84+
tx: Tx["tx"],
85+
transparentAddress: string
8486
): { amount: BigNumber; sender?: string; receiver?: string } | undefined => {
8587
if (!tx?.data) return undefined;
8688

@@ -90,22 +92,20 @@ const getTransactionInfo = (
9092
const source = sections.find((s) => s.sources?.length);
9193

9294
let amount: BigNumber | undefined;
93-
let receiver: string | undefined;
95+
const mainTarget = target?.targets.find(
96+
(src) => src.owner === transparentAddress
97+
);
98+
const mainSource = source?.sources.find(
99+
(src) => src.owner === transparentAddress
100+
);
94101

95-
if (target?.targets) {
96-
const mainTarget = target.targets.reduce((max, cur) =>
97-
new BigNumber(cur.amount).isGreaterThan(max.amount) ? cur : max
98-
);
102+
if (mainTarget) {
99103
amount = new BigNumber(mainTarget.amount);
100-
receiver = mainTarget.owner;
104+
} else if (mainSource) {
105+
amount = new BigNumber(mainSource.amount);
101106
}
102-
// fall back to sources only when we had no targets
103-
if (!amount && source?.sources?.[0]) {
104-
amount = new BigNumber(source.sources[0].amount);
105-
}
106-
107-
const sender = sections.find((s) => s.sources?.[0]?.owner)?.sources?.[0]
108-
?.owner;
107+
const receiver = target?.targets[0].owner;
108+
const sender = source?.sources[0].owner;
109109

110110
return amount ? { amount, sender, receiver } : undefined;
111111
};
@@ -121,10 +121,15 @@ export const TransactionCard = ({
121121
const isBondingOrUnbondingTransaction = ["bond", "unbond"].includes(
122122
transactionTopLevel?.tx?.kind ?? ""
123123
);
124+
const { data: accounts } = useAtomValue(allDefaultAccountsAtom);
125+
126+
const transparentAddress =
127+
accounts?.find((acc) => isTransparentAddress(acc.address))?.address ?? "";
128+
124129
const txnInfo =
125130
isBondingOrUnbondingTransaction ?
126131
getBondOrUnbondTransactionInfo(transaction)
127-
: getTransactionInfo(transaction);
132+
: getTransactionInfo(transaction, transparentAddress);
128133
const receiver = txnInfo?.receiver;
129134
const sender = txnInfo?.sender;
130135
const isReceived = transactionTopLevel?.kind === "received";

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

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,53 @@ export const TransactionHistory = (): JSX.Element => {
7979
} else return transactionKind === filter;
8080
};
8181

82+
const filterDuplicateTransactions = (
83+
transactions: TransactionHistoryType[]
84+
): TransactionHistoryType[] => {
85+
const seen = new Set();
86+
return transactions.filter((tx) => {
87+
// We only need to filter received transactions for the 5-6 repeat txns
88+
// For IBC -> Transparent transactions
89+
if (tx.kind !== "received") return true;
90+
try {
91+
const data =
92+
tx.tx?.data?.startsWith("[") ?
93+
JSON.parse(tx.tx.data)[1] || JSON.parse(tx.tx.data)[0]
94+
: JSON.parse(tx.tx?.data ?? "{}");
95+
const key = JSON.stringify({
96+
blockHeight: tx.block_height,
97+
target: tx.target,
98+
sources: (data.sources || [])
99+
.map((s: Record<string, string>) => ({
100+
owner: s.owner,
101+
token: s.token,
102+
amount: s.amount,
103+
type: s.type,
104+
}))
105+
.sort(),
106+
targets: (data.targets || [])
107+
.map((t: Record<string, string>) => ({
108+
owner: t.owner,
109+
token: t.token,
110+
amount: t.amount,
111+
type: t.type,
112+
}))
113+
.sort(),
114+
});
115+
return seen.has(key) ? false : seen.add(key);
116+
} catch {
117+
return true;
118+
}
119+
});
120+
};
82121
// Only show historical transactions that are in the transferKindOptions array
83-
const historicalTransactions =
122+
const filteredTransactions =
84123
transactions?.results?.filter((transaction) =>
85124
handleFiltering(transaction)
86125
) ?? [];
126+
// Remove duplicates
127+
const historicalTransactions =
128+
filterDuplicateTransactions(filteredTransactions);
87129

88130
const allHistoricalTransactions = [
89131
...historicalTransactions,

apps/namadillo/src/App/Transfer/CustomAddressForm.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export const CustomAddressForm = ({
4545
label="Memo"
4646
value={memo}
4747
onChange={(e) => onChangeMemo(e.target.value)}
48-
placeholder="Required for centralized exchanges"
48+
placeholder="Insert memo here"
4949
/>
5050
)}
5151
</Stack>

0 commit comments

Comments
 (0)