Skip to content

Commit

Permalink
Merge pull request #1632 from RoboSats/filter-deepth-chart-by-host
Browse files Browse the repository at this point in the history
Filter deepth chart by host
  • Loading branch information
KoalaSat authored Nov 25, 2024
2 parents a600e70 + c7c7f0b commit ce4a96b
Show file tree
Hide file tree
Showing 28 changed files with 70 additions and 36 deletions.
18 changes: 18 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ repos:
files: ^frontend/
types_or: [javascript, jsx, ts, tsx, css, markdown, json] # uses https://github.com/pre-commit/identify
entry: bash -c 'cd frontend && npm run format'
- id: lintern-frontend
name: lintern-frontend
stages:
- commit
- merge-commit
language: system
files: ^frontend/
types_or: [javascript, jsx, ts, tsx, css, markdown, json] # uses https://github.com/pre-commit/identify
entry: bash -c 'cd frontend && npm run lint'
- id: prettier-mobile
name: prettier-mobile
stages:
Expand All @@ -47,6 +56,15 @@ repos:
files: ^mobile/
types_or: [javascript, jsx, ts, tsx, css, markdown, json] # uses https://github.com/pre-commit/identify
entry: bash -c 'cd mobile && npm run format'
- id: lintern-mobile
name: lintern-mobile
stages:
- commit
- merge-commit
language: system
files: ^mobile/
types_or: [javascript, jsx, ts, tsx, css, markdown, json] # uses https://github.com/pre-commit/identify
entry: bash -c 'cd mobile && npm run lint'
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.13
hooks:
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/basic/MakerPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { NoRobotDialog } from '../../components/Dialogs';
import { FederationContext, type UseFederationStoreType } from '../../contexts/FederationContext';
import { GarageContext, type UseGarageStoreType } from '../../contexts/GarageContext';
import VisitThirdParty from '../../components/Dialogs/VisitThirdParty';
import { PublicOrder } from '../../models';
import { type PublicOrder } from '../../models';

const MakerPage = (): JSX.Element => {
const { fav, windowSize, navbarHeight } = useContext<UseAppStoreType>(AppContext);
Expand Down
1 change: 0 additions & 1 deletion frontend/src/components/BookTable/BookControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import CheckBoxOutlineBlankIcon from '@mui/icons-material/CheckBoxOutlineBlank';
import SwapCalls from '@mui/icons-material/SwapCalls';
import { FederationContext, type UseFederationStoreType } from '../../contexts/FederationContext';
import RobotAvatar from '../RobotAvatar';
import RoboSats from '../Icons/RoboSats';
import RoboSatsNoText from '../Icons/RoboSatsNoText';

interface BookControlProps {
Expand Down
27 changes: 21 additions & 6 deletions frontend/src/components/Charts/DepthChart/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,17 @@ const DepthChart: React.FC<DepthChartProps> = ({
const [xRange, setXRange] = useState<number>(8);
const [xType, setXType] = useState<string>('premium');
const [currencyCode, setCurrencyCode] = useState<number>(0);
const [coordinatorFilter, setCoordinatorFilter] = useState<string>('all');
const [center, setCenter] = useState<number>();

const height = maxHeight < 10 ? 10 : maxHeight;
const width = maxWidth < 10 ? 10 : maxWidth > 72.8 ? 72.8 : maxWidth;

useEffect(() => {
setCurrencyCode(fav.currency); // as selected in BookControl
}, [fav.currency]);
setCurrencyCode(fav.currency); // as selected in BookControl
setCoordinatorFilter(fav.coordinator);
console.log(fav.coordinator);
}, [fav.currency, fav.coordinator]);

useEffect(() => {
if (Object.values(federation.book).length > 0) {
Expand All @@ -89,7 +92,7 @@ const DepthChart: React.FC<DepthChartProps> = ({
});
setEnrichedOrders(enriched);
}
}, [federationUpdatedAt, currencyCode]);
}, [federationUpdatedAt, currencyCode, coordinatorFilter]);

useEffect(() => {
if (enrichedOrders.length > 0) {
Expand Down Expand Up @@ -119,22 +122,34 @@ const DepthChart: React.FC<DepthChartProps> = ({
setXRange(8);
setRangeSteps(0.5);
}
}, [enrichedOrders, xType, federationUpdatedAt, currencyCode]);
}, [enrichedOrders, xType, federationUpdatedAt, currencyCode, coordinatorFilter]);

const generateSeries: () => void = () => {
const sortedOrders: PublicOrder[] =
xType === 'base_price'
? enrichedOrders
.filter(
(order: PublicOrder | null) => currencyCode === 0 || order?.currency == currencyCode,
(order: PublicOrder | null) => currencyCode === 0 || order?.currency === currencyCode,
)
.filter(
(order: PublicOrder | null) =>
coordinatorFilter === 'any' ||
(coordinatorFilter === 'robosats' && order?.federated) ||
order?.coordinatorShortAlias === coordinatorFilter,
)
.sort(
(order1: PublicOrder | null, order2: PublicOrder | null) =>
(order1?.base_price ?? 0) - (order2?.base_price ?? 0),
)
: enrichedOrders
.filter(
(order: PublicOrder | null) => currencyCode === 0 || order?.currency == currencyCode,
(order: PublicOrder | null) => currencyCode === 0 || order?.currency === currencyCode,
)
.filter(
(order: PublicOrder | null) =>
coordinatorFilter === 'any' ||
(coordinatorFilter === 'robosats' && order?.federated) ||
order?.coordinatorShortAlias === coordinatorFilter,
)
.sort(
(order1: PublicOrder | null, order2: PublicOrder | null) =>
Expand Down
9 changes: 8 additions & 1 deletion frontend/src/components/Dialogs/Exchange.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,14 @@ const ExchangeDialog = ({ open = false, onClose }: Props): JSX.Element => {
const [loadingInfo, setLoadingInfo] = useState<boolean>(true);

useEffect(() => {
if (open) federation.loadInfo();
if (open) {
federation
.loadInfo()
.then(() => {})
.catch((error) => {
console.error('Error loading info:', error);
});
}
}, [open]);

useEffect(() => {
Expand Down
7 changes: 6 additions & 1 deletion frontend/src/components/MakerForm/MakerForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,12 @@ const MakerForm = ({
const amountSafeThresholds = [1.03, 0.98];

useEffect(() => {
federation.loadInfo();
federation
.loadInfo()
.then(() => {})
.catch((error) => {
console.error('Error loading info:', error);
});
}, []);

useEffect(() => {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/MakerForm/SelectCoordinator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
CircularProgress,
Stack,
} from '@mui/material';
import { Bolt, Link, Info } from '@mui/icons-material';
import { Link } from '@mui/icons-material';
import RobotAvatar from '../RobotAvatar';
import { AppContext, type UseAppStoreType } from '../../contexts/AppContext';
import { useTheme } from '@emotion/react';
Expand Down
1 change: 1 addition & 0 deletions frontend/src/models/Book.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface PublicOrder {
maker_status?: 'Active' | 'Seen recently' | 'Inactive';
coordinatorShortAlias?: string;
link?: string;
federated?: boolean;
}

export interface Book {
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/utils/filterOrders.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type PublicOrder, type Favorites, type Federation, Coordinator } from '../models';
import { type PublicOrder, type Favorites, type Federation } from '../models';
import thirdParties from '../../static/thirdparties.json';

interface AmountFilter {
Expand Down Expand Up @@ -35,7 +35,7 @@ const filterByHost = function (
): boolean {
if (shortAlias === 'any') {
return true;
} else if (shortAlias == 'robosats') {
} else if (shortAlias === 'robosats') {
const coordinator = federation.getCoordinator(order.coordinatorShortAlias ?? '');
return coordinator?.federated ?? false;
} else {
Expand Down Expand Up @@ -84,7 +84,7 @@ const filterOrders = function ({
const coordinatorCheck = [...enabledCoordinators, ...Object.keys(thirdParties)].includes(
order.coordinatorShortAlias ?? '',
);
const typeChecks = order.type === baseFilter.type || baseFilter.type == null;
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;
Expand Down
1 change: 1 addition & 0 deletions frontend/src/utils/nostr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const eventToPublicOrder = (event: Event): { dTag: string; publicOrder: PublicOr
if (!coordinator || statusTag[1] !== 'pending') return { dTag: dTag[1], publicOrder: null };

publicOrder.coordinatorShortAlias = coordinator?.shortAlias;
publicOrder.federated = coordinator?.federated ?? false;

event.tags.forEach((tag) => {
switch (tag[0]) {
Expand Down
15 changes: 10 additions & 5 deletions frontend/static/federation.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
"i2p": ""
},
"mainnetNodesPubkeys": ["0226f31c5f3a8b48bbbb7aaa97a10effcfb445b5972a676955d5c095383d35a428"],
"testnetNodesPubkeys": ["028e7a019180a664b84edf77ba656e96f2eb84f67f56d93020341caf4109e0dbc7"]
"testnetNodesPubkeys": ["028e7a019180a664b84edf77ba656e96f2eb84f67f56d93020341caf4109e0dbc7"],
"federated": true
},
"lake": {
"longAlias": "TheBigLake",
Expand Down Expand Up @@ -94,7 +95,8 @@
"i2p": ""
},
"mainnetNodesPubkeys": ["0385262f7e9e2eeeba1e7d6182a0efec98e79d01154b76189f3e0b88bcee279dd0"],
"testnetNodesPubkeys": ["0355f8604df9ec4bee20a284f045f94e26cdd1fc5e15dee0716a5a5dfc7cd33b7c"]
"testnetNodesPubkeys": ["0355f8604df9ec4bee20a284f045f94e26cdd1fc5e15dee0716a5a5dfc7cd33b7c"],
"federated": true
},
"veneto": {
"longAlias": "BitcoinVeneto",
Expand Down Expand Up @@ -140,7 +142,8 @@
"i2p": ""
},
"mainnetNodesPubkeys": ["02c5b5972b05fba2cd2c2d9269a47bc478f73fae0f248a85cb1e5af60a07c1919d"],
"testnetNodesPubkeys": ["032b698c8143f293d138c0926594f11d119194ddedb513f63a944d14c094d0e54a"]
"testnetNodesPubkeys": ["032b698c8143f293d138c0926594f11d119194ddedb513f63a944d14c094d0e54a"],
"federated": true
},
"moon": {
"longAlias": "Over the moon",
Expand Down Expand Up @@ -186,7 +189,8 @@
"i2p": ""
},
"mainnetNodesPubkeys": ["023924542082a5d16bce188ec4c29a45f00dd439a3f5992034d82e3353232a0345"],
"testnetNodesPubkeys": ["02f0ddc838b35fe54daa13baa4abab84475c7b9f2670ff4b53c1724792843ef62a"]
"testnetNodesPubkeys": ["02f0ddc838b35fe54daa13baa4abab84475c7b9f2670ff4b53c1724792843ef62a"],
"federated": true
},
"local": {
"longAlias": "Local Dev",
Expand All @@ -209,6 +213,7 @@
"Development Policy": "Don't look around, just buidl"
},
"mainnetNodesPubkeys": ["..."],
"testnetNodesPubkeys": ["..."]
"testnetNodesPubkeys": ["..."],
"federated": true
}
}
1 change: 0 additions & 1 deletion frontend/static/locales/ca.json
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,6 @@
"Maker": "Creador",
"Onchain payouts enabled": "Onchain payouts enabled",
"Taker": "Prenedor",
"Order Host": "Amfitrió de l'ordre",
"The provider the lightning and communication infrastructure. The host will be in charge of providing support and solving disputes. The trade fees are set by the host. Make sure to only select order hosts that you trust!": "El proveïdor de la infraestructura LN i comunicacions. L'amfitrió serà l'encarregat de donar suport i resoldre disputes. LEs comissions de les transaccions són fixades per l'amfitrió. Assegureu-vos de seleccionar només els amfitrions en què confieu!",
"#41": "Phrases in components/Notifications/index.tsx",
"Lightning routing failed": "L'enrutament Lightning ha fallat",
Expand Down
1 change: 0 additions & 1 deletion frontend/static/locales/cs.json
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,6 @@
"You send approx {{swapSats}} LN Sats (fees might vary)": "You send approx {{swapSats}} LN Sats (fees might vary)",
"Your order fixed exchange rate": "Pevný směnný kurz tvé nabídky",
"#40": "Phrases in components/MakerForm/SelectCoordinator.tsx",
"Order Host": "Order Host",
"Disabled": "Disabled",
"Maker": "Tvůrce",
"Onchain payouts enabled": "Onchain payouts enabled",
Expand Down
1 change: 0 additions & 1 deletion frontend/static/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,6 @@
"You send approx {{swapSats}} LN Sats (fees might vary)": "You send approx {{swapSats}} LN Sats (fees might vary)",
"Your order fixed exchange rate": "Dein fixierter Order-Kurs",
"#40": "Phrases in components/MakerForm/SelectCoordinator.tsx",
"Order Host": "Order Host",
"Disabled": "Disabled",
"Maker": "Maker",
"Onchain payouts enabled": "Onchain payouts enabled",
Expand Down
1 change: 0 additions & 1 deletion frontend/static/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,6 @@
"You send approx {{swapSats}} LN Sats (fees might vary)": "You send approx {{swapSats}} LN Sats (fees might vary)",
"Your order fixed exchange rate": "Your order fixed exchange rate",
"#40": "Phrases in components/MakerForm/SelectCoordinator.tsx",
"Order Host": "Order Host",
"Disabled": "Disabled",
"Maker": "Maker",
"Onchain payouts enabled": "Onchain payouts enabled",
Expand Down
1 change: 0 additions & 1 deletion frontend/static/locales/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,6 @@
"You send approx {{swapSats}} LN Sats (fees might vary)": "Envías aproximadamente {{swapSats}} LN Sats (la comisión puede variar)",
"Your order fixed exchange rate": "La tasa de cambio fija de tu orden",
"#40": "Phrases in components/MakerForm/SelectCoordinator.tsx",
"Order Host": "Order Host",
"Disabled": "Disabled",
"Maker": "Creador",
"Onchain payouts enabled": "Onchain payouts enabled",
Expand Down
1 change: 0 additions & 1 deletion frontend/static/locales/eu.json
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,6 @@
"You send approx {{swapSats}} LN Sats (fees might vary)": "You send approx {{swapSats}} LN Sats (fees might vary)",
"Your order fixed exchange rate": "Zure eskaeraren kanbio-tasa finkoa",
"#40": "Phrases in components/MakerForm/SelectCoordinator.tsx",
"Order Host": "Order Host",
"Disabled": "Disabled",
"Maker": "Egile",
"Onchain payouts enabled": "Onchain payouts enabled",
Expand Down
1 change: 0 additions & 1 deletion frontend/static/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,6 @@
"You send approx {{swapSats}} LN Sats (fees might vary)": "Vous envoyez environ {{swapSats}} LN Sats (les frais peuvent varier)",
"Your order fixed exchange rate": "Taux de change fixe de votre commande",
"#40": "Phrases in components/MakerForm/SelectCoordinator.tsx",
"Order Host": "Order Host",
"Disabled": "Disabled",
"Maker": "Auteur",
"Onchain payouts enabled": "Onchain payouts enabled",
Expand Down
1 change: 0 additions & 1 deletion frontend/static/locales/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,6 @@
"You send approx {{swapSats}} LN Sats (fees might vary)": "Invierai circa {{swapSats}} LN Sats (le commissioni possono variare)",
"Your order fixed exchange rate": "Il tasso di cambio fisso del tuo ordine",
"#40": "Phrases in components/MakerForm/SelectCoordinator.tsx",
"Order Host": "Order Host",
"Disabled": "Disabled",
"Maker": "Maker",
"Onchain payouts enabled": "Onchain payouts enabled",
Expand Down
1 change: 0 additions & 1 deletion frontend/static/locales/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,6 @@
"You send approx {{swapSats}} LN Sats (fees might vary)": "約{{swapSats}} ライトニングSatsを送信します(手数料は異なる場合があります)",
"Your order fixed exchange rate": "注文の固定為替レート",
"#40": "Phrases in components/MakerForm/SelectCoordinator.tsx",
"Order Host": "Order Host",
"Disabled": "Disabled",
"Maker": "メーカー",
"Onchain payouts enabled": "Onchain payouts enabled",
Expand Down
1 change: 0 additions & 1 deletion frontend/static/locales/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,6 @@
"You send approx {{swapSats}} LN Sats (fees might vary)": "You send approx {{swapSats}} LN Sats (fees might vary)",
"Your order fixed exchange rate": "Your order fixed exchange rate",
"#40": "Phrases in components/MakerForm/SelectCoordinator.tsx",
"Order Host": "Order Host",
"Disabled": "Disabled",
"Maker": "Maker",
"Onchain payouts enabled": "Onchain payouts enabled",
Expand Down
1 change: 0 additions & 1 deletion frontend/static/locales/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,6 @@
"You send approx {{swapSats}} LN Sats (fees might vary)": "Você envia aprox {{swapSats}} LN Sats (as taxas podem variar)",
"Your order fixed exchange rate": "Taxa de câmbio fixa do seu pedido",
"#40": "Phrases in components/MakerForm/SelectCoordinator.tsx",
"Order Host": "Order Host",
"Disabled": "Disabled",
"Maker": "Maker",
"Onchain payouts enabled": "Onchain payouts enabled",
Expand Down
1 change: 0 additions & 1 deletion frontend/static/locales/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,6 @@
"You send approx {{swapSats}} LN Sats (fees might vary)": "Вы отправляете примерно {{swapSats}} спутников LN (комиссия может различаться)",
"Your order fixed exchange rate": "Фиксированный курс обмена Вашего ордера",
"#40": "Phrases in components/MakerForm/SelectCoordinator.tsx",
"Order Host": "Order Host",
"Disabled": "Disabled",
"Maker": "Мейкер",
"Onchain payouts enabled": "Onchain payouts enabled",
Expand Down
1 change: 0 additions & 1 deletion frontend/static/locales/sv.json
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,6 @@
"You send approx {{swapSats}} LN Sats (fees might vary)": "You send approx {{swapSats}} LN Sats (fees might vary)",
"Your order fixed exchange rate": "Din orders fasta växelkurs",
"#40": "Phrases in components/MakerForm/SelectCoordinator.tsx",
"Order Host": "Order Host",
"Disabled": "Disabled",
"Maker": "Maker",
"Onchain payouts enabled": "Onchain payouts enabled",
Expand Down
1 change: 0 additions & 1 deletion frontend/static/locales/sw.json
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,6 @@
"You send approx {{swapSats}} LN Sats (fees might vary)": "Unatuma takribani {{swapSats}} LN Sats (ada inaweza kutofautiana)",
"Your order fixed exchange rate": "Kiwango chako cha kubadilisha cha amri",
"#40": "Phrases in components/MakerForm/SelectCoordinator.tsx",
"Order Host": "Order Host",
"Disabled": "Disabled",
"Maker": "Muumba",
"Onchain payouts enabled": "Onchain payouts enabled",
Expand Down
1 change: 0 additions & 1 deletion frontend/static/locales/th.json
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,6 @@
"You send approx {{swapSats}} LN Sats (fees might vary)": "You send approx {{swapSats}} LN Sats (fees might vary)",
"Your order fixed exchange rate": "คุณกำหนดอัตราแลกเปลี่ยนคงที่",
"#40": "Phrases in components/MakerForm/SelectCoordinator.tsx",
"Order Host": "Order Host",
"Disabled": "Disabled",
"Maker": "Maker",
"Onchain payouts enabled": "Onchain payouts enabled",
Expand Down
1 change: 0 additions & 1 deletion frontend/static/locales/zh-SI.json
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,6 @@
"You send approx {{swapSats}} LN Sats (fees might vary)": "你将发送大约{{swapSats}}闪电聪(费用会造成有所差异)",
"Your order fixed exchange rate": "你的订单的固定汇率",
"#40": "Phrases in components/MakerForm/SelectCoordinator.tsx",
"Order Host": "Order Host",
"Disabled": "Disabled",
"Maker": "挂单方",
"Onchain payouts enabled": "Onchain payouts enabled",
Expand Down
1 change: 0 additions & 1 deletion frontend/static/locales/zh-TR.json
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,6 @@
"You send approx {{swapSats}} LN Sats (fees might vary)": "你將發送大約{{swapSats}}閃電聰(費用會造成有所差異)",
"Your order fixed exchange rate": "你的訂單的固定匯率",
"#40": "Phrases in components/MakerForm/SelectCoordinator.tsx",
"Order Host": "Order Host",
"Disabled": "Disabled",
"Maker": "掛單方",
"Onchain payouts enabled": "Onchain payouts enabled",
Expand Down

0 comments on commit ce4a96b

Please sign in to comment.