Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add The Federation Layer #601

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
b30279b
Add federation basis and new coordinator form (#793)
Reckless-Satoshi Aug 21, 2023
9e211e8
Squash and rebase the-federation-layer over main v0.5.0
Reckless-Satoshi May 25, 2023
1f2628e
Federation robots (#635)
Reckless-Satoshi Aug 7, 2023
67af946
Improve main readability
Reckless-Satoshi Aug 7, 2023
d1b6257
Fix linting errors on federation-layer (#776)
Reckless-Satoshi Aug 11, 2023
ada817e
Enable on pull request JS linter
Reckless-Satoshi Aug 11, 2023
eee0d7e
Add coordinator selection component to maker form
Reckless-Satoshi Aug 14, 2023
f86e517
Add coordinator lottery sorting
Reckless-Satoshi Aug 14, 2023
1fb62b5
Add use sorted coordinators on book and maker page
Reckless-Satoshi Aug 15, 2023
7c2e88a
Add tldr to coordinator on book and maker pages
Reckless-Satoshi Aug 15, 2023
a40e41a
Fix federation limits
Reckless-Satoshi Aug 16, 2023
f065af4
Fix show non-awarded federation badges
Reckless-Satoshi Aug 17, 2023
471ffe2
Fix and adapt order page and navigation to federation
Reckless-Satoshi Aug 17, 2023
83e11b0
Fix routing in selfhosted app for multi-coordinators
Reckless-Satoshi Aug 17, 2023
18e749c
Add selfhosted logics for federation endpoints
Reckless-Satoshi Aug 18, 2023
dddecb5
Small fixes
Reckless-Satoshi Aug 19, 2023
ffefbdb
Bump version to v0.6.0-alpha
Reckless-Satoshi Aug 19, 2023
7ddb896
A
Reckless-Satoshi Aug 19, 2023
59e7875
Fix example coordinator descriptions
Reckless-Satoshi Aug 19, 2023
d2b8b87
Small fixes
Reckless-Satoshi Aug 20, 2023
4ab970d
Fix authorization cookies
Reckless-Satoshi Aug 21, 2023
14f002b
Small fixes
Reckless-Satoshi Aug 21, 2023
d521d5b
Small fixes
Reckless-Satoshi Aug 21, 2023
483021c
Update Nostr on Experimental coordinator
Reckless-Satoshi Aug 21, 2023
32f93c2
Fetch robot profile from coordinator
Reckless-Satoshi Sep 7, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions .github/workflows/js-linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
- main
paths:
- frontend
pull_request:
pull_request_target:
branches:
- main
paths:
Expand Down Expand Up @@ -41,7 +41,5 @@ jobs:
with:
prettier: true
prettier_dir: frontend

## Disabled due to error
# eslint: true
# eslint_dir: frontend
eslint: true
eslint_dir: frontend
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ services:
volumes:
- ./nodeapp/:/usr/src/robosats/
- ./nodeapp/nginx.conf:/etc/nginx/nginx.conf
- ./nodeapp/coordinators/:/etc/nginx/conf.d/
- ./frontend/static:/usr/src/robosats/static

clean-orders:
Expand Down
6 changes: 6 additions & 0 deletions federation.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,15 @@ Each RoboSats coordinator has a profile in the RoboSats app. The profile contain
- Large Limits - Can host orders with large limits.
- DevFund donator - Donates to the DevFund the default amount or more.

<<<<<<< HEAD
Some of these badges can be objectively measured and awarded. Other badges rely on the subjectivity of the development team. These will be generously awarded and only taken away after a warning.

We also envision more badges in the future, for example milestones by number of trades coordinated (200, 1K, 5K, 25K, 100K, etc).
=======
Some of these badges can be objectively measured and therefore awarded. Others badges rely on the subjectivity by the development team. These will be generously awarded and only taken away after a warning.

We also envision more badges in the future. For example milestones of number of trades coordinated (200, 1K, 5K, 25K, 100K, etc).
>>>>>>> 2254fa60 (Add federation basis and new coordinator form (#793))

## Timeline

Expand Down
11 changes: 10 additions & 1 deletion frontend/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,21 @@
"sourceType": "module",
"project": "./tsconfig.json"
},
"ignorePatterns": ["index.js", "**/PaymentMethods/Icons/code/code.js"],
"plugins": ["react", "react-hooks", "@typescript-eslint", "prettier"],
"rules": {
"react-hooks/rules-of-hooks": "error",
"react-hooks/exhaustive-deps": "warn",
"react/prop-types": "off",
"react/react-in-jsx-scope": "off"
"react/react-in-jsx-scope": "off",
"@typescript-eslint/naming-convention": [
"error",
{
"selector": "variableLike",
"format": ["camelCase", "snake_case", "PascalCase", "UPPER_CASE"],
"leadingUnderscore": "allow"
}
]
},
"settings": {
"import/resolver": {
Expand Down
4 changes: 2 additions & 2 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
@@ -1,14 +1,14 @@
{
"name": "frontend",
"version": "0.5.2",
"version": "0.6.0",
"description": "",
"main": "index.js",
"scripts": {
"dev": "node --max-old-space-size=4096 ./node_modules/.bin/webpack --watch --progress --mode development",
"test": "jest",
"build": "webpack --mode production",
"lint": "eslint src/**/*.{js,ts,tsx}",
"lint:fix": "eslint --fix 'src/**/*.{js,ts,tsx}'",
"lint": "eslint src/**/*.{js,ts,tsx} --quiet",
"lint:fix": "eslint --fix 'src/**/*.{js,ts,tsx}' --quiet",
"format": "prettier --write '**/**/*.{js,jsx,ts,tsx,css,md,json}' --config ./.prettierrc"
},
"keywords": [],
Expand Down
8 changes: 6 additions & 2 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,17 @@ const App = (): JSX.Element => {
);
};

const loadApp = () => {
const loadApp = (): void => {
// waits until the environment is ready for the Android WebView app
if (systemClient.loading) {
setTimeout(loadApp, 200);
} else {
const root = ReactDOM.createRoot(document.getElementById('app') ?? new HTMLElement());
root.render(<App />);
root.render(
<StrictMode>
<App />
</StrictMode>,
);
}
};

Expand Down
30 changes: 15 additions & 15 deletions frontend/src/basic/BookPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { BarChart, FormatListBulleted } from '@mui/icons-material';
import { AppContext, type UseAppStoreType } from '../../contexts/AppContext';

const BookPage = (): JSX.Element => {
const { robot, fetchBook, windowSize, setDelay, setOrder } =
const { robot, fetchFederationBook, windowSize, setDelay, clearOrder } =
useContext<UseAppStoreType>(AppContext);
const { t } = useTranslation();
const navigate = useNavigate();
Expand All @@ -27,24 +27,20 @@ const BookPage = (): JSX.Element => {
const chartWidthEm = width - maxBookTableWidth;

useEffect(() => {
fetchBook();
fetchFederationBook();
}, []);

const onViewOrder = function () {
setOrder(undefined);
setDelay(10000);
};

const onOrderClicked = function (id: number) {
const onOrderClicked = function (id: number, shortAlias: string): void {
if (robot.avatarLoaded) {
navigate('/order/' + id);
onViewOrder();
clearOrder();
setDelay(10000);
navigate(`/order/${shortAlias}/${id}`);
} else {
setOpenNoRobot(true);
}
};

const NavButtons = function () {
const NavButtons = function (): JSX.Element {
return (
<ButtonGroup variant='contained' color='inherit'>
<Button
Expand All @@ -63,7 +59,7 @@ const BookPage = (): JSX.Element => {
setView(view === 'depth' ? 'list' : 'depth');
}}
>
{view == 'depth' ? (
{view === 'depth' ? (
<>
<FormatListBulleted /> {t('List')}
</>
Expand All @@ -85,7 +81,9 @@ const BookPage = (): JSX.Element => {
onClose={() => {
setOpenNoRobot(false);
}}
onClickGenerateRobot={() => navigate('/robot')}
onClickGenerateRobot={() => {
navigate('/robot');
}}
/>
{openMaker ? (
<Dialog
Expand All @@ -97,9 +95,11 @@ const BookPage = (): JSX.Element => {
<Box sx={{ maxWidth: '18em', padding: '0.5em' }}>
<MakerForm
onOrderCreated={(id) => {
navigate('/order/' + id);
navigate(`/order/${id}`);
}}
onClickGenerateRobot={() => {
navigate('/robot');
}}
onClickGenerateRobot={() => navigate('/robot')}
/>
</Box>
</Dialog>
Expand Down
57 changes: 36 additions & 21 deletions frontend/src/basic/Main.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import React, { useContext } from 'react';
import React, { useContext, useEffect, useState } from 'react';
import { MemoryRouter, BrowserRouter, Routes, Route } from 'react-router-dom';
import { Box, Slide, Typography, styled } from '@mui/material';
import {
type UseAppStoreType,
AppContext,
closeAll,
hostUrl,
origin,
} from '../contexts/AppContext';

import RobotPage from './RobotPage';
import MakerPage from './MakerPage';
import BookPage from './BookPage';
import OrderPage from './OrderPage';
import SettingsPage from './SettingsPage';
import NavBar from './NavBar';
import MainDialogs from './MainDialogs';

import { RobotPage, MakerPage, BookPage, OrderPage, SettingsPage, NavBar, MainDialogs } from './';
import RobotAvatar from '../components/RobotAvatar';
import Notifications from '../components/Notifications';

import { useTranslation } from 'react-i18next';
import Notifications from '../components/Notifications';
import { type UseAppStoreType, AppContext, closeAll } from '../contexts/AppContext';
import { getEndpoint } from '../models/Coordinator.model';

const Router = window.NativeRobosats === undefined ? BrowserRouter : MemoryRouter;

Expand All @@ -39,21 +39,36 @@ const Main: React.FC = () => {
settings,
robot,
setRobot,
baseUrl,
order,
page,
slideDirection,
federation,
sortedCoordinators,
setOpen,
windowSize,
navbarHeight,
} = useContext<UseAppStoreType>(AppContext);

const [avatarBaseUrl, setAvatarBaseUrl] = useState<string>(hostUrl);

useEffect(() => {
const { url, basePath } = getEndpoint({
network: settings.network,
coordinator: federation[sortedCoordinators[0]],
origin,
selfHosted: settings.selfhostedClient,
hostUrl,
});
setAvatarBaseUrl(url + basePath);
console.log(url + basePath);
}, [settings.network, settings.selfhostedClient, federation, sortedCoordinators]);

return (
<Router>
<RobotAvatar
style={{ display: 'none' }}
nickname={robot.nickname}
baseUrl={baseUrl}
baseUrl={avatarBaseUrl}
onLoad={() => {
setRobot((robot) => {
return { ...robot, avatarLoaded: true };
Expand Down Expand Up @@ -87,10 +102,10 @@ const Main: React.FC = () => {
<Slide
direction={page === 'robot' ? slideDirection.in : slideDirection.out}
in={page === 'robot'}
appear={slideDirection.in != undefined}
appear={slideDirection.in !== undefined}
>
<div>
<RobotPage />
<RobotPage avatarBaseUrl={avatarBaseUrl} />
</div>
</Slide>
}
Expand All @@ -105,7 +120,7 @@ const Main: React.FC = () => {
<Slide
direction={page === 'offers' ? slideDirection.in : slideDirection.out}
in={page === 'offers'}
appear={slideDirection.in != undefined}
appear={slideDirection.in !== undefined}
>
<div>
<BookPage />
Expand All @@ -120,7 +135,7 @@ const Main: React.FC = () => {
<Slide
direction={page === 'create' ? slideDirection.in : slideDirection.out}
in={page === 'create'}
appear={slideDirection.in != undefined}
appear={slideDirection.in !== undefined}
>
<div>
<MakerPage />
Expand All @@ -130,12 +145,12 @@ const Main: React.FC = () => {
/>

<Route
path='/order/:orderId'
path='/order/:shortAlias/:orderId'
element={
<Slide
direction={page === 'order' ? slideDirection.in : slideDirection.out}
in={page === 'order'}
appear={slideDirection.in != undefined}
appear={slideDirection.in !== undefined}
>
<div>
<OrderPage />
Expand All @@ -150,7 +165,7 @@ const Main: React.FC = () => {
<Slide
direction={page === 'settings' ? slideDirection.in : slideDirection.out}
in={page === 'settings'}
appear={slideDirection.in != undefined}
appear={slideDirection.in !== undefined}
>
<div>
<SettingsPage />
Expand All @@ -160,7 +175,7 @@ const Main: React.FC = () => {
/>
</Routes>
</MainBox>
<NavBar width={windowSize.width} height={navbarHeight} />
<NavBar />
<MainDialogs />
</Router>
);
Expand Down
Loading