diff --git a/package.json b/package.json index fa4b019d90..976a90a259 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "@ledgerhq/hw-transport-webhid": "^6.27.19", "@polkadot-cloud/assets": "^0.1.16", "@polkadot-cloud/core": "^0.1.31", - "@polkadot-cloud/react": "^0.1.69", + "@polkadot-cloud/react": "^0.1.70", "@polkadot-cloud/utils": "^0.0.20", "@polkadot/api": "^10.9.1", "@polkadot/keyring": "^12.1.1", diff --git a/src/App.tsx b/src/App.tsx index 69a353f82b..0dbdddda34 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -8,6 +8,7 @@ import { ThemesProvider } from 'contexts/Themes'; import { i18next } from 'locale'; import { Providers } from 'Providers'; import { NetworkProvider } from 'contexts/Network'; +import { ActiveAccountsProvider } from 'contexts/ActiveAccounts'; export const App: React.FC = () => { let network = localStorage.getItem('network'); @@ -21,7 +22,9 @@ export const App: React.FC = () => { - + + + diff --git a/src/Providers.tsx b/src/Providers.tsx index c1417b86cf..c8842a6c93 100644 --- a/src/Providers.tsx +++ b/src/Providers.tsx @@ -3,7 +3,6 @@ import { BalancesProvider } from 'contexts/Balances'; import { BondedProvider } from 'contexts/Bonded'; -import { ConnectProvider } from 'contexts/Connect'; import { ExtensionsProvider, OverlayProvider } from '@polkadot-cloud/react'; import { ExtrinsicsProvider } from 'contexts/Extrinsics'; import { FastUnstakeProvider } from 'contexts/FastUnstake'; @@ -41,10 +40,16 @@ import { ThemedRouter } from 'Themes'; import type { AnyJson } from 'types'; import type { FC } from 'react'; import { withProviders } from 'library/Hooks'; +import { ExtensionAccountsProvider } from 'contexts/Connect/ExtensionAccounts'; +import { OtherAccountsProvider } from 'contexts/Connect/OtherAccounts'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; +import { DappName } from 'consts'; +import { ImportedAccountsProvider } from 'contexts/Connect/ImportedAccounts'; // Embed providers from hook. export const Providers = () => { const { network } = useNetwork(); + const { activeAccount } = useActiveAccounts(); // !! Provider order matters const providers: Array | [FC, AnyJson]> = [ @@ -55,7 +60,9 @@ export const Providers = () => { VaultHardwareProvider, LedgerHardwareProvider, ExtensionsProvider, - ConnectProvider, + [ExtensionAccountsProvider, { network, activeAccount, dappName: DappName }], + OtherAccountsProvider, + ImportedAccountsProvider, HelpProvider, NetworkMetricsProvider, SubscanProvider, diff --git a/src/Router.tsx b/src/Router.tsx index f84ea41898..2e21c059da 100644 --- a/src/Router.tsx +++ b/src/Router.tsx @@ -17,7 +17,6 @@ import { } from 'react-router-dom'; import { Prompt } from 'library/Prompt'; import { PagesConfig } from 'config/pages'; -import { useConnect } from 'contexts/Connect'; import { useNotifications } from 'contexts/Notifications'; import { useUi } from 'contexts/UI'; import { ErrorFallbackApp, ErrorFallbackRoutes } from 'library/ErrorBoundary'; @@ -30,14 +29,18 @@ import { SideMenu } from 'library/SideMenu'; import { Tooltip } from 'library/Tooltip'; import { Overlays } from 'overlay'; import { useNetwork } from 'contexts/Network'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; +import { useOtherAccounts } from 'contexts/Connect/OtherAccounts'; +import { useImportedAccounts } from 'contexts/Connect/ImportedAccounts'; export const RouterInner = () => { const { t } = useTranslation(); const { network } = useNetwork(); const { pathname } = useLocation(); + const { accounts } = useImportedAccounts(); const { addNotification } = useNotifications(); - const { accountsInitialised, accounts, activeAccount, connectToAccount } = - useConnect(); + const { accountsInitialised } = useOtherAccounts(); + const { activeAccount, setActiveAccount } = useActiveAccounts(); const { sideMenuOpen, sideMenuMinimised, setContainerRefs } = useUi(); // Scroll to top of the window on every page change or network change. @@ -59,7 +62,7 @@ export const RouterInner = () => { if (aUrl) { const account = accounts.find((a) => a.address === aUrl); if (account && aUrl !== activeAccount) { - connectToAccount(account); + setActiveAccount(account?.address || null); addNotification({ title: t('accountConnected', { ns: 'library' }), subtitle: `${t('connectedTo', { ns: 'library' })} ${ diff --git a/src/contexts/ActiveAccounts/defaults.ts b/src/contexts/ActiveAccounts/defaults.ts new file mode 100644 index 0000000000..3335436090 --- /dev/null +++ b/src/contexts/ActiveAccounts/defaults.ts @@ -0,0 +1,14 @@ +// Copyright 2023 @paritytech/polkadot-staking-dashboard authors & contributors +// SPDX-License-Identifier: GPL-3.0-only +/* eslint-disable @typescript-eslint/no-unused-vars */ + +import type { ActiveAccountsContextInterface } from './types'; + +export const defaultActiveAccountsContext: ActiveAccountsContextInterface = { + activeAccount: null, + activeProxy: null, + activeProxyType: null, + getActiveAccount: () => null, + setActiveAccount: (address, updateLocal) => {}, + setActiveProxy: (address, updateLocal) => {}, +}; diff --git a/src/contexts/ActiveAccounts/index.tsx b/src/contexts/ActiveAccounts/index.tsx new file mode 100644 index 0000000000..53e2c8d4a8 --- /dev/null +++ b/src/contexts/ActiveAccounts/index.tsx @@ -0,0 +1,80 @@ +// Copyright 2023 @paritytech/polkadot-staking-dashboard authors & contributors +// SPDX-License-Identifier: GPL-3.0-only + +import type { ReactNode } from 'react'; +import { createContext, useContext, useEffect, useRef, useState } from 'react'; +import type { MaybeAddress } from 'types'; +import { setStateWithRef } from '@polkadot-cloud/utils'; +import { useNetwork } from 'contexts/Network'; +import type { ActiveAccountsContextInterface, ActiveProxy } from './types'; +import { defaultActiveAccountsContext } from './defaults'; + +export const ActiveAccountsContext = + createContext(defaultActiveAccountsContext); + +export const ActiveAccountsProvider = ({ + children, +}: { + children: ReactNode; +}) => { + const { network } = useNetwork(); + + // Store the currently active account. + const [activeAccount, setActiveAccountState] = useState(null); + const activeAccountRef = useRef(activeAccount); + + // Store the active proxy account. + const [activeProxy, setActiveProxyState] = useState(null); + const activeProxyRef = useRef(activeProxy); + + // Setter for the active proxy account. + const setActiveProxy = (newActiveProxy: ActiveProxy, updateLocal = true) => { + if (updateLocal) + if (newActiveProxy) { + localStorage.setItem( + `${network}_active_proxy`, + JSON.stringify(newActiveProxy) + ); + } else { + localStorage.removeItem(`${network}_active_proxy`); + } + setStateWithRef(newActiveProxy, setActiveProxyState, activeProxyRef); + }; + + // Setter for the active account. + const setActiveAccount = ( + newActiveAccount: MaybeAddress, + local: boolean = true + ) => { + if (local) + if (newActiveAccount === null) { + localStorage.removeItem(`${network}_active_account`); + } else { + localStorage.setItem(`${network}_active_account`, newActiveAccount); + } + setStateWithRef(newActiveAccount, setActiveAccountState, activeAccountRef); + }; + + // Getter for the active account. + const getActiveAccount = () => activeAccountRef.current; + + // Disconnect from the active account on network change, but don't remove local record. + useEffect(() => setActiveAccount(null, false), [network]); + + return ( + + {children} + + ); +}; + +export const useActiveAccounts = () => useContext(ActiveAccountsContext); diff --git a/src/contexts/ActiveAccounts/types.ts b/src/contexts/ActiveAccounts/types.ts new file mode 100644 index 0000000000..19a05d2c72 --- /dev/null +++ b/src/contexts/ActiveAccounts/types.ts @@ -0,0 +1,18 @@ +// Copyright 2023 @paritytech/polkadot-staking-dashboard authors & contributors +// SPDX-License-Identifier: GPL-3.0-only + +import type { MaybeAddress } from 'types'; + +export interface ActiveAccountsContextInterface { + activeAccount: MaybeAddress; + activeProxy: MaybeAddress; + activeProxyType: string | null; + getActiveAccount: () => string | null; + setActiveAccount: (address: MaybeAddress, updateLocal?: boolean) => void; + setActiveProxy: (address: ActiveProxy, updateLocal?: boolean) => void; +} + +export type ActiveProxy = { + address: MaybeAddress; + proxyType: string; +} | null; diff --git a/src/contexts/Balances/Utils.ts b/src/contexts/Balances/Utils.ts index 6dd52796be..50a8008ddb 100644 --- a/src/contexts/Balances/Utils.ts +++ b/src/contexts/Balances/Utils.ts @@ -1,7 +1,7 @@ // Copyright 2023 @paritytech/polkadot-staking-dashboard authors & contributors // SPDX-License-Identifier: GPL-3.0-only -import type { MaybeAccount } from 'types'; +import type { MaybeAddress } from 'types'; import { defaultLedger } from './defaults'; import type { Ledger } from './types'; @@ -10,11 +10,11 @@ import type { Ledger } from './types'; * @summary Get an account's ledger record according to a key. * @param {Ledger} ledgers * @param {string} key - * @param { MaybeAccount } address + * @param { MaybeAddress } address * @returns Ledger */ export const getLedger = ( ledgers: Ledger[], key: 'stash' | 'address', - address: MaybeAccount + address: MaybeAddress ): Ledger => ledgers.find((l) => l[key] === address) || defaultLedger; diff --git a/src/contexts/Balances/index.tsx b/src/contexts/Balances/index.tsx index 7aa71be069..21a7181feb 100644 --- a/src/contexts/Balances/index.tsx +++ b/src/contexts/Balances/index.tsx @@ -12,10 +12,11 @@ import { import BigNumber from 'bignumber.js'; import React, { useRef, useState } from 'react'; import { useApi } from 'contexts/Api'; -import { useConnect } from 'contexts/Connect'; -import type { AnyApi, MaybeAccount } from 'types'; +import type { AnyApi, MaybeAddress } from 'types'; import { useEffectIgnoreInitial } from '@polkadot-cloud/react/hooks'; import { useNetwork } from 'contexts/Network'; +import { useImportedAccounts } from 'contexts/Connect/ImportedAccounts'; +import { useOtherAccounts } from 'contexts/Connect/OtherAccounts'; import { getLedger } from './Utils'; import * as defaults from './defaults'; import type { @@ -36,7 +37,9 @@ export const BalancesProvider = ({ }) => { const { api, isReady } = useApi(); const { network } = useNetwork(); - const { accounts, addExternalAccount, getAccount } = useConnect(); + const { accounts } = useImportedAccounts(); + const { getAccount } = useImportedAccounts(); + const { addExternalAccount } = useOtherAccounts(); const [balances, setBalances] = useState([]); const balancesRef = useRef(balances); @@ -189,21 +192,21 @@ export const BalancesProvider = ({ }, [network]); // Gets a ledger for a stash address. - const getStashLedger = (address: MaybeAccount) => { + const getStashLedger = (address: MaybeAddress) => { return getLedger(ledgersRef.current, 'stash', address); }; // Gets an account's balance metadata. - const getBalance = (address: MaybeAccount) => + const getBalance = (address: MaybeAddress) => balancesRef.current.find((a) => a.address === address)?.balance || defaults.defaultBalance; // Gets an account's locks. - const getLocks = (address: MaybeAccount) => + const getLocks = (address: MaybeAddress) => balancesRef.current.find((a) => a.address === address)?.locks ?? []; // Gets an account's nonce. - const getNonce = (address: MaybeAccount) => + const getNonce = (address: MaybeAddress) => balancesRef.current.find((a) => a.address === address)?.nonce ?? 0; return ( diff --git a/src/contexts/Balances/types.ts b/src/contexts/Balances/types.ts index 0dba4b6098..99ad4a820b 100644 --- a/src/contexts/Balances/types.ts +++ b/src/contexts/Balances/types.ts @@ -2,15 +2,15 @@ // SPDX-License-Identifier: GPL-3.0-only import type BigNumber from 'bignumber.js'; -import type { MaybeAccount } from 'types'; +import type { MaybeAddress } from 'types'; export interface BalancesContextInterface { ledgers: Ledger[]; balances: Balances[]; - getStashLedger: (a: MaybeAccount) => Ledger; - getBalance: (address: MaybeAccount) => Balance; - getLocks: (address: MaybeAccount) => BalanceLock[]; - getNonce: (address: MaybeAccount) => number; + getStashLedger: (a: MaybeAddress) => Ledger; + getBalance: (address: MaybeAddress) => Balance; + getLocks: (address: MaybeAddress) => BalanceLock[]; + getNonce: (address: MaybeAddress) => number; } export interface Balances { @@ -42,7 +42,7 @@ export interface BalanceLock { } export interface Ledger { - address: MaybeAccount; + address: MaybeAddress; stash: string | null; active: BigNumber; total: BigNumber; diff --git a/src/contexts/Bonded/index.tsx b/src/contexts/Bonded/index.tsx index b9c4289c81..212d0ecc65 100644 --- a/src/contexts/Bonded/index.tsx +++ b/src/contexts/Bonded/index.tsx @@ -10,17 +10,19 @@ import { } from '@polkadot-cloud/utils'; import React, { useEffect, useRef, useState } from 'react'; import { useApi } from 'contexts/Api'; -import { useConnect } from 'contexts/Connect'; -import type { AnyApi, MaybeAccount } from 'types'; +import type { AnyApi, MaybeAddress } from 'types'; import { useEffectIgnoreInitial } from '@polkadot-cloud/react/hooks'; import { useNetwork } from 'contexts/Network'; +import { useImportedAccounts } from 'contexts/Connect/ImportedAccounts'; +import { useOtherAccounts } from 'contexts/Connect/OtherAccounts'; import * as defaults from './defaults'; import type { BondedAccount, BondedContextInterface } from './types'; export const BondedProvider = ({ children }: { children: React.ReactNode }) => { const { network } = useNetwork(); const { api, isReady } = useApi(); - const { accounts, addExternalAccount } = useConnect(); + const { accounts } = useImportedAccounts(); + const { addExternalAccount } = useOtherAccounts(); // Balance accounts state. const [bondedAccounts, setBondedAccounts] = useState([]); @@ -132,18 +134,18 @@ export const BondedProvider = ({ children }: { children: React.ReactNode }) => { return unsub; }; - const getBondedAccount = (address: MaybeAccount) => + const getBondedAccount = (address: MaybeAddress) => bondedAccountsRef.current.find((a) => a.address === address)?.bonded || null; - const getAccountNominations = (address: MaybeAccount) => + const getAccountNominations = (address: MaybeAddress) => bondedAccountsRef.current.find((a) => a.address === address)?.nominations ?.targets || []; - const getAccount = (address: MaybeAccount) => + const getAccount = (address: MaybeAddress) => bondedAccountsRef.current.find((a) => a.address === address) || null; - const isController = (address: MaybeAccount) => + const isController = (address: MaybeAddress) => bondedAccountsRef.current.filter((a) => (a?.bonded || '') === address) ?.length > 0 || false; diff --git a/src/contexts/Bonded/types.ts b/src/contexts/Bonded/types.ts index 041e5d98a8..7ff494e281 100644 --- a/src/contexts/Bonded/types.ts +++ b/src/contexts/Bonded/types.ts @@ -1,7 +1,7 @@ // Copyright 2023 @paritytech/polkadot-staking-dashboard authors & contributors // SPDX-License-Identifier: GPL-3.0-only -import type { MaybeAccount } from 'types'; +import type { MaybeAddress } from 'types'; export interface BondedAccount { address?: string; @@ -17,9 +17,9 @@ export interface Nominations { export type Targets = string[]; export interface BondedContextInterface { - getAccount: (address: MaybeAccount) => BondedAccount | null; - getBondedAccount: (address: MaybeAccount) => string | null; - getAccountNominations: (address: MaybeAccount) => Targets; - isController: (address: MaybeAccount) => boolean; + getAccount: (address: MaybeAddress) => BondedAccount | null; + getBondedAccount: (address: MaybeAddress) => string | null; + getAccountNominations: (address: MaybeAddress) => Targets; + isController: (address: MaybeAddress) => boolean; bondedAccounts: BondedAccount[]; } diff --git a/src/contexts/Connect/ExtensionAccounts/index.tsx b/src/contexts/Connect/ExtensionAccounts/index.tsx new file mode 100644 index 0000000000..7a55356b92 --- /dev/null +++ b/src/contexts/Connect/ExtensionAccounts/index.tsx @@ -0,0 +1,338 @@ +// Copyright 2023 @paritytech/polkadot-staking-dashboard authors & contributors +// SPDX-License-Identifier: GPL-3.0-only + +import { createContext, useContext, useEffect, useRef, useState } from 'react'; +import type { + ExtensionAccountsContextInterface, + ExtensionAccountsProviderProps, +} from '@polkadot-cloud/react/connect/ExtensionAccountsProvider/types'; +import { + useEffectIgnoreInitial, + useExtensions, +} from '@polkadot-cloud/react/hooks'; +import type { AnyApi } from 'types'; +import type { VoidFn } from '@polkadot/api/types'; +import type { + ExtensionInjected, + ExtensionInterface, +} from '@polkadot-cloud/react/connect/ExtensionsProvider/types'; +import { localStorageOrDefault, setStateWithRef } from '@polkadot-cloud/utils'; +import { defaultExtensionAccountsContext } from '@polkadot-cloud/react/connect/ExtensionAccountsProvider/defaults'; +import type { ImportedAccount } from '@polkadot-cloud/react/connect/types'; +import { useImportExtension } from './useImportExtension'; +// TODO: the functions in this hook need to be moved to the cloud. +import { extensionIsLocal, removeFromLocalExtensions } from '../Utils'; +import { useActiveAccounts } from '../../ActiveAccounts'; + +export const ExtensionAccountsContext = + createContext( + defaultExtensionAccountsContext + ); + +export const ExtensionAccountsProvider = ({ + children, + network, + dappName, + activeAccount, +}: ExtensionAccountsProviderProps) => { + const { + handleImportExtension, + connectActiveExtensionAccount, + getActiveExtensionAccount, + } = useImportExtension(); + + // TODO: this should be passed into the context as a setter. + const { setActiveAccount } = useActiveAccounts(); + + const { checkingInjectedWeb3, setExtensionStatus, extensions } = + useExtensions(); + + // Store connected extension accounts. + const [extensionAccounts, setExtensionAccounts] = useState( + [] + ); + const extensionAccountsRef = useRef(extensionAccounts); + + // Store whether extension accounts have been synced. + const [extensionAccountsSynced, setExtensionAccountsSynced] = + useState(false); + + // Store extensions whose account subscriptions have been initialised. + const [extensionsInitialised, setExtensionsInitialised] = useState( + [] + ); + const extensionsInitialisedRef = useRef(extensionsInitialised); + + // Store unsubscribe handlers for connected extensions. + const unsubs = useRef>({}); + + const connectToAccount = (account: ImportedAccount | null) => { + setActiveAccount(account?.address ?? null); + }; + + // connectActiveExtensions + // + // Connects to extensions that already have been connected to and stored in localStorage. Loop + // through extensions and connect to accounts. If `activeAccount` exists locally, we wait until + // all extensions are looped before connecting to it; there is no guarantee it still exists - must + // explicitly find it. + const connectActiveExtensions = async () => { + // iterate extensions and add accounts to state + const total = extensions?.length ?? 0; + let activeWalletAccount: ImportedAccount | null = null; + if (!extensions) return; + let i = 0; + extensions.forEach(async (e: ExtensionInjected) => { + i++; + // Ensure the extension carries an `id` property. + const id = e?.id ?? undefined; + // Whether extension is locally stored (previously connected). + const isLocal = extensionIsLocal(id ?? 0); + if (!id || !isLocal) { + updateInitialisedExtensions( + id || + `unknown_extension_${extensionsInitialisedRef.current.length + 1}` + ); + } else { + try { + // Attempt to get extension `enable` property. + const { enable } = e; + // Summons extension popup. + const extension: ExtensionInterface = await enable(dappName); + if (extension !== undefined) { + const unsub = extension.accounts.subscribe((a) => { + if (a) { + const { newAccounts, meta } = handleImportExtension( + id, + extensionAccountsRef.current, + extension, + a, + forgetAccounts + ); + + // Store active wallet account if found in this extension. + if (!activeWalletAccount) { + activeWalletAccount = getActiveExtensionAccount(newAccounts); + } + // Set active account for network on final extension. + if (i === total && activeAccount === null) { + const activeAccountRemoved = + activeWalletAccount?.address !== + meta.removedActiveAccount && + meta.removedActiveAccount !== null; + if (!activeAccountRemoved) { + connectActiveExtensionAccount( + activeWalletAccount, + connectToAccount + ); + } + } + // Concat accounts and store. + addExtensionAccount(newAccounts); + // Update initialised extensions. + updateInitialisedExtensions(id); + } + }); + addToUnsubscribe(id, unsub); + } + } catch (err) { + handleExtensionError(id, String(err)); + } + } + }); + }; + + // connectExtensionAccounts + // + // Similar to the above but only connects to a single extension. This is invoked by the user by + // clicking on an extension. If activeAccount is not found here, it is simply ignored. + const connectExtensionAccounts = async ( + e: ExtensionInjected + ): Promise => { + // ensure the extension carries an `id` property + const id = e?.id ?? undefined; + if (!id) { + updateInitialisedExtensions( + `unknown_extension_${extensionsInitialisedRef.current.length + 1}` + ); + } else { + try { + // Attempt to get extension `enable` property. + const { enable } = e; + // Summons extension popup. + const extension: ExtensionInterface = await enable(dappName); + if (extension !== undefined) { + // Subscribe to accounts. + const unsub = extension.accounts.subscribe((a) => { + if (a) { + const { newAccounts, meta } = handleImportExtension( + id, + extensionAccountsRef.current, + extension, + a, + forgetAccounts + ); + // Set active account for network if not yet set. + if (activeAccount === null) { + const activeExtensionAccount = + getActiveExtensionAccount(newAccounts); + if ( + activeExtensionAccount !== meta.removedActiveAccount && + meta.removedActiveAccount !== null + ) + connectActiveExtensionAccount( + activeExtensionAccount, + connectToAccount + ); + } + // Concat accounts and store. + addExtensionAccount(newAccounts); + // Update initialised extensions. + updateInitialisedExtensions(id); + } + }); + addToUnsubscribe(id, unsub); + return true; + } + } catch (err) { + handleExtensionError(id, String(err)); + } + } + return false; + }; + + // Handle errors when communiating with extensions. + const handleExtensionError = (id: string, err: string) => { + // if not general error (maybe enabled but no accounts trust app) + if (err.startsWith('Error')) { + // remove extension from local `active_extensions`. + removeFromLocalExtensions(id); + // extension not found (does not exist) + if (err.substring(0, 17) === 'NotInstalledError') { + setExtensionStatus(id, 'not_found'); + } else { + // declare extension as no imported accounts authenticated. + setExtensionStatus(id, 'not_authenticated'); + } + } + // mark extension as initialised + updateInitialisedExtensions(id); + }; + + // Handle forgetting of an imported extension account. + const forgetAccounts = (forget: ImportedAccount[]) => { + // Unsubscribe and remove unsub from context ref. + if (forget.length) { + for (const { address } of forget) { + if (extensionAccountsRef.current.find((a) => a.address === address)) { + const unsub = unsubs.current[address]; + if (unsub) { + unsub(); + delete unsubs.current[address]; + } + } + } + // Remove forgotten accounts from context state. + setStateWithRef( + [...extensionAccountsRef.current].filter( + (a) => forget.find((s) => s.address === a.address) === undefined + ), + setExtensionAccounts, + extensionAccountsRef + ); + // If the currently active account is being forgotten, disconnect. + if (forget.find((a) => a.address === activeAccount) !== undefined) + setActiveAccount(null); + } + }; + + // Update initialised extensions. + const updateInitialisedExtensions = (id: string) => { + if (!extensionsInitialisedRef.current.includes(id)) { + setStateWithRef( + [...extensionsInitialisedRef.current].concat(id), + setExtensionsInitialised, + extensionsInitialisedRef + ); + } + }; + + // Add an extension account to context state. + const addExtensionAccount = (a: ImportedAccount[]) => { + setStateWithRef( + [...extensionAccountsRef.current].concat(a), + setExtensionAccounts, + extensionAccountsRef + ); + }; + + // add an extension id to unsubscribe state. + const addToUnsubscribe = (id: string, unsub: AnyApi) => { + unsubs.current[id] = unsub; + }; + + // Unsubscrbe all account subscriptions. + const unsubscribe = () => { + Object.values(unsubs.current).forEach((unsub) => { + unsub(); + }); + }; + + // Re-sync extensions accounts on network switch. + // + // Do this if activeAccount is present. If activeAccount is present, and extensions have for some + // reason been removed from local storage, then all pop-ups will be summoned here. + useEffect(() => { + // wait for injectedWeb3 check to finish before starting account import process. + if (!checkingInjectedWeb3) { + // unsubscribe from all accounts and reset state + unsubscribe(); + setStateWithRef([], setExtensionAccounts, extensionAccountsRef); + setStateWithRef([], setExtensionsInitialised, extensionsInitialisedRef); + setExtensionAccountsSynced(false); + // if extensions have been fetched, get accounts if extensions exist and + // local extensions exist (previously connected). + if (extensions.length) { + // get active extensions + const localExtensions = localStorageOrDefault( + `active_extensions`, + [], + true + ); + if (extensions.length && localExtensions.length) { + connectActiveExtensions(); + } else { + setExtensionAccountsSynced(true); + } + } + } + return () => unsubscribe(); + }, [extensions?.length, network, checkingInjectedWeb3]); + + // Once initialised extensions equal total extensions present in `injectedWeb3`, mark extensions + // as fetched. + useEffectIgnoreInitial(() => { + if ( + (!checkingInjectedWeb3 && + extensionsInitialisedRef.current.length === extensions?.length) || + 0 + ) { + setExtensionAccountsSynced(true); + } + }, [checkingInjectedWeb3, extensionsInitialisedRef.current]); + + return ( + + {children} + + ); +}; + +export const useExtensionAccounts = () => useContext(ExtensionAccountsContext); diff --git a/src/contexts/Connect/Hooks/useImportExtension.tsx b/src/contexts/Connect/ExtensionAccounts/useImportExtension.tsx similarity index 77% rename from src/contexts/Connect/Hooks/useImportExtension.tsx rename to src/contexts/Connect/ExtensionAccounts/useImportExtension.tsx index 8395f260ed..9a3f6c24af 100644 --- a/src/contexts/Connect/Hooks/useImportExtension.tsx +++ b/src/contexts/Connect/ExtensionAccounts/useImportExtension.tsx @@ -10,13 +10,14 @@ import type { } from '@polkadot-cloud/react/connect/ExtensionsProvider/types'; import type { AnyFunction } from 'types'; import { useNetwork } from 'contexts/Network'; +import { defaultHandleImportExtension } from '@polkadot-cloud/react/connect/ExtensionAccountsProvider/defaults'; +import type { ImportedAccount } from '@polkadot-cloud/react/connect/types'; +import type { HandleImportExtension } from '@polkadot-cloud/react/connect/ExtensionAccountsProvider/types'; import { addToLocalExtensions, getActiveAccountLocal, getInExternalAccounts, } from '../Utils'; -import { defaultHandleImportExtension } from '../defaults'; -import type { HandleImportExtension, ImportedAccount } from '../types'; export const useImportExtension = () => { const { networkData, network } = useNetwork(); @@ -60,37 +61,37 @@ export const useImportExtension = () => { newAccounts: ExtensionAccount[], forget: (a: ImportedAccount[]) => void ): HandleImportExtension => { - // set network ss58 format const keyring = new Keyring(); keyring.setSS58Format(networkData.ss58); - // remove accounts that do not contain correctly formatted addresses. + // Remove accounts that do not contain correctly formatted addresses. newAccounts = newAccounts.filter((i) => isValidAddress(i.address)); - // reformat addresses to ensure correct ss58 format + // Reformat addresses to ensure correct ss58 format newAccounts.forEach(async (account) => { const { address } = keyring.addFromAddress(account.address); account.address = address; return account; }); - // remove newAccounts from local external accounts if present + // Remove newAccounts from local external accounts if present const inExternal = getInExternalAccounts(newAccounts, network); forget(inExternal); - // find any accounts that have been removed from this extension + // Find any accounts that have been removed from this extension const goneFromExtension = currentAccounts .filter((j) => j.source === id) .filter((j) => !newAccounts.find((i) => i.address === j.address)); - // check whether active account is present in forgotten accounts + + // Check whether active account is present in forgotten accounts const activeGoneFromExtension = goneFromExtension.find( (i) => i.address === getActiveAccountLocal(network, networkData.ss58) ); - // commit remove forgotten accounts + // Commit remove forgotten accounts forget(goneFromExtension); - // remove accounts that have already been added to currentAccounts via another extension. - // note: does not include external accounts. + // Remove accounts that have already been added to `currentAccounts` via another extension. + // Note: does not include external accounts. newAccounts = newAccounts.filter( (i) => !currentAccounts.find( @@ -98,7 +99,7 @@ export const useImportExtension = () => { ) ); - // format accounts properties + // Format accounts properties newAccounts = newAccounts.map((a) => ({ address: a.address, source: id, @@ -115,11 +116,14 @@ export const useImportExtension = () => { // Get active extension account. // - // checks if the local active account is in the extension. - const getActiveExtensionAccount = (accounts: ImportedAccount[]) => - accounts.find( - (a) => a.address === getActiveAccountLocal(network, networkData.ss58) - ) ?? null; + // Checks if the local active account is in the extension. + const getActiveExtensionAccount = (accounts: ImportedAccount[]) => { + return ( + accounts.find( + (a) => a.address === getActiveAccountLocal(network, networkData.ss58) + ) ?? null + ); + }; // Connect active extension account. // diff --git a/src/contexts/Connect/ImportedAccounts/defaults.ts b/src/contexts/Connect/ImportedAccounts/defaults.ts new file mode 100644 index 0000000000..fb228f6243 --- /dev/null +++ b/src/contexts/Connect/ImportedAccounts/defaults.ts @@ -0,0 +1,14 @@ +// Copyright 2023 @paritytech/polkadot-staking-dashboard authors & contributors +// SPDX-License-Identifier: GPL-3.0-only +/* eslint-disable @typescript-eslint/no-unused-vars */ + +import type { ImportedAccountsContextInterface } from './types'; + +export const defaultImportedAccountsContext: ImportedAccountsContextInterface = + { + accounts: [], + getAccount: (a) => null, + isReadOnlyAccount: (a) => false, + accountHasSigner: (a) => false, + requiresManualSign: (a) => false, + }; diff --git a/src/contexts/Connect/ImportedAccounts/index.tsx b/src/contexts/Connect/ImportedAccounts/index.tsx new file mode 100644 index 0000000000..c0b0ca9047 --- /dev/null +++ b/src/contexts/Connect/ImportedAccounts/index.tsx @@ -0,0 +1,71 @@ +// Copyright 2023 @paritytech/polkadot-staking-dashboard authors & contributors +// SPDX-License-Identifier: GPL-3.0-only + +import type { ReactNode } from 'react'; +import { createContext, useContext } from 'react'; +import type { MaybeAddress } from 'types'; +import type { ExternalAccount } from '@polkadot-cloud/react/connect/types'; +import { defaultImportedAccountsContext } from './defaults'; +import type { ImportedAccountsContextInterface } from './types'; +import { useExtensionAccounts } from '../ExtensionAccounts'; +import { manualSigners } from '../Utils'; +import { useOtherAccounts } from '../OtherAccounts'; + +export const ImportedAccountsContext = + createContext( + defaultImportedAccountsContext + ); + +export const ImportedAccountsProvider = ({ + children, +}: { + children: ReactNode; +}) => { + const { otherAccounts } = useOtherAccounts(); + const { extensionAccounts } = useExtensionAccounts(); + + const allAccounts = extensionAccounts.concat(otherAccounts); + + const getAccount = (who: MaybeAddress) => + allAccounts.find(({ address }) => address === who) || null; + + const isReadOnlyAccount = (address: MaybeAddress) => { + const account = getAccount(address) ?? {}; + + if (Object.prototype.hasOwnProperty.call(account, 'addedBy')) { + const { addedBy } = account as ExternalAccount; + return addedBy === 'user'; + } + return false; + }; + + // Checks whether an account can sign transactions + const accountHasSigner = (address: MaybeAddress) => + allAccounts.find( + (a) => a.address === address && a.source !== 'external' + ) !== undefined; + + // Checks whether an account needs manual signing. This is the case for Ledger accounts, + // transactions of which cannot be automatically signed by a provided `signer` as is the case with + // extensions. + const requiresManualSign = (address: MaybeAddress) => + allAccounts.find( + (a) => a.address === address && manualSigners.includes(a.source) + ) !== undefined; + + return ( + + {children} + + ); +}; + +export const useImportedAccounts = () => useContext(ImportedAccountsContext); diff --git a/src/contexts/Connect/ImportedAccounts/types.ts b/src/contexts/Connect/ImportedAccounts/types.ts new file mode 100644 index 0000000000..f4406130a2 --- /dev/null +++ b/src/contexts/Connect/ImportedAccounts/types.ts @@ -0,0 +1,14 @@ +// Copyright 2023 @paritytech/polkadot-staking-dashboard authors & contributors +// SPDX-License-Identifier: GPL-3.0-only + +import type { MaybeAddress } from 'types'; +import type { ExtensionAccount } from '@polkadot-cloud/react/connect/ExtensionsProvider/types'; +import type { ImportedAccount } from '@polkadot-cloud/react/connect/types'; + +export interface ImportedAccountsContextInterface { + accounts: ImportedAccount[]; + getAccount: (account: MaybeAddress) => ExtensionAccount | null; + isReadOnlyAccount: (a: MaybeAddress) => boolean; + accountHasSigner: (a: MaybeAddress) => boolean; + requiresManualSign: (a: MaybeAddress) => boolean; +} diff --git a/src/contexts/Connect/OtherAccounts/defaults.ts b/src/contexts/Connect/OtherAccounts/defaults.ts new file mode 100644 index 0000000000..7629215a2b --- /dev/null +++ b/src/contexts/Connect/OtherAccounts/defaults.ts @@ -0,0 +1,16 @@ +// Copyright 2023 @paritytech/polkadot-staking-dashboard authors & contributors +// SPDX-License-Identifier: GPL-3.0-only +/* eslint-disable @typescript-eslint/no-unused-vars */ + +import type { OtherAccountsContextInterface } from './types'; + +export const defaultOtherAccountsContext: OtherAccountsContextInterface = { + addExternalAccount: (a, b) => {}, + addOtherAccounts: (a) => {}, + renameOtherAccount: (a, n) => {}, + importLocalOtherAccounts: (n) => {}, + forgetOtherAccounts: (a) => {}, + forgetExternalAccounts: (a) => {}, + otherAccounts: [], + accountsInitialised: false, +}; diff --git a/src/contexts/Connect/OtherAccounts/index.tsx b/src/contexts/Connect/OtherAccounts/index.tsx new file mode 100644 index 0000000000..f3805b368e --- /dev/null +++ b/src/contexts/Connect/OtherAccounts/index.tsx @@ -0,0 +1,276 @@ +// Copyright 2023 @paritytech/polkadot-staking-dashboard authors & contributors +// SPDX-License-Identifier: GPL-3.0-only + +import type { ReactNode } from 'react'; +import { createContext, useContext, useEffect, useRef, useState } from 'react'; +import { + useEffectIgnoreInitial, + useExtensions, +} from '@polkadot-cloud/react/hooks'; +import { + getLocalLedgerAccounts, + getLocalVaultAccounts, +} from 'contexts/Hardware/Utils'; +import type { AnyFunction, MaybeAddress, NetworkName } from 'types'; +import { ellipsisFn, setStateWithRef } from '@polkadot-cloud/utils'; +import { useNetwork } from 'contexts/Network'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; +import Keyring from '@polkadot/keyring'; +import type { + ExternalAccount, + ImportedAccount, +} from '@polkadot-cloud/react/connect/types'; +import { useExtensionAccounts } from '../ExtensionAccounts'; +import { + getActiveAccountLocal, + getLocalExternalAccounts, + removeLocalExternalAccounts, +} from '../Utils'; +import type { OtherAccountsContextInterface } from './types'; +import { defaultOtherAccountsContext } from './defaults'; + +export const OtherAccountsContext = + createContext(defaultOtherAccountsContext); + +export const OtherAccountsProvider = ({ + children, +}: { + children: ReactNode; +}) => { + const { + network, + networkData: { ss58 }, + } = useNetwork(); + const { checkingInjectedWeb3 } = useExtensions(); + const { extensionAccountsSynced } = useExtensionAccounts(); + const { activeAccount, setActiveAccount } = useActiveAccounts(); + + // Store whether other (non-extension) accounts have been initialised. + const [otherAccountsSynced, setOtherAccountsSynced] = + useState(false); + + // Store other (non-extension) accounts list. + const [otherAccounts, setOtherAccounts] = useState([]); + const otherAccountsRef = useRef(otherAccounts); + + // Store unsubscribe handlers for connected extensions. + const unsubs = useRef>({}); + + // Store whether all accounts have been synced. + const [accountsInitialised, setAccountsInitialised] = + useState(false); + + // Handle forgetting of an imported other account. + const forgetOtherAccounts = (forget: ImportedAccount[]) => { + // Unsubscribe and remove unsub from context ref. + if (forget.length) { + for (const { address } of forget) { + if (otherAccountsRef.current.find((a) => a.address === address)) { + const unsub = unsubs.current[address]; + if (unsub) { + unsub(); + delete unsubs.current[address]; + } + } + } + // Remove forgotten accounts from context state. + setStateWithRef( + [...otherAccountsRef.current].filter( + (a) => forget.find((s) => s.address === a.address) === undefined + ), + setOtherAccounts, + otherAccountsRef + ); + // If the currently active account is being forgotten, disconnect. + if (forget.find((a) => a.address === activeAccount) !== undefined) + setActiveAccount(null); + } + }; + + // Checks `localStorage` for previously added accounts from the provided source, and adds them to + // `accounts` state. if local active account is present, it will also be assigned as active. + // Accounts are ignored if they are already imported through an extension. + const importLocalOtherAccounts = ( + getter: (n: NetworkName) => ImportedAccount[] + ) => { + // Get accounts from provided `getter` function. The resulting array of accounts must contain an + // `address` field. + let localAccounts = getter(network); + + if (localAccounts.length) { + const activeAccountInSet = + localAccounts.find( + ({ address }) => address === getActiveAccountLocal(network, ss58) + ) ?? null; + + // remove already-imported accounts. + localAccounts = localAccounts.filter( + (l) => + otherAccountsRef.current.find( + ({ address }) => address === l.address + ) === undefined + ); + + // set active account for networkData. + if (activeAccountInSet) { + setActiveAccount(activeAccountInSet?.address || null); + } + // add accounts to imported. + addOtherAccounts(localAccounts); + } + }; + + // Renames an other account. + const renameOtherAccount = (address: MaybeAddress, newName: string) => { + setStateWithRef( + [...otherAccountsRef.current].map((a) => + a.address !== address + ? a + : { + ...a, + name: newName, + } + ), + setOtherAccounts, + otherAccountsRef + ); + }; + + // Adds an external account (non-wallet) to accounts. + const addExternalAccount = (address: string, addedBy: string) => { + // ensure account is formatted correctly + const keyring = new Keyring(); + keyring.setSS58Format(ss58); + const formatted = keyring.addFromAddress(address).address; + + const newAccount = { + address: formatted, + network, + name: ellipsisFn(address), + source: 'external', + addedBy, + }; + + // get all external accounts from localStorage. + const localExternalAccounts = getLocalExternalAccounts(); + const existsLocal = localExternalAccounts.find( + (l) => l.address === address && l.network === network + ); + + // check that address is not sitting in imported accounts (currently cannot check which + // network). + const existsImported = otherAccountsRef.current.find( + (a) => a.address === address + ); + + // add external account if not there already. + if (!existsLocal && !existsImported) { + localStorage.setItem( + 'external_accounts', + JSON.stringify(localExternalAccounts.concat(newAccount)) + ); + + // add external account to imported accounts + addOtherAccounts([newAccount]); + } else if (existsLocal && existsLocal.addedBy !== 'system') { + // the external account needs to change to `system` so it cannot be removed. This will replace + // the whole entry. + localStorage.setItem( + 'external_accounts', + JSON.stringify( + localExternalAccounts.map((item) => + item.address !== address ? item : newAccount + ) + ) + ); + // re-sync account state. + setStateWithRef( + [...otherAccountsRef.current].map((item) => + item.address !== newAccount.address ? item : newAccount + ), + setOtherAccounts, + otherAccountsRef + ); + } + }; + + // Get any external accounts and remove from localStorage. + const forgetExternalAccounts = (forget: ImportedAccount[]) => { + if (!forget.length) return; + removeLocalExternalAccounts( + network, + forget.filter((i) => 'network' in i) as ExternalAccount[] + ); + + // If the currently active account is being forgotten, disconnect. + if (forget.find((a) => a.address === activeAccount) !== undefined) + setActiveAccount(null); + }; + + // Re-sync other accounts on network switch. Waits for `injectedWeb3` to be injected. + useEffect(() => { + if (!checkingInjectedWeb3) { + // unsubscribe from all accounts and reset state. + unsubscribe(); + setStateWithRef([], setOtherAccounts, otherAccountsRef); + } + return () => unsubscribe(); + }, [network, checkingInjectedWeb3]); + + // Unsubscrbe all account subscriptions. + const unsubscribe = () => { + Object.values(unsubs.current).forEach((unsub) => { + unsub(); + }); + }; + + // Add other accounts to context state. + const addOtherAccounts = (a: ImportedAccount[]) => { + setStateWithRef( + [...otherAccountsRef.current].concat(a), + setOtherAccounts, + otherAccountsRef + ); + }; + + // Once extensions are fully initialised, fetch accounts from other sources. + useEffectIgnoreInitial(() => { + if (extensionAccountsSynced) { + // Fetch accounts from supported hardware wallets. + importLocalOtherAccounts(getLocalVaultAccounts); + importLocalOtherAccounts(getLocalLedgerAccounts); + + // Mark hardware wallets as initialised. + setOtherAccountsSynced(true); + + // Finally, fetch any read-only accounts that have been added by `system` or `user`. + importLocalOtherAccounts(getLocalExternalAccounts); + } + }, [extensionAccountsSynced]); + + // Account fetching complete, mark accounts as initialised. Does not include read only accounts. + useEffectIgnoreInitial(() => { + if (extensionAccountsSynced && otherAccountsSynced === true) { + setAccountsInitialised(true); + } + }, [extensionAccountsSynced, otherAccountsSynced]); + + return ( + + {children} + + ); +}; + +export const useOtherAccounts = () => useContext(OtherAccountsContext); diff --git a/src/contexts/Connect/OtherAccounts/types.ts b/src/contexts/Connect/OtherAccounts/types.ts new file mode 100644 index 0000000000..2beb3b7137 --- /dev/null +++ b/src/contexts/Connect/OtherAccounts/types.ts @@ -0,0 +1,16 @@ +// Copyright 2023 @paritytech/polkadot-staking-dashboard authors & contributors +// SPDX-License-Identifier: GPL-3.0-only + +import type { ImportedAccount } from '@polkadot-cloud/react/connect/types'; +import type { MaybeAddress, NetworkName } from 'types'; + +export interface OtherAccountsContextInterface { + addExternalAccount: (a: string, addedBy: string) => void; + addOtherAccounts: (a: ImportedAccount[]) => void; + renameOtherAccount: (a: MaybeAddress, n: string) => void; + importLocalOtherAccounts: (g: (n: NetworkName) => ImportedAccount[]) => void; + forgetOtherAccounts: (a: ImportedAccount[]) => void; + forgetExternalAccounts: (a: ImportedAccount[]) => void; + accountsInitialised: boolean; + otherAccounts: ImportedAccount[]; +} diff --git a/src/contexts/Connect/Utils.ts b/src/contexts/Connect/Utils.ts index 1c1e55622f..bf0aa77922 100644 --- a/src/contexts/Connect/Utils.ts +++ b/src/contexts/Connect/Utils.ts @@ -5,7 +5,7 @@ import Keyring from '@polkadot/keyring'; import { localStorageOrDefault } from '@polkadot-cloud/utils'; import type { ExtensionAccount } from '@polkadot-cloud/react/connect/ExtensionsProvider/types'; import type { NetworkName } from 'types'; -import type { ExternalAccount } from './types'; +import type { ExternalAccount } from '@polkadot-cloud/react/connect/types'; // extension utils @@ -103,6 +103,8 @@ export const removeLocalExternalAccounts = ( network: NetworkName, accounts: ExternalAccount[] ) => { + if (!accounts.length) return; + let localExternalAccounts = getLocalExternalAccounts(network); localExternalAccounts = localExternalAccounts.filter( (a) => @@ -114,3 +116,17 @@ export const removeLocalExternalAccounts = ( JSON.stringify(localExternalAccounts) ); }; + +export const formatAccountSs58 = (address: string, ss58: number) => { + try { + const keyring = new Keyring(); + keyring.setSS58Format(ss58); + const formatted = keyring.addFromAddress(address).address; + if (formatted !== address) { + return formatted; + } + return null; + } catch (e) { + return null; + } +}; diff --git a/src/contexts/Connect/defaults.ts b/src/contexts/Connect/defaults.ts deleted file mode 100644 index b03e89c384..0000000000 --- a/src/contexts/Connect/defaults.ts +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright 2023 @paritytech/polkadot-staking-dashboard authors & contributors -// SPDX-License-Identifier: GPL-3.0-only -/* eslint-disable @typescript-eslint/no-unused-vars */ - -import type { ConnectContextInterface } from 'contexts/Connect/types'; - -export const defaultConnectContext: ConnectContextInterface = { - formatAccountSs58: (a: string) => null, - connectExtensionAccounts: async (e) => - new Promise((resolve) => resolve(false)), - getAccount: (a) => null, - connectToAccount: (a) => {}, - disconnectFromAccount: () => {}, - addExternalAccount: (a, b) => {}, - getActiveAccount: () => null, - accountHasSigner: (a) => false, - requiresManualSign: (a) => false, - isReadOnlyAccount: (a) => false, - addToAccounts: (a) => {}, - forgetAccounts: (a) => {}, - setActiveProxy: (p, l) => {}, - renameImportedAccount: (a, n) => {}, - accounts: [], - activeAccount: null, - activeProxy: null, - activeProxyType: null, - accountsInitialised: false, -}; - -export const defaultHandleImportExtension = { - newAccounts: [], - meta: { - removedActiveAccount: null, - }, -}; diff --git a/src/contexts/Connect/index.tsx b/src/contexts/Connect/index.tsx deleted file mode 100644 index 510d3a2369..0000000000 --- a/src/contexts/Connect/index.tsx +++ /dev/null @@ -1,619 +0,0 @@ -// Copyright 2023 @paritytech/polkadot-staking-dashboard authors & contributors -// SPDX-License-Identifier: GPL-3.0-only - -import type { VoidFn } from '@polkadot/api/types'; -import Keyring from '@polkadot/keyring'; -import { - ellipsisFn, - localStorageOrDefault, - setStateWithRef, -} from '@polkadot-cloud/utils'; -import React, { useEffect, useRef, useState } from 'react'; -import { DappName } from 'consts'; -import type { - ActiveProxy, - ConnectContextInterface, - ExternalAccount, - ImportedAccount, -} from 'contexts/Connect/types'; -import { - useExtensions, - useEffectIgnoreInitial, -} from '@polkadot-cloud/react/hooks'; -import { - getLocalLedgerAccounts, - getLocalVaultAccounts, -} from 'contexts/Hardware/Utils'; -import type { AnyApi, MaybeAccount, NetworkName } from 'types'; -import type { - ExtensionInjected, - ExtensionInterface, -} from '@polkadot-cloud/react/connect/ExtensionsProvider/types'; -import { useNetwork } from 'contexts/Network'; -import { useImportExtension } from './Hooks/useImportExtension'; -import { - extensionIsLocal, - getActiveAccountLocal, - getLocalExternalAccounts, - manualSigners, - removeFromLocalExtensions, - removeLocalExternalAccounts, -} from './Utils'; -import { defaultConnectContext } from './defaults'; - -export const ConnectProvider = ({ - children, -}: { - children: React.ReactNode; -}) => { - const { networkData, network } = useNetwork(); - const { checkingInjectedWeb3, extensions, setExtensionStatus } = - useExtensions(); - const { - handleImportExtension, - getActiveExtensionAccount, - connectActiveExtensionAccount, - } = useImportExtension(); - - // store whether extension accounts have been synced. - const [extensionAccountsSynced, setExtensionAccountsSynced] = - useState(false); - - // store accounts list - const [accounts, setAccounts] = useState([]); - const accountsRef = useRef(accounts); - - // store the currently active account - const [activeAccount, setActiveAccountState] = useState(null); - const activeAccountRef = useRef(activeAccount); - - // store the active proxy account - const [activeProxy, setActiveProxyState] = useState(null); - const activeProxyRef = useRef(activeProxy); - - const setActiveProxy = (newActiveProxy: ActiveProxy, updateLocal = true) => { - if (updateLocal) { - if (newActiveProxy) { - localStorage.setItem( - `${network}_active_proxy`, - JSON.stringify(newActiveProxy) - ); - } else { - localStorage.removeItem(`${network}_active_proxy`); - } - } - setStateWithRef(newActiveProxy, setActiveProxyState, activeProxyRef); - }; - - // store unsubscribe handlers for connected extensions. - const unsubs = useRef>({}); - - // store extensions whose account subscriptions have been initialised - const [extensionsInitialised, setExtensionsInitialised] = useState( - [] - ); - const extensionsInitialisedRef = useRef(extensionsInitialised); - - // store whether hardwaree accounts have been initialised. - const hardwareInitialisedRef = useRef(false); - - // store whether all accounts have been initialised. - const accountsInitialisedRef = useRef(false); - - /* re-sync extensions accounts on network switch - * do this if activeAccount is present. - * if activeAccount is present, and extensions have for some - * reason forgot the site, then all pop-ups will be summoned - * here. - */ - useEffect(() => { - // wait for injectedWeb3 check to finish before starting - // account import process. - if (!checkingInjectedWeb3) { - // unsubscribe from all accounts and reset state - unsubscribe(); - setStateWithRef(null, setActiveAccountState, activeAccountRef); - setStateWithRef([], setAccounts, accountsRef); - setStateWithRef([], setExtensionsInitialised, extensionsInitialisedRef); - setExtensionAccountsSynced(false); - - // if extensions have been fetched, get accounts if extensions exist and - // local extensions exist (previously connected). - - if (extensions.length) { - // get active extensions - const localExtensions = localStorageOrDefault( - `active_extensions`, - [], - true - ); - if (extensions.length && localExtensions.length) { - connectActiveExtensions(); - } else { - setExtensionAccountsSynced(true); - } - } - } - return () => unsubscribe(); - }, [extensions?.length, network, checkingInjectedWeb3]); - - // Once initialised extensions equal total extensions present in `injectedWeb3`, mark extensions - // as fetched. - useEffectIgnoreInitial(() => { - if ( - (!checkingInjectedWeb3 && - extensionsInitialisedRef.current.length === extensions?.length) || - 0 - ) { - setExtensionAccountsSynced(true); - } - }, [checkingInjectedWeb3, extensionsInitialisedRef.current]); - - // Once extensions are fully initialised, fetch accounts from other sources. - useEffectIgnoreInitial(() => { - if (extensionAccountsSynced) { - // Fetch accounts from supported hardware wallets. - importLocalAccounts(getLocalVaultAccounts); - importLocalAccounts(getLocalLedgerAccounts); - hardwareInitialisedRef.current = true; - // Finally, fetch any read-only accounts that have been added by `system` or `user`. - importLocalAccounts(getLocalExternalAccounts); - } - }, [extensionAccountsSynced]); - - // Account fetching complete, mark accounts as initialised. Does not include read only accounts. - useEffectIgnoreInitial(() => { - if (extensionAccountsSynced && hardwareInitialisedRef.current === true) { - accountsInitialisedRef.current = true; - } - }, [extensionAccountsSynced, hardwareInitialisedRef.current]); - - // Unsubscrbe all account subscriptions. - const unsubscribe = () => { - Object.values(unsubs.current).forEach((unsub) => { - unsub(); - }); - }; - - // Unsubscrbe from some account subscriptions and update the resulting state. - const forgetAccounts = (forget: ImportedAccount[]) => { - if (!forget.length) return; - - for (const { address } of forget) { - const unsub = unsubs.current[address]; - if (unsub) { - unsub(); - delete unsubs.current[address]; - } - } - - // If the currently active account is being forgotten, disconnect. - if ( - forget.find((a) => a.address === activeAccountRef.current) !== undefined - ) { - localStorage.removeItem(`${network}_active_account`); - setStateWithRef(null, setActiveAccount, activeAccountRef); - } - - // Get any external accounts and remove from localStorage. - const externalToForget = forget.filter((i) => 'network' in i); - if (externalToForget.length) { - removeLocalExternalAccounts( - network, - externalToForget as ExternalAccount[] - ); - } - - // Remove forgotten accounts from state. - setStateWithRef( - [...accountsRef.current].filter( - (a) => forget.find(({ address }) => address === a.address) === undefined - ), - setAccounts, - accountsRef - ); - }; - - // renames an account - const renameImportedAccount = (address: MaybeAccount, newName: string) => { - setStateWithRef( - [...accountsRef.current].map((a) => - a.address !== address - ? a - : { - ...a, - name: newName, - } - ), - setAccounts, - accountsRef - ); - }; - - /* Checks `localStorage` for previously added accounts from the provided source, and adds them to - * `accounts` state. if local active account is present, it will also be assigned as active. - * Accounts are ignored if they are already imported through an extension. */ - const importLocalAccounts = ( - getter: (n: NetworkName) => ImportedAccount[] - ) => { - // Get accounts from provided `getter` function. The resulting array of accounts must contain an - // `address` field. - let localAccounts = getter(network); - - if (localAccounts.length) { - const activeAccountInSet = - localAccounts.find( - ({ address }) => - address === getActiveAccountLocal(network, networkData.ss58) - ) ?? null; - - // remove already-imported accounts. - localAccounts = localAccounts.filter( - (l) => - accountsRef.current.find(({ address }) => address === l.address) === - undefined - ); - - // set active account for networkData. - if (activeAccountInSet) { - connectToAccount(activeAccountInSet); - } - // add accounts to imported. - addToAccounts(localAccounts); - } - }; - - /* connectActiveExtensions - * Connects to extensions that already have been connected - * to and stored in localStorage. - * Loop through extensions and connect to accounts. - * If `activeAccount` exists locally, we wait until all - * extensions are looped before connecting to it; there is - * no guarantee it still exists - must explicitly find it. - */ - const connectActiveExtensions = async () => { - // iterate extensions and add accounts to state - const total = extensions?.length ?? 0; - let activeWalletAccount: ImportedAccount | null = null; - - if (!extensions) { - return; - } - - let i = 0; - extensions.forEach(async (e: ExtensionInjected) => { - i++; - - // ensure the extension carries an `id` property - const id = e?.id ?? undefined; - - // whether extension is locally stored (previously connected) - const isLocal = extensionIsLocal(id ?? 0); - - if (!id || !isLocal) { - updateInitialisedExtensions( - id || - `unknown_extension_${extensionsInitialisedRef.current.length + 1}` - ); - } else { - try { - // attempt to get extension `enable` property - const { enable } = e; - - // summons extension popup - const extension: ExtensionInterface = await enable(DappName); - - if (extension !== undefined) { - const unsub = extension.accounts.subscribe((a) => { - if (a) { - const { newAccounts, meta } = handleImportExtension( - id, - accountsRef.current, - extension, - a, - forgetAccounts - ); - - // store active wallet account if found in this extension - if (!activeWalletAccount) { - activeWalletAccount = getActiveExtensionAccount(newAccounts); - } - // set active account for network on final extension - if (i === total && activeAccountRef.current === null) { - const activeAccountRemoved = - activeWalletAccount?.address !== - meta.removedActiveAccount && - meta.removedActiveAccount !== null; - - if (!activeAccountRemoved) { - connectActiveExtensionAccount( - activeWalletAccount, - connectToAccount - ); - } - } - - // concat accounts and store - addToAccounts(newAccounts); - - // update initialised extensions - updateInitialisedExtensions(id); - } - }); - - addToUnsubscribe(id, unsub); - } - } catch (err) { - handleExtensionError(id, String(err)); - } - } - }); - }; - - /* connectExtensionAccounts - * Similar to the above but only connects to a single extension. - * This is invoked by the user by clicking on an extension. - * If activeAccount is not found here, it is simply ignored. - */ - const connectExtensionAccounts = async ( - e: ExtensionInjected - ): Promise => { - // ensure the extension carries an `id` property - const id = e?.id ?? undefined; - - if (!id) { - updateInitialisedExtensions( - `unknown_extension_${extensionsInitialisedRef.current.length + 1}` - ); - } else { - try { - // attempt to get extension `enable` property - const { enable } = e; - - // summons extension popup - const extension: ExtensionInterface = await enable(DappName); - - if (extension !== undefined) { - // subscribe to accounts - const unsub = extension.accounts.subscribe((a) => { - if (a) { - const { newAccounts, meta } = handleImportExtension( - id, - accountsRef.current, - extension, - a, - forgetAccounts - ); - // set active account for network if not yet set - if (activeAccountRef.current === null) { - const activeExtensionAccount = - getActiveExtensionAccount(newAccounts); - - if ( - activeExtensionAccount !== meta.removedActiveAccount && - meta.removedActiveAccount !== null - ) - connectActiveExtensionAccount( - activeExtensionAccount, - connectToAccount - ); - } - // concat accounts and store - addToAccounts(newAccounts); - - // update initialised extensions - updateInitialisedExtensions(id); - } - }); - addToUnsubscribe(id, unsub); - return true; - } - } catch (err) { - handleExtensionError(id, String(err)); - } - } - return false; - }; - - const handleExtensionError = (id: string, err: string) => { - // if not general error (maybe enabled but no accounts trust app) - if (err.startsWith('Error')) { - // remove extension from local `active_extensions`. - removeFromLocalExtensions(id); - - // extension not found (does not exist) - if (err.substring(0, 17) === 'NotInstalledError') { - setExtensionStatus(id, 'not_found'); - } else { - // declare extension as no imported accounts authenticated. - setExtensionStatus(id, 'not_authenticated'); - } - } - // mark extension as initialised - updateInitialisedExtensions(id); - }; - - const setActiveAccount = (address: MaybeAccount) => { - if (address === null) { - localStorage.removeItem(`${network}_active_account`); - } else { - localStorage.setItem(`${network}_active_account`, address); - } - setStateWithRef(address, setActiveAccountState, activeAccountRef); - }; - - const connectToAccount = (account: ImportedAccount | null) => { - setActiveAccount(account?.address ?? null); - }; - - const disconnectFromAccount = () => { - localStorage.removeItem(`${network}_active_account`); - setActiveAccount(null); - }; - - const getAccount = (who: MaybeAccount) => - accountsRef.current.find(({ address }) => address === who) || null; - - const getActiveAccount = () => activeAccountRef.current; - - // adds an external account (non-wallet) to accounts - const addExternalAccount = (address: string, addedBy: string) => { - // ensure account is formatted correctly - const keyring = new Keyring(); - keyring.setSS58Format(networkData.ss58); - const formatted = keyring.addFromAddress(address).address; - - const newAccount = { - address: formatted, - network, - name: ellipsisFn(address), - source: 'external', - addedBy, - }; - - // get all external accounts from localStorage. - const localExternalAccounts = getLocalExternalAccounts(); - const existsLocal = localExternalAccounts.find( - (l) => l.address === address && l.network === network - ); - - // check that address is not sitting in imported accounts (currently cannot check which - // network). - const existsImported = accountsRef.current.find( - (a) => a.address === address - ); - - // add external account if not there already. - if (!existsLocal && !existsImported) { - localStorage.setItem( - 'external_accounts', - JSON.stringify(localExternalAccounts.concat(newAccount)) - ); - - // add external account to imported accounts - addToAccounts([newAccount]); - } else if (existsLocal && existsLocal.addedBy !== 'system') { - // the external account needs to change to `system` so it cannot be removed. This will replace - // the whole entry. - localStorage.setItem( - 'external_accounts', - JSON.stringify( - localExternalAccounts.map((item) => - item.address !== address ? item : newAccount - ) - ) - ); - // refresh accounts state. - replaceAccount(newAccount); - } - }; - - // Checks whether an account can sign transactions - const accountHasSigner = (address: MaybeAccount) => - accountsRef.current.find( - (a) => a.address === address && a.source !== 'external' - ) !== undefined; - - // Checks whether an account needs manual signing. This is the case for Ledger accounts, - // transactions of which cannot be automatically signed by a provided `signer` as is the case with - // extensions. - const requiresManualSign = (address: MaybeAccount) => - accountsRef.current.find( - (a) => a.address === address && manualSigners.includes(a.source) - ) !== undefined; - - const isReadOnlyAccount = (address: MaybeAccount) => { - const account = getAccount(address) ?? {}; - - if (Object.prototype.hasOwnProperty.call(account, 'addedBy')) { - const { addedBy } = account as ExternalAccount; - return addedBy === 'user'; - } - return false; - }; - - // formats an address into the currently active network's ss58 format. - const formatAccountSs58 = (address: string) => { - try { - const keyring = new Keyring(); - keyring.setSS58Format(networkData.ss58); - const formatted = keyring.addFromAddress(address).address; - if (formatted !== address) { - return formatted; - } - return null; - } catch (e) { - return null; - } - }; - - // update initialised extensions. - const updateInitialisedExtensions = (id: string) => { - if (!extensionsInitialisedRef.current.includes(id)) { - setStateWithRef( - [...extensionsInitialisedRef.current].concat(id), - setExtensionsInitialised, - extensionsInitialisedRef - ); - } - }; - - // add accounts to context state. - const addToAccounts = (a: ImportedAccount[]) => { - setStateWithRef( - [...accountsRef.current].concat(a), - setAccounts, - accountsRef - ); - }; - - // replaces an account in context state. - const replaceAccount = (a: ImportedAccount) => { - setStateWithRef( - [...accountsRef.current].map((item) => - item.address !== a.address ? item : a - ), - setAccounts, - accountsRef - ); - }; - - // add an extension id to unsubscribe state. - const addToUnsubscribe = (id: string, unsub: AnyApi) => { - unsubs.current[id] = unsub; - }; - - return ( - - {children} - - ); -}; - -export const ConnectContext = React.createContext( - defaultConnectContext -); - -export const useConnect = () => React.useContext(ConnectContext); diff --git a/src/contexts/Connect/types.ts b/src/contexts/Connect/types.ts deleted file mode 100644 index c68e4d3c48..0000000000 --- a/src/contexts/Connect/types.ts +++ /dev/null @@ -1,71 +0,0 @@ -// Copyright 2023 @paritytech/polkadot-staking-dashboard authors & contributors -// SPDX-License-Identifier: GPL-3.0-only - -import type { - ExtensionAccount, - ExtensionInjected, -} from '@polkadot-cloud/react/connect/ExtensionsProvider/types'; -import type { MaybeAccount } from 'types'; - -export interface ConnectContextInterface { - formatAccountSs58: (a: string) => string | null; - connectExtensionAccounts: (e: ExtensionInjected) => Promise; - getAccount: (account: MaybeAccount) => ExtensionAccount | null; - connectToAccount: (a: ImportedAccount | null) => void; - disconnectFromAccount: () => void; - addExternalAccount: (a: string, addedBy: string) => void; - getActiveAccount: () => string | null; - accountHasSigner: (a: MaybeAccount) => boolean; - requiresManualSign: (a: MaybeAccount) => boolean; - isReadOnlyAccount: (a: MaybeAccount) => boolean; - addToAccounts: (a: ImportedAccount[]) => void; - forgetAccounts: (a: ImportedAccount[]) => void; - setActiveProxy: (p: ActiveProxy, l?: boolean) => void; - renameImportedAccount: (a: MaybeAccount, n: string) => void; - accounts: ExtensionAccount[]; - activeAccount: MaybeAccount; - activeProxy: MaybeAccount; - activeProxyType: string | null; - accountsInitialised: boolean; -} - -export type ImportedAccount = - | ExtensionAccount - | ExternalAccount - | LedgerAccount; - -export interface ExternalAccount { - address: string; - network: string; - name: string; - source: string; - addedBy: string; -} - -export interface LedgerAccount { - address: string; - network: string; - name: string; - source: string; - index: number; -} - -export interface VaultAccount { - address: string; - network: string; - name: string; - source: string; - index: number; -} - -export interface HandleImportExtension { - newAccounts: ExtensionAccount[]; - meta: { - removedActiveAccount: MaybeAccount; - }; -} - -export type ActiveProxy = { - address: MaybeAccount; - proxyType: string; -} | null; diff --git a/src/contexts/FastUnstake/index.tsx b/src/contexts/FastUnstake/index.tsx index 764dc3eb23..6c7712af60 100644 --- a/src/contexts/FastUnstake/index.tsx +++ b/src/contexts/FastUnstake/index.tsx @@ -10,15 +10,15 @@ import { import BigNumber from 'bignumber.js'; import React, { useRef, useState } from 'react'; import { useApi } from 'contexts/Api'; -import { useConnect } from 'contexts/Connect'; import { useNetworkMetrics } from 'contexts/NetworkMetrics'; import { useStaking } from 'contexts/Staking'; -import type { AnyApi, AnyJson, MaybeAccount } from 'types'; +import type { AnyApi, AnyJson, MaybeAddress } from 'types'; import Worker from 'workers/stakers?worker'; import { useEffectIgnoreInitial } from '@polkadot-cloud/react/hooks'; import { useNominationStatus } from 'library/Hooks/useNominationStatus'; import { validateLocalExposure } from 'contexts/Validators/Utils'; import { useNetwork } from 'contexts/Network'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; import { defaultFastUnstakeContext, defaultMeta } from './defaults'; import type { FastUnstakeContextInterface, @@ -34,8 +34,8 @@ export const FastUnstakeProvider = ({ children: React.ReactNode; }) => { const { network } = useNetwork(); - const { activeAccount } = useConnect(); const { api, isReady, consts } = useApi(); + const { activeAccount } = useActiveAccounts(); const { inSetup, fetchEraStakers } = useStaking(); const { metrics, activeEra } = useNetworkMetrics(); const { getNominationStatus } = useNominationStatus(); @@ -71,7 +71,7 @@ export const FastUnstakeProvider = ({ const unsubs = useRef([]); // localStorage key to fetch local metadata. - const getLocalkey = (a: MaybeAccount) => `${network}_fast_unstake_${a}`; + const getLocalkey = (a: MaybeAddress) => `${network}_fast_unstake_${a}`; // check until bond duration eras surpasssed. const checkToEra = activeEra.index.minus(bondDuration); @@ -216,7 +216,7 @@ export const FastUnstakeProvider = ({ }; // initiate fast unstake eligibility check. - const processEligibility = async (a: MaybeAccount, era: BigNumber) => { + const processEligibility = async (a: MaybeAddress, era: BigNumber) => { // ensure current era has synced if ( era.isLessThan(0) || @@ -251,7 +251,7 @@ export const FastUnstakeProvider = ({ // subscribe to fastUnstake queue const subscribeToFastUnstakeQueue = async () => { if (!api || !activeAccount) return; - const subscribeQueue = async (a: MaybeAccount) => { + const subscribeQueue = async (a: MaybeAddress) => { const u = await api.query.fastUnstake.queue(a, (q: AnyApi) => setStateWithRef( new BigNumber(rmCommas(q.unwrapOrDefault(0).toString())), diff --git a/src/contexts/FastUnstake/types.ts b/src/contexts/FastUnstake/types.ts index b903b23000..1c6dfc2c1b 100644 --- a/src/contexts/FastUnstake/types.ts +++ b/src/contexts/FastUnstake/types.ts @@ -2,7 +2,7 @@ // SPDX-License-Identifier: GPL-3.0-only import type BigNumber from 'bignumber.js'; -import type { AnyApi, MaybeAccount } from 'types'; +import type { AnyApi, MaybeAddress } from 'types'; export interface LocalMeta { isExposed: boolean; @@ -13,7 +13,7 @@ export interface MetaInterface { } export interface FastUnstakeContextInterface { - getLocalkey: (a: MaybeAccount) => string; + getLocalkey: (a: MaybeAddress) => string; checking: boolean; meta: MetaInterface; isExposed: boolean | null; diff --git a/src/contexts/Hardware/Ledger.tsx b/src/contexts/Hardware/Ledger.tsx index 8fa36324d1..af11d3c837 100644 --- a/src/contexts/Hardware/Ledger.tsx +++ b/src/contexts/Hardware/Ledger.tsx @@ -7,7 +7,7 @@ import { localStorageOrDefault, setStateWithRef } from '@polkadot-cloud/utils'; import { newSubstrateApp } from '@zondax/ledger-substrate'; import React, { useEffect, useRef, useState } from 'react'; import { useTranslation } from 'react-i18next'; -import type { LedgerAccount } from 'contexts/Connect/types'; +import type { LedgerAccount } from '@polkadot-cloud/react/connect/types'; import type { AnyFunction, AnyJson, MaybeString } from 'types'; import { useNetwork } from 'contexts/Network'; import { diff --git a/src/contexts/Hardware/Utils.tsx b/src/contexts/Hardware/Utils.tsx index 6dd25a8050..c61a8e324b 100644 --- a/src/contexts/Hardware/Utils.tsx +++ b/src/contexts/Hardware/Utils.tsx @@ -3,8 +3,11 @@ import { localStorageOrDefault } from '@polkadot-cloud/utils'; import { LedgerApps } from 'config/ledger'; -import type { LedgerAccount, VaultAccount } from 'contexts/Connect/types'; import type { MaybeString } from 'types'; +import type { + LedgerAccount, + VaultAccount, +} from '@polkadot-cloud/react/connect/types'; import type { LedgerAddress } from './types'; // Gets ledger app from local storage, fallback to first entry. diff --git a/src/contexts/Hardware/Vault.tsx b/src/contexts/Hardware/Vault.tsx index 20b623a536..0c68923374 100644 --- a/src/contexts/Hardware/Vault.tsx +++ b/src/contexts/Hardware/Vault.tsx @@ -3,7 +3,7 @@ import { ellipsisFn, setStateWithRef } from '@polkadot-cloud/utils'; import React, { useEffect, useRef, useState } from 'react'; -import type { VaultAccount } from 'contexts/Connect/types'; +import type { VaultAccount } from '@polkadot-cloud/react/connect/types'; import { useNetwork } from 'contexts/Network'; import { getLocalVaultAccounts, isLocalNetworkAddress } from './Utils'; import { defaultVaultHardwareContext } from './defaults'; diff --git a/src/contexts/Hardware/types.ts b/src/contexts/Hardware/types.ts index 552bbb7f5b..6d9e0b7b3f 100644 --- a/src/contexts/Hardware/types.ts +++ b/src/contexts/Hardware/types.ts @@ -1,8 +1,11 @@ // Copyright 2023 @paritytech/polkadot-staking-dashboard authors & contributors // SPDX-License-Identifier: GPL-3.0-only +import type { + LedgerAccount, + VaultAccount, +} from '@polkadot-cloud/react/connect/types'; import type { FunctionComponent, SVGProps } from 'react'; -import type { LedgerAccount, VaultAccount } from 'contexts/Connect/types'; import type { AnyJson, MaybeString, NetworkName } from 'types'; export type LedgerHardwareContextInterface = { diff --git a/src/contexts/Migrate/index.tsx b/src/contexts/Migrate/index.tsx index 93e5174906..4f5713ff4e 100644 --- a/src/contexts/Migrate/index.tsx +++ b/src/contexts/Migrate/index.tsx @@ -5,9 +5,9 @@ import React, { useState } from 'react'; import { NetworkList } from 'config/networks'; import { AppVersion } from 'consts'; import { useApi } from 'contexts/Api'; -import { useConnect } from 'contexts/Connect'; import { useUi } from 'contexts/UI'; import { useEffectIgnoreInitial } from '@polkadot-cloud/react/hooks'; +import { useImportedAccounts } from 'contexts/Connect/ImportedAccounts'; export const MigrateProvider = ({ children, @@ -15,8 +15,8 @@ export const MigrateProvider = ({ children: React.ReactNode; }) => { const { isReady } = useApi(); - const { accounts } = useConnect(); const { isNetworkSyncing } = useUi(); + const { accounts } = useImportedAccounts(); // The local app version of the current user. const localAppVersion = localStorage.getItem('app_version'); diff --git a/src/contexts/Payouts/index.tsx b/src/contexts/Payouts/index.tsx index 54e9a505bc..5b7d327d42 100644 --- a/src/contexts/Payouts/index.tsx +++ b/src/contexts/Payouts/index.tsx @@ -5,12 +5,12 @@ import React, { useState, useEffect, useRef } from 'react'; import { useStaking } from 'contexts/Staking'; import { useApi } from 'contexts/Api'; import type { AnyApi, AnyJson, Sync } from 'types'; -import { useConnect } from 'contexts/Connect'; import { useNetworkMetrics } from 'contexts/NetworkMetrics'; import Worker from 'workers/stakers?worker'; import { rmCommas, setStateWithRef } from '@polkadot-cloud/utils'; import BigNumber from 'bignumber.js'; import { useNetwork } from 'contexts/Network'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; import { MaxSupportedPayoutEras, defaultPayoutsContext } from './defaults'; import type { LocalValidatorExposure, @@ -33,8 +33,8 @@ export const PayoutsProvider = ({ }) => { const { api } = useApi(); const { network } = useNetwork(); - const { activeAccount } = useConnect(); const { activeEra } = useNetworkMetrics(); + const { activeAccount } = useActiveAccounts(); const { isNominating, fetchEraStakers } = useStaking(); // Store active accont's payout state. diff --git a/src/contexts/Plugins/Subscan/index.tsx b/src/contexts/Plugins/Subscan/index.tsx index e271822153..7272096ff7 100644 --- a/src/contexts/Plugins/Subscan/index.tsx +++ b/src/contexts/Plugins/Subscan/index.tsx @@ -18,8 +18,8 @@ import { locales } from 'locale'; import type { AnyApi, AnySubscan } from 'types'; import { useEffectIgnoreInitial } from '@polkadot-cloud/react/hooks'; import { useNetwork } from 'contexts/Network'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; import { useApi } from '../../Api'; -import { useConnect } from '../../Connect'; import { usePlugins } from '..'; import { defaultSubscanContext } from './defaults'; import type { SubscanContextInterface } from './types'; @@ -35,7 +35,7 @@ export const SubscanProvider = ({ network, networkData: { subscanEndpoint }, } = useNetwork(); - const { activeAccount } = useConnect(); + const { activeAccount } = useActiveAccounts(); const { activeEra } = useNetworkMetrics(); const { erasToSeconds } = useErasToTimeLeft(); const { plugins, pluginEnabled } = usePlugins(); diff --git a/src/contexts/Pools/ActivePools/index.tsx b/src/contexts/Pools/ActivePools/index.tsx index 37653cf9ce..a0fa72a39d 100644 --- a/src/contexts/Pools/ActivePools/index.tsx +++ b/src/contexts/Pools/ActivePools/index.tsx @@ -15,8 +15,8 @@ import { useEffectIgnoreInitial } from '@polkadot-cloud/react/hooks'; import { useSubscan } from 'contexts/Plugins/Subscan'; import { usePlugins } from 'contexts/Plugins'; import { useNetwork } from 'contexts/Network'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; import { useApi } from '../../Api'; -import { useConnect } from '../../Connect'; import { useBondedPools } from '../BondedPools'; import { usePoolMemberships } from '../PoolMemberships'; import { usePoolsConfig } from '../PoolsConfig'; @@ -32,10 +32,10 @@ export const ActivePoolsProvider = ({ const { api, isReady } = useApi(); const { eraStakers } = useStaking(); const { pluginEnabled } = usePlugins(); - const { activeAccount } = useConnect(); const { fetchPoolDetails } = useSubscan(); const { membership } = usePoolMemberships(); const { createAccounts } = usePoolsConfig(); + const { activeAccount } = useActiveAccounts(); const { getAccountPools, bondedPools } = useBondedPools(); const { getMembersOfPoolFromNode, poolMembersNode } = usePoolMembers(); diff --git a/src/contexts/Pools/BondedPools/index.tsx b/src/contexts/Pools/BondedPools/index.tsx index 77f8b0e691..338bf441dc 100644 --- a/src/contexts/Pools/BondedPools/index.tsx +++ b/src/contexts/Pools/BondedPools/index.tsx @@ -11,7 +11,7 @@ import type { NominationStatuses, } from 'contexts/Pools/types'; import { useStaking } from 'contexts/Staking'; -import type { AnyApi, AnyMetaBatch, Fn, MaybeAccount } from 'types'; +import type { AnyApi, AnyMetaBatch, Fn, MaybeAddress } from 'types'; import { useEffectIgnoreInitial } from '@polkadot-cloud/react/hooks'; import { useNetwork } from 'contexts/Network'; import { useApi } from '../../Api'; @@ -219,8 +219,8 @@ export const BondedPoolsProvider = ({ * Get bonded pool nomination statuses */ const getPoolNominationStatus = ( - nominator: MaybeAccount, - nomination: MaybeAccount + nominator: MaybeAddress, + nomination: MaybeAddress ) => { const pool = bondedPools.find((p: any) => p.addresses.stash === nominator); @@ -371,7 +371,7 @@ export const BondedPoolsProvider = ({ }; // get all the roles belonging to one pool account - const getAccountRoles = (who: MaybeAccount) => { + const getAccountRoles = (who: MaybeAddress) => { if (!who) { return { depositor: [], @@ -406,10 +406,9 @@ export const BondedPoolsProvider = ({ }; // accumulate account pool list - const getAccountPools = (who: MaybeAccount) => { + const getAccountPools = (who: MaybeAddress) => { // first get the roles of the account const roles = getAccountRoles(who); - // format new list has pool => roles const pools: any = {}; Object.entries(roles).forEach(([key, poolIds]: any) => { diff --git a/src/contexts/Pools/PoolMembers/index.tsx b/src/contexts/Pools/PoolMembers/index.tsx index 5d9bc9d366..bc3e9af98c 100644 --- a/src/contexts/Pools/PoolMembers/index.tsx +++ b/src/contexts/Pools/PoolMembers/index.tsx @@ -3,12 +3,12 @@ import { setStateWithRef } from '@polkadot-cloud/utils'; import React, { useRef, useState } from 'react'; -import { useConnect } from 'contexts/Connect'; import { usePlugins } from 'contexts/Plugins'; import type { PoolMember, PoolMemberContext } from 'contexts/Pools/types'; -import type { AnyApi, AnyMetaBatch, Fn, MaybeAccount, Sync } from 'types'; +import type { AnyApi, AnyMetaBatch, Fn, MaybeAddress, Sync } from 'types'; import { useEffectIgnoreInitial } from '@polkadot-cloud/react/hooks'; import { useNetwork } from 'contexts/Network'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; import { useApi } from '../../Api'; import { defaultPoolMembers } from './defaults'; @@ -20,7 +20,7 @@ export const PoolMembersProvider = ({ const { network } = useNetwork(); const { api, isReady } = useApi(); const { pluginEnabled } = usePlugins(); - const { activeAccount } = useConnect(); + const { activeAccount } = useActiveAccounts(); // Store pool members from node. const [poolMembersNode, setPoolMembersNode] = useState([]); @@ -100,7 +100,7 @@ export const PoolMembersProvider = ({ poolMembersNode.filter((p: any) => p.poolId === String(poolId)) ?? null; // queries a pool member and formats to `PoolMember`. - const queryPoolMember = async (who: MaybeAccount) => { + const queryPoolMember = async (who: MaybeAddress) => { if (!api) return null; const poolMember: AnyApi = ( @@ -281,7 +281,7 @@ export const PoolMembersProvider = ({ }; // Removes a member from the member list and updates state. - const removePoolMember = (who: MaybeAccount) => { + const removePoolMember = (who: MaybeAddress) => { if (!pluginEnabled('subscan')) return; const newMembers = poolMembersNode.filter((p: any) => p.who !== who); diff --git a/src/contexts/Pools/PoolMemberships/index.tsx b/src/contexts/Pools/PoolMemberships/index.tsx index 44d3e0cf55..4ef225fbed 100644 --- a/src/contexts/Pools/PoolMemberships/index.tsx +++ b/src/contexts/Pools/PoolMemberships/index.tsx @@ -13,8 +13,9 @@ import type { import type { AnyApi, Fn } from 'types'; import { useEffectIgnoreInitial } from '@polkadot-cloud/react/hooks'; import { useNetwork } from 'contexts/Network'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; +import { useImportedAccounts } from 'contexts/Connect/ImportedAccounts'; import { useApi } from '../../Api'; -import { useConnect } from '../../Connect'; import * as defaults from './defaults'; export const PoolMembershipsProvider = ({ @@ -25,7 +26,8 @@ export const PoolMembershipsProvider = ({ const { t } = useTranslation('base'); const { network } = useNetwork(); const { api, isReady } = useApi(); - const { accounts: connectAccounts, activeAccount } = useConnect(); + const { activeAccount } = useActiveAccounts(); + const { accounts: connectAccounts } = useImportedAccounts(); // Stores pool memberships for the imported accounts. const [poolMemberships, setPoolMemberships] = useState([]); diff --git a/src/contexts/Pools/types.ts b/src/contexts/Pools/types.ts index 49ce2e76d6..f8c068cff4 100644 --- a/src/contexts/Pools/types.ts +++ b/src/contexts/Pools/types.ts @@ -2,7 +2,7 @@ // SPDX-License-Identifier: GPL-3.0-only import type BigNumber from 'bignumber.js'; -import type { AnyApi, AnyJson, AnyMetaBatch, MaybeAccount, Sync } from 'types'; +import type { AnyApi, AnyJson, AnyMetaBatch, MaybeAddress, Sync } from 'types'; // PoolsConfig types export interface PoolsConfigContextState { @@ -66,10 +66,10 @@ export interface BondedPoolsContextState { updateBondedPools: (p: BondedPool[]) => void; addToBondedPools: (p: BondedPool) => void; removeFromBondedPools: (p: number) => void; - getPoolNominationStatus: (n: MaybeAccount, o: MaybeAccount) => any; + getPoolNominationStatus: (n: MaybeAddress, o: MaybeAddress) => any; getPoolNominationStatusCode: (t: NominationStatuses | null) => string; - getAccountRoles: (w: MaybeAccount) => any; - getAccountPools: (w: MaybeAccount) => any; + getAccountRoles: (w: MaybeAddress) => any; + getAccountPools: (w: MaybeAddress) => any; replacePoolRoles: (poolId: number, roleEdits: AnyJson) => void; poolSearchFilter: (l: any, k: string, v: string) => void; bondedPools: BondedPool[]; @@ -117,7 +117,7 @@ export interface ActivePoolsContextState { isMember: () => boolean; isDepositor: () => boolean; isBouncer: () => boolean; - getPoolBondedAccount: () => MaybeAccount; + getPoolBondedAccount: () => MaybeAddress; getPoolUnlocking: () => any; getPoolRoles: () => PoolRoles; setTargets: (t: any) => void; @@ -133,10 +133,10 @@ export interface ActivePoolsContextState { // PoolMembers types export interface PoolMemberContext { fetchPoolMembersMetaBatch: (k: string, v: AnyMetaBatch[], r: boolean) => void; - queryPoolMember: (w: MaybeAccount) => any; + queryPoolMember: (w: MaybeAddress) => any; getMembersOfPoolFromNode: (p: number) => any; addToPoolMembers: (m: any) => void; - removePoolMember: (w: MaybeAccount) => void; + removePoolMember: (w: MaybeAddress) => void; getPoolMemberCount: (p: number) => number; poolMembersNode: any; meta: AnyMetaBatch; diff --git a/src/contexts/Proxies/index.tsx b/src/contexts/Proxies/index.tsx index dab3ef0f87..3289ada39e 100644 --- a/src/contexts/Proxies/index.tsx +++ b/src/contexts/Proxies/index.tsx @@ -15,10 +15,12 @@ import BigNumber from 'bignumber.js'; import React, { useRef, useState } from 'react'; import { isSupportedProxy } from 'config/proxies'; import { useApi } from 'contexts/Api'; -import { useConnect } from 'contexts/Connect'; -import type { AnyApi, MaybeAccount } from 'types'; +import type { AnyApi, MaybeAddress } from 'types'; import { useEffectIgnoreInitial } from '@polkadot-cloud/react/hooks'; import { useNetwork } from 'contexts/Network'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; +import { useImportedAccounts } from 'contexts/Connect/ImportedAccounts'; +import { useOtherAccounts } from 'contexts/Connect/OtherAccounts'; import * as defaults from './defaults'; import type { Delegates, @@ -36,13 +38,9 @@ export const ProxiesProvider = ({ }) => { const { network } = useNetwork(); const { api, isReady } = useApi(); - const { - accounts, - activeProxy, - setActiveProxy, - activeAccount, - addExternalAccount, - } = useConnect(); + const { accounts } = useImportedAccounts(); + const { addExternalAccount } = useOtherAccounts(); + const { activeProxy, setActiveProxy, activeAccount } = useActiveAccounts(); // store the proxy accounts of each imported account. const [proxies, setProxies] = useState([]); @@ -139,12 +137,12 @@ export const ProxiesProvider = ({ }; // Gets the delegates of the given account - const getDelegates = (address: MaybeAccount): Proxy | undefined => + const getDelegates = (address: MaybeAddress): Proxy | undefined => proxiesRef.current.find(({ delegator }) => delegator === address) || undefined; // Gets delegators and proxy types for the given delegate address - const getProxiedAccounts = (address: MaybeAccount) => { + const getProxiedAccounts = (address: MaybeAddress) => { const delegate = delegatesRef.current[address || '']; if (!delegate) { return []; @@ -161,8 +159,8 @@ export const ProxiesProvider = ({ // Gets the delegates and proxy type of an account, if any. const getProxyDelegate = ( - delegator: MaybeAccount, - delegate: MaybeAccount + delegator: MaybeAddress, + delegate: MaybeAddress ): ProxyDelegate | null => proxiesRef.current .find((p) => p.delegator === delegator) diff --git a/src/contexts/Proxies/type.ts b/src/contexts/Proxies/type.ts index ef6ac4d167..9bff84464d 100644 --- a/src/contexts/Proxies/type.ts +++ b/src/contexts/Proxies/type.ts @@ -2,7 +2,7 @@ // SPDX-License-Identifier: GPL-3.0-only import type BigNumber from 'bignumber.js'; -import type { AnyJson, MaybeAccount } from 'types'; +import type { AnyJson, MaybeAddress } from 'types'; export type ProxyType = | 'Any' @@ -16,8 +16,8 @@ export type ProxyType = export type Proxies = Proxy[]; export interface Proxy { - address: MaybeAccount; - delegator: MaybeAccount; + address: MaybeAddress; + delegator: MaybeAddress; delegates: ProxyDelegate[]; reserved: BigNumber; } @@ -42,9 +42,9 @@ export interface ProxiedAccount { } export interface ProxiesContextInterface { - getDelegates: (a: MaybeAccount) => Proxy | undefined; - getProxyDelegate: (x: MaybeAccount, y: MaybeAccount) => ProxyDelegate | null; - getProxiedAccounts: (a: MaybeAccount) => ProxiedAccounts; + getDelegates: (a: MaybeAddress) => Proxy | undefined; + getProxyDelegate: (x: MaybeAddress, y: MaybeAddress) => ProxyDelegate | null; + getProxiedAccounts: (a: MaybeAddress) => ProxiedAccounts; handleDeclareDelegate: (delegator: string) => Promise; proxies: Proxies; delegates: Delegates; diff --git a/src/contexts/Setup/index.tsx b/src/contexts/Setup/index.tsx index cb23c9ff5f..1d89267de4 100644 --- a/src/contexts/Setup/index.tsx +++ b/src/contexts/Setup/index.tsx @@ -8,10 +8,11 @@ import { } from '@polkadot-cloud/utils'; import React, { useState } from 'react'; import { usePoolMemberships } from 'contexts/Pools/PoolMemberships'; -import type { BondFor, MaybeAccount } from 'types'; +import type { BondFor, MaybeAddress } from 'types'; import { useEffectIgnoreInitial } from '@polkadot-cloud/react/hooks'; import { useNetwork } from 'contexts/Network'; -import { useConnect } from '../Connect'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; +import { useImportedAccounts } from 'contexts/Connect/ImportedAccounts'; import { useStaking } from '../Staking'; import { defaultNominatorProgress, @@ -34,7 +35,8 @@ export const SetupProvider = ({ children }: { children: React.ReactNode }) => { network, networkData: { units }, } = useNetwork(); - const { accounts, activeAccount } = useConnect(); + const { accounts } = useImportedAccounts(); + const { activeAccount } = useActiveAccounts(); const { membership: poolMembership } = usePoolMemberships(); // is the user actively on the setup page @@ -60,7 +62,7 @@ export const SetupProvider = ({ children }: { children: React.ReactNode }) => { // not yet exist. const getSetupProgress = ( type: BondFor, - address: MaybeAccount + address: MaybeAddress ): NominatorSetup | PoolSetup => { const setup = Object.fromEntries( Object.entries( @@ -76,7 +78,7 @@ export const SetupProvider = ({ children }: { children: React.ReactNode }) => { }; // Remove setup progress for an account. - const removeSetupProgress = (type: BondFor, address: MaybeAccount) => { + const removeSetupProgress = (type: BondFor, address: MaybeAddress) => { const updatedSetups = Object.fromEntries( Object.entries( type === 'nominator' ? nominatorSetups : poolSetups @@ -137,7 +139,7 @@ export const SetupProvider = ({ children }: { children: React.ReactNode }) => { }; // Gets the stake setup progress as a percentage for an address. - const getNominatorSetupPercent = (address: MaybeAccount) => { + const getNominatorSetupPercent = (address: MaybeAddress) => { if (!address) return 0; const setup = getSetupProgress('nominator', address) as NominatorSetup; const { progress } = setup; @@ -152,7 +154,7 @@ export const SetupProvider = ({ children }: { children: React.ReactNode }) => { }; // Gets the stake setup progress as a percentage for an address. - const getPoolSetupPercent = (address: MaybeAccount) => { + const getPoolSetupPercent = (address: MaybeAddress) => { if (!address) return 0; const setup = getSetupProgress('pool', address) as PoolSetup; const { progress } = setup; diff --git a/src/contexts/Setup/types.ts b/src/contexts/Setup/types.ts index a87fe73f13..08e9178f92 100644 --- a/src/contexts/Setup/types.ts +++ b/src/contexts/Setup/types.ts @@ -3,7 +3,7 @@ import type { PoolRoles } from 'contexts/Pools/types'; import type { ValidatorPrefs } from 'contexts/Validators/types'; -import type { AnyJson, BondFor, MaybeAccount, MaybeString } from 'types'; +import type { AnyJson, BondFor, MaybeAddress, MaybeString } from 'types'; export type PayeeOptions = | 'Staked' @@ -27,7 +27,7 @@ export interface NominatorProgress { export interface PayeeConfig { destination: PayeeOptions | null; - account: MaybeAccount; + account: MaybeAddress; } export type PoolSetups = Record; @@ -45,10 +45,10 @@ export interface PoolProgress { } export interface SetupContextInterface { - getSetupProgress: (t: BondFor, a: MaybeAccount) => any; - removeSetupProgress: (t: BondFor, a: MaybeAccount) => void; - getNominatorSetupPercent: (a: MaybeAccount) => number; - getPoolSetupPercent: (a: MaybeAccount) => number; + getSetupProgress: (t: BondFor, a: MaybeAddress) => any; + removeSetupProgress: (t: BondFor, a: MaybeAddress) => void; + getNominatorSetupPercent: (a: MaybeAddress) => number; + getPoolSetupPercent: (a: MaybeAddress) => number; setActiveAccountSetup: ( t: BondFor, p: NominatorProgress | PoolProgress diff --git a/src/contexts/Staking/index.tsx b/src/contexts/Staking/index.tsx index 677b8f7366..89e8680dbb 100644 --- a/src/contexts/Staking/index.tsx +++ b/src/contexts/Staking/index.tsx @@ -11,7 +11,7 @@ import { import BigNumber from 'bignumber.js'; import React, { useRef, useState } from 'react'; import { useBalances } from 'contexts/Balances'; -import type { ExternalAccount } from 'contexts/Connect/types'; +import type { ExternalAccount } from '@polkadot-cloud/react/connect/types'; import type { PayeeConfig, PayeeOptions } from 'contexts/Setup/types'; import type { EraStakers, @@ -20,14 +20,15 @@ import type { StakingMetrics, StakingTargets, } from 'contexts/Staking/types'; -import type { AnyApi, AnyJson, MaybeAccount } from 'types'; +import type { AnyApi, AnyJson, MaybeAddress } from 'types'; import Worker from 'workers/stakers?worker'; import type { ResponseInitialiseExposures } from 'workers/types'; import { useEffectIgnoreInitial } from '@polkadot-cloud/react/hooks'; import { useNetwork } from 'contexts/Network'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; +import { useImportedAccounts } from 'contexts/Connect/ImportedAccounts'; import { useApi } from '../Api'; import { useBonded } from '../Bonded'; -import { useConnect } from '../Connect'; import { useNetworkMetrics } from '../NetworkMetrics'; import { defaultEraStakers, @@ -48,11 +49,8 @@ export const StakingProvider = ({ }: { children: React.ReactNode; }) => { - const { - activeAccount, - accounts: connectAccounts, - getActiveAccount, - } = useConnect(); + const { accounts: connectAccounts } = useImportedAccounts(); + const { activeAccount, getActiveAccount } = useActiveAccounts(); const { getStashLedger } = useBalances(); const { activeEra } = useNetworkMetrics(); const { networkData, network } = useNetwork(); @@ -186,7 +184,7 @@ export const StakingProvider = ({ } else { const payeeEntry = Object.entries(payeeHuman); const destination = `${payeeEntry[0][0]}` as PayeeOptions; - const account = `${payeeEntry[0][1]}` as MaybeAccount; + const account = `${payeeEntry[0][1]}` as MaybeAddress; payeeFinal = { destination, account, @@ -251,7 +249,7 @@ export const StakingProvider = ({ // Gets the nomination statuses of passed in nominations. const getNominationsStatusFromTargets = ( - who: MaybeAccount, + who: MaybeAddress, fromTargets: AnyJson[] ) => { const statuses: Record = {}; @@ -280,7 +278,7 @@ export const StakingProvider = ({ }; // Helper function to determine whether the controller account is the same as the stash account. - const addressDifferentToStash = (address: MaybeAccount) => { + const addressDifferentToStash = (address: MaybeAddress) => { // check if controller is imported. if (!connectAccounts.find((acc) => acc.address === address)) { return false; @@ -289,7 +287,7 @@ export const StakingProvider = ({ }; // Helper function to determine whether the controller account has been imported. - const getControllerNotImported = (address: MaybeAccount) => { + const getControllerNotImported = (address: MaybeAddress) => { if (address === null || !activeAccount) { return false; } @@ -332,7 +330,7 @@ export const StakingProvider = ({ (!hasController() && !isBonding() && !isNominating() && !isUnlocking()); // Helper function to get the lowest reward from an active validator. - const getLowestRewardFromStaker = (address: MaybeAccount) => { + const getLowestRewardFromStaker = (address: MaybeAddress) => { const staker = eraStakersRef.current.stakers.find( (s) => s.address === address ); diff --git a/src/contexts/Staking/types.ts b/src/contexts/Staking/types.ts index 006bc8a7e2..3eebda7323 100644 --- a/src/contexts/Staking/types.ts +++ b/src/contexts/Staking/types.ts @@ -3,7 +3,7 @@ import type BigNumber from 'bignumber.js'; import type { PayeeConfig } from 'contexts/Setup/types'; -import type { MaybeAccount } from 'types'; +import type { MaybeAddress } from 'types'; export interface StakingMetrics { totalNominators: BigNumber; @@ -71,15 +71,15 @@ interface LowestReward { export interface StakingContextInterface { fetchEraStakers: (era: string) => Promise; - getNominationsStatusFromTargets: (w: MaybeAccount, t: any[]) => any; + getNominationsStatusFromTargets: (w: MaybeAddress, t: any[]) => any; setTargets: (t: any) => any; hasController: () => boolean; - getControllerNotImported: (a: MaybeAccount) => any; - addressDifferentToStash: (a: MaybeAccount) => boolean; + getControllerNotImported: (a: MaybeAddress) => any; + addressDifferentToStash: (a: MaybeAddress) => boolean; isBonding: () => boolean; isNominating: () => boolean; inSetup: () => any; - getLowestRewardFromStaker: (a: MaybeAccount) => LowestReward; + getLowestRewardFromStaker: (a: MaybeAddress) => LowestReward; staking: StakingMetrics; eraStakers: EraStakers; targets: any; diff --git a/src/contexts/TransferOptions/index.tsx b/src/contexts/TransferOptions/index.tsx index fd7822c167..19c68955ee 100644 --- a/src/contexts/TransferOptions/index.tsx +++ b/src/contexts/TransferOptions/index.tsx @@ -7,12 +7,12 @@ import React, { useState } from 'react'; import { useApi } from 'contexts/Api'; import { useBalances } from 'contexts/Balances'; import { useBonded } from 'contexts/Bonded'; -import { useConnect } from 'contexts/Connect'; import { useNetworkMetrics } from 'contexts/NetworkMetrics'; import { usePoolMemberships } from 'contexts/Pools/PoolMemberships'; -import type { MaybeAccount } from 'types'; +import type { MaybeAddress } from 'types'; import { useEffectIgnoreInitial } from '@polkadot-cloud/react/hooks'; import { useNetwork } from 'contexts/Network'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; import * as defaults from './defaults'; import type { TransferOptions, TransferOptionsContextInterface } from './types'; @@ -30,10 +30,10 @@ export const TransferOptionsProvider = ({ const { getAccount } = useBonded(); const { membership } = usePoolMemberships(); const { existentialDeposit } = consts; - const { activeAccount } = useConnect(); + const { activeAccount } = useActiveAccounts(); // Get the local storage rcord for an account reserve balance. - const getFeeReserveLocalStorage = (address: MaybeAccount) => { + const getFeeReserveLocalStorage = (address: MaybeAddress) => { const reserves = JSON.parse( localStorage.getItem('reserve_balances') ?? '{}' ); @@ -54,7 +54,7 @@ export const TransferOptionsProvider = ({ }, [activeAccount, name]); // Get the bond and unbond amounts available to the user - const getTransferOptions = (address: MaybeAccount): TransferOptions => { + const getTransferOptions = (address: MaybeAddress): TransferOptions => { const account = getAccount(address); if (account === null) { return defaults.transferOptions; diff --git a/src/contexts/TransferOptions/types.ts b/src/contexts/TransferOptions/types.ts index bdca8b64d1..fe8a1ea136 100644 --- a/src/contexts/TransferOptions/types.ts +++ b/src/contexts/TransferOptions/types.ts @@ -2,10 +2,10 @@ // SPDX-License-Identifier: GPL-3.0-only import type BigNumber from 'bignumber.js'; -import type { MaybeAccount } from 'types'; +import type { MaybeAddress } from 'types'; export interface TransferOptionsContextInterface { - getTransferOptions: (a: MaybeAccount) => TransferOptions; + getTransferOptions: (a: MaybeAddress) => TransferOptions; setFeeReserveBalance: (r: BigNumber) => void; feeReserve: BigNumber; } diff --git a/src/contexts/TxMeta/index.tsx b/src/contexts/TxMeta/index.tsx index 34fe0191d1..fa45609fc8 100644 --- a/src/contexts/TxMeta/index.tsx +++ b/src/contexts/TxMeta/index.tsx @@ -5,25 +5,27 @@ import { setStateWithRef } from '@polkadot-cloud/utils'; import BigNumber from 'bignumber.js'; import React, { useState } from 'react'; import { useBonded } from 'contexts/Bonded'; -import { useConnect } from 'contexts/Connect'; import { useStaking } from 'contexts/Staking'; import { useTransferOptions } from 'contexts/TransferOptions'; -import type { AnyJson, MaybeAccount } from 'types'; +import type { AnyJson, MaybeAddress } from 'types'; import { useEffectIgnoreInitial } from '@polkadot-cloud/react/hooks'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; +import { useImportedAccounts } from 'contexts/Connect/ImportedAccounts'; import * as defaults from './defaults'; import type { TxMetaContextInterface } from './types'; export const TxMetaProvider = ({ children }: { children: React.ReactNode }) => { const { getBondedAccount } = useBonded(); - const { accountHasSigner, activeProxy } = useConnect(); + const { activeProxy } = useActiveAccounts(); const { getControllerNotImported } = useStaking(); + const { accountHasSigner } = useImportedAccounts(); const { getTransferOptions } = useTransferOptions(); // Store the transaction fees for the transaction. const [txFees, setTxFees] = useState(new BigNumber(0)); // Store the sender of the transaction. - const [sender, setSender] = useState(null); + const [sender, setSender] = useState(null); // Store whether the sender does not have enough funds. const [notEnoughFunds, setNotEnoughFunds] = useState(false); @@ -94,7 +96,7 @@ export const TxMetaProvider = ({ children }: { children: React.ReactNode }) => { })(); const controllerSignerAvailable = ( - stash: MaybeAccount, + stash: MaybeAddress, proxySupported: boolean ) => { const controller = getBondedAccount(stash); diff --git a/src/contexts/TxMeta/types.ts b/src/contexts/TxMeta/types.ts index 056bcc8ebd..70510cdc76 100644 --- a/src/contexts/TxMeta/types.ts +++ b/src/contexts/TxMeta/types.ts @@ -2,19 +2,19 @@ // SPDX-License-Identifier: GPL-3.0-only import type BigNumber from 'bignumber.js'; -import type { AnyJson, MaybeAccount } from 'types'; +import type { AnyJson, MaybeAddress } from 'types'; export interface TxMetaContextInterface { controllerSignerAvailable: ( - a: MaybeAccount, + a: MaybeAddress, b: boolean ) => 'controller_not_imported' | 'read_only' | 'ok'; txFees: BigNumber; notEnoughFunds: boolean; setTxFees: (f: BigNumber) => void; resetTxFees: () => void; - sender: MaybeAccount; - setSender: (s: MaybeAccount) => void; + sender: MaybeAddress; + setSender: (s: MaybeAddress) => void; txFeesValid: boolean; incrementPayloadUid: () => number; getPayloadUid: () => number; diff --git a/src/contexts/UI/index.tsx b/src/contexts/UI/index.tsx index 303e2241e0..e38a1faba9 100644 --- a/src/contexts/UI/index.tsx +++ b/src/contexts/UI/index.tsx @@ -6,11 +6,11 @@ import BigNumber from 'bignumber.js'; import React, { useEffect, useRef, useState } from 'react'; import { SideMenuStickyThreshold } from 'consts'; import { useBalances } from 'contexts/Balances'; -import type { ImportedAccount } from 'contexts/Connect/types'; +import type { ImportedAccount } from '@polkadot-cloud/react/connect/types'; import { useActivePools } from 'contexts/Pools/ActivePools'; import { useEffectIgnoreInitial } from '@polkadot-cloud/react/hooks'; +import { useImportedAccounts } from 'contexts/Connect/ImportedAccounts'; import { useApi } from '../Api'; -import { useConnect } from '../Connect'; import { useNetworkMetrics } from '../NetworkMetrics'; import { useStaking } from '../Staking'; import * as defaults from './defaults'; @@ -21,8 +21,8 @@ export const UIProvider = ({ children }: { children: React.ReactNode }) => { const { balances } = useBalances(); const { staking, eraStakers } = useStaking(); const { activeEra, metrics } = useNetworkMetrics(); - const { accounts: connectAccounts } = useConnect(); const { synced: activePoolsSynced } = useActivePools(); + const { accounts: connectAccounts } = useImportedAccounts(); // set whether the network has been synced. const [isNetworkSyncing, setIsNetworkSyncing] = useState(false); diff --git a/src/contexts/Validators/ValidatorEntries/index.tsx b/src/contexts/Validators/ValidatorEntries/index.tsx index a18fa7d5bd..cc9e196bce 100644 --- a/src/contexts/Validators/ValidatorEntries/index.tsx +++ b/src/contexts/Validators/ValidatorEntries/index.tsx @@ -8,11 +8,11 @@ import { ValidatorCommunity } from '@polkadot-cloud/assets/validators'; import type { AnyApi, Fn, Sync } from 'types'; import { useEffectIgnoreInitial } from '@polkadot-cloud/react/hooks'; import { useBonded } from 'contexts/Bonded'; -import { useConnect } from 'contexts/Connect'; import { useNetworkMetrics } from 'contexts/NetworkMetrics'; import { useActivePools } from 'contexts/Pools/ActivePools'; import { useNetwork } from 'contexts/Network'; import { useApi } from 'contexts/Api'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; import type { Identity, Validator, @@ -30,8 +30,8 @@ export const ValidatorsProvider = ({ }) => { const { network } = useNetwork(); const { isReady, api } = useApi(); - const { activeAccount } = useConnect(); const { poolNominations } = useActivePools(); + const { activeAccount } = useActiveAccounts(); const { activeEra, metrics } = useNetworkMetrics(); const { bondedAccounts, getAccountNominations } = useBonded(); const { earliestStoredSession } = metrics; diff --git a/src/library/Account/Default.tsx b/src/library/Account/Default.tsx index 5f2c402f6d..c3b2d57f96 100644 --- a/src/library/Account/Default.tsx +++ b/src/library/Account/Default.tsx @@ -6,8 +6,8 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { ellipsisFn, remToUnit } from '@polkadot-cloud/utils'; import { useEffect, useState } from 'react'; import { useTranslation } from 'react-i18next'; -import { useConnect } from 'contexts/Connect'; import { Polkicon } from '@polkadot-cloud/react'; +import { useImportedAccounts } from 'contexts/Connect/ImportedAccounts'; import { Wrapper } from './Wrapper'; import type { AccountProps } from './types'; @@ -22,7 +22,7 @@ export const Account = ({ onClick, }: AccountProps) => { const { t } = useTranslation('library'); - const { getAccount } = useConnect(); + const { getAccount } = useImportedAccounts(); const [displayValue, setDisplayValue] = useState(); diff --git a/src/library/Account/Pool.tsx b/src/library/Account/Pool.tsx index f88d478124..0c416f7832 100644 --- a/src/library/Account/Pool.tsx +++ b/src/library/Account/Pool.tsx @@ -6,9 +6,9 @@ import { ellipsisFn, remToUnit } from '@polkadot-cloud/utils'; import { useEffect, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { useApi } from 'contexts/Api'; -import { useConnect } from 'contexts/Connect'; import { useBondedPools } from 'contexts/Pools/BondedPools'; import { Polkicon } from '@polkadot-cloud/react'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; import { Wrapper } from './Wrapper'; import type { AccountProps } from './types'; @@ -21,7 +21,7 @@ export const Account = ({ }: AccountProps) => { const { t } = useTranslation('library'); const { isReady } = useApi(); - const { activeAccount } = useConnect(); + const { activeAccount } = useActiveAccounts(); const { fetchPoolsMetaBatch, meta } = useBondedPools(); // is this the initial fetch diff --git a/src/library/AccountInput/index.tsx b/src/library/AccountInput/index.tsx index 80a0b694ff..6da53ba134 100644 --- a/src/library/AccountInput/index.tsx +++ b/src/library/AccountInput/index.tsx @@ -7,8 +7,10 @@ import { ButtonSecondary, Polkicon } from '@polkadot-cloud/react'; import { isValidAddress } from '@polkadot-cloud/utils'; import React, { useEffect, useState } from 'react'; import { useTranslation } from 'react-i18next'; -import { useConnect } from 'contexts/Connect'; import { useOverlay } from '@polkadot-cloud/react/hooks'; +import { useImportedAccounts } from 'contexts/Connect/ImportedAccounts'; +import { useNetwork } from 'contexts/Network'; +import { formatAccountSs58 } from 'contexts/Connect/Utils'; import { AccountInputWrapper } from './Wrapper'; import type { AccountInputProps } from './types'; @@ -26,8 +28,11 @@ export const AccountInput = ({ }: AccountInputProps) => { const { t } = useTranslation('library'); + const { + networkData: { ss58 }, + } = useNetwork(); + const { accounts } = useImportedAccounts(); const { setModalResize } = useOverlay().modal; - const { formatAccountSs58, accounts } = useConnect(); // store current input value const [value, setValue] = useState(initialValue || ''); @@ -73,7 +78,7 @@ export const AccountInput = ({ const handleImport = async () => { // reformat address if in wrong format - const addressFormatted = formatAccountSs58(value); + const addressFormatted = formatAccountSs58(value, ss58); if (addressFormatted) { setValid('confirm_reformat'); setValue(addressFormatted); diff --git a/src/library/AccountInput/types.ts b/src/library/AccountInput/types.ts index f2a65abe8a..583af2aaa5 100644 --- a/src/library/AccountInput/types.ts +++ b/src/library/AccountInput/types.ts @@ -1,7 +1,7 @@ // Copyright 2023 @paritytech/polkadot-staking-dashboard authors & contributors // SPDX-License-Identifier: GPL-3.0-only -import type { AnyApi, MaybeAccount } from 'types'; +import type { AnyApi, MaybeAddress } from 'types'; export interface AccountInputProps { successCallback: (a: string) => Promise; @@ -12,6 +12,6 @@ export interface AccountInputProps { locked?: boolean; inactive?: boolean; disallowAlreadyImported?: boolean; - initialValue?: MaybeAccount; + initialValue?: MaybeAddress; border?: boolean; } diff --git a/src/library/Form/Bond/BondFeedback.tsx b/src/library/Form/Bond/BondFeedback.tsx index 35ffc8fc25..a4a2e21867 100644 --- a/src/library/Form/Bond/BondFeedback.tsx +++ b/src/library/Form/Bond/BondFeedback.tsx @@ -5,12 +5,12 @@ import { planckToUnit, unitToPlanck } from '@polkadot-cloud/utils'; import BigNumber from 'bignumber.js'; import { useEffect, useState } from 'react'; import { useTranslation } from 'react-i18next'; -import { useConnect } from 'contexts/Connect'; import { useActivePools } from 'contexts/Pools/ActivePools'; import { usePoolsConfig } from 'contexts/Pools/PoolsConfig'; import { useStaking } from 'contexts/Staking'; import { useTransferOptions } from 'contexts/TransferOptions'; import { useNetwork } from 'contexts/Network'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; import { Warning } from '../Warning'; import { Spacer } from '../Wrappers'; import type { BondFeedbackProps } from '../types'; @@ -34,7 +34,7 @@ export const BondFeedback = ({ networkData: { units, unit }, } = useNetwork(); const { staking } = useStaking(); - const { activeAccount } = useConnect(); + const { activeAccount } = useActiveAccounts(); const { stats } = usePoolsConfig(); const { isDepositor } = useActivePools(); const { getTransferOptions } = useTransferOptions(); diff --git a/src/library/Form/Bond/BondInput.tsx b/src/library/Form/Bond/BondInput.tsx index 69b84d9ef9..cc8f5835f0 100644 --- a/src/library/Form/Bond/BondInput.tsx +++ b/src/library/Form/Bond/BondInput.tsx @@ -5,8 +5,8 @@ import { ButtonSubmitInvert } from '@polkadot-cloud/react'; import BigNumber from 'bignumber.js'; import React, { useEffect, useState } from 'react'; import { useTranslation } from 'react-i18next'; -import { useConnect } from 'contexts/Connect'; import { useNetwork } from 'contexts/Network'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; import { InputWrapper } from '../Wrappers'; import type { BondInputProps } from '../types'; @@ -23,7 +23,7 @@ export const BondInput = ({ const { networkData: { unit }, } = useNetwork(); - const { activeAccount } = useConnect(); + const { activeAccount } = useActiveAccounts(); // the current local bond value const [localBond, setLocalBond] = useState(value); diff --git a/src/library/Form/Unbond/UnbondFeedback.tsx b/src/library/Form/Unbond/UnbondFeedback.tsx index 8c7d729111..462d7ea500 100644 --- a/src/library/Form/Unbond/UnbondFeedback.tsx +++ b/src/library/Form/Unbond/UnbondFeedback.tsx @@ -5,12 +5,12 @@ import { isNotZero, planckToUnit, unitToPlanck } from '@polkadot-cloud/utils'; import BigNumber from 'bignumber.js'; import { useEffect, useState } from 'react'; import { useTranslation } from 'react-i18next'; -import { useConnect } from 'contexts/Connect'; import { useActivePools } from 'contexts/Pools/ActivePools'; import { usePoolsConfig } from 'contexts/Pools/PoolsConfig'; import { useStaking } from 'contexts/Staking'; import { useTransferOptions } from 'contexts/TransferOptions'; import { useNetwork } from 'contexts/Network'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; import { Warning } from '../Warning'; import { Spacer } from '../Wrappers'; import type { UnbondFeedbackProps } from '../types'; @@ -30,7 +30,7 @@ export const UnbondFeedback = ({ const { networkData: { units, unit }, } = useNetwork(); - const { activeAccount } = useConnect(); + const { activeAccount } = useActiveAccounts(); const { staking } = useStaking(); const { getTransferOptions } = useTransferOptions(); const { isDepositor } = useActivePools(); diff --git a/src/library/Form/Unbond/UnbondInput.tsx b/src/library/Form/Unbond/UnbondInput.tsx index fdfb70bec2..91db1bbfb0 100644 --- a/src/library/Form/Unbond/UnbondInput.tsx +++ b/src/library/Form/Unbond/UnbondInput.tsx @@ -6,8 +6,8 @@ import { planckToUnit } from '@polkadot-cloud/utils'; import BigNumber from 'bignumber.js'; import React, { useEffect, useState } from 'react'; import { useTranslation } from 'react-i18next'; -import { useConnect } from 'contexts/Connect'; import { useNetwork } from 'contexts/Network'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; import { InputWrapper } from '../Wrappers'; import type { UnbondInputProps } from '../types'; @@ -21,7 +21,7 @@ export const UnbondInput = ({ }: UnbondInputProps) => { const { t } = useTranslation('library'); const { networkData } = useNetwork(); - const { activeAccount } = useConnect(); + const { activeAccount } = useActiveAccounts(); // get the actively bonded amount. const activeUnit = planckToUnit(active, networkData.units); diff --git a/src/library/Form/types.ts b/src/library/Form/types.ts index 1fbd955041..778eb0eb6f 100644 --- a/src/library/Form/types.ts +++ b/src/library/Form/types.ts @@ -3,9 +3,9 @@ import type BigNumber from 'bignumber.js'; import type { Balance } from 'contexts/Balances/types'; -import type { ExternalAccount } from 'contexts/Connect/types'; import type { ExtensionAccount } from '@polkadot-cloud/react/connect/ExtensionsProvider/types'; -import type { BondFor, MaybeAccount } from 'types'; +import type { BondFor, MaybeAddress } from 'types'; +import type { ExternalAccount } from '@polkadot-cloud/react/connect/types'; export interface ExtensionAccountItem extends ExtensionAccount { active?: boolean; @@ -28,7 +28,7 @@ export interface DropdownInput { export interface AccountDropdownProps { current: InputItem; - to: MaybeAccount; + to: MaybeAddress; } export interface BondFeedbackProps { diff --git a/src/library/GenerateNominations/index.tsx b/src/library/GenerateNominations/index.tsx index 14209cdae9..759b17aaf5 100644 --- a/src/library/GenerateNominations/index.tsx +++ b/src/library/GenerateNominations/index.tsx @@ -14,7 +14,6 @@ import { camelize } from '@polkadot-cloud/utils'; import { useEffect, useRef, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { useApi } from 'contexts/Api'; -import { useConnect } from 'contexts/Connect'; import { useValidators } from 'contexts/Validators/ValidatorEntries'; import { useUnstaking } from 'library/Hooks/useUnstaking'; import { SelectableWrapper } from 'library/List'; @@ -25,6 +24,8 @@ import { Wrapper } from 'pages/Overview/NetworkSats/Wrappers'; import { useStaking } from 'contexts/Staking'; import { useOverlay } from '@polkadot-cloud/react/hooks'; import { useFavoriteValidators } from 'contexts/Validators/FavoriteValidators'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; +import { useImportedAccounts } from 'contexts/Connect/ImportedAccounts'; import type { GenerateNominationsInnerProps, Nominations, @@ -42,7 +43,8 @@ export const GenerateNominations = ({ const { isFastUnstaking } = useUnstaking(); const { stakers } = useStaking().eraStakers; const { favoritesList } = useFavoriteValidators(); - const { activeAccount, isReadOnlyAccount } = useConnect(); + const { isReadOnlyAccount } = useImportedAccounts(); + const { activeAccount } = useActiveAccounts(); const { validators, validatorIdentities, validatorSupers } = useValidators(); const { fetch: fetchFromMethod, diff --git a/src/library/Headers/Connect.tsx b/src/library/Headers/Connect.tsx index 7fd273336b..5a2100ef49 100644 --- a/src/library/Headers/Connect.tsx +++ b/src/library/Headers/Connect.tsx @@ -4,14 +4,14 @@ import { faPlug, faWallet } from '@fortawesome/free-solid-svg-icons'; import { ButtonText } from '@polkadot-cloud/react'; import { useTranslation } from 'react-i18next'; -import { useConnect } from 'contexts/Connect'; import { useOverlay } from '@polkadot-cloud/react/hooks'; +import { useImportedAccounts } from 'contexts/Connect/ImportedAccounts'; import { ConnectedAccount, HeadingWrapper } from './Wrappers'; export const Connect = () => { const { t } = useTranslation('library'); - const { accounts } = useConnect(); const { openModal } = useOverlay().modal; + const { accounts } = useImportedAccounts(); return ( diff --git a/src/library/Headers/Connected.tsx b/src/library/Headers/Connected.tsx index 08cd7824aa..241e77a7d0 100644 --- a/src/library/Headers/Connected.tsx +++ b/src/library/Headers/Connected.tsx @@ -2,10 +2,11 @@ // SPDX-License-Identifier: GPL-3.0-only import { useTranslation } from 'react-i18next'; -import { useConnect } from 'contexts/Connect'; import { useActivePools } from 'contexts/Pools/ActivePools'; import { useStaking } from 'contexts/Staking'; import { useUi } from 'contexts/UI'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; +import { useImportedAccounts } from 'contexts/Connect/ImportedAccounts'; import { Account } from '../Account/Default'; import { Account as PoolAccount } from '../Account/Pool'; import { HeadingWrapper } from './Wrappers'; @@ -15,7 +16,8 @@ export const Connected = () => { const { isNetworkSyncing } = useUi(); const { isNominating } = useStaking(); const { selectedActivePool } = useActivePools(); - const { activeAccount, activeProxy, accountHasSigner } = useConnect(); + const { accountHasSigner } = useImportedAccounts(); + const { activeAccount, activeProxy } = useActiveAccounts(); let poolAddress = ''; if (selectedActivePool) { diff --git a/src/library/Hooks/useBatchCall/index.tsx b/src/library/Hooks/useBatchCall/index.tsx index cfe9bcb7ab..b3ee2dfca7 100644 --- a/src/library/Hooks/useBatchCall/index.tsx +++ b/src/library/Hooks/useBatchCall/index.tsx @@ -2,16 +2,16 @@ // SPDX-License-Identifier: GPL-3.0-only import { useApi } from 'contexts/Api'; -import { useConnect } from 'contexts/Connect'; -import type { AnyApi, MaybeAccount } from 'types'; +import type { AnyApi, MaybeAddress } from 'types'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; import { useProxySupported } from '../useProxySupported'; export const useBatchCall = () => { const { api } = useApi(); - const { activeProxy } = useConnect(); + const { activeProxy } = useActiveAccounts(); const { isProxySupported } = useProxySupported(); - const newBatchCall = (txs: AnyApi[], from: MaybeAccount) => { + const newBatchCall = (txs: AnyApi[], from: MaybeAddress) => { if (!api) return undefined; from = from || ''; diff --git a/src/library/Hooks/useBondGreatestFee/index.tsx b/src/library/Hooks/useBondGreatestFee/index.tsx index 172bd44331..e3cf6c333f 100644 --- a/src/library/Hooks/useBondGreatestFee/index.tsx +++ b/src/library/Hooks/useBondGreatestFee/index.tsx @@ -4,9 +4,9 @@ import BigNumber from 'bignumber.js'; import { useEffect, useMemo, useState } from 'react'; import { useApi } from 'contexts/Api'; -import { useConnect } from 'contexts/Connect'; import { useTransferOptions } from 'contexts/TransferOptions'; import type { BondFor } from 'types'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; interface Props { bondFor: BondFor; @@ -14,7 +14,7 @@ interface Props { export const useBondGreatestFee = ({ bondFor }: Props) => { const { api } = useApi(); - const { activeAccount } = useConnect(); + const { activeAccount } = useActiveAccounts(); const { feeReserve, getTransferOptions } = useTransferOptions(); const transferOptions = useMemo( () => getTransferOptions(activeAccount), diff --git a/src/library/Hooks/useNominationStatus/index.tsx b/src/library/Hooks/useNominationStatus/index.tsx index fa4ebf5ccc..07272560d9 100644 --- a/src/library/Hooks/useNominationStatus/index.tsx +++ b/src/library/Hooks/useNominationStatus/index.tsx @@ -9,7 +9,7 @@ import { useActivePools } from 'contexts/Pools/ActivePools'; import { useStaking } from 'contexts/Staking'; import { useUi } from 'contexts/UI'; import { useValidators } from 'contexts/Validators/ValidatorEntries'; -import type { AnyJson, MaybeAccount } from 'types'; +import type { AnyJson, MaybeAddress } from 'types'; import { useNetwork } from 'contexts/Network'; export const useNominationStatus = () => { @@ -30,7 +30,7 @@ export const useNominationStatus = () => { } = useStaking(); // Utility to get an account's nominees alongside their status. - const getNomineesStatus = (who: MaybeAccount, type: 'nominator' | 'pool') => { + const getNomineesStatus = (who: MaybeAddress, type: 'nominator' | 'pool') => { const nominations = type === 'nominator' ? getAccountNominations(who) @@ -47,7 +47,7 @@ export const useNominationStatus = () => { // Utility to get the status of the provided account's nominations, and whether they are earning // reards. const getNominationStatus = ( - who: MaybeAccount, + who: MaybeAddress, type: 'nominator' | 'pool' ) => { // Get the sets nominees from the provided account's targets. diff --git a/src/library/Hooks/useProxySupported/index.tsx b/src/library/Hooks/useProxySupported/index.tsx index 5fea5d6728..e62678a579 100644 --- a/src/library/Hooks/useProxySupported/index.tsx +++ b/src/library/Hooks/useProxySupported/index.tsx @@ -6,22 +6,22 @@ import { isSupportedProxyCall, } from 'config/proxies'; import { useBonded } from 'contexts/Bonded'; -import { useConnect } from 'contexts/Connect'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; import { useProxies } from 'contexts/Proxies'; -import type { AnyApi, AnyJson, MaybeAccount } from 'types'; +import type { AnyApi, AnyJson, MaybeAddress } from 'types'; export const useProxySupported = () => { - const { activeProxy } = useConnect(); + const { activeProxy } = useActiveAccounts(); const { getBondedAccount } = useBonded(); const { getProxyDelegate } = useProxies(); // If call is from controller, & controller is different from stash, then proxy is not // supported. - const controllerNotSupported = (c: string, f: MaybeAccount) => + const controllerNotSupported = (c: string, f: MaybeAddress) => UnsupportedIfUniqueController.includes(c) && getBondedAccount(f) !== f; // Determine whether the provided tx is proxy supported. - const isProxySupported = (tx: AnyApi, delegator: MaybeAccount) => { + const isProxySupported = (tx: AnyApi, delegator: MaybeAddress) => { // if already wrapped, return. if ( tx?.method.toHuman().section === 'proxy' && diff --git a/src/library/Hooks/useSignerWarnings/index.tsx b/src/library/Hooks/useSignerWarnings/index.tsx index 47baff1490..0b51c27a85 100644 --- a/src/library/Hooks/useSignerWarnings/index.tsx +++ b/src/library/Hooks/useSignerWarnings/index.tsx @@ -2,17 +2,19 @@ // SPDX-License-Identifier: GPL-3.0-only import { useTranslation } from 'react-i18next'; -import { useConnect } from 'contexts/Connect'; import { useTxMeta } from 'contexts/TxMeta'; -import type { MaybeAccount } from 'types'; +import type { MaybeAddress } from 'types'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; +import { useImportedAccounts } from 'contexts/Connect/ImportedAccounts'; export const useSignerWarnings = () => { const { t } = useTranslation('modals'); - const { activeProxy, accountHasSigner } = useConnect(); + const { activeProxy } = useActiveAccounts(); + const { accountHasSigner } = useImportedAccounts(); const { controllerSignerAvailable } = useTxMeta(); const getSignerWarnings = ( - account: MaybeAccount, + account: MaybeAddress, controller = false, proxySupported = false ) => { diff --git a/src/library/Hooks/useSubmitExtrinsic/index.tsx b/src/library/Hooks/useSubmitExtrinsic/index.tsx index 5c35456db8..ffaaaa65f7 100644 --- a/src/library/Hooks/useSubmitExtrinsic/index.tsx +++ b/src/library/Hooks/useSubmitExtrinsic/index.tsx @@ -6,7 +6,6 @@ import { useEffect, useRef, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { DappName } from 'consts'; import { useApi } from 'contexts/Api'; -import { useConnect } from 'contexts/Connect'; import { manualSigners } from 'contexts/Connect/Utils'; import { useExtensions } from '@polkadot-cloud/react/hooks'; import { useExtrinsics } from 'contexts/Extrinsics'; @@ -14,6 +13,8 @@ import { useLedgerHardware } from 'contexts/Hardware/Ledger'; import { useNotifications } from 'contexts/Notifications'; import { useTxMeta } from 'contexts/TxMeta'; import type { AnyApi, AnyJson } from 'types'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; +import { useImportedAccounts } from 'contexts/Connect/ImportedAccounts'; import { useBuildPayload } from '../useBuildPayload'; import { useProxySupported } from '../useProxySupported'; import type { UseSubmitExtrinsic, UseSubmitExtrinsicProps } from './types'; @@ -32,7 +33,8 @@ export const useSubmitExtrinsic = ({ const { isProxySupported } = useProxySupported(); const { addPending, removePending } = useExtrinsics(); const { buildPayload } = useBuildPayload(); - const { getAccount, requiresManualSign, activeProxy } = useConnect(); + const { activeProxy } = useActiveAccounts(); + const { getAccount, requiresManualSign } = useImportedAccounts(); const { setTxFees, incrementPayloadUid, diff --git a/src/library/Hooks/useSubmitExtrinsic/types.ts b/src/library/Hooks/useSubmitExtrinsic/types.ts index 0cdb8f7f9e..9b281cf9d8 100644 --- a/src/library/Hooks/useSubmitExtrinsic/types.ts +++ b/src/library/Hooks/useSubmitExtrinsic/types.ts @@ -1,14 +1,14 @@ // Copyright 2023 @paritytech/polkadot-staking-dashboard authors & contributors // SPDX-License-Identifier: GPL-3.0-only -import type { AnyApi, MaybeAccount } from 'types'; +import type { AnyApi, MaybeAddress } from 'types'; export interface UseSubmitExtrinsicProps { tx: AnyApi; shouldSubmit: boolean; callbackSubmit: { (): void }; callbackInBlock: { (): void }; - from: MaybeAccount; + from: MaybeAddress; } export interface UseSubmitExtrinsic { @@ -16,5 +16,5 @@ export interface UseSubmitExtrinsic { onSubmit: { (): void }; submitting: boolean; proxySupported: boolean; - submitAddress: MaybeAccount; + submitAddress: MaybeAddress; } diff --git a/src/library/Hooks/useUnstaking/index.tsx b/src/library/Hooks/useUnstaking/index.tsx index d18608b96b..8e0acffe41 100644 --- a/src/library/Hooks/useUnstaking/index.tsx +++ b/src/library/Hooks/useUnstaking/index.tsx @@ -3,19 +3,19 @@ import { useTranslation } from 'react-i18next'; import { useApi } from 'contexts/Api'; -import { useConnect } from 'contexts/Connect'; import { useFastUnstake } from 'contexts/FastUnstake'; import { useNetworkMetrics } from 'contexts/NetworkMetrics'; import { useStaking } from 'contexts/Staking'; import { useTransferOptions } from 'contexts/TransferOptions'; import type { AnyJson } from 'types'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; import { useNominationStatus } from '../useNominationStatus'; export const useUnstaking = () => { const { t } = useTranslation('library'); const { consts } = useApi(); const { inSetup } = useStaking(); - const { activeAccount } = useConnect(); + const { activeAccount } = useActiveAccounts(); const { activeEra } = useNetworkMetrics(); const { getTransferOptions } = useTransferOptions(); const { getNominationStatus } = useNominationStatus(); diff --git a/src/library/Import/Confirm.tsx b/src/library/Import/Confirm.tsx index b621b624d4..f35626ed85 100644 --- a/src/library/Import/Confirm.tsx +++ b/src/library/Import/Confirm.tsx @@ -3,16 +3,16 @@ import { ButtonMono, ButtonMonoInvert, Polkicon } from '@polkadot-cloud/react'; import { useTranslation } from 'react-i18next'; -import { useConnect } from 'contexts/Connect'; import { usePrompt } from 'contexts/Prompt'; import { ConfirmWrapper } from 'library/Import/Wrappers'; +import { useOtherAccounts } from 'contexts/Connect/OtherAccounts'; import type { ConfirmProps } from './types'; export const Confirm = ({ address, index, addHandler }: ConfirmProps) => { const { t } = useTranslation('modals'); - const { addToAccounts } = useConnect(); const { setStatus } = usePrompt(); + const { addOtherAccounts } = useOtherAccounts(); return ( @@ -26,7 +26,7 @@ export const Confirm = ({ address, index, addHandler }: ConfirmProps) => { onClick={() => { const account = addHandler(address, index); if (account) { - addToAccounts([account]); + addOtherAccounts([account]); } setStatus(0); }} diff --git a/src/library/Import/Remove.tsx b/src/library/Import/Remove.tsx index 555ed1cbda..a5d7206aa6 100644 --- a/src/library/Import/Remove.tsx +++ b/src/library/Import/Remove.tsx @@ -3,15 +3,15 @@ import { ButtonMono, ButtonMonoInvert, Polkicon } from '@polkadot-cloud/react'; import { useTranslation } from 'react-i18next'; -import { useConnect } from 'contexts/Connect'; import { usePrompt } from 'contexts/Prompt'; import { ConfirmWrapper } from 'library/Import/Wrappers'; +import { useOtherAccounts } from 'contexts/Connect/OtherAccounts'; import type { RemoveProps } from './types'; export const Remove = ({ address, getHandler, removeHandler }: RemoveProps) => { const { t } = useTranslation('modals'); - const { forgetAccounts } = useConnect(); const { setStatus } = usePrompt(); + const { forgetOtherAccounts } = useOtherAccounts(); return ( @@ -26,7 +26,7 @@ export const Remove = ({ address, getHandler, removeHandler }: RemoveProps) => { const account = getHandler(address); if (account) { removeHandler(address); - forgetAccounts([account]); + forgetOtherAccounts([account]); setStatus(0); } }} diff --git a/src/library/ListItem/Labels/EraStatus.tsx b/src/library/ListItem/Labels/EraStatus.tsx index 5eff8cbef1..7f41d75097 100644 --- a/src/library/ListItem/Labels/EraStatus.tsx +++ b/src/library/ListItem/Labels/EraStatus.tsx @@ -7,10 +7,10 @@ import { useTranslation } from 'react-i18next'; import { useStaking } from 'contexts/Staking'; import { useUi } from 'contexts/UI'; import { ValidatorStatusWrapper } from 'library/ListItem/Wrappers'; -import type { MaybeAccount } from 'types'; +import type { MaybeAddress } from 'types'; import { useNetwork } from 'contexts/Network'; -export const EraStatus = ({ address }: { address: MaybeAccount }) => { +export const EraStatus = ({ address }: { address: MaybeAddress }) => { const { t } = useTranslation('library'); const { networkData: { unit, units }, diff --git a/src/library/ListItem/Labels/NominationStatus.tsx b/src/library/ListItem/Labels/NominationStatus.tsx index 3c5a93f6cc..3f54fda96e 100644 --- a/src/library/ListItem/Labels/NominationStatus.tsx +++ b/src/library/ListItem/Labels/NominationStatus.tsx @@ -8,8 +8,8 @@ import { useBondedPools } from 'contexts/Pools/BondedPools'; import { useStaking } from 'contexts/Staking'; import { ValidatorStatusWrapper } from 'library/ListItem/Wrappers'; import { useNominationStatus } from 'library/Hooks/useNominationStatus'; -import { useConnect } from 'contexts/Connect'; import { useNetwork } from 'contexts/Network'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; import type { NominationStatusProps } from '../types'; export const NominationStatus = ({ @@ -21,7 +21,7 @@ export const NominationStatus = ({ const { networkData: { unit, units }, } = useNetwork(); - const { activeAccount } = useConnect(); + const { activeAccount } = useActiveAccounts(); const { getPoolNominationStatus } = useBondedPools(); const { getNomineesStatus } = useNominationStatus(); const { diff --git a/src/library/ListItem/types.ts b/src/library/ListItem/types.ts index 176d08889c..fff7b20056 100644 --- a/src/library/ListItem/types.ts +++ b/src/library/ListItem/types.ts @@ -3,7 +3,7 @@ import type React from 'react'; import type { BondedPool } from 'contexts/Pools/types'; -import type { BondFor, MaybeAccount } from 'types'; +import type { BondFor, MaybeAddress } from 'types'; export interface BlockedProps { prefs: { @@ -38,11 +38,11 @@ export interface MetricsProps { export interface NominationStatusProps { address: string; bondFor: BondFor; - nominator: MaybeAccount; + nominator: MaybeAddress; } export interface OversubscribedProps { - address: MaybeAccount; + address: MaybeAddress; } export interface SelectProps { @@ -52,5 +52,5 @@ export interface SelectProps { } export interface ParaValidatorProps { - address: MaybeAccount; + address: MaybeAddress; } diff --git a/src/library/PayeeInput/index.tsx b/src/library/PayeeInput/index.tsx index c2928966e2..ce24e13e6f 100644 --- a/src/library/PayeeInput/index.tsx +++ b/src/library/PayeeInput/index.tsx @@ -7,8 +7,11 @@ import { isValidAddress, remToUnit } from '@polkadot-cloud/utils'; import React, { useEffect, useRef, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { useBonded } from 'contexts/Bonded'; -import { useConnect } from 'contexts/Connect'; import { Polkicon } from '@polkadot-cloud/react'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; +import { useImportedAccounts } from 'contexts/Connect/ImportedAccounts'; +import { useNetwork } from 'contexts/Network'; +import { formatAccountSs58 } from 'contexts/Connect/Utils'; import { Wrapper } from './Wrapper'; import type { PayeeInputProps } from './types'; @@ -20,7 +23,11 @@ export const PayeeInput = ({ }: PayeeInputProps) => { const { t } = useTranslation('library'); const { getBondedAccount } = useBonded(); - const { activeAccount, formatAccountSs58, accounts } = useConnect(); + const { accounts } = useImportedAccounts(); + const { + networkData: { ss58 }, + } = useNetwork(); + const { activeAccount } = useActiveAccounts(); const controller = getBondedAccount(activeAccount); const accountMeta = accounts.find((a) => a.address === activeAccount); @@ -45,7 +52,7 @@ export const PayeeInput = ({ // Handle change of account value. Updates setup progress if the account is a valid value. const handleChangeAccount = (e: React.ChangeEvent) => { const newAddress = e.target.value; - const formatted = formatAccountSs58(newAddress) || newAddress || null; + const formatted = formatAccountSs58(newAddress, ss58) || newAddress || null; const isValid = isValidAddress(formatted || ''); setValid(isValid); diff --git a/src/library/PayeeInput/types.ts b/src/library/PayeeInput/types.ts index fecdc67b01..e8d971af5b 100644 --- a/src/library/PayeeInput/types.ts +++ b/src/library/PayeeInput/types.ts @@ -3,11 +3,11 @@ import type { Dispatch, SetStateAction } from 'react'; import type { PayeeConfig } from 'contexts/Setup/types'; -import type { MaybeAccount } from 'types'; +import type { MaybeAddress } from 'types'; export interface PayeeInputProps { payee: PayeeConfig; - account: MaybeAccount; - setAccount: Dispatch>; - handleChange: (a: MaybeAccount) => void; + account: MaybeAddress; + setAccount: Dispatch>; + handleChange: (a: MaybeAddress) => void; } diff --git a/src/library/Pool/index.tsx b/src/library/Pool/index.tsx index b3818ef3df..e836d6a337 100644 --- a/src/library/Pool/index.tsx +++ b/src/library/Pool/index.tsx @@ -6,7 +6,6 @@ import { faBars, faProjectDiagram } from '@fortawesome/free-solid-svg-icons'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { useRef } from 'react'; import { useTranslation } from 'react-i18next'; -import { useConnect } from 'contexts/Connect'; import { useMenu } from 'contexts/Menu'; import { useNotifications } from 'contexts/Notifications'; import type { NotificationText } from 'contexts/Notifications/types'; @@ -27,6 +26,8 @@ import { } from 'library/ListItem/Wrappers'; import { usePoolsTabs } from 'pages/Pools/Home/context'; import { useOverlay } from '@polkadot-cloud/react/hooks'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; +import { useImportedAccounts } from 'contexts/Connect/ImportedAccounts'; import { JoinPool } from '../ListItem/Labels/JoinPool'; import { Members } from '../ListItem/Labels/Members'; import { PoolId } from '../ListItem/Labels/PoolId'; @@ -36,7 +37,8 @@ export const Pool = ({ pool, batchKey, batchIndex }: PoolProps) => { const { t } = useTranslation('library'); const { memberCounter, addresses, id, state } = pool; const { openModal } = useOverlay().modal; - const { activeAccount, isReadOnlyAccount } = useConnect(); + const { isReadOnlyAccount } = useImportedAccounts(); + const { activeAccount } = useActiveAccounts(); const { meta } = useBondedPools(); const { membership } = usePoolMemberships(); const { addNotification } = useNotifications(); diff --git a/src/library/SelectItems/types.ts b/src/library/SelectItems/types.ts index c747c1f64c..fc88e8867b 100644 --- a/src/library/SelectItems/types.ts +++ b/src/library/SelectItems/types.ts @@ -3,7 +3,7 @@ import type React from 'react'; import type { Dispatch, SetStateAction } from 'react'; -import type { AnyJson, MaybeAccount } from 'types'; +import type { AnyJson, MaybeAddress } from 'types'; export interface SelectItemsProps { layout?: 'two-col' | 'three-col'; @@ -23,6 +23,6 @@ export interface SelectItemProps { includeToggle?: boolean; bodyRef?: AnyJson; containerRef?: AnyJson; - account?: MaybeAccount; - setAccount?: Dispatch>; + account?: MaybeAddress; + setAccount?: Dispatch>; } diff --git a/src/library/SetupSteps/Footer/index.tsx b/src/library/SetupSteps/Footer/index.tsx index 55372746f4..7a2ecf204b 100644 --- a/src/library/SetupSteps/Footer/index.tsx +++ b/src/library/SetupSteps/Footer/index.tsx @@ -3,14 +3,14 @@ import { ButtonPrimary } from '@polkadot-cloud/react'; import { useTranslation } from 'react-i18next'; -import { useConnect } from 'contexts/Connect'; import { useSetup } from 'contexts/Setup'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; import type { FooterProps } from '../types'; import { Wrapper } from './Wrapper'; export const Footer = ({ complete, bondFor }: FooterProps) => { const { t } = useTranslation('library'); - const { activeAccount } = useConnect(); + const { activeAccount } = useActiveAccounts(); const { getSetupProgress, setActiveAccountSetupSection } = useSetup(); const setup = getSetupProgress(bondFor, activeAccount); diff --git a/src/library/SetupSteps/Header/index.tsx b/src/library/SetupSteps/Header/index.tsx index e665245c59..dd59fac29d 100644 --- a/src/library/SetupSteps/Header/index.tsx +++ b/src/library/SetupSteps/Header/index.tsx @@ -3,9 +3,9 @@ import { ButtonHelp, ButtonSecondary } from '@polkadot-cloud/react'; import { useTranslation } from 'react-i18next'; -import { useConnect } from 'contexts/Connect'; import { useHelp } from 'contexts/Help'; import { useSetup } from 'contexts/Setup'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; import type { HeaderProps } from '../types'; import { Wrapper } from './Wrapper'; @@ -17,7 +17,7 @@ export const Header = ({ bondFor, }: HeaderProps) => { const { t } = useTranslation('library'); - const { activeAccount } = useConnect(); + const { activeAccount } = useActiveAccounts(); const { getSetupProgress, setActiveAccountSetupSection } = useSetup(); const setup = getSetupProgress(bondFor, activeAccount); const { openHelp } = useHelp(); diff --git a/src/library/SetupSteps/Nominate.tsx b/src/library/SetupSteps/Nominate.tsx index f584768b66..b002becd82 100644 --- a/src/library/SetupSteps/Nominate.tsx +++ b/src/library/SetupSteps/Nominate.tsx @@ -3,18 +3,18 @@ import { useTranslation } from 'react-i18next'; import { useApi } from 'contexts/Api'; -import { useConnect } from 'contexts/Connect'; import { useSetup } from 'contexts/Setup'; import { Footer } from 'library/SetupSteps/Footer'; import { Header } from 'library/SetupSteps/Header'; import { MotionContainer } from 'library/SetupSteps/MotionContainer'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; import { GenerateNominations } from '../GenerateNominations'; import type { NominationsProps } from './types'; export const Nominate = ({ batchKey, bondFor, section }: NominationsProps) => { const { t } = useTranslation('library'); const { consts } = useApi(); - const { activeAccount } = useConnect(); + const { activeAccount } = useActiveAccounts(); const { getSetupProgress, setActiveAccountSetup } = useSetup(); const setup = getSetupProgress(bondFor, activeAccount); const { progress } = setup; diff --git a/src/library/SideMenu/Main.tsx b/src/library/SideMenu/Main.tsx index 09d1748854..87515c1b12 100644 --- a/src/library/SideMenu/Main.tsx +++ b/src/library/SideMenu/Main.tsx @@ -7,7 +7,6 @@ import { useLocation } from 'react-router-dom'; import { PageCategories, PagesConfig } from 'config/pages'; import { PolkadotUrl } from 'consts'; import { useBonded } from 'contexts/Bonded'; -import { useConnect } from 'contexts/Connect'; import { usePoolMemberships } from 'contexts/Pools/PoolMemberships'; import { useSetup } from 'contexts/Setup'; import type { SetupContextInterface } from 'contexts/Setup/types'; @@ -16,6 +15,8 @@ import { useUi } from 'contexts/UI'; import type { UIContextInterface } from 'contexts/UI/types'; import type { PageCategory, PageItem, PagesConfigItems } from 'types'; import { useNetwork } from 'contexts/Network'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; +import { useImportedAccounts } from 'contexts/Connect/ImportedAccounts'; import { Heading } from './Heading/Heading'; import { Primary } from './Primary'; import { LogoWrapper } from './Wrapper'; @@ -23,9 +24,10 @@ import { LogoWrapper } from './Wrapper'; export const Main = () => { const { t, i18n } = useTranslation('base'); const { networkData } = useNetwork(); - const { activeAccount, accounts } = useConnect(); const { pathname } = useLocation(); const { getBondedAccount } = useBonded(); + const { accounts } = useImportedAccounts(); + const { activeAccount } = useActiveAccounts(); const { inSetup: inNominatorSetup, addressDifferentToStash } = useStaking(); const { membership } = usePoolMemberships(); const controller = getBondedAccount(activeAccount); diff --git a/src/library/Stat/types.ts b/src/library/Stat/types.ts index 987af8491d..e115163ce3 100644 --- a/src/library/Stat/types.ts +++ b/src/library/Stat/types.ts @@ -3,7 +3,7 @@ import type { IconProp } from '@fortawesome/fontawesome-svg-core'; import type { AnyObject } from '@polkadot-cloud/utils/types'; -import type { MaybeAccount } from 'types'; +import type { MaybeAddress } from 'types'; export interface StatProps { label: string; @@ -23,6 +23,6 @@ export interface StatProps { } export interface StatAddress { - address: MaybeAccount; + address: MaybeAddress; display: string; } diff --git a/src/library/SubmitTx/Default.tsx b/src/library/SubmitTx/Default.tsx index 46be97b0c0..f38e47306d 100644 --- a/src/library/SubmitTx/Default.tsx +++ b/src/library/SubmitTx/Default.tsx @@ -4,9 +4,9 @@ import { faArrowAltCircleUp } from '@fortawesome/free-regular-svg-icons'; import { ButtonSubmit } from '@polkadot-cloud/react'; import React from 'react'; -import { useConnect } from 'contexts/Connect'; import { useTxMeta } from 'contexts/TxMeta'; import { EstimatedTxFee } from 'library/EstimatedTxFee'; +import { useImportedAccounts } from 'contexts/Connect/ImportedAccounts'; import type { SubmitProps } from './types'; export const Default = ({ @@ -18,7 +18,7 @@ export const Default = ({ submitAddress, }: SubmitProps & { buttons?: React.ReactNode[] }) => { const { txFeesValid } = useTxMeta(); - const { accountHasSigner } = useConnect(); + const { accountHasSigner } = useImportedAccounts(); const disabled = submitting || !valid || !accountHasSigner(submitAddress) || !txFeesValid; diff --git a/src/library/SubmitTx/ManualSign/Ledger.tsx b/src/library/SubmitTx/ManualSign/Ledger.tsx index fa27d65bd1..a21331356d 100644 --- a/src/library/SubmitTx/ManualSign/Ledger.tsx +++ b/src/library/SubmitTx/ManualSign/Ledger.tsx @@ -5,8 +5,6 @@ import { faSquarePen } from '@fortawesome/free-solid-svg-icons'; import { ButtonHelp, ButtonSubmit } from '@polkadot-cloud/react'; import React, { useEffect, useRef } from 'react'; import { useTranslation } from 'react-i18next'; -import { useConnect } from 'contexts/Connect'; -import type { LedgerAccount } from 'contexts/Connect/types'; import { useLedgerHardware } from 'contexts/Hardware/Ledger'; import type { LedgerResponse } from 'contexts/Hardware/types'; import { useHelp } from 'contexts/Help'; @@ -14,6 +12,9 @@ import { useTxMeta } from 'contexts/TxMeta'; import { EstimatedTxFee } from 'library/EstimatedTxFee'; import { useLedgerLoop } from 'library/Hooks/useLedgerLoop'; import { useOverlay } from '@polkadot-cloud/react/hooks'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; +import { useImportedAccounts } from 'contexts/Connect/ImportedAccounts'; +import type { LedgerAccount } from '@polkadot-cloud/react/connect/types'; import type { SubmitProps } from '../types'; export const Ledger = ({ @@ -41,7 +42,9 @@ export const Ledger = ({ } = useLedgerHardware(); const { openHelp } = useHelp(); const { setModalResize } = useOverlay().modal; - const { activeAccount, accountHasSigner, getAccount } = useConnect(); + const { activeAccount } = useActiveAccounts(); + const { accountHasSigner } = useImportedAccounts(); + const { getAccount } = useImportedAccounts(); const { txFeesValid, setTxSignature, getTxSignature } = useTxMeta(); const getAddressIndex = () => { diff --git a/src/library/SubmitTx/ManualSign/Vault/index.tsx b/src/library/SubmitTx/ManualSign/Vault/index.tsx index 4a27da49d5..56d63083d5 100644 --- a/src/library/SubmitTx/ManualSign/Vault/index.tsx +++ b/src/library/SubmitTx/ManualSign/Vault/index.tsx @@ -5,10 +5,10 @@ import { faSquarePen } from '@fortawesome/free-solid-svg-icons'; import { ButtonSubmit } from '@polkadot-cloud/react'; import React from 'react'; import { useTranslation } from 'react-i18next'; -import { useConnect } from 'contexts/Connect'; import { usePrompt } from 'contexts/Prompt'; import { useTxMeta } from 'contexts/TxMeta'; import { EstimatedTxFee } from 'library/EstimatedTxFee'; +import { useImportedAccounts } from 'contexts/Connect/ImportedAccounts'; import type { SubmitProps } from '../../types'; import { SignPrompt } from './SignPrompt'; @@ -21,7 +21,7 @@ export const Vault = ({ submitAddress, }: SubmitProps & { buttons?: React.ReactNode[] }) => { const { t } = useTranslation('library'); - const { accountHasSigner } = useConnect(); + const { accountHasSigner } = useImportedAccounts(); const { txFeesValid, getTxSignature } = useTxMeta(); const { openPromptWith, status: promptStatus } = usePrompt(); diff --git a/src/library/SubmitTx/ManualSign/index.tsx b/src/library/SubmitTx/ManualSign/index.tsx index 09e7baac77..9220efa5b5 100644 --- a/src/library/SubmitTx/ManualSign/index.tsx +++ b/src/library/SubmitTx/ManualSign/index.tsx @@ -2,8 +2,8 @@ // SPDX-License-Identifier: GPL-3.0-only import React, { useEffect } from 'react'; -import { useConnect } from 'contexts/Connect'; import { useTxMeta } from 'contexts/TxMeta'; +import { useImportedAccounts } from 'contexts/Connect/ImportedAccounts'; import type { SubmitProps } from '../types'; import { Ledger } from './Ledger'; import { Vault } from './Vault'; @@ -11,7 +11,7 @@ import { Vault } from './Vault'; export const ManualSign = ( props: SubmitProps & { buttons?: React.ReactNode[] } ) => { - const { getAccount } = useConnect(); + const { getAccount } = useImportedAccounts(); const { getTxSignature, sender } = useTxMeta(); const accountMeta = getAccount(sender); const source = accountMeta?.source; diff --git a/src/library/SubmitTx/index.tsx b/src/library/SubmitTx/index.tsx index b067007523..50b9de4871 100644 --- a/src/library/SubmitTx/index.tsx +++ b/src/library/SubmitTx/index.tsx @@ -5,10 +5,11 @@ import { Tx } from '@polkadot-cloud/react'; import { useEffect } from 'react'; import { useTranslation } from 'react-i18next'; import { useBonded } from 'contexts/Bonded'; -import { useConnect } from 'contexts/Connect'; import { useTxMeta } from 'contexts/TxMeta'; import { useOverlay } from '@polkadot-cloud/react/hooks'; import { useNetwork } from 'contexts/Network'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; +import { useImportedAccounts } from 'contexts/Connect/ImportedAccounts'; import { Default } from './Default'; import { ManualSign } from './ManualSign'; import type { SubmitTxProps } from './types'; @@ -28,9 +29,9 @@ export const SubmitTx = ({ const { getBondedAccount } = useBonded(); const { unit } = useNetwork().networkData; const { setModalResize } = useOverlay().modal; + const { activeAccount, activeProxy } = useActiveAccounts(); const { notEnoughFunds, sender, setTxSignature } = useTxMeta(); - const { requiresManualSign, activeAccount, activeProxy, getAccount } = - useConnect(); + const { getAccount, requiresManualSign } = useImportedAccounts(); const controller = getBondedAccount(activeAccount); // Default to active account diff --git a/src/library/SubmitTx/types.ts b/src/library/SubmitTx/types.ts index fd9197d9c9..8f6d4fa303 100644 --- a/src/library/SubmitTx/types.ts +++ b/src/library/SubmitTx/types.ts @@ -2,13 +2,13 @@ // SPDX-License-Identifier: GPL-3.0-only import type React from 'react'; -import type { MaybeAccount } from 'types'; +import type { MaybeAddress } from 'types'; export type SubmitTxProps = SubmitProps & { buttons?: React.ReactNode[]; fromController?: boolean; proxySupported: boolean; - submitAddress?: MaybeAccount; + submitAddress?: MaybeAddress; noMargin?: boolean; }; @@ -18,9 +18,9 @@ export interface SubmitProps { submitting: boolean; valid: boolean; submitText?: string; - submitAddress: MaybeAccount; + submitAddress: MaybeAddress; } export interface SignerPromptProps { - submitAddress: MaybeAccount; + submitAddress: MaybeAddress; } diff --git a/src/library/ValidatorList/Validator/types.ts b/src/library/ValidatorList/Validator/types.ts index c50a5cbc0f..9054f9d2c0 100644 --- a/src/library/ValidatorList/Validator/types.ts +++ b/src/library/ValidatorList/Validator/types.ts @@ -1,11 +1,11 @@ // Copyright 2023 @paritytech/polkadot-staking-dashboard authors & contributors // SPDX-License-Identifier: GPL-3.0-only -import type { BondFor, MaybeAccount } from 'types'; +import type { BondFor, MaybeAddress } from 'types'; export interface NominationProps { validator: any; - nominator: MaybeAccount; + nominator: MaybeAddress; toggleFavorites: boolean; bondFor: BondFor; inModal: boolean; diff --git a/src/library/ValidatorList/index.tsx b/src/library/ValidatorList/index.tsx index 0df22232d7..e4c3fac0e7 100644 --- a/src/library/ValidatorList/index.tsx +++ b/src/library/ValidatorList/index.tsx @@ -9,7 +9,6 @@ import React, { useEffect, useRef, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { ListItemsPerBatch, ListItemsPerPage } from 'consts'; import { useApi } from 'contexts/Api'; -import { useConnect } from 'contexts/Connect'; import { useFilters } from 'contexts/Filters'; import { useNetworkMetrics } from 'contexts/NetworkMetrics'; import { useTheme } from 'contexts/Themes'; @@ -22,6 +21,7 @@ import { Selectable } from 'library/List/Selectable'; import { Validator } from 'library/ValidatorList/Validator'; import { useOverlay } from '@polkadot-cloud/react/hooks'; import { useNetwork } from 'contexts/Network'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; import { useValidatorFilters } from '../Hooks/useValidatorFilters'; import { ListProvider, useList } from '../List/context'; import { Filters } from './Filters'; @@ -56,7 +56,7 @@ export const ValidatorListInner = ({ const provider = useList(); const { mode } = useTheme(); const { isSyncing } = useUi(); - const { activeAccount } = useConnect(); + const { activeAccount } = useActiveAccounts(); const { activeEra } = useNetworkMetrics(); // determine the nominator of the validator list. diff --git a/src/main.tsx b/src/main.tsx index 2fb3a87deb..109a09bea8 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -2,14 +2,14 @@ // SPDX-License-Identifier: GPL-3.0-only // Network themes. -import '@polkadot-cloud/core/theme/polkadot-relay/index.css'; -import '@polkadot-cloud/core/theme/kusama-relay/index.css'; -import '@polkadot-cloud/core/theme/westend-relay/index.css'; +import '@polkadot-cloud/core/accent/polkadot-relay.css'; +import '@polkadot-cloud/core/accent/kusama-relay.css'; +import '@polkadot-cloud/core/accent/westend-relay.css'; // Default template fonts. -import '@polkadot-cloud/core/template/default/fonts/index.css'; +import '@polkadot-cloud/core/theme/default/fonts/index.css'; // Default template theme. -import '@polkadot-cloud/core/template/default/index.css'; +import '@polkadot-cloud/core/theme/default/index.css'; // Polkadot Cloud core styles. import '@polkadot-cloud/core/css/styles/index.css'; diff --git a/src/modals/Accounts/Account.tsx b/src/modals/Accounts/Account.tsx index 3d78e64f2e..896ce39cfd 100644 --- a/src/modals/Accounts/Account.tsx +++ b/src/modals/Accounts/Account.tsx @@ -6,13 +6,14 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { ellipsisFn, planckToUnit } from '@polkadot-cloud/utils'; import { useTranslation } from 'react-i18next'; import { Extensions } from '@polkadot-cloud/assets/extensions'; -import { useConnect } from 'contexts/Connect'; import LedgerIconSVG from 'img/ledgerIcon.svg?react'; import PolkadotVaultIconSVG from 'img/polkadotVault.svg?react'; import { Polkicon } from '@polkadot-cloud/react'; import { useTransferOptions } from 'contexts/TransferOptions'; import { useOverlay } from '@polkadot-cloud/react/hooks'; import { useNetwork } from 'contexts/Network'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; +import { useImportedAccounts } from 'contexts/Connect/ImportedAccounts'; import { AccountWrapper } from './Wrappers'; import type { AccountItemProps } from './types'; @@ -24,14 +25,14 @@ export const AccountButton = ({ noBorder = false, }: AccountItemProps) => { const { t } = useTranslation('modals'); + const { getAccount } = useImportedAccounts(); const { - getAccount, activeProxy, activeAccount, + setActiveAccount, setActiveProxy, activeProxyType, - connectToAccount, - } = useConnect(); + } = useActiveAccounts(); const { setModalStatus } = useOverlay().modal; const { units, unit } = useNetwork().networkData; const { getTransferOptions } = useTransferOptions(); @@ -64,7 +65,7 @@ export const AccountButton = ({ // Handle account click. Handles both active account and active proxy. const handleClick = () => { if (!imported) return; - connectToAccount(getAccount(connectTo)); + setActiveAccount(getAccount(connectTo)?.address || null); setActiveProxy(proxyType ? { address: connectProxy, proxyType } : null); setModalStatus('closing'); }; diff --git a/src/modals/Accounts/Delegates/index.tsx b/src/modals/Accounts/Delegates/index.tsx index 6e8a7bac3c..96ed618870 100644 --- a/src/modals/Accounts/Delegates/index.tsx +++ b/src/modals/Accounts/Delegates/index.tsx @@ -2,13 +2,14 @@ // SPDX-License-Identifier: GPL-3.0-only import { isSupportedProxy } from 'config/proxies'; -import { useConnect } from 'contexts/Connect'; +import { useImportedAccounts } from 'contexts/Connect/ImportedAccounts'; import { AccountButton } from '../Account'; import { DelegatesWrapper } from './Wrapper'; import type { DelegatesProps } from '../types'; export const Delegates = ({ delegates, delegator }: DelegatesProps) => { - const { getAccount, accounts } = useConnect(); + const { accounts } = useImportedAccounts(); + const { getAccount } = useImportedAccounts(); // Filter delegates that are external or not imported. Default to empty array if there are no // delegates for this address. diff --git a/src/modals/Accounts/index.tsx b/src/modals/Accounts/index.tsx index 8706ed0330..edf3d88076 100644 --- a/src/modals/Accounts/index.tsx +++ b/src/modals/Accounts/index.tsx @@ -13,7 +13,6 @@ import React, { useEffect, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { useBalances } from 'contexts/Balances'; import { useBonded } from 'contexts/Bonded'; -import { useConnect } from 'contexts/Connect'; import { useExtensions, useEffectIgnoreInitial, @@ -21,6 +20,8 @@ import { } from '@polkadot-cloud/react/hooks'; import { usePoolMemberships } from 'contexts/Pools/PoolMemberships'; import { useProxies } from 'contexts/Proxies'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; +import { useImportedAccounts } from 'contexts/Connect/ImportedAccounts'; import { AccountButton } from './Account'; import { Delegates } from './Delegates'; import { AccountSeparator, AccountWrapper } from './Wrappers'; @@ -44,8 +45,9 @@ export const Accounts = () => { status: modalStatus, setModalResize, } = useOverlay().modal; - const { activeAccount, disconnectFromAccount, setActiveProxy, accounts } = - useConnect(); + const { accounts } = useImportedAccounts(); + const { activeAccount, setActiveAccount, setActiveProxy } = + useActiveAccounts(); // Store local copy of accounts. const [localAccounts, setLocalAccounts] = useState(accounts); @@ -146,7 +148,7 @@ export const Accounts = () => { text={t('disconnect')} iconRight={faLinkSlash} onClick={() => { - disconnectFromAccount(); + setActiveAccount(null); setActiveProxy(null); }} /> diff --git a/src/modals/Accounts/types.ts b/src/modals/Accounts/types.ts index bc3b694f09..8584ec8439 100644 --- a/src/modals/Accounts/types.ts +++ b/src/modals/Accounts/types.ts @@ -3,10 +3,10 @@ import type { PoolMembership } from 'contexts/Pools/types'; import type { Proxy } from 'contexts/Proxies/type'; -import type { MaybeAccount } from 'types'; +import type { MaybeAddress } from 'types'; export interface AccountItemProps { - address?: MaybeAccount; + address?: MaybeAddress; label?: string[]; asElement?: boolean; delegator?: string; @@ -24,7 +24,7 @@ export interface AccountInPool extends PoolMembership { } export interface AccountNominating { - address: MaybeAccount; + address: MaybeAddress; stashImported: boolean; delegates?: Proxy; } diff --git a/src/modals/BalanceTest/index.tsx b/src/modals/BalanceTest/index.tsx index 4f984b4cd8..44203c2bf4 100644 --- a/src/modals/BalanceTest/index.tsx +++ b/src/modals/BalanceTest/index.tsx @@ -4,7 +4,6 @@ import { ModalPadding } from '@polkadot-cloud/react'; import { unitToPlanck } from '@polkadot-cloud/utils'; import { useApi } from 'contexts/Api'; -import { useConnect } from 'contexts/Connect'; import { useOverlay } from '@polkadot-cloud/react/hooks'; import { useTxMeta } from 'contexts/TxMeta'; import { useBatchCall } from 'library/Hooks/useBatchCall'; @@ -13,13 +12,14 @@ import { Close } from 'library/Modal/Close'; import { SubmitTx } from 'library/SubmitTx'; import { useEffect } from 'react'; import { useNetwork } from 'contexts/Network'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; export const BalanceTest = () => { const { api } = useApi(); const { networkData: { units }, } = useNetwork(); - const { activeAccount } = useConnect(); + const { activeAccount } = useActiveAccounts(); const { notEnoughFunds } = useTxMeta(); const { newBatchCall } = useBatchCall(); const { setModalStatus, setModalResize } = useOverlay().modal; diff --git a/src/modals/Bond/index.tsx b/src/modals/Bond/index.tsx index 2829b2b9ad..81104962d5 100644 --- a/src/modals/Bond/index.tsx +++ b/src/modals/Bond/index.tsx @@ -7,7 +7,6 @@ import BigNumber from 'bignumber.js'; import { useEffect, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { useApi } from 'contexts/Api'; -import { useConnect } from 'contexts/Connect'; import { useActivePools } from 'contexts/Pools/ActivePools'; import { useTransferOptions } from 'contexts/TransferOptions'; import { BondFeedback } from 'library/Form/Bond/BondFeedback'; @@ -20,6 +19,7 @@ import { SubmitTx } from 'library/SubmitTx'; import { useTxMeta } from 'contexts/TxMeta'; import { useOverlay } from '@polkadot-cloud/react/hooks'; import { useNetwork } from 'contexts/Network'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; export const Bond = () => { const { t } = useTranslation('modals'); @@ -27,7 +27,7 @@ export const Bond = () => { const { networkData: { units, unit }, } = useNetwork(); - const { activeAccount } = useConnect(); + const { activeAccount } = useActiveAccounts(); const { notEnoughFunds } = useTxMeta(); const { selectedActivePool } = useActivePools(); const { getSignerWarnings } = useSignerWarnings(); diff --git a/src/modals/ChangeNominations/index.tsx b/src/modals/ChangeNominations/index.tsx index df36bafa77..3801a330c7 100644 --- a/src/modals/ChangeNominations/index.tsx +++ b/src/modals/ChangeNominations/index.tsx @@ -10,7 +10,6 @@ import { useEffect, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { useApi } from 'contexts/Api'; import { useBonded } from 'contexts/Bonded'; -import { useConnect } from 'contexts/Connect'; import { useActivePools } from 'contexts/Pools/ActivePools'; import { Warning } from 'library/Form/Warning'; import { useSignerWarnings } from 'library/Hooks/useSignerWarnings'; @@ -19,11 +18,12 @@ import { Close } from 'library/Modal/Close'; import { SubmitTx } from 'library/SubmitTx'; import { useTxMeta } from 'contexts/TxMeta'; import { useOverlay } from '@polkadot-cloud/react/hooks'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; export const ChangeNominations = () => { const { t } = useTranslation('modals'); const { api } = useApi(); - const { activeAccount } = useConnect(); + const { activeAccount } = useActiveAccounts(); const { notEnoughFunds } = useTxMeta(); const { getSignerWarnings } = useSignerWarnings(); const { getBondedAccount, getAccountNominations } = useBonded(); diff --git a/src/modals/ChangePoolRoles/index.tsx b/src/modals/ChangePoolRoles/index.tsx index e8fa4959cf..53845ead90 100644 --- a/src/modals/ChangePoolRoles/index.tsx +++ b/src/modals/ChangePoolRoles/index.tsx @@ -4,7 +4,6 @@ import { ModalPadding } from '@polkadot-cloud/react'; import { useTranslation } from 'react-i18next'; import { useApi } from 'contexts/Api'; -import { useConnect } from 'contexts/Connect'; import { useBondedPools } from 'contexts/Pools/BondedPools'; import { useSubmitExtrinsic } from 'library/Hooks/useSubmitExtrinsic'; import { Close } from 'library/Modal/Close'; @@ -12,13 +11,14 @@ import { SubmitTx } from 'library/SubmitTx'; import { useTxMeta } from 'contexts/TxMeta'; import { useEffect } from 'react'; import { useOverlay } from '@polkadot-cloud/react/hooks'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; import { RoleChange } from './RoleChange'; import { Wrapper } from './Wrapper'; export const ChangePoolRoles = () => { const { t } = useTranslation('modals'); const { api } = useApi(); - const { activeAccount } = useConnect(); + const { activeAccount } = useActiveAccounts(); const { notEnoughFunds } = useTxMeta(); const { replacePoolRoles } = useBondedPools(); const { diff --git a/src/modals/ClaimPayouts/Forms.tsx b/src/modals/ClaimPayouts/Forms.tsx index 27058fdffb..98de20ecbd 100644 --- a/src/modals/ClaimPayouts/Forms.tsx +++ b/src/modals/ClaimPayouts/Forms.tsx @@ -12,7 +12,6 @@ import BigNumber from 'bignumber.js'; import { forwardRef, useEffect, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { useApi } from 'contexts/Api'; -import { useConnect } from 'contexts/Connect'; import { Warning } from 'library/Form/Warning'; import { useSignerWarnings } from 'library/Hooks/useSignerWarnings'; import { useSubmitExtrinsic } from 'library/Hooks/useSubmitExtrinsic'; @@ -23,6 +22,7 @@ import type { AnyApi, AnySubscan } from 'types'; import { useSubscan } from 'contexts/Plugins/Subscan'; import { usePayouts } from 'contexts/Payouts'; import { useNetwork } from 'contexts/Network'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; import type { FormProps, ActivePayout } from './types'; import { ContentWrapper } from './Wrappers'; @@ -33,7 +33,7 @@ export const Forms = forwardRef( const { networkData: { units, unit }, } = useNetwork(); - const { activeAccount } = useConnect(); + const { activeAccount } = useActiveAccounts(); const { newBatchCall } = useBatchCall(); const { removeEraPayout } = usePayouts(); const { setModalStatus } = useOverlay().modal; diff --git a/src/modals/ClaimReward/index.tsx b/src/modals/ClaimReward/index.tsx index 0619790bab..9b3edd12e6 100644 --- a/src/modals/ClaimReward/index.tsx +++ b/src/modals/ClaimReward/index.tsx @@ -7,7 +7,6 @@ import BigNumber from 'bignumber.js'; import { useEffect, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { useApi } from 'contexts/Api'; -import { useConnect } from 'contexts/Connect'; import { useActivePools } from 'contexts/Pools/ActivePools'; import { Warning } from 'library/Form/Warning'; import { useSignerWarnings } from 'library/Hooks/useSignerWarnings'; @@ -17,6 +16,7 @@ import { SubmitTx } from 'library/SubmitTx'; import { useTxMeta } from 'contexts/TxMeta'; import { useOverlay } from '@polkadot-cloud/react/hooks'; import { useNetwork } from 'contexts/Network'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; export const ClaimReward = () => { const { t } = useTranslation('modals'); @@ -24,7 +24,7 @@ export const ClaimReward = () => { const { networkData: { units, unit }, } = useNetwork(); - const { activeAccount } = useConnect(); + const { activeAccount } = useActiveAccounts(); const { notEnoughFunds } = useTxMeta(); const { selectedActivePool } = useActivePools(); const { getSignerWarnings } = useSignerWarnings(); diff --git a/src/modals/Connect/Extension.tsx b/src/modals/Connect/Extension.tsx index ac69072f41..011c9e1894 100644 --- a/src/modals/Connect/Extension.tsx +++ b/src/modals/Connect/Extension.tsx @@ -6,16 +6,16 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { ModalConnectItem } from '@polkadot-cloud/react'; import { useState } from 'react'; import { useTranslation } from 'react-i18next'; -import { useConnect } from 'contexts/Connect'; import { useExtensions } from '@polkadot-cloud/react/hooks'; import { useNotifications } from 'contexts/Notifications'; +import { useExtensionAccounts } from 'contexts/Connect/ExtensionAccounts'; import { ExtensionInner } from './Wrappers'; import type { ExtensionProps } from './types'; export const Extension = ({ meta, size, flag }: ExtensionProps) => { const { t } = useTranslation('modals'); const { addNotification } = useNotifications(); - const { connectExtensionAccounts } = useConnect(); + const { connectExtensionAccounts } = useExtensionAccounts(); const { extensions, extensionsStatus } = useExtensions(); const { title, Icon, website } = meta; diff --git a/src/modals/Connect/Proxies.tsx b/src/modals/Connect/Proxies.tsx index 0ab9086680..fad0651e5e 100644 --- a/src/modals/Connect/Proxies.tsx +++ b/src/modals/Connect/Proxies.tsx @@ -15,10 +15,10 @@ import { } from '@polkadot-cloud/react'; import React from 'react'; import { useTranslation } from 'react-i18next'; -import { useConnect } from 'contexts/Connect'; import { useHelp } from 'contexts/Help'; import { useProxies } from 'contexts/Proxies'; import { AccountInput } from 'library/AccountInput'; +import { useImportedAccounts } from 'contexts/Connect/ImportedAccounts'; import { ActionWithButton, ManualAccount, @@ -29,7 +29,8 @@ import type { ListWithInputProps } from './types'; export const Proxies = ({ setInputOpen, inputOpen }: ListWithInputProps) => { const { t } = useTranslation('modals'); const { openHelp } = useHelp(); - const { accounts, getAccount } = useConnect(); + const { accounts } = useImportedAccounts(); + const { getAccount } = useImportedAccounts(); const { delegates, handleDeclareDelegate } = useProxies(); // Filter delegates to only show those who are imported in the dashboard. diff --git a/src/modals/Connect/ReadOnly.tsx b/src/modals/Connect/ReadOnly.tsx index 3e302fffd6..ca01f43aa6 100644 --- a/src/modals/Connect/ReadOnly.tsx +++ b/src/modals/Connect/ReadOnly.tsx @@ -14,11 +14,12 @@ import { Polkicon, } from '@polkadot-cloud/react'; import { useTranslation } from 'react-i18next'; -import { useConnect } from 'contexts/Connect'; -import type { ExternalAccount } from 'contexts/Connect/types'; import { useHelp } from 'contexts/Help'; import { AccountInput } from 'library/AccountInput'; import { useOverlay } from '@polkadot-cloud/react/hooks'; +import { useImportedAccounts } from 'contexts/Connect/ImportedAccounts'; +import { useOtherAccounts } from 'contexts/Connect/OtherAccounts'; +import type { ExternalAccount } from '@polkadot-cloud/react/connect/types'; import { ActionWithButton, ManualAccount, @@ -29,8 +30,9 @@ import type { ListWithInputProps } from './types'; export const ReadOnly = ({ setInputOpen, inputOpen }: ListWithInputProps) => { const { t } = useTranslation('modals'); const { openHelp } = useHelp(); + const { accounts } = useImportedAccounts(); const { setModalResize } = useOverlay().modal; - const { accounts, forgetAccounts, addExternalAccount } = useConnect(); + const { forgetExternalAccounts, addExternalAccount } = useOtherAccounts(); // get all external accounts const externalAccountsOnly = accounts.filter( @@ -44,7 +46,7 @@ export const ReadOnly = ({ setInputOpen, inputOpen }: ListWithInputProps) => { // forget account const forgetAccount = (account: ExternalAccount) => { - forgetAccounts([account]); + forgetExternalAccounts([account]); setModalResize(); }; return ( diff --git a/src/modals/ImportLedger/Addresses.tsx b/src/modals/ImportLedger/Addresses.tsx index ad120c16ab..55f61a80d5 100644 --- a/src/modals/ImportLedger/Addresses.tsx +++ b/src/modals/ImportLedger/Addresses.tsx @@ -5,7 +5,6 @@ import { faArrowDown } from '@fortawesome/free-solid-svg-icons'; import { ButtonText, HardwareAddress, Polkicon } from '@polkadot-cloud/react'; import { ellipsisFn, unescape } from '@polkadot-cloud/utils'; import { useTranslation } from 'react-i18next'; -import { useConnect } from 'contexts/Connect'; import { useLedgerHardware } from 'contexts/Hardware/Ledger'; import { getLocalLedgerAddresses } from 'contexts/Hardware/Utils'; import { usePrompt } from 'contexts/Prompt'; @@ -14,6 +13,7 @@ import { Remove } from 'library/Import/Remove'; import { AddressesWrapper } from 'library/Import/Wrappers'; import type { AnyJson } from 'types'; import { useNetwork } from 'contexts/Network'; +import { useOtherAccounts } from 'contexts/Connect/OtherAccounts'; export const Addresess = ({ addresses, handleLedgerLoop }: AnyJson) => { const { t } = useTranslation('modals'); @@ -29,13 +29,13 @@ export const Addresess = ({ addresses, handleLedgerLoop }: AnyJson) => { getLedgerAccount, pairDevice, } = useLedgerHardware(); - const { openPromptWith } = usePrompt(); - const { renameImportedAccount } = useConnect(); const isExecuting = getIsExecuting(); + const { openPromptWith } = usePrompt(); + const { renameOtherAccount } = useOtherAccounts(); const renameHandler = (address: string, newName: string) => { renameLedgerAccount(address, newName); - renameImportedAccount(address, newName); + renameOtherAccount(address, newName); }; const openConfirmHandler = (address: string, index: number) => { diff --git a/src/modals/ImportLedger/Reset.tsx b/src/modals/ImportLedger/Reset.tsx index 11add0adce..1e6db89de8 100644 --- a/src/modals/ImportLedger/Reset.tsx +++ b/src/modals/ImportLedger/Reset.tsx @@ -3,8 +3,6 @@ import { ButtonMono, ButtonMonoInvert } from '@polkadot-cloud/react'; import { useTranslation } from 'react-i18next'; -import { useConnect } from 'contexts/Connect'; -import type { LedgerAccount } from 'contexts/Connect/types'; import { useLedgerHardware } from 'contexts/Hardware/Ledger'; import { getLocalLedgerAddresses } from 'contexts/Hardware/Utils'; import type { LedgerAddress } from 'contexts/Hardware/types'; @@ -12,12 +10,14 @@ import { usePrompt } from 'contexts/Prompt'; import { ConfirmWrapper } from 'library/Import/Wrappers'; import type { AnyJson } from 'types'; import { useOverlay } from '@polkadot-cloud/react/hooks'; +import { useOtherAccounts } from 'contexts/Connect/OtherAccounts'; +import type { LedgerAccount } from '@polkadot-cloud/react/connect/types'; export const Reset = ({ removeLedgerAddress }: AnyJson) => { const { t } = useTranslation('modals'); - const { forgetAccounts } = useConnect(); const { setStatus } = usePrompt(); const { replaceModal } = useOverlay().modal; + const { forgetOtherAccounts } = useOtherAccounts(); const { ledgerAccounts, removeLedgerAccount } = useLedgerHardware(); const removeAccounts = () => { @@ -25,7 +25,7 @@ export const Reset = ({ removeLedgerAddress }: AnyJson) => { ledgerAccounts.forEach((account: LedgerAccount) => { removeLedgerAccount(account.address); }); - forgetAccounts(ledgerAccounts); + forgetOtherAccounts(ledgerAccounts); // Remove local Ledger addresses. getLocalLedgerAddresses().forEach((address: LedgerAddress) => { diff --git a/src/modals/ImportVault/Reader.tsx b/src/modals/ImportVault/Reader.tsx index b5f4f8f2e2..406a56f970 100644 --- a/src/modals/ImportVault/Reader.tsx +++ b/src/modals/ImportVault/Reader.tsx @@ -5,15 +5,20 @@ import { ButtonSecondary } from '@polkadot-cloud/react'; import { isValidAddress } from '@polkadot-cloud/utils'; import { useEffect, useState } from 'react'; import { useTranslation } from 'react-i18next'; -import { useConnect } from 'contexts/Connect'; import { useVaultHardware } from 'contexts/Hardware/Vault'; import { usePrompt } from 'contexts/Prompt'; import { QRViewerWrapper } from 'library/Import/Wrappers'; import { QrScanSignature } from 'library/QRCode/ScanSignature'; +import { useNetwork } from 'contexts/Network'; +import { formatAccountSs58 } from 'contexts/Connect/Utils'; +import { useOtherAccounts } from 'contexts/Connect/OtherAccounts'; export const Reader = () => { const { t } = useTranslation('modals'); - const { addToAccounts, formatAccountSs58 } = useConnect(); + const { + networkData: { ss58 }, + } = useNetwork(); + const { addOtherAccounts } = useOtherAccounts(); const { setStatus: setPromptStatus } = usePrompt(); const { addVaultAccount, vaultAccountExists, vaultAccounts } = useVaultHardware(); @@ -31,7 +36,7 @@ export const Reader = () => { const valid = isValidAddress(qrData) && !vaultAccountExists(qrData) && - !formatAccountSs58(qrData); + !formatAccountSs58(qrData, ss58); // Reset QR data on open. useEffect(() => { @@ -43,7 +48,7 @@ export const Reader = () => { if (valid) { const account = addVaultAccount(qrData, vaultAccounts.length); if (account) { - addToAccounts([account]); + addOtherAccounts([account]); } setPromptStatus(0); } @@ -53,7 +58,7 @@ export const Reader = () => { qrData === undefined ? `${t('waitingForQRCode')}` : isValidAddress(qrData) - ? formatAccountSs58(qrData) + ? formatAccountSs58(qrData, ss58) ? `${t('differentNetworkAddress')}` : vaultAccountExists(qrData) ? `${t('accountAlreadyImported')}` diff --git a/src/modals/ImportVault/index.tsx b/src/modals/ImportVault/index.tsx index d9b4481f4c..3db087adc2 100644 --- a/src/modals/ImportVault/index.tsx +++ b/src/modals/ImportVault/index.tsx @@ -11,7 +11,6 @@ import { } from '@polkadot-cloud/react'; import { useEffect } from 'react'; import { useTranslation } from 'react-i18next'; -import { useConnect } from 'contexts/Connect'; import { useVaultHardware } from 'contexts/Hardware/Vault'; import { usePrompt } from 'contexts/Prompt'; import IconSVG from 'img/polkadotVault.svg?react'; @@ -22,12 +21,13 @@ import { Remove } from 'library/Import/Remove'; import { AddressesWrapper } from 'library/Import/Wrappers'; import type { AnyJson } from 'types'; import { useOverlay } from '@polkadot-cloud/react/hooks'; +import { useOtherAccounts } from 'contexts/Connect/OtherAccounts'; import { Reader } from './Reader'; export const ImportVault = () => { const { t } = useTranslation(); const { replaceModal } = useOverlay().modal; - const { renameImportedAccount } = useConnect(); + const { renameOtherAccount } = useOtherAccounts(); const { openPromptWith, status: promptStatus } = usePrompt(); const { @@ -42,7 +42,7 @@ export const ImportVault = () => { const renameHandler = (address: string, newName: string) => { renameVaultAccount(address, newName); - renameImportedAccount(address, newName); + renameOtherAccount(address, newName); }; const openConfirmHandler = (address: string, index: number) => { diff --git a/src/modals/JoinPool/index.tsx b/src/modals/JoinPool/index.tsx index 82eac703bf..10fee24f7f 100644 --- a/src/modals/JoinPool/index.tsx +++ b/src/modals/JoinPool/index.tsx @@ -7,7 +7,6 @@ import BigNumber from 'bignumber.js'; import { useEffect, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { useApi } from 'contexts/Api'; -import { useConnect } from 'contexts/Connect'; import { usePoolMembers } from 'contexts/Pools/PoolMembers'; import type { ClaimPermission } from 'contexts/Pools/types'; import { useSetup } from 'contexts/Setup'; @@ -24,6 +23,7 @@ import { Close } from 'library/Modal/Close'; import { SubmitTx } from 'library/SubmitTx'; import { useOverlay } from '@polkadot-cloud/react/hooks'; import { useNetwork } from 'contexts/Network'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; export const JoinPool = () => { const { t } = useTranslation('modals'); @@ -31,7 +31,7 @@ export const JoinPool = () => { const { networkData: { units }, } = useNetwork(); - const { activeAccount } = useConnect(); + const { activeAccount } = useActiveAccounts(); const { newBatchCall } = useBatchCall(); const { setActiveAccountSetup } = useSetup(); const { txFees, notEnoughFunds } = useTxMeta(); diff --git a/src/modals/ManageFastUnstake/index.tsx b/src/modals/ManageFastUnstake/index.tsx index 59481a6a71..1e3fe4ca14 100644 --- a/src/modals/ManageFastUnstake/index.tsx +++ b/src/modals/ManageFastUnstake/index.tsx @@ -13,7 +13,6 @@ import { useEffect, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { useApi } from 'contexts/Api'; import { useBonded } from 'contexts/Bonded'; -import { useConnect } from 'contexts/Connect'; import { useFastUnstake } from 'contexts/FastUnstake'; import { useNetworkMetrics } from 'contexts/NetworkMetrics'; import { useTransferOptions } from 'contexts/TransferOptions'; @@ -26,6 +25,7 @@ import { SubmitTx } from 'library/SubmitTx'; import { useTxMeta } from 'contexts/TxMeta'; import { useOverlay } from '@polkadot-cloud/react/hooks'; import { useNetwork } from 'contexts/Network'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; export const ManageFastUnstake = () => { const { t } = useTranslation('modals'); @@ -33,7 +33,7 @@ export const ManageFastUnstake = () => { const { networkData: { units, unit }, } = useNetwork(); - const { activeAccount } = useConnect(); + const { activeAccount } = useActiveAccounts(); const { notEnoughFunds } = useTxMeta(); const { getBondedAccount } = useBonded(); const { isFastUnstaking } = useUnstaking(); diff --git a/src/modals/ManagePool/Forms/ClaimCommission.tsx b/src/modals/ManagePool/Forms/ClaimCommission.tsx index 0f8f863984..2abe71ed60 100644 --- a/src/modals/ManagePool/Forms/ClaimCommission.tsx +++ b/src/modals/ManagePool/Forms/ClaimCommission.tsx @@ -13,7 +13,6 @@ import BigNumber from 'bignumber.js'; import { useEffect, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { useApi } from 'contexts/Api'; -import { useConnect } from 'contexts/Connect'; import { useActivePools } from 'contexts/Pools/ActivePools'; import { Warning } from 'library/Form/Warning'; import { useSignerWarnings } from 'library/Hooks/useSignerWarnings'; @@ -21,6 +20,7 @@ import { useSubmitExtrinsic } from 'library/Hooks/useSubmitExtrinsic'; import { SubmitTx } from 'library/SubmitTx'; import { useOverlay } from '@polkadot-cloud/react/hooks'; import { useNetwork } from 'contexts/Network'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; export const ClaimCommission = ({ setSection }: any) => { const { t } = useTranslation('modals'); @@ -29,7 +29,7 @@ export const ClaimCommission = ({ setSection }: any) => { networkData: { units, unit }, } = useNetwork(); const { setModalStatus } = useOverlay().modal; - const { activeAccount } = useConnect(); + const { activeAccount } = useActiveAccounts(); const { isOwner, selectedActivePool } = useActivePools(); const { getSignerWarnings } = useSignerWarnings(); const poolId = selectedActivePool?.id; diff --git a/src/modals/ManagePool/Forms/Commission.tsx b/src/modals/ManagePool/Forms/Commission.tsx index 2f732cbbe0..123b1475f3 100644 --- a/src/modals/ManagePool/Forms/Commission.tsx +++ b/src/modals/ManagePool/Forms/Commission.tsx @@ -15,7 +15,6 @@ import Slider from 'rc-slider'; import { useEffect, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { useApi } from 'contexts/Api'; -import { useConnect } from 'contexts/Connect'; import { useHelp } from 'contexts/Help'; import { useActivePools } from 'contexts/Pools/ActivePools'; import { useBondedPools } from 'contexts/Pools/BondedPools'; @@ -28,8 +27,9 @@ import { useSignerWarnings } from 'library/Hooks/useSignerWarnings'; import { useSubmitExtrinsic } from 'library/Hooks/useSubmitExtrinsic'; import { SubmitTx } from 'library/SubmitTx'; import 'rc-slider/assets/index.css'; -import type { MaybeAccount } from 'types'; +import type { MaybeAddress } from 'types'; import { useOverlay } from '@polkadot-cloud/react/hooks'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; import { SliderWrapper } from '../Wrappers'; import type { ChangeRateInput } from './types'; @@ -37,7 +37,7 @@ export const Commission = ({ setSection, incrementCalculateHeight }: any) => { const { t } = useTranslation('modals'); const { openHelp } = useHelp(); const { api, consts } = useApi(); - const { activeAccount } = useConnect(); + const { activeAccount } = useActiveAccounts(); const { newBatchCall } = useBatchCall(); const { stats } = usePoolsConfig(); const { setModalStatus } = useOverlay().modal; @@ -89,7 +89,7 @@ export const Commission = ({ setSection, incrementCalculateHeight }: any) => { ); // Store the commission payee. - const [payee, setPayee] = useState(initialPayee); + const [payee, setPayee] = useState(initialPayee); // Store the maximum commission value. const [maxCommission, setMaxCommission] = diff --git a/src/modals/ManagePool/Forms/LeavePool.tsx b/src/modals/ManagePool/Forms/LeavePool.tsx index 0401c185c9..f9e79b5c71 100644 --- a/src/modals/ManagePool/Forms/LeavePool.tsx +++ b/src/modals/ManagePool/Forms/LeavePool.tsx @@ -17,7 +17,6 @@ import { getUnixTime } from 'date-fns'; import { useEffect, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { useApi } from 'contexts/Api'; -import { useConnect } from 'contexts/Connect'; import { useActivePools } from 'contexts/Pools/ActivePools'; import { useTransferOptions } from 'contexts/TransferOptions'; import { Warning } from 'library/Form/Warning'; @@ -29,6 +28,7 @@ import { SubmitTx } from 'library/SubmitTx'; import { StaticNote } from 'modals/Utils/StaticNote'; import { useOverlay } from '@polkadot-cloud/react/hooks'; import { useNetwork } from 'contexts/Network'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; export const LeavePool = ({ setSection }: any) => { const { t } = useTranslation('modals'); @@ -36,7 +36,7 @@ export const LeavePool = ({ setSection }: any) => { const { networkData: { units, unit }, } = useNetwork(); - const { activeAccount } = useConnect(); + const { activeAccount } = useActiveAccounts(); const { setModalStatus, setModalResize } = useOverlay().modal; const { getTransferOptions } = useTransferOptions(); const { selectedActivePool } = useActivePools(); diff --git a/src/modals/ManagePool/Forms/SetClaimPermission.tsx b/src/modals/ManagePool/Forms/SetClaimPermission.tsx index 473b4c8993..0bf3035701 100644 --- a/src/modals/ManagePool/Forms/SetClaimPermission.tsx +++ b/src/modals/ManagePool/Forms/SetClaimPermission.tsx @@ -6,7 +6,6 @@ import { ButtonSubmitInvert, ModalWarnings } from '@polkadot-cloud/react'; import { useEffect, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { useApi } from 'contexts/Api'; -import { useConnect } from 'contexts/Connect'; import { useActivePools } from 'contexts/Pools/ActivePools'; import { usePoolMemberships } from 'contexts/Pools/PoolMemberships'; import type { ClaimPermission } from 'contexts/Pools/types'; @@ -16,11 +15,12 @@ import { useSignerWarnings } from 'library/Hooks/useSignerWarnings'; import { useSubmitExtrinsic } from 'library/Hooks/useSubmitExtrinsic'; import { SubmitTx } from 'library/SubmitTx'; import { useOverlay } from '@polkadot-cloud/react/hooks'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; export const SetClaimPermission = ({ setSection, section }: any) => { const { t } = useTranslation('modals'); const { api } = useApi(); - const { activeAccount } = useConnect(); + const { activeAccount } = useActiveAccounts(); const { setModalStatus } = useOverlay().modal; const { isOwner, isMember } = useActivePools(); const { getSignerWarnings } = useSignerWarnings(); diff --git a/src/modals/ManagePool/Forms/SetMetadata.tsx b/src/modals/ManagePool/Forms/SetMetadata.tsx index f2bee92c2a..1ed361ca57 100644 --- a/src/modals/ManagePool/Forms/SetMetadata.tsx +++ b/src/modals/ManagePool/Forms/SetMetadata.tsx @@ -7,7 +7,6 @@ import { ButtonSubmitInvert, ModalWarnings } from '@polkadot-cloud/react'; import React, { useEffect, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { useApi } from 'contexts/Api'; -import { useConnect } from 'contexts/Connect'; import { useActivePools } from 'contexts/Pools/ActivePools'; import { useBondedPools } from 'contexts/Pools/BondedPools'; import { Warning } from 'library/Form/Warning'; @@ -15,12 +14,13 @@ import { useSignerWarnings } from 'library/Hooks/useSignerWarnings'; import { useSubmitExtrinsic } from 'library/Hooks/useSubmitExtrinsic'; import { SubmitTx } from 'library/SubmitTx'; import { useOverlay } from '@polkadot-cloud/react/hooks'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; export const SetMetadata = ({ setSection, section }: any) => { const { t } = useTranslation('modals'); const { api } = useApi(); const { setModalStatus } = useOverlay().modal; - const { activeAccount } = useConnect(); + const { activeAccount } = useActiveAccounts(); const { isOwner, selectedActivePool } = useActivePools(); const { bondedPools, meta } = useBondedPools(); const { getSignerWarnings } = useSignerWarnings(); diff --git a/src/modals/ManagePool/Forms/SetState.tsx b/src/modals/ManagePool/Forms/SetState.tsx index c608eb7252..2262eb9f41 100644 --- a/src/modals/ManagePool/Forms/SetState.tsx +++ b/src/modals/ManagePool/Forms/SetState.tsx @@ -10,7 +10,6 @@ import { import { useEffect, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { useApi } from 'contexts/Api'; -import { useConnect } from 'contexts/Connect'; import { useActivePools } from 'contexts/Pools/ActivePools'; import { useBondedPools } from 'contexts/Pools/BondedPools'; import { Warning } from 'library/Form/Warning'; @@ -18,12 +17,13 @@ import { useSignerWarnings } from 'library/Hooks/useSignerWarnings'; import { useSubmitExtrinsic } from 'library/Hooks/useSubmitExtrinsic'; import { SubmitTx } from 'library/SubmitTx'; import { useOverlay } from '@polkadot-cloud/react/hooks'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; export const SetState = ({ setSection, task }: any) => { const { t } = useTranslation('modals'); const { api } = useApi(); const { setModalStatus } = useOverlay().modal; - const { activeAccount } = useConnect(); + const { activeAccount } = useActiveAccounts(); const { isOwner, isBouncer, selectedActivePool } = useActivePools(); const { updateBondedPools, getBondedPool } = useBondedPools(); const { getSignerWarnings } = useSignerWarnings(); diff --git a/src/modals/ManagePool/Tasks.tsx b/src/modals/ManagePool/Tasks.tsx index dc8e764173..4b65f14a3f 100644 --- a/src/modals/ManagePool/Tasks.tsx +++ b/src/modals/ManagePool/Tasks.tsx @@ -4,16 +4,16 @@ import { ButtonOption } from '@polkadot-cloud/react'; import { forwardRef } from 'react'; import { useTranslation } from 'react-i18next'; -import { useConnect } from 'contexts/Connect'; import { useActivePools } from 'contexts/Pools/ActivePools'; import { usePoolsConfig } from 'contexts/Pools/PoolsConfig'; import { useTransferOptions } from 'contexts/TransferOptions'; import { Warning } from 'library/Form/Warning'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; import { ContentWrapper } from './Wrappers'; export const Tasks = forwardRef(({ setSection, setTask }: any, ref: any) => { const { t } = useTranslation('modals'); - const { activeAccount } = useConnect(); + const { activeAccount } = useActiveAccounts(); const { selectedActivePool, isOwner, isBouncer, isMember, isDepositor } = useActivePools(); const { getTransferOptions } = useTransferOptions(); diff --git a/src/modals/Nominate/index.tsx b/src/modals/Nominate/index.tsx index ee87f2cb78..3e79d957f8 100644 --- a/src/modals/Nominate/index.tsx +++ b/src/modals/Nominate/index.tsx @@ -8,7 +8,6 @@ import { useTranslation } from 'react-i18next'; import { useApi } from 'contexts/Api'; import { useBalances } from 'contexts/Balances'; import { useBonded } from 'contexts/Bonded'; -import { useConnect } from 'contexts/Connect'; import { useStaking } from 'contexts/Staking'; import { Warning } from 'library/Form/Warning'; import { useSignerWarnings } from 'library/Hooks/useSignerWarnings'; @@ -18,6 +17,7 @@ import { SubmitTx } from 'library/SubmitTx'; import { useTxMeta } from 'contexts/TxMeta'; import { useOverlay } from '@polkadot-cloud/react/hooks'; import { useNetwork } from 'contexts/Network'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; export const Nominate = () => { const { t } = useTranslation('modals'); @@ -25,7 +25,7 @@ export const Nominate = () => { const { networkData: { units, unit }, } = useNetwork(); - const { activeAccount } = useConnect(); + const { activeAccount } = useActiveAccounts(); const { notEnoughFunds } = useTxMeta(); const { getBondedAccount } = useBonded(); const { getStashLedger } = useBalances(); diff --git a/src/modals/NominateFromFavorites/index.tsx b/src/modals/NominateFromFavorites/index.tsx index b586ebd32f..56a58b5932 100644 --- a/src/modals/NominateFromFavorites/index.tsx +++ b/src/modals/NominateFromFavorites/index.tsx @@ -10,7 +10,6 @@ import { useEffect, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { useApi } from 'contexts/Api'; import { useBonded } from 'contexts/Bonded'; -import { useConnect } from 'contexts/Connect'; import { useActivePools } from 'contexts/Pools/ActivePools'; import type { Validator } from 'contexts/Validators/types'; import { Warning } from 'library/Form/Warning'; @@ -22,12 +21,13 @@ import { ValidatorList } from 'library/ValidatorList'; import { useTxMeta } from 'contexts/TxMeta'; import { useOverlay } from '@polkadot-cloud/react/hooks'; import { useFavoriteValidators } from 'contexts/Validators/FavoriteValidators'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; import { ListWrapper } from './Wrappers'; export const NominateFromFavorites = () => { const { t } = useTranslation('modals'); const { consts, api } = useApi(); - const { activeAccount } = useConnect(); + const { activeAccount } = useActiveAccounts(); const { notEnoughFunds } = useTxMeta(); const { getBondedAccount } = useBonded(); const { favoritesList } = useFavoriteValidators(); diff --git a/src/modals/NominatePool/index.tsx b/src/modals/NominatePool/index.tsx index 1c413caafe..a9d34a2bec 100644 --- a/src/modals/NominatePool/index.tsx +++ b/src/modals/NominatePool/index.tsx @@ -5,7 +5,6 @@ import { ActionItem, ModalPadding, ModalWarnings } from '@polkadot-cloud/react'; import { useEffect, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { useApi } from 'contexts/Api'; -import { useConnect } from 'contexts/Connect'; import { useActivePools } from 'contexts/Pools/ActivePools'; import { Warning } from 'library/Form/Warning'; import { useSignerWarnings } from 'library/Hooks/useSignerWarnings'; @@ -14,12 +13,13 @@ import { Close } from 'library/Modal/Close'; import { SubmitTx } from 'library/SubmitTx'; import { useTxMeta } from 'contexts/TxMeta'; import { useOverlay } from '@polkadot-cloud/react/hooks'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; export const NominatePool = () => { const { t } = useTranslation('modals'); const { api } = useApi(); const { setModalStatus, setModalResize } = useOverlay().modal; - const { activeAccount } = useConnect(); + const { activeAccount } = useActiveAccounts(); const { selectedActivePool, isOwner, isNominator, targets } = useActivePools(); const { getSignerWarnings } = useSignerWarnings(); diff --git a/src/modals/Unbond/index.tsx b/src/modals/Unbond/index.tsx index 8a83425c03..36d176fd1d 100644 --- a/src/modals/Unbond/index.tsx +++ b/src/modals/Unbond/index.tsx @@ -9,7 +9,6 @@ import { useEffect, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { useApi } from 'contexts/Api'; import { useBonded } from 'contexts/Bonded'; -import { useConnect } from 'contexts/Connect'; import { useActivePools } from 'contexts/Pools/ActivePools'; import { usePoolsConfig } from 'contexts/Pools/PoolsConfig'; import { useStaking } from 'contexts/Staking'; @@ -26,13 +25,14 @@ import { SubmitTx } from 'library/SubmitTx'; import { StaticNote } from 'modals/Utils/StaticNote'; import { useOverlay } from '@polkadot-cloud/react/hooks'; import { useNetwork } from 'contexts/Network'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; export const Unbond = () => { const { t } = useTranslation('modals'); const { txFees } = useTxMeta(); const { staking } = useStaking(); const { stats } = usePoolsConfig(); - const { activeAccount } = useConnect(); + const { activeAccount } = useActiveAccounts(); const { notEnoughFunds } = useTxMeta(); const { getBondedAccount } = useBonded(); const { api, consts } = useApi(); diff --git a/src/modals/UnbondPoolMember/index.tsx b/src/modals/UnbondPoolMember/index.tsx index 423896f3a9..6e8857ff72 100644 --- a/src/modals/UnbondPoolMember/index.tsx +++ b/src/modals/UnbondPoolMember/index.tsx @@ -13,7 +13,6 @@ import { getUnixTime } from 'date-fns'; import { useEffect, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { useApi } from 'contexts/Api'; -import { useConnect } from 'contexts/Connect'; import { Warning } from 'library/Form/Warning'; import { useErasToTimeLeft } from 'library/Hooks/useErasToTimeLeft'; import { useSignerWarnings } from 'library/Hooks/useSignerWarnings'; @@ -25,6 +24,7 @@ import { StaticNote } from 'modals/Utils/StaticNote'; import { useTxMeta } from 'contexts/TxMeta'; import { useOverlay } from '@polkadot-cloud/react/hooks'; import { useNetwork } from 'contexts/Network'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; export const UnbondPoolMember = () => { const { t } = useTranslation('modals'); @@ -32,7 +32,7 @@ export const UnbondPoolMember = () => { const { networkData: { units, unit }, } = useNetwork(); - const { activeAccount } = useConnect(); + const { activeAccount } = useActiveAccounts(); const { notEnoughFunds } = useTxMeta(); const { erasToSeconds } = useErasToTimeLeft(); const { getSignerWarnings } = useSignerWarnings(); diff --git a/src/modals/UnlockChunks/Chunk.tsx b/src/modals/UnlockChunks/Chunk.tsx index 0eaadf3b87..37a7472317 100644 --- a/src/modals/UnlockChunks/Chunk.tsx +++ b/src/modals/UnlockChunks/Chunk.tsx @@ -7,13 +7,13 @@ import BigNumber from 'bignumber.js'; import { fromUnixTime } from 'date-fns'; import { useEffect } from 'react'; import { useTranslation } from 'react-i18next'; -import { useConnect } from 'contexts/Connect'; import { useNetworkMetrics } from 'contexts/NetworkMetrics'; import { Countdown } from 'library/Countdown'; import { useErasToTimeLeft } from 'library/Hooks/useErasToTimeLeft'; import { useTimeLeft } from 'library/Hooks/useTimeLeft'; import { useUnstaking } from 'library/Hooks/useUnstaking'; import { useNetwork } from 'contexts/Network'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; import { ChunkWrapper } from './Wrappers'; export const Chunk = ({ chunk, bondFor, onRebond }: any) => { @@ -23,7 +23,7 @@ export const Chunk = ({ chunk, bondFor, onRebond }: any) => { networkData: { units, unit }, network, } = useNetwork(); - const { activeAccount } = useConnect(); + const { activeAccount } = useActiveAccounts(); const { activeEra } = useNetworkMetrics(); const { isFastUnstaking } = useUnstaking(); const { erasToSeconds } = useErasToTimeLeft(); diff --git a/src/modals/UnlockChunks/Forms.tsx b/src/modals/UnlockChunks/Forms.tsx index f7c755bc81..3224659ec4 100644 --- a/src/modals/UnlockChunks/Forms.tsx +++ b/src/modals/UnlockChunks/Forms.tsx @@ -13,7 +13,6 @@ import { forwardRef, useEffect, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { useApi } from 'contexts/Api'; import { useBonded } from 'contexts/Bonded'; -import { useConnect } from 'contexts/Connect'; import { useActivePools } from 'contexts/Pools/ActivePools'; import { useBondedPools } from 'contexts/Pools/BondedPools'; import { usePoolMembers } from 'contexts/Pools/PoolMembers'; @@ -25,6 +24,7 @@ import { useSubmitExtrinsic } from 'library/Hooks/useSubmitExtrinsic'; import { SubmitTx } from 'library/SubmitTx'; import { useOverlay } from '@polkadot-cloud/react/hooks'; import { useNetwork } from 'contexts/Network'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; import { ContentWrapper } from './Wrappers'; export const Forms = forwardRef( @@ -34,7 +34,7 @@ export const Forms = forwardRef( const { networkData: { units, unit }, } = useNetwork(); - const { activeAccount } = useConnect(); + const { activeAccount } = useActiveAccounts(); const { removeFavorite: removeFavoritePool } = usePoolsConfig(); const { membership } = usePoolMemberships(); const { selectedActivePool } = useActivePools(); diff --git a/src/modals/UnlockChunks/index.tsx b/src/modals/UnlockChunks/index.tsx index f604b92407..4ac2983b88 100644 --- a/src/modals/UnlockChunks/index.tsx +++ b/src/modals/UnlockChunks/index.tsx @@ -10,17 +10,17 @@ import { setStateWithRef } from '@polkadot-cloud/utils'; import { useEffect, useRef, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { useBalances } from 'contexts/Balances'; -import { useConnect } from 'contexts/Connect'; import { useActivePools } from 'contexts/Pools/ActivePools'; import { Title } from 'library/Modal/Title'; import { useTxMeta } from 'contexts/TxMeta'; import { useOverlay } from '@polkadot-cloud/react/hooks'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; import { Forms } from './Forms'; import { Overview } from './Overview'; export const UnlockChunks = () => { const { t } = useTranslation('modals'); - const { activeAccount } = useConnect(); + const { activeAccount } = useActiveAccounts(); const { notEnoughFunds } = useTxMeta(); const { getStashLedger } = useBalances(); const { diff --git a/src/modals/Unstake/index.tsx b/src/modals/Unstake/index.tsx index 0fde76d745..ac9a88ca2a 100644 --- a/src/modals/Unstake/index.tsx +++ b/src/modals/Unstake/index.tsx @@ -12,7 +12,6 @@ import { useEffect, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { useApi } from 'contexts/Api'; import { useBonded } from 'contexts/Bonded'; -import { useConnect } from 'contexts/Connect'; import { useTransferOptions } from 'contexts/TransferOptions'; import { Warning } from 'library/Form/Warning'; import { useBatchCall } from 'library/Hooks/useBatchCall'; @@ -26,12 +25,13 @@ import { StaticNote } from 'modals/Utils/StaticNote'; import { useTxMeta } from 'contexts/TxMeta'; import { useOverlay } from '@polkadot-cloud/react/hooks'; import { useNetwork } from 'contexts/Network'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; export const Unstake = () => { const { t } = useTranslation('modals'); const { newBatchCall } = useBatchCall(); const { notEnoughFunds } = useTxMeta(); - const { activeAccount } = useConnect(); + const { activeAccount } = useActiveAccounts(); const { api, consts } = useApi(); const { networkData: { units, unit }, diff --git a/src/modals/UpdateController/Switch/index.tsx b/src/modals/UpdateController/Switch/index.tsx index bd47fa00f6..fa9c33bde3 100644 --- a/src/modals/UpdateController/Switch/index.tsx +++ b/src/modals/UpdateController/Switch/index.tsx @@ -4,13 +4,13 @@ import { faAnglesRight } from '@fortawesome/free-solid-svg-icons'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { remToUnit } from '@polkadot-cloud/utils'; -import { useConnect } from 'contexts/Connect'; import { Polkicon } from '@polkadot-cloud/react'; +import { useImportedAccounts } from 'contexts/Connect/ImportedAccounts'; import type { AccountDropdownProps } from '../../../library/Form/types'; import { StyledSelect } from './Wrappers'; export const Switch = ({ current, to }: AccountDropdownProps) => { - const { getAccount } = useConnect(); + const { getAccount } = useImportedAccounts(); const toAccount = getAccount(to); return ( diff --git a/src/modals/UpdateController/index.tsx b/src/modals/UpdateController/index.tsx index 034eabc247..b4de652bed 100644 --- a/src/modals/UpdateController/index.tsx +++ b/src/modals/UpdateController/index.tsx @@ -5,7 +5,6 @@ import { ModalPadding, ModalWarnings } from '@polkadot-cloud/react'; import { useTranslation } from 'react-i18next'; import { useApi } from 'contexts/Api'; import { useBonded } from 'contexts/Bonded'; -import { useConnect } from 'contexts/Connect'; import { Warning } from 'library/Form/Warning'; import { useSignerWarnings } from 'library/Hooks/useSignerWarnings'; import { useSubmitExtrinsic } from 'library/Hooks/useSubmitExtrinsic'; @@ -14,6 +13,8 @@ import { SubmitTx } from 'library/SubmitTx'; import { useTxMeta } from 'contexts/TxMeta'; import { useEffect } from 'react'; import { useOverlay } from '@polkadot-cloud/react/hooks'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; +import { useImportedAccounts } from 'contexts/Connect/ImportedAccounts'; import { Switch } from './Switch'; import { Wrapper } from './Wrapper'; @@ -22,8 +23,9 @@ export const UpdateController = () => { const { api } = useApi(); const { notEnoughFunds } = useTxMeta(); const { getBondedAccount } = useBonded(); + const { activeAccount } = useActiveAccounts(); + const { getAccount } = useImportedAccounts(); const { getSignerWarnings } = useSignerWarnings(); - const { activeAccount, getAccount } = useConnect(); const { setModalStatus, setModalResize } = useOverlay().modal; const controller = getBondedAccount(activeAccount); diff --git a/src/modals/UpdatePayee/index.tsx b/src/modals/UpdatePayee/index.tsx index 78509e36c3..2b4865c34f 100644 --- a/src/modals/UpdatePayee/index.tsx +++ b/src/modals/UpdatePayee/index.tsx @@ -7,7 +7,6 @@ import { useEffect, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { useApi } from 'contexts/Api'; import { useBonded } from 'contexts/Bonded'; -import { useConnect } from 'contexts/Connect'; import type { PayeeConfig, PayeeOptions } from 'contexts/Setup/types'; import { useStaking } from 'contexts/Staking'; import { Warning } from 'library/Form/Warning'; @@ -19,15 +18,16 @@ import { PayeeInput } from 'library/PayeeInput'; import { SelectItems } from 'library/SelectItems'; import { SelectItem } from 'library/SelectItems/Item'; import { SubmitTx } from 'library/SubmitTx'; -import type { MaybeAccount } from 'types'; +import type { MaybeAddress } from 'types'; import { useTxMeta } from 'contexts/TxMeta'; import { useOverlay } from '@polkadot-cloud/react/hooks'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; export const UpdatePayee = () => { const { t } = useTranslation('modals'); const { api } = useApi(); const { staking } = useStaking(); - const { activeAccount } = useConnect(); + const { activeAccount } = useActiveAccounts(); const { notEnoughFunds } = useTxMeta(); const { getBondedAccount } = useBonded(); const { getPayeeItems } = usePayeeConfig(); @@ -43,7 +43,7 @@ export const UpdatePayee = () => { }; // Store the current user-inputted custom payout account. - const [account, setAccount] = useState(payee.account); + const [account, setAccount] = useState(payee.account); // Store the currently selected payee option. const [selected, setSelected]: any = useState(DefaultSelected); @@ -57,7 +57,7 @@ export const UpdatePayee = () => { }; // update setup progress with payee account. - const handleChangeAccount = (newAccount: MaybeAccount) => { + const handleChangeAccount = (newAccount: MaybeAddress) => { setSelected({ destination: selected?.destination ?? null, account: newAccount, diff --git a/src/modals/UpdateReserve/index.tsx b/src/modals/UpdateReserve/index.tsx index 72636ac633..07db63a5a5 100644 --- a/src/modals/UpdateReserve/index.tsx +++ b/src/modals/UpdateReserve/index.tsx @@ -13,7 +13,6 @@ import BigNumber from 'bignumber.js'; import Slider from 'rc-slider'; import { useState } from 'react'; import { useTranslation } from 'react-i18next'; -import { useConnect } from 'contexts/Connect'; import { useHelp } from 'contexts/Help'; import { useTransferOptions } from 'contexts/TransferOptions'; import { CardHeaderWrapper } from 'library/Card/Wrappers'; @@ -23,6 +22,8 @@ import { SliderWrapper } from 'modals/ManagePool/Wrappers'; import 'rc-slider/assets/index.css'; import { useOverlay } from '@polkadot-cloud/react/hooks'; import { useNetwork } from 'contexts/Network'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; +import { useImportedAccounts } from 'contexts/Connect/ImportedAccounts'; export const UpdateReserve = () => { const { t } = useTranslation('modals'); @@ -32,7 +33,8 @@ export const UpdateReserve = () => { } = useNetwork(); const { openHelp } = useHelp(); const { setModalStatus } = useOverlay().modal; - const { activeAccount, accountHasSigner } = useConnect(); + const { activeAccount } = useActiveAccounts(); + const { accountHasSigner } = useImportedAccounts(); const { feeReserve, setFeeReserveBalance, getTransferOptions } = useTransferOptions(); diff --git a/src/modals/WithdrawPoolMember/index.tsx b/src/modals/WithdrawPoolMember/index.tsx index aa5c9a30ad..14d3bf7b0c 100644 --- a/src/modals/WithdrawPoolMember/index.tsx +++ b/src/modals/WithdrawPoolMember/index.tsx @@ -7,7 +7,6 @@ import BigNumber from 'bignumber.js'; import { useEffect, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { useApi } from 'contexts/Api'; -import { useConnect } from 'contexts/Connect'; import { useNetworkMetrics } from 'contexts/NetworkMetrics'; import { usePoolMembers } from 'contexts/Pools/PoolMembers'; import { Warning } from 'library/Form/Warning'; @@ -18,6 +17,7 @@ import { SubmitTx } from 'library/SubmitTx'; import { useTxMeta } from 'contexts/TxMeta'; import { useOverlay } from '@polkadot-cloud/react/hooks'; import { useNetwork } from 'contexts/Network'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; export const WithdrawPoolMember = () => { const { t } = useTranslation('modals'); @@ -25,7 +25,7 @@ export const WithdrawPoolMember = () => { const { networkData: { units, unit }, } = useNetwork(); - const { activeAccount } = useConnect(); + const { activeAccount } = useActiveAccounts(); const { setModalStatus, config: { options }, diff --git a/src/pages/Nominate/Active/ControllerNotStash.tsx b/src/pages/Nominate/Active/ControllerNotStash.tsx index 4a800dcb79..a370034c77 100644 --- a/src/pages/Nominate/Active/ControllerNotStash.tsx +++ b/src/pages/Nominate/Active/ControllerNotStash.tsx @@ -11,21 +11,23 @@ import { ButtonPrimary, PageRow } from '@polkadot-cloud/react'; import { useEffect, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { useBonded } from 'contexts/Bonded'; -import { useConnect } from 'contexts/Connect'; import { useStaking } from 'contexts/Staking'; import { useUi } from 'contexts/UI'; import { CardHeaderWrapper, CardWrapper } from 'library/Card/Wrappers'; import { useOverlay } from '@polkadot-cloud/react/hooks'; import { useNetwork } from 'contexts/Network'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; +import { useImportedAccounts } from 'contexts/Connect/ImportedAccounts'; export const ControllerNotStash = () => { const { t } = useTranslation('pages'); const { network } = useNetwork(); - const { activeAccount, isReadOnlyAccount } = useConnect(); + const { activeAccount } = useActiveAccounts(); const { addressDifferentToStash } = useStaking(); const { getBondedAccount } = useBonded(); const { openModal } = useOverlay().modal; const { isSyncing } = useUi(); + const { isReadOnlyAccount } = useImportedAccounts(); const controller = getBondedAccount(activeAccount); const [showPrompt, setShowPrompt] = useState( diff --git a/src/pages/Nominate/Active/ManageBond.tsx b/src/pages/Nominate/Active/ManageBond.tsx index f7af327253..1f79636b38 100644 --- a/src/pages/Nominate/Active/ManageBond.tsx +++ b/src/pages/Nominate/Active/ManageBond.tsx @@ -12,7 +12,6 @@ import { minDecimalPlaces, planckToUnit } from '@polkadot-cloud/utils'; import type BigNumber from 'bignumber.js'; import { useTranslation } from 'react-i18next'; import { useBalances } from 'contexts/Balances'; -import { useConnect } from 'contexts/Connect'; import { useHelp } from 'contexts/Help'; import { useStaking } from 'contexts/Staking'; import { useTransferOptions } from 'contexts/TransferOptions'; @@ -22,6 +21,8 @@ import { useUnstaking } from 'library/Hooks/useUnstaking'; import { useOverlay } from '@polkadot-cloud/react/hooks'; import { BondedChart } from 'library/BarChart/BondedChart'; import { useNetwork } from 'contexts/Network'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; +import { useImportedAccounts } from 'contexts/Connect/ImportedAccounts'; export const ManageBond = () => { const { t } = useTranslation('pages'); @@ -37,8 +38,9 @@ export const ManageBond = () => { const { openModal } = useOverlay().modal; const { getStashLedger } = useBalances(); const { isFastUnstaking } = useUnstaking(); + const { isReadOnlyAccount } = useImportedAccounts(); const { getTransferOptions } = useTransferOptions(); - const { activeAccount, isReadOnlyAccount } = useConnect(); + const { activeAccount } = useActiveAccounts(); const ledger = getStashLedger(activeAccount); const { active }: { active: BigNumber } = ledger; const allTransferOptions = getTransferOptions(activeAccount); diff --git a/src/pages/Nominate/Active/Nominations/index.tsx b/src/pages/Nominate/Active/Nominations/index.tsx index 04bc272d93..a08ce9b89f 100644 --- a/src/pages/Nominate/Active/Nominations/index.tsx +++ b/src/pages/Nominate/Active/Nominations/index.tsx @@ -5,7 +5,6 @@ import { faStopCircle } from '@fortawesome/free-solid-svg-icons'; import { ButtonHelp, ButtonPrimary } from '@polkadot-cloud/react'; import { useTranslation } from 'react-i18next'; import { useBonded } from 'contexts/Bonded'; -import { useConnect } from 'contexts/Connect'; import { useHelp } from 'contexts/Help'; import { useActivePools } from 'contexts/Pools/ActivePools'; import { useStaking } from 'contexts/Staking'; @@ -14,9 +13,11 @@ import { useValidators } from 'contexts/Validators/ValidatorEntries'; import { CardHeaderWrapper } from 'library/Card/Wrappers'; import { useUnstaking } from 'library/Hooks/useUnstaking'; import { ValidatorList } from 'library/ValidatorList'; -import type { MaybeAccount } from 'types'; +import type { MaybeAddress } from 'types'; import { useOverlay } from '@polkadot-cloud/react/hooks'; import { useFavoriteValidators } from 'contexts/Validators/FavoriteValidators'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; +import { useImportedAccounts } from 'contexts/Connect/ImportedAccounts'; import { Wrapper } from './Wrapper'; export const Nominations = ({ @@ -24,7 +25,7 @@ export const Nominations = ({ nominator, }: { bondFor: 'pool' | 'nominator'; - nominator: MaybeAccount; + nominator: MaybeAddress; }) => { const { t } = useTranslation('pages'); const { isSyncing } = useUi(); @@ -34,7 +35,8 @@ export const Nominations = ({ const { isFastUnstaking } = useUnstaking(); const { getAccountNominations } = useBonded(); const { favoritesList } = useFavoriteValidators(); - const { activeAccount, isReadOnlyAccount } = useConnect(); + const { isReadOnlyAccount } = useImportedAccounts(); + const { activeAccount } = useActiveAccounts(); const { nominated: stakeNominated, poolNominated } = useValidators(); const { diff --git a/src/pages/Nominate/Active/Status/NominationStatus.tsx b/src/pages/Nominate/Active/Status/NominationStatus.tsx index f42a0746df..1a2bf33222 100644 --- a/src/pages/Nominate/Active/Status/NominationStatus.tsx +++ b/src/pages/Nominate/Active/Status/NominationStatus.tsx @@ -9,7 +9,6 @@ import { import { useTranslation } from 'react-i18next'; import { useApi } from 'contexts/Api'; import { useBonded } from 'contexts/Bonded'; -import { useConnect } from 'contexts/Connect'; import { useFastUnstake } from 'contexts/FastUnstake'; import { useNetworkMetrics } from 'contexts/NetworkMetrics'; import { useSetup } from 'contexts/Setup'; @@ -19,6 +18,8 @@ import { useNominationStatus } from 'library/Hooks/useNominationStatus'; import { useUnstaking } from 'library/Hooks/useUnstaking'; import { Stat } from 'library/Stat'; import { useOverlay } from '@polkadot-cloud/react/hooks'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; +import { useImportedAccounts } from 'contexts/Connect/ImportedAccounts'; export const NominationStatus = ({ showButtons = true, @@ -35,8 +36,9 @@ export const NominationStatus = ({ const { metrics } = useNetworkMetrics(); const { getBondedAccount } = useBonded(); const { checking, isExposed } = useFastUnstake(); + const { isReadOnlyAccount } = useImportedAccounts(); const { getNominationStatus } = useNominationStatus(); - const { activeAccount, isReadOnlyAccount } = useConnect(); + const { activeAccount } = useActiveAccounts(); const { getFastUnstakeText, isUnstaking } = useUnstaking(); const { setOnNominatorSetup, getNominatorSetupPercent } = useSetup(); diff --git a/src/pages/Nominate/Active/Status/PayoutDestinationStatus.tsx b/src/pages/Nominate/Active/Status/PayoutDestinationStatus.tsx index 723ffc50f8..fa7ca94ddb 100644 --- a/src/pages/Nominate/Active/Status/PayoutDestinationStatus.tsx +++ b/src/pages/Nominate/Active/Status/PayoutDestinationStatus.tsx @@ -3,13 +3,14 @@ import { faGear, faWallet } from '@fortawesome/free-solid-svg-icons'; import { useTranslation } from 'react-i18next'; -import { useConnect } from 'contexts/Connect'; import { useStaking } from 'contexts/Staking'; import { useUi } from 'contexts/UI'; import { usePayeeConfig } from 'library/Hooks/usePayeeConfig'; import { useUnstaking } from 'library/Hooks/useUnstaking'; import { Stat } from 'library/Stat'; import { useOverlay } from '@polkadot-cloud/react/hooks'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; +import { useImportedAccounts } from 'contexts/Connect/ImportedAccounts'; export const PayoutDestinationStatus = () => { const { t } = useTranslation('pages'); @@ -18,7 +19,8 @@ export const PayoutDestinationStatus = () => { const { staking, inSetup } = useStaking(); const { isFastUnstaking } = useUnstaking(); const { getPayeeItems } = usePayeeConfig(); - const { activeAccount, isReadOnlyAccount } = useConnect(); + const { activeAccount } = useActiveAccounts(); + const { isReadOnlyAccount } = useImportedAccounts(); const { payee } = staking; // Get payee status text to display. diff --git a/src/pages/Nominate/Active/Status/UnclaimedPayoutsStatus.tsx b/src/pages/Nominate/Active/Status/UnclaimedPayoutsStatus.tsx index d292a94143..8fc09bd1e8 100644 --- a/src/pages/Nominate/Active/Status/UnclaimedPayoutsStatus.tsx +++ b/src/pages/Nominate/Active/Status/UnclaimedPayoutsStatus.tsx @@ -8,9 +8,10 @@ import BigNumber from 'bignumber.js'; import { useApi } from 'contexts/Api'; import { minDecimalPlaces, planckToUnit } from '@polkadot-cloud/utils'; import { faCircleDown } from '@fortawesome/free-solid-svg-icons'; -import { useConnect } from 'contexts/Connect'; import { useOverlay } from '@polkadot-cloud/react/hooks'; import { useNetwork } from 'contexts/Network'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; +import { useImportedAccounts } from 'contexts/Connect/ImportedAccounts'; export const UnclaimedPayoutsStatus = () => { const { t } = useTranslation(); @@ -20,7 +21,8 @@ export const UnclaimedPayoutsStatus = () => { } = useNetwork(); const { openModal } = useOverlay().modal; const { unclaimedPayouts } = usePayouts(); - const { activeAccount, isReadOnlyAccount } = useConnect(); + const { activeAccount } = useActiveAccounts(); + const { isReadOnlyAccount } = useImportedAccounts(); const totalUnclaimed = Object.values(unclaimedPayouts || {}).reduce( (total, validators) => diff --git a/src/pages/Nominate/Active/UnstakePrompts.tsx b/src/pages/Nominate/Active/UnstakePrompts.tsx index 585e7b2f2a..8cf09fc07c 100644 --- a/src/pages/Nominate/Active/UnstakePrompts.tsx +++ b/src/pages/Nominate/Active/UnstakePrompts.tsx @@ -5,7 +5,6 @@ import { faBolt, faLockOpen } from '@fortawesome/free-solid-svg-icons'; import { ButtonPrimary, ButtonRow, PageRow } from '@polkadot-cloud/react'; import { isNotZero } from '@polkadot-cloud/utils'; import { useTranslation } from 'react-i18next'; -import { useConnect } from 'contexts/Connect'; import { useTheme } from 'contexts/Themes'; import { useTransferOptions } from 'contexts/TransferOptions'; import { useUi } from 'contexts/UI'; @@ -13,11 +12,12 @@ import { CardWrapper } from 'library/Card/Wrappers'; import { useUnstaking } from 'library/Hooks/useUnstaking'; import { useOverlay } from '@polkadot-cloud/react/hooks'; import { useNetwork } from 'contexts/Network'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; export const UnstakePrompts = () => { const { t } = useTranslation('pages'); const { unit, colors } = useNetwork().networkData; - const { activeAccount } = useConnect(); + const { activeAccount } = useActiveAccounts(); const { mode } = useTheme(); const { openModal } = useOverlay().modal; const { isNetworkSyncing } = useUi(); diff --git a/src/pages/Nominate/Active/index.tsx b/src/pages/Nominate/Active/index.tsx index 337f93ee24..9647029ffb 100644 --- a/src/pages/Nominate/Active/index.tsx +++ b/src/pages/Nominate/Active/index.tsx @@ -11,7 +11,6 @@ import { } from '@polkadot-cloud/react'; import { useTranslation } from 'react-i18next'; import { useBonded } from 'contexts/Bonded'; -import { useConnect } from 'contexts/Connect'; import { useHelp } from 'contexts/Help'; import { useStaking } from 'contexts/Staking'; import { useUi } from 'contexts/UI'; @@ -20,6 +19,7 @@ import { GenerateNominations } from 'library/GenerateNominations'; import { useUnstaking } from 'library/Hooks/useUnstaking'; import { StatBoxList } from 'library/StatBoxList'; import { useOverlay } from '@polkadot-cloud/react/hooks'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; import { ControllerNotStash } from './ControllerNotStash'; import { ManageBond } from './ManageBond'; import { Nominations } from './Nominations'; @@ -31,9 +31,9 @@ import { UnstakePrompts } from './UnstakePrompts'; export const Active = () => { const { t } = useTranslation('pages'); - const { openModal } = useOverlay().modal; - const { activeAccount } = useConnect(); const { isSyncing } = useUi(); + const { openModal } = useOverlay().modal; + const { activeAccount } = useActiveAccounts(); const { targets, setTargets, inSetup } = useStaking(); const { getAccountNominations } = useBonded(); const { isFastUnstaking } = useUnstaking(); diff --git a/src/pages/Nominate/Setup/Bond/index.tsx b/src/pages/Nominate/Setup/Bond/index.tsx index 10c344e844..2b842645ac 100644 --- a/src/pages/Nominate/Setup/Bond/index.tsx +++ b/src/pages/Nominate/Setup/Bond/index.tsx @@ -4,7 +4,6 @@ import BigNumber from 'bignumber.js'; import { useEffect, useState } from 'react'; import { useTranslation } from 'react-i18next'; -import { useConnect } from 'contexts/Connect'; import { useSetup } from 'contexts/Setup'; import { useTxMeta } from 'contexts/TxMeta'; import { BondFeedback } from 'library/Form/Bond/BondFeedback'; @@ -13,10 +12,11 @@ import { Footer } from 'library/SetupSteps/Footer'; import { Header } from 'library/SetupSteps/Header'; import { MotionContainer } from 'library/SetupSteps/MotionContainer'; import type { SetupStepProps } from 'library/SetupSteps/types'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; export const Bond = ({ section }: SetupStepProps) => { const { t } = useTranslation('pages'); - const { activeAccount } = useConnect(); + const { activeAccount } = useActiveAccounts(); const { txFees } = useTxMeta(); const { getSetupProgress, setActiveAccountSetup } = useSetup(); const setup = getSetupProgress('nominator', activeAccount); diff --git a/src/pages/Nominate/Setup/Payee/index.tsx b/src/pages/Nominate/Setup/Payee/index.tsx index 24ef2f0f36..4766695f5d 100644 --- a/src/pages/Nominate/Setup/Payee/index.tsx +++ b/src/pages/Nominate/Setup/Payee/index.tsx @@ -3,7 +3,6 @@ import { useEffect, useState } from 'react'; import { useTranslation } from 'react-i18next'; -import { useConnect } from 'contexts/Connect'; import { useSetup } from 'contexts/Setup'; import type { PayeeConfig, PayeeOptions } from 'contexts/Setup/types'; import { Spacer } from 'library/Form/Wrappers'; @@ -15,12 +14,13 @@ import { Footer } from 'library/SetupSteps/Footer'; import { Header } from 'library/SetupSteps/Header'; import { MotionContainer } from 'library/SetupSteps/MotionContainer'; import type { SetupStepProps } from 'library/SetupSteps/types'; -import type { MaybeAccount } from 'types'; +import type { MaybeAddress } from 'types'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; export const Payee = ({ section }: SetupStepProps) => { const { t } = useTranslation('pages'); const { getPayeeItems } = usePayeeConfig(); - const { activeAccount } = useConnect(); + const { activeAccount } = useActiveAccounts(); const { getSetupProgress, setActiveAccountSetup } = useSetup(); const setup = getSetupProgress('nominator', activeAccount); @@ -28,7 +28,7 @@ export const Payee = ({ section }: SetupStepProps) => { const { payee } = progress; // Store the current user-inputted custom payout account. - const [account, setAccount] = useState(payee.account); + const [account, setAccount] = useState(payee.account); const DefaultPayeeConfig: PayeeConfig = { destination: 'Staked', @@ -50,7 +50,7 @@ export const Payee = ({ section }: SetupStepProps) => { }; // update setup progress with payee account. - const handleChangeAccount = (newAccount: MaybeAccount) => { + const handleChangeAccount = (newAccount: MaybeAddress) => { // set local value to update input element set setup payee setActiveAccountSetup('nominator', { ...progress, diff --git a/src/pages/Nominate/Setup/Summary/index.tsx b/src/pages/Nominate/Setup/Summary/index.tsx index 449bc05dff..51d8ae5971 100644 --- a/src/pages/Nominate/Setup/Summary/index.tsx +++ b/src/pages/Nominate/Setup/Summary/index.tsx @@ -6,7 +6,6 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { ellipsisFn, unitToPlanck } from '@polkadot-cloud/utils'; import BigNumber from 'bignumber.js'; import { useTranslation } from 'react-i18next'; -import { useConnect } from 'contexts/Connect'; import { useSetup } from 'contexts/Setup'; import { Warning } from 'library/Form/Warning'; import { useBatchCall } from 'library/Hooks/useBatchCall'; @@ -18,6 +17,8 @@ import type { SetupStepProps } from 'library/SetupSteps/types'; import { SubmitTx } from 'library/SubmitTx'; import { useNetwork } from 'contexts/Network'; import { useApi } from 'contexts/Api'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; +import { useImportedAccounts } from 'contexts/Connect/ImportedAccounts'; import { SummaryWrapper } from './Wrapper'; export const Summary = ({ section }: SetupStepProps) => { @@ -28,8 +29,9 @@ export const Summary = ({ section }: SetupStepProps) => { } = useNetwork(); const { newBatchCall } = useBatchCall(); const { getPayeeItems } = usePayeeConfig(); + const { accountHasSigner } = useImportedAccounts(); + const { activeAccount, activeProxy } = useActiveAccounts(); const { getSetupProgress, removeSetupProgress } = useSetup(); - const { activeAccount, activeProxy, accountHasSigner } = useConnect(); const setup = getSetupProgress('nominator', activeAccount); const { progress } = setup; diff --git a/src/pages/Nominate/Setup/index.tsx b/src/pages/Nominate/Setup/index.tsx index 8fa04d36f8..6d89180c27 100644 --- a/src/pages/Nominate/Setup/index.tsx +++ b/src/pages/Nominate/Setup/index.tsx @@ -12,10 +12,10 @@ import { extractUrlValue, removeVarFromUrlHash } from '@polkadot-cloud/utils'; import { useTranslation } from 'react-i18next'; import { useNavigate } from 'react-router-dom'; import { Element } from 'react-scroll'; -import { useConnect } from 'contexts/Connect'; import { useSetup } from 'contexts/Setup'; import { CardWrapper } from 'library/Card/Wrappers'; import { Nominate } from 'library/SetupSteps/Nominate'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; import { Bond } from './Bond'; import { Payee } from './Payee'; import { Summary } from './Summary'; @@ -23,7 +23,7 @@ import { Summary } from './Summary'; export const Setup = () => { const { t } = useTranslation('pages'); const navigate = useNavigate(); - const { activeAccount } = useConnect(); + const { activeAccount } = useActiveAccounts(); const { setOnNominatorSetup, removeSetupProgress } = useSetup(); return ( diff --git a/src/pages/Overview/ActiveAccounts/Item.tsx b/src/pages/Overview/ActiveAccounts/Item.tsx index e212fdb9de..849f220a2f 100644 --- a/src/pages/Overview/ActiveAccounts/Item.tsx +++ b/src/pages/Overview/ActiveAccounts/Item.tsx @@ -6,18 +6,18 @@ import { faArrowLeft } from '@fortawesome/free-solid-svg-icons'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { ellipsisFn, remToUnit } from '@polkadot-cloud/utils'; import { useTranslation } from 'react-i18next'; -import { useConnect } from 'contexts/Connect'; import { useNotifications } from 'contexts/Notifications'; import type { NotificationText } from 'contexts/Notifications/types'; import { useProxies } from 'contexts/Proxies'; import { Polkicon } from '@polkadot-cloud/react'; +import { useImportedAccounts } from 'contexts/Connect/ImportedAccounts'; import { ItemWrapper } from './Wrappers'; import type { ActiveAccountProps } from './types'; export const Item = ({ address, delegate = null }: ActiveAccountProps) => { const { t } = useTranslation('pages'); - const { getAccount } = useConnect(); const { getProxyDelegate } = useProxies(); + const { getAccount } = useImportedAccounts(); const { addNotification } = useNotifications(); const primaryAddress = delegate || address || ''; diff --git a/src/pages/Overview/ActiveAccounts/index.tsx b/src/pages/Overview/ActiveAccounts/index.tsx index 8ffcf6eb2a..323ae101e2 100644 --- a/src/pages/Overview/ActiveAccounts/index.tsx +++ b/src/pages/Overview/ActiveAccounts/index.tsx @@ -1,12 +1,12 @@ // Copyright 2023 @paritytech/polkadot-staking-dashboard authors & contributors // SPDX-License-Identifier: GPL-3.0-only -import { useConnect } from 'contexts/Connect'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; import { Item } from './Item'; import { ActiveAccounsWrapper } from './Wrappers'; export const ActiveAccounts = () => { - const { activeAccount, activeProxy } = useConnect(); + const { activeProxy, activeAccount } = useActiveAccounts(); return ( diff --git a/src/pages/Overview/ActiveAccounts/types.ts b/src/pages/Overview/ActiveAccounts/types.ts index 50b34510ae..e94406ab44 100644 --- a/src/pages/Overview/ActiveAccounts/types.ts +++ b/src/pages/Overview/ActiveAccounts/types.ts @@ -1,9 +1,9 @@ // Copyright 2023 @paritytech/polkadot-staking-dashboard authors & contributors // SPDX-License-Identifier: GPL-3.0-only -import type { MaybeAccount } from 'types'; +import type { MaybeAddress } from 'types'; export interface ActiveAccountProps { - address: MaybeAccount; - delegate?: MaybeAccount; + address: MaybeAddress; + delegate?: MaybeAddress; } diff --git a/src/pages/Overview/BalanceChart.tsx b/src/pages/Overview/BalanceChart.tsx index 17e7952b33..0673f7bed6 100644 --- a/src/pages/Overview/BalanceChart.tsx +++ b/src/pages/Overview/BalanceChart.tsx @@ -11,7 +11,6 @@ import { import BigNumber from 'bignumber.js'; import { useTranslation } from 'react-i18next'; import { useBalances } from 'contexts/Balances'; -import { useConnect } from 'contexts/Connect'; import { usePlugins } from 'contexts/Plugins'; import { useTransferOptions } from 'contexts/TransferOptions'; import { useUi } from 'contexts/UI'; @@ -22,6 +21,8 @@ import { CardHeaderWrapper } from 'library/Card/Wrappers'; import { usePrices } from 'library/Hooks/usePrices'; import { useOverlay } from '@polkadot-cloud/react/hooks'; import { useNetwork } from 'contexts/Network'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; +import { useImportedAccounts } from 'contexts/Connect/ImportedAccounts'; export const BalanceChart = () => { const { t } = useTranslation('pages'); @@ -37,7 +38,8 @@ export const BalanceChart = () => { const { isNetworkSyncing } = useUi(); const { openModal } = useOverlay().modal; const { getBalance, getLocks } = useBalances(); - const { activeAccount, accountHasSigner } = useConnect(); + const { activeAccount } = useActiveAccounts(); + const { accountHasSigner } = useImportedAccounts(); const { feeReserve, getTransferOptions } = useTransferOptions(); const balance = getBalance(activeAccount); const allTransferOptions = getTransferOptions(activeAccount); diff --git a/src/pages/Overview/BalanceLinks.tsx b/src/pages/Overview/BalanceLinks.tsx index 4203ad3321..1c62984495 100644 --- a/src/pages/Overview/BalanceLinks.tsx +++ b/src/pages/Overview/BalanceLinks.tsx @@ -4,14 +4,14 @@ import { faExternalLinkAlt } from '@fortawesome/free-solid-svg-icons'; import { ButtonPrimaryInvert, Separator } from '@polkadot-cloud/react'; import { useTranslation } from 'react-i18next'; -import { useConnect } from 'contexts/Connect'; import { useNetwork } from 'contexts/Network'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; import { MoreWrapper } from './Wrappers'; export const BalanceLinks = () => { const { network } = useNetwork(); const { t } = useTranslation('pages'); - const { activeAccount } = useConnect(); + const { activeAccount } = useActiveAccounts(); return ( diff --git a/src/pages/Overview/StakeStatus/Tips/index.tsx b/src/pages/Overview/StakeStatus/Tips/index.tsx index 89b1cb1446..0055ecda0d 100644 --- a/src/pages/Overview/StakeStatus/Tips/index.tsx +++ b/src/pages/Overview/StakeStatus/Tips/index.tsx @@ -7,7 +7,6 @@ import { useEffect, useRef, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { TipsConfig } from 'config/tips'; import { DefaultLocale, TipsThresholdMedium, TipsThresholdSmall } from 'consts'; -import { useConnect } from 'contexts/Connect'; import { useActivePools } from 'contexts/Pools/ActivePools'; import { usePoolMemberships } from 'contexts/Pools/PoolMemberships'; import { useStaking } from 'contexts/Staking'; @@ -16,6 +15,7 @@ import { useUi } from 'contexts/UI'; import { useFillVariables } from 'library/Hooks/useFillVariables'; import type { AnyJson } from 'types'; import { useNetwork } from 'contexts/Network'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; import { Items } from './Items'; import { PageToggle } from './PageToggle'; import { Syncing } from './Syncing'; @@ -24,8 +24,8 @@ import { TipsWrapper } from './Wrappers'; export const Tips = () => { const { i18n, t } = useTranslation(); const { network } = useNetwork(); - const { activeAccount } = useConnect(); const { isNetworkSyncing } = useUi(); + const { activeAccount } = useActiveAccounts(); const { fillVariables } = useFillVariables(); const { membership } = usePoolMemberships(); const { isNominating, staking } = useStaking(); diff --git a/src/pages/Pools/Create/Bond/index.tsx b/src/pages/Pools/Create/Bond/index.tsx index 8fa9df36a1..d912d4d0e6 100644 --- a/src/pages/Pools/Create/Bond/index.tsx +++ b/src/pages/Pools/Create/Bond/index.tsx @@ -4,7 +4,6 @@ import BigNumber from 'bignumber.js'; import { useEffect, useState } from 'react'; import { useTranslation } from 'react-i18next'; -import { useConnect } from 'contexts/Connect'; import { useSetup } from 'contexts/Setup'; import { useTxMeta } from 'contexts/TxMeta'; import { BondFeedback } from 'library/Form/Bond/BondFeedback'; @@ -13,10 +12,11 @@ import { Footer } from 'library/SetupSteps/Footer'; import { Header } from 'library/SetupSteps/Header'; import { MotionContainer } from 'library/SetupSteps/MotionContainer'; import type { SetupStepProps } from 'library/SetupSteps/types'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; export const Bond = ({ section }: SetupStepProps) => { const { t } = useTranslation('pages'); - const { activeAccount } = useConnect(); + const { activeAccount } = useActiveAccounts(); const { txFees } = useTxMeta(); const { getSetupProgress, setActiveAccountSetup } = useSetup(); const setup = getSetupProgress('pool', activeAccount); diff --git a/src/pages/Pools/Create/PoolName/Input.tsx b/src/pages/Pools/Create/PoolName/Input.tsx index d0e8f452c2..4ea4150e11 100644 --- a/src/pages/Pools/Create/PoolName/Input.tsx +++ b/src/pages/Pools/Create/PoolName/Input.tsx @@ -3,7 +3,7 @@ import React, { useEffect, useState } from 'react'; import { useTranslation } from 'react-i18next'; -import { useConnect } from 'contexts/Connect'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; export const Input = ({ listenIsValid, @@ -12,7 +12,7 @@ export const Input = ({ value = 0, }: any) => { const { t } = useTranslation('pages'); - const { activeAccount } = useConnect(); + const { activeAccount } = useActiveAccounts(); // the current local bond value const [metadata, setMetadata] = useState(value); diff --git a/src/pages/Pools/Create/PoolName/index.tsx b/src/pages/Pools/Create/PoolName/index.tsx index 2db9aeb76b..6d29c7fc32 100644 --- a/src/pages/Pools/Create/PoolName/index.tsx +++ b/src/pages/Pools/Create/PoolName/index.tsx @@ -3,17 +3,17 @@ import { useEffect, useState } from 'react'; import { useTranslation } from 'react-i18next'; -import { useConnect } from 'contexts/Connect'; import { useSetup } from 'contexts/Setup'; import { Footer } from 'library/SetupSteps/Footer'; import { Header } from 'library/SetupSteps/Header'; import { MotionContainer } from 'library/SetupSteps/MotionContainer'; import type { SetupStepProps } from 'library/SetupSteps/types'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; import { Input } from './Input'; export const PoolName = ({ section }: SetupStepProps) => { const { t } = useTranslation('pages'); - const { activeAccount } = useConnect(); + const { activeAccount } = useActiveAccounts(); const { getSetupProgress, setActiveAccountSetup } = useSetup(); const setup = getSetupProgress('pool', activeAccount); const { progress } = setup; diff --git a/src/pages/Pools/Create/PoolRoles/index.tsx b/src/pages/Pools/Create/PoolRoles/index.tsx index 47aa431d20..1f3cb57167 100644 --- a/src/pages/Pools/Create/PoolRoles/index.tsx +++ b/src/pages/Pools/Create/PoolRoles/index.tsx @@ -3,17 +3,17 @@ import { useEffect, useState } from 'react'; import { Trans, useTranslation } from 'react-i18next'; -import { useConnect } from 'contexts/Connect'; import { useSetup } from 'contexts/Setup'; import { Footer } from 'library/SetupSteps/Footer'; import { Header } from 'library/SetupSteps/Header'; import { MotionContainer } from 'library/SetupSteps/MotionContainer'; import type { SetupStepProps } from 'library/SetupSteps/types'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; import { Roles } from '../../Roles'; export const PoolRoles = ({ section }: SetupStepProps) => { const { t } = useTranslation('pages'); - const { activeAccount } = useConnect(); + const { activeAccount } = useActiveAccounts(); const { getSetupProgress, setActiveAccountSetup } = useSetup(); const setup = getSetupProgress('pool', activeAccount); const { progress } = setup; diff --git a/src/pages/Pools/Create/Summary/index.tsx b/src/pages/Pools/Create/Summary/index.tsx index fb02025979..2f8c924730 100644 --- a/src/pages/Pools/Create/Summary/index.tsx +++ b/src/pages/Pools/Create/Summary/index.tsx @@ -6,7 +6,6 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { unitToPlanck } from '@polkadot-cloud/utils'; import BigNumber from 'bignumber.js'; import { useTranslation } from 'react-i18next'; -import { useConnect } from 'contexts/Connect'; import { useBondedPools } from 'contexts/Pools/BondedPools'; import { usePoolMembers } from 'contexts/Pools/PoolMembers'; import { usePoolsConfig } from 'contexts/Pools/PoolsConfig'; @@ -20,6 +19,8 @@ import type { SetupStepProps } from 'library/SetupSteps/types'; import { SubmitTx } from 'library/SubmitTx'; import { useNetwork } from 'contexts/Network'; import { useApi } from 'contexts/Api'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; +import { useImportedAccounts } from 'contexts/Connect/ImportedAccounts'; import { SummaryWrapper } from './Wrapper'; export const Summary = ({ section }: SetupStepProps) => { @@ -30,10 +31,11 @@ export const Summary = ({ section }: SetupStepProps) => { } = useNetwork(); const { stats } = usePoolsConfig(); const { newBatchCall } = useBatchCall(); + const { accountHasSigner } = useImportedAccounts(); const { getSetupProgress, removeSetupProgress } = useSetup(); const { queryPoolMember, addToPoolMembers } = usePoolMembers(); const { queryBondedPool, addToBondedPools } = useBondedPools(); - const { activeAccount, activeProxy, accountHasSigner } = useConnect(); + const { activeAccount, activeProxy } = useActiveAccounts(); const { lastPoolId } = stats; const poolId = lastPoolId.plus(1); diff --git a/src/pages/Pools/Create/index.tsx b/src/pages/Pools/Create/index.tsx index b6d85e3c7a..cd10aa7300 100644 --- a/src/pages/Pools/Create/index.tsx +++ b/src/pages/Pools/Create/index.tsx @@ -10,10 +10,10 @@ import { } from '@polkadot-cloud/react'; import { useTranslation } from 'react-i18next'; import { Element } from 'react-scroll'; -import { useConnect } from 'contexts/Connect'; import { useSetup } from 'contexts/Setup'; import { CardWrapper } from 'library/Card/Wrappers'; import { Nominate } from 'library/SetupSteps/Nominate'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; import { Bond } from './Bond'; import { PoolName } from './PoolName'; import { PoolRoles } from './PoolRoles'; @@ -21,7 +21,7 @@ import { Summary } from './Summary'; export const Create = () => { const { t } = useTranslation('pages'); - const { activeAccount } = useConnect(); + const { activeAccount } = useActiveAccounts(); const { setOnPoolSetup, removeSetupProgress } = useSetup(); return ( diff --git a/src/pages/Pools/Home/ClosurePrompts.tsx b/src/pages/Pools/Home/ClosurePrompts.tsx index 408516c396..f8b4e92e4b 100644 --- a/src/pages/Pools/Home/ClosurePrompts.tsx +++ b/src/pages/Pools/Home/ClosurePrompts.tsx @@ -4,7 +4,6 @@ import { faLockOpen } from '@fortawesome/free-solid-svg-icons'; import { ButtonPrimary, ButtonRow, PageRow } from '@polkadot-cloud/react'; import { useTranslation } from 'react-i18next'; -import { useConnect } from 'contexts/Connect'; import { useActivePools } from 'contexts/Pools/ActivePools'; import { usePoolMemberships } from 'contexts/Pools/PoolMemberships'; import { useTheme } from 'contexts/Themes'; @@ -13,11 +12,12 @@ import { useUi } from 'contexts/UI'; import { CardWrapper } from 'library/Card/Wrappers'; import { useOverlay } from '@polkadot-cloud/react/hooks'; import { useNetwork } from 'contexts/Network'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; export const ClosurePrompts = () => { const { t } = useTranslation('pages'); const { colors } = useNetwork().networkData; - const { activeAccount } = useConnect(); + const { activeAccount } = useActiveAccounts(); const { mode } = useTheme(); const { openModal } = useOverlay().modal; const { membership } = usePoolMemberships(); diff --git a/src/pages/Pools/Home/ManageBond.tsx b/src/pages/Pools/Home/ManageBond.tsx index 0e9a2a2e79..620508f268 100644 --- a/src/pages/Pools/Home/ManageBond.tsx +++ b/src/pages/Pools/Home/ManageBond.tsx @@ -10,7 +10,6 @@ import { } from '@polkadot-cloud/react'; import { minDecimalPlaces, planckToUnit } from '@polkadot-cloud/utils'; import { useTranslation } from 'react-i18next'; -import { useConnect } from 'contexts/Connect'; import { useHelp } from 'contexts/Help'; import { useActivePools } from 'contexts/Pools/ActivePools'; import { useTransferOptions } from 'contexts/TransferOptions'; @@ -19,6 +18,8 @@ import { BondedChart } from 'library/BarChart/BondedChart'; import { CardHeaderWrapper } from 'library/Card/Wrappers'; import { useOverlay } from '@polkadot-cloud/react/hooks'; import { useNetwork } from 'contexts/Network'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; +import { useImportedAccounts } from 'contexts/Connect/ImportedAccounts'; export const ManageBond = () => { const { t } = useTranslation('pages'); @@ -32,8 +33,9 @@ export const ManageBond = () => { const { openHelp } = useHelp(); const { isPoolSyncing } = useUi(); const { openModal } = useOverlay().modal; + const { activeAccount } = useActiveAccounts(); + const { isReadOnlyAccount } = useImportedAccounts(); const { getTransferOptions } = useTransferOptions(); - const { activeAccount, isReadOnlyAccount } = useConnect(); const { isBonding, isMember, selectedActivePool } = useActivePools(); const allTransferOptions = getTransferOptions(activeAccount); diff --git a/src/pages/Pools/Home/ManagePool/index.tsx b/src/pages/Pools/Home/ManagePool/index.tsx index fdd8f07984..0e0a96a3c0 100644 --- a/src/pages/Pools/Home/ManagePool/index.tsx +++ b/src/pages/Pools/Home/ManagePool/index.tsx @@ -4,7 +4,6 @@ import { faChevronCircleRight } from '@fortawesome/free-solid-svg-icons'; import { ButtonHelp, ButtonPrimary, PageRow } from '@polkadot-cloud/react'; import { useTranslation } from 'react-i18next'; -import { useConnect } from 'contexts/Connect'; import { useHelp } from 'contexts/Help'; import { useActivePools } from 'contexts/Pools/ActivePools'; import { useUi } from 'contexts/UI'; @@ -12,12 +11,13 @@ import { CardHeaderWrapper, CardWrapper } from 'library/Card/Wrappers'; import { GenerateNominations } from 'library/GenerateNominations'; import { Nominations } from 'pages/Nominate/Active/Nominations'; import { useOverlay } from '@polkadot-cloud/react/hooks'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; export const ManagePool = () => { const { t } = useTranslation('pages'); const { isSyncing } = useUi(); const { openModal } = useOverlay().modal; - const { activeAccount } = useConnect(); + const { activeAccount } = useActiveAccounts(); const { isOwner, isNominator, diff --git a/src/pages/Pools/Home/MembersList/FetchPage.tsx b/src/pages/Pools/Home/MembersList/FetchPage.tsx index 2f95d55502..d53b55bc06 100644 --- a/src/pages/Pools/Home/MembersList/FetchPage.tsx +++ b/src/pages/Pools/Home/MembersList/FetchPage.tsx @@ -7,7 +7,6 @@ import { motion } from 'framer-motion'; import { useEffect, useRef, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { ListItemsPerBatch, ListItemsPerPage } from 'consts'; -import { useConnect } from 'contexts/Connect'; import { usePlugins } from 'contexts/Plugins'; import { useActivePools } from 'contexts/Pools/ActivePools'; import { usePoolMembers } from 'contexts/Pools/PoolMembers'; @@ -19,6 +18,7 @@ import { MotionContainer } from 'library/List/MotionContainer'; import { Pagination } from 'library/List/Pagination'; import { ListProvider, useList } from 'library/List/context'; import { useNetwork } from 'contexts/Network'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; import { Member } from './Member'; import type { FetchpageMembersListProps } from './types'; @@ -37,9 +37,9 @@ export const MembersListInner = ({ } = useNetwork(); const provider = useList(); const { mode } = useTheme(); - const { activeAccount } = useConnect(); const { pluginEnabled } = usePlugins(); const { fetchPoolMembers } = useSubscan(); + const { activeAccount } = useActiveAccounts(); const { selectedActivePool } = useActivePools(); const { poolMembersApi, diff --git a/src/pages/Pools/Home/Status/MembershipStatus.tsx b/src/pages/Pools/Home/Status/MembershipStatus.tsx index 73d46e71e8..95496c118e 100644 --- a/src/pages/Pools/Home/Status/MembershipStatus.tsx +++ b/src/pages/Pools/Home/Status/MembershipStatus.tsx @@ -5,13 +5,14 @@ import { faCog } from '@fortawesome/free-solid-svg-icons'; import { determinePoolDisplay } from '@polkadot-cloud/utils'; import { useTranslation } from 'react-i18next'; import { useApi } from 'contexts/Api'; -import { useConnect } from 'contexts/Connect'; import { useActivePools } from 'contexts/Pools/ActivePools'; import { useBondedPools } from 'contexts/Pools/BondedPools'; import { useTransferOptions } from 'contexts/TransferOptions'; import { useUi } from 'contexts/UI'; import { Stat } from 'library/Stat'; import { useOverlay } from '@polkadot-cloud/react/hooks'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; +import { useImportedAccounts } from 'contexts/Connect/ImportedAccounts'; import { useStatusButtons } from './useStatusButtons'; export const MembershipStatus = ({ @@ -25,10 +26,11 @@ export const MembershipStatus = ({ const { isReady } = useApi(); const { isPoolSyncing } = useUi(); const { openModal } = useOverlay().modal; + const { activeAccount } = useActiveAccounts(); const { label, buttons } = useStatusButtons(); const { bondedPools, meta } = useBondedPools(); + const { isReadOnlyAccount } = useImportedAccounts(); const { getTransferOptions } = useTransferOptions(); - const { activeAccount, isReadOnlyAccount } = useConnect(); const { selectedActivePool, isOwner, isBouncer, isMember } = useActivePools(); const { active } = getTransferOptions(activeAccount).pool; diff --git a/src/pages/Pools/Home/Status/RewardsStatus.tsx b/src/pages/Pools/Home/Status/RewardsStatus.tsx index e4a07ecaaa..d700c47b18 100644 --- a/src/pages/Pools/Home/Status/RewardsStatus.tsx +++ b/src/pages/Pools/Home/Status/RewardsStatus.tsx @@ -6,12 +6,13 @@ import { planckToUnit } from '@polkadot-cloud/utils'; import BigNumber from 'bignumber.js'; import { useTranslation } from 'react-i18next'; import { useApi } from 'contexts/Api'; -import { useConnect } from 'contexts/Connect'; import { useActivePools } from 'contexts/Pools/ActivePools'; import { useUi } from 'contexts/UI'; import { Stat } from 'library/Stat'; import { useOverlay } from '@polkadot-cloud/react/hooks'; import { useNetwork } from 'contexts/Network'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; +import { useImportedAccounts } from 'contexts/Connect/ImportedAccounts'; export const RewardsStatus = () => { const { t } = useTranslation('pages'); @@ -21,8 +22,9 @@ export const RewardsStatus = () => { const { isReady } = useApi(); const { isPoolSyncing } = useUi(); const { openModal } = useOverlay().modal; + const { activeAccount } = useActiveAccounts(); const { selectedActivePool } = useActivePools(); - const { activeAccount, isReadOnlyAccount } = useConnect(); + const { isReadOnlyAccount } = useImportedAccounts(); let { pendingRewards } = selectedActivePool || {}; pendingRewards = pendingRewards ?? new BigNumber(0); diff --git a/src/pages/Pools/Home/Status/useStatusButtons.tsx b/src/pages/Pools/Home/Status/useStatusButtons.tsx index 45de533727..0674328e89 100644 --- a/src/pages/Pools/Home/Status/useStatusButtons.tsx +++ b/src/pages/Pools/Home/Status/useStatusButtons.tsx @@ -4,26 +4,28 @@ import { faPlusCircle, faUserPlus } from '@fortawesome/free-solid-svg-icons'; import { useTranslation } from 'react-i18next'; import { useApi } from 'contexts/Api'; -import { useConnect } from 'contexts/Connect'; import { useActivePools } from 'contexts/Pools/ActivePools'; import { useBondedPools } from 'contexts/Pools/BondedPools'; import { usePoolMemberships } from 'contexts/Pools/PoolMemberships'; import { usePoolsConfig } from 'contexts/Pools/PoolsConfig'; import { useSetup } from 'contexts/Setup'; import { useTransferOptions } from 'contexts/TransferOptions'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; +import { useImportedAccounts } from 'contexts/Connect/ImportedAccounts'; import { usePoolsTabs } from '../context'; export const useStatusButtons = () => { const { t } = useTranslation('pages'); const { isReady } = useApi(); - const { setOnPoolSetup, getPoolSetupPercent } = useSetup(); - const { activeAccount, isReadOnlyAccount } = useConnect(); const { stats } = usePoolsConfig(); - const { membership } = usePoolMemberships(); + const { isOwner } = useActivePools(); const { setActiveTab } = usePoolsTabs(); const { bondedPools } = useBondedPools(); - const { isOwner } = useActivePools(); + const { membership } = usePoolMemberships(); + const { activeAccount } = useActiveAccounts(); const { getTransferOptions } = useTransferOptions(); + const { isReadOnlyAccount } = useImportedAccounts(); + const { setOnPoolSetup, getPoolSetupPercent } = useSetup(); const { maxPools } = stats; const { active } = getTransferOptions(activeAccount).pool; diff --git a/src/pages/Pools/Home/index.tsx b/src/pages/Pools/Home/index.tsx index e97bf327c3..11aea63a38 100644 --- a/src/pages/Pools/Home/index.tsx +++ b/src/pages/Pools/Home/index.tsx @@ -5,7 +5,6 @@ import { PageRow, PageTitle, RowSection } from '@polkadot-cloud/react'; import { useEffect } from 'react'; import { useTranslation } from 'react-i18next'; import type { PageTitleTabProps } from '@polkadot-cloud/react/base/types'; -import { useConnect } from 'contexts/Connect'; import { useActivePools } from 'contexts/Pools/ActivePools'; import { useBondedPools } from 'contexts/Pools/BondedPools'; import { CardWrapper } from 'library/Card/Wrappers'; @@ -13,6 +12,7 @@ import { PoolList } from 'library/PoolList/Default'; import { StatBoxList } from 'library/StatBoxList'; import { usePoolsConfig } from 'contexts/Pools/PoolsConfig'; import { useOverlay } from '@polkadot-cloud/react/hooks'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; import { Roles } from '../Roles'; import { ClosurePrompts } from './ClosurePrompts'; import { PoolFavorites } from './Favorites'; @@ -29,7 +29,7 @@ import { PoolsTabsProvider, usePoolsTabs } from './context'; export const HomeInner = () => { const { t } = useTranslation('pages'); const { openModal } = useOverlay().modal; - const { activeAccount } = useConnect(); + const { activeAccount } = useActiveAccounts(); const { favorites, stats: { counterForBondedPools }, diff --git a/src/pages/Pools/Roles/RoleEditInput/index.tsx b/src/pages/Pools/Roles/RoleEditInput/index.tsx index 9ac73dd5a5..98490320e9 100644 --- a/src/pages/Pools/Roles/RoleEditInput/index.tsx +++ b/src/pages/Pools/Roles/RoleEditInput/index.tsx @@ -4,12 +4,15 @@ import { isValidAddress } from '@polkadot-cloud/utils'; import React from 'react'; import { useTranslation } from 'react-i18next'; -import { useConnect } from 'contexts/Connect'; +import { useNetwork } from 'contexts/Network'; +import { formatAccountSs58 } from 'contexts/Connect/Utils'; import { Wrapper } from './Wrapper'; export const RoleEditInput = ({ setRoleEdit, roleKey, roleEdit }: any) => { const { t } = useTranslation('pages'); - const { formatAccountSs58 } = useConnect(); + const { + networkData: { ss58 }, + } = useNetwork(); const processRoleEdit = (newAddress: string) => { let edit = { @@ -18,7 +21,7 @@ export const RoleEditInput = ({ setRoleEdit, roleKey, roleEdit }: any) => { reformatted: false, }; if (isValidAddress(newAddress)) { - const addressFormatted = formatAccountSs58(newAddress); + const addressFormatted = formatAccountSs58(newAddress, ss58); if (addressFormatted) { edit = { newAddress: addressFormatted, diff --git a/src/pages/Pools/Roles/index.tsx b/src/pages/Pools/Roles/index.tsx index e2e7284b6f..a205982e44 100644 --- a/src/pages/Pools/Roles/index.tsx +++ b/src/pages/Pools/Roles/index.tsx @@ -14,7 +14,6 @@ import { import { useEffect, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { useApi } from 'contexts/Api'; -import { useConnect } from 'contexts/Connect'; import { useHelp } from 'contexts/Help'; import { useIdentities } from 'contexts/Identities'; import { useActivePools } from 'contexts/Pools/ActivePools'; @@ -22,6 +21,8 @@ import { useUi } from 'contexts/UI'; import { CardHeaderWrapper } from 'library/Card/Wrappers'; import { useOverlay } from '@polkadot-cloud/react/hooks'; import { useNetwork } from 'contexts/Network'; +import { useActiveAccounts } from 'contexts/ActiveAccounts'; +import { useImportedAccounts } from 'contexts/Connect/ImportedAccounts'; import { RolesWrapper } from '../Home/ManagePool/Wrappers'; import { PoolAccount } from '../PoolAccount'; import { RoleEditInput } from './RoleEditInput'; @@ -40,9 +41,10 @@ export const Roles = ({ const { network } = useNetwork(); const { isPoolSyncing } = useUi(); const { openModal } = useOverlay().modal; + const { activeAccount } = useActiveAccounts(); + const { isReadOnlyAccount } = useImportedAccounts(); const { fetchIdentitiesMetaBatch } = useIdentities(); const { isOwner, selectedActivePool } = useActivePools(); - const { activeAccount, isReadOnlyAccount } = useConnect(); const { id } = selectedActivePool || { id: 0 }; const roles = defaultRoles; diff --git a/src/types/index.ts b/src/types/index.ts index 5c44882626..c5f1fb46f3 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -87,7 +87,7 @@ interface PageProp { key: string; } -export type MaybeAccount = string | null; +export type MaybeAddress = string | null; export type MaybeString = string | null; diff --git a/src/workers/types.ts b/src/workers/types.ts index 86519d14fb..7293c7dd03 100644 --- a/src/workers/types.ts +++ b/src/workers/types.ts @@ -6,13 +6,13 @@ import type { Exposure, Staker, } from 'contexts/Staking/types'; -import type { MaybeAccount, NetworkName } from 'types'; +import type { MaybeAddress, NetworkName } from 'types'; export interface DataInitialiseExposures { task: string; networkName: NetworkName; era: string; - activeAccount: MaybeAccount; + activeAccount: MaybeAddress; units: number; exposures: Exposure[]; maxNominatorRewardedPerValidator: number; @@ -26,5 +26,5 @@ export interface ResponseInitialiseExposures { totalActiveNominators: number; activeAccountOwnStake: ActiveAccountStaker[]; activeValidators: number; - who: MaybeAccount; + who: MaybeAddress; } diff --git a/yarn.lock b/yarn.lock index 0ab029cfbe..dec617b76d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1215,9 +1215,9 @@ eslint-visitor-keys "^3.3.0" "@eslint-community/regexpp@^4.5.1", "@eslint-community/regexpp@^4.6.1": - version "4.9.0" - resolved "https://registry.yarnpkg.com/@eslint-community/regexpp/-/regexpp-4.9.0.tgz#7ccb5f58703fa61ffdcbf39e2c604a109e781162" - integrity sha512-zJmuCWj2VLBt4c25CfBIbMZLGLyhkvs7LznyVX5HfpzeocThgIj5XQK4L+g3U36mMcx8bPMhGyPpwCATamC4jQ== + version "4.9.1" + resolved "https://registry.yarnpkg.com/@eslint-community/regexpp/-/regexpp-4.9.1.tgz#449dfa81a57a1d755b09aa58d826c1262e4283b4" + integrity sha512-Y27x+MBLjXa+0JWDhykM3+JE+il3kHKAEqabfEWq3SDhZjLYb6/BHL/JKFnH3fe207JaXkyDo685Oc2Glt6ifA== "@eslint/eslintrc@^2.1.2": version "2.1.2" @@ -1443,48 +1443,39 @@ picocolors "^1.0.0" tslib "^2.6.0" -"@polkadot-cloud/assets@^0.1.15", "@polkadot-cloud/assets@^0.1.16": +"@polkadot-cloud/assets@^0.1.16": version "0.1.16" resolved "https://registry.yarnpkg.com/@polkadot-cloud/assets/-/assets-0.1.16.tgz#385b1b0b3a06942620b6e4e788997439f68dcf5c" integrity sha512-5YB7Op38hAxKVnHkJav/s6JPFa2KRpUob8zMMg2OBnC/tAaapFzNxVtE357+uSO0EbY1CHkYuOmmMTN87UwAzg== "@polkadot-cloud/core@^0.1.31": - version "0.1.35" - resolved "https://registry.yarnpkg.com/@polkadot-cloud/core/-/core-0.1.35.tgz#3bb4c5f34c33903ea6a3894e619f8f45c7b8f3f0" - integrity sha512-LsRlOQD3vNOvnCO9GaTQX0iISmiGEL4mlUJRkyh9lPWhPYBw3dwnEFCRMJS4lEE8bz/5CTX+D96GgR2RMz75Bw== + version "0.1.36" + resolved "https://registry.yarnpkg.com/@polkadot-cloud/core/-/core-0.1.36.tgz#d276aa81204d7eed41a26b9d9d9d6c1f15970079" + integrity sha512-VeWmCUuo8tYcPC8cvoohwP7xTc7MbL1LHHWbjItZR2LUH2iP4Szjty9fJb0Nh3TVJDspRRBjLbSeziHoJLvn/w== -"@polkadot-cloud/core@^1.0.6": +"@polkadot-cloud/core@^1.0.7": version "1.0.7" resolved "https://registry.yarnpkg.com/@polkadot-cloud/core/-/core-1.0.7.tgz#ace2356c524c11553ea125fc1c5f7538ba6fd044" integrity sha512-EjlOfMNc+Nh5RzMXNoiwMogeDNyZ+Up7LIEiz1TlbpWuHcnAk3zuNdrGpJC3SHvUnjQ16GKDfELtAzFblTCdIg== -"@polkadot-cloud/react@^0.1.69": - version "0.1.69" - resolved "https://registry.yarnpkg.com/@polkadot-cloud/react/-/react-0.1.69.tgz#a86d6ae3aa8e327b51bd0ec453b9543dea06eac3" - integrity sha512-zPTOSu55fA2v+t/bt6AZwp+kUXVeYOrFw2eAMz//PaiNQ609aHkfTF2CIbbYaNY3CRwmU7cah7CT1+h7WJbKrw== +"@polkadot-cloud/react@^0.1.70": + version "0.1.70" + resolved "https://registry.yarnpkg.com/@polkadot-cloud/react/-/react-0.1.70.tgz#bf1195464c981235dd04a61e7950e7b0580898d7" + integrity sha512-T+budh+dPziEYmdxGIKt4pUKneCorFcgnUBPnmaYGMZJexmmmmfIt3WqkpTjCJHZzrXEJYYQKKf+vvPPAMlTpA== dependencies: "@fortawesome/fontawesome-svg-core" "^6.4.2" "@fortawesome/free-brands-svg-icons" "^6.4.2" "@fortawesome/free-regular-svg-icons" "^6.4.2" "@fortawesome/free-solid-svg-icons" "^6.4.2" "@fortawesome/react-fontawesome" "^0.2.0" - "@polkadot-cloud/assets" "^0.1.15" - "@polkadot-cloud/core" "^1.0.6" - "@polkadot-cloud/utils" "^0.0.19" + "@polkadot-cloud/assets" "^0.1.16" + "@polkadot-cloud/core" "^1.0.7" + "@polkadot-cloud/utils" "^0.0.20" "@polkadot/util" "^12.5.1" "@polkadot/util-crypto" "^12.5.1" framer-motion "^10.15.0" react-error-boundary "^4.0.11" -"@polkadot-cloud/utils@^0.0.19": - version "0.0.19" - resolved "https://registry.yarnpkg.com/@polkadot-cloud/utils/-/utils-0.0.19.tgz#fff76682c66a3b252d754ca0cd1a01b11f12dce6" - integrity sha512-r+P360ZDaB0w/bRKtNTsRdREvBGPG5oBW/kBZRghsIigln5iSFTA1JP0YqS9685zfb+d3d9LH0TyiC+olNVURA== - dependencies: - "@polkadot/keyring" "^12.5.1" - "@polkadot/util" "^12.5.1" - bignumber.js "^9.1.1" - "@polkadot-cloud/utils@^0.0.20": version "0.0.20" resolved "https://registry.yarnpkg.com/@polkadot-cloud/utils/-/utils-0.0.20.tgz#b9a8038304d8dc24f6b530ec687543aaf268721a" @@ -1840,9 +1831,9 @@ picomatch "^2.2.2" "@rollup/pluginutils@^5.0.4": - version "5.0.4" - resolved "https://registry.yarnpkg.com/@rollup/pluginutils/-/pluginutils-5.0.4.tgz#74f808f9053d33bafec0cc98e7b835c9667d32ba" - integrity sha512-0KJnIoRI8A+a1dqOYLxH8vBf8bphDmty5QvIm2hqm7oFCFYKCAZWWd2hXgMibaPsNDhI0AtpYfQZJG47pt/k4g== + version "5.0.5" + resolved "https://registry.yarnpkg.com/@rollup/pluginutils/-/pluginutils-5.0.5.tgz#bbb4c175e19ebfeeb8c132c2eea0ecb89941a66c" + integrity sha512-6aEYR910NyP73oHiJglti74iRyOwgFU4x3meH/H8OJx6Ry0j6cOVZ5X/wTvub7G7Ao6qaHBEaNsV3GLJkSsF+Q== dependencies: "@types/estree" "^1.0.0" estree-walker "^2.0.2" @@ -1968,79 +1959,79 @@ "@svgr/hast-util-to-babel-ast" "8.0.0" svg-parser "^2.0.4" -"@swc/core-darwin-arm64@1.3.90": - version "1.3.90" - resolved "https://registry.yarnpkg.com/@swc/core-darwin-arm64/-/core-darwin-arm64-1.3.90.tgz#5eb85b4911c6e1a8a082711b7ef3d4be3f86163f" - integrity sha512-he0w74HvcoufE6CZrB/U/VGVbc7021IQvYrn1geMACnq/OqMBqjdczNtdNfJAy87LZ4AOUjHDKEIjsZZu7o8nQ== - -"@swc/core-darwin-x64@1.3.90": - version "1.3.90" - resolved "https://registry.yarnpkg.com/@swc/core-darwin-x64/-/core-darwin-x64-1.3.90.tgz#e6d5c2118c6ad060f58ce9c7d246cf4c30420516" - integrity sha512-hKNM0Ix0qMlAamPe0HUfaAhQVbZEL5uK6Iw8v9ew0FtVB4v7EifQ9n41wh+yCj0CjcHBPEBbQU0P6mNTxJu/RQ== - -"@swc/core-linux-arm-gnueabihf@1.3.90": - version "1.3.90" - resolved "https://registry.yarnpkg.com/@swc/core-linux-arm-gnueabihf/-/core-linux-arm-gnueabihf-1.3.90.tgz#02cfecb0e5f3457e64e81eca70337c6dadba864d" - integrity sha512-HumvtrqTWE8rlFuKt7If0ZL7145H/jVc4AeziVjcd+/ajpqub7IyfrLCYd5PmKMtfeSVDMsxjG0BJ0HLRxrTJA== - -"@swc/core-linux-arm64-gnu@1.3.90": - version "1.3.90" - resolved "https://registry.yarnpkg.com/@swc/core-linux-arm64-gnu/-/core-linux-arm64-gnu-1.3.90.tgz#1ed87e65facc446880f5753fb89951da418f6ff5" - integrity sha512-tA7DqCS7YCwngwXZQeqQhhMm8BbydpaABw8Z/EDQ7KPK1iZ1rNjZw+aWvSpmNmEGmH1RmQ9QDS9mGRDp0faAeg== - -"@swc/core-linux-arm64-musl@1.3.90": - version "1.3.90" - resolved "https://registry.yarnpkg.com/@swc/core-linux-arm64-musl/-/core-linux-arm64-musl-1.3.90.tgz#531edd90f46aa7282e919178633f483f7ba073d6" - integrity sha512-p2Vtid5BZA36fJkNUwk5HP+HJlKgTru+Ghna7pRe45ghKkkRIUk3fhkgudEvfKfhT+3AvP+GTVQ+T9k0gc9S8w== - -"@swc/core-linux-x64-gnu@1.3.90": - version "1.3.90" - resolved "https://registry.yarnpkg.com/@swc/core-linux-x64-gnu/-/core-linux-x64-gnu-1.3.90.tgz#7b3937570964e290a0f382353d88fe8421ceb470" - integrity sha512-J6pDtWaulYGXuANERuvv4CqmUbZOQrRZBCRQGZQJ6a86RWpesZqckBelnYx48wYmkgvMkF95Y3xbI3WTfoSHzw== - -"@swc/core-linux-x64-musl@1.3.90": - version "1.3.90" - resolved "https://registry.yarnpkg.com/@swc/core-linux-x64-musl/-/core-linux-x64-musl-1.3.90.tgz#ae042d8dc84e086954a26308e4bccf6f38c1dafe" - integrity sha512-3Gh6EA3+0K+l3MqnRON7h5bZ32xLmfcVM6QiHHJ9dBttq7YOEeEoMOCdIPMaQxJmK1VfLgZCsPYRd66MhvUSkw== - -"@swc/core-win32-arm64-msvc@1.3.90": - version "1.3.90" - resolved "https://registry.yarnpkg.com/@swc/core-win32-arm64-msvc/-/core-win32-arm64-msvc-1.3.90.tgz#4952413bae4c5dbd7c150f7a626556fc6a2a3525" - integrity sha512-BNaw/iJloDyaNOFV23Sr53ULlnbmzSoerTJ10v0TjSZOEIpsS0Rw6xOK1iI0voDJnRXeZeWRSxEC9DhefNtN/g== - -"@swc/core-win32-ia32-msvc@1.3.90": - version "1.3.90" - resolved "https://registry.yarnpkg.com/@swc/core-win32-ia32-msvc/-/core-win32-ia32-msvc-1.3.90.tgz#ea5d417d3085dc521e6be6ecaef8c6ca59c4e5ec" - integrity sha512-SiyTethWAheE/JbxXCukAAciU//PLcmVZ2ME92MRuLMLmOhrwksjbaa7ukj9WEF3LWrherhSqTXnpj3VC1l/qw== - -"@swc/core-win32-x64-msvc@1.3.90": - version "1.3.90" - resolved "https://registry.yarnpkg.com/@swc/core-win32-x64-msvc/-/core-win32-x64-msvc-1.3.90.tgz#af770b063fe7f32488a87cf0a9777e11932f7a3a" - integrity sha512-OpWAW5ljKcPJ3SQ0pUuKqYfwXv7ssIhVgrH9XP9ONtdgXKWZRL9hqJQkcL55FARw/gDjKanoCM47wsTNQL+ZZA== +"@swc/core-darwin-arm64@1.3.92": + version "1.3.92" + resolved "https://registry.yarnpkg.com/@swc/core-darwin-arm64/-/core-darwin-arm64-1.3.92.tgz#0498d3584cf877e39107c94705c38fa4a8c04789" + integrity sha512-v7PqZUBtIF6Q5Cp48gqUiG8zQQnEICpnfNdoiY3xjQAglCGIQCjJIDjreZBoeZQZspB27lQN4eZ43CX18+2SnA== + +"@swc/core-darwin-x64@1.3.92": + version "1.3.92" + resolved "https://registry.yarnpkg.com/@swc/core-darwin-x64/-/core-darwin-x64-1.3.92.tgz#1728e7ebbfe37b56c07d99e29dde78bfa90cf8d1" + integrity sha512-Q3XIgQfXyxxxms3bPN+xGgvwk0TtG9l89IomApu+yTKzaIIlf051mS+lGngjnh9L0aUiCp6ICyjDLtutWP54fw== + +"@swc/core-linux-arm-gnueabihf@1.3.92": + version "1.3.92" + resolved "https://registry.yarnpkg.com/@swc/core-linux-arm-gnueabihf/-/core-linux-arm-gnueabihf-1.3.92.tgz#6f7c20833b739f8911c936c9783976ded2c449dc" + integrity sha512-tnOCoCpNVXC+0FCfG84PBZJyLlz0Vfj9MQhyhCvlJz9hQmvpf8nTdKH7RHrOn8VfxtUBLdVi80dXgIFgbvl7qA== + +"@swc/core-linux-arm64-gnu@1.3.92": + version "1.3.92" + resolved "https://registry.yarnpkg.com/@swc/core-linux-arm64-gnu/-/core-linux-arm64-gnu-1.3.92.tgz#bb01dd9b922b0c076c38924013bd10036ce39c7c" + integrity sha512-lFfGhX32w8h1j74Iyz0Wv7JByXIwX11OE9UxG+oT7lG0RyXkF4zKyxP8EoxfLrDXse4Oop434p95e3UNC3IfCw== + +"@swc/core-linux-arm64-musl@1.3.92": + version "1.3.92" + resolved "https://registry.yarnpkg.com/@swc/core-linux-arm64-musl/-/core-linux-arm64-musl-1.3.92.tgz#0070165eed2805475c98eb732bab8bdca955932e" + integrity sha512-rOZtRcLj57MSAbiecMsqjzBcZDuaCZ8F6l6JDwGkQ7u1NYR57cqF0QDyU7RKS1Jq27Z/Vg21z5cwqoH5fLN+Sg== + +"@swc/core-linux-x64-gnu@1.3.92": + version "1.3.92" + resolved "https://registry.yarnpkg.com/@swc/core-linux-x64-gnu/-/core-linux-x64-gnu-1.3.92.tgz#d9785f93b9121eeef0f54e8d845dd216698e0115" + integrity sha512-qptoMGnBL6v89x/Qpn+l1TH1Y0ed+v0qhNfAEVzZvCvzEMTFXphhlhYbDdpxbzRmCjH6GOGq7Y+xrWt9T1/ARg== + +"@swc/core-linux-x64-musl@1.3.92": + version "1.3.92" + resolved "https://registry.yarnpkg.com/@swc/core-linux-x64-musl/-/core-linux-x64-musl-1.3.92.tgz#8fe5cf244695bf4f0bc7dc7df450a9bd1bfccc2b" + integrity sha512-g2KrJ43bZkCZHH4zsIV5ErojuV1OIpUHaEyW1gf7JWKaFBpWYVyubzFPvPkjcxHGLbMsEzO7w/NVfxtGMlFH/Q== + +"@swc/core-win32-arm64-msvc@1.3.92": + version "1.3.92" + resolved "https://registry.yarnpkg.com/@swc/core-win32-arm64-msvc/-/core-win32-arm64-msvc-1.3.92.tgz#d6150785455c813a8e62f4e4b0a22773baf398eb" + integrity sha512-3MCRGPAYDoQ8Yyd3WsCMc8eFSyKXY5kQLyg/R5zEqA0uthomo0m0F5/fxAJMZGaSdYkU1DgF73ctOWOf+Z/EzQ== + +"@swc/core-win32-ia32-msvc@1.3.92": + version "1.3.92" + resolved "https://registry.yarnpkg.com/@swc/core-win32-ia32-msvc/-/core-win32-ia32-msvc-1.3.92.tgz#8142166bceafbaa209d440b36fdc8cd4b4f82768" + integrity sha512-zqTBKQhgfWm73SVGS8FKhFYDovyRl1f5dTX1IwSKynO0qHkRCqJwauFJv/yevkpJWsI2pFh03xsRs9HncTQKSA== + +"@swc/core-win32-x64-msvc@1.3.92": + version "1.3.92" + resolved "https://registry.yarnpkg.com/@swc/core-win32-x64-msvc/-/core-win32-x64-msvc-1.3.92.tgz#4ba542875fc690b579232721ccec7873e139646a" + integrity sha512-41bE66ddr9o/Fi1FBh0sHdaKdENPTuDpv1IFHxSg0dJyM/jX8LbkjnpdInYXHBxhcLVAPraVRrNsC4SaoPw2Pg== "@swc/core@^1.3.85": - version "1.3.90" - resolved "https://registry.yarnpkg.com/@swc/core/-/core-1.3.90.tgz#ef43524b76ef04798e6afb01d90347f4f51de136" - integrity sha512-wptBxP4PldOnhmyDVj8qUcn++GRqyw1qc9wOTGtPNHz8cpuTfdfIgYGlhI4La0UYqecuaaIfLfokyuNePOMHPg== + version "1.3.92" + resolved "https://registry.yarnpkg.com/@swc/core/-/core-1.3.92.tgz#f51808cdb6cbb90b0877b9a51806eea9a70eafca" + integrity sha512-vx0vUrf4YTEw59njOJ46Ha5i0cZTMYdRHQ7KXU29efN1MxcmJH2RajWLPlvQarOP1ab9iv9cApD7SMchDyx2vA== dependencies: "@swc/counter" "^0.1.1" "@swc/types" "^0.1.5" optionalDependencies: - "@swc/core-darwin-arm64" "1.3.90" - "@swc/core-darwin-x64" "1.3.90" - "@swc/core-linux-arm-gnueabihf" "1.3.90" - "@swc/core-linux-arm64-gnu" "1.3.90" - "@swc/core-linux-arm64-musl" "1.3.90" - "@swc/core-linux-x64-gnu" "1.3.90" - "@swc/core-linux-x64-musl" "1.3.90" - "@swc/core-win32-arm64-msvc" "1.3.90" - "@swc/core-win32-ia32-msvc" "1.3.90" - "@swc/core-win32-x64-msvc" "1.3.90" + "@swc/core-darwin-arm64" "1.3.92" + "@swc/core-darwin-x64" "1.3.92" + "@swc/core-linux-arm-gnueabihf" "1.3.92" + "@swc/core-linux-arm64-gnu" "1.3.92" + "@swc/core-linux-arm64-musl" "1.3.92" + "@swc/core-linux-x64-gnu" "1.3.92" + "@swc/core-linux-x64-musl" "1.3.92" + "@swc/core-win32-arm64-msvc" "1.3.92" + "@swc/core-win32-ia32-msvc" "1.3.92" + "@swc/core-win32-x64-msvc" "1.3.92" "@swc/counter@^0.1.1": - version "0.1.1" - resolved "https://registry.yarnpkg.com/@swc/counter/-/counter-0.1.1.tgz#e8d066c653883238c291d8fdd8b36ed932e87920" - integrity sha512-xVRaR4u9hcYjFvcSg71Lz5Bo4//CyjAAfMxa7UsaDSYxAshflUkVJWiyVWrfxC59z2kP1IzI4/1BEpnhI9o3Mw== + version "0.1.2" + resolved "https://registry.yarnpkg.com/@swc/counter/-/counter-0.1.2.tgz#bf06d0770e47c6f1102270b744e17b934586985e" + integrity sha512-9F4ys4C74eSTEUNndnER3VJ15oru2NumfQxS8geE+f3eB5xvfxpWyqE5XlVnxb/R14uoXi6SLbBwwiDSkv+XEw== "@swc/types@^0.1.5": version "0.1.5" @@ -2107,19 +2098,19 @@ integrity sha512-Vrjz5N5Ia4SEzWWgIVwnHNEnb1UE1XMkvY5DGXrAeOGE9imk0hgTHh5GyDjLDJi9OTCn9oo9dXH1uToK1VRfrg== "@types/node@*": - version "20.7.1" - resolved "https://registry.yarnpkg.com/@types/node/-/node-20.7.1.tgz#06d732ead0bd5ad978ef0ea9cbdeb24dc8717514" - integrity sha512-LT+OIXpp2kj4E2S/p91BMe+VgGX2+lfO+XTpfXhh+bCk2LkQtHZSub8ewFBMGP5ClysPjTDFa4sMI8Q3n4T0wg== + version "20.8.3" + resolved "https://registry.yarnpkg.com/@types/node/-/node-20.8.3.tgz#c4ae2bb1cfab2999ed441a95c122bbbe1567a66d" + integrity sha512-jxiZQFpb+NlH5kjW49vXxvxTjeeqlbsnTAdBTKpzEdPs9itay7MscYXz3Fo9VYFEsfQ6LJFitHad3faerLAjCw== "@types/prop-types@*": - version "15.7.7" - resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.7.tgz#f9361f7b87fd5d8188b2c998db0a1f47e9fb391a" - integrity sha512-FbtmBWCcSa2J4zL781Zf1p5YUBXQomPEcep9QZCfRfQgTxz3pJWiDFLebohZ9fFntX5ibzOkSsrJ0TEew8cAog== + version "15.7.8" + resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.8.tgz#805eae6e8f41bd19e88917d2ea200dc992f405d3" + integrity sha512-kMpQpfZKSCBqltAJwskgePRaYRFukDkm1oItcAbC3gNELR20XIBcN9VRgg4+m8DKsTfkWeA4m4Imp4DDuWy7FQ== "@types/react-dom@^18.2.10": - version "18.2.10" - resolved "https://registry.yarnpkg.com/@types/react-dom/-/react-dom-18.2.10.tgz#06247cb600e39b63a0a385f6a5014c44bab296f2" - integrity sha512-5VEC5RgXIk1HHdyN1pHlg0cOqnxHzvPGpMMyGAP5qSaDRmyZNDaQ0kkVAkK6NYlDhP6YBID3llaXlmAS/mdgCA== + version "18.2.11" + resolved "https://registry.yarnpkg.com/@types/react-dom/-/react-dom-18.2.11.tgz#4332c315544698a0875dfdb6e320dda59e1b3d58" + integrity sha512-zq6Dy0EiCuF9pWFW6I6k6W2LdpUixLE4P6XjXU1QHLfak3GPACQfLwEuHzY5pOYa4hzj1d0GxX/P141aFjZsyg== dependencies: "@types/react" "*" @@ -2595,9 +2586,9 @@ binary-extensions@^2.0.0: resolved "https://registry.yarnpkg.com/binary-extensions/-/binary-extensions-2.2.0.tgz#75f502eeaf9ffde42fc98829645be4ea76bd9e2d" integrity sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA== -"bip32-ed25519@https://github.com/Zondax/bip32-ed25519": +"bip32-ed25519@git+https://github.com/Zondax/bip32-ed25519.git": version "0.0.4" - resolved "https://github.com/Zondax/bip32-ed25519#0949df01b5c93885339bc28116690292088f6134" + resolved "git+https://github.com/Zondax/bip32-ed25519.git#0949df01b5c93885339bc28116690292088f6134" dependencies: bn.js "^5.1.1" elliptic "^6.4.1" @@ -2662,7 +2653,7 @@ brorand@^1.1.0: resolved "https://registry.yarnpkg.com/brorand/-/brorand-1.1.0.tgz#12c25efe40a45e3c323eb8675a0a0ce57b22371f" integrity sha512-cKV8tMCEpQs4hK/ik71d6LrPOnpkpGBR0wzxqr68g2m/LB2GxVYQroAjMJZRVM1Y4BCjCKc3vAamxSzOY2RP+w== -browserslist@^4.21.10, browserslist@^4.21.9: +browserslist@^4.21.9, browserslist@^4.22.1: version "4.22.1" resolved "https://registry.yarnpkg.com/browserslist/-/browserslist-4.22.1.tgz#ba91958d1a59b87dab6fed8dfbcb3da5e2e9c619" integrity sha512-FEVc202+2iuClEhZhrWy6ZiAcRLvNMyYcxZ8raemul1DYVOVdFsbqckWLdsixQZCpJlwe77Z3UTalE7jsjnKfQ== @@ -2739,9 +2730,9 @@ camelize@^1.0.0: integrity sha512-dU+Tx2fsypxTgtLoE36npi3UqcjSSMNYfkqgmoEhtZrraP5VWq0K7FkWVTYa8eMPtnU/G2txVsfdCJTn9uzpuQ== caniuse-lite@^1.0.30001541: - version "1.0.30001541" - resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001541.tgz#b1aef0fadd87fb72db4dcb55d220eae17b81cdb1" - integrity sha512-bLOsqxDgTqUBkzxbNlSBt8annkDpQB9NdzdTbO2ooJ+eC/IQcvDspDc058g84ejCelF7vHUx57KIOjEecOHXaw== + version "1.0.30001546" + resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001546.tgz#10fdad03436cfe3cc632d3af7a99a0fb497407f0" + integrity sha512-zvtSJwuQFpewSyRrI3AsftF6rM0X80mZkChIt1spBGEvRglCrjTniXvinc8JKRoqTwXAgvqTImaN9igfSMtUBw== chai@^4.3.10: version "4.3.10" @@ -2889,11 +2880,11 @@ convert-source-map@^2.0.0: integrity sha512-Kvp459HrV2FEJ1CAsi1Ku+MY3kasH19TFykTz2xWmMeq6bk2NU3XXvfJ+Q61m0xktWwt+1HSYf3JZsTms3aRJg== core-js-compat@^3.31.0, core-js-compat@^3.32.2: - version "3.32.2" - resolved "https://registry.yarnpkg.com/core-js-compat/-/core-js-compat-3.32.2.tgz#8047d1a8b3ac4e639f0d4f66d4431aa3b16e004c" - integrity sha512-+GjlguTDINOijtVRUxrQOv3kfu9rl+qPNdX2LTbJ/ZyVTuxK+ksVSAGX1nHstu4hrv1En/uPTtWgq2gI5wt4AQ== + version "3.33.0" + resolved "https://registry.yarnpkg.com/core-js-compat/-/core-js-compat-3.33.0.tgz#24aa230b228406450b2277b7c8bfebae932df966" + integrity sha512-0w4LcLXsVEuNkIqwjjf9rjCoPhK8uqA4tMRh4Ge26vfLtUutshn+aRJU21I9LCJlh2QQHfisNToLjw1XEJLTWw== dependencies: - browserslist "^4.21.10" + browserslist "^4.22.1" cosmiconfig@^8.1.3: version "8.3.6" @@ -3073,9 +3064,9 @@ dot-case@^3.0.4: tslib "^2.0.3" electron-to-chromium@^1.4.535: - version "1.4.536" - resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.536.tgz#ebdf960fbc27fb8bd0b0dfa9a899cc333bb15f1c" - integrity sha512-L4VgC/76m6y8WVCgnw5kJy/xs7hXrViCFdNKVG8Y7B2isfwrFryFyJzumh3ugxhd/oB1uEaEEvRdmeLrnd7OFA== + version "1.4.544" + resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.544.tgz#fcb156d83f0ee6e4c9d030c6fedb2a37594f3abf" + integrity sha512-54z7squS1FyFRSUqq/knOFSptjjogLZXbKcYk3B0qkE1KZzvqASwRZnY2KzZQJqIYLVD38XZeoiMRflYSwyO4w== elliptic@^6.4.1: version "6.5.4" @@ -3654,15 +3645,15 @@ find-up@^5.0.0: path-exists "^4.0.0" flat-cache@^3.0.4: - version "3.1.0" - resolved "https://registry.yarnpkg.com/flat-cache/-/flat-cache-3.1.0.tgz#0e54ab4a1a60fe87e2946b6b00657f1c99e1af3f" - integrity sha512-OHx4Qwrrt0E4jEIcI5/Xb+f+QmJYNj2rrK8wiIdQOIrB9WrrJL8cjZvXdXuBTkkEwEqLycb5BeZDV1o2i9bTew== + version "3.1.1" + resolved "https://registry.yarnpkg.com/flat-cache/-/flat-cache-3.1.1.tgz#a02a15fdec25a8f844ff7cc658f03dd99eb4609b" + integrity sha512-/qM2b3LUIaIgviBQovTLvijfyOQXPtSRnRK26ksj2J7rzPIecePUIpJsZ4T02Qg+xiAEKIs5K8dsHEd+VaKa/Q== dependencies: - flatted "^3.2.7" + flatted "^3.2.9" keyv "^4.5.3" rimraf "^3.0.2" -flatted@^3.2.7: +flatted@^3.2.9: version "3.2.9" resolved "https://registry.yarnpkg.com/flatted/-/flatted-3.2.9.tgz#7eb4c67ca1ba34232ca9d2d93e9886e611ad7daf" integrity sha512-36yxDn5H7OFZQla0/jFJmbIKTdZAQHngCedGxiMmpNfEZM0sdEeT+WczLQrjK6D7o2aiyLYDnkw0R3JK0Qv1RQ== @@ -3829,9 +3820,9 @@ globals@^11.1.0: integrity sha512-WOBp/EEGUiIsJSp7wcv/y6MO+lV9UoncWqxuFfm8eBwzWNgyfBd6Gz+IeKQ9jCmyhoH99g15M3T+QaVHFjizVA== globals@^13.19.0: - version "13.22.0" - resolved "https://registry.yarnpkg.com/globals/-/globals-13.22.0.tgz#0c9fcb9c48a2494fbb5edbfee644285543eba9d8" - integrity sha512-H1Ddc/PbZHTDVJSnj8kWptIRSD6AM3pK+mKytuIVF4uoBV7rshFlhhvA58ceJ5wp3Er58w6zj7bykMpYXt3ETw== + version "13.23.0" + resolved "https://registry.yarnpkg.com/globals/-/globals-13.23.0.tgz#ef31673c926a0976e1f61dab4dca57e0c0a8af02" + integrity sha512-XAmF0RjlrjY23MA51q3HltdlGxUpXPvg0GioKiD9X6HD28iMjo2dKC8Vqwm7lne4GNr78+RHTfliktR6ZH09wA== dependencies: type-fest "^0.20.2" @@ -3927,11 +3918,9 @@ has-tostringtag@^1.0.0: has-symbols "^1.0.2" has@^1.0.3: - version "1.0.3" - resolved "https://registry.yarnpkg.com/has/-/has-1.0.3.tgz#722d7cbfc1f6aa8241f16dd814e011e1f41e8796" - integrity sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw== - dependencies: - function-bind "^1.1.1" + version "1.0.4" + resolved "https://registry.yarnpkg.com/has/-/has-1.0.4.tgz#2eb2860e000011dae4f1406a86fe80e530fb2ec6" + integrity sha512-qdSAmqLF6209RFj4VVItywPMbm3vWylknmB3nvNiUIs72xAimcM8nVYxYr7ncvZq5qzk9MKIZR8ijqD/1QuYjQ== hash-base@^3.0.0: version "3.1.0" @@ -5679,9 +5668,9 @@ tinypool@^0.7.0: integrity sha512-zSYNUlYSMhJ6Zdou4cJwo/p7w5nmAH17GRfU/ui3ctvjXFErXXkruT4MWW6poDeXgCaIBlGLrfU6TbTXxyGMww== tinyspy@^2.1.1: - version "2.1.1" - resolved "https://registry.yarnpkg.com/tinyspy/-/tinyspy-2.1.1.tgz#9e6371b00c259e5c5b301917ca18c01d40ae558c" - integrity sha512-XPJL2uSzcOyBMky6OFrusqWlzfFrXtE0hPuMgW8A2HmaqrPo4ZQHRN/V0QXN3FSjKxpsbRrFc5LI7KOwBsT1/w== + version "2.2.0" + resolved "https://registry.yarnpkg.com/tinyspy/-/tinyspy-2.2.0.tgz#9dc04b072746520b432f77ea2c2d17933de5d6ce" + integrity sha512-d2eda04AN/cPOR89F7Xv5bK/jrQEhmcLFe6HFldoeO9AJtps+fqEnh486vnT/8y4bw38pSyxDcTCAq+Ks2aJTg== titleize@^3.0.0: version "3.0.0" @@ -6032,9 +6021,9 @@ vscode-languageserver@^7.0.0: vscode-languageserver-protocol "3.16.0" vscode-uri@^3.0.2: - version "3.0.7" - resolved "https://registry.yarnpkg.com/vscode-uri/-/vscode-uri-3.0.7.tgz#6d19fef387ee6b46c479e5fb00870e15e58c1eb8" - integrity sha512-eOpPHogvorZRobNqJGhapa0JdwaxpjVvyBp0QIUMRMSf8ZAlqOdEquKuRmw9Qwu0qXtJIWqFtMkmvJjUZmMjVA== + version "3.0.8" + resolved "https://registry.yarnpkg.com/vscode-uri/-/vscode-uri-3.0.8.tgz#1770938d3e72588659a172d0fd4642780083ff9f" + integrity sha512-AyFQ0EVmsOZOlAnxoFOGOq1SQDWAB7C6aqMGS23svWAllfOaxbuFvcT8D1i8z3Gyn8fraVeZNNmN6e9bxxXkKw== web-streams-polyfill@^3.0.3: version "3.2.1"