diff --git a/components/chainSelect/ChainSelect.tsx b/components/chainSelect/ChainSelect.tsx index 7ea3e7a..0882bf1 100644 --- a/components/chainSelect/ChainSelect.tsx +++ b/components/chainSelect/ChainSelect.tsx @@ -9,6 +9,7 @@ import { useAppContext } from "../../context/AppContext"; import Select from "../inputs/Select"; import StackableContainer from "../layout/StackableContainer"; import { assert } from "@cosmjs/utils"; +import { ChainRegistryAsset } from "./chainregistry"; interface ChainOption { label: string; @@ -141,11 +142,12 @@ const ChainSelect = () => { setChainError("Multiple token denoms available, enter manually"); setShowSettings(true); } else { - const asset = assetData.assets[0]; + const asset: ChainRegistryAsset = assetData.assets[0]; denom = asset.base; displayDenom = asset.symbol; gasPrice = `0.03${asset.base}`; - displayDenomExponent = 6; // TODO: determine dynamically + const displayUnit = asset.denom_units.find((u) => u.denom == asset.display); + displayDenomExponent = displayUnit?.exponent ?? 6; } // test client connection diff --git a/components/chainSelect/chainregistry.ts b/components/chainSelect/chainregistry.ts new file mode 100644 index 0000000..ef1aa4a --- /dev/null +++ b/components/chainSelect/chainregistry.ts @@ -0,0 +1,25 @@ +/** + * See https://github.com/cosmos/chain-registry/blob/1e9ecde770951cab90f0853a624411d79af90b83/provenance/assetlist.json#L8-L12 + */ +export interface ChainRegistryDemonUnit { + denom: string; + exponent: number; + aliases: string[]; +} + +/** + * See https://github.com/cosmos/chain-registry/blob/1e9ecde770951cab90f0853a624411d79af90b83/provenance/assetlist.json#L5-L28 + */ +export interface ChainRegistryAsset { + description: string; + denom_units: ChainRegistryDemonUnit[]; + base: string; + name: string; + display: string; + symbol: string; + logo_URIs: { + png: string; + svg: string; + }; + coingecko_id: string; +}