@ -30,6 +30,9 @@ import {
TokenListController ,
TokensController ,
TokenRatesController ,
CollectiblesController ,
AssetsContractController ,
CollectibleDetectionController ,
} from '@metamask/controllers' ;
import { TRANSACTION _STATUSES } from '../../shared/constants/transaction' ;
import {
@ -176,6 +179,57 @@ export default class MetamaskController extends EventEmitter {
state : initState . TokensController ,
} ) ;
this . assetsContractController = new AssetsContractController ( ) ;
this . collectiblesController = new CollectiblesController ( {
onPreferencesStateChange : this . preferencesController . store . subscribe . bind (
this . preferencesController . store ,
) ,
onNetworkStateChange : this . networkController . store . subscribe . bind (
this . networkController . store ,
) ,
getAssetName : this . assetsContractController . getAssetName . bind (
this . assetsContractController ,
) ,
getAssetSymbol : this . assetsContractController . getAssetSymbol . bind (
this . assetsContractController ,
) ,
getCollectibleTokenURI : this . assetsContractController . getCollectibleTokenURI . bind (
this . assetsContractController ,
) ,
getOwnerOf : this . assetsContractController . getOwnerOf . bind (
this . assetsContractController ,
) ,
balanceOfERC1155Collectible : this . assetsContractController . balanceOfERC1155Collectible . bind (
this . assetsContractController ,
) ,
uriERC1155Collectible : this . assetsContractController . uriERC1155Collectible . bind (
this . assetsContractController ,
) ,
} ) ;
process . env . COLLECTIBLES _V1 &&
( this . collectibleDetectionController = new CollectibleDetectionController (
{
onCollectiblesStateChange : ( listener ) =>
this . collectiblesController . subscribe ( listener ) ,
onPreferencesStateChange : this . preferencesController . store . subscribe . bind (
this . preferencesController . store ,
) ,
onNetworkStateChange : this . networkController . store . subscribe . bind (
this . networkController . store ,
) ,
getOpenSeaApiKey : ( ) => this . collectiblesController . openSeaApiKey ,
getBalancesInSingleCall : this . assetsContractController . getBalancesInSingleCall . bind (
this . assetsContractController ,
) ,
addCollectible : this . collectiblesController . addCollectible . bind (
this . collectiblesController ,
) ,
getCollectiblesState : ( ) => this . collectiblesController . state ,
} ,
) ) ;
this . metaMetricsController = new MetaMetricsController ( {
segment ,
preferencesStore : this . preferencesController . store ,
@ -612,6 +666,7 @@ export default class MetamaskController extends EventEmitter {
GasFeeController : this . gasFeeController ,
TokenListController : this . tokenListController ,
TokensController : this . tokensController ,
CollectiblesController : this . collectiblesController ,
} ) ;
this . memStore = new ComposableObservableStore ( {
@ -646,6 +701,7 @@ export default class MetamaskController extends EventEmitter {
GasFeeController : this . gasFeeController ,
TokenListController : this . tokenListController ,
TokensController : this . tokensController ,
CollectiblesController : this . collectiblesController ,
} ,
controllerMessenger : this . controllerMessenger ,
} ) ;
@ -827,6 +883,7 @@ export default class MetamaskController extends EventEmitter {
threeBoxController ,
txController ,
tokensController ,
collectiblesController ,
} = this ;
return {
@ -949,6 +1006,22 @@ export default class MetamaskController extends EventEmitter {
preferencesController ,
) ,
// CollectiblesController
addCollectible : nodeify (
collectiblesController . addCollectible ,
collectiblesController ,
) ,
removeAndIgnoreCollectible : nodeify (
collectiblesController . removeAndIgnoreCollectible ,
collectiblesController ,
) ,
removeCollectible : nodeify (
collectiblesController . removeCollectible ,
collectiblesController ,
) ,
// AddressController
setAddressBook : nodeify (
this . addressBookController . set ,
@ -1247,6 +1320,14 @@ export default class MetamaskController extends EventEmitter {
this . detectTokensController . detectNewTokens ,
this . detectTokensController ,
) ,
// DetectCollectibleController
detectCollectibles : process . env . COLLECTIBLES _V1
? nodeify (
this . collectibleDetectionController . detectCollectibles ,
this . collectibleDetectionController ,
)
: null ,
} ;
}