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

feature: sync tokens #991

Merged
merged 2 commits into from
Aug 13, 2019
Merged
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
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