diff --git a/packages/common/src/allo-strategy-adapters/adapter.ts b/packages/common/src/allo-strategy-adapters/adapter.ts index 42ff66118..9906a1df5 100644 --- a/packages/common/src/allo-strategy-adapters/adapter.ts +++ b/packages/common/src/allo-strategy-adapters/adapter.ts @@ -1,31 +1,29 @@ import { Address, PublicClient } from "viem"; -export class AdapterError extends Error { - public readonly reason: string; - public readonly innerError?: Error; - - constructor(reason: string, innerError?: Error) { - super(reason); - this.reason = reason; - this.innerError = innerError; - } -} - -export class AdapterResponseError extends AdapterError { - constructor(reason: string, error: AdapterError) { - super(reason, error); - } -} - -export class UnknownAdapterError extends AdapterError { - constructor(strategyName: string) { - super(`Adapter not found for strategy: ${strategyName}`); - } -} +export type AdapterNotFoundError = { + type: "ADAPTER_NOT_FOUND"; + strategyName: string; + error: Error; +}; + +export type AdapterAllocationUnauthorizedError = { + type: "ADAPTER_ALLOCATION_UNAUTHORIZED"; + error: Error; +}; + +export type AdapterUnknownError = { + type: "ADAPTER_UNKNOWN_ERROR"; + error: Error; +}; + +export type AdapterErrorWrapper = + | AdapterNotFoundError + | AdapterAllocationUnauthorizedError + | AdapterUnknownError; export type AdapterResponse = | { type: "success"; value: T } - | { type: "error"; error: AdapterError }; + | { type: "error"; error: AdapterErrorWrapper }; export interface AllocationAdapter { // Returns true if the allocator can allocate to the pool. diff --git a/packages/common/src/allo-strategy-adapters/adapters/allov2.DonationVotingMerkleDistributionDirectTransferStrategy/allocation.ts b/packages/common/src/allo-strategy-adapters/adapters/allov2.QF/allocation.ts similarity index 83% rename from packages/common/src/allo-strategy-adapters/adapters/allov2.DonationVotingMerkleDistributionDirectTransferStrategy/allocation.ts rename to packages/common/src/allo-strategy-adapters/adapters/allov2.QF/allocation.ts index bcc7c21f9..26e5142b3 100644 --- a/packages/common/src/allo-strategy-adapters/adapters/allov2.DonationVotingMerkleDistributionDirectTransferStrategy/allocation.ts +++ b/packages/common/src/allo-strategy-adapters/adapters/allov2.QF/allocation.ts @@ -1,5 +1,5 @@ import { Address, PublicClient } from "viem"; -import { AdapterResponse, AdapterError } from "../../adapter"; +import { AdapterResponse } from "../../adapter"; export function canAllocate( _client: PublicClient, @@ -25,7 +25,10 @@ export function canAllocate( return resolve({ type: "error", - error: new AdapterError("you don't have a badge to vote."), + error: { + type: "ADAPTER_ALLOCATION_UNAUTHORIZED", + error: new Error("you don't have a badge to vote."), + }, }); }, 2000); }); diff --git a/packages/common/src/allo-strategy-adapters/adapters/allov2.DonationVotingMerkleDistributionDirectTransferStrategy/index.ts b/packages/common/src/allo-strategy-adapters/adapters/allov2.QF/index.ts similarity index 100% rename from packages/common/src/allo-strategy-adapters/adapters/allov2.DonationVotingMerkleDistributionDirectTransferStrategy/index.ts rename to packages/common/src/allo-strategy-adapters/adapters/allov2.QF/index.ts diff --git a/packages/common/src/allo-strategy-adapters/hooks.ts b/packages/common/src/allo-strategy-adapters/hooks.ts index fe665d246..6f5f67a71 100644 --- a/packages/common/src/allo-strategy-adapters/hooks.ts +++ b/packages/common/src/allo-strategy-adapters/hooks.ts @@ -2,11 +2,11 @@ import { Address } from "wagmi"; import { PublicClient } from "viem"; import { useState, useEffect } from "react"; import { getAllocationAdapter } from "./index"; -import { AdapterError, UnknownAdapterError } from "./adapter"; +import { AdapterErrorWrapper } from "./adapter"; type AdapterResponseWrapper = { loading: boolean; - error: Error | undefined; + error: AdapterErrorWrapper | undefined; value: T | undefined; }; @@ -17,7 +17,7 @@ export function useAdapterCanAllocate( address: Address | undefined ): AdapterResponseWrapper { const [loading, setLoading] = useState(false); - const [error, setError] = useState(); + const [error, setError] = useState(); const [value, setValue] = useState(); useEffect(() => { @@ -33,7 +33,11 @@ export function useAdapterCanAllocate( const adapter = getAllocationAdapter(strategyName); if (adapter === undefined) { - setError(new UnknownAdapterError(strategyName)); + setError({ + type: "ADAPTER_NOT_FOUND", + strategyName, + error: new Error(`Adapter not found for strategy: ${strategyName}`), + }); setLoading(false); return; } @@ -47,7 +51,7 @@ export function useAdapterCanAllocate( setError(resp.error); } }) - .catch((e: AdapterError) => { + .catch((e: AdapterErrorWrapper) => { setError(e); }) .finally(() => { diff --git a/packages/common/src/allo-strategy-adapters/index.ts b/packages/common/src/allo-strategy-adapters/index.ts index b4afb1adc..d784a2d56 100644 --- a/packages/common/src/allo-strategy-adapters/index.ts +++ b/packages/common/src/allo-strategy-adapters/index.ts @@ -1,9 +1,8 @@ import type { AllocationAdapter, Adapter } from "./adapter"; -import allov2DonationVotingMerkleDistributionDirectTransferStrategy from "./adapters/allov2.DonationVotingMerkleDistributionDirectTransferStrategy"; +import alloV2QF from "./adapters/allov2.QF"; export const adapters: { [key: string]: Adapter } = { - "allov2.DonationVotingMerkleDistributionDirectTransferStrategy": - allov2DonationVotingMerkleDistributionDirectTransferStrategy, + "allov2.DonationVotingMerkleDistributionDirectTransferStrategy": alloV2QF, }; export function getAllocationAdapter( diff --git a/packages/grant-explorer/src/features/round/ViewRoundPage.tsx b/packages/grant-explorer/src/features/round/ViewRoundPage.tsx index 339754f12..24b81d7a5 100644 --- a/packages/grant-explorer/src/features/round/ViewRoundPage.tsx +++ b/packages/grant-explorer/src/features/round/ViewRoundPage.tsx @@ -865,12 +865,22 @@ export function CartButtonToggle(props: { return
Loading...
; } - if (error) { - return
Error checking if you can allocate: {error.message}
; + if (error !== undefined) { + switch (error.type) { + case "ADAPTER_ALLOCATION_UNAUTHORIZED": + return ( +
+ You are not authorized to allocate: + {error.error.message} +
+ ); + default: + return
Something went wrong {error.error.message}
; + } } if (!canAllocate) { - return
You can't allocate
; + return
Allocation not allowed
; } return (