1
0
Fork 0
mirror of https://github.com/anyproto/anytype-ts.git synced 2025-06-08 05:57:02 +09:00

JS-3494: Remove authStore.phrase

This commit is contained in:
Andrew Simachev 2024-02-23 16:11:43 +01:00
parent 69c4a65f5b
commit c86ce22dd9
No known key found for this signature in database
GPG key ID: 49A163D0D14E6FD8
17 changed files with 83 additions and 178 deletions

View file

@ -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;
};
});
};

View file

@ -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) {

View file

@ -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);
},
});

View file

@ -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);

View file

@ -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; }

View file

@ -177,7 +177,6 @@ class App extends React.Component<object, State> {
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<object, State> {
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<object, State> {
};
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<object, State> {
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<object, State> {
});
} 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<object, State> {
};
};
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;

View file

@ -121,11 +121,9 @@ class Phrase extends React.Component<Props, State> {
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<Props, State> {
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();
};

View file

@ -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<I.PageComponent, State> {
state: State = {
error: '',
};
render () {
const { error } = this.state;
const { accounts } = authStore;
const length = accounts.length;
return (
<div>
<Header {...this.props} component="authIndex" />
<Footer {...this.props} component="authIndex" />
<Frame>
<Error text={error} />
</Frame>
</div>
);
};
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;

View file

@ -76,7 +76,7 @@ const PageAuthLogin = observer(class PageAuthLogin extends React.Component<I.Pag
};
componentDidUpdate () {
const { accounts, phrase } = authStore;
const { accounts } = authStore;
this.focus();
@ -84,7 +84,7 @@ const PageAuthLogin = observer(class PageAuthLogin extends React.Component<I.Pag
const account = accounts[0];
authStore.accountSet(account);
Renderer.send('keytarSet', account.id, phrase);
Renderer.send('keytarSet', account.id, this.refPhrase.getValue());
this.select();
};
@ -118,10 +118,8 @@ const PageAuthLogin = observer(class PageAuthLogin extends React.Component<I.Pag
return;
};
authStore.phraseSet(phrase);
authStore.accountListClear();
UtilData.createSession(() => {
UtilData.createSession(phrase, '', () => {
C.AccountRecover(message => this.setError(message.error));
});
});

View file

@ -21,6 +21,7 @@ const PageAuthOnboard = observer(class PageAuthOnboard extends React.Component<I
refNext: Button = null;
isDelayed = false;
isCreating = false;
phrase = '';
state: State = {
stage: Stage.Void,
@ -82,7 +83,7 @@ const PageAuthOnboard = observer(class PageAuthOnboard extends React.Component<I
<div className="animation" onClick={this.onCopy}>
<Phrase
ref={ref => 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<I
componentWillUnmount (): void {
this.unbind();
this.phrase = '';
};
unbind () {
@ -281,15 +283,15 @@ const PageAuthOnboard = observer(class PageAuthOnboard extends React.Component<I
return;
};
authStore.phraseSet(message.mnemonic);
this.phrase = message.mnemonic;
UtilData.createSession((message) => {
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<I
commonStore.isSidebarFixedSet(true);
UtilData.onInfo(message.account.info);
Renderer.send('keytarSet', message.account.id, phrase);
Renderer.send('keytarSet', message.account.id, this.phrase);
analytics.event('CreateAccount', { middleTime: message.middleTime });
analytics.event('CreateSpace', { middleTime: message.middleTime, usecase: I.Usecase.GetStarted });
@ -325,7 +327,7 @@ const PageAuthOnboard = observer(class PageAuthOnboard extends React.Component<I
/** Copies key phrase to clipboard and shows a toast */
onCopy () {
UtilCommon.copyToast(translate('commonPhrase'), authStore.phrase);
UtilCommon.copyToast(translate('commonPhrase'), this.phrase);
analytics.event('KeychainCopy', { type: 'Onboarding' });
};

View file

@ -1,6 +1,6 @@
import * as React from 'react';
import { Frame, Title, Label, Error, Button, Header, Footer, Icon, Loader } from 'Component';
import { I, Storage, translate, C, UtilData, UtilCommon, Action, Animation, analytics, UtilRouter } from 'Lib';
import { I, Storage, translate, C, UtilData, UtilCommon, Action, Animation, analytics, UtilRouter, Renderer } from 'Lib';
import { authStore, commonStore } from 'Store';
import { observer } from 'mobx-react';
import Errors from 'json/error.json';
@ -117,29 +117,27 @@ const PageAuthSetup = observer(class PageAuthSetup extends React.Component<I.Pag
};
init () {
const { walletPath, phrase } = authStore;
const { walletPath } = authStore;
const accountId = Storage.get('accountId');
if (!phrase) {
if (!accountId || !walletPath) {
this.setError({ description: 'Invalid account or wallet path', code: 0 });
return;
};
C.WalletRecover(walletPath, phrase, (message: any) => {
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 });
};
});
});
});
};

View file

@ -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,

View file

@ -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
<div className="inputs" onClick={this.onCopy}>
<Phrase
ref={ref => 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' });
};
};

View file

@ -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
<div className="inputs" onClick={this.onCopy}>
<Phrase
ref={ref => 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' });
};
};

View file

@ -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) {

View file

@ -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);

View file

@ -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) {