Skip to content

Commit

Permalink
Merge pull request #10072 from MetaMask/Version-v8.1.9
Browse files Browse the repository at this point in the history
Version v8.1.9 RC
  • Loading branch information
Gudahtt committed Dec 15, 2020
2 parents b0579f9 + 395e4c3 commit 47734b2
Show file tree
Hide file tree
Showing 21 changed files with 274 additions and 107 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ module.exports = {
'babel.config.js',
'nyc.config.js',
'stylelint.config.js',
'app/scripts/runLockdown.js',
'development/**/*.js',
'test/e2e/**/*.js',
'test/lib/wait-until-called.js',
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

## Current Develop Branch

## 8.1.9 Tue Dec 15 2020
- [#10034](https://github.com/MetaMask/metamask-extension/pull/10034): Fix contentscript injection failure on Firefox 56
- [#10045](https://github.com/MetaMask/metamask-extension/pull/10045): Fix token validation in Send flow
- [#10048](https://github.com/MetaMask/metamask-extension/pull/10048): Display boolean values when signing typed data
- [#10070](https://github.com/MetaMask/metamask-extension/pull/10070): Add eth_getProof
- [#10043](https://github.com/MetaMask/metamask-extension/pull/10043): Improve swaps maximum gas estimation
- [#10069](https://github.com/MetaMask/metamask-extension/pull/10069): Fetch swap quote refresh time from API

## 8.1.8 Wed Dec 09 2020
- [#9992](https://github.com/MetaMask/metamask-extension/pull/9992): Improve transaction params validation
- [#9991](https://github.com/MetaMask/metamask-extension/pull/9991): Don't allow more than 15% slippage
Expand Down
3 changes: 2 additions & 1 deletion app/manifest/_base.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
{
"matches": ["file://*/*", "http://*/*", "https://*/*"],
"js": [
"disable-console.js",
"globalthis.js",
"lockdown.js",
"runLockdown.js",
Expand Down Expand Up @@ -77,6 +78,6 @@
"notifications"
],
"short_name": "__MSG_appName__",
"version": "8.1.8",
"version": "8.1.9",
"web_accessible_resources": ["inpage.js", "phishing.html"]
}
27 changes: 13 additions & 14 deletions app/scripts/contentscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ function injectScript(content) {
scriptTag.textContent = content
container.insertBefore(scriptTag, container.children[0])
container.removeChild(scriptTag)
} catch (e) {
console.error('MetaMask provider injection failed.', e)
} catch (error) {
console.error('MetaMask: Provider injection failed.', error)
}
}

Expand Down Expand Up @@ -95,10 +95,10 @@ async function setupStreams() {
function forwardTrafficBetweenMuxers(channelName, muxA, muxB) {
const channelA = muxA.createStream(channelName)
const channelB = muxB.createStream(channelName)
pump(channelA, channelB, channelA, (err) =>
logStreamDisconnectWarning(
`MetaMask muxed traffic for channel "${channelName}" failed.`,
err,
pump(channelA, channelB, channelA, (error) =>
console.debug(
`MetaMask: Muxed traffic for channel "${channelName}" failed.`,
error,
),
)
}
Expand All @@ -107,14 +107,13 @@ function forwardTrafficBetweenMuxers(channelName, muxA, muxB) {
* Error handler for page to extension stream disconnections
*
* @param {string} remoteLabel - Remote stream name
* @param {Error} err - Stream connection error
* @param {Error} error - Stream connection error
*/
function logStreamDisconnectWarning(remoteLabel, err) {
let warningMsg = `MetamaskContentscript - lost connection to ${remoteLabel}`
if (err) {
warningMsg += `\n${err.stack}`
}
console.warn(warningMsg)
function logStreamDisconnectWarning(remoteLabel, error) {
console.debug(
`MetaMask: Content script lost connection to "${remoteLabel}".`,
error,
)
}

/**
Expand Down Expand Up @@ -214,7 +213,7 @@ function blockedDomainCheck() {
* Redirects the current page to a phishing information page
*/
function redirectToPhishingWarning() {
console.log('MetaMask - routing to Phishing Warning component')
console.debug('MetaMask: Routing to Phishing Warning component.')
const extensionURL = extension.runtime.getURL('phishing.html')
window.location.href = `${extensionURL}#${querystring.stringify({
hostname: window.location.hostname,
Expand Down
19 changes: 10 additions & 9 deletions app/scripts/controllers/permissions/enums.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,11 @@ export const LOG_METHOD_TYPES = {
export const LOG_LIMIT = 100

export const SAFE_METHODS = [
'web3_sha3',
'web3_clientVersion',
'net_listening',
'net_peerCount',
'net_version',
'eth_blockNumber',
'eth_call',
'eth_chainId',
'eth_coinbase',
'eth_decrypt',
'eth_estimateGas',
'eth_gasPrice',
'eth_getBalance',
Expand All @@ -49,9 +45,11 @@ export const SAFE_METHODS = [
'eth_getBlockTransactionCountByHash',
'eth_getBlockTransactionCountByNumber',
'eth_getCode',
'eth_getEncryptionPublicKey',
'eth_getFilterChanges',
'eth_getFilterLogs',
'eth_getLogs',
'eth_getProof',
'eth_getStorageAt',
'eth_getTransactionByBlockHashAndIndex',
'eth_getTransactionByBlockNumberAndIndex',
Expand All @@ -72,8 +70,6 @@ export const SAFE_METHODS = [
'eth_sendRawTransaction',
'eth_sendTransaction',
'eth_sign',
'personal_sign',
'personal_ecRecover',
'eth_signTypedData',
'eth_signTypedData_v1',
'eth_signTypedData_v3',
Expand All @@ -83,7 +79,12 @@ export const SAFE_METHODS = [
'eth_syncing',
'eth_uninstallFilter',
'metamask_watchAsset',
'net_listening',
'net_peerCount',
'net_version',
'personal_ecRecover',
'personal_sign',
'wallet_watchAsset',
'eth_getEncryptionPublicKey',
'eth_decrypt',
'web3_clientVersion',
'web3_sha3',
]
45 changes: 39 additions & 6 deletions app/scripts/controllers/swaps.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
import {
fetchTradesInfo as defaultFetchTradesInfo,
fetchSwapsFeatureLiveness as defaultFetchSwapsFeatureLiveness,
fetchSwapsQuoteRefreshTime as defaultFetchSwapsQuoteRefreshTime,
} from '../../../ui/app/pages/swaps/swaps.util'

const METASWAP_ADDRESS = '0x881d40237659c251811cec9c364ef91dc08d300c'
Expand All @@ -28,6 +29,14 @@ const MAX_GAS_LIMIT = 2500000
// 3 seems to be an appropriate balance of giving users the time they need when MetaMask is not left idle, and turning polling off when it is.
const POLL_COUNT_LIMIT = 3

// If for any reason the MetaSwap API fails to provide a refresh time,
// provide a reasonable fallback to avoid further errors
const FALLBACK_QUOTE_REFRESH_TIME = 60000

// This is the amount of time to wait, after successfully fetching quotes
// and their gas estimates, before fetching for new quotes
const QUOTE_POLLING_DIFFERENCE_INTERVAL = 10 * 1000

function calculateGasEstimateWithRefund(
maxGas = MAX_GAS_LIMIT,
estimatedRefund = 0,
Expand All @@ -42,9 +51,6 @@ function calculateGasEstimateWithRefund(
return gasEstimateWithRefund
}

// This is the amount of time to wait, after successfully fetching quotes and their gas estimates, before fetching for new quotes
const QUOTE_POLLING_INTERVAL = 50 * 1000

const initialState = {
swapsState: {
quotes: {},
Expand All @@ -61,6 +67,7 @@ const initialState = {
topAggId: null,
routeState: '',
swapsFeatureIsLive: false,
swapsQuoteRefreshTime: FALLBACK_QUOTE_REFRESH_TIME,
},
}

Expand All @@ -73,13 +80,15 @@ export default class SwapsController {
tokenRatesStore,
fetchTradesInfo = defaultFetchTradesInfo,
fetchSwapsFeatureLiveness = defaultFetchSwapsFeatureLiveness,
fetchSwapsQuoteRefreshTime = defaultFetchSwapsQuoteRefreshTime,
}) {
this.store = new ObservableStore({
swapsState: { ...initialState.swapsState },
})

this._fetchTradesInfo = fetchTradesInfo
this._fetchSwapsFeatureLiveness = fetchSwapsFeatureLiveness
this._fetchSwapsQuoteRefreshTime = fetchSwapsQuoteRefreshTime

this.getBufferedGasLimit = getBufferedGasLimit
this.tokenRatesStore = tokenRatesStore
Expand All @@ -101,19 +110,39 @@ export default class SwapsController {
this._setupSwapsLivenessFetching()
}

// Sets the refresh rate for quote updates from the MetaSwap API
async _setSwapsQuoteRefreshTime() {
// Default to fallback time unless API returns valid response
let swapsQuoteRefreshTime = FALLBACK_QUOTE_REFRESH_TIME
try {
swapsQuoteRefreshTime = await this._fetchSwapsQuoteRefreshTime()
} catch (e) {
console.error('Request for swaps quote refresh time failed: ', e)
}

const { swapsState } = this.store.getState()
this.store.updateState({
swapsState: { ...swapsState, swapsQuoteRefreshTime },
})
}

// Once quotes are fetched, we poll for new ones to keep the quotes up to date. Market and aggregator contract conditions can change fast enough
// that quotes will no longer be available after 1 or 2 minutes. When fetchAndSetQuotes is first called it, receives fetch that parameters are stored in
// state. These stored parameters are used on subsequent calls made during polling.
// Note: we stop polling after 3 requests, until new quotes are explicitly asked for. The logic that enforces that maximum is in the body of fetchAndSetQuotes
pollForNewQuotes() {
const {
swapsState: { swapsQuoteRefreshTime },
} = this.store.getState()

this.pollingTimeout = setTimeout(() => {
const { swapsState } = this.store.getState()
this.fetchAndSetQuotes(
swapsState.fetchParams,
swapsState.fetchParams?.metaData,
true,
)
}, QUOTE_POLLING_INTERVAL)
}, swapsQuoteRefreshTime - QUOTE_POLLING_DIFFERENCE_INTERVAL)
}

stopPollingForQuotes() {
Expand All @@ -128,7 +157,6 @@ export default class SwapsController {
if (!fetchParams) {
return null
}

// Every time we get a new request that is not from the polling, we reset the poll count so we can poll for up to three more sets of quotes with these new params.
if (!isPolledRequest) {
this.pollCount = 0
Expand All @@ -144,7 +172,10 @@ export default class SwapsController {
const indexOfCurrentCall = this.indexOfNewestCallInFlight + 1
this.indexOfNewestCallInFlight = indexOfCurrentCall

let newQuotes = await this._fetchTradesInfo(fetchParams)
let [newQuotes] = await Promise.all([
this._fetchTradesInfo(fetchParams),
this._setSwapsQuoteRefreshTime(),
])

newQuotes = mapValues(newQuotes, (quote) => ({
...quote,
Expand Down Expand Up @@ -422,6 +453,7 @@ export default class SwapsController {
tokens: swapsState.tokens,
fetchParams: swapsState.fetchParams,
swapsFeatureIsLive: swapsState.swapsFeatureIsLive,
swapsQuoteRefreshTime: swapsState.swapsQuoteRefreshTime,
},
})
clearTimeout(this.pollingTimeout)
Expand All @@ -435,6 +467,7 @@ export default class SwapsController {
...initialState.swapsState,
tokens: swapsState.tokens,
swapsFeatureIsLive: swapsState.swapsFeatureIsLive,
swapsQuoteRefreshTime: swapsState.swapsQuoteRefreshTime,
},
})
clearTimeout(this.pollingTimeout)
Expand Down
9 changes: 9 additions & 0 deletions app/scripts/disable-console.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Disable console.log in contentscript to prevent SES/lockdown logging to external page
// eslint-disable-next-line import/unambiguous
if (
!(typeof process !== 'undefined' && process.env.METAMASK_DEBUG) &&
typeof console !== undefined
) {
console.log = () => undefined
console.info = () => undefined
}
25 changes: 18 additions & 7 deletions app/scripts/runLockdown.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
// Freezes all intrinsics
// eslint-disable-next-line no-undef,import/unambiguous
lockdown({
consoleTaming: 'unsafe',
errorTaming: 'unsafe',
mathTaming: 'unsafe',
dateTaming: 'unsafe',
})
try {
// eslint-disable-next-line no-undef,import/unambiguous
lockdown({
consoleTaming: 'unsafe',
errorTaming: 'unsafe',
mathTaming: 'unsafe',
dateTaming: 'unsafe',
})
} catch (error) {
// If the `lockdown` call throws an exception, it interferes with the
// contentscript injection on some versions of Firefox. The error is
// caught and logged here so that the contentscript still gets injected.
// This affects Firefox v56 and Waterfox Classic
console.error('Lockdown failed:', error)
if (window.sentry && window.sentry.captureException) {
window.sentry.captureException(error)
}
}
18 changes: 18 additions & 0 deletions development/build/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,20 @@ function createScriptTasks({ browserPlatforms, livereload }) {
}),
)
})

// inpage must be built before contentscript
// because inpage bundle result is included inside contentscript
const contentscriptSubtask = createTask(
`${taskPrefix}:contentscript`,
createTaskForBuildJsExtensionContentscript({ devMode, testing }),
)

// this can run whenever
const disableConsoleSubtask = createTask(
`${taskPrefix}:disable-console`,
createTaskForBuildJsExtensionDisableConsole({ devMode }),
)

// task for initiating livereload
const initiateLiveReload = async () => {
if (devMode) {
Expand All @@ -142,6 +149,7 @@ function createScriptTasks({ browserPlatforms, livereload }) {
const allSubtasks = [
...standardSubtasks,
contentscriptSubtask,
disableConsoleSubtask,
].map((subtask) => runInChildProcess(subtask))
// const allSubtasks = [...standardSubtasks, contentscriptSubtask].map(subtask => (subtask))
// make a parent task that runs each task in a child thread
Expand All @@ -165,6 +173,16 @@ function createScriptTasks({ browserPlatforms, livereload }) {
})
}

function createTaskForBuildJsExtensionDisableConsole({ devMode }) {
const filename = 'disable-console'
return bundleTask({
label: filename,
filename: `${filename}.js`,
filepath: `./app/scripts/${filename}.js`,
devMode,
})
}

function createTaskForBuildJsExtensionContentscript({ devMode, testing }) {
const inpage = 'inpage'
const contentscript = 'contentscript'
Expand Down

0 comments on commit 47734b2

Please sign in to comment.