Skip to content

Commit

Permalink
fix: error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
corlard3y committed Feb 7, 2025
1 parent 42688c9 commit bb0690a
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions src/modules/purchasePlan/components/PurchaseSummery.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { useGetPaymentDetails, useInitiatePaymentInfo } from 'queries';
import { PlanPurchasedModal } from './PlanPurchasedModal';
import { convertAddressToAddrCaip } from 'helpers/CaipHelper';
import { getEip191Signature, getUSDCBalance, sendUSDC } from '../utils/handleUSDCutils';
import { addresses } from 'config';
import { addresses, appConfig } from 'config';

import { PricingPlanTabsType } from 'modules/pricing/Pricing.types';
import { PricingPlanType } from 'queries/types/pricing';
Expand Down Expand Up @@ -115,9 +115,25 @@ const PurchaseSummery: FC<PurchaseSummeryProps> = ({ selectedPlan }) => {

const paymentAmount = selectedPricingPlanTab === 'yearly' ? selectedPlan?.value * 12 : selectedPlan?.value;
const provider = new ethers.providers.Web3Provider(window.ethereum);
await provider.send('eth_requestAccounts', []);
await sendUSDC(paymentAmount, addresses?.usdcRecipient, provider);
handlePurchase();

try {
await provider.send('eth_requestAccounts', []);
await sendUSDC(paymentAmount, addresses?.usdcRecipient, provider);
handlePurchase();
} catch (error: any) {
console.error('Transaction failed:', error);
// Show error message based on error type
if (error?.message.includes('User denied transaction')) {
console.log('User rejected the transaction');
} else if (error?.message.includes('transfer amount exceeds balance')) {
console.log('Not enough balance');
} else {
console.log('Something went wrong while processing the payment');
}

setIsLoading(false);
modalControl.onClose();
}
};

const handlePurchase = async () => {
Expand Down Expand Up @@ -297,7 +313,7 @@ const PurchaseSummery: FC<PurchaseSummeryProps> = ({ selectedPlan }) => {
)}
</Box>

{usdcBalance < 1 && (
{usdcBalance < 1 && appConfig?.appEnv != 'prod' && (
<Link
style={{ alignSelf: 'center' }}
to="#"
Expand Down

0 comments on commit bb0690a

Please sign in to comment.