Skip to content

Commit 2a8da29

Browse files
committed
fix: add pooled balance to reserved with pool migrations
1 parent b3caf1c commit 2a8da29

File tree

3 files changed

+33
-10
lines changed

3 files changed

+33
-10
lines changed

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

Lines changed: 23 additions & 6 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
// @ts-nocheck
@@ -13,18 +13,24 @@ import { useCallback, useEffect, useMemo, useState } from 'react';
1313

1414
import { BN_ZERO } from '@polkadot/util';
1515

16-
import { PROXY_CHAINS } from '../util/constants';
16+
import { MIGRATED_NOMINATION_POOLS_CHAINS, PROXY_CHAINS } from '../util/constants';
1717
import useActiveRecoveries from './useActiveRecoveries';
18-
import { useInfo } from '.';
18+
import { useAccountAssets, useInfo } from '.';
1919

20-
type Item = 'identity' | 'proxy' | 'bounty' | 'recovery' | 'referenda' | 'index' | 'society' | 'multisig' | 'preimage';
20+
type Item = 'identity' | 'proxy' | 'bounty' | 'recovery' | 'referenda' | 'index' | 'society' | 'multisig' | 'preimage' | 'pooledBalance';
2121
export type Reserved = { [key in Item]?: Balance };
2222

2323
export default function useReservedDetails (address: string | undefined): Reserved {
2424
const { api, formatted, genesisHash } = useInfo(address);
2525
const activeRecoveries = useActiveRecoveries(api);
26+
const accountAssets = useAccountAssets(address);
27+
2628
const [reserved, setReserved] = useState<Reserved>({});
2729

30+
const maybePooledBalance = useMemo(() =>
31+
accountAssets?.find((balance) => balance.genesisHash === genesisHash)?.pooledBalance
32+
, [accountAssets, genesisHash]);
33+
2834
const activeLost = useMemo(() =>
2935
activeRecoveries && formatted
3036
? activeRecoveries.filter((active) => active.lost === String(formatted)).at(-1) ?? null
@@ -274,10 +280,21 @@ export default function useReservedDetails (address: string | undefined): Reserv
274280
}
275281
}).catch(console.error);
276282
}
283+
284+
/** handle pooleBalance as reserved */
285+
if (maybePooledBalance && MIGRATED_NOMINATION_POOLS_CHAINS.includes(genesisHash)) {
286+
if (!maybePooledBalance.isZero()) {
287+
setReserved((prev) => {
288+
prev.pooledBalance = toBalance(maybePooledBalance);
289+
290+
return prev;
291+
});
292+
}
293+
}
277294
} catch (e) {
278-
console.error('Fatal error while fetching reserved details:', e)
295+
console.error('Fatal error while fetching reserved details:', e);
279296
}
280-
}, [activeLost?.deposit, api, formatted, genesisHash, toBalance]);
297+
}, [activeLost?.deposit, api, formatted, genesisHash, maybePooledBalance, toBalance]);
281298

282299
useEffect(() => {
283300
setReserved({});

packages/extension-polkagate/src/popup/account/util.ts

Lines changed: 7 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
/**
@@ -10,6 +10,8 @@ import type { BalancesInfo } from '../../util/types';
1010

1111
import { BN, BN_ZERO, bnMax } from '@polkadot/util';
1212

13+
import { MIGRATED_NOMINATION_POOLS_CHAINS } from '../../util/constants';
14+
1315
function isEmptyObject (obj: object): boolean {
1416
return Object.keys(obj).length === 0;
1517
}
@@ -22,8 +24,11 @@ export const getValue = (type: string, balances: BalancesInfo | null | undefined
2224
switch (type.toLocaleLowerCase()) {
2325
case ('total'):
2426
case ('total balance'):
27+
// eslint-disable-next-line no-case-declarations
28+
const isPoolsMigrated = MIGRATED_NOMINATION_POOLS_CHAINS.includes(balances.genesisHash);
29+
2530
return balances?.freeBalance && balances.reservedBalance
26-
? new BN(balances.freeBalance).add(new BN(balances.reservedBalance)).add(balances?.pooledBalance ? new BN(balances.pooledBalance) : BN_ZERO)
31+
? new BN(balances.freeBalance).add(new BN(balances.reservedBalance)).add((balances?.pooledBalance && !isPoolsMigrated) ? new BN(balances.pooledBalance) : BN_ZERO)
2732
: new BN(balances?.totalBalance || 0);
2833
case ('pooled balance'):
2934
case ('pool stake'):

packages/extension-polkagate/src/util/constants.tsx

Lines changed: 3 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
import type { ProxyTypes } from './types';
@@ -53,7 +53,6 @@ export const POLKADOT_PEOPLE_GENESIS_HASH = '0x67fa177a097bfa18f77ea95ab56e9bcdf
5353
export const KUSAMA_PEOPLE_GENESIS_HASH = '0xc1af4cb4eb3918e5db15086c0cc5ec17fb334f728b7c65dd44bfe1e174ff8b3f';
5454
export const WESTEND_PEOPLE_GENESIS_HASH = '0x1eb6fb0ba5187434de017a70cb84d4f47142df1d571d0ef9e7e1407f2b80b93c';
5555

56-
5756
/** relay chains info */
5857
export const RELAY_CHAINS_NAMES = ['Polkadot', 'Kusama', 'Westend', 'Paseo'];
5958

@@ -62,6 +61,8 @@ export const KUSAMA_GENESIS_HASH = '0xb0a8d493285c2df73290dfb7e61f870f17b4180119
6261
export const WESTEND_GENESIS_HASH = '0xe143f23803ac50e8f6f8e62695d1ce9e4e1d68aa36c1cd2cfd15340213f3423e';
6362
export const PASEO_GENESIS_HASH = '0x77afd6190f1554ad45fd0d31aee62aacc33c6db0ea801129acb813f913e0764f';
6463

64+
export const MIGRATED_NOMINATION_POOLS_CHAINS = [WESTEND_GENESIS_HASH, KUSAMA_GENESIS_HASH];
65+
6566
export const RELAY_CHAINS_GENESISHASH = [
6667
POLKADOT_GENESIS_HASH,
6768
KUSAMA_GENESIS_HASH,

0 commit comments

Comments
 (0)