Skip to content

Commit

Permalink
Attempt to fix Android cookies
Browse files Browse the repository at this point in the history
  • Loading branch information
Reckless-Satoshi committed Nov 2, 2022
1 parent afbad30 commit f6228e4
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 11 deletions.
5 changes: 4 additions & 1 deletion frontend/src/components/SettingsForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,10 @@ const SettingsForm = ({
onChange={(e) => {
const fontSize = e.target.value;
setSettings({ ...settings, fontSize });
systemClient.setCookie(`settings_fontsize_${settings.frontend}`, fontSize);
systemClient.setCookie(
`settings_fontsize_${settings.frontend}`,
fontSize.toString(),
);
}}
valueLabelDisplay='off'
marks={fontSizes.map(({ label, value }) => ({
Expand Down
7 changes: 4 additions & 3 deletions frontend/src/models/Robot.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ export interface Robot {
copiedToken: boolean;
}

const tokenCookie = systemClient.getCookie('robot_token');
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,
token: tokenCookie != '' ? tokenCookie : null,
pubKey: pubKeyCookie != '' ? pubKeyCookie.split('\\').join('\n') : null,
encPrivKey: privKeyCookie != '' ? privKeyCookie.split('\\').join('\n') : null,
bitsEntropy: null,
shannonEntropy: null,
stealthInvoices: true,
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/models/Settings.default.basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { systemClient } from '../services/System';
import { baseSettings, Settings } from './Settings.model';

const fontSizeCookie = systemClient.getCookie('settings_fontsize_basic');
const fontSize = fontSizeCookie !== '' ? Number(fontSizeCookie) : 14;
const fontSize = fontSizeCookie != '' ? Number(fontSizeCookie) : 14;

export const defaultSettings: Settings = {
...baseSettings,
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/models/Settings.default.pro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { systemClient } from '../services/System';
import { baseSettings, Settings } from './Settings.model';

const fontSizeCookie = systemClient.getCookie('settings_fontsize_pro');
const fontSize = fontSizeCookie !== '' ? Number(fontSizeCookie) : 12;
const fontSize = fontSizeCookie != '' ? Number(fontSizeCookie) : 12;

export const defaultSettings: Settings = {
...baseSettings,
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/models/Settings.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ export interface Settings {

const modeCookie: 'light' | 'dark' | '' = systemClient.getCookie('settings_mode');
const mode: 'light' | 'dark' =
modeCookie !== ''
modeCookie != ''
? modeCookie
: window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches
? 'dark'
: 'light';

const languageCookie = systemClient.getCookie('settings_language');
const language: Language =
languageCookie !== ''
languageCookie != ''
? languageCookie
: i18n.resolvedLanguage == null
? 'en'
Expand Down
5 changes: 3 additions & 2 deletions frontend/src/services/System/SystemNativeClient/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ class SystemNativeClient implements SystemClient {
});
};

public getCookie: (key: string) => string | undefined = (key) => {
return window.NativeRobosats?.cookies[key];
public getCookie: (key: string) => string = (key) => {
const cookie = window.NativeRobosats?.cookies[key];
return cookie === null || cookie === undefined ? '' : cookie;
};

public setCookie: (key: string, value: string) => void = (key, value) => {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/services/System/SystemWebClient/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class SystemWebClient implements SystemClient {
}
};

public getCookie: (key: string) => string | undefined = (key) => {
public getCookie: (key: string) => string = (key) => {
let cookieValue = null;
if (document.cookie && document.cookie !== '') {
const cookies = document.cookie.split(';');
Expand Down

0 comments on commit f6228e4

Please sign in to comment.