Skip to content

Commit

Permalink
Staking/Unstaking with precision of 18 decimals (#513)
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigoncalves authored Jan 9, 2025
1 parent 137f67a commit a02c18f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/app/user/Stake/StakeInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const StakeInput = ({ onChange, value, symbol = 'RIF', labelText }: Props
value={value}
name="amount-stake"
fullWidth
inputProps={{ decimalScale: 18 }}
/>
)
}
13 changes: 6 additions & 7 deletions src/app/user/Stake/Steps/StepOne.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@ export const StepOne = ({ onGoNext = () => {} }: StepProps) => {
(value: string) => {
if (!value || value === '.') {
onAmountChange('0')
return
}

const regex = /^\d*\.?\d{0,8}$/
if (regex.test(value)) {
onAmountChange(value)
} else {
const regex = /^\d*\.?\d{0,18}$/
if (regex.test(value)) {
onAmountChange(value)
}
}
},
[onAmountChange],
Expand All @@ -45,7 +44,7 @@ export const StepOne = ({ onGoNext = () => {} }: StepProps) => {

// For other percentages, calculate with precision
const rawAmount = Number(balance) * (percentage / 100)
const displayAmount = rawAmount.toFixed(8)
const displayAmount = rawAmount.toString()
onAmountChange(displayAmount)
},
[tokenToSend.balance, onAmountChange],
Expand Down

0 comments on commit a02c18f

Please sign in to comment.