Fix mobile app (#969)

This commit is contained in:
KoalaSat 2023-11-26 18:00:50 +00:00 committed by Reckless_Satoshi
parent e8ec7f989a
commit 802942761d
5 changed files with 37 additions and 23 deletions

View File

@ -45,7 +45,7 @@ const RobotProfile = ({
width, width,
}: RobotProfileProps): JSX.Element => { }: RobotProfileProps): JSX.Element => {
const { windowSize, hostUrl } = useContext<UseAppStoreType>(AppContext); 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 { sortedCoordinators } = useContext<UseFederationStoreType>(FederationContext);
const { t } = useTranslation(); const { t } = useTranslation();
@ -60,7 +60,7 @@ const RobotProfile = ({
if (robot?.nickname != null && slot?.avatarLoaded) { if (robot?.nickname != null && slot?.avatarLoaded) {
setLoading(false); setLoading(false);
} }
}, [robotUpdatedAt, loading]); }, [orderUpdatedAt, robotUpdatedAt, loading]);
const handleAddRobot = (): void => { const handleAddRobot = (): void => {
getGenerateRobot(genBase62Token(36)); getGenerateRobot(genBase62Token(36));

View File

@ -1,6 +1,7 @@
import { createContext, type Dispatch, useState, type SetStateAction, useEffect } from 'react'; import { createContext, type Dispatch, useState, type SetStateAction, useEffect } from 'react';
import { defaultMaker, type Maker, Garage } from '../models'; import { defaultMaker, type Maker, Garage } from '../models';
import { systemClient } from '../services/System';
export interface UseGarageStoreType { export interface UseGarageStoreType {
garage: Garage; garage: Garage;
@ -45,6 +46,12 @@ export const useGarageStore = (): UseGarageStoreType => {
garage.registerHook('onOrderUpdate', onOrderUpdate); garage.registerHook('onOrderUpdate', onOrderUpdate);
}, []); }, []);
useEffect(() => {
if (window.NativeRobosats !== undefined && !systemClient.loading) {
garage.loadSlots();
}
}, [systemClient.loading]);
return { return {
garage, garage,
maker, maker,

View File

@ -15,21 +15,7 @@ class Garage {
onOrderUpdate: [], onOrderUpdate: [],
}; };
const slotsDump: string = systemClient.getItem('garageSlots') ?? ''; this.loadSlots();
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');
}
} }
slots: { [token: string]: Slot }; slots: { [token: string]: Slot };
@ -50,21 +36,43 @@ class Garage {
// Storage // Storage
download = (): void => { download = (): void => {
saveAsJson(`garageSlots_${new Date().toISOString()}.json`, this.slots); saveAsJson(`garage_slots_${new Date().toISOString()}.json`, this.slots);
}; };
save = (): void => { save = (): void => {
systemClient.setItem('garageSlots', JSON.stringify(this.slots)); systemClient.setItem('garage_slots', JSON.stringify(this.slots));
}; };
delete = (): void => { delete = (): void => {
this.slots = {}; this.slots = {};
this.currentSlot = null; this.currentSlot = null;
systemClient.deleteItem('garageSlots'); systemClient.deleteItem('garage_slots');
this.triggerHook('onRobotUpdate'); this.triggerHook('onRobotUpdate');
this.triggerHook('onOrderUpdate'); 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 // Slots
getSlot: (token?: string) => Slot | null = (token) => { getSlot: (token?: string) => Slot | null = (token) => {
const currentToken = token ?? this.currentSlot; const currentToken = token ?? this.currentSlot;

View File

@ -119,7 +119,7 @@
"i2p": "" "i2p": ""
}, },
"testnet": { "testnet": {
"onion": "https://testraliar7xkhos2gipv2k65obykofb4jqzl5l4danfryacifi4t7qd.onion", "onion": "http://testraliar7xkhos2gipv2k65obykofb4jqzl5l4danfryacifi4t7qd.onion",
"clearnet": "https://test.unsafe.satstralia.com", "clearnet": "https://test.unsafe.satstralia.com",
"i2p": "" "i2p": ""
}, },

View File

@ -44,13 +44,12 @@ const App = () => {
}); });
}; };
loadCookie('robot_token');
loadCookie('settings_fontsize_basic'); loadCookie('settings_fontsize_basic');
loadCookie('settings_language'); loadCookie('settings_language');
loadCookie('settings_mode'); loadCookie('settings_mode');
loadCookie('settings_light_qr'); loadCookie('settings_light_qr');
loadCookie('settings_network'); loadCookie('settings_network');
loadCookie('garage').then(() => injectMessageResolve(responseId)); loadCookie('garage_slots').then(() => injectMessageResolve(responseId));
}; };
const onCatch = (dataId: string, event: any) => { const onCatch = (dataId: string, event: any) => {