Use premium to filter matches (#459)

This commit is contained in:
Reckless_Satoshi 2023-04-26 12:18:54 +00:00 committed by GitHub
parent 4f2ef09c6f
commit edb8c8b3ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 2 deletions

View File

@ -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);

View File

@ -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;
};