Skip to content

Commit

Permalink
Merge pull request #6 from ixofoundation/dev
Browse files Browse the repository at this point in the history
fix: fixing convertCurrencyToTokenAsset coinMinimalDenom undefined bu…
  • Loading branch information
Michael-Ixo authored Nov 6, 2023
2 parents 15f614b + 80a2db5 commit 886adf5
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 34 deletions.
2 changes: 1 addition & 1 deletion docs/functions/getActiveRpcFromChainName.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ <h5>chainNetwork: <span class="tsd-signature-type">ChainNetwork</span><span clas
</div></li></ul></div>
<h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">Promise</span><span class="tsd-signature-symbol">&lt;</span><span class="tsd-signature-type">string</span><span class="tsd-signature-symbol">&gt;</span></h4><aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/ixofoundation/cosmos-chain-resolver/blob/a7c54fe/src/chain.ts#L73">chain.ts:73</a></li></ul></aside></li></ul></section></div>
<li>Defined in <a href="https://github.com/ixofoundation/cosmos-chain-resolver/blob/147fb56/src/chain.ts#L73">chain.ts:73</a></li></ul></aside></li></ul></section></div>
<div class="col-4 col-menu menu-sticky-wrap menu-highlight">
<div class="tsd-navigation settings">
<details class="tsd-index-accordion"><summary class="tsd-accordion-summary">
Expand Down
2 changes: 1 addition & 1 deletion docs/functions/getActiveRpcFromRegistryChainInfo.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ <h5>chainInfo: <span class="tsd-signature-type">RegistryChainInfo</span></h5>
</div></li></ul></div>
<h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">Promise</span><span class="tsd-signature-symbol">&lt;</span><span class="tsd-signature-type">string</span><span class="tsd-signature-symbol">&gt;</span></h4><aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/ixofoundation/cosmos-chain-resolver/blob/a7c54fe/src/chain.ts#L49">chain.ts:49</a></li></ul></aside></li></ul></section></div>
<li>Defined in <a href="https://github.com/ixofoundation/cosmos-chain-resolver/blob/147fb56/src/chain.ts#L49">chain.ts:49</a></li></ul></aside></li></ul></section></div>
<div class="col-4 col-menu menu-sticky-wrap menu-highlight">
<div class="tsd-navigation settings">
<details class="tsd-index-accordion"><summary class="tsd-accordion-summary">
Expand Down
2 changes: 1 addition & 1 deletion docs/functions/getChainExplorer.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ <h5><code class="tsd-tag ts-flagOptional">Optional</code> chainExplorers: <span
</div></li></ul></div>
<h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">KeplrChainExplorer</span></h4><aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/ixofoundation/cosmos-chain-resolver/blob/a7c54fe/src/chain.ts#L87">chain.ts:87</a></li></ul></aside></li></ul></section></div>
<li>Defined in <a href="https://github.com/ixofoundation/cosmos-chain-resolver/blob/147fb56/src/chain.ts#L87">chain.ts:87</a></li></ul></aside></li></ul></section></div>
<div class="col-4 col-menu menu-sticky-wrap menu-highlight">
<div class="tsd-navigation settings">
<details class="tsd-index-accordion"><summary class="tsd-accordion-summary">
Expand Down
2 changes: 1 addition & 1 deletion docs/functions/getChainExplorerAsync.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ <h5>chainNetwork: <span class="tsd-signature-type">ChainNetwork</span></h5>
</div></li></ul></div>
<h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">Promise</span><span class="tsd-signature-symbol">&lt;</span><span class="tsd-signature-type">KeplrChainExplorer</span><span class="tsd-signature-symbol">&gt;</span></h4><aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/ixofoundation/cosmos-chain-resolver/blob/a7c54fe/src/chain.ts#L126">chain.ts:126</a></li></ul></aside></li></ul></section></div>
<li>Defined in <a href="https://github.com/ixofoundation/cosmos-chain-resolver/blob/147fb56/src/chain.ts#L126">chain.ts:126</a></li></ul></aside></li></ul></section></div>
<div class="col-4 col-menu menu-sticky-wrap menu-highlight">
<div class="tsd-navigation settings">
<details class="tsd-index-accordion"><summary class="tsd-accordion-summary">
Expand Down
2 changes: 1 addition & 1 deletion docs/functions/getChainNameFromAddressPrefix.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ <h5>prefix: <span class="tsd-signature-type">string</span></h5>
</div></li></ul></div>
<h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">string</span></h4><aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/ixofoundation/cosmos-chain-resolver/blob/a7c54fe/src/chain.ts#L263">chain.ts:263</a></li></ul></aside></li></ul></section></div>
<li>Defined in <a href="https://github.com/ixofoundation/cosmos-chain-resolver/blob/147fb56/src/chain.ts#L263">chain.ts:263</a></li></ul></aside></li></ul></section></div>
<div class="col-4 col-menu menu-sticky-wrap menu-highlight">
<div class="tsd-navigation settings">
<details class="tsd-index-accordion"><summary class="tsd-accordion-summary">
Expand Down
2 changes: 1 addition & 1 deletion docs/functions/getKeplrChainInfo.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ <h5>chainNetwork: <span class="tsd-signature-type">ChainNetwork</span><span clas
</div></li></ul></div>
<h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">Promise</span><span class="tsd-signature-symbol">&lt;</span><span class="tsd-signature-type">KeplrChainInfo</span><span class="tsd-signature-symbol">&gt;</span></h4><aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/ixofoundation/cosmos-chain-resolver/blob/a7c54fe/src/chain.ts#L228">chain.ts:228</a></li></ul></aside></li></ul></section></div>
<li>Defined in <a href="https://github.com/ixofoundation/cosmos-chain-resolver/blob/147fb56/src/chain.ts#L228">chain.ts:228</a></li></ul></aside></li></ul></section></div>
<div class="col-4 col-menu menu-sticky-wrap menu-highlight">
<div class="tsd-navigation settings">
<details class="tsd-index-accordion"><summary class="tsd-accordion-summary">
Expand Down
2 changes: 1 addition & 1 deletion docs/functions/getKeplrChainInfoFromRegistryChainInfo.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ <h5>chainInfo: <span class="tsd-signature-type">RegistryChainInfo</span></h5>
</div></li></ul></div>
<h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">Promise</span><span class="tsd-signature-symbol">&lt;</span><span class="tsd-signature-type">KeplrChainInfo</span><span class="tsd-signature-symbol">&gt;</span></h4><aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/ixofoundation/cosmos-chain-resolver/blob/a7c54fe/src/chain.ts#L198">chain.ts:198</a></li></ul></aside></li></ul></section></div>
<li>Defined in <a href="https://github.com/ixofoundation/cosmos-chain-resolver/blob/147fb56/src/chain.ts#L198">chain.ts:198</a></li></ul></aside></li></ul></section></div>
<div class="col-4 col-menu menu-sticky-wrap menu-highlight">
<div class="tsd-navigation settings">
<details class="tsd-index-accordion"><summary class="tsd-accordion-summary">
Expand Down
2 changes: 1 addition & 1 deletion docs/functions/getRegistryChainInfo.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ <h5>chainNetwork: <span class="tsd-signature-type">ChainNetwork</span><span clas
</div></li></ul></div>
<h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">Promise</span><span class="tsd-signature-symbol">&lt;</span><span class="tsd-signature-type">RegistryChainInfo</span><span class="tsd-signature-symbol">&gt;</span></h4><aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/ixofoundation/cosmos-chain-resolver/blob/a7c54fe/src/chain.ts#L30">chain.ts:30</a></li></ul></aside></li></ul></section></div>
<li>Defined in <a href="https://github.com/ixofoundation/cosmos-chain-resolver/blob/147fb56/src/chain.ts#L30">chain.ts:30</a></li></ul></aside></li></ul></section></div>
<div class="col-4 col-menu menu-sticky-wrap menu-highlight">
<div class="tsd-navigation settings">
<details class="tsd-index-accordion"><summary class="tsd-accordion-summary">
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ixo/cosmos-chain-resolver",
"version": "0.0.4",
"version": "0.0.5",
"description": "An SDK to fetch and filter chain information",
"author": "ixo",
"homepage": "https://github.com/ixofoundation/cosmos-chain-resolver#readme",
Expand Down
33 changes: 8 additions & 25 deletions src/utils/currency.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,19 @@
import { KeplrChainInfo } from '../types/chain';
import { TokenAsset } from '../types/currency';

const convertCurrencyToTokenAsset = (
currency: TokenAsset,
stakeCurrency: TokenAsset,
feeCurrencies: TokenAsset[] = [],
coinImageUrl?: string,
): TokenAsset => {
const denomLowerCased = currency.coinMinimalDenom.toLowerCase() ?? '';
const isStakeCurrency = stakeCurrency.coinMinimalDenom.toLowerCase() === denomLowerCased;
const isFeeCurrency = !!feeCurrencies?.find(
(feeCur: TokenAsset) => feeCur.coinMinimalDenom.toLowerCase() === denomLowerCased,
);
const convertCurrencyToTokenAsset = (currency: TokenAsset, stakeCurrency: TokenAsset, feeCurrencies: TokenAsset[] = [], coinImageUrl?: string): TokenAsset | undefined => {
if (!currency) return undefined;
const denomLowerCased = currency?.coinMinimalDenom?.toLowerCase() ?? '';
const isStakeCurrency = stakeCurrency?.coinMinimalDenom?.toLowerCase() === denomLowerCased;
const isFeeCurrency = !!feeCurrencies?.find((feeCur: TokenAsset) => feeCur?.coinMinimalDenom?.toLowerCase() === denomLowerCased);
const result = { ...currency, isStakeCurrency, isFeeCurrency };
if (isStakeCurrency && isFeeCurrency && coinImageUrl?.length) result.coinImageUrl = coinImageUrl;
return result;
};

export const prepareKeplrChainInfoTokenAssets = (chainInfo: KeplrChainInfo): KeplrChainInfo => ({
...chainInfo,
currencies:
chainInfo.currencies?.map((cur) =>
convertCurrencyToTokenAsset(cur, chainInfo.stakeCurrency, chainInfo.feeCurrencies, chainInfo.chainSymbolImageUrl),
) ?? [],
stakeCurrency: convertCurrencyToTokenAsset(
chainInfo.stakeCurrency,
chainInfo.stakeCurrency,
chainInfo.feeCurrencies,
chainInfo.chainSymbolImageUrl,
),
feeCurrencies:
chainInfo.feeCurrencies?.map((cur) =>
convertCurrencyToTokenAsset(cur, chainInfo.stakeCurrency, chainInfo.feeCurrencies, chainInfo.chainSymbolImageUrl),
) ?? [],
currencies: chainInfo.currencies?.map(cur => convertCurrencyToTokenAsset(cur, chainInfo.stakeCurrency, chainInfo.feeCurrencies, chainInfo.chainSymbolImageUrl)) ?? [],
stakeCurrency: convertCurrencyToTokenAsset(chainInfo?.stakeCurrency, chainInfo?.stakeCurrency, chainInfo?.feeCurrencies, chainInfo?.chainSymbolImageUrl),
feeCurrencies: chainInfo.feeCurrencies?.map(cur => convertCurrencyToTokenAsset(cur, chainInfo?.stakeCurrency, chainInfo?.feeCurrencies, chainInfo?.chainSymbolImageUrl)) ?? [],
});

0 comments on commit 886adf5

Please sign in to comment.