Skip to content

Commit

Permalink
Fix BountyType with new PalletBountiesBounty (#11204)
Browse files Browse the repository at this point in the history
* fix: types for Bounties test

* fix: types for bounties page and related components
  • Loading branch information
ap211unitech authored Jan 15, 2025
1 parent a9118af commit e97d156
Show file tree
Hide file tree
Showing 17 changed files with 58 additions and 70 deletions.
31 changes: 11 additions & 20 deletions packages/page-bounties/src/Bounties.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import type { ApiPromise } from '@polkadot/api';
import type { SubmittableExtrinsic } from '@polkadot/api/types';
import type { DeriveCollectiveProposal } from '@polkadot/api-derive/types';
import type { BountyIndex, BountyStatus } from '@polkadot/types/interfaces';
import type { BountyIndex } from '@polkadot/types/interfaces';
import type { PalletBountiesBounty, PalletBountiesBountyStatus } from '@polkadot/types/lookup';

import { fireEvent } from '@testing-library/react';
Expand Down Expand Up @@ -55,7 +55,7 @@ let aProposal: (extrinsic: SubmittableExtrinsic<'promise'>, ayes?: string[], nay
let augmentedApi: ApiPromise;
let aBounty: ({ status, value }?: Partial<PalletBountiesBounty>) => PalletBountiesBounty;
let aBountyIndex: (index?: number) => BountyIndex;
let bountyStatusWith: ({ curator, status, updateDue }: { curator?: string, status?: string, updateDue?: number}) => BountyStatus;
let bountyStatusWith: ({ curator, status, updateDue }: { curator?: string, status?: string, updateDue?: number}) => PalletBountiesBountyStatus;
let bountyWith: ({ status, value }: { status?: string, value?: number }) => PalletBountiesBounty;

describe('Bounties', () => {
Expand Down Expand Up @@ -347,8 +347,7 @@ describe('Bounties', () => {

describe('Reject curator modal', () => {
it('creates extrinsic', async () => {
// FIXME: https://github.com/polkadot-js/apps/issues/11192
const bounty = aBounty({ status: bountyStatusWith({ curator: bob, status: 'CuratorProposed' }) as unknown as PalletBountiesBountyStatus });
const bounty = aBounty({ status: bountyStatusWith({ curator: bob, status: 'CuratorProposed' }) });

bountiesPage.renderOne(bounty);

Expand All @@ -359,8 +358,7 @@ describe('Bounties', () => {
});

it('shows options for all roles', async () => {
// FIXME: https://github.com/polkadot-js/apps/issues/11192
const bounty = aBounty({ status: bountyStatusWith({ curator: bob, status: 'Active' }) as unknown as PalletBountiesBountyStatus });
const bounty = aBounty({ status: bountyStatusWith({ curator: bob, status: 'Active' }) });

bountiesPage.renderOne(bounty);

Expand All @@ -374,8 +372,7 @@ describe('Bounties', () => {
it('creates extrinsic', async () => {
const bounty = aBounty({
fee: balanceOf(20),
// FIXME: https://github.com/polkadot-js/apps/issues/11192
status: bountyStatusWith({ curator: bob, status: 'CuratorProposed' }) as unknown as PalletBountiesBountyStatus
status: bountyStatusWith({ curator: bob, status: 'CuratorProposed' })
});

bountiesPage.renderOne(bounty);
Expand All @@ -393,8 +390,7 @@ describe('Bounties', () => {

describe('extend bounty expiry action modal', () => {
it('queues extend bounty expiry extrinsic on submit', async () => {
// FIXME: https://github.com/polkadot-js/apps/issues/11192
const bounty = aBounty({ status: bountyStatusWith({ curator: alice }) as unknown as PalletBountiesBountyStatus });
const bounty = aBounty({ status: bountyStatusWith({ curator: alice }) });

bountiesPage.renderOne(bounty);
await bountiesPage.openExtendExpiry();
Expand All @@ -409,8 +405,7 @@ describe('Bounties', () => {

describe('give up curator modal', () => {
it('gives up on the Curator role of an Active bounty', async () => {
// FIXME: https://github.com/polkadot-js/apps/issues/11192
const bounty = aBounty({ status: bountyStatusWith({ curator: alice }) as unknown as PalletBountiesBountyStatus });
const bounty = aBounty({ status: bountyStatusWith({ curator: alice }) });

bountiesPage.renderOne(bounty);
await bountiesPage.openGiveUpCuratorsRole();
Expand Down Expand Up @@ -439,8 +434,7 @@ describe('Bounties', () => {

describe('award beneficiary action modal', () => {
it('awards the beneficiary', async () => {
// FIXME: https://github.com/polkadot-js/apps/issues/11192
const bounty = aBounty({ status: bountyStatusWith({ curator: alice }) as unknown as PalletBountiesBountyStatus });
const bounty = aBounty({ status: bountyStatusWith({ curator: alice }) });

bountiesPage.renderOne(bounty);

Expand All @@ -460,8 +454,7 @@ describe('Bounties', () => {
curator: alice,
status: 'Active',
updateDue: defaultBountyUpdatePeriod.muln(BLOCKS_PERCENTAGE_LEFT_TO_SHOW_WARNING).divn(100).toNumber() - 1
// FIXME: https://github.com/polkadot-js/apps/issues/11192
}) as unknown as PalletBountiesBountyStatus });
}) });

bountiesPage.renderOne(bounty);

Expand All @@ -474,8 +467,7 @@ describe('Bounties', () => {
curator: alice,
status: 'Active',
updateDue: mockBountyHooks.bountyApi.bestNumber?.toNumber()
// FIXME: https://github.com/polkadot-js/apps/issues/11192
}) as unknown as PalletBountiesBountyStatus });
}) });

bountiesPage.renderOne(bounty);

Expand Down Expand Up @@ -511,8 +503,7 @@ describe('Bounties', () => {
curator: alice,
status: 'Active',
updateDue: defaultBountyUpdatePeriod.muln(BLOCKS_PERCENTAGE_LEFT_TO_SHOW_WARNING).divn(100).toNumber() + 1
// FIXME: https://github.com/polkadot-js/apps/issues/11192
}) as unknown as PalletBountiesBountyStatus });
}) });

bountiesPage.renderOne(bounty);
await bountiesPage.rendered();
Expand Down
7 changes: 1 addition & 6 deletions packages/page-bounties/src/Bounties.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright 2017-2025 @polkadot/app-bounties authors & contributors
// SPDX-License-Identifier: Apache-2.0

import type { Bounty as BountyType } from '@polkadot/types/interfaces';

import React, { useMemo, useRef } from 'react';

import { Button, styled, Table } from '@polkadot/react-components';
Expand Down Expand Up @@ -48,10 +46,7 @@ function Bounties ({ className }: Props): React.ReactElement {
{sorted && bestNumber && sorted.map(({ bounty, description, index, proposals }) => (
<Bounty
bestNumber={bestNumber}
// TODO: The bounty type here is now expected as PalletBountiesBounty type in the latest substrate release.
// This will require forward and backwards compatibility with the older Bounty type and the newer lookup type.
// ref: https://github.com/polkadot-js/apps/issues/11192
bounty={bounty as unknown as BountyType}
bounty={bounty}
description={description}
index={index}
key={index.toNumber()}
Expand Down
5 changes: 3 additions & 2 deletions packages/page-bounties/src/Bounty.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
// SPDX-License-Identifier: Apache-2.0

import type { DeriveCollectiveProposal } from '@polkadot/api-derive/types';
import type { Bounty as BountyType, BountyIndex } from '@polkadot/types/interfaces';
import type { BountyIndex } from '@polkadot/types/interfaces';
import type { PalletBountiesBounty } from '@polkadot/types/lookup';
import type { BN } from '@polkadot/util';

import React, { useMemo } from 'react';
Expand All @@ -25,7 +26,7 @@ import VotersColumn from './VotersColumn.js';

interface Props {
bestNumber: BN;
bounty: BountyType;
bounty: PalletBountiesBounty;
className?: string;
description: string;
index: BountyIndex;
Expand Down
5 changes: 3 additions & 2 deletions packages/page-bounties/src/BountyActions/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
// SPDX-License-Identifier: Apache-2.0

import type { DeriveCollectiveProposal } from '@polkadot/api-derive/types';
import type { Balance, BountyIndex, BountyStatus } from '@polkadot/types/interfaces';
import type { Balance, BountyIndex } from '@polkadot/types/interfaces';
import type { PalletBountiesBountyStatus } from '@polkadot/types/lookup';
import type { BN } from '@polkadot/util';

import React, { useMemo } from 'react';
Expand All @@ -20,7 +21,7 @@ interface Props {
fee?: BN;
index: BountyIndex;
proposals?: DeriveCollectiveProposal[];
status: BountyStatus;
status: PalletBountiesBountyStatus;
value: Balance;
}

Expand Down
5 changes: 3 additions & 2 deletions packages/page-bounties/src/BountyExtraActions/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
// SPDX-License-Identifier: Apache-2.0

import type { DeriveCollectiveProposal } from '@polkadot/api-derive/types';
import type { BountyIndex, BountyStatus } from '@polkadot/types/interfaces';
import type { BountyIndex } from '@polkadot/types/interfaces';
import type { PalletBountiesBountyStatus } from '@polkadot/types/lookup';
import type { BN } from '@polkadot/util';
import type { ValidUnassignCuratorAction } from '../types.js';

Expand All @@ -26,7 +27,7 @@ interface Props {
description: string;
index: BountyIndex;
proposals?: DeriveCollectiveProposal[];
status: BountyStatus;
status: PalletBountiesBountyStatus;
}

function Index ({ bestNumber, className, description, index, proposals, status }: Props): React.ReactElement<Props> | null {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

import type { DeriveCollectiveProposal } from '@polkadot/api-derive/types';
import type { BountyStatus } from '@polkadot/types/interfaces';
import type { PalletBountiesBountyStatus } from '@polkadot/types/lookup';

import React, { useRef } from 'react';

Expand All @@ -14,7 +14,7 @@ import { useTranslation } from '../translate.js';
interface Props {
className?: string;
proposal: DeriveCollectiveProposal;
status: BountyStatus;
status: PalletBountiesBountyStatus;
}

function VotingDescriptionInfo ({ className, proposal, status }: Props): React.ReactElement<Props> {
Expand Down
4 changes: 2 additions & 2 deletions packages/page-bounties/src/BountyInfos/VotingSummary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

import type { DeriveCollectiveProposal } from '@polkadot/api-derive/types';
import type { BountyStatus } from '@polkadot/types/interfaces';
import type { PalletBountiesBountyStatus } from '@polkadot/types/lookup';

import React, { useMemo } from 'react';

Expand All @@ -16,7 +16,7 @@ import VotingLink from './VotingLink.js';
interface Props {
className?: string;
proposal: DeriveCollectiveProposal;
status: BountyStatus;
status: PalletBountiesBountyStatus;
}

function VotingSummary ({ className, proposal, status }: Props): React.ReactElement<Props> {
Expand Down
5 changes: 3 additions & 2 deletions packages/page-bounties/src/BountyInfos/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
// SPDX-License-Identifier: Apache-2.0

import type { DeriveCollectiveProposal } from '@polkadot/api-derive/types';
import type { AccountId, BountyStatus } from '@polkadot/types/interfaces';
import type { AccountId } from '@polkadot/types/interfaces';
import type { PalletBountiesBountyStatus } from '@polkadot/types/lookup';

import React, { useMemo } from 'react';

Expand All @@ -16,7 +17,7 @@ import VotingSummary from './VotingSummary.js';
interface Props {
beneficiary?: AccountId;
proposals?: DeriveCollectiveProposal[];
status: BountyStatus;
status: PalletBountiesBountyStatus;
}

function BountyInfos ({ beneficiary, proposals, status }: Props): React.ReactElement<Props> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2017-2025 @polkadot/app-bounties authors & contributors
// SPDX-License-Identifier: Apache-2.0

import type { BountyStatus } from '@polkadot/types/interfaces';
import type { PalletBountiesBountyStatus } from '@polkadot/types/lookup';

import React, { useMemo } from 'react';

Expand All @@ -14,7 +14,7 @@ import BountyInfo from './BountyInfo.js';
interface Props {
bestNumber: BN;
blocksUntilUpdate?: BN;
status: BountyStatus;
status: PalletBountiesBountyStatus;
}

export const BLOCKS_PERCENTAGE_LEFT_TO_SHOW_WARNING = 10;
Expand Down
4 changes: 2 additions & 2 deletions packages/page-bounties/src/VotersColumn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import type { IconName } from '@fortawesome/fontawesome-svg-core';
import type { DeriveCollectiveProposal } from '@polkadot/api-derive/types';
import type { BountyStatus } from '@polkadot/types/interfaces';
import type { PalletBountiesBountyStatus } from '@polkadot/types/lookup';

import React, { useMemo } from 'react';

Expand All @@ -16,7 +16,7 @@ interface Props {
className?: string;
option: 'ayes' | 'nays';
proposals: DeriveCollectiveProposal[];
status: BountyStatus;
status: PalletBountiesBountyStatus;
}

const icons: Record<string, IconName> = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Copyright 2017-2025 @polkadot/app-bounties authors & contributors
// SPDX-License-Identifier: Apache-2.0

import type { BountyStatus } from '@polkadot/types/interfaces';
import type { PalletBountiesBountyStatus } from '@polkadot/types/lookup';
import type { BN } from '@polkadot/util';
import type { UserRole, ValidUnassignCuratorAction } from '../types.js';

import { BN_ZERO } from '@polkadot/util';

export function determineUnassignCuratorAction (roles: UserRole[], status: BountyStatus, blocksUntilUpdate?: BN): ValidUnassignCuratorAction[] {
export function determineUnassignCuratorAction (roles: UserRole[], status: PalletBountiesBountyStatus, blocksUntilUpdate?: BN): ValidUnassignCuratorAction[] {
const actions: ValidUnassignCuratorAction[] = [];

if (status.isCuratorProposed && roles.includes('Member')) {
Expand Down
10 changes: 5 additions & 5 deletions packages/page-bounties/src/helpers/extendedStatuses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

import type { DeriveCollectiveProposal } from '@polkadot/api-derive/types';
import type { BountyStatus } from '@polkadot/types/interfaces';
import type { PalletBountiesBountyStatus } from '@polkadot/types/lookup';
import type { BountyVotingStatuses, StatusName } from '../types.js';

const validProposalNames: BountyVotingStatuses = {
Expand All @@ -14,29 +14,29 @@ const validProposalNames: BountyVotingStatuses = {
Proposed: ['approveBounty', 'closeBounty']
};

function validMethods (status: BountyStatus): string[] {
function validMethods (status: PalletBountiesBountyStatus): string[] {
return validProposalNames[status.type as StatusName];
}

function getProposalByMethod (bountyProposals: DeriveCollectiveProposal[], method: string | undefined): DeriveCollectiveProposal | undefined {
return bountyProposals.find(({ proposal }) => proposal && proposal.method === method);
}

function bestValidProposalName (bountyProposals: DeriveCollectiveProposal[], status: BountyStatus): string | undefined {
function bestValidProposalName (bountyProposals: DeriveCollectiveProposal[], status: PalletBountiesBountyStatus): string | undefined {
const methods = bountyProposals.map(({ proposal }) => proposal?.method);

return validMethods(status).find((method) => methods.includes(method));
}

export function proposalNameToDisplay (bountyProposal: DeriveCollectiveProposal, status: BountyStatus): string | undefined {
export function proposalNameToDisplay (bountyProposal: DeriveCollectiveProposal, status: PalletBountiesBountyStatus): string | undefined {
if (bountyProposal.proposal && bountyProposal.proposal.method !== 'unassignCurator') {
return bountyProposal.proposal.method;
}

return status.isCuratorProposed ? 'unassignCurator' : 'slashCurator';
}

export function getProposalToDisplay (bountyProposals: DeriveCollectiveProposal[], status: BountyStatus): DeriveCollectiveProposal | null {
export function getProposalToDisplay (bountyProposals: DeriveCollectiveProposal[], status: PalletBountiesBountyStatus): DeriveCollectiveProposal | null {
const method = bestValidProposalName(bountyProposals, status);

return getProposalByMethod(bountyProposals, method) ?? null;
Expand Down
6 changes: 3 additions & 3 deletions packages/page-bounties/src/helpers/getBountyStatus.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,22 @@ describe('get bounty status', () => {
});

it('for CuratorProposed state it has curator defined', () => {
const bountyStatus = getBountyStatus(registry.createType('BountyStatus', 'CuratorProposed'));
const bountyStatus = getBountyStatus(registry.createType('PalletBountiesBountyStatus', 'CuratorProposed'));

expect(bountyStatus.bountyStatus).toEqual('CuratorProposed');
expect(bountyStatus.curator).toBeDefined();
});

it('for Active state it has curator and update due defined', () => {
const bountyStatus = getBountyStatus(registry.createType('BountyStatus', 'Active'));
const bountyStatus = getBountyStatus(registry.createType('PalletBountiesBountyStatus', 'Active'));

expect(bountyStatus.bountyStatus).toEqual('Active');
expect(bountyStatus.curator).toBeDefined();
expect(bountyStatus.updateDue).toBeDefined();
});

it('for PendingPayout state it has curator, beneficiary and unlock_at defined', () => {
const bountyStatus = getBountyStatus(registry.createType('BountyStatus', 'PendingPayout'));
const bountyStatus = getBountyStatus(registry.createType('PalletBountiesBountyStatus', 'PendingPayout'));

expect(bountyStatus.bountyStatus).toEqual('PendingPayout');
expect(bountyStatus.curator).toBeDefined();
Expand Down
4 changes: 2 additions & 2 deletions packages/page-bounties/src/helpers/getBountyStatus.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Copyright 2017-2025 @polkadot/app-bounties authors & contributors
// SPDX-License-Identifier: Apache-2.0

import type { BountyStatus } from '@polkadot/types/interfaces';
import type { PalletBountiesBountyStatus } from '@polkadot/types/lookup';
import type { BountyStatusType, StatusName } from '../types.js';

export const getBountyStatus = (status: BountyStatus): BountyStatusType => {
export const getBountyStatus = (status: PalletBountiesBountyStatus): BountyStatusType => {
const statusAsString = status.type as StatusName;

let result: BountyStatusType = {
Expand Down
4 changes: 2 additions & 2 deletions packages/page-bounties/src/hooks/useBountyStatus.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2017-2025 @polkadot/app-bounties authors & contributors
// SPDX-License-Identifier: Apache-2.0

import type { BountyStatus } from '@polkadot/types/interfaces';
import type { PalletBountiesBountyStatus } from '@polkadot/types/lookup';
import type { BountyStatusType } from '../types.js';

import { useCallback } from 'react';
Expand All @@ -10,7 +10,7 @@ import { createNamedHook } from '@polkadot/react-hooks';

import { getBountyStatus } from '../helpers/index.js';

function useBountyStatusImpl (status: BountyStatus): BountyStatusType {
function useBountyStatusImpl (status: PalletBountiesBountyStatus): BountyStatusType {
const updateStatus = useCallback(() => getBountyStatus(status), [status]);

return updateStatus();
Expand Down
Loading

0 comments on commit e97d156

Please sign in to comment.