Skip to content

Commit

Permalink
Handles errors during crypto/fiat conversions. (#1136)
Browse files Browse the repository at this point in the history
  • Loading branch information
jwhardwick authored Nov 8, 2023
1 parent d2a27eb commit 5ae3e30
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,19 @@ export function FundingRouteMenuItem({
if (!cryptoFiatState.conversions) {
return;
}

setFeesUsd(fundingRouteFees(fundingRoute, cryptoFiatState.conversions));
setUsdBalance(
calculateCryptoToFiat(
firstFundingStep.fundingItem.userBalance.formattedBalance,
firstFundingStep.fundingItem.token.symbol,
cryptoFiatState.conversions,
),
);
try {
setFeesUsd(fundingRouteFees(fundingRoute, cryptoFiatState.conversions));
setUsdBalance(
calculateCryptoToFiat(
firstFundingStep.fundingItem.userBalance.formattedBalance,
firstFundingStep.fundingItem.token.symbol,
cryptoFiatState.conversions,
),
);
} catch {
setFeesUsd(undefined);
setUsdBalance(undefined);
}
}, [cryptoFiatState, fundingRoute]);

const networkLabel = () => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,25 @@ export function PurchaseMenuItem({ fundingRoute }: PurchaseMenuItemProps) {
if (!cryptoFiatState.conversions) {
return;
}

setUsdPurchaseAmount(
calculateCryptoToFiat(
firstFundingStep.fundingItem.fundsRequired.formattedAmount,
firstFundingStep.fundingItem.token.symbol,
cryptoFiatState.conversions,
),
);
try {
setUsdPurchaseAmount(
calculateCryptoToFiat(
firstFundingStep.fundingItem.fundsRequired.formattedAmount,
firstFundingStep.fundingItem.token.symbol,
cryptoFiatState.conversions,
),
);
} catch {
setUsdPurchaseAmount(undefined);
}
}, [cryptoFiatState, fundingRoute]);

return (
<MenuItem
emphasized
testId="funding-route-purchase-item"
size="medium"
key={firstItem.name}
key={firstItem?.name}
>
<MenuItem.FramedImage
imageUrl={firstItem?.image}
Expand Down

0 comments on commit 5ae3e30

Please sign in to comment.