Skip to content

Commit

Permalink
fix: decimals
Browse files Browse the repository at this point in the history
  • Loading branch information
sven-hash committed Dec 15, 2024
1 parent 91452d7 commit 40bedc4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
1 change: 1 addition & 0 deletions app/src/components/FurnacePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ export const FurnacePage: FC = () => {

if (signer) {
try {

const floatToDecimals = convertToInt(amount)
console.log(floatToDecimals)
const tx = await burn(
Expand Down
20 changes: 14 additions & 6 deletions app/src/services/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,22 @@ export interface TokenFaucetConfig {
}


export const convertToInt = (withdrawAmount: string):[bigint, number] => {
let amountToWithdrawFloat = ''
export const convertToInt = (withdrawAmount: string): [bigint, number] => {
// Convert scientific notation to regular decimal
const normalizedNumber = Number(withdrawAmount).toLocaleString('fullwide', {
useGrouping: false,
maximumFractionDigits: 20
})

// Split the number into integer and decimal parts
const [integerPart, decimalPart = ''] = normalizedNumber.split('.')

// Combine integer and decimal parts without the decimal point
const fullNumber = integerPart + decimalPart

if (withdrawAmount.split('.').length > 0)
amountToWithdrawFloat = withdrawAmount.split('.')[0] + withdrawAmount.split('.')[1]
return [
withdrawAmount.split('.').length > 1 ? BigInt(amountToWithdrawFloat) : BigInt(withdrawAmount),
withdrawAmount.split('.').length > 1 ? Number(withdrawAmount.split('.')[1].length) : Number(0)
BigInt(fullNumber),
decimalPart.length
]
}

Expand Down

0 comments on commit 40bedc4

Please sign in to comment.