Skip to content

Commit 9cd5237

Browse files
committed
fix: cleanup
1 parent 470c506 commit 9cd5237

File tree

4 files changed

+32
-31
lines changed

4 files changed

+32
-31
lines changed

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

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,9 @@ export const LocalStorageTransactionCard = ({
3535
}: TransactionCardProps): JSX.Element => {
3636
const namadaAssetsMap = useAtomValue(namadaRegistryChainAssetsMapAtom);
3737
const namadaAsset =
38-
namadaAssetsMap.data ?
39-
Object.values(namadaAssetsMap.data).find((namadaAsset) => {
40-
// If the transaction asset has an address, try to match it directly
41-
if (
42-
transaction.asset.symbol &&
43-
namadaAsset.symbol === transaction.asset.symbol
44-
) {
45-
return true;
46-
}
47-
})
48-
: undefined;
38+
namadaAssetsMap.data &&
39+
Object.values(namadaAssetsMap.data).find((namadaAsset) => transaction.asset.symbol &&
40+
namadaAsset.symbol === transaction.asset.symbol);
4941

5042
// Use the Namada asset address if available, otherwise try the original asset address
5143
const assetAddress = namadaAsset?.address || transaction.asset.address;
@@ -54,12 +46,12 @@ export const LocalStorageTransactionCard = ({
5446
tokenPricesFamily(assetAddress ? [assetAddress] : [])
5547
);
5648
const tokenPrice =
57-
assetAddress ? tokenPrices.data?.[assetAddress] : undefined;
49+
assetAddress && tokenPrices.data?.[assetAddress];
5850

5951
// Ensure displayAmount is a BigNumber before performing calculations
6052
const displayAmount = BigNumber(transaction.displayAmount);
6153
const dollarAmount =
62-
tokenPrice ? displayAmount.multipliedBy(tokenPrice) : undefined;
54+
tokenPrice && displayAmount.multipliedBy(tokenPrice);
6355

6456
const renderKeplrIcon = (address: string): JSX.Element | null => {
6557
if (isShieldedAddress(address)) return null;

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

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import { allValidatorsAtom } from "atoms/validators";
1818
import BigNumber from "bignumber.js";
1919
import clsx from "clsx";
2020
import { useAtomValue } from "jotai";
21+
import { AtomWithQueryResult } from "jotai-tanstack-query";
22+
import { useCallback } from "react";
2123
import { FaLock } from "react-icons/fa6";
2224
import {
2325
IoCheckmarkCircleOutline,
@@ -85,14 +87,23 @@ export function getToken(
8587
return undefined;
8688
}
8789

88-
const getVoteTransactionInfo = (
89-
tx: Tx["tx"]
90-
): VoteTransactionInfo | undefined => {
91-
if (!tx?.data) return undefined;
92-
const parsed = typeof tx.data === "string" ? JSON.parse(tx.data) : tx.data;
90+
const getVoteTransactionInfo = (tx: Tx["tx"]): VoteTransactionInfo => {
91+
if (!tx?.data)
92+
return {
93+
proposalId: "",
94+
vote: "",
95+
};
96+
97+
let parsed;
98+
try {
99+
parsed = JSON.parse(tx.data);
100+
} catch (error) {
101+
parsed = tx.data;
102+
}
103+
93104
return {
94-
proposalId: parsed.id,
95-
vote: parsed.vote,
105+
proposalId: parsed.id || "",
106+
vote: parsed.vote || "",
96107
};
97108
};
98109

@@ -103,7 +114,7 @@ const getBondOrUnbondTransactionInfo = (
103114

104115
let parsed: BondData;
105116
try {
106-
parsed = typeof tx.data === "string" ? JSON.parse(tx.data) : tx.data;
117+
parsed = JSON.parse(tx.data);
107118
} catch {
108119
return undefined;
109120
}
@@ -165,7 +176,7 @@ const useTransactionCardData = (
165176
asset: NamadaAsset | undefined;
166177
transparentAddress: string;
167178
transactionFailed: boolean;
168-
validators: ReturnType<typeof useAtomValue<typeof allValidatorsAtom>>;
179+
validators: AtomWithQueryResult<Validator[], Error>;
169180
} => {
170181
const transaction = tx.tx;
171182
const nativeToken = useAtomValue(nativeTokenAddressAtom).data;
@@ -434,9 +445,8 @@ const TransactionAmount = ({
434445
const tokenPrices = useAtomValue(
435446
tokenPricesFamily(asset?.address ? [asset.address] : [])
436447
);
437-
const tokenPrice =
438-
asset?.address ? tokenPrices.data?.[asset.address] : undefined;
439-
const dollarAmount = tokenPrice ? amount.multipliedBy(tokenPrice) : undefined;
448+
const tokenPrice = asset?.address && tokenPrices.data?.[asset.address];
449+
const dollarAmount = tokenPrice && amount.multipliedBy(tokenPrice);
440450

441451
return (
442452
<div className="flex items-center">
@@ -469,11 +479,11 @@ const BondUnbondTransactionCard = ({ tx }: Props): JSX.Element => {
469479
(v) => v.address === txnInfo?.receiver
470480
);
471481

472-
const getTitle = (): string => {
482+
const getTitle = useCallback((): string => {
473483
if (transaction?.kind === "bond") return "Stake";
474484
if (transaction?.kind === "unbond") return "Unstake";
475485
return "Bond/Unbond";
476-
};
486+
}, [transaction?.kind]);
477487

478488
return (
479489
<TransactionCardContainer
@@ -581,8 +591,7 @@ const RedelegationTransactionCard = ({ tx }: Props): JSX.Element => {
581591
const VoteTransactionCard = ({ tx }: Props): JSX.Element => {
582592
const { transaction, transactionFailed } = useTransactionCardData(tx);
583593
const voteInfo = getVoteTransactionInfo(transaction);
584-
const proposalId =
585-
voteInfo?.proposalId ? BigInt(voteInfo.proposalId) : undefined;
594+
const proposalId = voteInfo?.proposalId && BigInt(voteInfo.proposalId);
586595
const proposal = useAtomValue(proposalFamily(proposalId || BigInt(0)));
587596
const navigate = useNavigate();
588597

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"git-commit-msg-linter": "^5.0.6",
2828
"husky": "^8.0.3",
2929
"lint-staged": "^15.2.0",
30-
"prettier": "^3.3.3",
30+
"prettier": "^3.6.2",
3131
"prettier-plugin-organize-imports": "^3.2.4",
3232
"stream-browserify": "^3.0.0",
3333
"typescript": "5.5.4",

yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21736,4 +21736,4 @@ __metadata:
2173621736
resolution: "zxcvbn@npm:4.4.2"
2173721737
checksum: 10c0/862f101cc95247b30290bad67ade333e430a16763bb771ce4e4c5414396d987f9a64288225675c96bd6f8d3eba65da0dee119b2a4eaa2e249da3f540b036942e
2173821738
languageName: node
21739-
linkType: hard
21739+
linkType: hard

0 commit comments

Comments
 (0)