Skip to content
This repository has been archived by the owner on Jun 7, 2023. It is now read-only.

Desktop: Fix account addition error check #578

Merged
merged 2 commits into from Nov 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/desktop/src/libs/crypto.js
Expand Up @@ -195,6 +195,11 @@ export const hash = async (inputPlain) => {
}

const saltHex = await Electron.readKeychain(`${ACC_MAIN}-salt`);

if (!saltHex) {
throw new Error('Keychain unavailable');
}

const saltArray = saltHex.split(',');
const salt = Uint8Array.from(saltArray);

Expand Down
24 changes: 17 additions & 7 deletions src/desktop/src/ui/Index.js
Expand Up @@ -12,6 +12,7 @@ import { ACC_MAIN } from 'libs/crypto';

import { getAccountNamesFromState } from 'selectors/accounts';

import { setOnboardingComplete } from 'actions/accounts';
import { setPassword, clearWalletData, setDeepLink, setSeedIndex, setAdditionalAccountInfo } from 'actions/wallet';
import { updateTheme } from 'actions/settings';
import { fetchNodeList } from 'actions/polling';
Expand Down Expand Up @@ -49,6 +50,10 @@ class App extends React.Component {
/** @ignore */
location: PropTypes.object,
/** @ignore */
onboardingComplete: PropTypes.bool.isRequired,
/** @ignore */
setOnboardingComplete: PropTypes.func.isRequired,
/** @ignore */
history: PropTypes.object.isRequired,
/** @ignore */
locale: PropTypes.string.isRequired,
Expand Down Expand Up @@ -116,12 +121,15 @@ class App extends React.Component {
Electron.updateMenu('authorised', true);

// If there was an error adding additional seed, go back to onboarding
if (
this.props.wallet.addingAdditionalAccount &&
!nextProps.wallet.addingAdditionalAccount &&
nextProps.wallet.additionalAccountName.length
) {
return this.props.history.push('/onboarding/account-name');
if (nextProps.wallet.addingAdditionalAccount) {
if (nextProps.accountNames.length > 0) {
return this.props.history.push('/onboarding/account-name');
}
return this.props.history.push('/onboarding/login');
}

if (!this.props.onboardingComplete){
this.props.setOnboardingComplete(true);
}

this.props.history.push('/wallet/');
Expand Down Expand Up @@ -281,6 +289,7 @@ const mapStateToProps = (state) => ({
locale: state.settings.locale,
wallet: state.wallet,
themeName: state.settings.themeName,
onboardingComplete: state.accounts.onboardingComplete,
isBusy:
!state.wallet.ready || state.ui.isSyncing || state.ui.isSendingTransfer || state.ui.isGeneratingReceiveAddress
});
Expand All @@ -294,7 +303,8 @@ const mapDispatchToProps = {
generateAlert,
fetchNodeList,
updateTheme,
setAdditionalAccountInfo
setAdditionalAccountInfo,
setOnboardingComplete
};

export default withRouter(connect(mapStateToProps, mapDispatchToProps)(withI18n()(withAutoNodeSwitching(App))));
8 changes: 1 addition & 7 deletions src/desktop/src/ui/views/onboarding/AccountPassword.js
Expand Up @@ -6,7 +6,6 @@ import { withI18n } from 'react-i18next';
import { zxcvbn } from 'libs/exports';

import { generateAlert } from 'actions/alerts';
import { setOnboardingComplete } from 'actions/accounts';
import { setPassword } from 'actions/wallet';

import SeedStore from 'libs/SeedStore';
Expand All @@ -24,8 +23,6 @@ class AccountPassword extends React.PureComponent {
/** @ignore */
setPassword: PropTypes.func.isRequired,
/** @ignore */
setOnboardingComplete: PropTypes.func.isRequired,
/** @ignore */
history: PropTypes.shape({
push: PropTypes.func.isRequired,
}).isRequired,
Expand All @@ -48,7 +45,7 @@ class AccountPassword extends React.PureComponent {
* @returns {undefined}
*/
createAccount = async (e) => {
const { wallet, setPassword, setOnboardingComplete, history, generateAlert, t } = this.props;
const { wallet, setPassword, history, generateAlert, t } = this.props;
const { password, passwordConfirm } = this.state;

if (e) {
Expand Down Expand Up @@ -97,8 +94,6 @@ class AccountPassword extends React.PureComponent {

Electron.setOnboardingSeed(null);

setOnboardingComplete(true);

history.push('/onboarding/done');
};

Expand Down Expand Up @@ -162,7 +157,6 @@ const mapStateToProps = (state) => ({

const mapDispatchToProps = {
setPassword,
setOnboardingComplete,
generateAlert,
};

Expand Down
2 changes: 1 addition & 1 deletion src/desktop/src/ui/views/onboarding/Done.js
Expand Up @@ -19,7 +19,7 @@ class Done extends React.PureComponent {
};

/**
* Set onboarding state as complete and navigate to Login view
* Navigate to Login view
* @returns {undefined}
*/
setComplete = () => {
Expand Down
3 changes: 2 additions & 1 deletion src/desktop/src/ui/views/onboarding/Index.js
Expand Up @@ -113,7 +113,7 @@ class Onboarding extends React.PureComponent {
return (
<main className={css.onboarding}>
<header>
{!isAuthorised ? (
{!isAuthorised && currentKey !== 'login' ? (
this.steps(currentKey)
) : (
<a onClick={() => history.push('/wallet/')}>
Expand All @@ -133,6 +133,7 @@ class Onboarding extends React.PureComponent {
<Route path="/onboarding/account-name" component={SeedName} />
<Route path="/onboarding/account-password" component={SecurityEnter} />
<Route path="/onboarding/done" component={Done} />
<Route path="/onboarding/login" component={Login} />
<Route path="/" component={indexComponent} />
</Switch>
</div>
Expand Down
8 changes: 7 additions & 1 deletion src/desktop/src/ui/views/onboarding/Login.js
Expand Up @@ -143,9 +143,15 @@ class Login extends React.Component {
const { password, code, verifyTwoFA } = this.state;
const { setPassword, generateAlert, t } = this.props;

const passwordHash = await hash(password);
let passwordHash = null;
let authorised = false;

try {
passwordHash = await hash(password);
} catch (err) {
generateAlert('error', t('errorAccessingKeychain'), t('errorAccessingKeychainExplanation'));
}

try {
authorised = await authorize(passwordHash);

Expand Down