Skip to content

Commit

Permalink
fix possible null balance checks
Browse files Browse the repository at this point in the history
  • Loading branch information
jhesgodi committed May 1, 2024
1 parent 097642a commit 3e2ba23
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,34 +56,43 @@ export const fetchFundingBalances = async (
}
};

const balancePromises = currencies.map(async (currency) => {
const amount = getAmountByCurrency(currency) || '0';
const itemRequirements = getERC20ItemRequirement(
amount,
spenderAddress,
currency.address,
);
const balancePromises: Promise<FundingBalanceResult>[] = currencies
.map(async (currency) => {
const amount = getAmountByCurrency(currency);

const transactionOrGasAmount = getIsGasless()
? undefined
: getGasEstimate();
if (!amount) {
return null;
}

const itemRequirements = getERC20ItemRequirement(
amount,
spenderAddress,
currency.address,
);

const transactionOrGasAmount = getIsGasless()
? undefined
: getGasEstimate();

const smartCheckoutResult = await checkout.smartCheckout({
provider,
itemRequirements,
transactionOrGasAmount,
routingOptions: { bridge: false, onRamp: false, swap: true },
fundingRouteFullAmount: true,
onComplete: () => {
onComplete?.(pushToFoundBalances([]));
},
onFundingRoute: (route) => {
updateFundingBalances(getAlternativeFundingSteps([route], environment));
},
});
const smartCheckoutResult = await checkout.smartCheckout({
provider,
itemRequirements,
transactionOrGasAmount,
routingOptions: { bridge: false, onRamp: false, swap: true },
fundingRouteFullAmount: true,
onComplete: () => {
onComplete?.(pushToFoundBalances([]));
},
onFundingRoute: (route) => {
updateFundingBalances(
getAlternativeFundingSteps([route], environment),
);
},
});

return { currency, smartCheckoutResult };
});
return { currency, smartCheckoutResult };
})
.filter(Boolean) as Promise<FundingBalanceResult>[];

const results = await wrapPromisesWithOnResolve(
balancePromises,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const useFundingBalances = () => {
routingOptions: { bridge: false, onRamp: false, swap: true },
baseCurrency: selectedCurrency,
getAmountByCurrency: (currency) => clientConfig.currencyConversion?.[
currency.name
currency.name.toUpperCase()
]?.amount?.toString(),
getIsGasless: () => (provider.provider as any)?.isPassport || false,
onFundingBalance: (foundBalances) => {
Expand Down

0 comments on commit 3e2ba23

Please sign in to comment.