Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(auth): split previous auth values for profile and #926

Merged
merged 1 commit into from
Mar 11, 2019
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/renderer/login/actions/previousProfileActions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { wallet } from '@cityofzion/neon-js';
import { createActions } from 'spunky';

import { getStorage, setStorage } from 'shared/lib/storage';

export const ID = 'previousProfile';

export const writePreviousAuthActions = createActions(ID, ({ encryptedWIF }) => async () => {
if (!wallet.isNEP2(encryptedWIF)) {
throw new Error('Invalid encrypted WIF');
}

const data = { encryptedWIF };
await setStorage(ID, data);
return data;
});

export default createActions(ID, () => async () => {
return (await getStorage(ID)) || {};
});
Original file line number Diff line number Diff line change
Expand Up @@ -50,28 +50,27 @@ export default class LoginFormWIF extends React.PureComponent {
onChange={this.handleChangePassphrase}
/>


<LoginButton disabled={disabled || !this.isValid()} />
</form>
);
}

handleChangeEncryptedWIF = (event) => {
this.props.setEncryptedWIF(event.target.value);
}
};

handleChangePassphrase = (event) => {
this.props.setPassphrase(event.target.value);
}
};

handleLogin = (event) => {
const { passphrase, encryptedWIF, onLogin } = this.props;

event.preventDefault();
onLogin({ passphrase, encryptedWIF });
}
};

isValid = () => {
return this.props.passphrase !== '' && this.props.encryptedWIF !== '';
}
};
}
9 changes: 4 additions & 5 deletions src/renderer/login/components/LoginFormProfile/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { withRouter } from 'react-router-dom';
import { compose, withState } from 'recompose';
import {
withData,
withActions
} from 'spunky';
import { withData, withActions } from 'spunky';
import { isEmpty } from 'lodash';

import withInitialCall from 'shared/hocs/withInitialCall';
Expand All @@ -12,7 +9,9 @@ import withNullLoader from 'browser/hocs/withNullLoader';
import { getProfiles } from 'register/actions/storeProfileActions';

import LoginFormProfile from './LoginFormProfile';
import previousAuthActions, { writePreviousAuthActions } from '../../actions/previousAuthActions';
import previousAuthActions, {
writePreviousAuthActions
} from '../../actions/previousProfileActions';
import withLogin from '../../hocs/withLogin';

const mapProfileActionsToProps = ({ profiles }) => ({
Expand Down