Fix eth_accounts request
This commit is contained in:
parent
daa06f0be2
commit
78d4a79146
|
@ -60,6 +60,7 @@ const isEdge = !isIE && !!window.StyleMedia
|
|||
let popupIsOpen = false
|
||||
let notificationIsOpen = false
|
||||
const openMetamaskTabsIDs = {}
|
||||
const requestAccountTabIds = {}
|
||||
|
||||
// state persistence
|
||||
const diskStore = new LocalStorageStore({ storageKey: STORAGE_KEY })
|
||||
|
@ -263,6 +264,9 @@ function setupController (initState, initLangCode) {
|
|||
initLangCode,
|
||||
// platform specific api
|
||||
platform,
|
||||
getRequestAccountTabIds: () => {
|
||||
return requestAccountTabIds
|
||||
},
|
||||
encryptor: isEdge ? new EdgeEncryptor() : undefined,
|
||||
})
|
||||
global.metamaskController = controller
|
||||
|
@ -328,6 +332,10 @@ function setupController (initState, initLangCode) {
|
|||
[ENVIRONMENT_TYPE_FULLSCREEN]: true,
|
||||
}
|
||||
|
||||
const metamaskBlacklistedPorts = [
|
||||
'trezor-connect',
|
||||
]
|
||||
|
||||
const isClientOpenStatus = () => {
|
||||
return popupIsOpen || Boolean(Object.keys(openMetamaskTabsIDs).length) || notificationIsOpen
|
||||
}
|
||||
|
@ -348,11 +356,15 @@ function setupController (initState, initLangCode) {
|
|||
const processName = remotePort.name
|
||||
const isMetaMaskInternalProcess = metamaskInternalProcessHash[processName]
|
||||
|
||||
if (metamaskBlacklistedPorts.includes(remotePort.name)) {
|
||||
return false
|
||||
}
|
||||
|
||||
if (isMetaMaskInternalProcess) {
|
||||
const portStream = new PortStream(remotePort)
|
||||
// communication with popup
|
||||
controller.isClientOpen = true
|
||||
controller.setupTrustedCommunication(portStream, 'MetaMask')
|
||||
controller.setupTrustedCommunication(portStream, remotePort.sender)
|
||||
|
||||
if (processName === ENVIRONMENT_TYPE_POPUP) {
|
||||
popupIsOpen = true
|
||||
|
@ -382,6 +394,17 @@ function setupController (initState, initLangCode) {
|
|||
})
|
||||
}
|
||||
} else {
|
||||
if (remotePort.sender && remotePort.sender.tab && remotePort.sender.url) {
|
||||
const tabId = remotePort.sender.tab.id
|
||||
const url = new URL(remotePort.sender.url)
|
||||
const origin = url.hostname
|
||||
|
||||
remotePort.onMessage.addListener((msg) => {
|
||||
if (msg.data && msg.data.method === 'eth_requestAccounts') {
|
||||
requestAccountTabIds[origin] = tabId
|
||||
}
|
||||
})
|
||||
}
|
||||
connectExternal(remotePort)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -70,6 +70,7 @@ export const SAFE_METHODS = [
|
|||
'eth_signTypedData',
|
||||
'eth_signTypedData_v1',
|
||||
'eth_signTypedData_v3',
|
||||
'eth_signTypedData_v4',
|
||||
'eth_submitHashrate',
|
||||
'eth_submitWork',
|
||||
'eth_syncing',
|
||||
|
|
|
@ -440,7 +440,6 @@ module.exports = class MetamaskController extends EventEmitter {
|
|||
setUsePhishDetect: this.setUsePhishDetect.bind(this),
|
||||
setCurrentLocale: this.setCurrentLocale.bind(this),
|
||||
setDProvider: this.setDProvider.bind(this),
|
||||
markAccountsFound: this.markAccountsFound.bind(this),
|
||||
markPasswordForgotten: this.markPasswordForgotten.bind(this),
|
||||
unMarkPasswordForgotten: this.unMarkPasswordForgotten.bind(this),
|
||||
getGasPrice: (cb) => cb(null, this.getGasPrice()),
|
||||
|
@ -1380,8 +1379,8 @@ cancelEncryptionPublicKey (msgId, cb) {
|
|||
* @param {Object} msgParams - The params passed to eth_signTypedData.
|
||||
* @param {Function} cb - The callback function, called with the signature.
|
||||
*/
|
||||
newUnsignedTypedMessage (msgParams, req) {
|
||||
const promise = this.typedMessageManager.addUnapprovedMessageAsync(msgParams, req)
|
||||
newUnsignedTypedMessage (msgParams, req, version) {
|
||||
const promise = this.typedMessageManager.addUnapprovedMessageAsync(msgParams, req, version)
|
||||
this.sendUpdate()
|
||||
this.opts.showUnconfirmedMessage()
|
||||
return promise
|
||||
|
@ -1392,7 +1391,7 @@ cancelEncryptionPublicKey (msgId, cb) {
|
|||
* Triggers the callback in newUnsignedTypedMessage.
|
||||
*
|
||||
* @param {Object} msgParams - The params passed to eth_signTypedData.
|
||||
* @returns {Object} Full state update.
|
||||
* @returns {Object} - Full state update.
|
||||
*/
|
||||
async signTypedMessage (msgParams) {
|
||||
log.info('MetaMaskController - eth_signTypedData')
|
||||
|
@ -1434,64 +1433,6 @@ cancelEncryptionPublicKey (msgId, cb) {
|
|||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// MetaMask Version 3 Migration Account Restauration Methods
|
||||
|
||||
/**
|
||||
* A legacy method (probably dead code) that was used when we swapped out our
|
||||
* key management library that we depended on.
|
||||
*
|
||||
* Described in:
|
||||
* https://medium.com/metamask/metamask-3-migration-guide-914b79533cdd
|
||||
*
|
||||
* @deprecated
|
||||
* @param {} migratorOutput
|
||||
*/
|
||||
restoreOldVaultAccounts (migratorOutput) {
|
||||
const { serialized } = migratorOutput
|
||||
return this.keyringController.restoreKeyring(serialized)
|
||||
.then(() => migratorOutput)
|
||||
}
|
||||
|
||||
/**
|
||||
* A legacy method used to record user confirmation that they understand
|
||||
* that some of their accounts have been recovered but should be backed up.
|
||||
* This function no longer does anything and will be removed.
|
||||
*
|
||||
* @deprecated
|
||||
* @param {Function} cb - A callback function called with a full state update.
|
||||
*/
|
||||
markAccountsFound (cb) {
|
||||
// TODO Remove me
|
||||
cb(null, this.getState())
|
||||
}
|
||||
|
||||
/**
|
||||
* An account object
|
||||
* @typedef Account
|
||||
* @property string privateKey - The private key of the account.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Probably no longer needed, related to the Version 3 migration.
|
||||
* Imports a hash of accounts to private keys into the vault.
|
||||
*
|
||||
* Described in:
|
||||
* https://medium.com/metamask/metamask-3-migration-guide-914b79533cdd
|
||||
*
|
||||
* Uses the array's private keys to create a new Simple Key Pair keychain
|
||||
* and add it to the keyring controller.
|
||||
* @deprecated
|
||||
* @param {Account[]} lostAccounts -
|
||||
* @returns {Keyring[]} An array of the restored keyrings.
|
||||
*/
|
||||
importLostAccounts ({ lostAccounts }) {
|
||||
const privKeys = lostAccounts.map(acct => acct.privateKey)
|
||||
return this.keyringController.restoreKeyring({
|
||||
type: 'Simple Key Pair',
|
||||
data: privKeys,
|
||||
})
|
||||
}
|
||||
|
||||
//=============================================================================
|
||||
// END (VAULT / KEYRING RELATED METHODS)
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -121,7 +121,7 @@
|
|||
"eth-net-props": "^1.0.33",
|
||||
"eth-phishing-detect": "^1.1.4",
|
||||
"eth-query": "^2.1.2",
|
||||
"eth-sig-util": "^2.3.0",
|
||||
"eth-sig-util": "^2.5.1",
|
||||
"eth-token-watcher": "^1.1.7",
|
||||
"eth-trezor-keyring": "github:vbaranov/eth-trezor-keyring#0.4.0",
|
||||
"ethereumjs-abi": "^0.6.7",
|
||||
|
@ -156,7 +156,7 @@
|
|||
"mkdirp": "^0.5.1",
|
||||
"multihashes": "^0.4.12",
|
||||
"nanoid": "^2.1.6",
|
||||
"nifty-wallet-inpage-provider": "github:poanetwork/nifty-wallet-inpage-provider#1.4.0",
|
||||
"nifty-wallet-inpage-provider": "github:poanetwork/nifty-wallet-inpage-provider#1.5.0",
|
||||
"nonce-tracker": "^1.0.0",
|
||||
"number-to-bn": "^1.7.0",
|
||||
"obj-multiplex": "^1.0.0",
|
||||
|
|
Loading…
Reference in New Issue