From c9749bde246572edb7d328b2deb443a8f15396be Mon Sep 17 00:00:00 2001 From: Reckless_Satoshi Date: Mon, 31 Oct 2022 09:20:20 -0700 Subject: [PATCH] Fix navbar refactor bugs on native app --- frontend/src/basic/Main.tsx | 14 ++++++-------- frontend/src/basic/UserGenPage.js | 16 ++++++++-------- .../components/TradeBox/EncryptedChat/index.tsx | 2 +- frontend/src/models/Robot.model.ts | 7 +++++-- 4 files changed, 20 insertions(+), 19 deletions(-) diff --git a/frontend/src/basic/Main.tsx b/frontend/src/basic/Main.tsx index 2345095f..5dee83f3 100644 --- a/frontend/src/basic/Main.tsx +++ b/frontend/src/basic/Main.tsx @@ -65,13 +65,11 @@ const Main = ({ settings, setSettings }: MainProps): JSX.Element => { const theme = useTheme(); const history = useHistory(); - const Router = window.NativeRobosats != null ? HashRouter : BrowserRouter; - const basename = window.NativeRobosats != null ? window.location.pathname : ''; - const [page, setPage] = useState( - window.location.pathname.split('/')[1] == '' - ? 'offers' - : window.location.pathname.split('/')[1], - ); + const Router = window.NativeRobosats === undefined ? BrowserRouter : HashRouter; + const basename = window.NativeRobosats === undefined ? '' : window.location.pathname; + const entryPage: Page | '' = + window.NativeRobosats === undefined ? window.location.pathname.split('/')[1] : ''; + const [page, setPage] = useState(entryPage == '' ? 'offers' : entryPage); const [slideDirection, setSlideDirection] = useState({ in: undefined, out: undefined, @@ -166,7 +164,7 @@ const Main = ({ settings, setSettings }: MainProps): JSX.Element => { ? data.active_order_id : data.last_order_id ? data.last_order_id - : order, + : null, ); setRobot({ ...robot, diff --git a/frontend/src/basic/UserGenPage.js b/frontend/src/basic/UserGenPage.js index 65ded8e6..96418969 100644 --- a/frontend/src/basic/UserGenPage.js +++ b/frontend/src/basic/UserGenPage.js @@ -42,10 +42,7 @@ class UserGenPage extends Component { // Displays the existing one if (this.props.robot.nickname != null) { this.setState({ inputToken: this.props.robot.token }); - } else if ( - this.props.robot.token || - (window.NativeRobosats && systemClient.getCookie('robot_token')) - ) { + } else if (this.props.robot.token) { this.setState({ inputToken: this.props.robot.token }); this.getGeneratedUser(this.props.robot.token); } else { @@ -117,10 +114,13 @@ class UserGenPage extends Component { pub_key: data.public_key, enc_priv_key: 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.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('\\'), + ); }), ); }; diff --git a/frontend/src/components/TradeBox/EncryptedChat/index.tsx b/frontend/src/components/TradeBox/EncryptedChat/index.tsx index c1325dcc..53041e7f 100644 --- a/frontend/src/components/TradeBox/EncryptedChat/index.tsx +++ b/frontend/src/components/TradeBox/EncryptedChat/index.tsx @@ -520,4 +520,4 @@ const EncryptedChat: React.FC = ({ orderId, userNick }: Props): JSX.Eleme ); }; -export default EncryptedChat; \ No newline at end of file +export default EncryptedChat; diff --git a/frontend/src/models/Robot.model.ts b/frontend/src/models/Robot.model.ts index 0de15f07..16c2889b 100644 --- a/frontend/src/models/Robot.model.ts +++ b/frontend/src/models/Robot.model.ts @@ -20,11 +20,14 @@ export interface Robot { copiedToken: boolean; } +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, - pub_key: systemClient.getCookie('pub_key').split('\\').join('\n'), - enc_priv_key: systemClient.getCookie('enc_priv_key').split('\\').join('\n'), + pub_key: pubKeyCookie ? pubKeyCookie.split('\\').join('\n') : null, + enc_priv_key: privKeyCookie ? privKeyCookie.split('\\').join('\n') : null, bitsEntropy: null, shannonEntropy: null, stealthInvoices: true,