Merge branch 'main' into android-notification-system

This commit is contained in:
KoalaSat 2024-08-10 16:07:02 +00:00 committed by GitHub
commit e9863417dd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
28 changed files with 1624 additions and 794 deletions

View File

@ -50,16 +50,16 @@ class Command(BaseCommand):
parts = message.split(" ")
if len(parts) < 2:
self.notifications.send_telegram_message(
chat_id=result["message"]["from"]["id"],
text='You must enable the notifications bot using the RoboSats client. Click on your "Robot robot" -> "Enable Telegram" and follow the link or scan the QR code.',
result["message"]["from"]["id"],
'You must enable the notifications bot using the RoboSats client. Click on your "Robot robot" -> "Enable Telegram" and follow the link or scan the QR code.',
)
continue
token = parts[-1]
robot = Robot.objects.filter(telegram_token=token).first()
if not robot:
self.notifications.send_telegram_message(
chat_id=result["message"]["from"]["id"],
text=f'Wops, invalid token! There is no Robot with telegram chat token "{token}"',
result["message"]["from"]["id"],
f'Wops, invalid token! There is no Robot with telegram chat token "{token}"',
)
continue

View File

@ -37,13 +37,13 @@ class Notifications:
if robot.telegram_enabled:
self.send_telegram_message(robot.telegram_chat_id, title, description)
def save_message(self, order, robot, title, description):
def save_message(self, order, robot, title, description=""):
"""Save a message for a user"""
Notification.objects.create(
title=title, description=description, robot=robot, order=order
)
def send_telegram_message(self, chat_id, title, description):
def send_telegram_message(self, chat_id, title, description=""):
"""sends a message to a user with telegram notifications enabled"""
bot_token = config("TELEGRAM_TOKEN")

View File

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

View File

@ -23,11 +23,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",
@ -81,7 +81,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"
}
@ -6411,9 +6411,9 @@
}
},
"node_modules/country-flag-icons": {
"version": "1.5.11",
"resolved": "https://registry.npmjs.org/country-flag-icons/-/country-flag-icons-1.5.11.tgz",
"integrity": "sha512-B+mvFywunkRJs270k7kCBjhogvIA0uNn6GAXv6m2cPn3rrwqZzZVr2gBWcz+Cz7OGVWlcbERlYRIX0S6OGr8Bw=="
"version": "1.5.13",
"resolved": "https://registry.npmjs.org/country-flag-icons/-/country-flag-icons-1.5.13.tgz",
"integrity": "sha512-4JwHNqaKZ19doQoNcBjsoYA+I7NqCH/mC/6f5cBWvdKzcK5TMmzLpq3Z/syVHMHJuDGFwJ+rPpGizvrqJybJow=="
},
"node_modules/create-require": {
"version": "1.1.1",
@ -8823,9 +8823,9 @@
}
},
"node_modules/i18next-browser-languagedetector": {
"version": "7.2.1",
"resolved": "https://registry.npmjs.org/i18next-browser-languagedetector/-/i18next-browser-languagedetector-7.2.1.tgz",
"integrity": "sha512-h/pM34bcH6tbz8WgGXcmWauNpQupCGr25XPp9cZwZInR9XHSjIFDYp1SIok7zSPsTOMxdvuLyu86V+g2Kycnfw==",
"version": "8.0.0",
"resolved": "https://registry.npmjs.org/i18next-browser-languagedetector/-/i18next-browser-languagedetector-8.0.0.tgz",
"integrity": "sha512-zhXdJXTTCoG39QsrOCiOabnWj2jecouOqbchu3EfhtSHxIB5Uugnm9JaizenOy39h7ne3+fLikIjeW88+rgszw==",
"dependencies": {
"@babel/runtime": "^7.23.2"
}
@ -16730,9 +16730,9 @@
}
},
"node_modules/typescript": {
"version": "5.4.2",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.4.2.tgz",
"integrity": "sha512-+2/g0Fds1ERlP6JsakQQDXjZdZMM+rqpamFZJEKh4kwTIn3iDkgKtby0CeNd5ATNZ4Ry1ax15TMx0W2V+miizQ==",
"version": "5.5.4",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.5.4.tgz",
"integrity": "sha512-Mtq29sKDAEYP7aljRgtPOpTvOfbwRWlS6dPRzwjdE+C0R4brX/GUyhHSecbHMFLNBLcJIPt9nl9yG5TZ1weH+Q==",
"dev": true,
"bin": {
"tsc": "bin/tsc",

View File

@ -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"
},
@ -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",

View File

@ -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 (

View File

@ -156,7 +156,7 @@ const RobotProfile = ({
)}
</Grid>
{loadingCoordinators > 0 && !Boolean(robot?.activeOrderId) ? (
{loadingCoordinators > 0 && !robot?.activeOrderId ? (
<Grid>
<b>{t('Looking for orders!')}</b>
<LinearProgress />
@ -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}

View File

@ -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);
@ -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 {
@ -65,7 +65,9 @@ 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'
@ -73,7 +75,9 @@ const SettingsPage = (): JSX.Element => {
variant='outlined'
size='small'
value={newUrl}
onChange={(e) => setNewUrl(e.target.value)}
onChange={(e) => {
setNewUrl(e.target.value);
}}
/>
<Button
sx={{ maxHeight: 38 }}

View File

@ -14,7 +14,6 @@ import {
LinearProgress,
IconButton,
Tooltip,
type LinearProgressProps,
styled,
} from '@mui/material';
import {
@ -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';
@ -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

View File

@ -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 {

View File

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

View File

@ -1,4 +1,4 @@
import React, { useContext, useMemo } from 'react';
import React, { useContext } from 'react';
import {
Grid,
Select,

View File

@ -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 {
@ -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 {
@ -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 = [

View File

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

View File

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

View File

@ -56,7 +56,7 @@ export class Federation {
settings: Settings,
hostUrl: string,
attributes: Record<any, any>,
) => {
): void => {
const value = {
...coordinatorDefaultValues,
...attributes,
@ -115,7 +115,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();
});
@ -128,7 +128,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();
});
}

View File

@ -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';
@ -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];
@ -132,9 +137,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();
}
};

View File

@ -1,5 +1,5 @@
import { sha256 } from 'js-sha256';
import { Coordinator, Garage, Robot, type Order } from '.';
import { type Coordinator, type Garage, Robot, type Order } from '.';
import { roboidentitiesClient } from '../services/Roboidentities/Web';
class Slot {
@ -13,12 +13,12 @@ class Slot {
this.hashId = sha256(sha256(this.token));
this.nickname = null;
roboidentitiesClient.generateRoboname(this.hashId).then((nickname) => {
void roboidentitiesClient.generateRoboname(this.hashId).then((nickname) => {
this.nickname = nickname;
onRobotUpdate();
});
roboidentitiesClient.generateRobohash(this.hashId, 'small');
roboidentitiesClient.generateRobohash(this.hashId, 'large');
void roboidentitiesClient.generateRobohash(this.hashId, 'small');
void roboidentitiesClient.generateRobohash(this.hashId, 'large');
this.robots = shortAliases.reduce((acc: Record<string, Robot>, shortAlias: string) => {
acc[shortAlias] = new Robot(robotAttributes);
@ -82,7 +82,7 @@ class Slot {
pubKey: defaultRobot.pubKey,
encPrivKey: defaultRobot.encPrivKey,
});
coordinator.fetchRobot(garage, defaultRobot.token);
void coordinator.fetchRobot(garage, defaultRobot.token);
}
};
}

View File

@ -1,4 +1,4 @@
import RoboidentitiesClientNativeClient from './RoboidentitiesNativeClient';
import { RoboidentitiesClient } from './type';
import { type RoboidentitiesClient } from './type';
export const roboidentitiesClient: RoboidentitiesClient = new RoboidentitiesClientNativeClient();

View File

@ -31,8 +31,8 @@ class RoboidentitiesNativeClient implements RoboidentitiesClient {
type: 'robohash',
detail: key,
});
const result = response ? Object.values(response)[0] : '';
const image = `data:image/png;base64,${result}`;
const result: string = response ? Object.values(response)[0] : '';
const image: string = `data:image/png;base64,${result}`;
this.robohashes[key] = image;
return image;
}

View File

@ -4,14 +4,14 @@ import { robohash } from './RobohashGenerator';
class RoboidentitiesClientWebClient implements RoboidentitiesClient {
public generateRoboname: (initialString: string) => Promise<string> = async (initialString) => {
return new Promise<string>(async (resolve, _reject) => {
return await new Promise<string>((resolve, _reject) => {
resolve(generate_roboname(initialString));
});
};
public generateRobohash: (initialString: string, size: 'small' | 'large') => Promise<string> =
async (initialString, size) => {
return robohash.generate(initialString, size);
return await robohash.generate(initialString, size);
};
}

View File

@ -1,4 +1,4 @@
import RoboidentitiesClientWebClient from './RoboidentitiesWebClient';
import { RoboidentitiesClient } from './type';
import { type RoboidentitiesClient } from './type';
export const roboidentitiesClient: RoboidentitiesClient = new RoboidentitiesClientWebClient();

View File

@ -5,7 +5,7 @@ import ApiWebClient from '../ApiWebClient';
class ApiNativeClient implements ApiClient {
public useProxy = true;
private webClient: ApiClient = new ApiWebClient();
private readonly webClient: ApiClient = new ApiWebClient();
private readonly assetsPromises = new Map<string, Promise<string | undefined>>();
@ -55,7 +55,7 @@ class ApiNativeClient implements ApiClient {
public delete: (baseUrl: string, path: string, auth?: Auth) => Promise<object | undefined> =
async (baseUrl, path, auth) => {
if (!this.useProxy) return this.webClient.delete(baseUrl, path, auth);
if (!this.useProxy) return await this.webClient.delete(baseUrl, path, auth);
return await window.NativeRobosats?.postMessage({
category: 'http',
type: 'delete',
@ -71,7 +71,7 @@ class ApiNativeClient implements ApiClient {
body: object,
auth?: Auth,
) => Promise<object | undefined> = async (baseUrl, path, body, auth) => {
if (!this.useProxy) return this.webClient.post(baseUrl, path, body, auth);
if (!this.useProxy) return await this.webClient.post(baseUrl, path, body, auth);
return await window.NativeRobosats?.postMessage({
category: 'http',
type: 'post',
@ -87,7 +87,7 @@ class ApiNativeClient implements ApiClient {
path,
auth,
) => {
if (!this.useProxy) return this.webClient.get(baseUrl, path, auth);
if (!this.useProxy) return await this.webClient.get(baseUrl, path, auth);
return await window.NativeRobosats?.postMessage({
category: 'http',
type: 'get',

View File

@ -16,14 +16,6 @@ export interface AggregatedInfo {
version: Version;
}
type toAdd =
| 'num_public_buy_orders'
| 'num_public_sell_orders'
| 'book_liquidity'
| 'active_robots_today'
| 'last_day_volume'
| 'lifetime_volume';
export const weightedMean = (arrValues: number[], arrWeights: number[]): number => {
if (arrValues.length === 0) {
return 0;

2229
mobile/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -26,7 +26,7 @@
"@types/jest": "^29.5.12",
"@types/react-native": "^0.71.3",
"@types/react-test-renderer": "^18.0.0",
"@typescript-eslint/eslint-plugin": "^5.59.2",
"@typescript-eslint/eslint-plugin": "^8.0.1",
"@typescript-eslint/parser": "^5.59.6",
"babel-jest": "^29.7.0",
"eslint": "^8.39.0",
@ -35,13 +35,13 @@
"eslint-import-resolver-typescript": "^3.6.0",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-n": "^15.7.0",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-promise": "^6.1.1",
"eslint-plugin-react": "^7.32.2",
"eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-promise": "^6.6.0",
"eslint-plugin-react": "^7.35.0",
"eslint-plugin-react-hooks": "^4.6.2",
"jest": "^29.7.0",
"metro-react-native-babel-preset": "^0.75.1",
"prettier": "^3.3.2",
"prettier": "^3.3.3",
"react-test-renderer": "18.2.0",
"typescript": "^5.4.5"
},

View File

@ -1,4 +1,4 @@
django==5.0.6
django==5.0.8
django-admin-relation-links==0.2.5
django-celery-beat==2.6.0
django-celery-results==2.5.1
@ -19,7 +19,7 @@ ring==0.10.1
gunicorn==22.0.0
psycopg2==2.9.9
SQLAlchemy==2.0.16
django-import-export==4.1.0
django-import-export==4.1.1
requests[socks]
shapely==2.0.4
python-gnupg==0.5.2

View File

@ -1,4 +1,4 @@
coverage==7.5.0
coverage==7.6.0
ruff==0.5.1
git+https://github.com/Reckless-Satoshi/drf-openapi-tester.git@soften-django-requirements
pre-commit==3.7.0