-
Notifications
You must be signed in to change notification settings - Fork 5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bump controllers v30.0.2 #14906
Bump controllers v30.0.2 #14906
Changes from all commits
295127e
d2c75e1
8cddae7
b95bdb7
f692549
bb56538
1836db7
b3b0099
254cfac
6206bc8
a47a233
5934776
e781121
a65a1d1
1d4dffa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,9 +54,11 @@ import { | |
///: END:ONLY_INCLUDE_IN | ||
|
||
import { | ||
ASSET_TYPES, | ||
TRANSACTION_STATUSES, | ||
TRANSACTION_TYPES, | ||
} from '../../shared/constants/transaction'; | ||
import { PHISHING_NEW_ISSUE_URLS } from '../../shared/constants/phishing'; | ||
import { | ||
GAS_API_BASE_URL, | ||
GAS_DEV_API_BASE_URL, | ||
|
@@ -85,7 +87,7 @@ import { | |
POLLING_TOKEN_ENVIRONMENT_TYPES, | ||
SUBJECT_TYPES, | ||
} from '../../shared/constants/app'; | ||
import { EVENT } from '../../shared/constants/metametrics'; | ||
import { EVENT, EVENT_NAMES } from '../../shared/constants/metametrics'; | ||
|
||
import { hexToDecimal } from '../../ui/helpers/utils/conversions.util'; | ||
import { getTokenValueParam } from '../../ui/helpers/utils/token-util'; | ||
|
@@ -245,35 +247,28 @@ export default class MetamaskController extends EventEmitter { | |
config: { provider: this.provider }, | ||
state: initState.TokensController, | ||
}); | ||
process.env.TOKEN_DETECTION_V2 | ||
? (this.assetsContractController = new AssetsContractController({ | ||
onPreferencesStateChange: (listener) => | ||
this.preferencesController.store.subscribe(listener), | ||
onNetworkStateChange: (cb) => | ||
this.networkController.store.subscribe((networkState) => { | ||
const modifiedNetworkState = { | ||
...networkState, | ||
provider: { | ||
...networkState.provider, | ||
chainId: hexToDecimal(networkState.provider.chainId), | ||
}, | ||
}; | ||
return cb(modifiedNetworkState); | ||
}), | ||
config: { | ||
provider: this.provider, | ||
}, | ||
state: initState.AssetsContractController, | ||
})) | ||
: (this.assetsContractController = new AssetsContractController( | ||
{ | ||
onPreferencesStateChange: (listener) => | ||
this.preferencesController.store.subscribe(listener), | ||
}, | ||
{ | ||
provider: this.provider, | ||
}, | ||
)); | ||
|
||
this.assetsContractController = new AssetsContractController( | ||
{ | ||
onPreferencesStateChange: (listener) => | ||
this.preferencesController.store.subscribe(listener), | ||
onNetworkStateChange: (cb) => | ||
this.networkController.store.subscribe((networkState) => { | ||
const modifiedNetworkState = { | ||
...networkState, | ||
provider: { | ||
...networkState.provider, | ||
chainId: hexToDecimal(networkState.provider.chainId), | ||
}, | ||
}; | ||
return cb(modifiedNetworkState); | ||
}), | ||
}, | ||
{ | ||
provider: this.provider, | ||
}, | ||
initState.AssetsContractController, | ||
); | ||
|
||
this.collectiblesController = new CollectiblesController( | ||
{ | ||
|
@@ -301,6 +296,21 @@ export default class MetamaskController extends EventEmitter { | |
getERC1155TokenURI: this.assetsContractController.getERC1155TokenURI.bind( | ||
this.assetsContractController, | ||
), | ||
onCollectibleAdded: ({ address, symbol, tokenId, standard, source }) => | ||
this.metaMetricsController.trackEvent({ | ||
event: EVENT_NAMES.NFT_ADDED, | ||
category: EVENT.CATEGORIES.WALLET, | ||
properties: { | ||
token_contract_address: address, | ||
token_symbol: symbol, | ||
asset_type: ASSET_TYPES.COLLECTIBLE, | ||
token_standard: standard, | ||
source, | ||
}, | ||
sensitiveProperties: { | ||
tokenId, | ||
}, | ||
}), | ||
}, | ||
{}, | ||
initState.CollectiblesController, | ||
|
@@ -417,50 +427,23 @@ export default class MetamaskController extends EventEmitter { | |
const tokenListMessenger = this.controllerMessenger.getRestricted({ | ||
name: 'TokenListController', | ||
}); | ||
process.env.TOKEN_DETECTION_V2 | ||
? (this.tokenListController = new TokenListController({ | ||
chainId: hexToDecimal(this.networkController.getCurrentChainId()), | ||
onNetworkStateChange: (cb) => | ||
this.networkController.store.subscribe((networkState) => { | ||
const modifiedNetworkState = { | ||
...networkState, | ||
provider: { | ||
...networkState.provider, | ||
chainId: hexToDecimal(networkState.provider.chainId), | ||
}, | ||
}; | ||
return cb(modifiedNetworkState); | ||
}), | ||
messenger: tokenListMessenger, | ||
state: initState.TokenListController, | ||
})) | ||
: (this.tokenListController = new TokenListController({ | ||
chainId: hexToDecimal(this.networkController.getCurrentChainId()), | ||
useStaticTokenList: !this.preferencesController.store.getState() | ||
.useTokenDetection, | ||
onNetworkStateChange: (cb) => | ||
this.networkController.store.subscribe((networkState) => { | ||
const modifiedNetworkState = { | ||
...networkState, | ||
provider: { | ||
...networkState.provider, | ||
chainId: hexToDecimal(networkState.provider.chainId), | ||
}, | ||
}; | ||
return cb(modifiedNetworkState); | ||
}), | ||
onPreferencesStateChange: (cb) => | ||
this.preferencesController.store.subscribe((preferencesState) => { | ||
const modifiedPreferencesState = { | ||
...preferencesState, | ||
useStaticTokenList: !this.preferencesController.store.getState() | ||
.useTokenDetection, | ||
}; | ||
return cb(modifiedPreferencesState); | ||
}), | ||
messenger: tokenListMessenger, | ||
state: initState.TokenListController, | ||
})); | ||
Comment on lines
-439
to
-463
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
this.tokenListController = new TokenListController({ | ||
chainId: hexToDecimal(this.networkController.getCurrentChainId()), | ||
onNetworkStateChange: (cb) => | ||
this.networkController.store.subscribe((networkState) => { | ||
const modifiedNetworkState = { | ||
...networkState, | ||
provider: { | ||
...networkState.provider, | ||
chainId: hexToDecimal(networkState.provider.chainId), | ||
}, | ||
}; | ||
return cb(modifiedNetworkState); | ||
}), | ||
messenger: tokenListMessenger, | ||
state: initState.TokenListController, | ||
}); | ||
|
||
this.phishingController = new PhishingController(); | ||
|
||
|
@@ -1586,7 +1569,6 @@ export default class MetamaskController extends EventEmitter { | |
tokensController, | ||
), | ||
updateTokenType: tokensController.updateTokenType.bind(tokensController), | ||
removeToken: tokensController.removeAndIgnoreToken.bind(tokensController), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
setAccountLabel: preferencesController.setAccountLabel.bind( | ||
preferencesController, | ||
), | ||
|
@@ -1960,20 +1942,14 @@ export default class MetamaskController extends EventEmitter { | |
: null, | ||
|
||
/** Token Detection V2 */ | ||
addDetectedTokens: process.env.TOKEN_DETECTION_V2 | ||
? tokensController.addDetectedTokens.bind(tokensController) | ||
: null, | ||
importTokens: process.env.TOKEN_DETECTION_V2 | ||
? tokensController.importTokens.bind(tokensController) | ||
: null, | ||
ignoreTokens: process.env.TOKEN_DETECTION_V2 | ||
? tokensController.ignoreTokens.bind(tokensController) | ||
: null, | ||
getBalancesInSingleCall: process.env.TOKEN_DETECTION_V2 | ||
? assetsContractController.getBalancesInSingleCall.bind( | ||
assetsContractController, | ||
) | ||
: null, | ||
addDetectedTokens: tokensController.addDetectedTokens.bind( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
tokensController, | ||
), | ||
addImportedTokens: tokensController.addTokens.bind(tokensController), | ||
ignoreTokens: tokensController.ignoreTokens.bind(tokensController), | ||
getBalancesInSingleCall: assetsContractController.getBalancesInSingleCall.bind( | ||
assetsContractController, | ||
), | ||
}; | ||
} | ||
|
||
|
@@ -3342,9 +3318,13 @@ export default class MetamaskController extends EventEmitter { | |
if (sender.url) { | ||
const { hostname } = new URL(sender.url); | ||
// Check if new connection is blocked if phishing detection is on | ||
if (usePhishDetect && this.phishingController.test(hostname)) { | ||
log.debug('MetaMask - sending phishing warning for', hostname); | ||
this.sendPhishingWarning(connectionStream, hostname); | ||
const phishingTestResponse = this.phishingController.test(hostname); | ||
if (usePhishDetect && phishingTestResponse?.result) { | ||
this.sendPhishingWarning( | ||
connectionStream, | ||
hostname, | ||
phishingTestResponse, | ||
); | ||
return; | ||
} | ||
} | ||
|
@@ -3422,11 +3402,15 @@ export default class MetamaskController extends EventEmitter { | |
* @param {*} connectionStream - The duplex stream to the per-page script, | ||
* for sending the reload attempt to. | ||
* @param {string} hostname - The hostname that triggered the suspicion. | ||
* @param {object} phishingTestResponse - Result of calling `phishingController.test`, | ||
* which is the result of calling eth-phishing-detects detector.check method https://github.com/MetaMask/eth-phishing-detect/blob/master/src/detector.js#L55-L112 | ||
*/ | ||
sendPhishingWarning(connectionStream, hostname) { | ||
sendPhishingWarning(connectionStream, hostname, phishingTestResponse) { | ||
const newIssueUrl = PHISHING_NEW_ISSUE_URLS[phishingTestResponse?.name]; | ||
|
||
const mux = setupMultiplex(connectionStream); | ||
const phishingStream = mux.createStream('phishing'); | ||
phishingStream.write({ hostname }); | ||
phishingStream.write({ hostname, newIssueUrl }); | ||
} | ||
|
||
/** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all instances of
TokensControllers.removeAndIgnoreToken()
have been replaced with use ofTokensControllers.ignoreTokens()