diff --git a/packages/checkout/src/components/SequenceCheckoutProvider/ForteController.tsx b/packages/checkout/src/components/SequenceCheckoutProvider/ForteController.tsx index 38d823d62..aeccb0826 100644 --- a/packages/checkout/src/components/SequenceCheckoutProvider/ForteController.tsx +++ b/packages/checkout/src/components/SequenceCheckoutProvider/ForteController.tsx @@ -125,7 +125,10 @@ export const ForteController = ({ children }: { children: React.ReactNode }) => }, [fortePaymentData]) const checkFortePaymentStatus = async () => { - if (!fortePaymentData || isSuccess) { + if (!fortePaymentData) { + throw new Error('Forte payment data is not available. Unable to check payment status.') + } + if (isSuccess) { return } diff --git a/packages/checkout/src/hooks/useERC1155SaleContractCheckout.ts b/packages/checkout/src/hooks/useERC1155SaleContractCheckout.ts index 601ef1331..7a08ff3f7 100644 --- a/packages/checkout/src/hooks/useERC1155SaleContractCheckout.ts +++ b/packages/checkout/src/hooks/useERC1155SaleContractCheckout.ts @@ -162,9 +162,16 @@ export const useERC1155SaleContractCheckout = ({ const error = isErrorCheckoutOptions || isErrorSaleConfig const openCheckoutModal = () => { - if (isLoading || error) { - console.error('Error loading checkout options or sale config', { isLoading, error }) - return + if (isLoading) { + throw new Error('Checkout options are still loading. Please wait and try again.') + } + if (error) { + throw new Error( + 'Failed to load checkout options or sale configuration. Please check your network connection and try again.', + { + cause: error + } + ) } openSelectPaymentModal( diff --git a/packages/checkout/src/views/Checkout/PaymentMethodSelect/PayWithCrypto/index.tsx b/packages/checkout/src/views/Checkout/PaymentMethodSelect/PayWithCrypto/index.tsx index 9e87dfada..60ccce297 100644 --- a/packages/checkout/src/views/Checkout/PaymentMethodSelect/PayWithCrypto/index.tsx +++ b/packages/checkout/src/views/Checkout/PaymentMethodSelect/PayWithCrypto/index.tsx @@ -72,7 +72,12 @@ export const PayWithCryptoTab = ({ skipOnCloseCallback, isSwitchingChainRef }: P const chainId = network?.chainId || 137 const { address: userAddress, connector } = useAccount() - const { data: walletClient, isLoading: isLoadingWalletClient } = useWalletClient() + const { + data: walletClient, + isLoading: isLoadingWalletClient, + isError: isErrorWalletClient, + error: errorWalletClient + } = useWalletClient() const publicClient = usePublicClient() const indexerClient = useIndexerClient(chainId) @@ -197,9 +202,22 @@ export const PayWithCryptoTab = ({ skipOnCloseCallback, isSwitchingChainRef }: P const priceFiat = (fiatExchangeRate * Number(formattedPrice)).toFixed(2) const onPurchaseMainCurrency = async () => { - if (!walletClient || !userAddress || !publicClient || !indexerClient || !connector) { - throw new Error('Wallet client, user address, public client, indexer client, or connector is not found') - // TODO: Handle these states better + if (!walletClient || isErrorWalletClient || errorWalletClient) { + throw new Error('Wallet client is not available. Please ensure your wallet is connected.', { + cause: errorWalletClient + }) + } + if (!userAddress) { + throw new Error('User address is not available. Please ensure your wallet is connected.') + } + if (!publicClient) { + throw new Error('Public client is not available. Please check your network connection.') + } + if (!indexerClient) { + throw new Error('Indexer client is not available. Please check your network connection.') + } + if (!connector) { + throw new Error('Wallet connector is not available. Please ensure your wallet is properly connected.') } setIsPurchasing(true) @@ -309,8 +327,20 @@ export const PayWithCryptoTab = ({ skipOnCloseCallback, isSwitchingChainRef }: P } const onClickPurchaseSwap = async () => { - if (!walletClient || !userAddress || !publicClient || !userAddress || !connector || !swapQuote) { - return + if (!walletClient) { + throw new Error('Wallet client is not available. Please ensure your wallet is connected.') + } + if (!userAddress) { + throw new Error('User address is not available. Please ensure your wallet is connected.') + } + if (!publicClient) { + throw new Error('Public client is not available. Please check your network connection.') + } + if (!connector) { + throw new Error('Wallet connector is not available. Please ensure your wallet is properly connected.') + } + if (!swapQuote) { + throw new Error('Swap quote is not available. Please try selecting a different token or refresh the page.') } setIsPurchasing(true) diff --git a/packages/checkout/src/views/Swap/index.tsx b/packages/checkout/src/views/Swap/index.tsx index 4e2e59896..27d81fb9f 100644 --- a/packages/checkout/src/views/Swap/index.tsx +++ b/packages/checkout/src/views/Swap/index.tsx @@ -38,7 +38,12 @@ export const Swap = () => { const [isError, setIsError] = useState(false) const [selectedCurrency, setSelectedCurrency] = useState() const publicClient = usePublicClient() - const { data: walletClient, isLoading: isLoadingWalletClient } = useWalletClient() + const { + data: walletClient, + isLoading: isLoadingWalletClient, + isError: isErrorWalletClient, + error: errorWalletClient + } = useWalletClient() const { switchChain } = useSwitchChain() const { @@ -168,8 +173,19 @@ export const Swap = () => { const isLoading = isLoadingCurrencyInfo || swapRoutesIsLoading const onClickProceed = async () => { - if (!userAddress || !publicClient || !walletClient || !connector) { - throw new Error('Wallet client, user address, public client, indexer client, or connector is not found') + if (!userAddress) { + throw new Error('User address is not available. Please ensure your wallet is connected.') + } + if (!publicClient) { + throw new Error('Public client is not available. Please check your network connection.') + } + if (!walletClient || isErrorWalletClient || errorWalletClient) { + throw new Error('Wallet client is not available. Please ensure your wallet is connected.', { + cause: errorWalletClient + }) + } + if (!connector) { + throw new Error('Wallet connector is not available. Please ensure your wallet is properly connected.') } if (connectedChainId != chainId) {