Skip to content

Commit

Permalink
Pass all token numbers as strings
Browse files Browse the repository at this point in the history
These numbers may be well beyond JavaScript's number max.

Signed-off-by: Andrew Richardson <[email protected]>
  • Loading branch information
awrichar committed Apr 20, 2022
1 parent e3650f4 commit a1b562d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 21 deletions.
2 changes: 1 addition & 1 deletion server/src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export class TokenMint {
@IsString()
pool: string;

@IsString()
@IsNumberString()
amount: string;
}

Expand Down
10 changes: 4 additions & 6 deletions ui/src/components/Forms/BurnForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ export const BurnForm: React.FC = () => {

const [tokenPools, setTokenPools] = useState<ITokenPool[]>([]);
const [pool, setPool] = useState<ITokenPool>();
const [amount, setAmount] = useState<number>(0);
const [amount, setAmount] = useState<string>('0');
const [tokenIndex, setTokenIndex] = useState<string | null>('');
const [refresh, setRefresh] = useState<number>(0);
const [tokenBalance, setTokenBalance] = useState<number>(0);
const [tokenBalance, setTokenBalance] = useState<string>('0');

useEffect(() => {
if (activeForm !== TUTORIALS.BURN) return;
Expand Down Expand Up @@ -80,7 +80,7 @@ export const BurnForm: React.FC = () => {

useEffect(() => {
if (!isFungible()) {
setAmount(1);
setAmount('1');
}
}, [pool, amount]);

Expand All @@ -96,9 +96,7 @@ export const BurnForm: React.FC = () => {
};

const handleAmountChange = (event: React.ChangeEvent<HTMLInputElement>) => {
if (parseInt(event.target.value)) {
setAmount(parseInt(event.target.value));
}
setAmount(event.target.value);
};

return (
Expand Down
10 changes: 4 additions & 6 deletions ui/src/components/Forms/MintForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@ export const MintForm: React.FC = () => {
const { t } = useTranslation();

const [tokenPools, setTokenPools] = useState<ITokenPool[]>([]);
const [tokenBalance, setTokenBalance] = useState<number>(0);
const [tokenBalance, setTokenBalance] = useState<string>('0');

const [message] = useState<string | object | undefined>(
DEFAULT_MESSAGE_STRING
);

const [pool, setPool] = useState<ITokenPool>();
const [amount, setAmount] = useState<number>(1);
const [amount, setAmount] = useState<string>('1');
const [refresh, setRefresh] = useState<number>(0);

useEffect(() => {
if (activeForm !== TUTORIALS.MINT) {
setAmount(1);
setAmount('1');
return;
}
setPayloadMissingFields(!amount || !pool);
Expand Down Expand Up @@ -101,9 +101,7 @@ export const MintForm: React.FC = () => {
}, [pool, refresh]);

const handleAmountChange = (event: React.ChangeEvent<HTMLInputElement>) => {
if (parseInt(event.target.value)) {
setAmount(parseInt(event.target.value));
}
setAmount(event.target.value);
};

return (
Expand Down
14 changes: 6 additions & 8 deletions ui/src/components/Forms/TransferForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ export const TransferForm: React.FC = () => {

const [tokenPools, setTokenPools] = useState<ITokenPool[]>([]);
const [pool, setPool] = useState<ITokenPool>();
const [amount, setAmount] = useState<number>(1);
const [amount, setAmount] = useState<string>('1');
const [tokenVerifiers, setTokenVerifiers] = useState<IVerifiers[]>([]);
const [recipient, setRecipient] = useState<string>('');
const [tokenIndex, setTokenIndex] = useState<string | null>('');
const [tokenBalance, setTokenBalance] = useState<number>(0);
const [refresh, setRefresh] = useState<number>(0);
const [tokenBalance, setTokenBalance] = useState<string>('0');
const [refresh, setRefresh] = useState<string>('0');

useEffect(() => {
if (activeForm !== TUTORIALS.TRANSFER) {
setAmount(1);
setAmount('1');
return;
}
setPayloadMissingFields(
Expand Down Expand Up @@ -80,7 +80,7 @@ export const TransferForm: React.FC = () => {

useEffect(() => {
if (!isFungible()) {
setAmount(1);
setAmount('1');
}
}, [pool, amount]);

Expand Down Expand Up @@ -112,9 +112,7 @@ export const TransferForm: React.FC = () => {
};

const handleAmountChange = (event: React.ChangeEvent<HTMLInputElement>) => {
if (parseInt(event.target.value)) {
setAmount(parseInt(event.target.value));
}
setAmount(event.target.value);
};

const handleTokenIndexChange = (
Expand Down

0 comments on commit a1b562d

Please sign in to comment.