Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
13 changes: 10 additions & 3 deletions packages/checkout/src/hooks/useERC1155SaleContractCheckout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
22 changes: 19 additions & 3 deletions packages/checkout/src/views/Swap/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ export const Swap = () => {
const [isError, setIsError] = useState(false)
const [selectedCurrency, setSelectedCurrency] = useState<string>()
const publicClient = usePublicClient()
const { data: walletClient, isLoading: isLoadingWalletClient } = useWalletClient()
const {
data: walletClient,
isLoading: isLoadingWalletClient,
isError: isErrorWalletClient,
error: errorWalletClient
} = useWalletClient()
const { switchChain } = useSwitchChain()

const {
Expand Down Expand Up @@ -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) {
Expand Down