Skip to content

Commit

Permalink
A0-2616: suspension page does not show new suspensions (#69)
Browse files Browse the repository at this point in the history
* A0-2616: Fix suspension events filtering

* Fix react unique key warning

* Migrate to committeeManagement
  • Loading branch information
youPickItUp authored Jun 19, 2023
1 parent ac67ebf commit 24d03a9
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/page-staking/src/Suspensions/CurrentList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function CurrentList ({ suspensions }: Props): React.ReactElement<Props> {
address={address}
era={era}
filterName={nameFilter}
key={address}
key={`address-${address}-era-${era}`}
suspensionLiftsInEra={suspensionLiftsInEra}
suspensionReason={suspensionReason}
/>
Expand Down
6 changes: 3 additions & 3 deletions packages/page-staking/src/Suspensions/Suspensions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import { useEffect, useMemo, useState } from 'react';

import getCommitteeManagement from '@polkadot/react-api/getCommitteeManagement';
import getCommitteeManagement, { COMMITTEE_MANAGEMENT_NAMES } from '@polkadot/react-api/getCommitteeManagement';
import { createNamedHook, useApi, useCall } from '@polkadot/react-hooks';
import { u64, Vec } from '@polkadot/types';
import { EventRecord, Hash } from '@polkadot/types/interfaces';
Expand All @@ -16,7 +16,7 @@ import { SuspensionEvent } from './index.js';
type SuspensionReasons = [string, string, number][];

function parseEvents (events: EventRecord[]): SuspensionReasons {
return events.filter(({ event }) => event.section === 'elections' && event.method === 'BanValidators')
return events.filter(({ event }) => COMMITTEE_MANAGEMENT_NAMES.includes(event.section) && event.method === 'BanValidators')
.map(({ event }) => {
const raw = event.data[0] as unknown as Codec[][];

Expand Down Expand Up @@ -73,7 +73,7 @@ function useSuspensions (): SuspensionEvent[] | undefined {
);

useEffect(() => {
if (!(api && api.consts.elections) || erasStartSessionIndexLookup.length === 0) {
if (!(api && getCommitteeManagement(api).consts) || erasStartSessionIndexLookup.length === 0) {
return;
}

Expand Down
2 changes: 2 additions & 0 deletions packages/react-api/src/getCommitteeManagement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import type { ApiPromise } from '@polkadot/api';
import type { ApiDecoration } from '@polkadot/api/types';

export const COMMITTEE_MANAGEMENT_NAMES = ['committeeManagement', 'elections'];

export default function getCommitteeManagement (api: ApiPromise | ApiDecoration<'promise'>) {
return {
consts: api.consts.committeeManagement || api.consts.elections,
Expand Down
3 changes: 2 additions & 1 deletion packages/react-signer/src/Address.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import type { AddressFlags, AddressProxy } from './types.js';
import React, { useCallback, useEffect, useMemo, useState } from 'react';

import { ApiPromise } from '@polkadot/api';
import { COMMITTEE_MANAGEMENT_NAMES } from '@polkadot/react-api/getCommitteeManagement';
import { InputAddress, MarkError, Modal, Toggle } from '@polkadot/react-components';
import { useAccounts, useApi, useIsMountedRef } from '@polkadot/react-hooks';
import { BN_ZERO, isFunction } from '@polkadot/util';
Expand Down Expand Up @@ -100,7 +101,7 @@ function filterProxies (allAccounts: string[], tx: Call | SubmittableExtrinsic<'

case 'Governance':
return checkNested(address) || (
['convictionVoting', 'council', 'councilCollective', 'democracy', 'elections', 'electionsPhragmen', 'fellowshipCollective', 'fellowshipReferenda', 'phragmenElection', 'poll', 'referenda', 'society', 'technicalCommittee', 'tips', 'treasury', 'whitelist'].includes(section)
['convictionVoting', 'council', 'councilCollective', 'democracy', 'elections', 'electionsPhragmen', 'fellowshipCollective', 'fellowshipReferenda', 'phragmenElection', 'poll', 'referenda', 'society', 'technicalCommittee', 'tips', 'treasury', 'whitelist', ...COMMITTEE_MANAGEMENT_NAMES].includes(section)
);

case 'IdentityJudgement':
Expand Down

0 comments on commit 24d03a9

Please sign in to comment.