From deeb0620889c59f83197b69d1841971ab742969b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20Mi=C3=B1o?= Date: Fri, 26 Jun 2020 14:38:18 -0400 Subject: [PATCH] feature/sync imported accounts from extension (#1591) * feature/sync-imported-accounts * enable-apple-pay * analytics only on not dev * startwatcher * dev * env. * importedAccounts check Co-authored-by: Ibrahim Taveras --- app/components/UI/AccountList/index.js | 3 ++- app/components/Views/ImportWallet/index.js | 11 +++++++++-- app/components/Views/SyncWithExtension/index.js | 11 +++++++++-- app/core/Engine.js | 11 +++++++++-- ios/Podfile.lock | 2 +- 5 files changed, 30 insertions(+), 8 deletions(-) diff --git a/app/components/UI/AccountList/index.js b/app/components/UI/AccountList/index.js index 6ce81c61aac..daaf8c03d50 100644 --- a/app/components/UI/AccountList/index.js +++ b/app/components/UI/AccountList/index.js @@ -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); diff --git a/app/components/Views/ImportWallet/index.js b/app/components/Views/ImportWallet/index.js index 076ed54b22e..2e88c19b8c1 100644 --- a/app/components/Views/ImportWallet/index.js +++ b/app/components/Views/ImportWallet/index.js @@ -138,6 +138,7 @@ class ImportWallet extends PureComponent { }; seedwords = null; + importedAccounts = null; channelName = null; incomingDataStr = ''; dataToSync = null; @@ -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()); @@ -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); diff --git a/app/components/Views/SyncWithExtension/index.js b/app/components/Views/SyncWithExtension/index.js index 290bd4ee4c0..ba70eb51b69 100644 --- a/app/components/Views/SyncWithExtension/index.js +++ b/app/components/Views/SyncWithExtension/index.js @@ -93,6 +93,7 @@ class SyncWithExtension extends PureComponent { seedwords = null; channelName = null; + importedAccounts = null; incomingDataStr = ''; dataToSync = null; mounted = false; @@ -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()); @@ -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); diff --git a/app/core/Engine.js b/app/core/Engine.js index 6a875782d70..bd2fd51659a 100644 --- a/app/core/Engine.js +++ b/app/core/Engine.js @@ -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, @@ -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 => { @@ -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 { diff --git a/ios/Podfile.lock b/ios/Podfile.lock index 66872575dc0..d9bd5f8667e 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -656,4 +656,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: f49eb6bbca6fb51334d5950f1a3b8db487c775dc -COCOAPODS: 1.9.1 +COCOAPODS: 1.9.3