diff --git a/frontend/src/basic/UserGenPage.js b/frontend/src/basic/UserGenPage.js index 83dc166c..36e42351 100644 --- a/frontend/src/basic/UserGenPage.js +++ b/frontend/src/basic/UserGenPage.js @@ -115,12 +115,9 @@ class UserGenPage extends Component { encPrivKey: data.encrypted_private_key, copiedToken: data.found ? true : this.props.robot.copiedToken, }) & - systemClient.setCookie('robot_token', token) & - systemClient.setCookie('pub_key', data.public_key.split('\n').join('\\')) & - systemClient.setCookie( - 'enc_priv_key', - data.encrypted_private_key.split('\n').join('\\'), - ); + systemClient.setItem('robot_token', token) & + systemClient.setItem('pub_key', data.public_key.split('\n').join('\\')) & + systemClient.setItem('enc_priv_key', data.encrypted_private_key.split('\n').join('\\')); }), ); }; @@ -298,7 +295,7 @@ class UserGenPage extends Component { color='primary' disabled={ !this.props.robot.avatarLoaded || - !(systemClient.getCookie('robot_token') == this.state.inputToken) + !(systemClient.getItem('robot_token') == this.state.inputToken) } onClick={() => saveAsJson( @@ -320,10 +317,10 @@ class UserGenPage extends Component { color={this.props.robot.copiedToken ? 'inherit' : 'primary'} disabled={ !this.props.robot.avatarLoaded || - !(systemClient.getCookie('robot_token') === this.state.inputToken) + !(systemClient.getItem('robot_token') === this.state.inputToken) } onClick={() => - systemClient.copyToClipboard(systemClient.getCookie('robot_token')) & + systemClient.copyToClipboard(systemClient.getItem('robot_token')) & this.props.setRobot({ ...this.props.robot, copiedToken: true }) } > diff --git a/frontend/src/components/Dialogs/Profile.tsx b/frontend/src/components/Dialogs/Profile.tsx index a8d13a3c..6bf40dfd 100644 --- a/frontend/src/components/Dialogs/Profile.tsx +++ b/frontend/src/components/Dialogs/Profile.tsx @@ -83,7 +83,7 @@ const ProfileDialog = ({ }, [showRewards]); const copyTokenHandler = () => { - const robotToken = systemClient.getCookie('robot_token'); + const robotToken = systemClient.getItem('robot_token'); if (robotToken) { systemClient.copyToClipboard(robotToken); @@ -244,12 +244,12 @@ const ProfileDialog = ({ - {systemClient.getCookie('robot_token') ? ( + {systemClient.getItem('robot_token') ? ( - systemClient.copyToClipboard(systemClient.getCookie('robot_token')) + systemClient.copyToClipboard(systemClient.getItem('robot_token')) } > diff --git a/frontend/src/components/SettingsForm/index.tsx b/frontend/src/components/SettingsForm/index.tsx index 1873150a..a08c1ca3 100644 --- a/frontend/src/components/SettingsForm/index.tsx +++ b/frontend/src/components/SettingsForm/index.tsx @@ -61,7 +61,7 @@ const SettingsForm = ({ language={settings.language} setLanguage={(language) => { setSettings({ ...settings, language }); - systemClient.setCookie('settings_language', language); + systemClient.setItem('settings_language', language); }} /> @@ -110,7 +110,7 @@ const SettingsForm = ({ onChange={(e) => { const mode = e.target.checked ? 'dark' : 'light'; setSettings({ ...settings, mode }); - systemClient.setCookie('settings_mode', mode); + systemClient.setItem('settings_mode', mode); }} /> } @@ -129,10 +129,7 @@ const SettingsForm = ({ onChange={(e) => { const fontSize = e.target.value; setSettings({ ...settings, fontSize }); - systemClient.setCookie( - `settings_fontsize_${settings.frontend}`, - fontSize.toString(), - ); + systemClient.setItem(`settings_fontsize_${settings.frontend}`, fontSize.toString()); }} valueLabelDisplay='off' marks={fontSizes.map(({ label, value }) => ({ @@ -152,7 +149,7 @@ const SettingsForm = ({ value={settings.network} onChange={(e, network) => { setSettings({ ...settings, network }); - systemClient.setCookie('settings_network', network); + systemClient.setItem('settings_network', network); }} > diff --git a/frontend/src/components/TradeBox/EncryptedChat/index.tsx b/frontend/src/components/TradeBox/EncryptedChat/index.tsx index 29a731a6..82af7256 100644 --- a/frontend/src/components/TradeBox/EncryptedChat/index.tsx +++ b/frontend/src/components/TradeBox/EncryptedChat/index.tsx @@ -44,13 +44,13 @@ const EncryptedChat: React.FC = ({ orderId, userNick, baseUrl }: Props): const [connected, setConnected] = useState(false); const [peerConnected, setPeerConnected] = useState(false); const [ownPubKey] = useState( - (systemClient.getCookie('pub_key') ?? '').split('\\').join('\n'), + (systemClient.getItem('pub_key') ?? '').split('\\').join('\n'), ); const [ownEncPrivKey] = useState( - (systemClient.getCookie('enc_priv_key') ?? '').split('\\').join('\n'), + (systemClient.getItem('enc_priv_key') ?? '').split('\\').join('\n'), ); const [peerPubKey, setPeerPubKey] = useState(); - const [token] = useState(systemClient.getCookie('robot_token') || ''); + const [token] = useState(systemClient.getItem('robot_token') || ''); const [messages, setMessages] = useState([]); const [serverMessages, setServerMessages] = useState([]); const [value, setValue] = useState(''); diff --git a/frontend/src/models/Robot.model.ts b/frontend/src/models/Robot.model.ts index 35ea93c3..32330e27 100644 --- a/frontend/src/models/Robot.model.ts +++ b/frontend/src/models/Robot.model.ts @@ -2,9 +2,9 @@ import { systemClient } from '../services/System'; 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; + this.token = systemClient.getItem('robot_token') ?? undefined; + this.pubKey = systemClient.getItem('pub_key') ?? undefined; + this.encPrivKey = systemClient.getItem('enc_priv_key') ?? undefined; } public nickname?: string; diff --git a/frontend/src/models/Settings.default.basic.ts b/frontend/src/models/Settings.default.basic.ts index 005df634..a8f81925 100644 --- a/frontend/src/models/Settings.default.basic.ts +++ b/frontend/src/models/Settings.default.basic.ts @@ -4,7 +4,7 @@ import BaseSettings from './Settings.model'; class Settings extends BaseSettings { constructor() { super(); - const fontSizeCookie = systemClient.getCookie('settings_fontsize_basic'); + const fontSizeCookie = systemClient.getItem('settings_fontsize_basic'); this.fontSize = fontSizeCookie !== '' ? Number(fontSizeCookie) : 14; } public frontend: 'basic' | 'pro' = 'basic'; diff --git a/frontend/src/models/Settings.default.pro.ts b/frontend/src/models/Settings.default.pro.ts index 835082fb..98092311 100644 --- a/frontend/src/models/Settings.default.pro.ts +++ b/frontend/src/models/Settings.default.pro.ts @@ -4,7 +4,7 @@ import BaseSettings from './Settings.model'; class Settings extends BaseSettings { constructor() { super(); - const fontSizeCookie = systemClient.getCookie('settings_fontsize_pro'); + const fontSizeCookie = systemClient.getItem('settings_fontsize_pro'); this.fontSize = fontSizeCookie !== '' ? Number(fontSizeCookie) : 12; } public frontend: 'basic' | 'pro' = 'pro'; diff --git a/frontend/src/models/Settings.model.ts b/frontend/src/models/Settings.model.ts index 189c48f8..ce0fd874 100644 --- a/frontend/src/models/Settings.model.ts +++ b/frontend/src/models/Settings.model.ts @@ -22,7 +22,7 @@ export type Language = class BaseSettings { constructor() { - const modeCookie: 'light' | 'dark' | '' = systemClient.getCookie('settings_mode'); + const modeCookie: 'light' | 'dark' | '' = systemClient.getItem('settings_mode'); this.mode = modeCookie !== '' ? modeCookie @@ -30,7 +30,7 @@ class BaseSettings { ? 'dark' : 'light'; - const languageCookie = systemClient.getCookie('settings_language'); + const languageCookie = systemClient.getItem('settings_language'); this.language = languageCookie !== '' ? languageCookie @@ -38,7 +38,7 @@ class BaseSettings { ? 'en' : i18n.resolvedLanguage.substring(0, 2); - const networkCookie = systemClient.getCookie('settings_network'); + const networkCookie = systemClient.getItem('settings_network'); this.network = networkCookie !== '' ? networkCookie : 'mainnet'; } diff --git a/frontend/src/services/System/SystemNativeClient/index.ts b/frontend/src/services/System/SystemNativeClient/index.ts index c27770dc..0907463a 100644 --- a/frontend/src/services/System/SystemNativeClient/index.ts +++ b/frontend/src/services/System/SystemNativeClient/index.ts @@ -46,6 +46,17 @@ class SystemNativeClient implements SystemClient { key, }); }; + + // Emulate storage as emulated cookies (....to improve) + public getItem: (key: string) => string = (key) => { + return this.getCookie(key); + }; + public setItem: (key: string, value: string) => void = (key, value) => { + this.setCookie(key, value); + }; + public deleteItem: (key: string) => void = (key) => { + this.deleteCookie(key); + }; } export default SystemNativeClient; diff --git a/frontend/src/services/System/SystemWebClient/index.ts b/frontend/src/services/System/SystemWebClient/index.ts index 3aab1a3c..ace23e01 100644 --- a/frontend/src/services/System/SystemWebClient/index.ts +++ b/frontend/src/services/System/SystemWebClient/index.ts @@ -27,6 +27,7 @@ class SystemWebClient implements SystemClient { } }; + //Cookies public getCookie: (key: string) => string = (key) => { let cookieValue = null; if (document.cookie && document.cookie !== '') { @@ -43,14 +44,24 @@ class SystemWebClient implements SystemClient { return cookieValue || ''; }; - public setCookie: (key: string, value: string) => void = (key, value) => { document.cookie = `${key}=${value};path=/;SameSite=Strict`; }; - public deleteCookie: (key: string) => void = (key) => { document.cookie = `${name}= ; expires = Thu, 01 Jan 1970 00:00:00 GMT`; }; + + // Local storage + public getItem: (key: string) => string = (key) => { + const value = window.localStorage.getItem(key); + return value || ''; + }; + public setItem: (key: string, value: string) => void = (key, value) => { + window.localStorage.setItem(key, value); + }; + public deleteItem: (key: string) => void = (key) => { + window.localStorage.removeItem(key); + }; } export default SystemWebClient; diff --git a/frontend/src/services/System/index.ts b/frontend/src/services/System/index.ts index f6ea91b9..7ebde6b2 100644 --- a/frontend/src/services/System/index.ts +++ b/frontend/src/services/System/index.ts @@ -7,6 +7,9 @@ export interface SystemClient { getCookie: (key: string) => string | undefined; setCookie: (key: string, value: string) => void; deleteCookie: (key: string) => void; + getItem: (key: string) => string | undefined; + setItem: (key: string, value: string) => void; + deleteItem: (key: string) => void; } export const systemClient: SystemClient = diff --git a/frontend/src/services/api/ApiNativeClient/index.ts b/frontend/src/services/api/ApiNativeClient/index.ts index 219cc8bb..dd677bc1 100644 --- a/frontend/src/services/api/ApiNativeClient/index.ts +++ b/frontend/src/services/api/ApiNativeClient/index.ts @@ -10,11 +10,11 @@ class ApiNativeClient implements ApiClient { 'Content-Type': 'application/json', }; - const robotToken = systemClient.getCookie('robot_token'); + const robotToken = systemClient.getItem('robot_token'); if (robotToken) { const sessionid = systemClient.getCookie('sessionid'); const csrftoken = systemClient.getCookie('csrftoken'); - const pubKey = systemClient.getCookie('pub_key'); + const pubKey = systemClient.getItem('pub_key'); headers = { ...headers,