Skip to content

Commit

Permalink
formating on ube balance
Browse files Browse the repository at this point in the history
  • Loading branch information
muhammedea committed Mar 19, 2024
1 parent 521b8ba commit 422a938
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 15 deletions.
30 changes: 16 additions & 14 deletions src/components/Header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -526,20 +526,22 @@ export default function Header() {
UBE
</UBEAmount>
<CardNoise />
<HideSmall>
<UBEAmount active={!!account} style={{ pointerEvents: 'auto' }}>
{account && (
<TYPE.white
style={{
paddingRight: '.4rem',
}}
>
{oldUbeBalanceFormatted}
</TYPE.white>
)}
old-UBE
</UBEAmount>
</HideSmall>
{oldUbeBalance?.greaterThan('0') && (
<HideSmall>
<UBEAmount active={!!account} style={{ pointerEvents: 'auto' }}>
{account && (
<TYPE.white
style={{
paddingRight: '.4rem',
}}
>
{oldUbeBalanceFormatted}
</TYPE.white>
)}
old-UBE
</UBEAmount>
</HideSmall>
)}
</UBEWrapper>
)}

Expand Down
37 changes: 36 additions & 1 deletion src/utils/relevantDigits.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,45 @@
import { TokenAmount } from '@ubeswap/sdk'
import { Fraction, TokenAmount } from '@ubeswap/sdk'

function substringDigit(input: string) {
switch (input) {
case '0':
return '₀'
case '1':
return '₁'
case '2':
return '₂'
case '3':
return '₃'
case '4':
return '₄'
case '5':
return '₅'
case '6':
return '₆'
case '7':
return '₇'
case '8':
return '₈'
case '9':
return '₉'
default:
return ''
}
}

export function relevantDigits(tokenAmount?: TokenAmount) {
if (!tokenAmount || tokenAmount.equalTo('0')) {
return '0.0'
}

if (tokenAmount.lessThan(new Fraction('1', '100'))) {
const text = tokenAmount.toSignificant(1)
return text.replace(/\.([0]{3,})/, function (m: string, g1: string) {
const length = g1.length
return '.0' + (length + '').replace(/\d/g, substringDigit)
})
}

if (tokenAmount.lessThan('1')) {
return tokenAmount.toSignificant(2)
}
Expand Down

0 comments on commit 422a938

Please sign in to comment.