diff --git a/packages/page-council/src/Motions/ProposeExternal.tsx b/packages/page-council/src/Motions/ProposeExternal.tsx index 20d8b6fa7129..e99ccc167c56 100644 --- a/packages/page-council/src/Motions/ProposeExternal.tsx +++ b/packages/page-council/src/Motions/ProposeExternal.tsx @@ -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'; diff --git a/packages/page-democracy/src/Overview/ProposalCell.tsx b/packages/page-democracy/src/Overview/ProposalCell.tsx index 9e70644730e7..cff5a2510d86 100644 --- a/packages/page-democracy/src/Overview/ProposalCell.tsx +++ b/packages/page-democracy/src/Overview/ProposalCell.tsx @@ -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'; diff --git a/packages/page-democracy/src/Overview/Propose.tsx b/packages/page-democracy/src/Overview/Propose.tsx index 50e6a76bcb76..f7f9eb8834bf 100644 --- a/packages/page-democracy/src/Overview/Propose.tsx +++ b/packages/page-democracy/src/Overview/Propose.tsx @@ -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'; diff --git a/packages/page-preimages/src/Preimages/Call.tsx b/packages/page-preimages/src/Preimages/Call.tsx index 8c1c77b0d740..fa83fbfa2db6 100644 --- a/packages/page-preimages/src/Preimages/Call.tsx +++ b/packages/page-preimages/src/Preimages/Call.tsx @@ -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'; diff --git a/packages/page-preimages/src/Preimages/Free.tsx b/packages/page-preimages/src/Preimages/Free.tsx index cb62dbf196a5..f15c51a3ba6c 100644 --- a/packages/page-preimages/src/Preimages/Free.tsx +++ b/packages/page-preimages/src/Preimages/Free.tsx @@ -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'; diff --git a/packages/page-preimages/src/Preimages/Preimage.tsx b/packages/page-preimages/src/Preimages/Preimage.tsx index 705f833c916d..b244d1002660 100644 --- a/packages/page-preimages/src/Preimages/Preimage.tsx +++ b/packages/page-preimages/src/Preimages/Preimage.tsx @@ -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'; diff --git a/packages/page-preimages/src/types.ts b/packages/page-preimages/src/types.ts deleted file mode 100644 index 51f63a54fd9f..000000000000 --- a/packages/page-preimages/src/types.ts +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright 2017-2023 @polkadot/app-preimages authors & contributors -// SPDX-License-Identifier: Apache-2.0 - -import type { Bytes } from '@polkadot/types'; -import type { Call } from '@polkadot/types/interfaces'; -import type { PalletPreimageRequestStatus } from '@polkadot/types/lookup'; -import type { Registry } from '@polkadot/types/types'; -import type { BN } from '@polkadot/util'; -import type { HexString } from '@polkadot/util/types'; - -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 -} diff --git a/packages/page-referenda/src/Referenda/RefOngoing.tsx b/packages/page-referenda/src/Referenda/RefOngoing.tsx index bfc1ea231a54..7c2010c41512 100644 --- a/packages/page-referenda/src/Referenda/RefOngoing.tsx +++ b/packages/page-referenda/src/Referenda/RefOngoing.tsx @@ -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'; diff --git a/packages/page-referenda/src/Referenda/Submit.tsx b/packages/page-referenda/src/Referenda/Submit.tsx index 613be587709f..ca6e888ec6d4 100644 --- a/packages/page-referenda/src/Referenda/Submit.tsx +++ b/packages/page-referenda/src/Referenda/Submit.tsx @@ -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'; diff --git a/packages/page-referenda/src/Referenda/Vote.tsx b/packages/page-referenda/src/Referenda/Vote.tsx index 10f0a25dda02..730e0d6adaec 100644 --- a/packages/page-referenda/src/Referenda/Vote.tsx +++ b/packages/page-referenda/src/Referenda/Vote.tsx @@ -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'; diff --git a/packages/page-scheduler/src/Scheduled.tsx b/packages/page-scheduler/src/Scheduled.tsx index 7132af9213cf..cd1e5eae7a7f 100644 --- a/packages/page-scheduler/src/Scheduled.tsx +++ b/packages/page-scheduler/src/Scheduled.tsx @@ -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'; diff --git a/packages/page-whitelist/src/Hashes/Details.tsx b/packages/page-whitelist/src/Hashes/Details.tsx index 2aa905012586..e49915a89d5a 100644 --- a/packages/page-whitelist/src/Hashes/Details.tsx +++ b/packages/page-whitelist/src/Hashes/Details.tsx @@ -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; diff --git a/packages/react-hooks/src/index.ts b/packages/react-hooks/src/index.ts index 99da1b726b3b..8fb0b95d41f7 100644 --- a/packages/react-hooks/src/index.ts +++ b/packages/react-hooks/src/index.ts @@ -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'; diff --git a/packages/react-hooks/src/types.ts b/packages/react-hooks/src/types.ts index fa155e9fb1a2..051e596f5469 100644 --- a/packages/react-hooks/src/types.ts +++ b/packages/react-hooks/src/types.ts @@ -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; @@ -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 +} diff --git a/packages/page-preimages/src/usePreimage.ts b/packages/react-hooks/src/usePreimage.ts similarity index 97% rename from packages/page-preimages/src/usePreimage.ts rename to packages/react-hooks/src/usePreimage.ts index 7385cecea451..118b26035966 100644 --- a/packages/page-preimages/src/usePreimage.ts +++ b/packages/react-hooks/src/usePreimage.ts @@ -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'; @@ -203,4 +203,4 @@ function usePreimageImpl (hashOrBounded?: Hash | HexString | FrameSupportPreimag ); } -export default createNamedHook('usePreimage', usePreimageImpl); +export const usePreimage = createNamedHook('usePreimage', usePreimageImpl);