mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-22 01:47:00 +01:00
Add CollectiblesController & CollectibleDetectionController (#12443)
* Add CollectiblesController * bump controllers version * add CollectibleDetectionController * adapt to ERC1155 support changes in CollectiblesController * update @metamask/controllers to v20.0.0 * update lavamoat policy files * put collectibleDetectionController instantiation behind feature flag
This commit is contained in:
parent
3f3479bf6e
commit
b119b7744d
@ -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,
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -526,6 +526,7 @@
|
||||
"ethjs-util": true,
|
||||
"events": true,
|
||||
"human-standard-collectible-abi": true,
|
||||
"human-standard-multi-collectible-abi": true,
|
||||
"human-standard-token-abi": true,
|
||||
"immer": true,
|
||||
"isomorphic-fetch": true,
|
||||
|
@ -526,6 +526,7 @@
|
||||
"ethjs-util": true,
|
||||
"events": true,
|
||||
"human-standard-collectible-abi": true,
|
||||
"human-standard-multi-collectible-abi": true,
|
||||
"human-standard-token-abi": true,
|
||||
"immer": true,
|
||||
"isomorphic-fetch": true,
|
||||
|
@ -526,6 +526,7 @@
|
||||
"ethjs-util": true,
|
||||
"events": true,
|
||||
"human-standard-collectible-abi": true,
|
||||
"human-standard-multi-collectible-abi": true,
|
||||
"human-standard-token-abi": true,
|
||||
"immer": true,
|
||||
"isomorphic-fetch": true,
|
||||
|
@ -107,7 +107,7 @@
|
||||
"@fortawesome/fontawesome-free": "^5.13.0",
|
||||
"@material-ui/core": "^4.11.0",
|
||||
"@metamask/contract-metadata": "^1.28.0",
|
||||
"@metamask/controllers": "^17.0.0",
|
||||
"@metamask/controllers": "^20.0.0",
|
||||
"@metamask/eth-ledger-bridge-keyring": "^0.10.0",
|
||||
"@metamask/eth-token-tracker": "^3.0.1",
|
||||
"@metamask/etherscan-link": "^2.1.0",
|
||||
|
@ -1292,6 +1292,79 @@ export function addToken(
|
||||
};
|
||||
}
|
||||
|
||||
export function addCollectible(address, tokenID, dontShowLoadingIndicator) {
|
||||
return async (dispatch) => {
|
||||
if (!address) {
|
||||
throw new Error('MetaMask - Cannot add collectible without address');
|
||||
}
|
||||
if (!tokenID) {
|
||||
throw new Error('MetaMask - Cannot add collectible without tokenID');
|
||||
}
|
||||
if (!dontShowLoadingIndicator) {
|
||||
dispatch(showLoadingIndication());
|
||||
}
|
||||
try {
|
||||
await promisifiedBackground.addCollectible(address, tokenID);
|
||||
} catch (error) {
|
||||
log.error(error);
|
||||
dispatch(displayWarning(error.message));
|
||||
} finally {
|
||||
await forceUpdateMetamaskState(dispatch);
|
||||
dispatch(hideLoadingIndication());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export function removeAndIgnoreCollectible(
|
||||
address,
|
||||
tokenID,
|
||||
dontShowLoadingIndicator,
|
||||
) {
|
||||
return async (dispatch) => {
|
||||
if (!address) {
|
||||
throw new Error('MetaMask - Cannot ignore collectible without address');
|
||||
}
|
||||
if (!tokenID) {
|
||||
throw new Error('MetaMask - Cannot ignore collectible without tokenID');
|
||||
}
|
||||
if (!dontShowLoadingIndicator) {
|
||||
dispatch(showLoadingIndication());
|
||||
}
|
||||
try {
|
||||
await promisifiedBackground.removeAndIgnoreCollectible(address, tokenID);
|
||||
} catch (error) {
|
||||
log.error(error);
|
||||
dispatch(displayWarning(error.message));
|
||||
} finally {
|
||||
await forceUpdateMetamaskState(dispatch);
|
||||
dispatch(hideLoadingIndication());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export function removeCollectible(address, tokenID, dontShowLoadingIndicator) {
|
||||
return async (dispatch) => {
|
||||
if (!address) {
|
||||
throw new Error('MetaMask - Cannot remove collectible without address');
|
||||
}
|
||||
if (!tokenID) {
|
||||
throw new Error('MetaMask - Cannot remove collectible without tokenID');
|
||||
}
|
||||
if (!dontShowLoadingIndicator) {
|
||||
dispatch(showLoadingIndication());
|
||||
}
|
||||
try {
|
||||
await promisifiedBackground.removeCollectible(address, tokenID);
|
||||
} catch (error) {
|
||||
log.error(error);
|
||||
dispatch(displayWarning(error.message));
|
||||
} finally {
|
||||
await forceUpdateMetamaskState(dispatch);
|
||||
dispatch(hideLoadingIndication());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export function removeToken(address) {
|
||||
return async (dispatch) => {
|
||||
dispatch(showLoadingIndication());
|
||||
|
18
yarn.lock
18
yarn.lock
@ -4183,19 +4183,19 @@
|
||||
semver "^7.3.5"
|
||||
yargs "^17.0.1"
|
||||
|
||||
"@metamask/contract-metadata@^1.19.0", "@metamask/contract-metadata@^1.28.0", "@metamask/contract-metadata@^1.29.0":
|
||||
"@metamask/contract-metadata@^1.19.0", "@metamask/contract-metadata@^1.28.0", "@metamask/contract-metadata@^1.30.0":
|
||||
version "1.30.0"
|
||||
resolved "https://registry.yarnpkg.com/@metamask/contract-metadata/-/contract-metadata-1.30.0.tgz#fa8e1b0c3e7aaa963986088f691fb553ffbe3904"
|
||||
integrity sha512-b2usYW/ptQYnE6zhUmr4T+nvOAQJK5ABcpKudyQANpy4K099elpv4aN0WcrcOcwV99NHOdMzFP3ZuG0HoAyOBQ==
|
||||
|
||||
"@metamask/controllers@^17.0.0":
|
||||
version "17.0.0"
|
||||
resolved "https://registry.yarnpkg.com/@metamask/controllers/-/controllers-17.0.0.tgz#7ef00b4f7583d8075115e8a2f074d7b66646bbe8"
|
||||
integrity sha512-myPlAk8SpNm5SwHHKGgm2XDLP4bxNR2UsKoQlYtV7bJq3l8FV1agSFwHBwDhg61/52Xvqdqy+1YDVdV3kOwPgg==
|
||||
"@metamask/controllers@^20.0.0":
|
||||
version "20.0.0"
|
||||
resolved "https://registry.yarnpkg.com/@metamask/controllers/-/controllers-20.0.0.tgz#5c3fd293e1c8d3de964bbbfadbd73d637d83a1a8"
|
||||
integrity sha512-H7ql719730+KCFRvAxWVKe3PvEabKgA9b+0+k4/nRA2Xvb7Pe3BlQ4lgt44wOFKDqdWyvwvH7mgNTAhDzBu4OA==
|
||||
dependencies:
|
||||
"@ethereumjs/common" "^2.3.1"
|
||||
"@ethereumjs/tx" "^3.2.1"
|
||||
"@metamask/contract-metadata" "^1.29.0"
|
||||
"@metamask/contract-metadata" "^1.30.0"
|
||||
"@types/uuid" "^8.3.0"
|
||||
abort-controller "^3.0.0"
|
||||
async-mutex "^0.2.6"
|
||||
@ -4214,6 +4214,7 @@
|
||||
ethjs-unit "^0.1.6"
|
||||
ethjs-util "^0.1.6"
|
||||
human-standard-collectible-abi "^1.0.2"
|
||||
human-standard-multi-collectible-abi "^1.0.2"
|
||||
human-standard-token-abi "^2.0.0"
|
||||
immer "^9.0.6"
|
||||
isomorphic-fetch "^3.0.0"
|
||||
@ -16415,6 +16416,11 @@ human-standard-collectible-abi@^1.0.2:
|
||||
resolved "https://registry.yarnpkg.com/human-standard-collectible-abi/-/human-standard-collectible-abi-1.0.2.tgz#077bae9ed1b0b0b82bc46932104b4b499c941aa0"
|
||||
integrity sha512-nD3ITUuSAIBgkaCm9J2BGwlHL8iEzFjJfTleDAC5Wi8RBJEXXhxV0JeJjd95o+rTwf98uTE5MW+VoBKOIYQh0g==
|
||||
|
||||
human-standard-multi-collectible-abi@^1.0.2:
|
||||
version "1.0.3"
|
||||
resolved "https://registry.yarnpkg.com/human-standard-multi-collectible-abi/-/human-standard-multi-collectible-abi-1.0.3.tgz#be5896b13f8622289cff70040e478366931bf3d7"
|
||||
integrity sha512-1VXqats7JQqDZozLKhpmFG0S33hVePrkLNRJNKfJTxewR0heYKjSoz72kqs+6O/Tywi0zW4fWe7dfTaPX4j7gQ==
|
||||
|
||||
human-standard-token-abi@^1.0.2:
|
||||
version "1.0.2"
|
||||
resolved "https://registry.yarnpkg.com/human-standard-token-abi/-/human-standard-token-abi-1.0.2.tgz#207d7846796ee5bb85fdd336e769cb38045b2ae0"
|
||||
|
Loading…
Reference in New Issue
Block a user