Skip to content

Commit a62f281

Browse files
authored
fix: stopgap for transparent assets (#2299)
1 parent f23e656 commit a62f281

File tree

4 files changed

+43
-24
lines changed

4 files changed

+43
-24
lines changed

apps/namadillo/src/atoms/balance/functions.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,43 @@ export const getTotalDollar = (list?: TokenBalance[]): BigNumber =>
1717
export const getTotalNam = (list?: TokenBalance[]): BigNumber =>
1818
list?.find((i) => isNamadaAsset(i.asset))?.amount ?? new BigNumber(0);
1919

20+
// Type to handle both balance data structures
21+
type BalanceItem = Balance | { tokenAddress: string; minDenomAmount: string };
22+
2023
export const mapNamadaAddressesToAssets = ({
2124
balances,
2225
assets,
2326
}: {
24-
balances: Balance[];
27+
balances: BalanceItem[];
2528
assets: NamadaAsset[];
2629
}): Record<Address, NamadaAssetWithAmount> => {
2730
const map: Record<Address, NamadaAssetWithAmount> = {};
2831
balances.forEach((item) => {
29-
const asset = assets.find((asset) => asset.address === item.token.address);
32+
// Handle both data structures temporarily:
33+
// 1. {token: {address: '...'}, minDenomAmount: '...'}
34+
// 2. {tokenAddress: '...', minDenomAmount: '...'}
35+
let tokenAddress: string | undefined;
36+
37+
if ("token" in item && item.token?.address) {
38+
tokenAddress = item.token.address;
39+
} else if ("tokenAddress" in item) {
40+
tokenAddress = item.tokenAddress;
41+
}
42+
43+
if (!tokenAddress) {
44+
return;
45+
}
46+
47+
const asset = assets.find((asset) => asset.address === tokenAddress);
3048

3149
if (asset) {
32-
map[item.token.address] = {
50+
map[tokenAddress] = {
3351
amount: toDisplayAmount(asset, BigNumber(item.minDenomAmount)),
3452
asset,
3553
};
3654
}
3755
});
56+
3857
return map;
3958
};
4059

apps/namadillo/src/atoms/fees/atoms.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import { atomFamily } from "jotai/utils";
1313
import { isPublicKeyRevealed } from "lib/query";
1414
import isEqual from "lodash.isequal";
1515
import { TxKind } from "types/txKind";
16-
import { isNamadaAsset, toDisplayAmount } from "utils";
1716
import { fetchGasEstimate, fetchTokensGasPrice } from "./services";
1817

1918
export type GasPriceTableItem = {
@@ -69,16 +68,12 @@ export const gasPriceTableAtom = atomWithQuery<GasPriceTable>((get) => {
6968
return (
7069
response
7170
// filter only tokens that exists on the chain
72-
.filter(({ token }) => Boolean(chainAssetsMap.data[token.address]))
71+
.filter(({ token }) => Boolean(chainAssetsMap.data[token]))
7372
.map(({ token, minDenomAmount }) => {
74-
const asset = chainAssetsMap.data[token.address];
7573
const baseAmount = BigNumber(minDenomAmount);
74+
// Transform string address to token object format
7675
return {
77-
token,
78-
gasPrice:
79-
asset && isNamadaAsset(asset) ?
80-
toDisplayAmount(asset, baseAmount)
81-
: baseAmount,
76+
token: { address: token } as ApiV1ChainTokenGet200ResponseInner,
8277
gasPriceInMinDenom: baseAmount,
8378
};
8479
})

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

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
import {
2-
DefaultApi,
3-
GasEstimate,
4-
GasPriceTableInner,
5-
} from "@namada/indexer-client";
1+
import { DefaultApi, GasEstimate } from "@namada/indexer-client";
62
import { TxKind } from "types/txKind";
73

4+
// Type for the actual API response - token is a string address
5+
// Note: The API type definition is incorrect (says it's an object), but server returns a string
6+
export type GasPriceResponse = {
7+
token: string;
8+
minDenomAmount: string;
9+
};
10+
811
export const fetchGasEstimate = async (
912
api: DefaultApi,
1013
txKinds: TxKind[]
@@ -45,6 +48,9 @@ export const fetchGasEstimate = async (
4548

4649
export const fetchTokensGasPrice = async (
4750
api: DefaultApi
48-
): Promise<GasPriceTableInner[]> => {
49-
return (await api.apiV1GasPriceGet()).data;
51+
): Promise<GasPriceResponse[]> => {
52+
const response = await api.apiV1GasPriceGet();
53+
// The API type definition is wrong - it says token is an object, but server returns a string
54+
// Cast the response to match the actual runtime data
55+
return response.data as unknown as GasPriceResponse[];
5056
};

apps/namadillo/src/utils/gas.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { isTransparentAddress } from "App/Transfer/common";
22
import BigNumber from "bignumber.js";
33
import namadaAssets from "chain-registry/mainnet/namada/assets";
44
import { Address, Asset, GasConfig, GasConfigToDisplay } from "types";
5-
import { isNamadaAsset, toDisplayAmount } from "utils";
5+
import { toDisplayAmount } from "utils";
66
import { unknownAsset } from "./assets";
77

88
export const calculateGasFee = (gasConfig: GasConfig): BigNumber => {
@@ -35,12 +35,11 @@ export const getDisplayGasFee = (
3535
) ?? unknownAsset(gasToken);
3636
}
3737

38-
const totalDisplayAmount = calculateGasFee(gasConfig);
38+
const totalInMinDenom = calculateGasFee(gasConfig);
39+
const totalDisplayAmount = toDisplayAmount(asset, totalInMinDenom);
40+
3941
return {
40-
totalDisplayAmount:
41-
isNamadaAsset(asset) ? totalDisplayAmount : (
42-
toDisplayAmount(asset, totalDisplayAmount).decimalPlaces(6)
43-
),
42+
totalDisplayAmount: totalDisplayAmount.decimalPlaces(6),
4443
asset,
4544
};
4645
};

0 commit comments

Comments
 (0)