Skip to content

Commit

Permalink
sync imported accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
estebanmino committed May 20, 2020
1 parent c413d09 commit ea1f89f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
4 changes: 3 additions & 1 deletion app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -744,10 +744,12 @@ export default class MetamaskController extends EventEmitter {

// Accounts
const hdKeyring = this.keyringController.getKeyringsByType('HD Key Tree')[0]
const simpleKeyPairKeyring = this.keyringController.getKeyringsByType('Simple Key Pair')[0]
const hdAccounts = await hdKeyring.getAccounts()
const simpleKeyPairAccounts = await simpleKeyPairKeyring.getAccounts()
const accounts = {
hd: hdAccounts.filter((item, pos) => (hdAccounts.indexOf(item) === pos)).map((address) => ethUtil.toChecksumAddress(address)),
simpleKeyPair: [],
simpleKeyPair: simpleKeyPairAccounts.filter((item, pos) => (simpleKeyPairAccounts.indexOf(item) === pos)).map((address) => ethUtil.toChecksumAddress(address)),
ledger: [],
trezor: [],
}
Expand Down
21 changes: 20 additions & 1 deletion ui/app/pages/mobile-sync/mobile-sync.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,16 @@ export default class MobileSyncPage extends Component {
displayWarning: PropTypes.func.isRequired,
fetchInfoToSync: PropTypes.func.isRequired,
requestRevealSeedWords: PropTypes.func.isRequired,
exportAccount: PropTypes.func.isRequired,
keyrings: PropTypes.array,
}


state = {
screen: PASSWORD_PROMPT_SCREEN,
password: '',
seedWords: null,
importedAccounts: [],
error: null,
syncing: false,
completed: false,
Expand Down Expand Up @@ -62,11 +65,26 @@ export default class MobileSyncPage extends Component {
.then((seedWords) => {
this.startKeysGeneration()
this.startIdleTimeout()
this.setState({ seedWords, screen: REVEAL_SEED_SCREEN })
this.exportAccounts()
.then((importedAccounts) => {
this.setState({ seedWords, importedAccounts, screen: REVEAL_SEED_SCREEN })
})
})
.catch((error) => this.setState({ error: error.message }))
}

async exportAccounts () {
const importedAccountPromises = []
this.props.keyrings.forEach((keyring) => {
if (keyring.type === 'Simple Key Pair') {
const privateKeyPromise = this.props.exportAccount(this.state.password, keyring.accounts[0])
importedAccountPromises.push(privateKeyPromise)
}
})
const importedAccounts = await Promise.all(importedAccountPromises)
return importedAccounts
}

startKeysGeneration () {
this.keysGenerationTimeout && clearTimeout(this.keysGenerationTimeout)
this.disconnectWebsockets()
Expand Down Expand Up @@ -201,6 +219,7 @@ export default class MobileSyncPage extends Component {
udata: {
pwd: this.state.password,
seed: this.state.seedWords,
importedAccounts: this.state.importedAccounts,
},
})

Expand Down
5 changes: 4 additions & 1 deletion ui/app/pages/mobile-sync/mobile-sync.container.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { connect } from 'react-redux'
import { displayWarning, requestRevealSeedWords, fetchInfoToSync } from '../../store/actions'
import { displayWarning, requestRevealSeedWords, fetchInfoToSync, exportAccount } from '../../store/actions'
import MobileSyncPage from './mobile-sync.component'
import { getMetaMaskKeyrings } from '../../selectors'

const mapDispatchToProps = (dispatch) => {
return {
requestRevealSeedWords: (password) => dispatch(requestRevealSeedWords(password)),
fetchInfoToSync: () => dispatch(fetchInfoToSync()),
displayWarning: (message) => dispatch(displayWarning(message || null)),
exportAccount: (password, address) => dispatch(exportAccount(password, address)),
}
}

Expand All @@ -19,6 +21,7 @@ const mapStateToProps = (state) => {

return {
selectedAddress,
keyrings: getMetaMaskKeyrings(state),
}
}

Expand Down

0 comments on commit ea1f89f

Please sign in to comment.