Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
6dc07ef
need to install dayjs to run examples/telescope
Jul 17, 2024
a84ed08
* Fixed issue that deposit/withdraw modal title always show "Deposit"…
Jul 17, 2024
b1c120a
show balance on the deposit/withdraw modal from the list
Jul 18, 2024
df07835
test changing timeEstimateLabel and found it not working
Jul 18, 2024
3f8ed9a
remove log of inputvalue
Jul 18, 2024
40185cd
upgrade interchain-ui
Jul 18, 2024
62dc7bc
upgrade interchain-ui to 1.23.26 and issues of estimate time label an…
Jul 22, 2024
ae4a55d
bug fixed: show displayAmount instaed amount in the OverviewTransfer …
Jul 22, 2024
290d6f1
modify useBalance hook to fetch all assets balance
Jul 22, 2024
d07b36e
get balance by token symbol
Jul 24, 2024
7550c8d
fixed some bugs related to undefined
Jul 24, 2024
064954e
add getDenomBySymbolAndChain
Jul 24, 2024
ad68f5e
get the right denom when deposit from list
Jul 24, 2024
456534a
add paramater chainName to symbolToDenom function, to find ibc denom …
Jul 25, 2024
fca945e
modify dollarValue by getting 1 token price to be token usd value
Jul 25, 2024
a68619f
upgrade @interchain-ui/react from 1.23.26 to 1.23.28 to solve the bug…
Jul 25, 2024
3f91414
change title of website from "Create Cosmos App" to "Asset List - Cre…
Jul 25, 2024
02278b1
more details of error
Jul 26, 2024
00be52b
upgrade @interchain-ui/react from 1.23.22 to 1.23.28
Jul 26, 2024
f08a455
modify title name
Jul 29, 2024
3ba8b76
upgrade interchain-ui from 1.23.28 to 1.23.29
Jul 31, 2024
bdc7589
modify title, added "Vote Proposal" to it
Jul 31, 2024
25fa997
use v1 of proposal API
Jul 31, 2024
72ae9d3
show proposal description from v1 API
Jul 31, 2024
fa15db5
fix: input clamp behavior
yyyyaaa Jul 31, 2024
4aac19f
upgrade interchanjs to 1.23.29
Aug 1, 2024
89e396e
solve the issue that shows 'Box' cannot be used as a JSX component by…
Aug 4, 2024
58c289f
fixed two bug of example telescope while building
Aug 4, 2024
0de7da8
fixed build failed of authz by upgrading @cosmjs/encoding
Aug 5, 2024
730d957
fixed the bug that cca nft build failed by upgrading @interchain-ui/r…
Aug 5, 2024
4355162
fixed the bug that cca rollkie example failed to build by upgrading b…
Aug 5, 2024
f5eefff
fixed the path not found for Coin
Aug 5, 2024
135959a
fixed the issue shows 'Box' cannot be used as a JSX component
Aug 5, 2024
c5fc3af
Merge branch 'bugs/stake-tokens' into eason/bugfixing
Aug 6, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions examples/asset-list/components/asset-list/AssetsOverview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const AssetsOverview = ({
isLoading: isLoadingTotalAssets,
refetch,
} = useTotalAssets(selectedChainName);
const { getChainName, getNativeDenom, isNativeAsset } =
const { getChainName, getNativeDenom, isNativeAsset, getDenomBySymbolAndChain } =
useChainUtils(selectedChainName);

const modalControl = useDisclosure();
Expand Down Expand Up @@ -70,7 +70,7 @@ const AssetsOverview = ({
showWithdraw: !isNativeAsset(asset),
onDeposit: () => {
const sourceChainName = getChainName(asset.denom);
const sourceChainNativeDenom = getNativeDenom(sourceChainName);
const denom = getDenomBySymbolAndChain(sourceChainName, asset.symbol);
flushSync(() => {
setRowTransferInfo({
sourceChainName,
Expand All @@ -80,7 +80,7 @@ const AssetsOverview = ({
...prettyAssetToTransferItem(asset),
priceDisplayAmount: 0,
available: 0,
denom: sourceChainNativeDenom,
denom
},
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ const OverviewTransferWrapper = (
return asset.symbol !== transferToken.symbol;
})
.map((asset) => ({
available: new BigNumber(asset.amount).toNumber(),
available: new BigNumber(asset.displayAmount).toNumber(),
symbol: asset.symbol,
name: asset.prettyChainName,
denom: asset.denom,
Expand Down
28 changes: 16 additions & 12 deletions examples/asset-list/components/asset-list/RowTransferModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,25 +66,30 @@ const TransferModalBody = (

const { balance, isLoading: isLoadingBalance } = useBalance(
sourceChainName,
isDeposit
isDeposit,
transferInfo.token.symbol
);

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

const availableAmount = useMemo(() => {
if (!isDeposit) return transferToken.priceDisplayAmount ?? 0;
if (isLoading) return 0;
if (!isDeposit) return transferToken.available ?? 0;
if (isLoadingBalance) return 0;

console.log('transferInfo.token', transferInfo.token)

return new BigNumber(
convRawToDispAmount(transferToken.symbol, balance?.amount || '0')
convRawToDispAmount(transferInfo.token.symbol, balance?.amount || '0')
).toNumber();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [isDeposit, isLoading, transferToken]);
}, [isDeposit, isLoading, transferToken.symbol, balance?.amount, transferInfo.token.symbol,
isLoadingBalance
]);

const dollarValue = new BigNumber(inputValue)
.multipliedBy(prices[symbolToDenom(transferToken.symbol)])
.decimalPlaces(2)
const dollarValue = new BigNumber(1)
.multipliedBy(prices[symbolToDenom(transferToken.symbol, transferInfo.sourceChainName)])
.decimalPlaces(6)
.toNumber();

useEffect(() => {
Expand Down Expand Up @@ -145,7 +150,6 @@ const TransferModalBody = (

const sourceChain = useMemo(() => {
return {
symbol: sourceChainInfo.chain_name.toUpperCase(),
name: sourceChainInfo.pretty_name,
address: sourceAddress ?? '',
imgSrc: getChainLogo(sourceChainName) ?? '',
Expand Down Expand Up @@ -212,7 +216,7 @@ const TransferModalBody = (
return (
<AssetWithdrawTokens
isDropdown={false}
fromSymbol={sourceChain.symbol}
fromSymbol={transferInfo.token.symbol}
fromName={sourceChain.name}
fromAddress={sourceChain.address}
fromImgSrc={sourceChain.imgSrc}
Expand Down Expand Up @@ -246,7 +250,7 @@ const TransferModalBody = (
};

export const RowTransferModal = (props: IProps) => {
const { modalControl } = props;
const { modalControl, transferInfo } = props;
const [inputValue, setInputValue] = useState('');
const [isLoading, setIsLoading] = useState(false);

Expand All @@ -258,7 +262,7 @@ export const RowTransferModal = (props: IProps) => {
return (
<BasicModal
isOpen={modalControl.isOpen}
title="Deposit"
title={transferInfo.type}
onClose={() => closeModal()}
>
<TransferModalBody
Expand Down
2 changes: 1 addition & 1 deletion examples/asset-list/components/common/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const Layout = ({ children }: { children?: React.ReactNode }) => {
}}
>
<Head>
<title>Create Cosmos App</title>
<title>Asset List - Create Cosmos App</title>
<meta name="description" content="Generated by create cosmos app" />
<link rel="icon" href="/favicon.ico" />
</Head>
Expand Down
6 changes: 3 additions & 3 deletions examples/asset-list/hooks/queries/useAssets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@ export const useAssets = (chainName: string) => {

const { allBalances, prices, topTokens } = queriesData;

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

const emptyBalances: Coin[] = ibcAssets
.filter(({ base }) => {
const notInBalances = !nativeAndIbcBalances.find(
const notInBalances = !nativeAndIbcBalances?.find(
({ denom }) => denom === base
);
return notInBalances && prices[base];
Expand All @@ -96,7 +96,7 @@ export const useAssets = (chainName: string) => {
})
.map((asset) => ({ denom: asset.base, amount: '0' }));

const finalAssets = [...nativeAndIbcBalances, ...emptyBalances]
const finalAssets = [...(nativeAndIbcBalances ?? []), ...emptyBalances]
.map(({ amount, denom }) => {
const asset = getAssetByDenom(denom);
const symbol = denomToSymbol(denom);
Expand Down
17 changes: 13 additions & 4 deletions examples/asset-list/hooks/queries/useBalance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,17 @@ import { UseQueryResult } from '@tanstack/react-query';
import { useEffect } from 'react';
import { useQueryHooks } from './useQueryHooks';

export const useBalance = (chainName: string, enabled: boolean = true) => {
export const useBalance = (chainName: string, enabled: boolean = true,
displayDenom?: string
) => {
const { address, assets } = useChain(chainName);
let denom = assets?.assets[0].base!;
for (const asset of assets?.assets || []) {
if (asset.display.toLowerCase() === displayDenom?.toLowerCase()) {
denom = asset.base;
break;
}
}

const { cosmosQuery, isReady, isFetching } = useQueryHooks(
chainName,
Expand All @@ -15,7 +24,7 @@ export const useBalance = (chainName: string, enabled: boolean = true) => {
const balanceQuery: UseQueryResult<Coin> =
cosmosQuery.bank.v1beta1.useBalance({
request: {
denom: assets!.assets[0]!.base,
denom,
address: address || '',
},
options: {
Expand All @@ -26,13 +35,13 @@ export const useBalance = (chainName: string, enabled: boolean = true) => {

useEffect(() => {
return () => {
balanceQuery.remove();
balanceQuery.remove()
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

return {
balance: balanceQuery.data,
isLoading: isFetching || balanceQuery.isFetching,
isLoading: isFetching // || !!balanceQueries.find(item => item.isFetching),
};
};
20 changes: 17 additions & 3 deletions examples/asset-list/hooks/useChainUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,14 @@ export const useChainUtils = (chainName: string) => {
return symbol;
};

const symbolToDenom = (symbol: CoinSymbol): CoinDenom => {
const asset = allAssets.find((asset) => asset.symbol === symbol);
const symbolToDenom = (symbol: CoinSymbol, chainName?: string): CoinDenom => {
const asset = allAssets.find((asset) => (
asset.symbol === symbol
&& (
!chainName
|| asset.traces?.[0].counterparty.chain_name.toLowerCase() === chainName.toLowerCase()
)
));
const base = asset?.base;
if (!base) {
return symbol;
Expand Down Expand Up @@ -85,7 +91,7 @@ export const useChainUtils = (chainName: string) => {
}
const asset = ibcAssets.find((asset) => asset.base === ibcDenom);
const ibcChainName = asset?.traces?.[0].counterparty.chain_name;
if (!ibcChainName) throw Error('chainName not found: ' + ibcDenom);
if (!ibcChainName) throw Error('chainName not found for ibcDenom: ' + ibcDenom);
return ibcChainName;
};

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

const getDenomBySymbolAndChain = (chainName: ChainName, symbol: string) => {
const chainRecord = getChainRecord(chainName);
const denom = chainRecord.assetList?.assets.find((asset) => asset.symbol === symbol)?.base;
if (!denom) throw Error('denom not found');
return denom;
};

const getIbcInfo = (fromChainName: string, toChainName: string) => {
let flipped = false;

Expand Down Expand Up @@ -156,5 +169,6 @@ export const useChainUtils = (chainName: string) => {
getNativeDenom,
getIbcInfo,
getExponentByDenom,
getDenomBySymbolAndChain
};
};
2 changes: 1 addition & 1 deletion examples/asset-list/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"@cosmos-kit/react": "2.17.0",
"@emotion/react": "11.10.6",
"@emotion/styled": "11.10.6",
"@interchain-ui/react": "1.23.22",
"@interchain-ui/react": "1.23.29",
"@interchain-ui/react-no-ssr": "^0.1.6",
"@tanstack/react-query": "4.32.0",
"@uidotdev/usehooks": "2.4.1",
Expand Down
3 changes: 2 additions & 1 deletion examples/asset-list/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import '../styles/globals.css';
import '@interchain-ui/react/globalStyles';
import '@interchain-ui/react/styles';

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

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

<Toaster position={'top-right'} closeButton={true} />
<OverlaysManager />
</ThemeProvider>
);
}
Expand Down
Loading