mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
metamask controller - cleanup remote api
This commit is contained in:
parent
fc1b11e373
commit
9ab8362843
@ -152,7 +152,7 @@ module.exports = class MetamaskController extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Constructor helpers
|
// State Management
|
||||||
//
|
//
|
||||||
|
|
||||||
getState () {
|
getState () {
|
||||||
@ -181,87 +181,49 @@ module.exports = class MetamaskController extends EventEmitter {
|
|||||||
const noticeController = this.noticeController
|
const noticeController = this.noticeController
|
||||||
|
|
||||||
return {
|
return {
|
||||||
getState: nodeify(this.getState.bind(this)),
|
// etc
|
||||||
setRpcTarget: this.setRpcTarget.bind(this),
|
getState: nodeify(this.getState.bind(this)),
|
||||||
setProviderType: this.setProviderType.bind(this),
|
setRpcTarget: this.setRpcTarget.bind(this),
|
||||||
useEtherscanProvider: this.useEtherscanProvider.bind(this),
|
setProviderType: this.setProviderType.bind(this),
|
||||||
agreeToDisclaimer: this.agreeToDisclaimer.bind(this),
|
useEtherscanProvider: this.useEtherscanProvider.bind(this),
|
||||||
resetDisclaimer: this.resetDisclaimer.bind(this),
|
agreeToDisclaimer: this.agreeToDisclaimer.bind(this),
|
||||||
setCurrentFiat: this.setCurrentFiat.bind(this),
|
resetDisclaimer: this.resetDisclaimer.bind(this),
|
||||||
setTOSHash: this.setTOSHash.bind(this),
|
setCurrentFiat: this.setCurrentFiat.bind(this),
|
||||||
checkTOSChange: this.checkTOSChange.bind(this),
|
setTOSHash: this.setTOSHash.bind(this),
|
||||||
setGasMultiplier: this.setGasMultiplier.bind(this),
|
checkTOSChange: this.checkTOSChange.bind(this),
|
||||||
markAccountsFound: this.markAccountsFound.bind(this),
|
setGasMultiplier: this.setGasMultiplier.bind(this),
|
||||||
|
markAccountsFound: this.markAccountsFound.bind(this),
|
||||||
// forward directly to keyringController
|
|
||||||
createNewVaultAndKeychain: nodeify(keyringController.createNewVaultAndKeychain).bind(keyringController),
|
|
||||||
createNewVaultAndRestore: nodeify(keyringController.createNewVaultAndRestore).bind(keyringController),
|
|
||||||
// Adds the current vault's seed words to the UI's state tree.
|
|
||||||
//
|
|
||||||
// Used when creating a first vault, to allow confirmation.
|
|
||||||
// Also used when revealing the seed words in the confirmation view.
|
|
||||||
placeSeedWords: (cb) => {
|
|
||||||
const primaryKeyring = keyringController.getKeyringsByType('HD Key Tree')[0]
|
|
||||||
if (!primaryKeyring) return cb(new Error('MetamaskController - No HD Key Tree found'))
|
|
||||||
primaryKeyring.serialize()
|
|
||||||
.then((serialized) => {
|
|
||||||
const seedWords = serialized.mnemonic
|
|
||||||
this.configManager.setSeedWords(seedWords)
|
|
||||||
promiseToCallback(this.keyringController.fullUpdate())(cb)
|
|
||||||
})
|
|
||||||
},
|
|
||||||
// ClearSeedWordCache
|
|
||||||
//
|
|
||||||
// Removes the primary account's seed words from the UI's state tree,
|
|
||||||
// ensuring they are only ever available in the background process.
|
|
||||||
clearSeedWordCache: (cb) => {
|
|
||||||
this.configManager.setSeedWords(null)
|
|
||||||
cb(null, this.configManager.getSelectedAccount())
|
|
||||||
},
|
|
||||||
setLocked: nodeify(keyringController.setLocked).bind(keyringController),
|
|
||||||
submitPassword: (password, cb) => {
|
|
||||||
this.migrateOldVaultIfAny(password)
|
|
||||||
.then(keyringController.submitPassword.bind(keyringController, password))
|
|
||||||
.then((newState) => { cb(null, newState) })
|
|
||||||
.catch((reason) => { cb(reason) })
|
|
||||||
},
|
|
||||||
addNewKeyring: (type, opts, cb) => {
|
|
||||||
keyringController.addNewKeyring(type, opts)
|
|
||||||
.then(() => keyringController.fullUpdate())
|
|
||||||
.then((newState) => { cb(null, newState) })
|
|
||||||
.catch((reason) => { cb(reason) })
|
|
||||||
},
|
|
||||||
addNewAccount: (cb) => {
|
|
||||||
const primaryKeyring = keyringController.getKeyringsByType('HD Key Tree')[0]
|
|
||||||
if (!primaryKeyring) return cb(new Error('MetamaskController - No HD Key Tree found'))
|
|
||||||
promiseToCallback(keyringController.addNewAccount(primaryKeyring))(cb)
|
|
||||||
},
|
|
||||||
importAccountWithStrategy: (strategy, args, cb) => {
|
|
||||||
accountImporter.importAccount(strategy, args)
|
|
||||||
.then((privateKey) => {
|
|
||||||
return keyringController.addNewKeyring('Simple Key Pair', [ privateKey ])
|
|
||||||
})
|
|
||||||
.then(keyring => keyring.getAccounts())
|
|
||||||
.then((accounts) => keyringController.setSelectedAccount(accounts[0]))
|
|
||||||
.then(() => { cb(null, keyringController.fullUpdate()) })
|
|
||||||
.catch((reason) => { cb(reason) })
|
|
||||||
},
|
|
||||||
setSelectedAccount: nodeify(keyringController.setSelectedAccount).bind(keyringController),
|
|
||||||
saveAccountLabel: nodeify(keyringController.saveAccountLabel).bind(keyringController),
|
|
||||||
exportAccount: nodeify(keyringController.exportAccount).bind(keyringController),
|
|
||||||
|
|
||||||
// signing methods
|
|
||||||
approveTransaction: txManager.approveTransaction.bind(txManager),
|
|
||||||
cancelTransaction: txManager.cancelTransaction.bind(txManager),
|
|
||||||
signMessage: keyringController.signMessage.bind(keyringController),
|
|
||||||
cancelMessage: keyringController.cancelMessage.bind(keyringController),
|
|
||||||
|
|
||||||
// coinbase
|
// coinbase
|
||||||
buyEth: this.buyEth.bind(this),
|
buyEth: this.buyEth.bind(this),
|
||||||
// shapeshift
|
// shapeshift
|
||||||
createShapeShiftTx: this.createShapeShiftTx.bind(this),
|
createShapeShiftTx: this.createShapeShiftTx.bind(this),
|
||||||
|
|
||||||
|
// primary HD keyring management
|
||||||
|
addNewAccount: this.addNewAccount.bind(this),
|
||||||
|
placeSeedWords: this.placeSeedWords.bind(this),
|
||||||
|
clearSeedWordCache: this.clearSeedWordCache.bind(this),
|
||||||
|
importAccountWithStrategy: this.importAccountWithStrategy.bind(this),
|
||||||
|
|
||||||
|
// vault management
|
||||||
|
submitPassword: this.submitPassword.bind(this),
|
||||||
|
|
||||||
|
// KeyringController
|
||||||
|
setLocked: nodeify(keyringController.setLocked).bind(keyringController),
|
||||||
|
createNewVaultAndKeychain: nodeify(keyringController.createNewVaultAndKeychain).bind(keyringController),
|
||||||
|
createNewVaultAndRestore: nodeify(keyringController.createNewVaultAndRestore).bind(keyringController),
|
||||||
|
addNewKeyring: nodeify(keyringController.addNewKeyring).bind(keyringController),
|
||||||
|
setSelectedAccount: nodeify(keyringController.setSelectedAccount).bind(keyringController),
|
||||||
|
saveAccountLabel: nodeify(keyringController.saveAccountLabel).bind(keyringController),
|
||||||
|
exportAccount: nodeify(keyringController.exportAccount).bind(keyringController),
|
||||||
|
|
||||||
|
// signing methods
|
||||||
|
approveTransaction: txManager.approveTransaction.bind(txManager),
|
||||||
|
cancelTransaction: txManager.cancelTransaction.bind(txManager),
|
||||||
|
signMessage: keyringController.signMessage.bind(keyringController),
|
||||||
|
cancelMessage: keyringController.cancelMessage.bind(keyringController),
|
||||||
|
|
||||||
// notices
|
// notices
|
||||||
checkNotices: noticeController.updateNoticesList.bind(noticeController),
|
checkNotices: noticeController.updateNoticesList.bind(noticeController),
|
||||||
markNoticeRead: noticeController.markNoticeRead.bind(noticeController),
|
markNoticeRead: noticeController.markNoticeRead.bind(noticeController),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -314,6 +276,67 @@ module.exports = class MetamaskController extends EventEmitter {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Vault Management
|
||||||
|
//
|
||||||
|
|
||||||
|
submitPassword (password, cb) {
|
||||||
|
this.migrateOldVaultIfAny(password)
|
||||||
|
.then(this.keyringController.submitPassword.bind(this.keyringController, password))
|
||||||
|
.then((newState) => { cb(null, newState) })
|
||||||
|
.catch((reason) => { cb(reason) })
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Opinionated Keyring Management
|
||||||
|
//
|
||||||
|
|
||||||
|
addNewAccount (cb) {
|
||||||
|
const primaryKeyring = this.keyringController.getKeyringsByType('HD Key Tree')[0]
|
||||||
|
if (!primaryKeyring) return cb(new Error('MetamaskController - No HD Key Tree found'))
|
||||||
|
promiseToCallback(this.keyringController.addNewAccount(primaryKeyring))(cb)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Adds the current vault's seed words to the UI's state tree.
|
||||||
|
//
|
||||||
|
// Used when creating a first vault, to allow confirmation.
|
||||||
|
// Also used when revealing the seed words in the confirmation view.
|
||||||
|
placeSeedWords (cb) {
|
||||||
|
const primaryKeyring = this.keyringController.getKeyringsByType('HD Key Tree')[0]
|
||||||
|
if (!primaryKeyring) return cb(new Error('MetamaskController - No HD Key Tree found'))
|
||||||
|
primaryKeyring.serialize()
|
||||||
|
.then((serialized) => {
|
||||||
|
const seedWords = serialized.mnemonic
|
||||||
|
this.configManager.setSeedWords(seedWords)
|
||||||
|
promiseToCallback(this.keyringController.fullUpdate())(cb)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearSeedWordCache
|
||||||
|
//
|
||||||
|
// Removes the primary account's seed words from the UI's state tree,
|
||||||
|
// ensuring they are only ever available in the background process.
|
||||||
|
clearSeedWordCache (cb) {
|
||||||
|
this.configManager.setSeedWords(null)
|
||||||
|
cb(null, this.configManager.getSelectedAccount())
|
||||||
|
}
|
||||||
|
|
||||||
|
importAccountWithStrategy (strategy, args, cb) {
|
||||||
|
accountImporter.importAccount(strategy, args)
|
||||||
|
.then((privateKey) => {
|
||||||
|
return this.keyringController.addNewKeyring('Simple Key Pair', [ privateKey ])
|
||||||
|
})
|
||||||
|
.then(keyring => keyring.getAccounts())
|
||||||
|
.then((accounts) => this.keyringController.setSelectedAccount(accounts[0]))
|
||||||
|
.then(() => { cb(null, this.keyringController.fullUpdate()) })
|
||||||
|
.catch((reason) => { cb(reason) })
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// Identity Management
|
||||||
|
//
|
||||||
|
|
||||||
newUnapprovedTransaction (txParams, cb) {
|
newUnapprovedTransaction (txParams, cb) {
|
||||||
const self = this
|
const self = this
|
||||||
self.txManager.addUnapprovedTransaction(txParams, (err, txMeta) => {
|
self.txManager.addUnapprovedTransaction(txParams, (err, txMeta) => {
|
||||||
|
@ -270,10 +270,9 @@ function requestRevealSeed (password) {
|
|||||||
function addNewKeyring (type, opts) {
|
function addNewKeyring (type, opts) {
|
||||||
return (dispatch) => {
|
return (dispatch) => {
|
||||||
dispatch(actions.showLoadingIndication())
|
dispatch(actions.showLoadingIndication())
|
||||||
background.addNewKeyring(type, opts, (err, newState) => {
|
background.addNewKeyring(type, opts, (err) => {
|
||||||
dispatch(actions.hideLoadingIndication())
|
dispatch(actions.hideLoadingIndication())
|
||||||
if (err) return dispatch(actions.displayWarning(err.message))
|
if (err) return dispatch(actions.displayWarning(err.message))
|
||||||
dispatch(actions.updateMetamaskState(newState))
|
|
||||||
dispatch(actions.showAccountsPage())
|
dispatch(actions.showAccountsPage())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user