diff --git a/frontend/src/components/App.js b/frontend/src/components/App.js
index 853cbbc9..bb524e7e 100644
--- a/frontend/src/components/App.js
+++ b/frontend/src/components/App.js
@@ -134,6 +134,13 @@ export default class App extends Component {
}
}
-const root = ReactDOM.createRoot(document.getElementById('app'));
+const loadApp = () => {
+ if (systemClient.loading) {
+ setTimeout(loadApp, 200);
+ } else {
+ const root = ReactDOM.createRoot(document.getElementById('app'));
+ root.render();
+ }
+};
-root.render();
+loadApp();
diff --git a/frontend/src/components/BottomBar.js b/frontend/src/components/BottomBar.js
index 6f12b3b7..c1dbb2b0 100644
--- a/frontend/src/components/BottomBar.js
+++ b/frontend/src/components/BottomBar.js
@@ -19,6 +19,7 @@ import MediaQuery from 'react-responsive';
import Flags from 'country-flag-icons/react/3x2';
import { Link as LinkRouter } from 'react-router-dom';
import { apiClient } from '../services/api';
+import { systemClient } from '../services/System';
import RobotAvatar from './Robots/RobotAvatar';
// Icons
@@ -41,7 +42,6 @@ import {
UpdateClientDialog,
} from './Dialogs';
-import { getCookie } from '../utils/cookies';
import checkVer from '../utils/checkVer';
class BottomBar extends Component {
@@ -172,9 +172,8 @@ class BottomBar extends Component {
showProfileButton = () => {
return (
this.props.avatarLoaded &&
- (window.NativeRobosats ||
- ((this.props.token ? getCookie('robot_token') === this.props.token : true) &&
- getCookie('sessionid')))
+ (this.props.token ? systemClient.getCookie('robot_token') === this.props.token : true) &&
+ systemClient.getCookie('sessionid')
);
};
@@ -467,7 +466,7 @@ class BottomBar extends Component {
handleClickOpenExchangeSummary = () => {
// avoid calling getInfo while sessionid not yet set. Temporary fix.
- if (getCookie('sessionid')) {
+ if (systemClient.getCookie('sessionid')) {
this.getInfo();
}
this.setState({ openExchangeSummary: true });
diff --git a/frontend/src/components/Dialogs/Profile.tsx b/frontend/src/components/Dialogs/Profile.tsx
index 95a57aa3..0495303f 100644
--- a/frontend/src/components/Dialogs/Profile.tsx
+++ b/frontend/src/components/Dialogs/Profile.tsx
@@ -36,7 +36,6 @@ import PersonAddAltIcon from '@mui/icons-material/PersonAddAlt';
import EmojiEventsIcon from '@mui/icons-material/EmojiEvents';
import { UserNinjaIcon, BitcoinIcon } from '../Icons';
-import { getCookie } from '../../utils/cookies';
import { systemClient } from '../../services/System';
import { getWebln } from '../../utils/webln';
import RobotAvatar from '../Robots/RobotAvatar';
@@ -98,7 +97,7 @@ const ProfileDialog = ({
}, [showRewards]);
const copyTokenHandler = () => {
- const robotToken = getCookie('robot_token');
+ const robotToken = systemClient.getCookie('robot_token');
if (robotToken) {
systemClient.copyToClipboard(robotToken);
@@ -226,12 +225,12 @@ const ProfileDialog = ({
- {getCookie('robot_token') ? (
+ {systemClient.getCookie('robot_token') ? (
- {getCookie('robot_token') ? (
+ {systemClient.getCookie('robot_token') ? (
this.setState({ openStoreToken: false })}
onClickCopy={() =>
- systemClient.copyToClipboard(getCookie('robot_token')) &
+ systemClient.copyToClipboard(systemClient.getCookie('robot_token')) &
this.props.setAppState({ copiedToken: true })
}
copyIconColor={this.props.copiedToken ? 'inherit' : 'primary'}
diff --git a/frontend/src/components/OrderPage.js b/frontend/src/components/OrderPage.js
index f7a73147..7b1eb407 100644
--- a/frontend/src/components/OrderPage.js
+++ b/frontend/src/components/OrderPage.js
@@ -50,7 +50,6 @@ import HourglassTopIcon from '@mui/icons-material/HourglassTop';
import CheckIcon from '@mui/icons-material/Check';
import { SendReceiveIcon } from './Icons';
-import { getCookie } from '../utils/cookies';
import { pn } from '../utils/prettyNumbers';
import { systemClient } from '../services/System';
import { getWebln } from '../utils/webln';
@@ -522,12 +521,12 @@ class OrderPage extends Component {
};
tokenDialog = () => {
- return getCookie('robot_token') ? (
+ return systemClient.getCookie('robot_token') ? (
this.setState({ openStoreToken: false })}
onClickCopy={() =>
- systemClient.copyToClipboard(getCookie('robot_token')) &
+ systemClient.copyToClipboard(systemClient.getCookie('robot_token')) &
this.props.setAppState({ copiedToken: true })
}
copyIconColor={this.props.copiedToken ? 'inherit' : 'primary'}
diff --git a/frontend/src/components/TradeBox.js b/frontend/src/components/TradeBox.js
index de378a43..ad3f3f0c 100644
--- a/frontend/src/components/TradeBox.js
+++ b/frontend/src/components/TradeBox.js
@@ -52,7 +52,6 @@ import RocketLaunchIcon from '@mui/icons-material/RocketLaunch';
import RefreshIcon from '@mui/icons-material/Refresh';
import { NewTabIcon } from './Icons';
-import { getCookie } from '../utils/cookies';
import { pn } from '../utils/prettyNumbers';
class TradeBox extends Component {
diff --git a/frontend/src/components/UserGenPage.js b/frontend/src/components/UserGenPage.js
index 9cc6fcdf..187f0876 100644
--- a/frontend/src/components/UserGenPage.js
+++ b/frontend/src/components/UserGenPage.js
@@ -24,7 +24,6 @@ import { RoboSatsNoTextIcon } from './Icons';
import { sha256 } from 'js-sha256';
import { genBase62Token, tokenStrength } from '../utils/token';
import { genKey } from '../utils/pgp';
-import { getCookie, writeCookie, deleteCookie } from '../utils/cookies';
import { saveAsJson } from '../utils/saveFile';
import { systemClient } from '../services/System';
import { apiClient } from '../services/api/index';
@@ -47,10 +46,13 @@ class UserGenPage extends Component {
// Displays the existing one
if (this.props.nickname != null) {
this.setState({
- nickname: this.props.nickname,
token: this.props.token ? this.props.token : '',
loadingRobot: false,
});
+ } else if (window.NativeRobosats && systemClient.getCookie('robot_token')) {
+ const token = systemClient.getCookie('robot_token');
+ this.props.setAppState({ token });
+ this.setState({ token, loadingRobot: false });
} else {
const newToken = genBase62Token(36);
this.setState({
@@ -78,7 +80,6 @@ class UserGenPage extends Component {
requestBody.then((body) =>
apiClient.post('/api/user/', body).then((data) => {
this.setState({
- nickname: data.nickname,
bit_entropy: data.token_bits_entropy,
shannon_entropy: data.token_shannon_entropy,
bad_request: data.bad_request,
@@ -110,9 +111,12 @@ class UserGenPage extends Component {
tgBotName: data.tg_bot_name,
tgToken: data.tg_token,
}) &
- writeCookie('robot_token', token) &
- writeCookie('pub_key', data.public_key.split('\n').join('\\')) &
- writeCookie('enc_priv_key', data.encrypted_private_key.split('\n').join('\\'))) &
+ 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('\\'),
+ )) &
// If the robot has been found (recovered) we assume the token is backed up
(data.found ? this.props.setAppState({ copiedToken: true }) : null);
}),
@@ -122,10 +126,10 @@ class UserGenPage extends Component {
delGeneratedUser() {
apiClient.delete('/api/user');
- deleteCookie('sessionid');
- deleteCookie('robot_token');
- deleteCookie('pub_key');
- deleteCookie('enc_priv_key');
+ systemClient.deleteCookie('sessionid');
+ systemClient.deleteCookie('robot_token');
+ systemClient.deleteCookie('pub_key');
+ systemClient.deleteCookie('enc_priv_key');
}
handleClickNewRandomToken = () => {
@@ -168,11 +172,11 @@ class UserGenPage extends Component {
createJsonFile = () => {
return {
- token: getCookie('robot_token'),
+ token: systemClient.getCookie('robot_token'),
token_shannon_entropy: this.state.shannon_entropy,
token_bit_entropy: this.state.bit_entropy,
- public_key: getCookie('pub_key').split('\\').join('\n'),
- encrypted_private_key: getCookie('enc_priv_key').split('\\').join('\n'),
+ public_key: systemClient.getCookie('pub_key').split('\\').join('\n'),
+ encrypted_private_key: systemClient.getCookie('enc_priv_key').split('\\').join('\n'),
};
};
@@ -191,12 +195,12 @@ class UserGenPage extends Component {
align='center'
sx={{ width: 370 * fontSizeFactor, height: 260 * fontSizeFactor }}
>
- {this.props.avatarLoaded && this.state.nickname ? (
+ {this.props.avatarLoaded && this.props.nickname ? (
- {this.state.nickname && getCookie('sessionid') ? (
+ {this.props.nickname && systemClient.getCookie('sessionid') ? (
- {this.state.nickname}
+ {this.props.nickname}
- saveAsJson(this.state.nickname + '.json', this.createJsonFile())
+ saveAsJson(this.props.nickname + '.json', this.createJsonFile())
}
>
- systemClient.copyToClipboard(getCookie('robot_token')) &
+ systemClient.copyToClipboard(systemClient.getCookie('robot_token')) &
this.props.setAppState({ copiedToken: true })
}
>
@@ -374,8 +376,9 @@ class UserGenPage extends Component {