Skip to content

Commit

Permalink
feature: sync tokens (#991)
Browse files Browse the repository at this point in the history
  • Loading branch information
estebanmino authored Aug 13, 2019
1 parent 1b31b76 commit a30000d
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions app/core/Engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,15 +257,33 @@ class Engine {
KeyringController,
PreferencesController,
NetworkController,
TransactionController
TransactionController,
AssetsController
} = this.datamodel.context;

// Select same network ?
await NetworkController.setProviderType(network.provider.type);

// Recreate accounts
await KeyringController.createNewVaultAndRestore(pass, seed);
for (let i = 0; i < accounts.hd.length - 1; i++) {
await KeyringController.addNewAccount();
}

// Sync tokens
const allTokens = {};
Object.keys(preferences.accountTokens).forEach(address => {
const checksummedAddress = toChecksumAddress(address);
allTokens[checksummedAddress] = {};
Object.keys(preferences.accountTokens[address]).forEach(
networkType =>
(allTokens[checksummedAddress][networkType] = preferences.accountTokens[address][networkType].map(
token => ({ ...token, address: toChecksumAddress(token.address) })
))
);
});
await AssetsController.update({ allTokens });

// Restore preferences
const updatedPref = { ...preferences, identities: {} };
Object.keys(preferences.identities).forEach(address => {
Expand Down Expand Up @@ -301,8 +319,6 @@ class Engine {
}))
});

// Select same network ?
await NetworkController.setProviderType(network.provider.type);
return true;
};
}
Expand Down

0 comments on commit a30000d

Please sign in to comment.