-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from ixofoundation/dev
fix: fixing convertCurrencyToTokenAsset coinMinimalDenom undefined bu…
- Loading branch information
Showing
10 changed files
with
17 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) ?? [], | ||
}); |