Skip to content

Commit a765e1e

Browse files
committed
fix: adjust voting balance
1 parent f3e38f1 commit a765e1e

File tree

5 files changed

+28
-16
lines changed

5 files changed

+28
-16
lines changed

packages/extension-polkagate/src/fullscreen/governance/delegate/partial/AlreadyLockedTooltipText.tsx

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
1-
// Copyright 2019-2024 @polkadot/extension-polkagate authors & contributors
1+
// Copyright 2019-2025 @polkadot/extension-polkagate authors & contributors
22
// SPDX-License-Identifier: Apache-2.0
3-
// @ts-nocheck
43

54
/* eslint-disable react/jsx-max-props-per-line */
5+
// @ts-nocheck
66

7-
import type { DeriveBalancesAll } from '@polkadot/api-derive/types';
7+
import type { BalancesInfo } from '@polkadot/extension-polkagate/util/types';
8+
import type { BN } from '@polkadot/util';
9+
import type { Lock } from '../../../../hooks/useAccountLocks';
810

9-
import { Grid, Skeleton, Typography } from '@mui/material';
11+
import { Grid, Typography } from '@mui/material';
1012
import React from 'react';
1113

12-
import { BN, BN_MAX_INTEGER } from '@polkadot/util';
14+
import { BN_MAX_INTEGER } from '@polkadot/util';
1315

1416
import { useCurrentBlockNumber, useDecimal, useToken, useTranslation } from '../../../../hooks';
15-
import { Lock } from '../../../../hooks/useAccountLocks';
1617
import { amountToHuman, remainingTime } from '../../../../util/utils';
1718

1819
interface Props {
1920
address: string | undefined;
2021
accountLocks: Lock[] | undefined
2122
}
2223

23-
export function getAlreadyLockedValue(allBalances: DeriveBalancesAll | undefined): BN | undefined {
24+
export function getAlreadyLockedValue (allBalances: BalancesInfo | undefined): BN | undefined {
2425
const LOCKS_ORDERED = ['pyconvot', 'democrac', 'phrelect'];
2526
const sortedLocks = allBalances?.lockedBreakdown
2627
// first sort by amount, so greatest value first
@@ -30,6 +31,7 @@ export function getAlreadyLockedValue(allBalances: DeriveBalancesAll | undefined
3031
// then sort by the type of lock (we try to find relevant)
3132
.sort((a, b): number => {
3233
if (!a.id.eq(b.id)) {
34+
// eslint-disable-next-line @typescript-eslint/prefer-for-of
3335
for (let i = 0; i < LOCKS_ORDERED.length; i++) {
3436
const lockName = LOCKS_ORDERED[i];
3537

@@ -48,7 +50,7 @@ export function getAlreadyLockedValue(allBalances: DeriveBalancesAll | undefined
4850
return sortedLocks?.[0] || allBalances?.lockedBalance;
4951
}
5052

51-
function AlreadyLockedTooltipText({ accountLocks, address }: Props): React.ReactElement {
53+
function AlreadyLockedTooltipText ({ accountLocks, address }: Props): React.ReactElement {
5254
const { t } = useTranslation();
5355
const currentBlock = useCurrentBlockNumber(address);
5456
const token = useToken(address);
@@ -80,7 +82,7 @@ function AlreadyLockedTooltipText({ accountLocks, address }: Props): React.React
8082
{currentBlock && accountLocks?.map((lock, index) => (
8183
<React.Fragment key={index}>
8284
<Grid item xs={2.5}>
83-
{lock.refId.toNumber()}
85+
{lock.refId?.toNumber()}
8486
</Grid>
8587
<Grid item xs={3.6}>
8688
{amountToHuman(lock.total, decimal)} {token}

packages/extension-polkagate/src/fullscreen/manageIdentity/Review.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2019-2024 @polkadot/extension-polkagate authors & contributors
1+
// Copyright 2019-2025 @polkadot/extension-polkagate authors & contributors
22
// SPDX-License-Identifier: Apache-2.0
33

44
/* eslint-disable react/jsx-max-props-per-line */
@@ -76,7 +76,7 @@ export default function Review ({ address, api, chain, depositToPay, depositValu
7676

7777
useEffect(() => {
7878
formatted && api?.derive.balances?.all(formatted).then((b) => {
79-
setBalances(b as BalancesInfo);
79+
setBalances(b as unknown as BalancesInfo);
8080
});
8181
}, [api, formatted]);
8282

packages/extension-polkagate/src/hooks/useNativeAssetBalances.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
// Copyright 2019-2024 @polkadot/extension-polkagate authors & contributors
1+
// Copyright 2019-2025 @polkadot/extension-polkagate authors & contributors
22
// SPDX-License-Identifier: Apache-2.0
33

44
import type React from 'react';
5+
import type { Balance } from '@polkadot/types/interfaces';
56
//@ts-ignore
67
import type { FrameSystemAccountInfo } from '@polkadot/types/lookup';
78
import type { HexString } from '@polkadot/util/types';
@@ -42,6 +43,8 @@ export default function useNativeAssetBalances (address: string | undefined, ref
4243
// some chains such as PARALLEL does not support this call hence BN_ZERO is set for them
4344
const frozenBalance = systemBalance?.frozen || BN_ZERO;
4445

46+
const votingBalance = api.createType('Balance', allBalances.freeBalance.add(allBalances.reservedBalance)) as unknown as Balance;
47+
4548
setNewBalances({
4649
ED,
4750
assetId: isFetchingNativeTokenOfAssetHub ? NATIVE_TOKEN_ASSET_ID_ON_ASSETHUB : NATIVE_TOKEN_ASSET_ID,
@@ -53,7 +56,8 @@ export default function useNativeAssetBalances (address: string | undefined, ref
5356
genesisHash: api.genesisHash.toString(),
5457
pooledBalance: balances?.pooledBalance, // fill from saved balance it exists, it will be updated
5558
soloTotal: stakingAccount?.stakingLedger?.total as unknown as BN,
56-
token
59+
token,
60+
votingBalance // since api derive does not updated after pools migration
5761
});
5862
setRefresh?.(false);
5963
isFetching.fetching[String(formatted)]['balances'] = false;

packages/extension-polkagate/src/util/types.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
// Copyright 2019-2024 @polkadot/extension-polkagate authors & contributors
1+
// Copyright 2019-2025 @polkadot/extension-polkagate authors & contributors
22
// SPDX-License-Identifier: Apache-2.0
33

4+
/* eslint-disable @typescript-eslint/consistent-indexed-object-style */
5+
46
import type { LinkOption } from '@polkagate/apps-config/endpoints/types';
57
import type React from 'react';
68
import type { ApiPromise } from '@polkadot/api';
@@ -683,6 +685,7 @@ export interface BalancesInfo extends DeriveBalancesAll {
683685
decimal: number;
684686
genesisHash: string;
685687
pooledBalance?: BN;
688+
votingBalance: Balance;
686689
frozenBalance: BN;
687690
soloTotal?: BN;
688691
token: string;

packages/extension-polkagate/src/util/workers/utils/balancify.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
// Copyright 2019-2024 @polkadot/extension-polkagate authors & contributors
1+
// Copyright 2019-2025 @polkadot/extension-polkagate authors & contributors
22
// SPDX-License-Identifier: Apache-2.0
33

44
// @ts-nocheck
5+
import { BN_ZERO } from '@polkadot/util';
6+
57

68
export function balancify (balances) {
79
const base = {
@@ -14,7 +16,8 @@ export function balancify (balances) {
1416
vestedClaimable: String(balances.vestedClaimable),
1517
vestingLocked: String(balances.vestingLocked),
1618
vestingTotal: String(balances.vestingTotal),
17-
votingBalance: String(balances.votingBalance)
19+
// votingBalance: String(balances.votingBalance)
20+
votingBalance: String(balances.free.add(balances?.reserved || BN_ZERO)) // after pool migration the voting balance returned fro api is not correct
1821
};
1922

2023
if (balances.soloTotal) {

0 commit comments

Comments
 (0)