comments: proposal how to format output to show fraction.
This commit is contained in:
@@ -29,6 +29,15 @@ export function formatNumber(number) {
|
|||||||
return formattedWithOptions;
|
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) {
|
export function getAddressShortName(address) {
|
||||||
// const address = "0x66422602B2f4885c57EE794174f98d9E4DDBBBC6";
|
// const address = "0x66422602B2f4885c57EE794174f98d9E4DDBBBC6";
|
||||||
const addressBegin = address.substring(0, 6);
|
const addressBegin = address.substring(0, 6);
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import { useRewardLockerStore } from "@/stores/rewardlocker";
|
|||||||
import { useTokenStore } from "@/stores/tokens";
|
import { useTokenStore } from "@/stores/tokens";
|
||||||
import { waitForTransaction, readContract, watchBlockNumber, multicall } from "@wagmi/core";
|
import { waitForTransaction, readContract, watchBlockNumber, multicall } from "@wagmi/core";
|
||||||
import { showSuccessToast } from "@/helper/toast.js";
|
import { showSuccessToast } from "@/helper/toast.js";
|
||||||
import { formatNumber } from "@/helper/helper.js";
|
import { formatNumber, formatBigIntDivision } from "@/helper/helper.js";
|
||||||
|
|
||||||
export const useSacrificeStore = defineStore("sacrifice", {
|
export const useSacrificeStore = defineStore("sacrifice", {
|
||||||
state: () => ({
|
state: () => ({
|
||||||
@@ -64,16 +64,17 @@ export const useSacrificeStore = defineStore("sacrifice", {
|
|||||||
});
|
});
|
||||||
console.log("rewardData", rewardData);
|
console.log("rewardData", rewardData);
|
||||||
//output
|
//output
|
||||||
const outputSacrifice = rewardData.reduce((x, y) => {
|
let 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);
|
||||||
return x + BigInt(y.data) / 10n ** token.decimals;
|
|
||||||
}, 0n);
|
}, 0n);
|
||||||
|
outputSacrifice = formatBigIntDivision(outputSacrifice, 10n ** token.decimals);
|
||||||
|
|
||||||
console.log("outputSacrifice", outputSacrifice);
|
console.log("outputSacrifice", outputSacrifice);
|
||||||
token.allowance = await tokenStore.allowance();
|
token.allowance = await tokenStore.allowance();
|
||||||
this.sacrificeState = 4;
|
this.sacrificeState = 4;
|
||||||
|
|
||||||
showSuccessToast(
|
showSuccessToast(
|
||||||
formatNumber(outputSacrifice),
|
outputSacrifice,
|
||||||
"Success!",
|
"Success!",
|
||||||
"You turned your meme into:",
|
"You turned your meme into:",
|
||||||
"You can claim once the current cycle is finished and your clan bonus was calculated."
|
"You can claim once the current cycle is finished and your clan bonus was calculated."
|
||||||
|
|||||||
Reference in New Issue
Block a user