From edb8c8b3ffad4970c1f725b77dea5800f0fc58a9 Mon Sep 17 00:00:00 2001 From: Reckless_Satoshi <90936742+Reckless-Satoshi@users.noreply.github.com> Date: Wed, 26 Apr 2023 12:18:54 +0000 Subject: [PATCH] Use premium to filter matches (#459) --- frontend/src/basic/MakerPage/index.tsx | 3 ++- frontend/src/utils/filterOrders.ts | 20 +++++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/frontend/src/basic/MakerPage/index.tsx b/frontend/src/basic/MakerPage/index.tsx index 515c9522..331066db 100644 --- a/frontend/src/basic/MakerPage/index.tsx +++ b/frontend/src/basic/MakerPage/index.tsx @@ -29,6 +29,7 @@ const MakerPage = (): JSX.Element => { type: fav.type, mode: fav.mode, }, + premium: Number(maker.premium) ?? null, paymentMethods: maker.paymentMethods, amountFilter: { amount: maker.amount, @@ -37,7 +38,7 @@ const MakerPage = (): JSX.Element => { threshold: 0.7, }, }); - }, [book.orders, fav, maker.amount, maker.minAmount, maker.maxAmount]); + }, [book.orders, fav, maker.premium, maker.amount, maker.minAmount, maker.maxAmount]); const onViewOrder = function () { setOrder(undefined); diff --git a/frontend/src/utils/filterOrders.ts b/frontend/src/utils/filterOrders.ts index 911debb6..1dc1cf75 100644 --- a/frontend/src/utils/filterOrders.ts +++ b/frontend/src/utils/filterOrders.ts @@ -10,6 +10,7 @@ interface AmountFilter { interface FilterOrders { orders: PublicOrder[]; baseFilter: Favorites; + premium: number | null; amountFilter?: AmountFilter | null; paymentMethods?: string[]; } @@ -42,20 +43,37 @@ const filterByAmount = function (order: PublicOrder, filter: AmountFilter) { return Math.max(filterMinAmount, orderMinAmount) <= Math.min(filterMaxAmount, orderMaxAmount); }; +const filterByPremium = function (order: PublicOrder, premium: number) { + if (order.type == 0) { + return order.premium >= premium; + } else { + return order.premium <= premium; + } +}; + const filterOrders = function ({ orders, baseFilter, + premium = null, paymentMethods = [], amountFilter = null, }: FilterOrders) { const filteredOrders = orders.filter((order) => { const typeChecks = order.type == baseFilter.type || baseFilter.type == null; const modeChecks = baseFilter.mode === 'fiat' ? !(order.currency === 1000) : true; + const premiumChecks = premium != null ? filterByPremium(order, premium) : true; const currencyChecks = order.currency == baseFilter.currency || baseFilter.currency == 0; const paymentMethodChecks = paymentMethods.length > 0 ? filterByPayment(order, paymentMethods) : true; const amountChecks = amountFilter != null ? filterByAmount(order, amountFilter) : true; - return typeChecks && modeChecks && currencyChecks && paymentMethodChecks && amountChecks; + return ( + typeChecks && + modeChecks && + premiumChecks && + currencyChecks && + paymentMethodChecks && + amountChecks + ); }); return filteredOrders; };