-
Notifications
You must be signed in to change notification settings - Fork 175
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Use
useCanFastUnstake
query (#2377)
- Loading branch information
Showing
20 changed files
with
157 additions
and
455 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright 2024 @polkadot-cloud/polkadot-staking-dashboard authors & contributors | ||
// SPDX-License-Identifier: GPL-3.0-only | ||
|
||
import { useFastUnstake } from 'contexts/FastUnstake' | ||
import { useCanFastUnstake } from 'plugin-staking-api' | ||
import { useEffect } from 'react' | ||
import type { Props } from './types' | ||
|
||
export const FastUnstakeApi = ({ activeAccount, network }: Props) => { | ||
const { setFastUnstakeStatus } = useFastUnstake() | ||
const { data, loading, error } = useCanFastUnstake({ | ||
chain: network, | ||
who: activeAccount, | ||
}) | ||
|
||
// Update fast unstake status on active account change. Must be bonding | ||
useEffect(() => { | ||
if (!loading && !error && data?.canFastUnstake) { | ||
setFastUnstakeStatus(data.canFastUnstake) | ||
} | ||
}, [JSON.stringify(data?.canFastUnstake)]) | ||
|
||
return null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright 2024 @polkadot-cloud/polkadot-staking-dashboard authors & contributors | ||
// SPDX-License-Identifier: GPL-3.0-only | ||
|
||
import { useFastUnstake } from 'contexts/FastUnstake' | ||
import { useStaking } from 'contexts/Staking' | ||
import { ApolloProvider, client } from 'plugin-staking-api' | ||
import { useEffect } from 'react' | ||
import { FastUnstakeApi } from './FastUnstakeApi' | ||
import type { Props } from './types' | ||
import { UnclaimedRewardsApi } from './UnclaimedRewardsApi' | ||
|
||
export const StakingApi = (props: Props) => { | ||
const { isBonding } = useStaking() | ||
const { setFastUnstakeStatus } = useFastUnstake() | ||
|
||
useEffect(() => { | ||
if (!isBonding()) { | ||
setFastUnstakeStatus(null) | ||
} | ||
}, [isBonding()]) | ||
|
||
return ( | ||
<ApolloProvider client={client}> | ||
<UnclaimedRewardsApi {...props} /> | ||
{isBonding() && <FastUnstakeApi {...props} />} | ||
</ApolloProvider> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Copyright 2024 @polkadot-cloud/polkadot-staking-dashboard authors & contributors | ||
// SPDX-License-Identifier: GPL-3.0-only | ||
|
||
import type { NetworkId } from 'common-types' | ||
|
||
export interface Props { | ||
activeAccount: string | ||
network: NetworkId | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.