mirror of
https://github.com/RoboSats/robosats.git
synced 2025-01-18 20:21:35 +00:00
Use premium to filter matches (#459)
This commit is contained in:
parent
4f2ef09c6f
commit
edb8c8b3ff
@ -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);
|
||||
|
@ -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;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user