Get displayDenomExponent from chain registry

This commit is contained in:
Simon Warta
2022-08-12 22:07:42 +02:00
parent 5070eb6c74
commit b95d88b10e
2 changed files with 29 additions and 2 deletions
+4 -2
View File
@@ -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
+25
View File
@@ -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;
}