diff --git a/frontend/src/components/BookTable/index.tsx b/frontend/src/components/BookTable/index.tsx index 90a2b06bf..e1f2c7ae9 100644 --- a/frontend/src/components/BookTable/index.tsx +++ b/frontend/src/components/BookTable/index.tsx @@ -412,18 +412,38 @@ const BookTable = ({ }; }, []); + const getOrderPrice = useCallback( + (row: PublicOrder): number | null => { + const limits = federation.getLimits(row.coordinatorShortAlias ?? ''); + const limitPrice = limits[(row.currency ?? 0).toString()]?.price; + if (!limitPrice) return null; + const premium = parseFloat(row.premium ?? '0'); + return limitPrice * (1 + premium / 100); + }, + [federation], + ); + const priceObj = useCallback(() => { return { field: 'price', headerName: t('Price'), type: 'number', flex: 2, + sortComparator: ( + _v1: number, + _v2: number, + p1: { api: { getRow: (id: number) => PublicOrder }; id: number }, + p2: { api: { getRow: (id: number) => PublicOrder }; id: number }, + ) => { + const row1 = p1.api.getRow(p1.id); + const row2 = p2.api.getRow(p2.id); + const price1 = getOrderPrice(row1) ?? 0; + const price2 = getOrderPrice(row2) ?? 0; + return price1 - price2; + }, renderCell: (params: { row: PublicOrder }) => { const currencyCode = String(currencyDict[(params.row.currency ?? 0).toString()]); - const limits = federation.getLimits(params.row.coordinatorShortAlias ?? ''); - const premium = parseFloat(params.row.premium ?? '0'); - const limitPrice = limits[(params.row.currency ?? 0).toString()]?.price; - const price = (limitPrice ?? 1) * (1 + premium / 100); + const price = getOrderPrice(params.row); return (
- {limitPrice ? ( + {price ? ( `${pn(Math.round(price))} ${currencyCode}/BTC` ) : (