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

Fix remove passphrase when locking an account - Closes #1022, #1031 #1027

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
2 changes: 1 addition & 1 deletion src/components/header/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class Header extends React.Component {
date={this.props.account.expireTime}
renderer={CountDownTemplate}
onComplete={() => {
this.props.removeSavedAccountPassphrase();
this.props.removeSavedAccountPassphrase(this.props.account);
}}
>
<CustomCountDown
Expand Down
2 changes: 1 addition & 1 deletion src/components/header/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const mapDispatchToProps = dispatch => ({
setActiveDialog: data => dispatch(dialogDisplayed(data)),
logOut: () => dispatch(accountLoggedOut()),
removePassphrase: data => dispatch(removePassphrase(data)),
removeSavedAccountPassphrase: () => dispatch(removeSavedAccountPassphrase()),
removeSavedAccountPassphrase: data => dispatch(removeSavedAccountPassphrase(data)),
resetTimer: () => dispatch(accountUpdated({ expireTime: Date.now() + lockDuration })),
});
export default withRouter(connect(
Expand Down
2 changes: 1 addition & 1 deletion src/components/savedAccounts/accountCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const AccountCard = ({
null)}
{(account.network !== networks.mainnet.code ?
<strong className={styles.network}>
{account.address ? account.address : t(getNetwork(account.network).name)}
{account.peerAddress ? account.peerAddress : t(getNetwork(account.network).name)}
</strong> :
null)}
<div className={styles.cardIcon}>
Expand Down
5 changes: 3 additions & 2 deletions src/store/middlewares/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ const loginMiddleware = store => next => (action) => {
}
next(action);

const { passphrase, activePeer } = action.data;
const { passphrase, activePeer, options } = action.data;
const publicKey = passphrase ? extractPublicKey(passphrase) : action.data.publicKey;
const address = extractAddress(publicKey);
const accountBasics = {
passphrase,
publicKey,
address,
network: activePeer.currentNode,
network: options.code,
peerAddress: options.address,
};

store.dispatch(accountLoading());
Expand Down
6 changes: 3 additions & 3 deletions src/store/middlewares/savedAccounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const savedAccountsMiddleware = (store) => {

/* istanbul ignore if */
if (account.network === networks.customNode.code) {
network.address = account.address;
network.address = account.peerAddress;
}

store.dispatch(activePeerSet({
Expand Down Expand Up @@ -84,7 +84,7 @@ const savedAccountsMiddleware = (store) => {
passphrase: action.data.passphrase,
network: {
...getNetwork(action.data.network),
address: action.data.address,
address: action.data.peerAddress,
},
}));
break;
Expand All @@ -103,7 +103,7 @@ const savedAccountsMiddleware = (store) => {
balance: action.data.balance,
publicKey: action.data.publicKey,
network: peers.options.code,
address: peers.options.address,
peerAddress: action.data.peerAddress,
}));
break;
case actionTypes.accountRemoved:
Expand Down
5 changes: 3 additions & 2 deletions src/store/reducers/savedAccounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ const savedAccounts = (state = { accounts: [] }, action) => {
passphrase: action.data,
},
};

case actionTypes.accountSwitched:
return {
...state,
Expand All @@ -64,7 +63,9 @@ const savedAccounts = (state = { accounts: [] }, action) => {
return {
...state,
accounts: state.accounts.map((account) => {
if (!action.data || (`${action.data.network}${action.data.passphrase}` === `${account.network}${account.passphrase}`)) {
if (!action.data ||
(action.data.peerAddress === account.peerAddress &&
action.data.passphrase === account.passphrase)) {
delete account.passphrase;
}
return account;
Expand Down
8 changes: 4 additions & 4 deletions src/utils/savedAccounts.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { validateUrl } from './login';
import { extractAddress } from './account';

const isValidSavedAccount = ({ publicKey, network, address }) => {
const isValidSavedAccount = ({ publicKey, network, peerAddress }) => {
try {
return extractAddress(publicKey) &&
network >= 0 && network <= 2 &&
(validateUrl(address).addressValidity === '' || network !== 2);
(validateUrl(peerAddress).addressValidity === '' || network !== 2);
} catch (e) {
return false;
}
Expand All @@ -21,9 +21,9 @@ export const getSavedAccounts = () => {

export const setSavedAccounts = (accounts) => {
accounts = accounts.map(({
publicKey, network, address, balance,
publicKey, network, address, balance, peerAddress,
}) => ({
publicKey, network, address, balance,
publicKey, network, address, balance, peerAddress,
}));
localStorage.setItem('accounts', JSON.stringify(accounts));
};
Expand Down