Skip to content

Commit

Permalink
Merge pull request #879 from rainlanguage/2024-09-20-order-quote-zero…
Browse files Browse the repository at this point in the history
…-divide-error

Add zero check for division error on order quotes table
  • Loading branch information
hardyjosh authored Sep 25, 2024
2 parents 233a725 + d72f468 commit 38389d4
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@
<TableBodyCell
>{formatUnits(BigInt(item.data.ratio), 18)}
<span class="text-gray-400"
>({formatUnits(10n ** 36n / BigInt(item.data.ratio), 18)})</span
>({BigInt(item.data.ratio) > 0n
? formatUnits(10n ** 36n / BigInt(item.data.ratio), 18)
: '0'})</span
></TableBodyCell
>
<TableBodyCell
Expand Down
35 changes: 35 additions & 0 deletions tauri-app/src/lib/components/detail/TanstackOrderQuote.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,38 @@ test('displays error message when query fails', async () => {
expect(errorCell).toBeInTheDocument();
});
});

test('displays zero for price when io ratio is zero', async () => {
mockIPC((cmd) => {
if (cmd === 'batch_order_quotes') {
return [
{
success: true,
block_number: '0x123',
pair: { pair_name: 'ETH/USDT', input_index: 0, output_index: 1 },
data: { maxOutput: '0x158323e942e36d8c', ratio: '0x0' },
error: undefined,
} satisfies BatchOrderQuotesResponse,
];
}
});

const queryClient = new QueryClient();

render(TanstackOrderQuote, {
props: {
id: '0x123',
order: mockOrderDetailsExtended.order,
},
context: new Map([['$$_queryClient', queryClient]]),
});

await waitFor(() => {
const orderQuoteComponent = screen.getByTestId('bodyRow');

expect(orderQuoteComponent).toHaveTextContent('ETH/USDT');
expect(orderQuoteComponent).toHaveTextContent('1.550122181502135692'); // maxOutput
expect(orderQuoteComponent).toHaveTextContent('0'); // ratio
expect(orderQuoteComponent).toHaveTextContent('(0)'); // inverse price
});
});

0 comments on commit 38389d4

Please sign in to comment.