Skip to content

Commit

Permalink
fix: Safely handle empty Swap fees (#1786)
Browse files Browse the repository at this point in the history
  • Loading branch information
jwhardwick authored May 16, 2024
1 parent 36a39bf commit 35f22b2
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,51 @@ describe('formatQuoteConversionRate', () => {
fee: 1,
});
});

it('should handle an empty fee array', () => {
const fromAmount = '1.50';
const fromToken = {
name: 'ETH',
symbol: 'ETH',
address: '0x123',
chainId: 1,
decimals: 18,
} as TokenInfo;
const mockQuote = {
quote: {
amount: {
value: BigNumber.from('2000000000000000000'),
token: {
symbol: 'DAI',
address: '0x456',
chainId: 1,
decimals: 18,
},
} as Amount,
amountWithMaxSlippage: {} as Amount,
slippage: 0,
fees: [],
} as Quote,
swap: {
gasFeeEstimate: {
value: BigNumber.from(100),
},
},
approval: {
gasFeeEstimate: {
value: BigNumber.from(50),
},
},
} as TransactionResponse;
const labelKey = 'conversion.label';

formatQuoteConversionRate(fromAmount, fromToken, mockQuote, labelKey, mockTranslate as unknown as TFunction);

expect(mockTranslate).toHaveBeenCalledWith(labelKey, {
fromSymbol: 'ETH',
toSymbol: 'DAI',
rate: '1.33',
fee: 0,
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@ export const formatQuoteConversionRate = (
fromSymbol: fromToken.symbol,
toSymbol: toToken.symbol,
rate: formattedConversion,
fee: secondaryFee.basisPoints / 100,
fee: (secondaryFee?.basisPoints ?? 0) / 100,
});
};

0 comments on commit 35f22b2

Please sign in to comment.