mirror of
https://github.com/Reckless-Satoshi/robosats.git
synced 2024-08-16 23:30:29 +03:00
Fix mobile app (#969)
This commit is contained in:
parent
e8ec7f989a
commit
802942761d
@ -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();
|
||||
@ -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));
|
||||
|
@ -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,
|
||||
|
@ -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 };
|
||||
@ -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;
|
||||
|
@ -119,7 +119,7 @@
|
||||
"i2p": ""
|
||||
},
|
||||
"testnet": {
|
||||
"onion": "https://testraliar7xkhos2gipv2k65obykofb4jqzl5l4danfryacifi4t7qd.onion",
|
||||
"onion": "http://testraliar7xkhos2gipv2k65obykofb4jqzl5l4danfryacifi4t7qd.onion",
|
||||
"clearnet": "https://test.unsafe.satstralia.com",
|
||||
"i2p": ""
|
||||
},
|
||||
|
@ -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) => {
|
||||
|
Loading…
Reference in New Issue
Block a user