Skip to content

Commit

Permalink
Merge pull request #3 from OverGamesDev/main
Browse files Browse the repository at this point in the history
decimal correction
  • Loading branch information
sven-hash authored Jan 6, 2025
2 parents bb12740 + 53e6092 commit 47e9f82
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
34 changes: 31 additions & 3 deletions appv2/src/app/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ function BurnInterface() {
setBurnAmount(computedBalance);
}
} else {
const amount = (parseFloat(computedBalance) * percentage / 100).toFixed(selectedToken.decimals);
const amount = (parseFloat(computedBalance.replace(',', '.')) * percentage / 100)
.toFixed(0)
.replace(',', '.');
setBurnAmount(amount);
setRawAmount(undefined);
}
Expand All @@ -84,7 +86,32 @@ function BurnInterface() {
if (!selectedToken || !burnAmount) return;

try {
const floatToDecimals = rawAmount ? [rawAmount, 0] : convertToInt(burnAmount);
let amountToConvert;
if (rawAmount) {
amountToConvert = rawAmount;
} else {
const cleanAmount = burnAmount.toString()
.replace(/\s/g, '')
.replace(/\./g, '')
.replace(',', '.');

const formattedAmount = parseFloat(cleanAmount)
.toFixed(selectedToken.decimals)
.toString();

amountToConvert = formattedAmount;
}

if (isNaN(Number(amountToConvert))) {
throw new Error('Invalid number format');
}

const floatToDecimals = rawAmount ? [rawAmount, 0] : convertToInt(amountToConvert, selectedToken.decimals);

console.log("Amount to convert:", amountToConvert);
console.log("Converted values:", floatToDecimals);
console.log("Token decimals:", selectedToken.decimals);

const tx = await burn(
signer,
BigInt(floatToDecimals[0]),
Expand All @@ -93,7 +120,7 @@ function BurnInterface() {
selectedToken?.decimals ?? 0,
wantNFT,
account?.group,
rawAmount != undefined? true : false
rawAmount != undefined ? true : false
);

setRawAmount(undefined);
Expand All @@ -105,6 +132,7 @@ function BurnInterface() {
});
} catch (error) {
console.error("Error during burn:", error);
alert("Failed to process burn amount. Please check the number format.");
}
};

Expand Down
3 changes: 1 addition & 2 deletions appv2/src/app/services/token.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ export const burn = async (
groupIndex: number,
isMax?: boolean
): Promise<ExecuteScriptResult> => {
let decimalsPower = 0n

const decimalsPower = BigInt(tokenDecimals - decimalsAmount)

const contract = getContractFactory(groupIndex)
return await contract.transact.burn({
Expand Down

0 comments on commit 47e9f82

Please sign in to comment.