Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: SMR token amount formatting #3988

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 20 additions & 19 deletions packages/shared/lib/participation/staking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,31 +120,32 @@ export function isAirdropAvailable(airdrop: StakingAirdrop): boolean {
* @returns {string}
*/
export const formatStakingAirdropReward = (airdrop: StakingAirdrop, amount: number, decimalPlaces: number): string => {
if (!amount) {
amount = 0
}

if (!decimalPlaces) {
decimalPlaces = 0
}

const decimalSeparator = getDecimalSeparator(get(activeProfile)?.settings?.currency)
const thousandthSeparator = decimalSeparator === '.' ? ',' : '.'

let reward: string
switch (airdrop) {
case StakingAirdrop.Assembly: {
decimalPlaces = clamp(decimalPlaces, 0, 6)
decimalPlaces = clamp(decimalPlaces, 0, 6)

const [integer, float] = (amount / 1_000_000).toFixed(decimalPlaces).split('.')
reward = `${delineateNumber(integer, thousandthSeparator)}${
Number(float) > 0 ? decimalSeparator + float : ''
}`
const [integer, float] = (amount / 1_000_000).toFixed(decimalPlaces).split('.')

break
}
case StakingAirdrop.Shimmer: {
reward = delineateNumber(String(Math.floor(amount)), thousandthSeparator)
break
}
default:
reward = '0'
break
let reward: string
const shouldModifyForGlowUnits = Number(integer) <= 0 && airdrop === StakingAirdrop.Shimmer
if (shouldModifyForGlowUnits) {
reward = `${delineateNumber(float, thousandthSeparator)}` ?? '0'
return `${reward} glow`
} else {
reward =
`${delineateNumber(integer, thousandthSeparator)}${Number(float) > 0 ? decimalSeparator + float : ''}` ??
'0'
return `${reward} ${STAKING_AIRDROP_TOKENS[airdrop]}`
}

return `${reward} ${STAKING_AIRDROP_TOKENS[airdrop]}`
}

/**
Expand Down