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

Android notification system #1380

Merged
merged 14 commits into from
Sep 6, 2024
Merged
25 changes: 25 additions & 0 deletions api/lightning/pip-build-env-wwuhobll/site/sitecustomize.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import os
import site
import sys

# First, drop system-sites related paths.
original_sys_path = sys.path[:]
known_paths = set()
for path in {"/usr/local/lib/python3.12/site-packages"}:
site.addsitedir(path, known_paths=known_paths)
system_paths = set(
os.path.normcase(path) for path in sys.path[len(original_sys_path) :]
)
original_sys_path = [
path for path in original_sys_path if os.path.normcase(path) not in system_paths
]
sys.path = original_sys_path

# Second, add lib directories.
# ensuring .pth file are processed.
for path in [
"/tmp/pip-build-env-wwuhobll/overlay/lib/python3.12/site-packages",
"/tmp/pip-build-env-wwuhobll/normal/lib/python3.12/site-packages",
]:
assert path not in sys.path
site.addsitedir(path)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we might have commited a few files under api/lightning that are not part of this PR and possibly shouod be ignored?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no idea why but these files has been extremely persistent on being created, everytine I tried to do a commit they appear probably because after-commit, any clue?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed anyways

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
git+https://github.com/Reckless-Satoshi/drf-openapi-tester.git@soften-django-requirements (from -r requirements_dev.txt (line 3))
1 change: 1 addition & 0 deletions api/lightning/pip-req-build-bfeegnca
Submodule pip-req-build-bfeegnca added at 2af4d2
89 changes: 5 additions & 84 deletions frontend/src/basic/Main.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import React, { useContext } from 'react';
import { MemoryRouter, BrowserRouter, Routes, Route } from 'react-router-dom';
import { Box, Slide, Typography, styled } from '@mui/material';
import { MemoryRouter, BrowserRouter } from 'react-router-dom';
import { Box, Typography, styled } from '@mui/material';
import { type UseAppStoreType, AppContext, closeAll } from '../contexts/AppContext';

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

import { useTranslation } from 'react-i18next';
import { GarageContext, type UseGarageStoreType } from '../contexts/GarageContext';
import Routes from './Routes';

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

Expand Down Expand Up @@ -53,87 +54,7 @@ const Main: React.FC = () => {
)}

<MainBox navbarHeight={navbarHeight}>
<Routes>
{['/robot/:token?', '/', ''].map((path, index) => {
return (
<Route
path={path}
element={
<Slide
direction={page === 'robot' ? slideDirection.in : slideDirection.out}
in={page === 'robot'}
appear={slideDirection.in !== undefined}
>
<div>
<RobotPage />
</div>
</Slide>
}
key={index}
/>
);
})}

<Route
path={'/offers'}
element={
<Slide
direction={page === 'offers' ? slideDirection.in : slideDirection.out}
in={page === 'offers'}
appear={slideDirection.in !== undefined}
>
<div>
<BookPage />
</div>
</Slide>
}
/>

<Route
path='/create'
element={
<Slide
direction={page === 'create' ? slideDirection.in : slideDirection.out}
in={page === 'create'}
appear={slideDirection.in !== undefined}
>
<div>
<MakerPage />
</div>
</Slide>
}
/>

<Route
path='/order/:shortAlias/:orderId'
element={
<Slide
direction={page === 'order' ? slideDirection.in : slideDirection.out}
in={page === 'order'}
appear={slideDirection.in !== undefined}
>
<div>
<OrderPage />
</div>
</Slide>
}
/>

<Route
path='/settings'
element={
<Slide
direction={page === 'settings' ? slideDirection.in : slideDirection.out}
in={page === 'settings'}
appear={slideDirection.in !== undefined}
>
<div>
<SettingsPage />
</div>
</Slide>
}
/>
</Routes>
<Routes />
</MainBox>
<NavBar />
<MainDialogs />
Expand Down
114 changes: 114 additions & 0 deletions frontend/src/basic/Routes.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
import React, { useContext, useEffect } from 'react';
import { Routes as DomRoutes, Route, useNavigate } from 'react-router-dom';
import { Box, Slide, Typography, styled } from '@mui/material';
import { type UseAppStoreType, AppContext } from '../contexts/AppContext';

import { RobotPage, MakerPage, BookPage, OrderPage, SettingsPage } from '.';
import { GarageContext, UseGarageStoreType } from '../contexts/GarageContext';

const Routes: React.FC = () => {
const navigate = useNavigate();
const { garage } = useContext<UseGarageStoreType>(GarageContext);
const { page, slideDirection } = useContext<UseAppStoreType>(AppContext);

useEffect(() => {
window.addEventListener('navigateToPage', (event) => {
console.log('navigateToPage', JSON.stringify(event));
const orderId = event?.detail?.order_id;
const coordinator = event?.detail?.coordinator;
if (orderId && coordinator) {
const slot = garage.getSlotByOrder(coordinator, orderId);
if (slot?.token) {
garage.setCurrentSlot(slot?.token);
navigate(`/order/${coordinator}/${orderId}`);
}
}
});
}, []);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Necessary to catch navigation requests form the system


return (
<DomRoutes>
{['/robot/:token?', '/', ''].map((path, index) => {
return (
<Route
path={path}
element={
<Slide
direction={page === 'robot' ? slideDirection.in : slideDirection.out}
in={page === 'robot'}
appear={slideDirection.in !== undefined}
>
<div>
<RobotPage />
</div>
</Slide>
}
key={index}
/>
);
})}

<Route
path={'/offers'}
element={
<Slide
direction={page === 'offers' ? slideDirection.in : slideDirection.out}
in={page === 'offers'}
appear={slideDirection.in !== undefined}
>
<div>
<BookPage />
</div>
</Slide>
}
/>

<Route
path='/create'
element={
<Slide
direction={page === 'create' ? slideDirection.in : slideDirection.out}
in={page === 'create'}
appear={slideDirection.in !== undefined}
>
<div>
<MakerPage />
</div>
</Slide>
}
/>

<Route
path='/order/:shortAlias/:orderId'
element={
<Slide
direction={page === 'order' ? slideDirection.in : slideDirection.out}
in={page === 'order'}
appear={slideDirection.in !== undefined}
>
<div>
<OrderPage />
</div>
</Slide>
}
/>

<Route
path='/settings'
element={
<Slide
direction={page === 'settings' ? slideDirection.in : slideDirection.out}
in={page === 'settings'}
appear={slideDirection.in !== undefined}
>
<div>
<SettingsPage />
</div>
</Slide>
}
/>
</DomRoutes>
);
};

export default Routes;
4 changes: 4 additions & 0 deletions frontend/src/models/Federation.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
defaultExchange,
} from '.';
import defaultFederation from '../../static/federation.json';
import { systemClient } from '../services/System';
import { getHost } from '../utils';
import { coordinatorDefaultValues } from './Coordinator.model';
import { updateExchangeInfo } from './Exchange.model';
Expand Down Expand Up @@ -90,9 +91,12 @@ export class Federation {
};

updateUrl = async (origin: Origin, settings: Settings, hostUrl: string): Promise<void> => {
const federationUrls = {};
for (const coor of Object.values(this.coordinators)) {
coor.updateUrl(origin, settings, hostUrl);
federationUrls[coor.shortAlias] = coor.url;
}
systemClient.setCookie('federation', JSON.stringify(federationUrls));
Copy link
Member Author

@KoalaSat KoalaSat Jul 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Informs the system about current coordinators and their URLs, useful when changing to tesnet and to avoid duplication on the systems' code

};

update = async (): Promise<void> => {
Expand Down
15 changes: 15 additions & 0 deletions frontend/src/models/Garage.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,30 @@ class Garage {
const slot = this.getSlot(token);
if (attributes) {
if (attributes.copiedToken !== undefined) slot?.setCopiedToken(attributes.copiedToken);
this.save();
this.triggerHook('onRobotUpdate');
}
return slot;
};

setCurrentSlot: (currentSlot: string) => void = (currentSlot) => {
this.currentSlot = currentSlot;
this.save();
this.triggerHook('onRobotUpdate');
};

getSlotByOrder: (coordinator: string, orderID: number) => Slot | null = (
coordinator,
orderID,
) => {
return (
Object.values(this.slots).find((slot) => {
const robot = slot.getRobot(coordinator);
return slot.activeShortAlias === coordinator && robot?.activeOrderId === orderID;
}) ?? null
);
};

// Robots
createRobot: (token: string, shortAliases: string[], attributes: Record<any, any>) => void = (
token,
Expand Down Expand Up @@ -169,6 +183,7 @@ class Garage {
Object.values(this.slots).forEach((slot) => {
slot.syncCoordinator(coordinator, this);
});
this.save();
};
}

Expand Down
8 changes: 7 additions & 1 deletion frontend/src/services/Native/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@ export interface NativeWebViewMessageHttp {
export interface NativeWebViewMessageSystem {
id?: number;
category: 'system';
type: 'init' | 'torStatus' | 'copyToClipboardString' | 'setCookie' | 'deleteCookie';
type:
| 'init'
| 'torStatus'
| 'copyToClipboardString'
| 'setCookie'
| 'deleteCookie'
| 'navigateToPage';
key?: string;
detail?: string;
}
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/services/Native/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { redirect } from 'react-router-dom';
import {
type NativeRobosatsPromise,
type NativeWebViewMessage,
Expand Down Expand Up @@ -45,6 +46,8 @@ class NativeRobosats {
if (message.key !== undefined) {
this.cookies[message.key] = String(message.detail);
}
} else if (message.type === 'navigateToPage') {
window.dispatchEvent(new CustomEvent('navigateToPage', { detail: message?.detail }));
}
};

Expand Down
Loading
Loading