From 07231fa60cfb8f21c3baeeef0527ab4952793528 Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 14 Mar 2024 12:32:37 +0200 Subject: [PATCH 1/2] TW-1394: Fix bakers balance --- src/app/hooks/use-balances-loading.ts | 5 ++++- src/app/store/balances/epics.ts | 5 ++++- src/lib/apis/tzkt/api.ts | 14 ++++++++------ src/lib/apis/tzkt/types.ts | 10 ++++++---- 4 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/app/hooks/use-balances-loading.ts b/src/app/hooks/use-balances-loading.ts index 4da31f401..c7a48f1ac 100644 --- a/src/app/hooks/use-balances-loading.ts +++ b/src/app/hooks/use-balances-loading.ts @@ -88,11 +88,14 @@ export const useBalancesLoading = () => { matchingAccount?.type === TzktAccountType.Delegate || matchingAccount?.type === TzktAccountType.User ) { + const balance = + matchingAccount.balance - (matchingAccount.stakedBalance ?? 0) - (matchingAccount.unstakedBalance ?? 0); + dispatch( loadGasBalanceActions.success({ publicKeyHash, chainId, - balance: matchingAccount.balance.toFixed() + balance: balance.toFixed() }) ); } else if (matchingAccount) { diff --git a/src/app/store/balances/epics.ts b/src/app/store/balances/epics.ts index 1fbcf2b78..a68b81b2d 100644 --- a/src/app/store/balances/epics.ts +++ b/src/app/store/balances/epics.ts @@ -15,7 +15,10 @@ const loadGasBalanceEpic: Epic = action$ => switchMap(({ publicKeyHash, chainId }) => from(fetchTezosBalanceFromTzkt(publicKeyHash, chainId)).pipe( map(info => { - const balance = new BigNumber(info.balance ?? 0).minus(info.frozenDeposit ?? 0).toFixed(); + const balance = new BigNumber(info.balance ?? 0) + .minus(info.stakedBalance ?? 0) + .minus(info.unstakedBalance ?? 0) + .toFixed(); return loadGasBalanceActions.success({ publicKeyHash, diff --git a/src/lib/apis/tzkt/api.ts b/src/lib/apis/tzkt/api.ts index 46e24897c..ace52b402 100644 --- a/src/lib/apis/tzkt/api.ts +++ b/src/lib/apis/tzkt/api.ts @@ -196,17 +196,19 @@ export async function refetchOnce429(fetcher: () => Promise, delayAroundIn } interface GetAccountResponse { - balance: string; - frozenDeposit?: string; + balance: number; + stakedBalance?: number; + unstakedBalance?: number; } export const fetchTezosBalanceFromTzkt = async (account: string, chainId: TzktApiChainId) => fetchGet(chainId, `/accounts/${account}`, { - select: 'balance,frozenDeposit', + select: 'balance,stakedBalance,unstakedBalance', 'balance.gt': 0 - }).then(({ frozenDeposit, balance }) => ({ - frozenDeposit, - balance + }).then(({ stakedBalance, balance, unstakedBalance }) => ({ + balance, + stakedBalance, + unstakedBalance })); export const fetchAllAssetsBalancesFromTzkt = async (account: string, chainId: TzktApiChainId) => { diff --git a/src/lib/apis/tzkt/types.ts b/src/lib/apis/tzkt/types.ts index 68da5d511..6bf7f6b82 100644 --- a/src/lib/apis/tzkt/types.ts +++ b/src/lib/apis/tzkt/types.ts @@ -114,7 +114,7 @@ export type TzktGetRewardsParams = { quote?: TzktQuoteCurrency[]; }; -export type TzktRewardsEntry = { +export interface TzktRewardsEntry { cycle: number; balance: number; baker: { @@ -164,7 +164,7 @@ export type TzktRewardsEntry = { revelationLostRewards: number; revelationLostFees: number; quote?: TzktQuote; -}; +} export type TzktGetRewardsResponse = TzktRewardsEntry[] | undefined; @@ -246,6 +246,8 @@ interface TzktAccountBase { type: TzktAccountType; address: string; alias: string | nullish; + stakedBalance?: number; + unstakedBalance?: number; } interface TzktUserAccount extends TzktAccountBase { @@ -309,14 +311,14 @@ interface TzktDelegateAccount extends TzktAccountBase { balance: number; rollupBonds: number; smartRollupBonds: number; - frozenDeposit: number; frozenDepositLimit: number | nullish; counter: number; activationLevel: number; activationTime: string; deactivationLevel: number | nullish; deactivationTime: string | nullish; - stakingBalance: number; + stakedBalance?: number; + unstakedBalance?: number; delegatedBalance: number; numContracts: number; rollupsCount: number; From 2d260ba901d72f8cbc7423d3da03f08a9c7f0fcf Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 14 Mar 2024 14:38:49 +0200 Subject: [PATCH 2/2] TW-1394: Fix bakers balance. Refactor --- src/lib/apis/tzkt/types.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/lib/apis/tzkt/types.ts b/src/lib/apis/tzkt/types.ts index 6bf7f6b82..f942147f3 100644 --- a/src/lib/apis/tzkt/types.ts +++ b/src/lib/apis/tzkt/types.ts @@ -317,8 +317,6 @@ interface TzktDelegateAccount extends TzktAccountBase { activationTime: string; deactivationLevel: number | nullish; deactivationTime: string | nullish; - stakedBalance?: number; - unstakedBalance?: number; delegatedBalance: number; numContracts: number; rollupsCount: number;