Skip to content

Commit

Permalink
fix: mint/burn large numbers (#82)
Browse files Browse the repository at this point in the history
  • Loading branch information
fmorency authored Nov 27, 2024
1 parent 2ed7ed7 commit 2ff6eac
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
8 changes: 3 additions & 5 deletions components/factory/forms/BurnForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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;
}),
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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({
Expand Down
10 changes: 3 additions & 7 deletions components/factory/forms/MintForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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(),
});

Expand All @@ -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({
Expand Down

0 comments on commit 2ff6eac

Please sign in to comment.