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

Fix mobile app #969

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions frontend/src/basic/RobotPage/RobotProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const RobotProfile = ({
width,
}: RobotProfileProps): JSX.Element => {
const { windowSize, hostUrl } = useContext<UseAppStoreType>(AppContext);
const { garage, robotUpdatedAt } = useContext<UseGarageStoreType>(GarageContext);
const { garage, robotUpdatedAt, orderUpdatedAt } = useContext<UseGarageStoreType>(GarageContext);
const { sortedCoordinators } = useContext<UseFederationStoreType>(FederationContext);

const { t } = useTranslation();
Expand All @@ -60,7 +60,7 @@ const RobotProfile = ({
if (robot?.nickname != null && slot?.avatarLoaded) {
setLoading(false);
}
}, [robotUpdatedAt, loading]);
}, [orderUpdatedAt, robotUpdatedAt, loading]);

const handleAddRobot = (): void => {
getGenerateRobot(genBase62Token(36));
Expand Down
7 changes: 7 additions & 0 deletions frontend/src/contexts/GarageContext.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { createContext, type Dispatch, useState, type SetStateAction, useEffect } from 'react';

import { defaultMaker, type Maker, Garage } from '../models';
import { systemClient } from '../services/System';

export interface UseGarageStoreType {
garage: Garage;
Expand Down Expand Up @@ -45,6 +46,12 @@ export const useGarageStore = (): UseGarageStoreType => {
garage.registerHook('onOrderUpdate', onOrderUpdate);
}, []);

useEffect(() => {
if (window.NativeRobosats !== undefined && !systemClient.loading) {
garage.loadSlots();
}
}, [systemClient.loading]);

return {
garage,
maker,
Expand Down
44 changes: 26 additions & 18 deletions frontend/src/models/Garage.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,7 @@ class Garage {
onOrderUpdate: [],
};

const slotsDump: string = systemClient.getItem('garageSlots') ?? '';
if (slotsDump !== '') {
const rawSlots = JSON.parse(slotsDump);
Object.values(rawSlots).forEach((rawSlot: Record<any, any>) => {
if (rawSlot?.token) {
this.createSlot(rawSlot?.token);
Object.keys(rawSlot.robots).forEach((shortAlias) => {
const rawRobot = rawSlot.robots[shortAlias];
this.upsertRobot(rawRobot.token, shortAlias, rawRobot);
});
this.currentSlot = rawSlot?.token;
}
});
console.log('Robot Garage was loaded from local storage');
}
this.loadSlots();
}

slots: { [token: string]: Slot };
Expand All @@ -50,21 +36,43 @@ class Garage {

// Storage
download = (): void => {
saveAsJson(`garageSlots_${new Date().toISOString()}.json`, this.slots);
saveAsJson(`garage_slots_${new Date().toISOString()}.json`, this.slots);
};

save = (): void => {
systemClient.setItem('garageSlots', JSON.stringify(this.slots));
systemClient.setItem('garage_slots', JSON.stringify(this.slots));
};

delete = (): void => {
this.slots = {};
this.currentSlot = null;
systemClient.deleteItem('garageSlots');
systemClient.deleteItem('garage_slots');
this.triggerHook('onRobotUpdate');
this.triggerHook('onOrderUpdate');
};

loadSlots = (): void => {
this.slots = {};
const slotsDump: string = systemClient.getItem('garage_slots') ?? '';

if (slotsDump !== '') {
const rawSlots = JSON.parse(slotsDump);
Object.values(rawSlots).forEach((rawSlot: Record<any, any>) => {
if (rawSlot?.token) {
this.createSlot(rawSlot?.token);
Object.keys(rawSlot.robots).forEach((shortAlias) => {
const rawRobot = rawSlot.robots[shortAlias];
this.upsertRobot(rawRobot.token, shortAlias, rawRobot);
});
this.currentSlot = rawSlot?.token;
}
});
console.log('Robot Garage was loaded from local storage');
this.triggerHook('onRobotUpdate');
this.triggerHook('onOrderUpdate');
}
};

// Slots
getSlot: (token?: string) => Slot | null = (token) => {
const currentToken = token ?? this.currentSlot;
Expand Down
2 changes: 1 addition & 1 deletion frontend/static/federation.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
"i2p": ""
},
"testnet": {
"onion": "https://testraliar7xkhos2gipv2k65obykofb4jqzl5l4danfryacifi4t7qd.onion",
"onion": "http://testraliar7xkhos2gipv2k65obykofb4jqzl5l4danfryacifi4t7qd.onion",
Copy link
Member Author

Choose a reason for hiding this comment

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

https is not valid and making the request in mobile to fail

Copy link
Collaborator

Choose a reason for hiding this comment

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

https is likely to fail in browser too, was it working in the browser? Maybe TOR browser is smart enough to replace it for http by default. Onion services are usually http:// as they do not require TLS and it is, in fact, difficult to set up TLS for onion. More info: https://community.torproject.org/onion-services/advanced/https/

"clearnet": "https://test.unsafe.satstralia.com",
"i2p": ""
},
Expand Down
3 changes: 1 addition & 2 deletions mobile/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,12 @@ const App = () => {
});
};

loadCookie('robot_token');
loadCookie('settings_fontsize_basic');
loadCookie('settings_language');
loadCookie('settings_mode');
loadCookie('settings_light_qr');
loadCookie('settings_network');
loadCookie('garage').then(() => injectMessageResolve(responseId));
loadCookie('garage_slots').then(() => injectMessageResolve(responseId));
};

const onCatch = (dataId: string, event: any) => {
Expand Down