From 2ff6eac1bfd5744f580b3e8e8f1bbb9dc1bd7cfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20C=2E=20Morency?= <1102868+fmorency@users.noreply.github.com> Date: Wed, 27 Nov 2024 13:02:19 -0500 Subject: [PATCH] fix: mint/burn large numbers (#82) --- components/factory/forms/BurnForm.tsx | 8 +++----- components/factory/forms/MintForm.tsx | 10 +++------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/components/factory/forms/BurnForm.tsx b/components/factory/forms/BurnForm.tsx index cf3abaf7..c575e424 100644 --- a/components/factory/forms/BurnForm.tsx +++ b/components/factory/forms/BurnForm.tsx @@ -4,7 +4,7 @@ import { useTokenFactoryBalance, useFeeEstimation, useTx } from '@/hooks'; import { cosmos, osmosis, liftedinit } from '@liftedinit/manifestjs'; import { MdContacts } from 'react-icons/md'; -import { shiftDigits } from '@/utils'; +import { parseNumberToBigInt, shiftDigits } from '@/utils'; import { Any } from '@liftedinit/manifestjs/dist/codegen/google/protobuf/any'; import { MsgBurnHeldBalance } from '@liftedinit/manifestjs/dist/codegen/liftedinit/manifest/v1/tx'; @@ -75,7 +75,6 @@ export default function BurnForm({ amount: Yup.number() .positive('Amount must be positive') .required('Amount is required') - .max(1e12, 'Amount is too large') .test('max-balance', 'Amount exceeds balance', function (value) { return value <= balanceNumber; }), @@ -103,8 +102,7 @@ export default function BurnForm({ } setIsSigning(true); try { - const amountInBaseUnits = BigInt(parseFloat(amount) * Math.pow(10, exponent)).toString(); - + const amountInBaseUnits = parseNumberToBigInt(amount, exponent).toString(); let msg; if (isMFX) { const burnMsg = burnHeldBalance({ @@ -166,7 +164,7 @@ export default function BurnForm({ authority: admin ?? '', burnCoins: burnPairs.map(pair => ({ denom: denom.base, - amount: BigInt(parseFloat(pair.amount) * Math.pow(10, exponent)).toString(), + amount: parseNumberToBigInt(pair.amount, exponent).toString(), })), }); const encodedMessage = Any.fromPartial({ diff --git a/components/factory/forms/MintForm.tsx b/components/factory/forms/MintForm.tsx index 610e291e..d683b1ab 100644 --- a/components/factory/forms/MintForm.tsx +++ b/components/factory/forms/MintForm.tsx @@ -3,7 +3,7 @@ import { chainName } from '@/config'; import { useFeeEstimation, useTx } from '@/hooks'; import { osmosis } from '@liftedinit/manifestjs'; -import { shiftDigits } from '@/utils'; +import { parseNumberToBigInt, shiftDigits } from '@/utils'; import { MdContacts } from 'react-icons/md'; import { Formik, Form } from 'formik'; @@ -43,10 +43,7 @@ export default function MintForm({ const isMFX = denom.base.includes('mfx'); const MintSchema = Yup.object().shape({ - amount: Yup.number() - .positive('Amount must be positive') - .required('Amount is required') - .max(1e12, 'Amount is too large'), + amount: Yup.number().positive('Amount must be positive').required('Amount is required'), recipient: Yup.string().required('Recipient address is required').manifestAddress(), }); @@ -56,8 +53,7 @@ export default function MintForm({ } setIsSigning(true); try { - const amountInBaseUnits = BigInt(parseFloat(amount) * Math.pow(10, exponent)).toString(); - + const amountInBaseUnits = parseNumberToBigInt(amount, exponent).toString(); let msg; msg = mint({