Skip to content

Commit

Permalink
feat(refactor): disable identities on networks where People Chain is …
Browse files Browse the repository at this point in the history
…being used (#2183)
  • Loading branch information
rossbulat authored Jul 6, 2024
1 parent 59f2806 commit e5edec2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 13 deletions.
5 changes: 5 additions & 0 deletions src/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,8 @@ export const MaxPayoutDays = 60;
export const MaxEraRewardPointsEras = 10;
export const ZondaxMetadataHashApiUrl =
'https://api.zondax.ch/polkadot/node/metadata/hash';

/*
* People Chain migration - disallow identities on networks where People Chain is live.
*/
export const PeopleChainNetworks = ['westend', 'kusama'];
19 changes: 11 additions & 8 deletions src/contexts/Validators/ValidatorEntries/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type { AnyApi, Fn } from 'types';
import { useEffectIgnoreInitial } from '@w3ux/hooks';
import { useNetwork } from 'contexts/Network';
import { useApi } from 'contexts/Api';
import { MaxEraRewardPointsEras } from 'consts';
import { MaxEraRewardPointsEras, PeopleChainNetworks } from 'consts';
import { useStaking } from 'contexts/Staking';
import type {
EraPointsBoundaries,
Expand Down Expand Up @@ -316,14 +316,17 @@ export const ValidatorsProvider = ({ children }: { children: ReactNode }) => {
// NOTE: validators are shuffled before committed to state.
setValidators(shuffle(validatorEntries));

const addresses = validatorEntries.map(({ address }) => address);
const { identities, supers } = await IdentitiesController.fetch(
api,
addresses
);
// PEOPLE CHAIN MIGRATION: Currently ignoring identities while People Chain is not supported.
if (!PeopleChainNetworks.includes(network)) {
const addresses = validatorEntries.map(({ address }) => address);
const { identities, supers } = await IdentitiesController.fetch(
api,
addresses
);
setValidatorIdentities(identities);
setValidatorSupers(supers);
}

setValidatorIdentities(identities);
setValidatorSupers(supers);
setValidatorsFetched('synced');
};

Expand Down
16 changes: 11 additions & 5 deletions src/controllers/ActivePoolsController/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import type {
import { SyncController } from 'controllers/SyncController';
import type { Nominations } from 'contexts/Balances/types';
import type { ApiPromise } from '@polkadot/api';
import { PeopleChainNetworks } from 'consts';

export class ActivePoolsController {
// ------------------------------------------------------
Expand Down Expand Up @@ -126,11 +127,16 @@ export class ActivePoolsController {
const balance = accountDataResult.data;
const rewardAccountBalance = balance?.free.toString();

// Fetch identities for roles and expand `bondedPool` state to store them.
bondedPool.roleIdentities = await IdentitiesController.fetch(
api,
this.getUniqueRoleAddresses(bondedPool.roles)
);
// PEOPLE CHAIN MIGRATION: Currently ignoring identities while People Chain is not supported.
if (
!PeopleChainNetworks.includes(api.runtimeChain.toString().toLowerCase())
) {
// Fetch identities for roles and expand `bondedPool` state to store them.
bondedPool.roleIdentities = await IdentitiesController.fetch(
api,
this.getUniqueRoleAddresses(bondedPool.roles)
);
}

// Only persist the active pool to class state (and therefore dispatch an event) if both the
// bonded pool and reward pool are returned.
Expand Down

0 comments on commit e5edec2

Please sign in to comment.