Skip to content

Commit 97d2866

Browse files
authored
Use useCollectiveModule for all collective locations (#5762)
* Use useCollectiveModule for all collective locations * staking useCollectiveModule * Bounties useCollectiveModule * Mock collective * Adjust * useMember -> useCollectiveMembers
1 parent 08f4089 commit 97d2866

32 files changed

+138
-133
lines changed

packages/page-bounties/src/Bounties.spec.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,12 @@ jest.mock('@polkadot/react-hooks/useTreasury', () => ({
2727
useTreasury: () => mockHooks.treasury
2828
}));
2929

30-
jest.mock('@polkadot/react-hooks/useMembers', () => ({
31-
useMembers: () => mockHooks.members
30+
jest.mock('@polkadot/react-hooks/useCollectiveInstance', () => ({
31+
useCollectiveInstance: () => 'council'
32+
}));
33+
34+
jest.mock('@polkadot/react-hooks/useCollectiveMembers', () => ({
35+
useCollectiveMembers: () => mockHooks.members
3236
}));
3337

3438
jest.mock('@polkadot/react-hooks/useBlockTime', () => ({

packages/page-bounties/src/BountyActions/BountyInitiateVoting.tsx

+6-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import React, { useEffect, useMemo, useRef, useState } from 'react';
99

1010
import { getTreasuryProposalThreshold } from '@polkadot/apps-config';
1111
import { Button, InputAddress, Modal, TxButton } from '@polkadot/react-components';
12-
import { useApi, useMembers, useToggle } from '@polkadot/react-hooks';
12+
import { useApi, useCollectiveInstance, useCollectiveMembers, useToggle } from '@polkadot/react-hooks';
1313

1414
import { truncateTitle } from '../helpers';
1515
import { useBounties } from '../hooks';
@@ -26,7 +26,8 @@ const BOUNTY_METHODS = ['approveBounty', 'closeBounty'];
2626
function BountyInitiateVoting ({ description, index, proposals }: Props): React.ReactElement<Props> | null {
2727
const { t } = useTranslation();
2828
const { api } = useApi();
29-
const { isMember, members } = useMembers('council');
29+
const { isMember, members } = useCollectiveMembers('council');
30+
const councilMod = useCollectiveInstance('council');
3031
const { approveBounty, closeBounty } = useBounties();
3132
const [isOpen, toggleOpen] = useToggle();
3233
const [accountId, setAccountId] = useState<string | null>(null);
@@ -43,7 +44,7 @@ function BountyInitiateVoting ({ description, index, proposals }: Props): React.
4344

4445
const isVotingInitiated = useMemo(() => proposals?.filter(({ proposal }) => BOUNTY_METHODS.includes(proposal.method)).length !== 0, [proposals]);
4546

46-
return isMember && !isVotingInitiated
47+
return isMember && !isVotingInitiated && councilMod
4748
? (
4849
<>
4950
<Button
@@ -77,7 +78,7 @@ function BountyInitiateVoting ({ description, index, proposals }: Props): React.
7778
label={t<string>('Approve')}
7879
onStart={toggleOpen}
7980
params={[threshold, approveBountyProposal.current, approveBountyProposal.current.length]}
80-
tx={api.tx.council.propose}
81+
tx={api.tx[councilMod].propose}
8182
/>
8283
<TxButton
8384
accountId={accountId}
@@ -86,7 +87,7 @@ function BountyInitiateVoting ({ description, index, proposals }: Props): React.
8687
label={t<string>('Reject')}
8788
onStart={toggleOpen}
8889
params={[threshold, closeBountyProposal.current, closeBountyProposal.current.length]}
89-
tx={api.tx.council.propose}
90+
tx={api.tx[councilMod].propose}
9091
/>
9192
</Modal.Actions>
9293
</Modal>

packages/page-bounties/src/BountyActions/ProposeCuratorAction.tsx

+5-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import React, { useEffect, useMemo, useState } from 'react';
99

1010
import { getTreasuryProposalThreshold } from '@polkadot/apps-config';
1111
import { Button, InputAddress, InputBalance, MarkError, Modal, TxButton } from '@polkadot/react-components';
12-
import { useApi, useMembers, useToggle } from '@polkadot/react-hooks';
12+
import { useApi, useCollectiveInstance, useCollectiveMembers, useToggle } from '@polkadot/react-hooks';
1313
import { BN_ZERO } from '@polkadot/util';
1414

1515
import { truncateTitle } from '../helpers';
@@ -28,7 +28,8 @@ const BOUNTY_METHODS = ['proposeCurator'];
2828
function ProposeCuratorAction ({ description, index, proposals, value }: Props): React.ReactElement<Props> | null {
2929
const { t } = useTranslation();
3030
const { api } = useApi();
31-
const { isMember, members } = useMembers('council');
31+
const { isMember, members } = useCollectiveMembers('council');
32+
const councilMod = useCollectiveInstance('council');
3233
const { proposeCurator } = useBounties();
3334
const [isOpen, toggleOpen] = useToggle();
3435
const [accountId, setAccountId] = useState<string | null>(null);
@@ -51,7 +52,7 @@ function ProposeCuratorAction ({ description, index, proposals, value }: Props):
5152
setIsFeeValid(!!value?.gt(fee));
5253
}, [value, fee]);
5354

54-
return isMember && !isVotingInitiated
55+
return isMember && !isVotingInitiated && councilMod
5556
? (
5657
<>
5758
<Button
@@ -107,7 +108,7 @@ function ProposeCuratorAction ({ description, index, proposals, value }: Props):
107108
label={t<string>('Propose curator')}
108109
onStart={toggleOpen}
109110
params={[threshold, proposeCuratorProposal, proposeCuratorProposal?.length]}
110-
tx={api.tx.council.propose}
111+
tx={api.tx[councilMod].propose}
111112
/>
112113
</Modal.Actions>
113114
</Modal>

packages/page-bounties/src/BountyExtraActions/CloseBounty.tsx

+8-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import React, { useEffect, useRef, useState } from 'react';
88

99
import { getTreasuryProposalThreshold } from '@polkadot/apps-config';
1010
import { InputAddress, Modal, TxButton } from '@polkadot/react-components';
11-
import { useApi, useMembers } from '@polkadot/react-hooks';
11+
import { useApi, useCollectiveInstance, useCollectiveMembers } from '@polkadot/react-hooks';
1212

1313
import { truncateTitle } from '../helpers';
1414
import { useBounties } from '../hooks';
@@ -23,7 +23,8 @@ interface Props {
2323
function CloseBounty ({ description, index, toggleOpen }: Props): React.ReactElement<Props> | null {
2424
const { t } = useTranslation();
2525
const { api } = useApi();
26-
const { members } = useMembers('council');
26+
const { members } = useCollectiveMembers('council');
27+
const councilMod = useCollectiveInstance('council');
2728
const { closeBounty } = useBounties();
2829
const [accountId, setAccountId] = useState<string | null>(null);
2930
const [threshold, setThreshold] = useState<BN>();
@@ -36,6 +37,10 @@ function CloseBounty ({ description, index, toggleOpen }: Props): React.ReactEle
3637

3738
const closeBountyProposal = useRef(closeBounty(index));
3839

40+
if (!councilMod) {
41+
return null;
42+
}
43+
3944
return (
4045
<Modal
4146
header={`${t<string>('close bounty')} - "${truncateTitle(description, 30)}"`}
@@ -61,7 +66,7 @@ function CloseBounty ({ description, index, toggleOpen }: Props): React.ReactEle
6166
label={t<string>('Close Bounty')}
6267
onStart={toggleOpen}
6368
params={[threshold, closeBountyProposal.current, closeBountyProposal.current.length]}
64-
tx={api.tx.council.propose}
69+
tx={api.tx[councilMod].propose}
6570
/>
6671
</Modal.Actions>
6772
</Modal>

packages/page-bounties/src/BountyExtraActions/SlashCurator.tsx

+11-6
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import React, { useEffect, useMemo, useState } from 'react';
99
import { SubmittableExtrinsic } from '@polkadot/api/types';
1010
import { getTreasuryProposalThreshold } from '@polkadot/apps-config';
1111
import { InputAddress, Modal, TxButton } from '@polkadot/react-components';
12-
import { useAccounts, useApi, useMembers } from '@polkadot/react-hooks';
12+
import { useAccounts, useApi, useCollectiveInstance, useCollectiveMembers } from '@polkadot/react-hooks';
1313

1414
import { truncateTitle } from '../helpers';
1515
import { useBounties } from '../hooks';
@@ -32,13 +32,14 @@ interface ActionProperties {
3232
proposingAccountTip: string;
3333
tip: string;
3434
title: string;
35-
tx: ((...args: any[]) => SubmittableExtrinsic<'promise'>);
35+
tx: null | ((...args: any[]) => SubmittableExtrinsic<'promise'>);
3636
}
3737

3838
function SlashCurator ({ action, curatorId, description, index, toggleOpen }: Props): React.ReactElement<Props> | null {
3939
const { t } = useTranslation();
4040
const { api } = useApi();
41-
const { members } = useMembers('council');
41+
const { members } = useCollectiveMembers('council');
42+
const councilMod = useCollectiveInstance('council');
4243
const { unassignCurator } = useBounties();
4344
const [accountId, setAccountId] = useState<string | null>(null);
4445
const [threshold, setThreshold] = useState<BN>();
@@ -71,7 +72,7 @@ function SlashCurator ({ action, curatorId, description, index, toggleOpen }: Pr
7172
proposingAccountTip: t('The council member that will create the motion, submission equates to an "aye" vote.'),
7273
tip: t("If the motion is approved, Curator's deposit will be slashed and Curator will be unassigned. Bounty will return to the Funded state."),
7374
title: t('Slash curator'),
74-
tx: api.tx.council.propose
75+
tx: councilMod && api.tx[councilMod].propose
7576
},
7677
UnassignCurator: {
7778
filter: members,
@@ -81,12 +82,16 @@ function SlashCurator ({ action, curatorId, description, index, toggleOpen }: Pr
8182
proposingAccountTip: t('The council member that will create the motion, submission equates to an "aye" vote.'),
8283
tip: t('If the motion is approved, the current Curator will be unassigned and the Bounty will return to the Funded state.'),
8384
title: t('Unassign curator'),
84-
tx: api.tx.council.propose
85+
tx: councilMod && api.tx[councilMod].propose
8586
}
86-
}), [t, index, unassignCurator, api.tx.council.propose, allAccounts, members, threshold, unassignCuratorProposal]);
87+
}), [t, index, unassignCurator, api, allAccounts, councilMod, members, threshold, unassignCuratorProposal]);
8788

8889
const { filter, helpMessage, params, proposingAccountTip, tip, title, tx } = actionProperties[action];
8990

91+
if (!tx) {
92+
return null;
93+
}
94+
9095
return (
9196
<Modal
9297
header={`${title} - "${truncateTitle(description, 30)}"`}

packages/page-bounties/src/BountyExtraActions/index.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import React, { useMemo, useRef, useState } from 'react';
55

66
import { DeriveCollectiveProposal } from '@polkadot/api-derive/types';
77
import { Button, Menu, Popup } from '@polkadot/react-components';
8-
import { useMembers, useToggle } from '@polkadot/react-hooks';
8+
import { useCollectiveMembers, useToggle } from '@polkadot/react-hooks';
99
import { BlockNumber, BountyIndex, BountyStatus } from '@polkadot/types/interfaces';
1010

1111
import { determineUnassignCuratorAction } from '../helpers';
@@ -36,7 +36,7 @@ function Index ({ bestNumber, className, description, index, proposals, status }
3636
const [isGiveUpCuratorOpen, toggleGiveUpCurator] = useToggle();
3737
const [selectedAction, setSlashAction] = useState<ValidUnassignCuratorAction>();
3838
const { t } = useTranslation();
39-
const { isMember } = useMembers('council');
39+
const { isMember } = useCollectiveMembers('council');
4040
const { curator, updateDue } = useBountyStatus(status);
4141

4242
const blocksUntilUpdate = useMemo(() => updateDue?.sub(bestNumber), [bestNumber, updateDue]);

packages/page-bounties/src/BountyInfos/VotingSummary.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import React, { useMemo } from 'react';
88
import styled from 'styled-components';
99

1010
import VotingDescriptionInfo from '@polkadot/app-bounties/BountyInfos/VotingDescriptionInfo';
11-
import { useMembers } from '@polkadot/react-hooks';
11+
import { useCollectiveMembers } from '@polkadot/react-hooks';
1212

1313
import { useTranslation } from '../translate';
1414
import VotingLink from './VotingLink';
@@ -20,7 +20,7 @@ interface Props {
2020
}
2121

2222
function VotingSummary ({ className, proposal, status }: Props): JSX.Element {
23-
const { members } = useMembers('council');
23+
const { members } = useCollectiveMembers('council');
2424
const { t } = useTranslation();
2525
const ayes = useMemo(() => proposal?.votes?.ayes?.length, [proposal]);
2626
const nays = useMemo(() => proposal?.votes?.nays?.length, [proposal]);

packages/page-bounties/src/hooks/useUserRole.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type { AccountId } from '@polkadot/types/interfaces';
55

66
import { useMemo } from 'react';
77

8-
import { useAccounts, useMembers } from '@polkadot/react-hooks';
8+
import { useAccounts, useCollectiveMembers } from '@polkadot/react-hooks';
99

1010
import { UserRole } from '../types';
1111

@@ -14,7 +14,7 @@ export type UserRolesInfo = { roles: UserRole[], isCurator: boolean };
1414
export function useUserRole (curatorId?: AccountId): UserRolesInfo {
1515
const { allAccounts, hasAccounts } = useAccounts();
1616

17-
const { isMember } = useMembers('council');
17+
const { isMember } = useCollectiveMembers('council');
1818

1919
const isCurator = useMemo(() => curatorId && allAccounts.includes(curatorId.toString()), [allAccounts, curatorId]);
2020

packages/page-council/src/Motions/Close.tsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@ import type { Hash, Proposal, ProposalIndex } from '@polkadot/types/interfaces';
66
import React, { useState } from 'react';
77

88
import { Button, InputAddress, Modal, ProposedAction, TxButton } from '@polkadot/react-components';
9-
import { useApi, useToggle, useWeight } from '@polkadot/react-hooks';
9+
import { useApi, useCollectiveInstance, useToggle, useWeight } from '@polkadot/react-hooks';
1010

1111
import { useTranslation } from '../translate';
12-
import { useModuleCouncil } from '../useModuleCouncil';
1312

1413
interface Props {
1514
hasFailed: boolean;
@@ -25,7 +24,7 @@ function Close ({ hasFailed, hash, idNumber, members, proposal }: Props): React.
2524
const [isOpen, toggleOpen] = useToggle();
2625
const [accountId, setAccountId] = useState<string | null>(null);
2726
const [proposalWeight, proposalLength] = useWeight(proposal);
28-
const modLocation = useModuleCouncil();
27+
const modLocation = useCollectiveInstance('council');
2928

3029
// protect against older versions
3130
if (!modLocation) {

packages/page-council/src/Motions/Motion.tsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@ import React, { useMemo } from 'react';
88

99
import ProposalCell from '@polkadot/app-democracy/Overview/ProposalCell';
1010
import { Icon, LinkExternal, TxButton } from '@polkadot/react-components';
11-
import { useAccounts, useApi, useVotingStatus, useWeight } from '@polkadot/react-hooks';
11+
import { useAccounts, useApi, useCollectiveInstance, useVotingStatus, useWeight } from '@polkadot/react-hooks';
1212
import { BlockToTime } from '@polkadot/react-query';
1313
import { formatNumber } from '@polkadot/util';
1414

1515
import { useTranslation } from '../translate';
16-
import { useModuleCouncil } from '../useModuleCouncil';
1716
import Close from './Close';
1817
import Voters from './Voters';
1918
import Voting from './Voting';
@@ -37,7 +36,7 @@ function Motion ({ className = '', isMember, members, motion: { hash, proposal,
3736
const { allAccounts } = useAccounts();
3837
const { hasFailed, isCloseable, isVoteable, remainingBlocks } = useVotingStatus(votes, members.length, 'council');
3938
const [proposalWeight, proposalLength] = useWeight(proposal);
40-
const modLocation = useModuleCouncil();
39+
const modLocation = useCollectiveInstance('council');
4140

4241
const [councilId, isMultiMembers] = useMemo(
4342
(): [string | null, boolean] => {

packages/page-council/src/Motions/ProposeExternal.tsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@ import React, { useCallback, useEffect, useState } from 'react';
77

88
import { getProposalThreshold } from '@polkadot/apps-config';
99
import { Button, Input, InputAddress, Modal, TxButton } from '@polkadot/react-components';
10-
import { useApi, useToggle } from '@polkadot/react-hooks';
10+
import { useApi, useCollectiveInstance, useToggle } from '@polkadot/react-hooks';
1111
import { isHex } from '@polkadot/util';
1212

1313
import { useTranslation } from '../translate';
14-
import { useModuleCouncil } from '../useModuleCouncil';
1514

1615
interface Props {
1716
className?: string;
@@ -36,7 +35,7 @@ function ProposeExternal ({ className = '', isMember, members }: Props): React.R
3635
const [accountId, setAcountId] = useState<string | null>(null);
3736
const [{ proposal, proposalLength }, setProposal] = useState<ProposalState>({ proposalLength: 0 });
3837
const [{ hash, isHashValid }, setHash] = useState<HashState>({ hash: '', isHashValid: false });
39-
const modLocation = useModuleCouncil();
38+
const modLocation = useCollectiveInstance('council');
4039

4140
const threshold = Math.ceil((members.length || 0) * getProposalThreshold(api));
4241

packages/page-council/src/Motions/ProposeMotion.tsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@ import React, { useCallback, useEffect, useState } from 'react';
88

99
import { getProposalThreshold } from '@polkadot/apps-config';
1010
import { Button, Extrinsic, InputAddress, InputNumber, Modal, TxButton } from '@polkadot/react-components';
11-
import { useApi, useToggle } from '@polkadot/react-hooks';
11+
import { useApi, useCollectiveInstance, useToggle } from '@polkadot/react-hooks';
1212
import { BN_ZERO } from '@polkadot/util';
1313

1414
import { useTranslation } from '../translate';
15-
import { useModuleCouncil } from '../useModuleCouncil';
1615

1716
interface Props {
1817
isMember: boolean;
@@ -36,7 +35,7 @@ function Propose ({ isMember, members }: Props): React.ReactElement<Props> | nul
3635
const [accountId, setAcountId] = useState<string | null>(null);
3736
const [{ proposal, proposalLength }, setProposal] = useState<ProposalState>({ proposalLength: 0 });
3837
const [{ isThresholdValid, threshold }, setThreshold] = useState<Threshold>({ isThresholdValid: false });
39-
const modLocation = useModuleCouncil();
38+
const modLocation = useCollectiveInstance('council');
4039

4140
useEffect((): void => {
4241
members && setThreshold({

packages/page-council/src/Motions/Slashing.tsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@ import React, { useEffect, useMemo, useState } from 'react';
77

88
import { getSlashProposalThreshold } from '@polkadot/apps-config';
99
import { Button, Dropdown, Input, InputAddress, Modal, TxButton } from '@polkadot/react-components';
10-
import { useApi, useAvailableSlashes, useToggle } from '@polkadot/react-hooks';
10+
import { useApi, useAvailableSlashes, useCollectiveInstance, useToggle } from '@polkadot/react-hooks';
1111

1212
import { useTranslation } from '../translate';
13-
import { useModuleCouncil } from '../useModuleCouncil';
1413

1514
interface Props {
1615
className?: string;
@@ -36,7 +35,7 @@ function Slashing ({ className = '', isMember, members }: Props): React.ReactEle
3635
const [accountId, setAcountId] = useState<string | null>(null);
3736
const [{ proposal, proposalLength }, setProposal] = useState<ProposalState>({ proposal: null, proposalLength: 0 });
3837
const [selectedEra, setSelectedEra] = useState(0);
39-
const modLocation = useModuleCouncil();
38+
const modLocation = useCollectiveInstance('council');
4039

4140
const threshold = Math.ceil((members.length || 0) * getSlashProposalThreshold(api));
4241

packages/page-council/src/Motions/Voting.tsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@ import type { AccountId, Hash, Proposal, ProposalIndex } from '@polkadot/types/i
66
import React, { useState } from 'react';
77

88
import { Button, MarkWarning, Modal, ProposedAction, TxButton, VoteAccount } from '@polkadot/react-components';
9-
import { useAccounts, useApi, useToggle } from '@polkadot/react-hooks';
9+
import { useAccounts, useApi, useCollectiveInstance, useToggle } from '@polkadot/react-hooks';
1010

1111
import { useTranslation } from '../translate';
12-
import { useModuleCouncil } from '../useModuleCouncil';
1312

1413
interface Props {
1514
hash: Hash;
@@ -26,7 +25,7 @@ function Voting ({ hash, idNumber, isDisabled, members, prime, proposal }: Props
2625
const { hasAccounts } = useAccounts();
2726
const [isVotingOpen, toggleVoting] = useToggle();
2827
const [accountId, setAccountId] = useState<string | null>(null);
29-
const modLocation = useModuleCouncil();
28+
const modLocation = useCollectiveInstance('council');
3029

3130
if (!hasAccounts || !modLocation) {
3231
return null;

packages/page-council/src/Motions/index.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type { AccountId } from '@polkadot/types/interfaces';
77
import React, { useRef } from 'react';
88

99
import { Button, Table } from '@polkadot/react-components';
10-
import { useMembers } from '@polkadot/react-hooks';
10+
import { useCollectiveMembers } from '@polkadot/react-hooks';
1111

1212
import { useTranslation } from '../translate';
1313
import Motion from './Motion';
@@ -23,7 +23,7 @@ interface Props {
2323

2424
function Proposals ({ className = '', motions, prime }: Props): React.ReactElement<Props> {
2525
const { t } = useTranslation();
26-
const { isMember, members } = useMembers('council');
26+
const { isMember, members } = useCollectiveMembers('council');
2727

2828
const headerRef = useRef([
2929
[t('motions'), 'start', 2],

0 commit comments

Comments
 (0)