feat: explorer API, wallet, CCIP scripts, and config refresh
- Backend REST/gateway/track routes, analytics, Blockscout proxy paths. - Frontend wallet and liquidity surfaces; MetaMask token list alignment. - Deployment docs, verification scripts, address inventory updates. Check: go build ./... under backend/ (pass). Made-with: Cursor
This commit is contained in:
30
frontend/src/utils/format.ts
Normal file
30
frontend/src/utils/format.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
const WEI_DECIMALS = 18n
|
||||
|
||||
export function formatWeiAsEth(value: string, fractionDigits = 4): string {
|
||||
try {
|
||||
const normalizedDigits = Math.max(0, Math.min(18, fractionDigits))
|
||||
const wei = BigInt(value)
|
||||
const divisor = 10n ** WEI_DECIMALS
|
||||
const whole = wei / divisor
|
||||
const fraction = wei % divisor
|
||||
|
||||
if (normalizedDigits === 0) {
|
||||
return `${whole.toString()} ETH`
|
||||
}
|
||||
|
||||
const scale = 10n ** (WEI_DECIMALS - BigInt(normalizedDigits))
|
||||
const truncatedFraction = fraction / scale
|
||||
const paddedFraction = truncatedFraction
|
||||
.toString()
|
||||
.padStart(normalizedDigits, '0')
|
||||
.replace(/0+$/, '')
|
||||
|
||||
if (!paddedFraction) {
|
||||
return `${whole.toString()} ETH`
|
||||
}
|
||||
|
||||
return `${whole.toString()}.${paddedFraction} ETH`
|
||||
} catch {
|
||||
return '0 ETH'
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user