Skip to content

Commit

Permalink
feature/sync imported accounts from extension (#1591)
Browse files Browse the repository at this point in the history
* feature/sync-imported-accounts

* enable-apple-pay

* analytics only on not dev

* startwatcher

* dev

* env.

* importedAccounts check

Co-authored-by: Ibrahim Taveras <ibrahimtaveras00@gmail.com>
  • Loading branch information
estebanmino and ibrahimtaveras00 authored Jun 26, 2020
1 parent efd186e commit deeb062
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 8 deletions.
3 changes: 2 additions & 1 deletion app/components/UI/AccountList/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,8 @@ class AccountList extends PureComponent {
}

const mapStateToProps = state => ({
accounts: state.engine.backgroundState.AccountTrackerController.accounts
accounts: state.engine.backgroundState.AccountTrackerController.accounts,
keyrings: state.engine.backgroundState.KeyringController.keyrings
});

export default connect(mapStateToProps)(AccountList);
11 changes: 9 additions & 2 deletions app/components/Views/ImportWallet/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ class ImportWallet extends PureComponent {
};

seedwords = null;
importedAccounts = null;
channelName = null;
incomingDataStr = '';
dataToSync = null;
Expand Down Expand Up @@ -236,9 +237,10 @@ class ImportWallet extends PureComponent {
},
data => {
this.incomingDataStr = null;
const { pwd, seed } = data.udata;
const { pwd, seed, importedAccounts } = data.udata;
this.password = pwd;
this.seedWords = seed;
this.importedAccounts = importedAccounts;
delete data.udata;
this.dataToSync = { ...data };
this.pubnubWrapper.endSync(() => this.disconnect());
Expand Down Expand Up @@ -334,7 +336,12 @@ class ImportWallet extends PureComponent {
try {
await AsyncStorage.removeItem('@MetaMask:nextMakerReminder');
await Engine.resetState();
await Engine.sync({ ...this.dataToSync, seed: this.seedWords, pass: opts.password });
await Engine.sync({
...this.dataToSync,
seed: this.seedWords,
importedAccounts: this.importedAccounts,
pass: opts.password
});
await AsyncStorage.setItem('@MetaMask:existingUser', 'true');
this.props.passwordHasBeenSet();
this.props.setLockTime(AppConstants.DEFAULT_LOCK_TIMEOUT);
Expand Down
11 changes: 9 additions & 2 deletions app/components/Views/SyncWithExtension/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ class SyncWithExtension extends PureComponent {

seedwords = null;
channelName = null;
importedAccounts = null;
incomingDataStr = '';
dataToSync = null;
mounted = false;
Expand Down Expand Up @@ -207,9 +208,10 @@ class SyncWithExtension extends PureComponent {
return false;
},
data => {
const { pwd, seed } = data.udata;
const { pwd, seed, importedAccounts } = data.udata;
this.password = pwd;
this.seedWords = seed;
this.importedAccounts = importedAccounts;
delete data.udata;
this.dataToSync = { ...data };
this.pubnubWrapper.endSync(() => this.disconnect());
Expand Down Expand Up @@ -272,7 +274,12 @@ class SyncWithExtension extends PureComponent {
try {
await AsyncStorage.removeItem('@MetaMask:nextMakerReminder');
await Engine.resetState();
await Engine.sync({ ...this.dataToSync, seed: this.seedWords, pass: password });
await Engine.sync({
...this.dataToSync,
seed: this.seedWords,
pass: password,
importedAccounts: this.importedAccounts
});
await AsyncStorage.setItem('@MetaMask:existingUser', 'true');
this.props.passwordHasBeenSet();
this.props.setLockTime(AppConstants.DEFAULT_LOCK_TIMEOUT);
Expand Down
11 changes: 9 additions & 2 deletions app/core/Engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ class Engine {
});
};

sync = async ({ accounts, preferences, network, transactions, seed, pass }) => {
sync = async ({ accounts, preferences, network, transactions, seed, pass, importedAccounts }) => {
const {
KeyringController,
PreferencesController,
Expand All @@ -306,6 +306,12 @@ class Engine {
await KeyringController.addNewAccount();
}

// Recreate imported accounts
if (importedAccounts) {
for (let i = 0; i < importedAccounts.length; i++) {
await KeyringController.importAccountWithStrategy('privateKey', [importedAccounts[i]]);
}
}
// Sync tokens
const allTokens = {};
Object.keys(preferences.accountTokens).forEach(address => {
Expand All @@ -331,11 +337,12 @@ class Engine {
const updatedPref = { ...preferences, identities: {} };
Object.keys(preferences.identities).forEach(address => {
const checksummedAddress = toChecksumAddress(address);
if (accounts.hd.includes(checksummedAddress)) {
if (accounts.hd.includes(checksummedAddress) || accounts.simpleKeyPair.includes(checksummedAddress)) {
updatedPref.identities[checksummedAddress] = preferences.identities[address];
}
});
await PreferencesController.update(updatedPref);

if (accounts.hd.includes(toChecksumAddress(updatedPref.selectedAddress))) {
PreferencesController.setSelectedAddress(updatedPref.selectedAddress);
} else {
Expand Down
2 changes: 1 addition & 1 deletion ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -656,4 +656,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: f49eb6bbca6fb51334d5950f1a3b8db487c775dc

COCOAPODS: 1.9.1
COCOAPODS: 1.9.3

0 comments on commit deeb062

Please sign in to comment.