Skip to content

Commit

Permalink
updated symbol use in asset.ts (#1060)
Browse files Browse the repository at this point in the history
* updated symbol use in asset.ts

* typo
  • Loading branch information
Thorian1te authored Mar 5, 2024
1 parent 3aec134 commit c71952d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/heavy-tomatoes-lay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@xchainjs/xchain-util': patch
---

Added Dash/ltc/doge symbols to asset utils
24 changes: 21 additions & 3 deletions packages/xchain-util/src/asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,9 @@ export enum AssetCurrencySymbol {
SATOSHI = '⚡',
ETH = 'Ξ',
USD = '$',
DASH = 'Đ',
LTC = 'Ł',
DOGE = 'Ð',
}

/**
Expand All @@ -281,15 +284,21 @@ export enum AssetCurrencySymbol {
* @param {Asset} asset The given asset.
* @returns {string} The currency symbol from the given asset.
*/
export const currencySymbolByAsset = ({ ticker }: Asset) => {
export const currencySymbolByAsset = ({ ticker }: Asset): string => {
switch (true) {
case ticker === 'RUNE':
return AssetCurrencySymbol.RUNE
case ticker === AssetBTC.ticker:
return AssetCurrencySymbol.BTC
case ticker === AssetETH.ticker:
return AssetCurrencySymbol.ETH
case ticker.includes('USD') || ticker.includes('UST'):
case ticker === 'DASH':
return AssetCurrencySymbol.DASH
case ticker === 'LTC':
return AssetCurrencySymbol.LTC
case ticker === 'DOGE':
return AssetCurrencySymbol.DOGE
case ticker.includes('USD'):
return AssetCurrencySymbol.USD
default:
return ticker
Expand Down Expand Up @@ -331,7 +340,7 @@ export const formatAssetAmountCurrency = ({
if (ticker === 'RUNE') return `${AssetCurrencySymbol.RUNE} ${amountFormatted}`
// BTC
let regex = new RegExp(AssetBTC.ticker, 'i')
if (ticker.match(new RegExp(AssetBTC.ticker, 'i'))) {
if (ticker.match(regex)) {
const base = assetToBase(amount)
// format all < ₿ 0.01 in statoshi
if (base.amount().isLessThanOrEqualTo('1000000')) {
Expand All @@ -342,6 +351,15 @@ export const formatAssetAmountCurrency = ({
// ETH
regex = new RegExp(AssetETH.ticker, 'i')
if (ticker.match(regex)) return `${AssetCurrencySymbol.ETH} ${amountFormatted}`
// LTC
regex = new RegExp('LTC', 'i')
if (ticker.match(regex)) return `${AssetCurrencySymbol.LTC} ${amountFormatted}`
// DASH
regex = new RegExp('DASH', 'i')
if (ticker.match(regex)) return `${AssetCurrencySymbol.DASH} ${amountFormatted}`
// DOGE
regex = new RegExp('DOGE', 'i')
if (ticker.match(regex)) return `${AssetCurrencySymbol.DOGE} ${amountFormatted}`
// USD
regex = new RegExp('USD', 'i')
if (ticker.match('USD')) return `${AssetCurrencySymbol.USD} ${amountFormatted}`
Expand Down

0 comments on commit c71952d

Please sign in to comment.