Skip to content

Commit

Permalink
Merge pull request #2648 from ethereum/issue/2647
Browse files Browse the repository at this point in the history
load and save method fixed in Wallet class
  • Loading branch information
nivida authored Apr 4, 2019
2 parents c5372b6 + 8a99c01 commit 340d621
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
6 changes: 2 additions & 4 deletions packages/web3-eth-accounts/src/models/Wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export default class Wallet {
encrypt(password, options) {
let encryptedAccounts = [];

for (let i = 0; i <= this.accountsIndex; i++) {
for (let i = 0; i < this.accountsIndex; i++) {
encryptedAccounts.push(this.accounts[i].encrypt(password, options));
}

Expand Down Expand Up @@ -249,9 +249,7 @@ export default class Wallet {
keystore = localStorage.getItem(keyName || this.defaultKeyName);

if (keystore) {
keystore = JSON.parse(keystore).map((item) => {
Account.fromV3Keystore(item, password, false, this.accountsModule);
});
keystore = JSON.parse(keystore);
}
} catch (error) {
// code 18 means trying to use local storage in a iframe
Expand Down
3 changes: 2 additions & 1 deletion packages/web3-eth-accounts/tests/src/models/WalletTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,13 @@ describe('WalletTest', () => {
accountMock.encrypt.mockReturnValueOnce(true);

wallet.accounts[0] = accountMock;
wallet.accountsIndex = 1;

expect(wallet.encrypt('pw', {})).toEqual([true]);

expect(accountMock.encrypt).toHaveBeenCalledWith('pw', {});

expect(wallet.accountsIndex).toEqual(0);
expect(wallet.accountsIndex).toEqual(1);
});

it('calls decrypt and returns the expected value', () => {
Expand Down

0 comments on commit 340d621

Please sign in to comment.