diff --git a/packages/app/src/contexts/Pools/ActivePool/defaults.ts b/packages/app/src/contexts/Pools/ActivePool/defaults.ts index 2a81abe8ed..1a05922519 100644 --- a/packages/app/src/contexts/Pools/ActivePool/defaults.ts +++ b/packages/app/src/contexts/Pools/ActivePool/defaults.ts @@ -19,6 +19,7 @@ export const defaultPoolNominations = { } export const defaultActivePoolContext: ActivePoolContextState = { + inPool: () => false, isBonding: () => false, isNominator: () => false, isOwner: () => false, diff --git a/packages/app/src/contexts/Pools/ActivePool/index.tsx b/packages/app/src/contexts/Pools/ActivePool/index.tsx index b2ed0541d8..7f868635a9 100644 --- a/packages/app/src/contexts/Pools/ActivePool/index.tsx +++ b/packages/app/src/contexts/Pools/ActivePool/index.tsx @@ -119,6 +119,9 @@ export const ActivePoolProvider = ({ children }: { children: ReactNode }) => { return String(membership?.poolId || '') === p } + // Returns whether the active account is in a pool. + const inPool = () => !!membership + // Returns whether the active account is the depositor of the active pool. const isDepositor = () => { const roles = activePool?.bondedPool?.roles @@ -170,6 +173,7 @@ export const ActivePoolProvider = ({ children }: { children: ReactNode }) => { boolean isBonding: () => boolean isNominator: () => boolean isOwner: () => boolean diff --git a/packages/app/src/library/CallToAction/index.tsx b/packages/app/src/library/CallToAction/index.tsx index 6c88ec2be9..e26c37d19c 100644 --- a/packages/app/src/library/CallToAction/index.tsx +++ b/packages/app/src/library/CallToAction/index.tsx @@ -145,8 +145,6 @@ export const CallToActionWrapper = styled.div` } &.disabled { - opacity: 0.5; - &:hover { filter: none; } @@ -197,13 +195,14 @@ export const CallToActionWrapper = styled.div` margin-left: 0.75rem; } - &:disabled { - cursor: default; - } - > svg { margin: 0 0.75rem; } + + &:disabled { + opacity: var(--opacity-disabled); + cursor: default; + } } &.inactive { @@ -211,6 +210,11 @@ export const CallToActionWrapper = styled.div` cursor: default; } } + + &:disabled { + opacity: var(--opacity-disabled); + cursor: default; + } } } } diff --git a/packages/app/src/library/SideMenu/Main.tsx b/packages/app/src/library/SideMenu/Main.tsx index 6458949619..482b5bc344 100644 --- a/packages/app/src/library/SideMenu/Main.tsx +++ b/packages/app/src/library/SideMenu/Main.tsx @@ -9,6 +9,7 @@ import { useBalances } from 'contexts/Balances' import { useBonded } from 'contexts/Bonded' import { useImportedAccounts } from 'contexts/Connect/ImportedAccounts' import { useNetwork } from 'contexts/Network' +import { useActivePool } from 'contexts/Pools/ActivePool' import { useSetup } from 'contexts/Setup' import type { SetupContextInterface } from 'contexts/Setup/types' import { useStaking } from 'contexts/Staking' @@ -26,12 +27,13 @@ export const Main = () => { const { t, i18n } = useTranslation('base') const { syncing } = useSyncing() const { pathname } = useLocation() + const { inPool } = useActivePool() const { networkData } = useNetwork() + const { getNominations } = useBalances() const { getBondedAccount } = useBonded() const { accounts } = useImportedAccounts() const { formatWithPrefs } = useValidators() const { activeAccount } = useActiveAccounts() - const { getPoolMembership, getNominations } = useBalances() const { getPoolSetupPercent, getNominatorSetupPercent, @@ -39,7 +41,6 @@ export const Main = () => { const { sideMenuMinimised }: UIContextInterface = useUi() const { inSetup: inNominatorSetup, addressDifferentToStash } = useStaking() - const membership = getPoolMembership(activeAccount) const controller = getBondedAccount(activeAccount) const controllerDifferentToStash = addressDifferentToStash(controller) @@ -99,9 +100,8 @@ export const Main = () => { if (uri === `${import.meta.env.BASE_URL}pools`) { // configure Pools action - const inPool = membership - if (inPool) { + if (inPool()) { pages[i].action = { type: 'text', status: 'success', @@ -122,7 +122,7 @@ export const Main = () => { accounts, controllerDifferentToStash, syncing, - membership, + inPool(), inNominatorSetup(), getNominatorSetupPercent(activeAccount), getPoolSetupPercent(activeAccount), diff --git a/packages/app/src/library/StatusLabel/index.tsx b/packages/app/src/library/StatusLabel/index.tsx index b22662c06a..1f7b62dc5a 100644 --- a/packages/app/src/library/StatusLabel/index.tsx +++ b/packages/app/src/library/StatusLabel/index.tsx @@ -3,10 +3,9 @@ import { faExclamationTriangle } from '@fortawesome/free-solid-svg-icons' import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' -import { useActiveAccounts } from 'contexts/ActiveAccounts' -import { useBalances } from 'contexts/Balances' import { useHelp } from 'contexts/Help' import { usePlugins } from 'contexts/Plugins' +import { useActivePool } from 'contexts/Pools/ActivePool' import { useStaking } from 'contexts/Staking' import { useSyncing } from 'hooks/useSyncing' import { ButtonHelp } from 'ui-buttons' @@ -25,13 +24,11 @@ export const StatusLabel = ({ const { syncing } = useSyncing() const { plugins } = usePlugins() const { inSetup } = useStaking() - const { getPoolMembership } = useBalances() - const { activeAccount } = useActiveAccounts() - const membership = getPoolMembership(activeAccount) + const { inPool } = useActivePool() // syncing or not staking if (status === 'sync_or_setup') { - if (syncing || !inSetup() || membership !== null) { + if (syncing || !inSetup() || inPool()) { return null } } diff --git a/packages/app/src/overlay/canvas/JoinPool/Overview/index.tsx b/packages/app/src/overlay/canvas/JoinPool/Overview/index.tsx index 7032147e0f..7b5b3af600 100644 --- a/packages/app/src/overlay/canvas/JoinPool/Overview/index.tsx +++ b/packages/app/src/overlay/canvas/JoinPool/Overview/index.tsx @@ -4,7 +4,8 @@ import { JoinForm } from './JoinForm' import { useActiveAccounts } from 'contexts/ActiveAccounts' -import { useBalances } from 'contexts/Balances' +import { useActivePool } from 'contexts/Pools/ActivePool' +import { useStaking } from 'contexts/Staking' import { GraphLayoutWrapper } from '../Wrappers' import type { OverviewSectionProps } from '../types' import { Addresses } from './Addresses' @@ -13,7 +14,8 @@ import { Roles } from './Roles' import { Stats } from './Stats' export const Overview = (props: OverviewSectionProps) => { - const { getPoolMembership } = useBalances() + const { inSetup } = useStaking() + const { inPool } = useActivePool() const { activeAccount } = useActiveAccounts() const { @@ -21,9 +23,7 @@ export const Overview = (props: OverviewSectionProps) => { } = props const showJoinForm = - activeAccount !== null && - state === 'Open' && - getPoolMembership(activeAccount) === null + activeAccount !== null && state === 'Open' && !inPool() && !inSetup() return ( <> diff --git a/packages/app/src/pages/Nominate/Active/Status/NewNominator.tsx b/packages/app/src/pages/Nominate/Active/Status/NewNominator.tsx index a521879c55..e2187b0b8d 100644 --- a/packages/app/src/pages/Nominate/Active/Status/NewNominator.tsx +++ b/packages/app/src/pages/Nominate/Active/Status/NewNominator.tsx @@ -6,6 +6,7 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' import { useActiveAccounts } from 'contexts/ActiveAccounts' import { useApi } from 'contexts/Api' import { useImportedAccounts } from 'contexts/Connect/ImportedAccounts' +import { useActivePool } from 'contexts/Pools/ActivePool' import { useOverlay } from 'kits/Overlay/Provider' import { CallToActionWrapper } from 'library/CallToAction' import { CallToActionLoader } from 'library/Loader/CallToAction' @@ -17,12 +18,13 @@ export const NewNominator = ({ syncing }: NewNominatorProps) => { const { t } = useTranslation() const { isReady } = useApi() const navigate = useNavigate() + const { inPool } = useActivePool() const { openCanvas } = useOverlay().canvas const { activeAccount } = useActiveAccounts() const { isReadOnlyAccount } = useImportedAccounts() const nominateButtonDisabled = - !isReady || !activeAccount || isReadOnlyAccount(activeAccount) + !isReady || !activeAccount || isReadOnlyAccount(activeAccount) || inPool() return ( diff --git a/packages/app/src/pages/Nominate/Active/Status/NominationStatus.tsx b/packages/app/src/pages/Nominate/Active/Status/NominationStatus.tsx index a71c69f8d5..dd5f3f61b7 100644 --- a/packages/app/src/pages/Nominate/Active/Status/NominationStatus.tsx +++ b/packages/app/src/pages/Nominate/Active/Status/NominationStatus.tsx @@ -14,6 +14,7 @@ import { useUnstaking } from 'hooks/useUnstaking' import { useOverlay } from 'kits/Overlay/Provider' import { Stat } from 'library/Stat' import { useTranslation } from 'react-i18next' +import { useActivePool } from '../../../../contexts/Pools/ActivePool' export const NominationStatus = ({ showButtons = true, @@ -23,19 +24,20 @@ export const NominationStatus = ({ buttonType?: string }) => { const { t } = useTranslation('pages') - const { inSetup } = useStaking() - const { openModal } = useOverlay().modal - const { getBondedAccount } = useBonded() - const { syncing } = useSyncing(['initialization', 'era-stakers', 'balances']) const { isReady, networkMetrics: { fastUnstakeErasToCheckPerBlock }, } = useApi() + const { inSetup } = useStaking() + const { inPool } = useActivePool() + const { openModal } = useOverlay().modal + const { getBondedAccount } = useBonded() const { activeAccount } = useActiveAccounts() const { checking, isExposed } = useFastUnstake() const { isReadOnlyAccount } = useImportedAccounts() const { getNominationStatus } = useNominationStatus() const { getFastUnstakeText, isUnstaking } = useUnstaking() + const { syncing } = useSyncing(['initialization', 'era-stakers', 'balances']) const fastUnstakeText = getFastUnstakeText() const controller = getBondedAccount(activeAccount) @@ -65,7 +67,7 @@ export const NominationStatus = ({ { const { inSetup } = useStaking() const { syncing } = useSyncing() const { containerRefs } = useUi() + const { inPool } = useActivePool() const { pluginEnabled } = usePlugins() - const { getPoolMembership } = useBalances() - const { activeAccount } = useActiveAccounts() - const membership = getPoolMembership(activeAccount) - const nominating = !inSetup() - const inPool = membership !== null - const staking = nominating || inPool + const staking = !inSetup() || inPool const notStaking = !syncing && !staking const [lastReward, setLastReward] = useState() @@ -121,8 +116,8 @@ export const Payouts = () => { > {staking && pluginEnabled('staking_api') ? ( diff --git a/packages/app/src/pages/Overview/StakeStatus/Tips/index.tsx b/packages/app/src/pages/Overview/StakeStatus/Tips/index.tsx index 4c08247068..bc216035b2 100644 --- a/packages/app/src/pages/Overview/StakeStatus/Tips/index.tsx +++ b/packages/app/src/pages/Overview/StakeStatus/Tips/index.tsx @@ -8,7 +8,6 @@ import { TipsConfig } from 'config/tips' import { TipsThresholdMedium, TipsThresholdSmall } from 'consts' import { useActiveAccounts } from 'contexts/ActiveAccounts' import { useApi } from 'contexts/Api' -import { useBalances } from 'contexts/Balances' import { useNetwork } from 'contexts/Network' import { useActivePool } from 'contexts/Pools/ActivePool' import { useStaking } from 'contexts/Staking' @@ -30,15 +29,14 @@ export const Tips = () => { const { stakingMetrics: { minNominatorBond }, } = useApi() + const { inPool } = useActivePool() const { isOwner } = useActivePool() const { isNominating } = useStaking() - const { getPoolMembership } = useBalances() const { activeAccount } = useActiveAccounts() const { fillVariables } = useFillVariables() const { syncing } = useSyncing(['initialization']) const { feeReserve, getTransferOptions } = useTransferOptions() - const membership = getPoolMembership(activeAccount) const transferOptions = getTransferOptions(activeAccount) // multiple tips per row is currently turned off. @@ -101,7 +99,7 @@ export const Tips = () => { const segments: AnyJson = [] if (!activeAccount) { segments.push(1) - } else if (!isNominating() && !membership) { + } else if (!isNominating() && !inPool()) { if ( transferOptions.freeBalance .minus(feeReserve) @@ -116,7 +114,7 @@ export const Tips = () => { if (isNominating()) { segments.push(5) } - if (membership) { + if (inPool()) { if (!isOwner()) { segments.push(6) } else { diff --git a/packages/app/src/pages/Overview/StakeStatus/index.tsx b/packages/app/src/pages/Overview/StakeStatus/index.tsx index a71e639888..cd8e6083b6 100644 --- a/packages/app/src/pages/Overview/StakeStatus/index.tsx +++ b/packages/app/src/pages/Overview/StakeStatus/index.tsx @@ -2,6 +2,8 @@ // SPDX-License-Identifier: GPL-3.0-only import { usePlugins } from 'contexts/Plugins' +import { useActivePool } from 'contexts/Pools/ActivePool' +import { useStaking } from 'contexts/Staking' import { CardWrapper } from 'library/Card/Wrappers' import { NominationStatus } from 'pages/Nominate/Active/Status/NominationStatus' import { MembershipStatus } from 'pages/Pools/Status/MembershipStatus' @@ -11,21 +13,35 @@ import { StatusWrapper } from './Wrappers' export const StakeStatus = () => { const { plugins } = usePlugins() + const { inPool } = useActivePool() + const { inSetup } = useStaking() + const showTips = plugins.includes('tips') + const notStaking = !inPool() && inSetup() + const showNominate = notStaking || !inSetup() + const showMembership = notStaking || inPool() return ( - -
- -
-
- -
- -
-
+ {showNominate && ( + +
+ +
+
+ )} + {showMembership && ( + +
+ +
+
+ )}
{showTips ? : null} diff --git a/packages/app/src/pages/Payouts/index.tsx b/packages/app/src/pages/Payouts/index.tsx index 57847c3df1..9bc74f7b4b 100644 --- a/packages/app/src/pages/Payouts/index.tsx +++ b/packages/app/src/pages/Payouts/index.tsx @@ -3,10 +3,9 @@ import { useSize } from '@w3ux/hooks' import type { AnyApi, PageProps } from 'common-types' -import { useActiveAccounts } from 'contexts/ActiveAccounts' -import { useBalances } from 'contexts/Balances' import { useHelp } from 'contexts/Help' import { usePlugins } from 'contexts/Plugins' +import { useActivePool } from 'contexts/Pools/ActivePool' import { useStaking } from 'contexts/Staking' import { useUi } from 'contexts/UI' import { useSyncing } from 'hooks/useSyncing' @@ -35,13 +34,10 @@ export const Payouts = ({ page: { key } }: PageProps) => { const { inSetup } = useStaking() const { syncing } = useSyncing() const { containerRefs } = useUi() + const { inPool } = useActivePool() const { pluginEnabled } = usePlugins() - const { getPoolMembership } = useBalances() - const { activeAccount } = useActiveAccounts() - const membership = getPoolMembership(activeAccount) const nominating = !inSetup() - const inPool = membership !== null const staking = nominating || inPool const notStaking = !syncing && !staking @@ -124,7 +120,7 @@ export const Payouts = ({ page: { key } }: PageProps) => { {staking && pluginEnabled('staking_api') ? ( ) : ( diff --git a/packages/app/src/pages/Pools/Status/MembershipStatus.tsx b/packages/app/src/pages/Pools/Status/MembershipStatus.tsx index ff15738480..a69391910c 100644 --- a/packages/app/src/pages/Pools/Status/MembershipStatus.tsx +++ b/packages/app/src/pages/Pools/Status/MembershipStatus.tsx @@ -8,6 +8,7 @@ import { useImportedAccounts } from 'contexts/Connect/ImportedAccounts' import { useActivePool } from 'contexts/Pools/ActivePool' import { useBondedPools } from 'contexts/Pools/BondedPools' import { determinePoolDisplay } from 'contexts/Pools/util' +import { useStaking } from 'contexts/Staking' import { useTransferOptions } from 'contexts/TransferOptions' import { useOverlay } from 'kits/Overlay/Provider' import { Stat } from 'library/Stat' @@ -21,10 +22,11 @@ export const MembershipStatus = ({ }: MembershipStatusProps) => { const { t } = useTranslation('pages') const { isReady } = useApi() + const { inSetup } = useStaking() + const { label } = useStatusButtons() const { openModal } = useOverlay().modal const { poolsMetaData } = useBondedPools() const { activeAccount } = useActiveAccounts() - const { label } = useStatusButtons() const { isReadOnlyAccount } = useImportedAccounts() const { getTransferOptions } = useTransferOptions() const { activePool, isOwner, isBouncer, isMember } = useActivePool() @@ -81,7 +83,7 @@ export const MembershipStatus = ({ ) diff --git a/packages/app/src/pages/Pools/Status/NewMember.tsx b/packages/app/src/pages/Pools/Status/NewMember.tsx index c186779b71..3dff73e612 100644 --- a/packages/app/src/pages/Pools/Status/NewMember.tsx +++ b/packages/app/src/pages/Pools/Status/NewMember.tsx @@ -5,6 +5,7 @@ import { faUserPlus } from '@fortawesome/free-solid-svg-icons' import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' import { useJoinPools } from 'contexts/Pools/JoinPools' import { usePoolPerformance } from 'contexts/Pools/PoolPerformance' +import { useStaking } from 'contexts/Staking' import { useOverlay } from 'kits/Overlay/Provider' import { CallToActionWrapper } from 'library/CallToAction' import { CallToActionLoader } from 'library/Loader/CallToAction' @@ -17,6 +18,7 @@ import { useStatusButtons } from './useStatusButtons' export const NewMember = ({ syncing }: NewMemberProps) => { const { t } = useTranslation() + const { inSetup } = useStaking() const { poolsForJoin } = useJoinPools() const { setActiveTab } = usePoolsTabs() const { openCanvas } = useOverlay().canvas @@ -27,11 +29,12 @@ export const NewMember = ({ syncing }: NewMemberProps) => { // Get the pool performance task to determine if performance data is ready. const poolJoinPerformanceTask = getPoolPerformanceTask('pool_join') - // Alias for create button disabled state. - const createDisabled = getCreateDisabled() + // Alias for create button disabled state + const createDisabled = getCreateDisabled() || !inSetup() // Disable opening the canvas if data is not ready. - const joinButtonDisabled = getJoinDisabled() || !poolsForJoin.length + const joinButtonDisabled = + getJoinDisabled() || !poolsForJoin.length || !inSetup() return ( @@ -43,7 +46,7 @@ export const NewMember = ({ syncing }: NewMemberProps) => {