diff --git a/packages/page-staking/src/useOwnPools.ts b/packages/page-staking/src/useOwnPools.ts index b2ec46dced..6394bbd43b 100644 --- a/packages/page-staking/src/useOwnPools.ts +++ b/packages/page-staking/src/useOwnPools.ts @@ -9,7 +9,7 @@ import { useMemo } from 'react'; import { createNamedHook, useAccounts, useApi, useCall } from '@polkadot/react-hooks'; -import { createAccount } from './usePoolAccounts'; +import { createAccounts } from './usePoolAccounts'; const OPT_MULTI = { transform: ([[ids], opts]: [[string[]], Option[]]): OwnPoolBase[] => @@ -40,8 +40,7 @@ function useOwnPoolsImpl (): OwnPool[] | undefined { return useMemo( () => base && base.map((base) => ({ ...base, - rewardId: createAccount(api, base.poolId, 1), - stashId: createAccount(api, base.poolId, 0) + ...createAccounts(api, base.poolId) })), [api, base] ); diff --git a/packages/page-staking/src/usePoolAccounts.ts b/packages/page-staking/src/usePoolAccounts.ts index d497db02c8..36576ef46b 100644 --- a/packages/page-staking/src/usePoolAccounts.ts +++ b/packages/page-staking/src/usePoolAccounts.ts @@ -12,28 +12,32 @@ import { bnToU8a, stringToU8a, u8aConcat } from '@polkadot/util'; const EMPTY_H256 = new Uint8Array(32); const MOD_PREFIX = stringToU8a('modl'); +const U32_OPTS = { bitLength: 32, isLe: true }; -export function createAccount (api: ApiPromise, poolId: BN, index: number): string { - return api.registry.createType( - 'AccountId32', - u8aConcat( - MOD_PREFIX, - api.consts.nominationPools.palletId.toU8a(), - new Uint8Array([index]), - bnToU8a(poolId, { bitLength: 32 }), - EMPTY_H256 - ) - ).toString(); +function createAccount (api: ApiPromise, palletId: Uint8Array, poolId: BN, index: number): string { + return api.registry.createType('AccountId32', u8aConcat( + MOD_PREFIX, + palletId, + new Uint8Array([index]), + bnToU8a(poolId, U32_OPTS), + EMPTY_H256 + )).toString(); +} + +export function createAccounts (api: ApiPromise, poolId: BN): PoolAccounts { + const palletId = api.consts.nominationPools.palletId.toU8a(); + + return { + rewardId: createAccount(api, palletId, poolId, 1), + stashId: createAccount(api, palletId, poolId, 0) + }; } function usePoolAccountsImpl (poolId: BN): PoolAccounts { const { api } = useApi(); return useMemo( - () => ({ - rewardId: createAccount(api, poolId, 1), - stashId: createAccount(api, poolId, 0) - }), + () => createAccounts(api, poolId), [api, poolId] ); }