Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move usePreimage to react-hooks #8796

Merged
merged 3 commits into from
Jan 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions packages/page-council/src/Motions/ProposeExternal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ import type { HexString } from '@polkadot/util/types';

import React, { useCallback, useEffect, useState } from 'react';

import usePreimage from '@polkadot/app-preimages/usePreimage';
import { getProposalThreshold } from '@polkadot/apps-config';
import { Button, Input, InputAddress, Modal, TxButton } from '@polkadot/react-components';
import { useApi, useCollectiveInstance, useToggle } from '@polkadot/react-hooks';
import { useApi, useCollectiveInstance, usePreimage, useToggle } from '@polkadot/react-hooks';
import { isFunction, isHex } from '@polkadot/util';

import { useTranslation } from '../translate';
Expand Down
3 changes: 1 addition & 2 deletions packages/page-democracy/src/Overview/ProposalCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ import type { HexString } from '@polkadot/util/types';
import React from 'react';
import styled from 'styled-components';

import usePreimage from '@polkadot/app-preimages/usePreimage';
import { CallExpander } from '@polkadot/react-components';
import { useApi } from '@polkadot/react-hooks';
import { useApi, usePreimage } from '@polkadot/react-hooks';

import { useTranslation } from '../translate';
import ExternalCell from './ExternalCell';
Expand Down
3 changes: 1 addition & 2 deletions packages/page-democracy/src/Overview/Propose.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ import type { HexString } from '@polkadot/util/types';

import React, { useCallback, useState } from 'react';

import usePreimage from '@polkadot/app-preimages/usePreimage';
import { Input, InputAddress, InputBalance, Modal, TxButton } from '@polkadot/react-components';
import { useApi, useCall } from '@polkadot/react-hooks';
import { useApi, useCall, usePreimage } from '@polkadot/react-hooks';
import { Available } from '@polkadot/react-query';
import { isFunction, isHex } from '@polkadot/util';

Expand Down
2 changes: 1 addition & 1 deletion packages/page-preimages/src/Preimages/Call.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2017-2023 @polkadot/app-preimages authors & contributors
// SPDX-License-Identifier: Apache-2.0

import type { Preimage } from '../types';
import type { Preimage } from '@polkadot/react-hooks/types';

import React from 'react';

Expand Down
2 changes: 1 addition & 1 deletion packages/page-preimages/src/Preimages/Free.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2017-2023 @polkadot/app-preimages authors & contributors
// SPDX-License-Identifier: Apache-2.0

import type { Preimage } from '../types';
import type { Preimage } from '@polkadot/react-hooks/types';

import React, { useMemo } from 'react';

Expand Down
2 changes: 1 addition & 1 deletion packages/page-preimages/src/Preimages/Preimage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import type { HexString } from '@polkadot/util/types';

import React from 'react';

import { usePreimage } from '@polkadot/react-hooks';
import { formatNumber } from '@polkadot/util';

import usePreimage from '../usePreimage';
import Call from './Call';
import Free from './Free';
import Hash from './Hash';
Expand Down
35 changes: 0 additions & 35 deletions packages/page-preimages/src/types.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/page-referenda/src/Referenda/RefOngoing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import type { Referendum, ReferendumProps as Props } from '../types';

import React, { useMemo } from 'react';

import usePreimage, { getPreimageHash } from '@polkadot/app-preimages/usePreimage';
import { CallExpander, Progress } from '@polkadot/react-components';
import { getPreimageHash, usePreimage } from '@polkadot/react-hooks/usePreimage';

import { useTranslation } from '../translate';
import Deposits from './Deposits';
Expand Down
3 changes: 1 addition & 2 deletions packages/page-referenda/src/Referenda/Submit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ import type { PalletReferenda, TrackDescription } from '../types';
import React, { useCallback, useEffect, useMemo, useState } from 'react';
import styled from 'styled-components';

import usePreimage from '@polkadot/app-preimages/usePreimage';
import { Button, Dropdown, Input, InputAddress, InputBalance, InputNumber, Modal, ToggleGroup, TxButton } from '@polkadot/react-components';
import { useApi, useBestNumber, useToggle } from '@polkadot/react-hooks';
import { useApi, useBestNumber, usePreimage, useToggle } from '@polkadot/react-hooks';
import Params from '@polkadot/react-params';
import { Available } from '@polkadot/react-query';
import { getTypeDef } from '@polkadot/types/create';
Expand Down
2 changes: 1 addition & 1 deletion packages/page-referenda/src/Referenda/Vote.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import type { TFunction } from 'react-i18next';
import type { ApiPromise } from '@polkadot/api';
import type { Preimage } from '@polkadot/app-preimages/types';
import type { Preimage } from '@polkadot/react-hooks/types';
import type { BN } from '@polkadot/util';
import type { PalletVote, TrackInfo } from '../types';

Expand Down
2 changes: 1 addition & 1 deletion packages/page-scheduler/src/Scheduled.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import type { ScheduledExt } from './types';
import React from 'react';

import Hash from '@polkadot/app-preimages/Preimages/Hash';
import usePreimage from '@polkadot/app-preimages/usePreimage';
import { CallExpander } from '@polkadot/react-components';
import { usePreimage } from '@polkadot/react-hooks';
import { BlockToTime } from '@polkadot/react-query';
import { formatNumber } from '@polkadot/util';

Expand Down
2 changes: 1 addition & 1 deletion packages/page-whitelist/src/Hashes/Details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import React from 'react';

import Call from '@polkadot/app-preimages/Preimages/Call';
import Hash from '@polkadot/app-preimages/Preimages/Hash';
import usePreimage from '@polkadot/app-preimages/usePreimage';
import { usePreimage } from '@polkadot/react-hooks';

interface Props {
className?: string;
Expand Down
1 change: 1 addition & 0 deletions packages/react-hooks/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export { useOwnStashInfos } from './useOwnStashInfos';
export { useOutsideClick } from './useOutsideClick';
export { useParaApi } from './useParaApi';
export { usePopupWindow } from './usePopupWindow';
export { usePreimage } from './usePreimage';
export { useProxies } from './useProxies';
export { useIsParasLinked, useParaEndpoints } from './useParaEndpoints';
export { usePassword } from './usePassword';
Expand Down
32 changes: 31 additions & 1 deletion packages/react-hooks/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ import type { ApiPromise } from '@polkadot/api';
import type { SubmittableExtrinsic } from '@polkadot/api/types';
import type { DeriveAccountFlags, DeriveAccountRegistration } from '@polkadot/api-derive/types';
import type { DisplayedJudgement } from '@polkadot/react-components/types';
import type { Bytes } from '@polkadot/types';
import type { AccountId, Balance, BlockNumber, Call, Exposure, Hash, RewardDestination, SessionIndex, StakingLedger, ValidatorPrefs } from '@polkadot/types/interfaces';
import type { IExtrinsic } from '@polkadot/types/types';
import type { PalletPreimageRequestStatus } from '@polkadot/types/lookup';
import type { IExtrinsic, Registry } from '@polkadot/types/types';
import type { KeyringJson$Meta } from '@polkadot/ui-keyring/types';
import type { BN } from '@polkadot/util';
import type { HexString } from '@polkadot/util/types';

export type CallParam = any;

Expand Down Expand Up @@ -167,3 +171,29 @@ export interface BatchOptions {
max?: number;
type?: BatchType;
}

export interface PreimageDeposit {
amount: BN;
who: string;
}

export interface PreimageStatus {
count: number;
deposit?: PreimageDeposit;
isCompleted: boolean;
proposalHash: HexString;
proposalLength?: BN;
registry: Registry;
status: PalletPreimageRequestStatus | null;
}

export interface PreimageBytes {
bytes?: Bytes | null;
proposal?: Call | null;
proposalError?: string | null;
proposalWarning?: string | null;
}

export interface Preimage extends PreimageBytes, PreimageStatus {
// just the interfaces above
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017-2023 @polkadot/app-preimages authors & contributors
// Copyright 2017-2023 @polkadot/react-hooks authors & contributors
// SPDX-License-Identifier: Apache-2.0

import type { ApiPromise } from '@polkadot/api';
Expand Down Expand Up @@ -203,4 +203,4 @@ function usePreimageImpl (hashOrBounded?: Hash | HexString | FrameSupportPreimag
);
}

export default createNamedHook('usePreimage', usePreimageImpl);
export const usePreimage = createNamedHook('usePreimage', usePreimageImpl);