|
|
|
@ -238,16 +238,35 @@ export default class MetamaskController extends EventEmitter { |
|
|
|
|
config: { provider: this.provider }, |
|
|
|
|
state: initState.TokensController, |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
this.assetsContractController = new AssetsContractController( |
|
|
|
|
{ |
|
|
|
|
onPreferencesStateChange: (listener) => |
|
|
|
|
this.preferencesController.store.subscribe(listener), |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
provider: this.provider, |
|
|
|
|
}, |
|
|
|
|
); |
|
|
|
|
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.collectiblesController = new CollectiblesController( |
|
|
|
|
{ |
|
|
|
@ -388,33 +407,50 @@ export default class MetamaskController extends EventEmitter { |
|
|
|
|
const tokenListMessenger = this.controllerMessenger.getRestricted({ |
|
|
|
|
name: '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, |
|
|
|
|
}); |
|
|
|
|
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, |
|
|
|
|
})); |
|
|
|
|
|
|
|
|
|
this.phishingController = new PhishingController(); |
|
|
|
|
|
|
|
|
@ -665,13 +701,22 @@ export default class MetamaskController extends EventEmitter { |
|
|
|
|
}); |
|
|
|
|
///: END:ONLY_INCLUDE_IN
|
|
|
|
|
|
|
|
|
|
this.detectTokensController = new DetectTokensController({ |
|
|
|
|
preferences: this.preferencesController, |
|
|
|
|
tokensController: this.tokensController, |
|
|
|
|
network: this.networkController, |
|
|
|
|
keyringMemStore: this.keyringController.memStore, |
|
|
|
|
tokenList: this.tokenListController, |
|
|
|
|
}); |
|
|
|
|
process.env.TOKEN_DETECTION_V2 |
|
|
|
|
? (this.detectTokensController = new DetectTokensController({ |
|
|
|
|
preferences: this.preferencesController, |
|
|
|
|
tokensController: this.tokensController, |
|
|
|
|
assetsContractController: this.assetsContractController, |
|
|
|
|
network: this.networkController, |
|
|
|
|
keyringMemStore: this.keyringController.memStore, |
|
|
|
|
tokenList: this.tokenListController, |
|
|
|
|
})) |
|
|
|
|
: (this.detectTokensController = new DetectTokensController({ |
|
|
|
|
preferences: this.preferencesController, |
|
|
|
|
tokensController: this.tokensController, |
|
|
|
|
network: this.networkController, |
|
|
|
|
keyringMemStore: this.keyringController.memStore, |
|
|
|
|
tokenList: this.tokenListController, |
|
|
|
|
})); |
|
|
|
|
|
|
|
|
|
this.addressBookController = new AddressBookController( |
|
|
|
|
undefined, |
|
|
|
@ -1337,6 +1382,7 @@ export default class MetamaskController extends EventEmitter { |
|
|
|
|
tokensController, |
|
|
|
|
smartTransactionsController, |
|
|
|
|
txController, |
|
|
|
|
assetsContractController, |
|
|
|
|
} = this; |
|
|
|
|
|
|
|
|
|
return { |
|
|
|
@ -1817,6 +1863,22 @@ export default class MetamaskController extends EventEmitter { |
|
|
|
|
collectibleDetectionController, |
|
|
|
|
) |
|
|
|
|
: 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, |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|