Book coordinator filter (#1087)

* Fix book loading

* Fix Robot page

* Code Review

* Book coordinator filter
This commit is contained in:
KoalaSat 2024-01-24 00:32:00 +01:00 committed by GitHub
parent c648132163
commit 83410c174e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
21 changed files with 113 additions and 2 deletions

View File

@ -20,6 +20,8 @@ import { AppContext, type UseAppStoreType } from '../../contexts/AppContext';
import CheckBoxOutlineBlankIcon from '@mui/icons-material/CheckBoxOutlineBlank'; import CheckBoxOutlineBlankIcon from '@mui/icons-material/CheckBoxOutlineBlank';
import SwapCalls from '@mui/icons-material/SwapCalls'; import SwapCalls from '@mui/icons-material/SwapCalls';
import { FederationContext, UseFederationStoreType } from '../../contexts/FederationContext';
import RobotAvatar from '../RobotAvatar';
interface BookControlProps { interface BookControlProps {
width: number; width: number;
@ -33,6 +35,7 @@ const BookControl = ({
setPaymentMethods, setPaymentMethods,
}: BookControlProps): JSX.Element => { }: BookControlProps): JSX.Element => {
const { fav, setFav } = useContext<UseAppStoreType>(AppContext); const { fav, setFav } = useContext<UseAppStoreType>(AppContext);
const { federation } = useContext<UseFederationStoreType>(FederationContext);
const { t, i18n } = useTranslation(); const { t, i18n } = useTranslation();
const theme = useTheme(); const theme = useTheme();
@ -52,6 +55,11 @@ const BookControl = ({
setFav({ ...fav, currency, mode: currency === 1000 ? 'swap' : 'fiat' }); setFav({ ...fav, currency, mode: currency === 1000 ? 'swap' : 'fiat' });
}; };
const handleHostChange = function (e: React.ChangeEvent<HTMLInputElement>): void {
const coordinator = String(e.target.value);
setFav({ ...fav, coordinator });
};
const handleTypeChange = function (mouseEvent: React.MouseEvent, val: number): void { const handleTypeChange = function (mouseEvent: React.MouseEvent, val: number): void {
setFav({ ...fav, type: val }); setFav({ ...fav, type: val });
}; };
@ -306,6 +314,63 @@ const BookControl = ({
</Select> </Select>
</Grid> </Grid>
) : null} ) : null}
{width > large ? (
<Grid item sx={{ position: 'relative', top: '0.5em' }}>
<Typography variant='caption' color='text.secondary'>
{fav.currency === 1000 ? t(fav.type === 0 ? 'to' : 'from') : t('hosted by')}
</Typography>
</Grid>
) : null}
<Grid item>
<Select
autoWidth
sx={{
height: '2.3em',
border: '0.5px solid',
backgroundColor: theme.palette.background.paper,
borderRadius: '4px',
borderColor: 'text.disabled',
'&:hover': {
borderColor: 'text.primary',
},
}}
size='small'
label={t('Select Host')}
required={true}
value={fav.coordinator}
inputProps={{
style: { textAlign: 'center' },
}}
onChange={handleHostChange}
>
<MenuItem value='any'>
<div style={{ display: 'flex', alignItems: 'center', flexWrap: 'wrap' }}>
<FlagWithProps code='ANY' />
</div>
</MenuItem>
{Object.values(federation.coordinators).map((coordinator) =>
coordinator.enabled ? (
<MenuItem
key={coordinator.shortAlias}
value={coordinator.shortAlias}
color='text.secondary'
>
<div style={{ display: 'flex', alignItems: 'center', flexWrap: 'wrap' }}>
<RobotAvatar
shortAlias={coordinator.shortAlias}
style={{ width: '1.428em', height: '1.428em' }}
smooth={true}
small={true}
/>
</div>
</MenuItem>
) : (
<></>
),
)}
</Select>
</Grid>
</Grid> </Grid>
<Divider /> <Divider />
</Box> </Box>

View File

@ -154,7 +154,7 @@ export const initialAppContext: UseAppStoreType = {
clientVersion: getClientVersion(), clientVersion: getClientVersion(),
setAcknowledgedWarning: () => {}, setAcknowledgedWarning: () => {},
acknowledgedWarning: false, acknowledgedWarning: false,
fav: { type: null, currency: 0, mode: 'fiat' }, fav: { type: null, currency: 0, mode: 'fiat', coordinator: 'any' },
setFav: () => {}, setFav: () => {},
}; };

View File

@ -2,6 +2,7 @@ export interface Favorites {
type: number | null; type: number | null;
mode: 'swap' | 'fiat'; mode: 'swap' | 'fiat';
currency: number; currency: number;
coordinator: string;
} }
export default Favorites; export default Favorites;

View File

@ -27,6 +27,14 @@ const filterByPayment = function (order: PublicOrder, paymentMethods: any[]): bo
} }
}; };
const filterByHost = function (order: PublicOrder, shortAlias: string): boolean {
if (shortAlias === 'any') {
return true;
} else {
return order.coordinatorShortAlias === shortAlias;
}
};
const filterByAmount = function (order: PublicOrder, filter: AmountFilter): boolean { const filterByAmount = function (order: PublicOrder, filter: AmountFilter): boolean {
const filterMaxAmount = const filterMaxAmount =
Number(filter.amount !== '' ? filter.amount : filter.maxAmount) * (1 + filter.threshold); Number(filter.amount !== '' ? filter.amount : filter.maxAmount) * (1 + filter.threshold);
@ -66,13 +74,16 @@ const filterOrders = function ({
const paymentMethodChecks = const paymentMethodChecks =
paymentMethods.length > 0 ? filterByPayment(order, paymentMethods) : true; paymentMethods.length > 0 ? filterByPayment(order, paymentMethods) : true;
const amountChecks = amountFilter != null ? filterByAmount(order, amountFilter) : true; const amountChecks = amountFilter != null ? filterByAmount(order, amountFilter) : true;
const hostChecks =
baseFilter.coordinator != 'any' ? filterByHost(order, baseFilter.coordinator) : true;
return ( return (
typeChecks && typeChecks &&
modeChecks && modeChecks &&
premiumChecks && premiumChecks &&
currencyChecks && currencyChecks &&
paymentMethodChecks && paymentMethodChecks &&
amountChecks amountChecks &&
hostChecks
); );
}); });
return filteredOrders; return filteredOrders;

View File

@ -83,6 +83,7 @@
"DESTINATION": "DESTÍ", "DESTINATION": "DESTÍ",
"I want to": "Vull", "I want to": "Vull",
"METHOD": "MÈTODE", "METHOD": "MÈTODE",
"Select Host": "Select Host",
"Select Payment Currency": "Selecciona moneda de pagament", "Select Payment Currency": "Selecciona moneda de pagament",
"Select Payment Method": "Tria mètode de pagament", "Select Payment Method": "Tria mètode de pagament",
"Sell": "Vendre", "Sell": "Vendre",
@ -90,6 +91,7 @@
"Swap In": "Swap In", "Swap In": "Swap In",
"Swap Out": "Swap Out", "Swap Out": "Swap Out",
"and use": "i fer servir", "and use": "i fer servir",
"hosted by": "hosted by",
"pay with": "pagar amb", "pay with": "pagar amb",
"#15": "Phrases in components/BookTable/index.tsx", "#15": "Phrases in components/BookTable/index.tsx",
"Add filter": "Afegir filtre", "Add filter": "Afegir filtre",

View File

@ -83,6 +83,7 @@
"DESTINATION": "DESTINATION", "DESTINATION": "DESTINATION",
"I want to": "Já chci", "I want to": "Já chci",
"METHOD": "METHOD", "METHOD": "METHOD",
"Select Host": "Select Host",
"Select Payment Currency": "Vybrat měnu platby", "Select Payment Currency": "Vybrat měnu platby",
"Select Payment Method": "Select Payment Method", "Select Payment Method": "Select Payment Method",
"Sell": "Prodej", "Sell": "Prodej",
@ -90,6 +91,7 @@
"Swap In": "Swap In", "Swap In": "Swap In",
"Swap Out": "Swap Out", "Swap Out": "Swap Out",
"and use": "použít", "and use": "použít",
"hosted by": "hosted by",
"pay with": "pay with", "pay with": "pay with",
"#15": "Phrases in components/BookTable/index.tsx", "#15": "Phrases in components/BookTable/index.tsx",
"Add filter": "Přidat filter", "Add filter": "Přidat filter",

View File

@ -83,6 +83,7 @@
"DESTINATION": "DESTINATION", "DESTINATION": "DESTINATION",
"I want to": "Ich möchte", "I want to": "Ich möchte",
"METHOD": "METHOD", "METHOD": "METHOD",
"Select Host": "Select Host",
"Select Payment Currency": "Währung auswählen", "Select Payment Currency": "Währung auswählen",
"Select Payment Method": "Select Payment Method", "Select Payment Method": "Select Payment Method",
"Sell": "Verkaufen", "Sell": "Verkaufen",
@ -90,6 +91,7 @@
"Swap In": "Swap In", "Swap In": "Swap In",
"Swap Out": "Swap Out", "Swap Out": "Swap Out",
"and use": "und verwende", "and use": "und verwende",
"hosted by": "hosted by",
"pay with": "pay with", "pay with": "pay with",
"#15": "Phrases in components/BookTable/index.tsx", "#15": "Phrases in components/BookTable/index.tsx",
"Add filter": "Add filter", "Add filter": "Add filter",

View File

@ -83,6 +83,7 @@
"DESTINATION": "DESTINATION", "DESTINATION": "DESTINATION",
"I want to": "I want to", "I want to": "I want to",
"METHOD": "METHOD", "METHOD": "METHOD",
"Select Host": "Select Host",
"Select Payment Currency": "Select Payment Currency", "Select Payment Currency": "Select Payment Currency",
"Select Payment Method": "Select Payment Method", "Select Payment Method": "Select Payment Method",
"Sell": "Sell", "Sell": "Sell",
@ -90,6 +91,7 @@
"Swap In": "Swap In", "Swap In": "Swap In",
"Swap Out": "Swap Out", "Swap Out": "Swap Out",
"and use": "and use", "and use": "and use",
"hosted by": "hosted by",
"pay with": "pay with", "pay with": "pay with",
"#15": "Phrases in components/BookTable/index.tsx", "#15": "Phrases in components/BookTable/index.tsx",
"Add filter": "Add filter", "Add filter": "Add filter",

View File

@ -83,6 +83,7 @@
"DESTINATION": "DESTINO", "DESTINATION": "DESTINO",
"I want to": "Quiero", "I want to": "Quiero",
"METHOD": "MÉTODO", "METHOD": "MÉTODO",
"Select Host": "Select Host",
"Select Payment Currency": "Selecciona moneda de pago", "Select Payment Currency": "Selecciona moneda de pago",
"Select Payment Method": "Selecciona método de pago", "Select Payment Method": "Selecciona método de pago",
"Sell": "Vender", "Sell": "Vender",
@ -90,6 +91,7 @@
"Swap In": "Swap a LN", "Swap In": "Swap a LN",
"Swap Out": "Swap desde LN", "Swap Out": "Swap desde LN",
"and use": "y usa", "and use": "y usa",
"hosted by": "hosted by",
"pay with": "paga con", "pay with": "paga con",
"#15": "Phrases in components/BookTable/index.tsx", "#15": "Phrases in components/BookTable/index.tsx",
"Add filter": "Añadir filtro", "Add filter": "Añadir filtro",

View File

@ -83,6 +83,7 @@
"DESTINATION": "DESTINATION", "DESTINATION": "DESTINATION",
"I want to": "Nahi dut", "I want to": "Nahi dut",
"METHOD": "METHOD", "METHOD": "METHOD",
"Select Host": "Select Host",
"Select Payment Currency": "Aukeratu Ordainketa Txanpona", "Select Payment Currency": "Aukeratu Ordainketa Txanpona",
"Select Payment Method": "Select Payment Method", "Select Payment Method": "Select Payment Method",
"Sell": "Saldu", "Sell": "Saldu",
@ -90,6 +91,7 @@
"Swap In": "Swap In", "Swap In": "Swap In",
"Swap Out": "Swap Out", "Swap Out": "Swap Out",
"and use": "eta erabili", "and use": "eta erabili",
"hosted by": "hosted by",
"pay with": "pay with", "pay with": "pay with",
"#15": "Phrases in components/BookTable/index.tsx", "#15": "Phrases in components/BookTable/index.tsx",
"Add filter": "Gehitu iragazkia", "Add filter": "Gehitu iragazkia",

View File

@ -83,6 +83,7 @@
"DESTINATION": "DESTINATION", "DESTINATION": "DESTINATION",
"I want to": "Je veux", "I want to": "Je veux",
"METHOD": "MÉTHODE", "METHOD": "MÉTHODE",
"Select Host": "Select Host",
"Select Payment Currency": "Sélectionner la devise de paiement", "Select Payment Currency": "Sélectionner la devise de paiement",
"Select Payment Method": "Sélectionner le mode de paiement", "Select Payment Method": "Sélectionner le mode de paiement",
"Sell": "Vendre", "Sell": "Vendre",
@ -90,6 +91,7 @@
"Swap In": "Échange LN->OC", "Swap In": "Échange LN->OC",
"Swap Out": "Échange OC->LN", "Swap Out": "Échange OC->LN",
"and use": "et utiliser", "and use": "et utiliser",
"hosted by": "hosted by",
"pay with": "payer avec", "pay with": "payer avec",
"#15": "Phrases in components/BookTable/index.tsx", "#15": "Phrases in components/BookTable/index.tsx",
"Add filter": "Ajouter filtre", "Add filter": "Ajouter filtre",

View File

@ -83,6 +83,7 @@
"DESTINATION": "DESTINAZIONE", "DESTINATION": "DESTINAZIONE",
"I want to": "Voglio", "I want to": "Voglio",
"METHOD": "METODO", "METHOD": "METODO",
"Select Host": "Select Host",
"Select Payment Currency": "Seleziona valuta di pagamento", "Select Payment Currency": "Seleziona valuta di pagamento",
"Select Payment Method": "Seleziona il metodo di pagamento", "Select Payment Method": "Seleziona il metodo di pagamento",
"Sell": "Vendere", "Sell": "Vendere",
@ -90,6 +91,7 @@
"Swap In": "Swap In", "Swap In": "Swap In",
"Swap Out": "Swap Out", "Swap Out": "Swap Out",
"and use": "ed usa", "and use": "ed usa",
"hosted by": "hosted by",
"pay with": "paga con", "pay with": "paga con",
"#15": "Phrases in components/BookTable/index.tsx", "#15": "Phrases in components/BookTable/index.tsx",
"Add filter": "Aggiungi filtro", "Add filter": "Aggiungi filtro",

View File

@ -83,6 +83,7 @@
"DESTINATION": "方向", "DESTINATION": "方向",
"I want to": "私はしたいのは:", "I want to": "私はしたいのは:",
"METHOD": "方法", "METHOD": "方法",
"Select Host": "Select Host",
"Select Payment Currency": "支払い通貨を選択してください。", "Select Payment Currency": "支払い通貨を選択してください。",
"Select Payment Method": "支払い方法を選択してください。", "Select Payment Method": "支払い方法を選択してください。",
"Sell": "売る", "Sell": "売る",
@ -90,6 +91,7 @@
"Swap In": "スワップイン", "Swap In": "スワップイン",
"Swap Out": "スワップアウト", "Swap Out": "スワップアウト",
"and use": "そして使用するのは", "and use": "そして使用するのは",
"hosted by": "hosted by",
"pay with": "支払い方法は:", "pay with": "支払い方法は:",
"#15": "Phrases in components/BookTable/index.tsx", "#15": "Phrases in components/BookTable/index.tsx",
"Add filter": "フィルタを追加", "Add filter": "フィルタを追加",

View File

@ -83,6 +83,7 @@
"DESTINATION": "DESTINATION", "DESTINATION": "DESTINATION",
"I want to": "chcę", "I want to": "chcę",
"METHOD": "METHOD", "METHOD": "METHOD",
"Select Host": "Select Host",
"Select Payment Currency": "Wybierz walutę płatności", "Select Payment Currency": "Wybierz walutę płatności",
"Select Payment Method": "Select Payment Method", "Select Payment Method": "Select Payment Method",
"Sell": "Sprzedać", "Sell": "Sprzedać",
@ -90,6 +91,7 @@
"Swap In": "Swap In", "Swap In": "Swap In",
"Swap Out": "Swap Out", "Swap Out": "Swap Out",
"and use": "i użyć", "and use": "i użyć",
"hosted by": "hosted by",
"pay with": "pay with", "pay with": "pay with",
"#15": "Phrases in components/BookTable/index.tsx", "#15": "Phrases in components/BookTable/index.tsx",
"Add filter": "Add filter", "Add filter": "Add filter",

View File

@ -83,6 +83,7 @@
"DESTINATION": "DESTINATION", "DESTINATION": "DESTINATION",
"I want to": "Eu quero", "I want to": "Eu quero",
"METHOD": "METHOD", "METHOD": "METHOD",
"Select Host": "Select Host",
"Select Payment Currency": "Selecione a moeda de pagamento", "Select Payment Currency": "Selecione a moeda de pagamento",
"Select Payment Method": "Select Payment Method", "Select Payment Method": "Select Payment Method",
"Sell": "Vender", "Sell": "Vender",
@ -90,6 +91,7 @@
"Swap In": "Swap In", "Swap In": "Swap In",
"Swap Out": "Swap Out", "Swap Out": "Swap Out",
"and use": "e utilizar", "and use": "e utilizar",
"hosted by": "hosted by",
"pay with": "pay with", "pay with": "pay with",
"#15": "Phrases in components/BookTable/index.tsx", "#15": "Phrases in components/BookTable/index.tsx",
"Add filter": "Add filter", "Add filter": "Add filter",

View File

@ -83,6 +83,7 @@
"DESTINATION": "МЕСТО НАЗНАЧЕНИЯ", "DESTINATION": "МЕСТО НАЗНАЧЕНИЯ",
"I want to": "Я хочу", "I want to": "Я хочу",
"METHOD": "МЕТОД", "METHOD": "МЕТОД",
"Select Host": "Select Host",
"Select Payment Currency": "Выбрать Валюту", "Select Payment Currency": "Выбрать Валюту",
"Select Payment Method": "Выбрать способ оплаты", "Select Payment Method": "Выбрать способ оплаты",
"Sell": "Продать", "Sell": "Продать",
@ -90,6 +91,7 @@
"Swap In": "Своп в", "Swap In": "Своп в",
"Swap Out": "Своп из", "Swap Out": "Своп из",
"and use": "и использовать", "and use": "и использовать",
"hosted by": "hosted by",
"pay with": "оплатить", "pay with": "оплатить",
"#15": "Phrases in components/BookTable/index.tsx", "#15": "Phrases in components/BookTable/index.tsx",
"Add filter": "Добавить фильтр", "Add filter": "Добавить фильтр",

View File

@ -83,6 +83,7 @@
"DESTINATION": "DESTINATION", "DESTINATION": "DESTINATION",
"I want to": "Jag vill", "I want to": "Jag vill",
"METHOD": "METHOD", "METHOD": "METHOD",
"Select Host": "Select Host",
"Select Payment Currency": "Välj betalningsvaluta", "Select Payment Currency": "Välj betalningsvaluta",
"Select Payment Method": "Select Payment Method", "Select Payment Method": "Select Payment Method",
"Sell": "Sälja", "Sell": "Sälja",
@ -90,6 +91,7 @@
"Swap In": "Swap In", "Swap In": "Swap In",
"Swap Out": "Swap Out", "Swap Out": "Swap Out",
"and use": "och använda", "and use": "och använda",
"hosted by": "hosted by",
"pay with": "pay with", "pay with": "pay with",
"#15": "Phrases in components/BookTable/index.tsx", "#15": "Phrases in components/BookTable/index.tsx",
"Add filter": "Add filter", "Add filter": "Add filter",

View File

@ -83,6 +83,7 @@
"DESTINATION": "MAELEKEZO", "DESTINATION": "MAELEKEZO",
"I want to": "Nataka", "I want to": "Nataka",
"METHOD": "NJIA", "METHOD": "NJIA",
"Select Host": "Select Host",
"Select Payment Currency": "Chagua Sarafu ya Malipo", "Select Payment Currency": "Chagua Sarafu ya Malipo",
"Select Payment Method": "Chagua Njia ya Malipo", "Select Payment Method": "Chagua Njia ya Malipo",
"Sell": "Uza", "Sell": "Uza",
@ -90,6 +91,7 @@
"Swap In": "Badilisha Ndani", "Swap In": "Badilisha Ndani",
"Swap Out": "Badilisha Nje", "Swap Out": "Badilisha Nje",
"and use": "na tumia", "and use": "na tumia",
"hosted by": "hosted by",
"pay with": "lipa kwa", "pay with": "lipa kwa",
"#15": "Phrases in components/BookTable/index.tsx", "#15": "Phrases in components/BookTable/index.tsx",
"Add filter": "Ongeza kichujio", "Add filter": "Ongeza kichujio",

View File

@ -83,6 +83,7 @@
"DESTINATION": "DESTINATION", "DESTINATION": "DESTINATION",
"I want to": "ฉันต้องการ", "I want to": "ฉันต้องการ",
"METHOD": "METHOD", "METHOD": "METHOD",
"Select Host": "Select Host",
"Select Payment Currency": "เลือกสกุลเงิน", "Select Payment Currency": "เลือกสกุลเงิน",
"Select Payment Method": "Select Payment Method", "Select Payment Method": "Select Payment Method",
"Sell": "ขาย", "Sell": "ขาย",
@ -90,6 +91,7 @@
"Swap In": "Swap In", "Swap In": "Swap In",
"Swap Out": "Swap Out", "Swap Out": "Swap Out",
"and use": "และใช้", "and use": "และใช้",
"hosted by": "hosted by",
"pay with": "pay with", "pay with": "pay with",
"#15": "Phrases in components/BookTable/index.tsx", "#15": "Phrases in components/BookTable/index.tsx",
"Add filter": "เพิ่มตัวกรอง", "Add filter": "เพิ่มตัวกรอง",

View File

@ -83,6 +83,7 @@
"DESTINATION": "目的地", "DESTINATION": "目的地",
"I want to": "我想要", "I want to": "我想要",
"METHOD": "方式", "METHOD": "方式",
"Select Host": "Select Host",
"Select Payment Currency": "选择支付货币", "Select Payment Currency": "选择支付货币",
"Select Payment Method": "选择付款方式", "Select Payment Method": "选择付款方式",
"Sell": "出售", "Sell": "出售",
@ -90,6 +91,7 @@
"Swap In": "换入", "Swap In": "换入",
"Swap Out": "换出", "Swap Out": "换出",
"and use": "并使用", "and use": "并使用",
"hosted by": "hosted by",
"pay with": "支付", "pay with": "支付",
"#15": "Phrases in components/BookTable/index.tsx", "#15": "Phrases in components/BookTable/index.tsx",
"Add filter": "加筛选", "Add filter": "加筛选",

View File

@ -83,6 +83,7 @@
"DESTINATION": "目的地", "DESTINATION": "目的地",
"I want to": "我想要", "I want to": "我想要",
"METHOD": "方式", "METHOD": "方式",
"Select Host": "Select Host",
"Select Payment Currency": "選擇支付貨幣", "Select Payment Currency": "選擇支付貨幣",
"Select Payment Method": "選擇付款方式", "Select Payment Method": "選擇付款方式",
"Sell": "出售", "Sell": "出售",
@ -90,6 +91,7 @@
"Swap In": "換入", "Swap In": "換入",
"Swap Out": "換出", "Swap Out": "換出",
"and use": "並使用", "and use": "並使用",
"hosted by": "hosted by",
"pay with": "支付", "pay with": "支付",
"#15": "Phrases in components/BookTable/index.tsx", "#15": "Phrases in components/BookTable/index.tsx",
"Add filter": "加篩選", "Add filter": "加篩選",