Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: asset assetlist #1245

Merged
merged 2 commits into from
Feb 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Features

- [#1245](https://github.com/alleslabs/celatone-frontend/pull/1245) Support assets from assetlist in chain config
- [#1244](https://github.com/alleslabs/celatone-frontend/pull/1244) Add EVM contract verify alert info to both Solidity and Vyper upload file(s) and contract code
- [#1240](https://github.com/alleslabs/celatone-frontend/pull/1240) Update social media handle and naming convention from Celatone to Scan
- [#1232](https://github.com/alleslabs/celatone-frontend/pull/1232) Support EVM verification with multiparts and standard JSON input for both Solidity and Vyper
Expand Down
47 changes: 43 additions & 4 deletions src/lib/services/assetService.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,58 @@
import { useQuery } from "@tanstack/react-query";
import { pickBy } from "lodash";

import { useCelatoneApp } from "lib/app-provider";
import { CELATONE_QUERY_KEYS } from "lib/app-provider/env";
import { useBaseApiRoute } from "lib/app-provider/hooks/useBaseApiRoute";
import { getAssetInfos } from "lib/services/asset";
import type { AssetInfos } from "lib/types";
import type { AssetInfo, AssetInfos, Option } from "lib/types";

export const useAssetInfos = ({ withPrices }: { withPrices: boolean }) => {
const assetsApiRoute = useBaseApiRoute("assets");

const {
chainConfig: { registry },
} = useCelatoneApp();
const registryAssets = registry?.assets ?? [];

return useQuery<AssetInfos>(
[CELATONE_QUERY_KEYS.ASSET_INFOS, assetsApiRoute, withPrices],
async () =>
getAssetInfos(assetsApiRoute, withPrices).then((assets) =>
assets.reduce((acc, asset) => ({ ...acc, [asset.id]: asset }), {})
),
getAssetInfos(assetsApiRoute, withPrices).then((assets) => {
const assetsMap = assets.reduce<AssetInfos>(
(acc, asset) => ({ ...acc, [asset.id]: asset }),
{}
);

registryAssets.forEach((registryAsset) => {
const asset: Option<AssetInfo> = assetsMap[registryAsset.base];
assetsMap[registryAsset.base] = {
coingecko: registryAsset.coingecko_id ?? asset?.coingecko ?? "",
description: registryAsset.description ?? asset?.description ?? "",
id: registryAsset.base,
logo:
registryAsset.logo_URIs?.svg ??
registryAsset.logo_URIs?.png ??
asset?.logo ??
"",
name: registryAsset.name,
precision:
registryAsset.denom_units.find(
(unit) => unit.denom === registryAsset.symbol
)?.exponent ??
asset?.precision ??
0,
price: asset?.price ?? 0,
slugs: registryAsset.coingecko_id
? [registryAsset.coingecko_id]
: (asset?.slugs ?? []),
symbol: registryAsset.symbol,
type: asset?.type ?? "native",
};
});

return assetsMap;
}),
{ enabled: Boolean(assetsApiRoute), retry: 1, refetchOnWindowFocus: false }
);
};
Expand Down