Revert useVoter changes
This commit is contained in:
parent
355559d622
commit
15b06ed3d4
@ -3,7 +3,6 @@
|
||||
|
||||
import type { ApiPromise } from '@polkadot/api';
|
||||
import type { DeriveSocietyCandidate } from '@polkadot/api-derive/types';
|
||||
import type { Option } from '@polkadot/types';
|
||||
import type { AccountId } from '@polkadot/types/interfaces';
|
||||
import type { Voters } from './types';
|
||||
|
||||
@ -11,14 +10,12 @@ import { useEffect, useState } from 'react';
|
||||
|
||||
import { useApi, useCall, useEventTrigger } from '@polkadot/react-hooks';
|
||||
|
||||
const transformDefender = {
|
||||
transform: (opt: Option<AccountId>) => opt.unwrapOr(null)
|
||||
};
|
||||
const EMPTY_VOTERS: Voters = {};
|
||||
|
||||
async function getVoters (api: ApiPromise, defender: AccountId | null | undefined, candidates: DeriveSocietyCandidate[]): Promise<Voters> {
|
||||
const accountIds: AccountId[] = defender
|
||||
? [defender]
|
||||
: [];
|
||||
async function getVoters (api: ApiPromise, candidates: DeriveSocietyCandidate[]): Promise<Voters> {
|
||||
const accountIds: AccountId[] = [];
|
||||
const skeptics: string[] = [];
|
||||
const voters: string[] = [];
|
||||
|
||||
candidates.forEach(({ accountId }): void => {
|
||||
accountIds.push(accountId);
|
||||
@ -27,8 +24,6 @@ async function getVoters (api: ApiPromise, defender: AccountId | null | undefine
|
||||
const entries = accountIds.length
|
||||
? await Promise.all(accountIds.map((a) => api.query.society.votes.entries(a)))
|
||||
: [];
|
||||
const skeptics: string[] = [];
|
||||
const voters: string[] = [];
|
||||
|
||||
entries.forEach((list): void => {
|
||||
list.forEach(([{ args: [, accountId] }, opt]) => {
|
||||
@ -52,15 +47,12 @@ export default function useVoters (): Voters {
|
||||
const { api } = useApi();
|
||||
const voteTrigger = useEventTrigger([api.events.society.Vote]);
|
||||
const candidates = useCall<DeriveSocietyCandidate[]>(api.derive.society.candidates);
|
||||
const defender = useCall<AccountId | null>(api.query.society.defender, undefined, transformDefender);
|
||||
const [state, setState] = useState<Voters>({});
|
||||
const [state, setState] = useState<Voters>(EMPTY_VOTERS);
|
||||
|
||||
useEffect((): void => {
|
||||
console.log('useEffect', voteTrigger, candidates);
|
||||
|
||||
voteTrigger && candidates &&
|
||||
getVoters(api, defender, candidates).then(setState).catch(console.error);
|
||||
}, [api, candidates, defender, voteTrigger]);
|
||||
getVoters(api, candidates).then(setState).catch(console.error);
|
||||
}, [api, candidates, voteTrigger]);
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user