Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

Commit

Permalink
fix: input formatting on send page. fixes #729
Browse files Browse the repository at this point in the history
  • Loading branch information
hstove committed Jan 29, 2021
1 parent c60a564 commit c6ad05e
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion packages/app/src/pages/popup/send.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,32 @@ export const PopupSend: React.FC = () => {
</Text>
<Input
display="block"
type="number"
type="text"
inputMode="numeric"
width="100%"
placeholder="0.0 STX"
min="0"
value={values.amount}
onKeyDown={(event: React.KeyboardEvent<HTMLInputElement>) => {
const { key } = event;
if (key.length > 1) {
return;
}
// no leading zeros
if (key === '0' && event.currentTarget.value.length === 0)
return event.preventDefault();
// only allow decimal if STX
if (key === '.') {
if (selectedAsset?.type !== 'stx') return event.preventDefault();
const hasPeriod = event.currentTarget.value.includes('.');
if (hasPeriod && key === '.') {
return event.preventDefault();
}
}
if (!/^[0-9]|\.+$/.test(key)) {
return event.preventDefault();
}
}}
onChange={handleChange}
name="amount"
/>
Expand Down

0 comments on commit c6ad05e

Please sign in to comment.