Skip to content

Commit d4cbd79

Browse files
authored
Merge pull request #197 from cosmology-tech/eason/bugfixing
Eason/bugfixing
2 parents 7ec0efc + f4304d1 commit d4cbd79

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+931
-42692
lines changed

examples/asset-list/components/asset-list/AssetsOverview.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ const AssetsOverview = ({
4040
isLoading: isLoadingTotalAssets,
4141
refetch,
4242
} = useTotalAssets(selectedChainName);
43-
const { getChainName, getNativeDenom, isNativeAsset } =
43+
const { getChainName, getNativeDenom, isNativeAsset, getDenomBySymbolAndChain } =
4444
useChainUtils(selectedChainName);
4545

4646
const modalControl = useDisclosure();
@@ -70,7 +70,7 @@ const AssetsOverview = ({
7070
showWithdraw: !isNativeAsset(asset),
7171
onDeposit: () => {
7272
const sourceChainName = getChainName(asset.denom);
73-
const sourceChainNativeDenom = getNativeDenom(sourceChainName);
73+
const denom = getDenomBySymbolAndChain(sourceChainName, asset.symbol);
7474
flushSync(() => {
7575
setRowTransferInfo({
7676
sourceChainName,
@@ -80,7 +80,7 @@ const AssetsOverview = ({
8080
...prettyAssetToTransferItem(asset),
8181
priceDisplayAmount: 0,
8282
available: 0,
83-
denom: sourceChainNativeDenom,
83+
denom
8484
},
8585
});
8686
});

examples/asset-list/components/asset-list/DropdownTransferModal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ const OverviewTransferWrapper = (
188188
return asset.symbol !== transferToken.symbol;
189189
})
190190
.map((asset) => ({
191-
available: new BigNumber(asset.amount).toNumber(),
191+
available: new BigNumber(asset.displayAmount).toNumber(),
192192
symbol: asset.symbol,
193193
name: asset.prettyChainName,
194194
denom: asset.denom,

examples/asset-list/components/asset-list/RowTransferModal.tsx

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,25 +66,30 @@ const TransferModalBody = (
6666

6767
const { balance, isLoading: isLoadingBalance } = useBalance(
6868
sourceChainName,
69-
isDeposit
69+
isDeposit,
70+
transferInfo.token.symbol
7071
);
7172

7273
const { getChainLogo } = useManager();
7374
const { tx } = useTx(sourceChainName);
7475

7576
const availableAmount = useMemo(() => {
76-
if (!isDeposit) return transferToken.priceDisplayAmount ?? 0;
77-
if (isLoading) return 0;
77+
if (!isDeposit) return transferToken.available ?? 0;
78+
if (isLoadingBalance) return 0;
79+
80+
console.log('transferInfo.token', transferInfo.token)
7881

7982
return new BigNumber(
80-
convRawToDispAmount(transferToken.symbol, balance?.amount || '0')
83+
convRawToDispAmount(transferInfo.token.symbol, balance?.amount || '0')
8184
).toNumber();
8285
// eslint-disable-next-line react-hooks/exhaustive-deps
83-
}, [isDeposit, isLoading, transferToken]);
86+
}, [isDeposit, isLoading, transferToken.symbol, balance?.amount, transferInfo.token.symbol,
87+
isLoadingBalance
88+
]);
8489

85-
const dollarValue = new BigNumber(inputValue)
86-
.multipliedBy(prices[symbolToDenom(transferToken.symbol)])
87-
.decimalPlaces(2)
90+
const dollarValue = new BigNumber(1)
91+
.multipliedBy(prices[symbolToDenom(transferToken.symbol, transferInfo.sourceChainName)])
92+
.decimalPlaces(6)
8893
.toNumber();
8994

9095
useEffect(() => {
@@ -145,7 +150,6 @@ const TransferModalBody = (
145150

146151
const sourceChain = useMemo(() => {
147152
return {
148-
symbol: sourceChainInfo.chain_name.toUpperCase(),
149153
name: sourceChainInfo.pretty_name,
150154
address: sourceAddress ?? '',
151155
imgSrc: getChainLogo(sourceChainName) ?? '',
@@ -212,7 +216,7 @@ const TransferModalBody = (
212216
return (
213217
<AssetWithdrawTokens
214218
isDropdown={false}
215-
fromSymbol={sourceChain.symbol}
219+
fromSymbol={transferInfo.token.symbol}
216220
fromName={sourceChain.name}
217221
fromAddress={sourceChain.address}
218222
fromImgSrc={sourceChain.imgSrc}
@@ -246,7 +250,7 @@ const TransferModalBody = (
246250
};
247251

248252
export const RowTransferModal = (props: IProps) => {
249-
const { modalControl } = props;
253+
const { modalControl, transferInfo } = props;
250254
const [inputValue, setInputValue] = useState('');
251255
const [isLoading, setIsLoading] = useState(false);
252256

@@ -258,7 +262,7 @@ export const RowTransferModal = (props: IProps) => {
258262
return (
259263
<BasicModal
260264
isOpen={modalControl.isOpen}
261-
title="Deposit"
265+
title={transferInfo.type}
262266
onClose={() => closeModal()}
263267
>
264268
<TransferModalBody

examples/asset-list/components/common/Layout.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export const Layout = ({ children }: { children?: React.ReactNode }) => {
2424
}}
2525
>
2626
<Head>
27-
<title>Create Cosmos App</title>
27+
<title>Asset List - Create Cosmos App</title>
2828
<meta name="description" content="Generated by create cosmos app" />
2929
<link rel="icon" href="/favicon.ico" />
3030
</Head>

examples/asset-list/hooks/queries/useAssets.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,13 @@ export const useAssets = (chainName: string) => {
7979

8080
const { allBalances, prices, topTokens } = queriesData;
8181

82-
const nativeAndIbcBalances: Coin[] = allBalances.filter(
82+
const nativeAndIbcBalances: Coin[] = allBalances?.filter(
8383
({ denom }) => !denom.startsWith('gamm') && prices[denom]
8484
);
8585

8686
const emptyBalances: Coin[] = ibcAssets
8787
.filter(({ base }) => {
88-
const notInBalances = !nativeAndIbcBalances.find(
88+
const notInBalances = !nativeAndIbcBalances?.find(
8989
({ denom }) => denom === base
9090
);
9191
return notInBalances && prices[base];
@@ -96,7 +96,7 @@ export const useAssets = (chainName: string) => {
9696
})
9797
.map((asset) => ({ denom: asset.base, amount: '0' }));
9898

99-
const finalAssets = [...nativeAndIbcBalances, ...emptyBalances]
99+
const finalAssets = [...(nativeAndIbcBalances ?? []), ...emptyBalances]
100100
.map(({ amount, denom }) => {
101101
const asset = getAssetByDenom(denom);
102102
const symbol = denomToSymbol(denom);

examples/asset-list/hooks/queries/useBalance.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,17 @@ import { UseQueryResult } from '@tanstack/react-query';
44
import { useEffect } from 'react';
55
import { useQueryHooks } from './useQueryHooks';
66

7-
export const useBalance = (chainName: string, enabled: boolean = true) => {
7+
export const useBalance = (chainName: string, enabled: boolean = true,
8+
displayDenom?: string
9+
) => {
810
const { address, assets } = useChain(chainName);
11+
let denom = assets?.assets[0].base!;
12+
for (const asset of assets?.assets || []) {
13+
if (asset.display.toLowerCase() === displayDenom?.toLowerCase()) {
14+
denom = asset.base;
15+
break;
16+
}
17+
}
918

1019
const { cosmosQuery, isReady, isFetching } = useQueryHooks(
1120
chainName,
@@ -15,7 +24,7 @@ export const useBalance = (chainName: string, enabled: boolean = true) => {
1524
const balanceQuery: UseQueryResult<Coin> =
1625
cosmosQuery.bank.v1beta1.useBalance({
1726
request: {
18-
denom: assets!.assets[0]!.base,
27+
denom,
1928
address: address || '',
2029
},
2130
options: {
@@ -26,13 +35,13 @@ export const useBalance = (chainName: string, enabled: boolean = true) => {
2635

2736
useEffect(() => {
2837
return () => {
29-
balanceQuery.remove();
38+
balanceQuery.remove()
3039
};
3140
// eslint-disable-next-line react-hooks/exhaustive-deps
3241
}, []);
3342

3443
return {
3544
balance: balanceQuery.data,
36-
isLoading: isFetching || balanceQuery.isFetching,
45+
isLoading: isFetching // || !!balanceQueries.find(item => item.isFetching),
3746
};
3847
};

examples/asset-list/hooks/useChainUtils.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,14 @@ export const useChainUtils = (chainName: string) => {
4949
return symbol;
5050
};
5151

52-
const symbolToDenom = (symbol: CoinSymbol): CoinDenom => {
53-
const asset = allAssets.find((asset) => asset.symbol === symbol);
52+
const symbolToDenom = (symbol: CoinSymbol, chainName?: string): CoinDenom => {
53+
const asset = allAssets.find((asset) => (
54+
asset.symbol === symbol
55+
&& (
56+
!chainName
57+
|| asset.traces?.[0].counterparty.chain_name.toLowerCase() === chainName.toLowerCase()
58+
)
59+
));
5460
const base = asset?.base;
5561
if (!base) {
5662
return symbol;
@@ -85,7 +91,7 @@ export const useChainUtils = (chainName: string) => {
8591
}
8692
const asset = ibcAssets.find((asset) => asset.base === ibcDenom);
8793
const ibcChainName = asset?.traces?.[0].counterparty.chain_name;
88-
if (!ibcChainName) throw Error('chainName not found: ' + ibcDenom);
94+
if (!ibcChainName) throw Error('chainName not found for ibcDenom: ' + ibcDenom);
8995
return ibcChainName;
9096
};
9197

@@ -111,6 +117,13 @@ export const useChainUtils = (chainName: string) => {
111117
return denom;
112118
};
113119

120+
const getDenomBySymbolAndChain = (chainName: ChainName, symbol: string) => {
121+
const chainRecord = getChainRecord(chainName);
122+
const denom = chainRecord.assetList?.assets.find((asset) => asset.symbol === symbol)?.base;
123+
if (!denom) throw Error('denom not found');
124+
return denom;
125+
};
126+
114127
const getIbcInfo = (fromChainName: string, toChainName: string) => {
115128
let flipped = false;
116129

@@ -156,5 +169,6 @@ export const useChainUtils = (chainName: string) => {
156169
getNativeDenom,
157170
getIbcInfo,
158171
getExponentByDenom,
172+
getDenomBySymbolAndChain
159173
};
160174
};

examples/asset-list/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"@cosmos-kit/react": "2.17.0",
2828
"@emotion/react": "11.10.6",
2929
"@emotion/styled": "11.10.6",
30-
"@interchain-ui/react": "1.23.22",
30+
"@interchain-ui/react": "1.23.29",
3131
"@interchain-ui/react-no-ssr": "^0.1.6",
3232
"@tanstack/react-query": "4.32.0",
3333
"@uidotdev/usehooks": "2.4.1",

examples/asset-list/pages/_app.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import '../styles/globals.css';
22
import '@interchain-ui/react/globalStyles';
33
import '@interchain-ui/react/styles';
44

5-
import { ThemeProvider, Toaster, useTheme } from '@interchain-ui/react';
5+
import { OverlaysManager, ThemeProvider, Toaster, useTheme } from '@interchain-ui/react';
66
import type { AppProps } from 'next/app';
77
import { ChainProvider } from '@cosmos-kit/react';
88

@@ -75,6 +75,7 @@ function CreateCosmosApp({ Component, pageProps }: AppProps) {
7575
</ChainProvider>
7676

7777
<Toaster position={'top-right'} closeButton={true} />
78+
<OverlaysManager />
7879
</ThemeProvider>
7980
);
8081
}

0 commit comments

Comments
 (0)