Skip to content

Commit

Permalink
fix: decimals
Browse files Browse the repository at this point in the history
  • Loading branch information
Keyrxng committed Mar 25, 2024
1 parent 3c163d0 commit 36e05c2
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 36e05c2

Please sign in to comment.