Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
swapQuoterErrorMessage: (asset: Asset, error: Error): string | undefined => {
if (error.message === SwapQuoterError.InsufficientAssetLiquidity) {
const assetName = assetUtils.bestNameForAsset(asset, 'of this asset');
if (
error instanceof InsufficientAssetLiquidityError &&
error.amountAvailableToFill.isGreaterThan(BIG_NUMBER_ZERO)
) {
const unitAmountAvailableToFill =
asset.metaData.assetProxyId === AssetProxyId.ERC20
? Web3Wrapper.toUnitAmount(error.amountAvailableToFill, asset.metaData.decimals)
: error.amountAvailableToFill;
const roundedUnitAmountAvailableToFill = unitAmountAvailableToFill.decimalPlaces(
2,
BigNumber.ROUND_DOWN,
);
if (roundedUnitAmountAvailableToFill.isGreaterThan(BIG_NUMBER_ZERO)) {
return `There are only ${roundedUnitAmountAvailableToFill} ${assetName} available to buy`;