diff --git a/packages/snapshot/src/hooks/actions/useCreateProposal.ts b/packages/snapshot/src/hooks/actions/useCreateProposal.ts index 42943703..c4edd31f 100644 --- a/packages/snapshot/src/hooks/actions/useCreateProposal.ts +++ b/packages/snapshot/src/hooks/actions/useCreateProposal.ts @@ -3,7 +3,7 @@ import snapshot from '@snapshot-labs/snapshot.js' import { useEthersSigner } from './useEthersSigner' import { ChainSnapshotHub } from '@dae/chains' import { Proposal } from '@snapshot-labs/snapshot.js/dist/sign/types' -import { useHookState } from './useHookState' +import { useSnapshotHookState } from './useSnapshotHookState' type ProposalCreationResult = { id: string @@ -20,7 +20,7 @@ export const useCreateProposal = (snapshotSpaceENS: string | undefined) => { const { data: blockNumber } = useBlockNumber() const { isSuccess, isValidating, isLoading, isError, error, ...state } = - useHookState() + useSnapshotHookState() const spaceNetwork = chain!.id as keyof typeof ChainSnapshotHub const hub = ChainSnapshotHub[spaceNetwork] diff --git a/packages/snapshot/src/hooks/actions/useCreateSnapshotSpace.ts b/packages/snapshot/src/hooks/actions/useCreateSnapshotSpace.ts index e356b348..820e4913 100644 --- a/packages/snapshot/src/hooks/actions/useCreateSnapshotSpace.ts +++ b/packages/snapshot/src/hooks/actions/useCreateSnapshotSpace.ts @@ -3,7 +3,7 @@ import snapshot from '@snapshot-labs/snapshot.js' import { useEthersSigner } from './useEthersSigner' import { ChainSnapshotHub } from '@dae/chains' import { type VotingStrategy } from '@dae/types' -import { useHookState } from './useHookState' +import { useSnapshotHookState } from './useSnapshotHookState' import { SpaceConfig } from '../../types' import { mutate } from 'swr' @@ -80,7 +80,7 @@ export const useCreateSnapshotSpace = () => { const { address } = useAccount() const { chain } = useNetwork() const { isSuccess, isValidating, isLoading, isError, error, ...state } = - useHookState() + useSnapshotHookState() const spaceNetwork = chain!.id as keyof typeof ChainSnapshotHub const hub = ChainSnapshotHub[spaceNetwork] diff --git a/packages/snapshot/src/hooks/actions/useEditSnapshotSpace.ts b/packages/snapshot/src/hooks/actions/useEditSnapshotSpace.ts index e70cbfe1..b672e85d 100644 --- a/packages/snapshot/src/hooks/actions/useEditSnapshotSpace.ts +++ b/packages/snapshot/src/hooks/actions/useEditSnapshotSpace.ts @@ -2,7 +2,7 @@ import { Address, useAccount } from 'wagmi' import snapshot from '@snapshot-labs/snapshot.js' import { useEthersSigner } from './useEthersSigner' import { ChainSnapshotHub } from '@dae/chains' -import { useHookState } from './useHookState' +import { useSnapshotHookState } from './useSnapshotHookState' import { useCourseSpace } from '../api' import { mutate } from 'swr' @@ -11,7 +11,7 @@ export const useEditSnapshotSpace = ( chainId: number | undefined, ) => { const { isSuccess, isValidating, isLoading, isError, error, ...state } = - useHookState() + useSnapshotHookState() const { address } = useAccount() const spaceNetwork = chainId as keyof typeof ChainSnapshotHub const hub = ChainSnapshotHub[spaceNetwork] diff --git a/packages/snapshot/src/hooks/actions/useHookState.ts b/packages/snapshot/src/hooks/actions/useSnapshotHookState.ts similarity index 75% rename from packages/snapshot/src/hooks/actions/useHookState.ts rename to packages/snapshot/src/hooks/actions/useSnapshotHookState.ts index f30f2131..c6da01df 100644 --- a/packages/snapshot/src/hooks/actions/useHookState.ts +++ b/packages/snapshot/src/hooks/actions/useSnapshotHookState.ts @@ -8,7 +8,7 @@ type HookState = { isValidating: boolean } -export function useHookState() { +export function useSnapshotHookState() { const [state, setState] = useState({ error: null, isError: false, @@ -39,13 +39,22 @@ export function useHookState() { const handleError = (error: unknown) => { let parsedError: Error - switch (true) { - case error instanceof Error: - parsedError = error as Error - break - default: - parsedError = new Error('An error occurred') + + if ( + error && + typeof error === 'object' && + 'error' in error && + 'error_description' in error + ) { + parsedError = new Error( + `Snapshot service returned an error: ${ + error.error_description as string + }.`, + ) + } else { + parsedError = new Error('An error occurred.') } + setState({ ...state, isSuccess: false, diff --git a/packages/snapshot/src/hooks/actions/useVoteProposal.ts b/packages/snapshot/src/hooks/actions/useVoteProposal.ts index 1568c370..09f283ab 100644 --- a/packages/snapshot/src/hooks/actions/useVoteProposal.ts +++ b/packages/snapshot/src/hooks/actions/useVoteProposal.ts @@ -3,7 +3,7 @@ import snapshot from '@snapshot-labs/snapshot.js' import { useAccount } from 'wagmi' import { ChainSnapshotHub } from '@dae/chains' import { ProposalType } from '@snapshot-labs/snapshot.js/dist/sign/types' -import { useHookState } from './useHookState' +import { useSnapshotHookState } from './useSnapshotHookState' import { mutate } from 'swr' export const useVotePropsal = ( @@ -14,7 +14,7 @@ export const useVotePropsal = ( ) => { const { address } = useAccount() const { isSuccess, isValidating, isLoading, isError, error, ...state } = - useHookState() + useSnapshotHookState() const hub = ChainSnapshotHub[spaceNetwork] const snapshotClient = new snapshot.Client712(hub)