From b8a7e5ee7079f324d1256bdf61e0f0c4827082aa Mon Sep 17 00:00:00 2001 From: evilpeach Date: Mon, 16 Oct 2023 15:24:13 +0700 Subject: [PATCH] fix: use native tokens in select funds --- CHANGELOG.md | 1 + src/lib/app-provider/hooks/useBaseApiRoute.ts | 3 --- src/lib/components/fund/selectFund.tsx | 2 +- src/lib/services/assetService.ts | 24 +++++++++---------- 4 files changed, 13 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ae6ad1aa..62d3b5aa7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -113,6 +113,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Bug fixes +- [#570](https://github.com/alleslabs/celatone-frontend/pull/570) Use native tokens in attached funds - [#567](https://github.com/alleslabs/celatone-frontend/pull/567) Fix attached funds in code snippet - [#539](https://github.com/alleslabs/celatone-frontend/pull/539) Fix JSON schema upload text - [#527](https://github.com/alleslabs/celatone-frontend/pull/527) Fix ellipsis explorer link diff --git a/src/lib/app-provider/hooks/useBaseApiRoute.ts b/src/lib/app-provider/hooks/useBaseApiRoute.ts index b9cf4862e..d0f1454e1 100644 --- a/src/lib/app-provider/hooks/useBaseApiRoute.ts +++ b/src/lib/app-provider/hooks/useBaseApiRoute.ts @@ -13,7 +13,6 @@ export const useBaseApiRoute = ( | "rest" | "icns_names" | "icns_address" - | "native_tokens" | "cosmwasm" ): string => { const { @@ -49,8 +48,6 @@ export const useBaseApiRoute = ( return `${api}/icns/names`; case "icns_address": return `${api}/icns/address`; - case "native_tokens": - return `${api}/native-assets/${chain}/${currentChainId}`; case "cosmwasm": return `${api}/cosmwasm/${chain}/${currentChainId}`; default: diff --git a/src/lib/components/fund/selectFund.tsx b/src/lib/components/fund/selectFund.tsx index 71297fb45..aea438691 100644 --- a/src/lib/components/fund/selectFund.tsx +++ b/src/lib/components/fund/selectFund.tsx @@ -26,7 +26,7 @@ export const SelectFund = ({ assetsSelect, labelBgColor, }: SelectFundProps) => { - const { data: assetInfos = [] } = useAssetInfoList(); + const { data: assetInfos = [] } = useAssetInfoList({ assetType: "native" }); const { fields, append, remove } = useFieldArray({ control, name: ASSETS_SELECT, diff --git a/src/lib/services/assetService.ts b/src/lib/services/assetService.ts index 7e031a115..60e9f7994 100644 --- a/src/lib/services/assetService.ts +++ b/src/lib/services/assetService.ts @@ -34,23 +34,21 @@ export const useAssetInfos = ({ }; }; -export const useAssetInfoList = () => { - const assetsApiRoute = useBaseApiRoute("assets"); - return useQuery( - [CELATONE_QUERY_KEYS.ASSET_INFO_LIST, assetsApiRoute], - async () => getAssetInfosWithoutPricesPath(assetsApiRoute), - { enabled: Boolean(assetsApiRoute), retry: 1, refetchOnWindowFocus: false } +export const useAssetInfoList = ({ + assetType, +}: { + assetType: "all" | "native" | "cw20"; +}) => { + const assetsApiRoute = useBaseApiRoute("assets").concat( + assetType !== "all" ? `/type/${assetType}` : "" ); -}; - -export const useNativeTokensInfo = () => { - const nativeTokensApiRoute = useBaseApiRoute("native_tokens"); return useQuery( - [CELATONE_QUERY_KEYS.NATIVE_TOKENS_INFO, nativeTokensApiRoute], - async () => getAssetInfosWithoutPricesPath(nativeTokensApiRoute), + [CELATONE_QUERY_KEYS.ASSET_INFO_LIST, assetsApiRoute], + async () => getAssetInfosWithoutPricesPath(assetsApiRoute), { - enabled: Boolean(nativeTokensApiRoute), + enabled: Boolean(assetsApiRoute), + retry: 1, refetchOnWindowFocus: false, } );