comments: proposal how to format output to show fraction.
This commit is contained in:
@@ -29,6 +29,15 @@ export function formatNumber(number) {
|
||||
return formattedWithOptions;
|
||||
}
|
||||
|
||||
// input type bigint
|
||||
export function formatBigIntDivision(nominator, denominator) {
|
||||
const integer = (nominator / denominator).toString();
|
||||
// pick how much digits after point to show
|
||||
const fraction = (nominator % denominator).toString().substring(0,10);
|
||||
// output type string
|
||||
return integer + '.' + fraction;
|
||||
}
|
||||
|
||||
export function getAddressShortName(address) {
|
||||
// const address = "0x66422602B2f4885c57EE794174f98d9E4DDBBBC6";
|
||||
const addressBegin = address.substring(0, 6);
|
||||
|
||||
@@ -9,7 +9,7 @@ import { useRewardLockerStore } from "@/stores/rewardlocker";
|
||||
import { useTokenStore } from "@/stores/tokens";
|
||||
import { waitForTransaction, readContract, watchBlockNumber, multicall } from "@wagmi/core";
|
||||
import { showSuccessToast } from "@/helper/toast.js";
|
||||
import { formatNumber } from "@/helper/helper.js";
|
||||
import { formatNumber, formatBigIntDivision } from "@/helper/helper.js";
|
||||
|
||||
export const useSacrificeStore = defineStore("sacrifice", {
|
||||
state: () => ({
|
||||
@@ -64,16 +64,17 @@ export const useSacrificeStore = defineStore("sacrifice", {
|
||||
});
|
||||
console.log("rewardData", rewardData);
|
||||
//output
|
||||
const outputSacrifice = rewardData.reduce((x, y) => {
|
||||
// CHECK: when you divide like this you are losing remainder, let's better work on formatShowNumber(BigInt: number) function
|
||||
return x + BigInt(y.data) / 10n ** token.decimals;
|
||||
let outputSacrifice = rewardData.reduce((x, y) => {
|
||||
return x + BigInt(y.data);
|
||||
}, 0n);
|
||||
outputSacrifice = formatBigIntDivision(outputSacrifice, 10n ** token.decimals);
|
||||
|
||||
console.log("outputSacrifice", outputSacrifice);
|
||||
token.allowance = await tokenStore.allowance();
|
||||
this.sacrificeState = 4;
|
||||
|
||||
showSuccessToast(
|
||||
formatNumber(outputSacrifice),
|
||||
outputSacrifice,
|
||||
"Success!",
|
||||
"You turned your meme into:",
|
||||
"You can claim once the current cycle is finished and your clan bonus was calculated."
|
||||
|
||||
Reference in New Issue
Block a user