fix(governance): clear wallet state if user changes to a non existent party (#3813)
This commit is contained in:
parent
34400be18a
commit
653688c1dd
@ -52,6 +52,7 @@ import {
|
|||||||
} from './components/telemetry-dialog/telemetry-dialog';
|
} from './components/telemetry-dialog/telemetry-dialog';
|
||||||
import { useLocalStorage } from '@vegaprotocol/react-helpers';
|
import { useLocalStorage } from '@vegaprotocol/react-helpers';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
import { isPartyNotFoundError } from './lib/party';
|
||||||
|
|
||||||
const cache: InMemoryCacheConfig = {
|
const cache: InMemoryCacheConfig = {
|
||||||
typePolicies: {
|
typePolicies: {
|
||||||
@ -219,9 +220,8 @@ const AppContainer = () => {
|
|||||||
const transaction = event.transaction;
|
const transaction = event.transaction;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
(errorIsString && error.includes('failed to get party ID')) ||
|
(errorIsString && isPartyNotFoundError({ message: error })) ||
|
||||||
(errorIsObject &&
|
(errorIsObject && isPartyNotFoundError(error))
|
||||||
error?.message?.includes('failed to get party ID'))
|
|
||||||
) {
|
) {
|
||||||
// This error is caused by a pubkey making an API request before
|
// This error is caused by a pubkey making an API request before
|
||||||
// it has interacted with the chain. This isn't needed in Sentry.
|
// it has interacted with the chain. This isn't needed in Sentry.
|
||||||
|
@ -26,6 +26,7 @@ import type {
|
|||||||
WalletDelegationFieldsFragment,
|
WalletDelegationFieldsFragment,
|
||||||
} from './__generated__/Delegations';
|
} from './__generated__/Delegations';
|
||||||
import { DelegationsDocument } from './__generated__/Delegations';
|
import { DelegationsDocument } from './__generated__/Delegations';
|
||||||
|
import { isPartyNotFoundError } from '../../lib/party';
|
||||||
|
|
||||||
export const usePollForDelegations = () => {
|
export const usePollForDelegations = () => {
|
||||||
const { token: vegaToken } = useContracts();
|
const { token: vegaToken } = useContracts();
|
||||||
@ -75,6 +76,7 @@ export const usePollForDelegations = () => {
|
|||||||
})
|
})
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
if (!mounted) return;
|
if (!mounted) return;
|
||||||
|
|
||||||
const canonisedDelegations = removePaginationWrapper(
|
const canonisedDelegations = removePaginationWrapper(
|
||||||
res.data.party?.delegationsConnection?.edges
|
res.data.party?.delegationsConnection?.edges
|
||||||
);
|
);
|
||||||
@ -203,6 +205,15 @@ export const usePollForDelegations = () => {
|
|||||||
setDelegatedNodes(delegatedAmounts);
|
setDelegatedNodes(delegatedAmounts);
|
||||||
})
|
})
|
||||||
.catch((err: Error) => {
|
.catch((err: Error) => {
|
||||||
|
// if party isn't found, dont log to Sentry, just clear state as, user
|
||||||
|
// will not have any delagations or accounts
|
||||||
|
if (isPartyNotFoundError(err)) {
|
||||||
|
setDelegations([]);
|
||||||
|
setAccounts([]);
|
||||||
|
setDelegatedNodes([]);
|
||||||
|
setCurrentStakeAvailable(new BigNumber(0));
|
||||||
|
return;
|
||||||
|
}
|
||||||
Sentry.captureException(err);
|
Sentry.captureException(err);
|
||||||
// If query fails stop interval. Its almost certain that the query
|
// If query fails stop interval. Its almost certain that the query
|
||||||
// will just continue to fail
|
// will just continue to fail
|
||||||
|
8
apps/governance/src/lib/party.ts
Normal file
8
apps/governance/src/lib/party.ts
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
export const PARTY_NOT_FOUND = 'failed to get party for ID';
|
||||||
|
|
||||||
|
export const isPartyNotFoundError = (error: { message: string }) => {
|
||||||
|
if (error.message.includes(PARTY_NOT_FOUND)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
};
|
@ -9,6 +9,7 @@ import { usePreviousEpochQuery } from '../__generated__/PreviousEpoch';
|
|||||||
import type { ReactElement } from 'react';
|
import type { ReactElement } from 'react';
|
||||||
import type { StakingQuery } from '../__generated__/Staking';
|
import type { StakingQuery } from '../__generated__/Staking';
|
||||||
import type { PreviousEpochQuery } from '../__generated__/PreviousEpoch';
|
import type { PreviousEpochQuery } from '../__generated__/PreviousEpoch';
|
||||||
|
import { isPartyNotFoundError } from '../../../lib/party';
|
||||||
|
|
||||||
// TODO should only request a single node. When migrating from deprecated APIs we should address this.
|
// TODO should only request a single node. When migrating from deprecated APIs we should address this.
|
||||||
|
|
||||||
@ -50,7 +51,7 @@ export const NodeContainer = ({
|
|||||||
|
|
||||||
useRefreshAfterEpoch(data?.epoch.timestamps.expiry, refetch);
|
useRefreshAfterEpoch(data?.epoch.timestamps.expiry, refetch);
|
||||||
|
|
||||||
if (error && !error.message.includes('failed to get party for ID')) {
|
if (error && !isPartyNotFoundError(error)) {
|
||||||
return (
|
return (
|
||||||
<Callout intent={Intent.Danger} title={t('Something went wrong')}>
|
<Callout intent={Intent.Danger} title={t('Something went wrong')}>
|
||||||
<pre>
|
<pre>
|
||||||
|
Loading…
Reference in New Issue
Block a user