From 5ae1f8ca18aecc51e2e96f68eac6c694ce8c216b Mon Sep 17 00:00:00 2001 From: KoalaSat Date: Sun, 6 Nov 2022 16:20:54 +0000 Subject: [PATCH] Fix Robot token not loading to android (#313) * Fix Robot token not loading to android * Redo Maker --- frontend/package-lock.json | 4 +- frontend/src/basic/Main.tsx | 3 +- frontend/src/models/Robot.model.ts | 65 ++++++++++----------------- frontend/src/models/Settings.model.ts | 3 +- frontend/src/models/index.ts | 7 +-- frontend/src/pro/Main.tsx | 3 +- frontend/src/services/Native/index.ts | 1 - mobile/package-lock.json | 4 +- 8 files changed, 36 insertions(+), 54 deletions(-) diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 4c5ddc67..7e209c8a 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -1,12 +1,12 @@ { "name": "frontend", - "version": "0.2.2", + "version": "0.2.3", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "frontend", - "version": "0.2.2", + "version": "0.2.3", "license": "ISC", "dependencies": { "@babel/plugin-proposal-class-properties": "^7.16.7", diff --git a/frontend/src/basic/Main.tsx b/frontend/src/basic/Main.tsx index f4dec211..0412160f 100644 --- a/frontend/src/basic/Main.tsx +++ b/frontend/src/basic/Main.tsx @@ -20,7 +20,6 @@ import { Settings, Favorites, defaultMaker, - defaultRobot, defaultInfo, Coordinator, } from '../models'; @@ -56,7 +55,7 @@ const Main = ({ settings, setSettings }: MainProps): JSX.Element => { list: [], loading: true, }); - const [robot, setRobot] = useState(defaultRobot); + const [robot, setRobot] = useState(new Robot()); const [maker, setMaker] = useState(defaultMaker); const [info, setInfo] = useState(defaultInfo); const [coordinators, setCoordinators] = useState(defaultCoordinators); diff --git a/frontend/src/models/Robot.model.ts b/frontend/src/models/Robot.model.ts index b1df8008..35ea93c3 100644 --- a/frontend/src/models/Robot.model.ts +++ b/frontend/src/models/Robot.model.ts @@ -1,46 +1,29 @@ import { systemClient } from '../services/System'; -export interface Robot { - nickname: string | null; - token: string | null; - pubKey: string | null; - encPrivKey: string | null; - bitsEntropy: number | null; - shannonEntropy: number | null; - stealthInvoices: boolean; - activeOrderId: number | null; - lastOrderId: number | null; - earnedRewards: number; - referralCode: string; - tgEnabled: boolean; - tgBotName: string; - tgToken: string; - loading: boolean; - avatarLoaded: boolean; - copiedToken: boolean; +class Robot { + constructor() { + this.token = systemClient.getCookie('robot_token') ?? undefined; + this.pubKey = systemClient.getCookie('pub_key') ?? undefined; + this.encPrivKey = systemClient.getCookie('enc_priv_key') ?? undefined; + } + + public nickname?: string; + public token?: string; + public pubKey?: string; + public encPrivKey?: string; + public bitsEntropy?: number; + public shannonEntropy?: number; + public stealthInvoices: boolean = true; + public activeOrderId?: number; + public lastOrderId?: number; + public earnedRewards: number = 0; + public referralCode: string = ''; + public tgEnabled: boolean = false; + public tgBotName: string = 'unknown'; + public tgToken: string = 'unknown'; + public loading: boolean = false; + public avatarLoaded: boolean = false; + public copiedToken: boolean = false; } -const pubKeyCookie = systemClient.getCookie('pub_key'); -const privKeyCookie = systemClient.getCookie('enc_priv_key'); - -export const defaultRobot: Robot = { - nickname: null, - token: systemClient.getCookie('robot_token') ?? null, - pubKey: pubKeyCookie ? pubKeyCookie.split('\\').join('\n') : null, - encPrivKey: privKeyCookie ? privKeyCookie.split('\\').join('\n') : null, - bitsEntropy: null, - shannonEntropy: null, - stealthInvoices: true, - activeOrderId: null, - lastOrderId: null, - earnedRewards: 0, - referralCode: '', - tgEnabled: false, - tgBotName: 'unknown', - tgToken: 'unknown', - loading: false, - avatarLoaded: false, - copiedToken: false, -}; - export default Robot; diff --git a/frontend/src/models/Settings.model.ts b/frontend/src/models/Settings.model.ts index 7fc5a360..147980b0 100644 --- a/frontend/src/models/Settings.model.ts +++ b/frontend/src/models/Settings.model.ts @@ -36,7 +36,8 @@ export const baseSettings: Settings = { ? 'dark' : 'light', fontSize: 14, - language: i18n.resolvedLanguage == null ? 'en' : i18n.resolvedLanguage.substring(0, 2), + language: + i18n.resolvedLanguage == null ? 'en' : (i18n.resolvedLanguage.substring(0, 2) as Language), freezeViewports: false, network: undefined, coordinator: undefined, diff --git a/frontend/src/models/index.ts b/frontend/src/models/index.ts index 268beb05..0266021d 100644 --- a/frontend/src/models/index.ts +++ b/frontend/src/models/index.ts @@ -1,16 +1,17 @@ +import Robot from './Robot.model'; + export type { LimitList } from './Limit.model'; export type { Limit } from './Limit.model'; -export type { Maker } from './Maker.model'; export type { Order } from './Book.model'; export type { Book } from './Book.model'; -export type { Robot } from './Robot.model'; export type { Info } from './Info.model'; export type { Settings } from './Settings.model'; export type { Language } from './Settings.model'; export type { Favorites } from './Favorites.model'; export type { Coordinator } from './Coordinator.model'; +export type { Maker } from './Maker.model'; +export { Robot }; export { defaultMaker } from './Maker.model'; -export { defaultRobot } from './Robot.model'; export { defaultSettings } from './Settings.default.basic'; export { defaultInfo } from './Info.model'; diff --git a/frontend/src/pro/Main.tsx b/frontend/src/pro/Main.tsx index 68871f26..ee99231c 100644 --- a/frontend/src/pro/Main.tsx +++ b/frontend/src/pro/Main.tsx @@ -13,7 +13,6 @@ import { Settings, Favorites, defaultMaker, - defaultRobot, defaultInfo, } from '../models'; @@ -78,7 +77,7 @@ const Main = ({ settings, setSettings }: MainProps): JSX.Element => { list: [], loading: true, }); - const [robot, setRobot] = useState(defaultRobot); + const [robot, setRobot] = useState(new Robot()); const [maker, setMaker] = useState(defaultMaker); const [info, setInfo] = useState(defaultInfo); const [fav, setFav] = useState({ type: null, currency: 0 }); diff --git a/frontend/src/services/Native/index.ts b/frontend/src/services/Native/index.ts index 763651a9..fda462b2 100644 --- a/frontend/src/services/Native/index.ts +++ b/frontend/src/services/Native/index.ts @@ -1,4 +1,3 @@ -import { systemClient } from '../System'; import { NativeRobosatsPromise, NativeWebViewMessage, NativeWebViewMessageSystem } from './index.d'; class NativeRobosats { diff --git a/mobile/package-lock.json b/mobile/package-lock.json index 0c55c351..c6c9df82 100644 --- a/mobile/package-lock.json +++ b/mobile/package-lock.json @@ -1,12 +1,12 @@ { "name": "robosats", - "version": "0.2.2", + "version": "0.2.3", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "robosats", - "version": "0.2.2", + "version": "0.2.3", "dependencies": { "@react-native-clipboard/clipboard": "^1.11.1", "@react-native-community/netinfo": "^9.3.4",