diff --git a/frontend/src/basic/RobotPage/RobotProfile.tsx b/frontend/src/basic/RobotPage/RobotProfile.tsx index 1d909417..46198203 100644 --- a/frontend/src/basic/RobotPage/RobotProfile.tsx +++ b/frontend/src/basic/RobotPage/RobotProfile.tsx @@ -45,7 +45,7 @@ const RobotProfile = ({ width, }: RobotProfileProps): JSX.Element => { const { windowSize, hostUrl } = useContext(AppContext); - const { garage, robotUpdatedAt } = useContext(GarageContext); + const { garage, robotUpdatedAt, orderUpdatedAt } = useContext(GarageContext); const { sortedCoordinators } = useContext(FederationContext); const { t } = useTranslation(); @@ -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)); diff --git a/frontend/src/contexts/GarageContext.ts b/frontend/src/contexts/GarageContext.ts index fd9083e3..6c1c4db5 100644 --- a/frontend/src/contexts/GarageContext.ts +++ b/frontend/src/contexts/GarageContext.ts @@ -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; @@ -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, diff --git a/frontend/src/models/Garage.model.ts b/frontend/src/models/Garage.model.ts index c3e1310b..8f51c350 100644 --- a/frontend/src/models/Garage.model.ts +++ b/frontend/src/models/Garage.model.ts @@ -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) => { - 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 }; @@ -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) => { + 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; diff --git a/frontend/static/federation.json b/frontend/static/federation.json index 56ef5521..7c02a23b 100644 --- a/frontend/static/federation.json +++ b/frontend/static/federation.json @@ -119,7 +119,7 @@ "i2p": "" }, "testnet": { - "onion": "https://testraliar7xkhos2gipv2k65obykofb4jqzl5l4danfryacifi4t7qd.onion", + "onion": "http://testraliar7xkhos2gipv2k65obykofb4jqzl5l4danfryacifi4t7qd.onion", "clearnet": "https://test.unsafe.satstralia.com", "i2p": "" }, diff --git a/mobile/App.tsx b/mobile/App.tsx index 53255130..66a2babe 100644 --- a/mobile/App.tsx +++ b/mobile/App.tsx @@ -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) => {