Skip to content

Commit 5ae3e30

Browse files
authored
Handles errors during crypto/fiat conversions. (#1136)
1 parent d2a27eb commit 5ae3e30

File tree

2 files changed

+25
-18
lines changed

2 files changed

+25
-18
lines changed

packages/checkout/widgets-lib/src/widgets/sale/components/FundingRouteMenuItem/FundingRouteMenuItem.tsx

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,19 @@ export function FundingRouteMenuItem({
5252
if (!cryptoFiatState.conversions) {
5353
return;
5454
}
55-
56-
setFeesUsd(fundingRouteFees(fundingRoute, cryptoFiatState.conversions));
57-
setUsdBalance(
58-
calculateCryptoToFiat(
59-
firstFundingStep.fundingItem.userBalance.formattedBalance,
60-
firstFundingStep.fundingItem.token.symbol,
61-
cryptoFiatState.conversions,
62-
),
63-
);
55+
try {
56+
setFeesUsd(fundingRouteFees(fundingRoute, cryptoFiatState.conversions));
57+
setUsdBalance(
58+
calculateCryptoToFiat(
59+
firstFundingStep.fundingItem.userBalance.formattedBalance,
60+
firstFundingStep.fundingItem.token.symbol,
61+
cryptoFiatState.conversions,
62+
),
63+
);
64+
} catch {
65+
setFeesUsd(undefined);
66+
setUsdBalance(undefined);
67+
}
6468
}, [cryptoFiatState, fundingRoute]);
6569

6670
const networkLabel = () => (

packages/checkout/widgets-lib/src/widgets/sale/components/PurchaseMenuItem/PurchaseMenuItem.tsx

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,25 @@ export function PurchaseMenuItem({ fundingRoute }: PurchaseMenuItemProps) {
2626
if (!cryptoFiatState.conversions) {
2727
return;
2828
}
29-
30-
setUsdPurchaseAmount(
31-
calculateCryptoToFiat(
32-
firstFundingStep.fundingItem.fundsRequired.formattedAmount,
33-
firstFundingStep.fundingItem.token.symbol,
34-
cryptoFiatState.conversions,
35-
),
36-
);
29+
try {
30+
setUsdPurchaseAmount(
31+
calculateCryptoToFiat(
32+
firstFundingStep.fundingItem.fundsRequired.formattedAmount,
33+
firstFundingStep.fundingItem.token.symbol,
34+
cryptoFiatState.conversions,
35+
),
36+
);
37+
} catch {
38+
setUsdPurchaseAmount(undefined);
39+
}
3740
}, [cryptoFiatState, fundingRoute]);
3841

3942
return (
4043
<MenuItem
4144
emphasized
4245
testId="funding-route-purchase-item"
4346
size="medium"
44-
key={firstItem.name}
47+
key={firstItem?.name}
4548
>
4649
<MenuItem.FramedImage
4750
imageUrl={firstItem?.image}

0 commit comments

Comments
 (0)