Skip to content
This repository has been archived by the owner on Apr 15, 2019. It is now read-only.

Allow to save and manage multiple accounts in local storage - Closes #573 #966

Merged
merged 22 commits into from
Nov 13, 2017

Conversation

slaweet
Copy link
Contributor

@slaweet slaweet commented Nov 7, 2017

What was the problem?

There was no tool for managing multiple saved accounts.

How did I fix it?

By creating a component that can:

  • List accounts
  • Save account
  • Forget account
  • Switch accounts
  • Remember last active account

How to test it?

Review checklist

@slaweet slaweet self-assigned this Nov 7, 2017
@slaweet slaweet force-pushed the 573-multi-account-management branch from 54abcd5 to ec17131 Compare November 8, 2017 14:08
@slaweet slaweet force-pushed the 573-multi-account-management branch from ec17131 to 097fcd8 Compare November 8, 2017 14:12
@slaweet slaweet force-pushed the 573-multi-account-management branch from 24127d0 to 04921d1 Compare November 9, 2017 13:56
@slaweet slaweet force-pushed the 573-multi-account-management branch from 1d6d6e2 to aab4ee4 Compare November 9, 2017 15:12
@slaweet slaweet force-pushed the 573-multi-account-management branch from a1d1073 to 3461c07 Compare November 9, 2017 15:58
@@ -0,0 +1,41 @@
export const getSavedAccounts = () => {
const savedAccounts = localStorage.getItem('accounts');
let accounts = [];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you initiate an array if your going to re-assign it?

const savedAccounts = localStorage.getItem('accounts');
let accounts = [];
if (savedAccounts) {
accounts = JSON.parse(savedAccounts);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check the structure of what you retrieve here, it might be modified to an undesired value. if this returns a non array value ,then your code with fail in line 16

};

export const getLastActiveAccount = () => (
getSavedAccounts()[localStorage.getItem('lastActiveAccountIndex') || 0]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if:

  • Saved account is an empty array?
  • lastActiveAccountIndex is modified to a non numeric string?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then getLastActiveAccount returns undefined

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, thank you 348f38e fixed it.

getSavedAccounts()[localStorage.getItem('lastActiveAccountIndex') || 0]
);

export const setLastActiveAccount = ({ publicKey, network, address }) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By convention, methods which set a value, return the new state.
same goes for setSavedAccount

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@@ -127,8 +127,9 @@ class Login extends React.Component {

autoLogin() {
const { savedAccounts } = this.props;
if (savedAccounts && savedAccounts.length > 0 && !this.props.account.afterLogout) {
this.account = savedAccounts[0];
console.log('dass', savedAccounts);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove

Repository owner deleted a comment from slaweet Nov 10, 2017
Repository owner deleted a comment from ginacontrino Nov 10, 2017
Repository owner deleted a comment from slaweet Nov 10, 2017
Repository owner deleted a comment from slaweet Nov 10, 2017
reyraa
reyraa previously approved these changes Nov 10, 2017
...because it doesn't work on Jenkins
@slaweet slaweet merged commit bb863f4 into 1.3.0 Nov 13, 2017
@slaweet slaweet deleted the 573-multi-account-management branch November 13, 2017 14:35
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants