Skip to content

Commit

Permalink
fix(ui): validate decimal places in add/remove stake modals (#208)
Browse files Browse the repository at this point in the history
  • Loading branch information
drichar authored Jun 2, 2024
1 parent 24ec13d commit a6f9b14
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
9 changes: 9 additions & 0 deletions ui/src/components/AddStakeModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,15 @@ export function AddStakeModal({
.refine((val) => !isNaN(Number(val)) && parseFloat(val) > 0, {
message: 'Invalid amount',
})
.refine(
(val) => {
const match = val.match(/^\d+(\.\d{1,6})?$/)
return match !== null
},
{
message: 'Cannot have more than 6 decimal places',
},
)
.superRefine((val, ctx) => {
const algoAmount = parseFloat(val)
const amountToStake = AlgoAmount.Algos(algoAmount).microAlgos
Expand Down
9 changes: 9 additions & 0 deletions ui/src/components/UnstakeModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,15 @@ export function UnstakeModal({ validator, setValidator, stakesByValidator }: Uns
.refine((val) => !isNaN(Number(val)) && parseFloat(val) > 0, {
message: 'Invalid amount',
})
.refine(
(val) => {
const match = val.match(/^\d+(\.\d{1,6})?$/)
return match !== null
},
{
message: 'Cannot have more than 6 decimal places',
},
)
.superRefine((val, ctx) => {
const algoAmount = parseFloat(val)
const amountToUnstake = AlgoAmount.Algos(algoAmount).microAlgos
Expand Down

0 comments on commit a6f9b14

Please sign in to comment.