Skip to content

Commit

Permalink
Merge branch 'main' into use-nostr-as-cache-system
Browse files Browse the repository at this point in the history
  • Loading branch information
KoalaSat authored Aug 10, 2024
2 parents 58d21d9 + 771f8db commit e9620e3
Show file tree
Hide file tree
Showing 26 changed files with 1,633 additions and 803 deletions.
2 changes: 1 addition & 1 deletion api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def get_devfund_pubkey(network: str) -> str:
"""

session = get_session()
url = "https://raw.githubusercontent.com/RoboSats/robosats/main/devfund_pubey.json"
url = "https://raw.githubusercontent.com/RoboSats/robosats/main/devfund_pubkey.json"

try:
response = session.get(url)
Expand Down
24 changes: 12 additions & 12 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"jest": "^29.6.1",
"prettier": "^3.3.2",
"ts-node": "^10.9.2",
"typescript": "^5.4.2",
"typescript": "^5.5.4",
"webpack": "^5.89.0",
"webpack-cli": "^5.1.4"
},
Expand All @@ -62,11 +62,11 @@
"@nivo/core": "^0.86.0",
"@nivo/line": "^0.86.0",
"base-ex": "^0.8.1",
"country-flag-icons": "^1.5.11",
"country-flag-icons": "^1.5.13",
"date-fns": "^2.30.0",
"file-replace-loader": "^1.4.0",
"i18next": "^23.2.11",
"i18next-browser-languagedetector": "^7.2.1",
"i18next-browser-languagedetector": "^8.0.0",
"i18next-http-backend": "^2.5.0",
"install": "^0.13.0",
"js-sha256": "^0.11.0",
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/basic/OrderPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ const OrderPage = (): JSX.Element => {
const shortAlias = params.shortAlias;
const coordinator = federation.getCoordinator(shortAlias ?? '');
if (coordinator) {
const { url, basePath } = coordinator?.getEndpoint(
const endpoint = coordinator?.getEndpoint(
settings.network,
origin,
settings.selfhostedClient,
hostUrl,
);

setBaseUrl(`${url}${basePath}`);
if (endpoint) setBaseUrl(`${endpoint?.url}${endpoint?.basePath}`);

const orderId = Number(params.orderId);
if (
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/basic/RobotPage/RobotProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ const RobotProfile = ({
)}
</Grid>

{loadingCoordinators > 0 && !Boolean(robot?.activeOrderId) ? (
{loadingCoordinators > 0 && !robot?.activeOrderId ? (
<Grid>
<b>{t('Looking for orders!')}</b>
<LinearProgress />
Expand Down Expand Up @@ -210,9 +210,9 @@ const RobotProfile = ({
</Grid>
) : null}

{!Boolean(robot?.activeOrderId) &&
{!robot?.activeOrderId &&
slot?.hashId &&
!Boolean(robot?.lastOrderId) &&
!robot?.lastOrderId &&
loadingCoordinators === 0 ? (
<Grid item>{t('No existing orders found')}</Grid>
) : null}
Expand Down
12 changes: 8 additions & 4 deletions frontend/src/basic/SettingsPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import SettingsForm from '../../components/SettingsForm';
import { AppContext, type UseAppStoreType } from '../../contexts/AppContext';
import FederationTable from '../../components/FederationTable';
import { t } from 'i18next';
import { FederationContext, UseFederationStoreType } from '../../contexts/FederationContext';
import { FederationContext, type UseFederationStoreType } from '../../contexts/FederationContext';

const SettingsPage = (): JSX.Element => {
const { windowSize, navbarHeight } = useContext<UseAppStoreType>(AppContext);
Expand All @@ -16,7 +16,7 @@ const SettingsPage = (): JSX.Element => {
// Regular expression to match a valid .onion URL
const onionUrlPattern = /^((http|https):\/\/)?[a-zA-Z2-7]{16,56}\.onion$/;

const addCoordinator = () => {
const addCoordinator: () => void = () => {
if (federation.coordinators[newAlias]) {
setError(t('Alias already exists'));
} else {
Expand Down Expand Up @@ -65,15 +65,19 @@ const SettingsPage = (): JSX.Element => {
variant='outlined'
size='small'
value={newAlias}
onChange={(e) => setNewAlias(e.target.value)}
onChange={(e) => {
setNewAlias(e.target.value);
}}
/>
<TextField
id='outlined-basic'
label={t('URL')}
variant='outlined'
size='small'
value={newUrl}
onChange={(e) => setNewUrl(e.target.value)}
onChange={(e) => {
setNewUrl(e.target.value);
}}
/>
<Button
sx={{ maxHeight: 38 }}
Expand Down
11 changes: 1 addition & 10 deletions frontend/src/components/BookTable/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
LinearProgress,
IconButton,
Tooltip,
type LinearProgressProps,
styled,
} from '@mui/material';
import {
Expand All @@ -24,7 +23,7 @@ import {
type GridPaginationModel,
type GridColDef,
type GridValidRowModel,
GridSlotsComponent,
type GridSlotsComponent,
} from '@mui/x-data-grid';
import currencyDict from '../../../static/assets/currencies.json';
import { type PublicOrder } from '../../models';
Expand Down Expand Up @@ -831,14 +830,6 @@ const BookTable = ({
);
};

interface GridComponentProps {
LoadingOverlay: (props: LinearProgressProps) => JSX.Element;
NoResultsOverlay?: (props: any) => JSX.Element;
NoRowsOverlay?: (props: any) => JSX.Element;
Footer?: (props: any) => JSX.Element;
Toolbar?: (props: any) => JSX.Element;
}

const NoResultsOverlay = function (): JSX.Element {
return (
<Grid
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/Dialogs/Exchange.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useContext, useEffect, useMemo, useState } from 'react';
import React, { useContext, useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';

import {
Expand Down
3 changes: 1 addition & 2 deletions frontend/src/components/MakerForm/AutocompletePayments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -409,9 +409,8 @@ const AutocompletePayments: React.FC<AutocompletePaymentsProps> = (props) => {
))}
{qttHiddenTags > 0 ? (
<StyledChip
sx={{ borderRadius: 1 }}
label={`+${qttHiddenTags}`}
sx={{ height: '1.6rem' }}
sx={{ borderRadius: 1, height: '1.6rem' }}
/>
) : null}
</>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/MakerForm/SelectCoordinator.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useContext, useMemo } from 'react';
import React, { useContext } from 'react';
import {
Grid,
Select,
Expand Down
7 changes: 1 addition & 6 deletions frontend/src/components/SettingsForm/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useContext, useEffect } from 'react';
import React, { useContext } from 'react';
import { useTranslation } from 'react-i18next';
import { type UseAppStoreType, AppContext } from '../../contexts/AppContext';
import {
Expand Down Expand Up @@ -26,13 +26,10 @@ import {
AccountBalance,
AttachMoney,
QrCode,
ControlPoint,
} from '@mui/icons-material';
import { systemClient } from '../../services/System';
import { TorIcon } from '../Icons';
import SwapCalls from '@mui/icons-material/SwapCalls';
import { FederationContext, type UseFederationStoreType } from '../../contexts/FederationContext';
import { GarageContext, UseGarageStoreType } from '../../contexts/GarageContext';
import { apiClient } from '../../services/api';

interface SettingsFormProps {
Expand All @@ -41,8 +38,6 @@ interface SettingsFormProps {

const SettingsForm = ({ dense = false }: SettingsFormProps): JSX.Element => {
const { fav, setFav, settings, setSettings } = useContext<UseAppStoreType>(AppContext);
const { federation } = useContext<UseFederationStoreType>(FederationContext);
const { garage } = useContext<UseGarageStoreType>(GarageContext);
const theme = useTheme();
const { t } = useTranslation();
const fontSizes = [
Expand Down
19 changes: 9 additions & 10 deletions frontend/src/contexts/FederationContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,17 @@ import React, {
useEffect,
useState,
type SetStateAction,
useMemo,
useContext,
type ReactNode,
} from 'react';

import { type Order, Federation, Settings, Coordinator } from '../models';
import { type Order, Federation, Settings } from '../models';

import { federationLottery } from '../utils';

import { AppContext, type UseAppStoreType } from './AppContext';
import { GarageContext, type UseGarageStoreType } from './GarageContext';
import NativeRobosats from '../services/Native';
import { Origins } from '../models/Coordinator.model';
import { type Origin, type Origins } from '../models/Coordinator.model';

// Refresh delays (ms) according to Order status
const defaultDelay = 5000;
Expand Down Expand Up @@ -175,14 +173,15 @@ export const FederationContextProvider = ({
federated: false,
enabled: true,
};
const origins: Origins = {
clearnet: undefined,
onion: url as Origin,
i2p: undefined,
};
if (settings.network === 'mainnet') {
attributes.mainnet = {
onion: url,
} as Origins;
attributes.mainnet = origins;
} else {
attributes.testnet = {
onion: url,
} as Origins;
attributes.testnet = origins;
}
federation.addCoordinator(origin, settings, hostUrl, attributes);
const newCoordinator = federation.coordinators[alias];
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/models/Coordinator.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ export class Coordinator {

generateAllMakerAvatars = async (data: [PublicOrder]): Promise<void> => {
for (const order of data) {
roboidentitiesClient.generateRobohash(order.maker_hash_id, 'small');
void roboidentitiesClient.generateRobohash(order.maker_hash_id, 'small');
}
};

Expand Down
6 changes: 3 additions & 3 deletions frontend/src/models/Federation.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export class Federation {
settings: Settings,
hostUrl: string,
attributes: Record<any, any>,
) => {
): void => {
const value = {
...coordinatorDefaultValues,
...attributes,
Expand Down Expand Up @@ -111,7 +111,7 @@ export class Federation {
this.exchange.loadingCoordinators = Object.keys(this.coordinators).length;
this.updateEnabledCoordinators();
for (const coor of Object.values(this.coordinators)) {
coor.update(() => {
void coor.update(() => {
this.exchange.onlineCoordinators = this.exchange.onlineCoordinators + 1;
this.onCoordinatorSaved();
});
Expand All @@ -124,7 +124,7 @@ export class Federation {
this.triggerHook('onCoordinatorUpdate');
this.exchange.loadingCoordinators = Object.keys(this.coordinators).length;
for (const coor of Object.values(this.coordinators)) {
coor.updateBook(() => {
void coor.updateBook(() => {
this.onCoordinatorSaved();
});
}
Expand Down
17 changes: 11 additions & 6 deletions frontend/src/models/Garage.model.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Coordinator, type Order } from '.';
import { type Coordinator, type Order } from '.';
import { systemClient } from '../services/System';
import { saveAsJson } from '../utils';
import Slot from './Slot.model';
Expand Down Expand Up @@ -59,8 +59,13 @@ class Garage {
const rawSlots = JSON.parse(slotsDump);
Object.values(rawSlots).forEach((rawSlot: Record<any, any>) => {
if (rawSlot?.token) {
this.slots[rawSlot.token] = new Slot(rawSlot.token, Object.keys(rawSlot.robots), {}, () =>
this.triggerHook('onRobotUpdate'),
this.slots[rawSlot.token] = new Slot(
rawSlot.token,
Object.keys(rawSlot.robots),
{},
() => {
this.triggerHook('onRobotUpdate');
},
);
Object.keys(rawSlot.robots).forEach((shortAlias) => {
const rawRobot = rawSlot.robots[shortAlias];
Expand Down Expand Up @@ -118,9 +123,9 @@ class Garage {
if (!token || !shortAliases) return;

if (this.getSlot(token) === null) {
this.slots[token] = new Slot(token, shortAliases, attributes, () =>
this.triggerHook('onRobotUpdate'),
);
this.slots[token] = new Slot(token, shortAliases, attributes, () => {
this.triggerHook('onRobotUpdate');
});
this.save();
}
};
Expand Down
Loading

0 comments on commit e9620e3

Please sign in to comment.