From 59b16710759bb4a25fffd0fcb757678ce9e8b648 Mon Sep 17 00:00:00 2001 From: Jaco Date: Thu, 5 May 2022 06:44:01 +0200 Subject: [PATCH] HACK for both npols & nopls (#7527) --- packages/page-staking/src/usePoolAccounts.ts | 13 ++++++++++++- packages/react-components/src/AccountName.tsx | 4 ++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/packages/page-staking/src/usePoolAccounts.ts b/packages/page-staking/src/usePoolAccounts.ts index a64bb9fbcd..b7b4de1d80 100644 --- a/packages/page-staking/src/usePoolAccounts.ts +++ b/packages/page-staking/src/usePoolAccounts.ts @@ -12,11 +12,22 @@ import { bnToU8a, stringToU8a, u8aConcat } from '@polkadot/util'; const EMPTY_H256 = new Uint8Array(32); const ADDR_PREFIX = stringToU8a('modlpy/npols'); +const ADDR_PREFIX_WST = stringToU8a('modlpy/nopls'); export function createAccount (api: ApiPromise, poolId: BN, index: number): string { return api.registry.createType( 'AccountId32', - u8aConcat(ADDR_PREFIX, new Uint8Array([index]), bnToU8a(poolId, { bitLength: 32 }), EMPTY_H256) + u8aConcat( + // HACK: We have a naming issue between Substrate master as well as Westend. Since + // we don't quite have access to palletId, we here check the specName and adjust + // accordingly + api.runtimeVersion.specName.eq('westend') + ? ADDR_PREFIX_WST + : ADDR_PREFIX, + new Uint8Array([index]), + bnToU8a(poolId, { bitLength: 32 }), + EMPTY_H256 + ) ).toString(); } diff --git a/packages/react-components/src/AccountName.tsx b/packages/react-components/src/AccountName.tsx index c5cf35872e..eca4440398 100644 --- a/packages/react-components/src/AccountName.tsx +++ b/packages/react-components/src/AccountName.tsx @@ -62,8 +62,12 @@ const MATCHERS: AddrMatcher[] = [ createAllMatcher('modlpy/socie', 'Society'), createAllMatcher('modlpy/trsry', 'Treasury'), createNumMatcher('modlpy/cfund', 'Crowdloan'), + // Substrate master createNumMatcher('modlpy/npols\x00', 'Pool', 'Stash'), createNumMatcher('modlpy/npols\x01', 'Pool', 'Reward'), + // Westend + createNumMatcher('modlpy/nopls\x00', 'Pool', 'Stash'), + createNumMatcher('modlpy/nopls\x01', 'Pool', 'Reward'), createNumMatcher('para', 'Parachain') ];