From c86ce22dd9a2c696bc05c941b4205c7b3cb11559 Mon Sep 17 00:00:00 2001 From: Andrew Simachev Date: Fri, 23 Feb 2024 16:11:43 +0100 Subject: [PATCH 01/86] JS-3494: Remove authStore.phrase --- electron.js | 3 +- electron/js/api.js | 10 +-- electron/js/preload.js | 2 +- extension/lib/util.ts | 2 +- src/scss/page/auth.scss | 4 -- src/ts/app.tsx | 51 ++++---------- src/ts/component/form/phrase.tsx | 13 ++-- src/ts/component/page/auth/accountSelect.tsx | 68 ------------------- src/ts/component/page/auth/login.tsx | 8 +-- src/ts/component/page/auth/onboard.tsx | 14 ++-- src/ts/component/page/auth/setup.tsx | 26 ++++--- src/ts/component/page/index.tsx | 2 - .../component/popup/page/settings/logout.tsx | 21 ++++-- .../component/popup/page/settings/phrase.tsx | 22 +++--- src/ts/lib/renderer.ts | 2 +- src/ts/lib/util/data.ts | 5 +- src/ts/store/auth.ts | 8 --- 17 files changed, 83 insertions(+), 178 deletions(-) delete mode 100644 src/ts/component/page/auth/accountSelect.tsx diff --git a/electron.js b/electron.js index e99943047f..e481e6e626 100644 --- a/electron.js +++ b/electron.js @@ -141,9 +141,10 @@ function createWindow () { }; if (Api[cmd]) { - Api[cmd].apply(Api, [ win ].concat(args || [])); + return Api[cmd].apply(Api, [ win ].concat(args || [])); } else { console.error('[Api] method not defined:', cmd); + return null; }; }); }; diff --git a/electron/js/api.js b/electron/js/api.js index a093edd29e..b28479d377 100644 --- a/electron/js/api.js +++ b/electron/js/api.js @@ -17,7 +17,6 @@ const KEYTAR_SERVICE = 'Anytype'; class Api { account = null; - phrase = ''; isPinChecked = false; appOnLoad (win) { @@ -35,7 +34,6 @@ class Api { isChild: win.isChild, route: win.route, account: this.account, - phrase: this.phrase, isPinChecked: this.isPinChecked, languages: win.webContents.session.availableSpellCheckerLanguages, css: String(css || ''), @@ -104,16 +102,12 @@ class Api { keytarSet (win, key, value) { if (key && value) { - this.phrase = value; keytar.setPassword(KEYTAR_SERVICE, key, value); }; }; - keytarGet (win, key) { - keytar.getPassword(KEYTAR_SERVICE, key).then(value => { - this.phrase = value; - Util.send(win, 'keytarGet', key, value); - }); + async keytarGet (win, key) { + return await keytar.getPassword(KEYTAR_SERVICE, key); }; keytarDelete (win, key) { diff --git a/electron/js/preload.js b/electron/js/preload.js index 1680b44fa8..2c393b23fd 100644 --- a/electron/js/preload.js +++ b/electron/js/preload.js @@ -55,6 +55,6 @@ contextBridge.exposeInMainWorld('Electron', { cmd = String(cmd || ''); args = args || []; - ipcRenderer.invoke('Api', id, cmd, args); + return ipcRenderer.invoke('Api', id, cmd, args); }, }); \ No newline at end of file diff --git a/extension/lib/util.ts b/extension/lib/util.ts index 9d5e75ecf1..09a8b25ec5 100644 --- a/extension/lib/util.ts +++ b/extension/lib/util.ts @@ -50,7 +50,7 @@ class Util { authorize (appKey: string, onSuccess?: () => void, onError?: (error) => void) { authStore.appKeySet(appKey); - UtilData.createSession((message: any) => { + UtilData.createSession('', appKey, (message: any) => { if (message.error.code) { if (onError) { onError(message.error); diff --git a/src/scss/page/auth.scss b/src/scss/page/auth.scss index 56480d5c9b..e60f5c7548 100644 --- a/src/scss/page/auth.scss +++ b/src/scss/page/auth.scss @@ -180,10 +180,6 @@ html.bodyAuthDeleted { } } -.pageAuthAccountSelect { - .frame { padding-bottom: 48px; } -} - .pageAuthOnboard, .pageAuthInvite, .pageAuthLogin, .pageAuthDeleted, .pageAuthSetup { .frame { display: flex; flex-direction: column; align-items: center; } .title { @include text-header3; color: var(--color-text-primary) !important; } diff --git a/src/ts/app.tsx b/src/ts/app.tsx index 883f764466..3295883e22 100644 --- a/src/ts/app.tsx +++ b/src/ts/app.tsx @@ -177,7 +177,6 @@ class App extends React.Component { super(props); this.onInit = this.onInit.bind(this); - this.onKeytarGet = this.onKeytarGet.bind(this); this.onPopup = this.onPopup.bind(this); this.onUpdateCheck = this.onUpdateCheck.bind(this); this.onUpdateConfirm = this.onUpdateConfirm.bind(this); @@ -261,7 +260,6 @@ class App extends React.Component { registerIpcEvents () { Renderer.on('init', this.onInit); - Renderer.on('keytarGet', this.onKeytarGet); Renderer.on('route', (e: any, route: string) => UtilRouter.go(route, {})); Renderer.on('popup', this.onPopup); Renderer.on('checking-for-update', this.onUpdateCheck); @@ -304,7 +302,7 @@ class App extends React.Component { }; onInit (e: any, data: any) { - const { dataPath, config, isDark, isChild, account, phrase, languages, isPinChecked, css } = data; + const { dataPath, config, isDark, isChild, account, languages, isPinChecked, css } = data; const win = $(window); const body = $('body'); const node = $(this.node); @@ -353,18 +351,18 @@ class App extends React.Component { if (accountId) { if (isChild) { - authStore.phraseSet(phrase); + Renderer.send('keytarGet', accountId).then((phrase: string) => { + UtilData.createSession(phrase, '', () => { + keyboard.setPinChecked(isPinChecked); + commonStore.redirectSet(route); - UtilData.createSession(() => { - keyboard.setPinChecked(isPinChecked); - commonStore.redirectSet(route); - - if (account) { - authStore.accountSet(account); - commonStore.configSet(account.config, false); - UtilData.onInfo(account.info); - UtilData.onAuth({}, cb); - }; + if (account) { + authStore.accountSet(account); + commonStore.configSet(account.config, false); + UtilData.onInfo(account.info); + UtilData.onAuth({}, cb); + }; + }); }); win.off('unload').on('unload', (e: any) => { @@ -381,8 +379,7 @@ class App extends React.Component { }); } else { commonStore.redirectSet(route); - Renderer.send('keytarGet', accountId); - + UtilRouter.go('/auth/setup/init', { replace: true }); cb(); }; } else { @@ -390,28 +387,6 @@ class App extends React.Component { }; }; - onKeytarGet (e: any, key: string, value: string) { - const accountId = Storage.get('accountId'); - const phrase = Storage.get('phrase'); - - if (!accountId || (key != accountId)) { - return; - }; - - if (phrase) { - value = phrase; - Renderer.send('keytarSet', accountId, phrase); - Storage.delete('phrase'); - }; - - if (value) { - authStore.phraseSet(value); - UtilRouter.go('/auth/setup/init', { replace: true }); - } else { - Storage.logout(); - }; - }; - onPopup (e: any, id: string, param: any, close?: boolean) { if (Constant.popupPinIds.includes(id) && !keyboard.isPinChecked) { return; diff --git a/src/ts/component/form/phrase.tsx b/src/ts/component/form/phrase.tsx index 824a2843d2..0198a2d787 100644 --- a/src/ts/component/form/phrase.tsx +++ b/src/ts/component/form/phrase.tsx @@ -121,11 +121,9 @@ class Phrase extends React.Component { componentDidMount () { const { value, isHidden } = this.props; - const text = this.normalizeWhiteSpace(value); - const phrase = text.length ? text.split(' '): []; - this.init(); - this.setState({ isHidden, phrase }); + this.setState({ isHidden }); + this.setValue(value); this.focus(); }; @@ -264,6 +262,13 @@ class Phrase extends React.Component { return String(val || '').replace(/\s\s+/g, ' ').trim() || ''; }; + setValue (value: string) { + const text = this.normalizeWhiteSpace(value); + const phrase = text.length ? text.split(' '): []; + + this.setState({ phrase }); + }; + getValue () { return this.state.phrase.join(' ').trim().toLowerCase(); }; diff --git a/src/ts/component/page/auth/accountSelect.tsx b/src/ts/component/page/auth/accountSelect.tsx deleted file mode 100644 index ac6494b6fe..0000000000 --- a/src/ts/component/page/auth/accountSelect.tsx +++ /dev/null @@ -1,68 +0,0 @@ -import * as React from 'react'; -import { Frame, Error, Header, Footer } from 'Component'; -import { I, C, UtilCommon, UtilRouter, UtilData, Renderer } from 'Lib'; -import { authStore } from 'Store'; -import { observer } from 'mobx-react'; - -interface State { - error: string; -}; - -const PageAccountSelect = observer(class PageAccountSelect extends React.Component { - - state: State = { - error: '', - }; - - render () { - const { error } = this.state; - const { accounts } = authStore; - const length = accounts.length; - - return ( -
-
-
- - - - -
- ); - }; - - componentDidMount () { - const { walletPath, phrase } = authStore; - - authStore.accountListClear(); - - C.WalletRecover(walletPath, phrase, () => { - UtilData.createSession(() => { - C.AccountRecover((message) => { - if (message.error.code) { - UtilCommon.checkError(message.error.code); - this.setState({ error: message.error.description }); - }; - }); - }); - }); - }; - - componentDidUpdate () { - const { accounts, phrase } = authStore; - - if (!accounts || !accounts.length) { - return; - }; - - const account = accounts[0]; - - authStore.accountSet(account); - - Renderer.send('keytarSet', account.id, phrase); - UtilRouter.go('/auth/setup/select', { replace: true }); - }; - -}); - -export default PageAccountSelect; \ No newline at end of file diff --git a/src/ts/component/page/auth/login.tsx b/src/ts/component/page/auth/login.tsx index ffedf33757..3dbbbf92bb 100644 --- a/src/ts/component/page/auth/login.tsx +++ b/src/ts/component/page/auth/login.tsx @@ -76,7 +76,7 @@ const PageAuthLogin = observer(class PageAuthLogin extends React.Component { + UtilData.createSession(phrase, '', () => { C.AccountRecover(message => this.setError(message.error)); }); }); diff --git a/src/ts/component/page/auth/onboard.tsx b/src/ts/component/page/auth/onboard.tsx index ae9d72dbe1..f21b4408f1 100644 --- a/src/ts/component/page/auth/onboard.tsx +++ b/src/ts/component/page/auth/onboard.tsx @@ -21,6 +21,7 @@ const PageAuthOnboard = observer(class PageAuthOnboard extends React.Component this.refPhrase = ref} - value={authStore.phrase} + value={this.phrase} readonly={true} isHidden={!phraseVisible} onCopy={this.onCopy} @@ -167,6 +168,7 @@ const PageAuthOnboard = observer(class PageAuthOnboard extends React.Component { + UtilData.createSession(this.phrase, '', (message) => { if (message.error.code) { this.setError(message.error.description); return; }; - const { accountPath, phrase } = authStore; + const { accountPath } = authStore; C.AccountCreate(name, '', accountPath, UtilCommon.rand(1, Constant.iconCnt), mode, path, (message) => { if (message.error.code) { @@ -302,7 +304,7 @@ const PageAuthOnboard = observer(class PageAuthOnboard extends React.Component { - if (this.setError(message.error)) { - return; - }; - - UtilData.createSession((message: any) => { + Renderer.send('keytarGet', accountId).then((phrase: string) => { + C.WalletRecover(walletPath, phrase, (message: any) => { if (this.setError(message.error)) { return; }; - if (accountId) { - authStore.phraseSet(phrase); + UtilData.createSession(phrase, '' ,(message: any) => { + if (this.setError(message.error)) { + return; + }; + this.select(accountId, walletPath, false); - } else { - UtilRouter.go('/auth/account-select', { replace: true }); - }; + }); }); }); }; diff --git a/src/ts/component/page/index.tsx b/src/ts/component/page/index.tsx index de86742ec4..f3177fe2f9 100644 --- a/src/ts/component/page/index.tsx +++ b/src/ts/component/page/index.tsx @@ -11,7 +11,6 @@ import PageAuthSelect from './auth/select'; import PageAuthLogin from './auth/login'; import PageAuthPinCheck from './auth/pinCheck'; import PageAuthSetup from './auth/setup'; -import PageAuthAccountSelect from './auth/accountSelect'; import PageAuthOnboard from './auth/onboard'; import PageAuthDeleted from './auth/deleted'; @@ -40,7 +39,6 @@ const Components = { 'auth/login': PageAuthLogin, 'auth/pin-check': PageAuthPinCheck, 'auth/setup': PageAuthSetup, - 'auth/account-select': PageAuthAccountSelect, 'auth/onboard': PageAuthOnboard, 'auth/deleted': PageAuthDeleted, diff --git a/src/ts/component/popup/page/settings/logout.tsx b/src/ts/component/popup/page/settings/logout.tsx index ad15bb3946..30740b1830 100644 --- a/src/ts/component/popup/page/settings/logout.tsx +++ b/src/ts/component/popup/page/settings/logout.tsx @@ -23,6 +23,7 @@ const PopupSettingsPageLogout = observer(class PopupSettingsPageLogout extends R this.onCopy = this.onCopy.bind(this); this.onLogout = this.onLogout.bind(this); + this.onToggle = this.onToggle.bind(this); }; render () { @@ -36,7 +37,6 @@ const PopupSettingsPageLogout = observer(class PopupSettingsPageLogout extends R
this.refPhrase = ref} - value={authStore.phrase} readonly={true} isHidden={true} checkPin={true} @@ -53,20 +53,27 @@ const PopupSettingsPageLogout = observer(class PopupSettingsPageLogout extends R }; componentDidMount () { - const { phrase } = authStore; + const { account } = authStore; - if (phrase) { - C.WalletConvert(phrase, '', (message: any) => { - this.setState({ entropy: message.entropy }); - }); + if (!account) { + return; }; + Renderer.send('keytarGet', account.id).then((value: string) => { + C.WalletConvert(value, '', (message: any) => { + if (!message.error.code) { + this.refPhrase.setValue(value); + this.setState({ entropy: message.entropy }); + }; + }); + }); + analytics.event('ScreenKeychain', { type: 'BeforeLogout' }); }; onToggle (isHidden: boolean): void { if (!isHidden) { - UtilCommon.copyToast(translate('commonPhrase'), authStore.phrase); + UtilCommon.copyToast(translate('commonPhrase'), this.refPhrase.getValue()); analytics.event('KeychainCopy', { type: 'BeforeLogout' }); }; }; diff --git a/src/ts/component/popup/page/settings/phrase.tsx b/src/ts/component/popup/page/settings/phrase.tsx index 00b76c0b68..e06070e509 100644 --- a/src/ts/component/popup/page/settings/phrase.tsx +++ b/src/ts/component/popup/page/settings/phrase.tsx @@ -2,7 +2,7 @@ import * as React from 'react'; import { observer } from 'mobx-react'; import QRCode from 'qrcode.react'; import { Title, Label, Phrase } from 'Component'; -import { I, C, translate, analytics, UtilCommon, Storage } from 'Lib'; +import { I, C, translate, analytics, UtilCommon, Storage, Renderer } from 'Lib'; import { commonStore, authStore, popupStore } from 'Store'; import Theme from 'json/theme.json'; @@ -42,7 +42,6 @@ const PopupSettingsPagePhrase = observer(class PopupSettingsPagePhrase extends R
this.refPhrase = ref} - value={authStore.phrase} readonly={true} isHidden={true} checkPin={true} @@ -63,20 +62,27 @@ const PopupSettingsPagePhrase = observer(class PopupSettingsPagePhrase extends R }; componentDidMount () { - const { phrase } = authStore; + const { account } = authStore; - if (phrase) { - C.WalletConvert(phrase, '', (message: any) => { - this.setState({ entropy: message.entropy }); - }); + if (!account) { + return; }; + Renderer.send('keytarGet', account.id).then((value: string) => { + C.WalletConvert(value, '', (message: any) => { + if (!message.error.code) { + this.refPhrase.setValue(value); + this.setState({ entropy: message.entropy }); + }; + }); + }); + analytics.event('ScreenKeychain', { type: 'ScreenSettings' }); }; onToggle (isHidden: boolean): void { if (!isHidden) { - UtilCommon.copyToast(translate('commonPhrase'), authStore.phrase); + UtilCommon.copyToast(translate('commonPhrase'), this.refPhrase.getValue()); analytics.event('KeychainCopy', { type: 'ScreenSettings' }); }; }; diff --git a/src/ts/lib/renderer.ts b/src/ts/lib/renderer.ts index 14a8b28187..ebccd22ad3 100644 --- a/src/ts/lib/renderer.ts +++ b/src/ts/lib/renderer.ts @@ -16,7 +16,7 @@ class Renderer { return it; }); - UtilCommon.getElectron().Api(winId, cmd, UtilCommon.objectCopy(args)); + return UtilCommon.getElectron().Api(winId, cmd, UtilCommon.objectCopy(args)); }; on (event: string, callBack: any) { diff --git a/src/ts/lib/util/data.ts b/src/ts/lib/util/data.ts index 1de056e81e..266de31314 100644 --- a/src/ts/lib/util/data.ts +++ b/src/ts/lib/util/data.ts @@ -424,8 +424,9 @@ class UtilData { return Constant.defaultRelationKeys.concat(Constant.participantRelationKeys); }; - createSession (callBack?: (message: any) => void) { - C.WalletCreateSession(authStore.phrase, authStore.appKey, (message: any) => { + createSession (phrase: string, key: string, callBack?: (message: any) => void) { + C.WalletCreateSession(phrase, key, (message: any) => { + if (!message.error.code) { authStore.tokenSet(message.token); authStore.appTokenSet(message.appToken); diff --git a/src/ts/store/auth.ts b/src/ts/store/auth.ts index d6178fede0..b20a6ce9fe 100644 --- a/src/ts/store/auth.ts +++ b/src/ts/store/auth.ts @@ -15,7 +15,6 @@ class AuthStore { public accountItem: I.Account = null; public accountList: I.Account[] = []; public name = ''; - public phrase = ''; public token = ''; public appToken = ''; public appKey = ''; @@ -28,7 +27,6 @@ class AuthStore { accountItem: observable, accountList: observable, name: observable, - phrase: observable, threadMap: observable, walletPath: computed, accountPath: computed, @@ -36,7 +34,6 @@ class AuthStore { account: computed, walletPathSet: action, accountPathSet: action, - phraseSet: action, nameSet: action, accountAdd: action, accountSet: action, @@ -84,10 +81,6 @@ class AuthStore { this.accountPathValue = String(v || ''); }; - phraseSet (v: string) { - this.phrase = String(v || ''); - }; - nameSet (v: string) { this.name = String(v || ''); }; @@ -180,7 +173,6 @@ class AuthStore { this.accountListClear(); this.nameSet(''); - this.phraseSet(''); }; logout (mainWindow: boolean, removeData: boolean) { From 25e8d076468faf99cde96ec6d63e77d0b653773e Mon Sep 17 00:00:00 2001 From: Andrew Simachev Date: Fri, 1 Mar 2024 12:51:19 +0100 Subject: [PATCH 02/86] SpaceJoinCancel integration --- src/json/text.json | 1 + src/ts/component/popup/invite/request.tsx | 11 +++- .../popup/page/settings/space/list.tsx | 63 +++++++++++++------ src/ts/lib/api/command.ts | 4 +- src/ts/lib/util/data.ts | 3 - 5 files changed, 55 insertions(+), 27 deletions(-) diff --git a/src/json/text.json b/src/json/text.json index 56e55463cc..ef726dd0dd 100644 --- a/src/json/text.json +++ b/src/json/text.json @@ -664,6 +664,7 @@ "popupSettingsSpacesListTitle": "Spaces", "popupSettingsSpacesListSpace": "Space", + "popupSettingsSpacesCancelRequest": "Cancel request", "popupSettingsSpacesListAccess": "Access", "popupSettingsSpacesListSize": "Size", "popupSettingsSpacesListNetwork": "Network", diff --git a/src/ts/component/popup/invite/request.tsx b/src/ts/component/popup/invite/request.tsx index c5a9eb5c9b..4d6d725647 100644 --- a/src/ts/component/popup/invite/request.tsx +++ b/src/ts/component/popup/invite/request.tsx @@ -3,6 +3,7 @@ import { Title, Icon, Label, Button, Error } from 'Component'; import { I, C, translate, UtilCommon } from 'Lib'; import { observer } from 'mobx-react'; import { popupStore, authStore } from 'Store'; +import Constant from 'json/constant.json'; interface State { error: string; @@ -13,6 +14,8 @@ const PopupInviteRequest = observer(class PopupInviteRequest extends React.Compo state = { error: '', }; + + refButton = null; invite = { spaceName: '', creatorName: '', @@ -39,7 +42,7 @@ const PopupInviteRequest = observer(class PopupInviteRequest extends React.Compo