Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TW-1394: Fix bakers balance #1111

Draft
wants to merge 2 commits into
base: development
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/app/hooks/use-balances-loading.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 4 additions & 1 deletion src/app/store/balances/epics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
lendihop marked this conversation as resolved.
Show resolved Hide resolved

return loadGasBalanceActions.success({
publicKeyHash,
Expand Down
14 changes: 8 additions & 6 deletions src/lib/apis/tzkt/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,17 +196,19 @@ export async function refetchOnce429<R>(fetcher: () => Promise<R>, delayAroundIn
}

interface GetAccountResponse {
balance: string;
frozenDeposit?: string;
balance: number;
stakedBalance?: number;
unstakedBalance?: number;
}

export const fetchTezosBalanceFromTzkt = async (account: string, chainId: TzktApiChainId) =>
fetchGet<GetAccountResponse>(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) => {
Expand Down
8 changes: 4 additions & 4 deletions src/lib/apis/tzkt/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export type TzktGetRewardsParams = {
quote?: TzktQuoteCurrency[];
};

export type TzktRewardsEntry = {
export interface TzktRewardsEntry {
cycle: number;
balance: number;
baker: {
Expand Down Expand Up @@ -164,7 +164,7 @@ export type TzktRewardsEntry = {
revelationLostRewards: number;
revelationLostFees: number;
quote?: TzktQuote;
};
}

export type TzktGetRewardsResponse = TzktRewardsEntry[] | undefined;

Expand Down Expand Up @@ -246,6 +246,8 @@ interface TzktAccountBase {
type: TzktAccountType;
address: string;
alias: string | nullish;
stakedBalance?: number;
unstakedBalance?: number;
}

interface TzktUserAccount extends TzktAccountBase {
Expand Down Expand Up @@ -309,14 +311,12 @@ 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;
delegatedBalance: number;
numContracts: number;
rollupsCount: number;
Expand Down
Loading