Skip to content

Commit

Permalink
Merge pull request #211 from ubq-testing/fix-decimals
Browse files Browse the repository at this point in the history
fix: decimals
  • Loading branch information
0x4007 authored Mar 25, 2024
2 parents 3c163d0 + 36e05c2 commit cd49591
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion static/scripts/rewards/render-transaction/render-token-symbol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,16 @@ export async function renderTokenSymbol({
}

// Format the amount
const formattedAmount = parseFloat(utils.formatUnits(amount, decimals)).toFixed(0);
let formattedAmount: string | number = parseFloat(utils.formatUnits(amount, decimals));

// If the amount is an integer, convert it to a string
if (Number.isInteger(formattedAmount)) {
formattedAmount = formattedAmount.toString();
} else {
// If the amount is not an integer, round it to a max of 4 decimal places
const decimals = Math.min(4, (formattedAmount.toString().split(".")[1] || "").length);
formattedAmount = formattedAmount.toFixed(decimals);
}

table.setAttribute(`data-contract-loaded`, "true");
requestedAmountElement.innerHTML = `<a target="_blank" rel="noopener noreferrer" href="${explorerUrl}/token/${tokenAddress}?a=${ownerAddress}">${formattedAmount} ${symbol}</a>`;
Expand Down

0 comments on commit cd49591

Please sign in to comment.