fix: Move BigInt formatting functions from helper.ts to kraiken-lib/format (#246)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
openhands 2026-02-24 23:00:58 +00:00
parent 0f74cc8276
commit 8c43d3890c
16 changed files with 377 additions and 102 deletions

View file

@ -5,7 +5,7 @@ import axios from 'axios';
import { getAccount, watchChainId, watchAccount, watchContractEvent, type Config } from '@wagmi/core';
import type { WatchChainIdReturnType, WatchAccountReturnType, GetAccountReturnType } from '@wagmi/core';
import { bigInt2Number } from '@/utils/helper';
import { weiToNumber } from 'kraiken-lib/format';
import { getTaxRateIndexByDecimal } from '@/composables/useAdjustTaxRates';
import logger from '@/utils/logger';
import { DEFAULT_CHAIN_ID } from '@/config';
@ -43,7 +43,7 @@ const activePositions = computed(() => {
return {
...obj,
positionId: BigInt(obj.id),
amount: bigInt2Number(obj.harbDeposit, 18),
amount: weiToNumber(obj.harbDeposit, 18),
taxRatePercentage: taxRateDecimal * 100,
taxRate: taxRateDecimal,
taxRateIndex,
@ -97,7 +97,7 @@ const myClosedPositions: ComputedRef<Position[]> = computed(() => {
...obj,
positionId: BigInt(obj.id),
amount: obj.share * 1000000,
// amount: bigInt2Number(obj.harbDeposit, 18),
// amount: weiToNumber(obj.harbDeposit, 18),
taxRatePercentage: taxRateDecimal * 100,
taxRate: taxRateDecimal,
taxRateIndex,

View file

@ -8,7 +8,7 @@ import { StakeContract, permitAndSnatch, minStake } from '@/contracts/stake';
import { getNonce, nonce, getName } from '@/contracts/harb';
import { useWallet } from '@/composables/useWallet';
import { createPermitObject, getSignatureRSV } from '@/utils/blockchain';
import { formatBigIntDivision, compactNumber } from '@/utils/helper';
import { weiToNumber, compactNumber } from 'kraiken-lib/format';
import { getTaxRateOptionByIndex } from '@/composables/useAdjustTaxRates';
import { useContractToast } from './useContractToast';
const wallet = useWallet();
@ -69,7 +69,7 @@ export function useStake() {
const stakingAmountNumber = computed({
// getter
get() {
return formatBigIntDivision(stakingAmount.value, 10n ** 18n);
return weiToNumber(stakingAmount.value, 18);
},
// setter
set(newValue) {
@ -128,8 +128,7 @@ export function useStake() {
}) as DecodeEventLogReturnType & { args: PositionCreatedArgs };
const eventArgs: PositionCreatedArgs = topics.args;
const decimalsAsBigInt = typeof wallet.balance.decimals === 'bigint' ? wallet.balance.decimals : BigInt(wallet.balance.decimals);
const amount = compactNumber(formatBigIntDivision(eventArgs.harbergDeposit, 10n ** decimalsAsBigInt));
const amount = compactNumber(weiToNumber(eventArgs.harbergDeposit, wallet.balance.decimals));
contractToast.showSuccessToast(amount, 'Success!', 'You Staked', 'Check your positions on the<br /> Staker Dashboard', '$KRK');
waiting.value = false;

View file

@ -5,7 +5,7 @@ import type { Config } from '@wagmi/core';
import { config } from '@/wagmi';
import logger from '@/utils/logger';
import type { WatchBlocksReturnType } from 'viem';
import { bigInt2Number } from '@/utils/helper';
import { weiToNumber } from 'kraiken-lib/format';
import { minStake as stakeMinStake } from '@/contracts/stake';
import { DEFAULT_CHAIN_ID } from '@/config';
import { createRetryManager, formatGraphqlError, resolveGraphqlEndpoint } from '@/utils/graphqlRetry';
@ -174,7 +174,7 @@ const stakeableSupply = computed(() => {
//maxSlots
const maxSlots = computed(() => {
if (rawStatsCollections.value?.length > 0 && BigInt(rawStatsCollections.value[0].kraikenTotalSupply) > 0n) {
return (bigInt2Number(stakeTotalSupply.value, 18) * 0.2) / 100;
return (weiToNumber(stakeTotalSupply.value, 18) * 0.2) / 100;
} else {
return 0;
}
@ -182,8 +182,8 @@ const maxSlots = computed(() => {
const claimedSlots = computed(() => {
if (stakeTotalSupply.value > 0n) {
const stakeableSupplyNumber = bigInt2Number(stakeableSupply.value, 18);
const outstandingStakeNumber = bigInt2Number(outstandingStake.value, 18);
const stakeableSupplyNumber = weiToNumber(stakeableSupply.value, 18);
const outstandingStakeNumber = weiToNumber(outstandingStake.value, 18);
return (outstandingStakeNumber / stakeableSupplyNumber) * maxSlots.value;
} else {
return 0;

View file

@ -4,7 +4,7 @@ import { waitForTransactionReceipt } from '@wagmi/core';
import type { Config } from '@wagmi/core';
import { config } from '@/wagmi';
import { useContractToast } from './useContractToast';
import { compactNumber, formatBigIntDivision } from '@/utils/helper';
import { compactNumber, weiToNumber } from 'kraiken-lib/format';
import { decodeEventLog, type DecodeEventLogReturnType } from 'viem';
import { useWallet } from './useWallet';
@ -55,7 +55,7 @@ export function useUnstake() {
const eventArgs: PositionRemovedArgs = topics.args;
const amount = compactNumber(formatBigIntDivision(eventArgs.harbergPayout, 10n ** BigInt(wallet.balance.decimals)));
const amount = compactNumber(weiToNumber(eventArgs.harbergPayout, wallet.balance.decimals));
contractToast.showSuccessToast(amount, 'Success!', 'You unstaked', '', '$KRK');
waiting.value = false;