mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Add new inpage provider package (#8442)
* add @metamask/inpage-provider * fix failing e2e tests Co-authored-by: Mark Stacey <markjstacey@gmail.com>
This commit is contained in:
parent
da373713da
commit
c011c0406b
@ -34,9 +34,9 @@ cleanContextForImports()
|
|||||||
|
|
||||||
import log from 'loglevel'
|
import log from 'loglevel'
|
||||||
import LocalMessageDuplexStream from 'post-message-stream'
|
import LocalMessageDuplexStream from 'post-message-stream'
|
||||||
import MetamaskInpageProvider from 'metamask-inpage-provider'
|
import { initProvider } from '@metamask/inpage-provider'
|
||||||
|
|
||||||
// TODO:deprecate:Q1-2020
|
// TODO:deprecate:2020
|
||||||
import 'web3/dist/web3.min.js'
|
import 'web3/dist/web3.min.js'
|
||||||
|
|
||||||
import setupDappAutoReload from './lib/auto-reload.js'
|
import setupDappAutoReload from './lib/auto-reload.js'
|
||||||
@ -55,22 +55,12 @@ const metamaskStream = new LocalMessageDuplexStream({
|
|||||||
target: 'contentscript',
|
target: 'contentscript',
|
||||||
})
|
})
|
||||||
|
|
||||||
// compose the inpage provider
|
initProvider({
|
||||||
const inpageProvider = new MetamaskInpageProvider(metamaskStream)
|
connectionStream: metamaskStream,
|
||||||
|
|
||||||
// set a high max listener count to avoid unnecesary warnings
|
|
||||||
inpageProvider.setMaxListeners(100)
|
|
||||||
|
|
||||||
// Work around for web3@1.0 deleting the bound `sendAsync` but not the unbound
|
|
||||||
// `sendAsync` method on the prototype, causing `this` reference issues
|
|
||||||
const proxiedInpageProvider = new Proxy(inpageProvider, {
|
|
||||||
// straight up lie that we deleted the property so that it doesnt
|
|
||||||
// throw an error in strict mode
|
|
||||||
deleteProperty: () => true,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
//
|
//
|
||||||
// TODO:deprecate:Q1-2020
|
// TODO:deprecate:2020
|
||||||
//
|
//
|
||||||
|
|
||||||
// setup web3
|
// setup web3
|
||||||
@ -83,19 +73,13 @@ if (typeof window.web3 !== 'undefined') {
|
|||||||
and try again.`)
|
and try again.`)
|
||||||
}
|
}
|
||||||
|
|
||||||
const web3 = new Web3(proxiedInpageProvider)
|
const web3 = new Web3(window.ethereum)
|
||||||
web3.setProvider = function () {
|
web3.setProvider = function () {
|
||||||
log.debug('MetaMask - overrode web3.setProvider')
|
log.debug('MetaMask - overrode web3.setProvider')
|
||||||
}
|
}
|
||||||
log.debug('MetaMask - injected web3')
|
log.debug('MetaMask - injected web3')
|
||||||
|
|
||||||
proxiedInpageProvider._web3Ref = web3.eth
|
window.ethereum._web3Ref = web3.eth
|
||||||
|
|
||||||
// setup dapp auto reload AND proxy web3
|
// setup dapp auto reload AND proxy web3
|
||||||
setupDappAutoReload(web3, inpageProvider._publicConfigStore)
|
setupDappAutoReload(web3, window.ethereum._publicConfigStore)
|
||||||
|
|
||||||
//
|
|
||||||
// end deprecate:Q1-2020
|
|
||||||
//
|
|
||||||
|
|
||||||
window.ethereum = proxiedInpageProvider
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
|
|
||||||
// TODO:deprecate:Q1-2020
|
// TODO:deprecate:2020
|
||||||
|
|
||||||
export default setupDappAutoReload
|
export default setupDappAutoReload
|
||||||
|
|
||||||
@ -16,7 +16,7 @@ function setupDappAutoReload (web3, observable) {
|
|||||||
lastTimeUsed = Date.now()
|
lastTimeUsed = Date.now()
|
||||||
// show warning once on web3 access
|
// show warning once on web3 access
|
||||||
if (!hasBeenWarned && key !== 'currentProvider') {
|
if (!hasBeenWarned && key !== 'currentProvider') {
|
||||||
console.warn(`MetaMask: In Q1 2020, MetaMask will no longer inject web3. For more information, see: https://medium.com/metamask/no-longer-injecting-web3-js-4a899ad6e59e`)
|
console.warn(`MetaMask: We will soon stop injecting web3. For more information, see: https://medium.com/metamask/no-longer-injecting-web3-js-4a899ad6e59e`)
|
||||||
hasBeenWarned = true
|
hasBeenWarned = true
|
||||||
}
|
}
|
||||||
// return value normally
|
// return value normally
|
||||||
|
@ -76,6 +76,7 @@
|
|||||||
"@metamask/eth-ledger-bridge-keyring": "^0.2.6",
|
"@metamask/eth-ledger-bridge-keyring": "^0.2.6",
|
||||||
"@metamask/eth-token-tracker": "^2.0.0",
|
"@metamask/eth-token-tracker": "^2.0.0",
|
||||||
"@metamask/etherscan-link": "^1.1.0",
|
"@metamask/etherscan-link": "^1.1.0",
|
||||||
|
"@metamask/inpage-provider": "^5.0.0",
|
||||||
"@sentry/browser": "^5.11.1",
|
"@sentry/browser": "^5.11.1",
|
||||||
"@sentry/integrations": "^5.11.1",
|
"@sentry/integrations": "^5.11.1",
|
||||||
"@zxing/library": "^0.8.0",
|
"@zxing/library": "^0.8.0",
|
||||||
@ -130,7 +131,6 @@
|
|||||||
"lodash": "^4.17.15",
|
"lodash": "^4.17.15",
|
||||||
"loglevel": "^1.4.1",
|
"loglevel": "^1.4.1",
|
||||||
"luxon": "^1.23.0",
|
"luxon": "^1.23.0",
|
||||||
"metamask-inpage-provider": "^4.1.2",
|
|
||||||
"metamask-logo": "^2.1.4",
|
"metamask-logo": "^2.1.4",
|
||||||
"multihashes": "^0.4.12",
|
"multihashes": "^0.4.12",
|
||||||
"nanoid": "^2.1.6",
|
"nanoid": "^2.1.6",
|
||||||
|
@ -89,7 +89,7 @@ const initialize = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const onClickConnect = async () => {
|
const onClickConnect = async () => {
|
||||||
await window.ethereum.enable()
|
await window.ethereum.request({ method: 'eth_requestAccounts' })
|
||||||
}
|
}
|
||||||
|
|
||||||
const updateButtons = () => {
|
const updateButtons = () => {
|
||||||
@ -324,7 +324,7 @@ const initialize = () => {
|
|||||||
|
|
||||||
getAccountsButton.addEventListener('click', async () => {
|
getAccountsButton.addEventListener('click', async () => {
|
||||||
try {
|
try {
|
||||||
const accounts = await ethereum.send({ method: 'eth_accounts' })
|
const accounts = await ethereum.request({ method: 'eth_accounts' })
|
||||||
getAccountsResults.innerHTML = accounts[0] || 'Not able to get accounts'
|
getAccountsResults.innerHTML = accounts[0] || 'Not able to get accounts'
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
@ -340,7 +340,7 @@ const initialize = () => {
|
|||||||
ethereum.on('networkChanged', (networkId) => {
|
ethereum.on('networkChanged', (networkId) => {
|
||||||
networkDiv.innerHTML = networkId
|
networkDiv.innerHTML = networkId
|
||||||
})
|
})
|
||||||
ethereum.on('chainIdChanged', (chainId) => {
|
ethereum.on('chainChanged', (chainId) => {
|
||||||
chainIdDiv.innerHTML = chainId
|
chainIdDiv.innerHTML = chainId
|
||||||
})
|
})
|
||||||
ethereum.on('accountsChanged', (newAccounts) => {
|
ethereum.on('accountsChanged', (newAccounts) => {
|
||||||
|
36
yarn.lock
36
yarn.lock
@ -1888,6 +1888,21 @@
|
|||||||
resolved "https://registry.yarnpkg.com/@metamask/forwarder/-/forwarder-1.1.0.tgz#13829d8244bbf19ea658c0b20d21a77b67de0bdd"
|
resolved "https://registry.yarnpkg.com/@metamask/forwarder/-/forwarder-1.1.0.tgz#13829d8244bbf19ea658c0b20d21a77b67de0bdd"
|
||||||
integrity sha512-Hggj4y0QIjDzKGTXzarhEPIQyFSB2bi2y6YLJNwaT4JmP30UB5Cj6gqoY0M4pj3QT57fzp0BUuGp7F/AUe28tw==
|
integrity sha512-Hggj4y0QIjDzKGTXzarhEPIQyFSB2bi2y6YLJNwaT4JmP30UB5Cj6gqoY0M4pj3QT57fzp0BUuGp7F/AUe28tw==
|
||||||
|
|
||||||
|
"@metamask/inpage-provider@^5.0.0":
|
||||||
|
version "5.0.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/@metamask/inpage-provider/-/inpage-provider-5.0.0.tgz#f3961ceb02821255785fe20b1b676bfd944532d7"
|
||||||
|
integrity sha512-DjQy/hJPKwEhk+L/XPHfR6bSTWsGGXjHCQ3Q/LgieQX/Kv91yyMu+QUu+tWuVi0qX0dSRmaTnFNCF9FWNV1XgA==
|
||||||
|
dependencies:
|
||||||
|
eth-json-rpc-errors "^2.0.2"
|
||||||
|
fast-deep-equal "^2.0.1"
|
||||||
|
json-rpc-engine "^5.1.5"
|
||||||
|
json-rpc-middleware-stream "^2.1.1"
|
||||||
|
loglevel "^1.6.1"
|
||||||
|
obj-multiplex "^1.0.0"
|
||||||
|
obs-store "^4.0.3"
|
||||||
|
pump "^3.0.0"
|
||||||
|
safe-event-emitter "^1.0.1"
|
||||||
|
|
||||||
"@metamask/onboarding@^0.2.0":
|
"@metamask/onboarding@^0.2.0":
|
||||||
version "0.2.0"
|
version "0.2.0"
|
||||||
resolved "https://registry.yarnpkg.com/@metamask/onboarding/-/onboarding-0.2.0.tgz#9594f6a9a1c779083d71434b9f5e6a973af941f7"
|
resolved "https://registry.yarnpkg.com/@metamask/onboarding/-/onboarding-0.2.0.tgz#9594f6a9a1c779083d71434b9f5e6a973af941f7"
|
||||||
@ -18396,9 +18411,9 @@ loglevel@^1.4.1, loglevel@^1.5.0:
|
|||||||
integrity sha1-rgyqVhERSYxboTcj1vtjHSQAOTQ=
|
integrity sha1-rgyqVhERSYxboTcj1vtjHSQAOTQ=
|
||||||
|
|
||||||
loglevel@^1.6.1:
|
loglevel@^1.6.1:
|
||||||
version "1.6.3"
|
version "1.6.8"
|
||||||
resolved "https://registry.yarnpkg.com/loglevel/-/loglevel-1.6.3.tgz#77f2eb64be55a404c9fd04ad16d57c1d6d6b1280"
|
resolved "https://registry.yarnpkg.com/loglevel/-/loglevel-1.6.8.tgz#8a25fb75d092230ecd4457270d80b54e28011171"
|
||||||
integrity sha512-LoEDv5pgpvWgPF4kNYuIp0qqSJVWak/dML0RY74xlzMZiT9w77teNAwKYKWBTYjlokMirg+o3jBwp+vlLrcfAA==
|
integrity sha512-bsU7+gc9AJ2SqpzxwU3+1fedl8zAntbtC5XYlt3s2j1hJcn2PsXSmgN8TaLG/J1/2mod4+cE/3vNL70/c1RNCA==
|
||||||
|
|
||||||
logplease@^1.2.14, logplease@~1.2.14, logplease@~1.2.15:
|
logplease@^1.2.14, logplease@~1.2.14, logplease@~1.2.15:
|
||||||
version "1.2.15"
|
version "1.2.15"
|
||||||
@ -18927,21 +18942,6 @@ mersenne-twister@^1.0.1, mersenne-twister@^1.1.0:
|
|||||||
resolved "https://registry.yarnpkg.com/mersenne-twister/-/mersenne-twister-1.1.0.tgz#f916618ee43d7179efcf641bec4531eb9670978a"
|
resolved "https://registry.yarnpkg.com/mersenne-twister/-/mersenne-twister-1.1.0.tgz#f916618ee43d7179efcf641bec4531eb9670978a"
|
||||||
integrity sha1-+RZhjuQ9cXnvz2Qb7EUx65Zwl4o=
|
integrity sha1-+RZhjuQ9cXnvz2Qb7EUx65Zwl4o=
|
||||||
|
|
||||||
metamask-inpage-provider@^4.1.2:
|
|
||||||
version "4.1.2"
|
|
||||||
resolved "https://registry.yarnpkg.com/metamask-inpage-provider/-/metamask-inpage-provider-4.1.2.tgz#8068004d51160dc5869c5aa881074284b8db03da"
|
|
||||||
integrity sha512-HLCW4DdvubLGntez5yB6kOqvptnpgUcUaRenEwzqN+hHQMnA2+1mNLp5IYks30kvX/fI2ACJgekFwIRDFWA9gQ==
|
|
||||||
dependencies:
|
|
||||||
eth-json-rpc-errors "^2.0.2"
|
|
||||||
fast-deep-equal "^2.0.1"
|
|
||||||
json-rpc-engine "^5.1.5"
|
|
||||||
json-rpc-middleware-stream "^2.1.1"
|
|
||||||
loglevel "^1.6.1"
|
|
||||||
obj-multiplex "^1.0.0"
|
|
||||||
obs-store "^4.0.3"
|
|
||||||
pump "^3.0.0"
|
|
||||||
safe-event-emitter "^1.0.1"
|
|
||||||
|
|
||||||
metamask-logo@^2.1.4:
|
metamask-logo@^2.1.4:
|
||||||
version "2.1.4"
|
version "2.1.4"
|
||||||
resolved "https://registry.yarnpkg.com/metamask-logo/-/metamask-logo-2.1.4.tgz#0612b2b0ffc7eeb6be480c310785426ad9599e3c"
|
resolved "https://registry.yarnpkg.com/metamask-logo/-/metamask-logo-2.1.4.tgz#0612b2b0ffc7eeb6be480c310785426ad9599e3c"
|
||||||
|
Loading…
Reference in New Issue
Block a user