Skip to content

Commit cc1ef48

Browse files
KoalaSatReckless-Satoshi
authored andcommitted
Fix mobile app (#969)
1 parent 4785fd8 commit cc1ef48

File tree

5 files changed

+37
-23
lines changed

5 files changed

+37
-23
lines changed

frontend/src/basic/RobotPage/RobotProfile.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const RobotProfile = ({
4545
width,
4646
}: RobotProfileProps): JSX.Element => {
4747
const { windowSize, hostUrl } = useContext<UseAppStoreType>(AppContext);
48-
const { garage, robotUpdatedAt } = useContext<UseGarageStoreType>(GarageContext);
48+
const { garage, robotUpdatedAt, orderUpdatedAt } = useContext<UseGarageStoreType>(GarageContext);
4949
const { sortedCoordinators } = useContext<UseFederationStoreType>(FederationContext);
5050

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

6565
const handleAddRobot = (): void => {
6666
getGenerateRobot(genBase62Token(36));

frontend/src/contexts/GarageContext.ts

+7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { createContext, type Dispatch, useState, type SetStateAction, useEffect } from 'react';
22

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

56
export interface UseGarageStoreType {
67
garage: Garage;
@@ -45,6 +46,12 @@ export const useGarageStore = (): UseGarageStoreType => {
4546
garage.registerHook('onOrderUpdate', onOrderUpdate);
4647
}, []);
4748

49+
useEffect(() => {
50+
if (window.NativeRobosats !== undefined && !systemClient.loading) {
51+
garage.loadSlots();
52+
}
53+
}, [systemClient.loading]);
54+
4855
return {
4956
garage,
5057
maker,

frontend/src/models/Garage.model.ts

+26-18
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,7 @@ class Garage {
1515
onOrderUpdate: [],
1616
};
1717

18-
const slotsDump: string = systemClient.getItem('garageSlots') ?? '';
19-
if (slotsDump !== '') {
20-
const rawSlots = JSON.parse(slotsDump);
21-
Object.values(rawSlots).forEach((rawSlot: Record<any, any>) => {
22-
if (rawSlot?.token) {
23-
this.createSlot(rawSlot?.token);
24-
Object.keys(rawSlot.robots).forEach((shortAlias) => {
25-
const rawRobot = rawSlot.robots[shortAlias];
26-
this.upsertRobot(rawRobot.token, shortAlias, rawRobot);
27-
});
28-
this.currentSlot = rawSlot?.token;
29-
}
30-
});
31-
console.log('Robot Garage was loaded from local storage');
32-
}
18+
this.loadSlots();
3319
}
3420

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

5137
// Storage
5238
download = (): void => {
53-
saveAsJson(`garageSlots_${new Date().toISOString()}.json`, this.slots);
39+
saveAsJson(`garage_slots_${new Date().toISOString()}.json`, this.slots);
5440
};
5541

5642
save = (): void => {
57-
systemClient.setItem('garageSlots', JSON.stringify(this.slots));
43+
systemClient.setItem('garage_slots', JSON.stringify(this.slots));
5844
};
5945

6046
delete = (): void => {
6147
this.slots = {};
6248
this.currentSlot = null;
63-
systemClient.deleteItem('garageSlots');
49+
systemClient.deleteItem('garage_slots');
6450
this.triggerHook('onRobotUpdate');
6551
this.triggerHook('onOrderUpdate');
6652
};
6753

54+
loadSlots = (): void => {
55+
this.slots = {};
56+
const slotsDump: string = systemClient.getItem('garage_slots') ?? '';
57+
58+
if (slotsDump !== '') {
59+
const rawSlots = JSON.parse(slotsDump);
60+
Object.values(rawSlots).forEach((rawSlot: Record<any, any>) => {
61+
if (rawSlot?.token) {
62+
this.createSlot(rawSlot?.token);
63+
Object.keys(rawSlot.robots).forEach((shortAlias) => {
64+
const rawRobot = rawSlot.robots[shortAlias];
65+
this.upsertRobot(rawRobot.token, shortAlias, rawRobot);
66+
});
67+
this.currentSlot = rawSlot?.token;
68+
}
69+
});
70+
console.log('Robot Garage was loaded from local storage');
71+
this.triggerHook('onRobotUpdate');
72+
this.triggerHook('onOrderUpdate');
73+
}
74+
};
75+
6876
// Slots
6977
getSlot: (token?: string) => Slot | null = (token) => {
7078
const currentToken = token ?? this.currentSlot;

frontend/static/federation.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@
119119
"i2p": ""
120120
},
121121
"testnet": {
122-
"onion": "https://testraliar7xkhos2gipv2k65obykofb4jqzl5l4danfryacifi4t7qd.onion",
122+
"onion": "http://testraliar7xkhos2gipv2k65obykofb4jqzl5l4danfryacifi4t7qd.onion",
123123
"clearnet": "https://test.unsafe.satstralia.com",
124124
"i2p": ""
125125
},

mobile/App.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,12 @@ const App = () => {
4444
});
4545
};
4646

47-
loadCookie('robot_token');
4847
loadCookie('settings_fontsize_basic');
4948
loadCookie('settings_language');
5049
loadCookie('settings_mode');
5150
loadCookie('settings_light_qr');
5251
loadCookie('settings_network');
53-
loadCookie('garage').then(() => injectMessageResolve(responseId));
52+
loadCookie('garage_slots').then(() => injectMessageResolve(responseId));
5453
};
5554

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

0 commit comments

Comments
 (0)