Skip to content

Commit

Permalink
chore: add formatter helper functions
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasRalee committed Jul 15, 2024
1 parent 5fe757e commit 14d72d5
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions layer/utils/formatter.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import {
BigNumber,
BigNumberInBase,
BigNumberInWei
BigNumberInWei,
BigNumberInBase
} from '@injectivelabs/utils'
import { Coin } from '@injectivelabs/sdk-ts'
import { TimeDuration } from './../types'

export const sharedToBalanceInWei = ({
Expand Down Expand Up @@ -152,3 +153,24 @@ export const sharedGetTensMultiplier = (number: number | string): number => {

return zerosInTheNumber.length
}

export const sharedEllipsisFormatText = (text: string, length = 20): string => {
return text.length > length
? `${text.slice(0, length)}...${text.slice(
text.length - length,
text.length
)}`
: text
}

export const sharedCoinStringToCoins = (coinString: string): Coin[] => {
return coinString.split(',').map((coin) => {
// is used to remove any empty strings that might result from the split operation.
const [amount, denom] = coin.split(/(\d+)/).filter(Boolean)

return {
denom,
amount
}
})
}

0 comments on commit 14d72d5

Please sign in to comment.