Skip to content

NFT: Replaced all the instances of collectibles with NFTs #17741

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

Merged
merged 16 commits into from
Feb 16, 2023
2 changes: 1 addition & 1 deletion app/_locales/el/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions app/_locales/fr/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions app/_locales/tl/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/_locales/zh_TW/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions app/scripts/controllers/app-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ export default class AppStateController extends EventEmitter {
recoveryPhraseReminderHasBeenShown: false,
recoveryPhraseReminderLastShown: new Date().getTime(),
outdatedBrowserWarningLastShown: new Date().getTime(),
collectiblesDetectionNoticeDismissed: false,
nftsDetectionNoticeDismissed: false,
showTestnetMessageInDropdown: true,
showPortfolioTooltip: true,
showBetaHeader: isBeta(),
trezorModel: null,
...initState,
qrHardware: {},
collectiblesDropdownState: {},
nftsDropdownState: {},
usedNetworks: {
'0x1': true,
'0x5': true,
Expand Down Expand Up @@ -330,13 +330,13 @@ export default class AppStateController extends EventEmitter {
}

/**
* A setter for the `collectiblesDropdownState` property
* A setter for the `nftsDropdownState` property
*
* @param collectiblesDropdownState
* @param nftsDropdownState
*/
updateCollectibleDropDownState(collectiblesDropdownState) {
updateNftDropDownState(nftsDropdownState) {
this.store.updateState({
collectiblesDropdownState,
nftsDropdownState,
});
}

Expand Down
2 changes: 1 addition & 1 deletion app/scripts/controllers/backup.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function getMockController() {
return mcState;
}

const jsonData = `{"preferences":{"frequentRpcListDetail":[{"chainId":"0x539","nickname":"Localhost 8545","rpcPrefs":{},"rpcUrl":"http://localhost:8545","ticker":"ETH"},{"chainId":"0x38","nickname":"Binance Smart Chain Mainnet","rpcPrefs":{"blockExplorerUrl":"https://bscscan.com"},"rpcUrl":"https://bsc-dataseed1.binance.org","ticker":"BNB"},{"chainId":"0x61","nickname":"Binance Smart Chain Testnet","rpcPrefs":{"blockExplorerUrl":"https://testnet.bscscan.com"},"rpcUrl":"https://data-seed-prebsc-1-s1.binance.org:8545","ticker":"tBNB"},{"chainId":"0x89","nickname":"Polygon Mainnet","rpcPrefs":{"blockExplorerUrl":"https://polygonscan.com"},"rpcUrl":"https://polygon-rpc.com","ticker":"MATIC"}],"useBlockie":false,"useNonceField":false,"usePhishDetect":true,"dismissSeedBackUpReminder":false,"useTokenDetection":false,"useCollectibleDetection":false,"openSeaEnabled":false,"advancedGasFee":null,"featureFlags":{"sendHexData":true,"showIncomingTransactions":true},"knownMethodData":{},"currentLocale":"en","forgottenPassword":false,"preferences":{"hideZeroBalanceTokens":false,"showFiatInTestnets":false,"showTestNetworks":true,"useNativeCurrencyAsPrimaryCurrency":true},"ipfsGateway":"dweb.link","infuraBlocked":false,"ledgerTransportType":"webhid","theme":"light","customNetworkListEnabled":false,"textDirection":"auto"},"addressBook":{"addressBook":{"0x61":{"0x42EB768f2244C8811C63729A21A3569731535f06":{"address":"0x42EB768f2244C8811C63729A21A3569731535f06","chainId":"0x61","isEns":false,"memo":"","name":""}}}}}`;
const jsonData = `{"preferences":{"frequentRpcListDetail":[{"chainId":"0x539","nickname":"Localhost 8545","rpcPrefs":{},"rpcUrl":"http://localhost:8545","ticker":"ETH"},{"chainId":"0x38","nickname":"Binance Smart Chain Mainnet","rpcPrefs":{"blockExplorerUrl":"https://bscscan.com"},"rpcUrl":"https://bsc-dataseed1.binance.org","ticker":"BNB"},{"chainId":"0x61","nickname":"Binance Smart Chain Testnet","rpcPrefs":{"blockExplorerUrl":"https://testnet.bscscan.com"},"rpcUrl":"https://data-seed-prebsc-1-s1.binance.org:8545","ticker":"tBNB"},{"chainId":"0x89","nickname":"Polygon Mainnet","rpcPrefs":{"blockExplorerUrl":"https://polygonscan.com"},"rpcUrl":"https://polygon-rpc.com","ticker":"MATIC"}],"useBlockie":false,"useNonceField":false,"usePhishDetect":true,"dismissSeedBackUpReminder":false,"useTokenDetection":false,"useNftDetection":false,"openSeaEnabled":false,"advancedGasFee":null,"featureFlags":{"sendHexData":true,"showIncomingTransactions":true},"knownMethodData":{},"currentLocale":"en","forgottenPassword":false,"preferences":{"hideZeroBalanceTokens":false,"showFiatInTestnets":false,"showTestNetworks":true,"useNativeCurrencyAsPrimaryCurrency":true},"ipfsGateway":"dweb.link","infuraBlocked":false,"ledgerTransportType":"webhid","theme":"light","customNetworkListEnabled":false,"textDirection":"auto"},"addressBook":{"addressBook":{"0x61":{"0x42EB768f2244C8811C63729A21A3569731535f06":{"address":"0x42EB768f2244C8811C63729A21A3569731535f06","chainId":"0x61","isEns":false,"memo":"","name":""}}}}}`;

describe('BackupController', function () {
const getBackupController = () => {
Expand Down
4 changes: 2 additions & 2 deletions app/scripts/controllers/metametrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@ export default class MetaMetricsController {
}

/**
* Returns an array of all of the collectibles/NFTs the user
* Returns an array of all of the NFTs the user
* possesses across all networks and accounts.
*
* @param {object} allNfts
Expand All @@ -771,7 +771,7 @@ export default class MetaMetricsController {
});

/**
* Returns the number of unique collectible/NFT addresses the user
* Returns the number of unique NFT addresses the user
* possesses across all networks and accounts.
*
* @param {object} allNfts
Expand Down
4 changes: 2 additions & 2 deletions app/scripts/controllers/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ export default class PreferencesController {
/**
* Setter for the `useNftDetection` property
*
* @param {boolean} useNftDetection - Whether or not the user prefers to autodetect collectibles.
* @param {boolean} useNftDetection - Whether or not the user prefers to autodetect NFTs.
*/
setUseNftDetection(useNftDetection) {
this.store.updateState({ useNftDetection });
Expand All @@ -169,7 +169,7 @@ export default class PreferencesController {
/**
* Setter for the `openSeaEnabled` property
*
* @param {boolean} openSeaEnabled - Whether or not the user prefers to use the OpenSea API for collectibles data.
* @param {boolean} openSeaEnabled - Whether or not the user prefers to use the OpenSea API for NFTs data.
*/
setOpenSeaEnabled(openSeaEnabled) {
this.store.updateState({
Expand Down
22 changes: 9 additions & 13 deletions app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -960,8 +960,8 @@ export default class MetamaskController extends EventEmitter {

const { txReceipt } = txMeta;

// if this is a transferFrom method generated from within the app it may be a collectible transfer transaction
// in which case we will want to check and update ownership status of the transferred collectible.
// if this is a transferFrom method generated from within the app it may be an NFT transfer transaction
// in which case we will want to check and update ownership status of the transferred NFT.
if (
txMeta.type === TransactionType.tokenMethodTransferFrom &&
txMeta.txParams !== undefined
Expand All @@ -982,19 +982,17 @@ export default class MetamaskController extends EventEmitter {
const { allNfts } = this.nftController.state;

const chainIdAsDecimal = hexToDecimal(chainId);
// check if its a known collectible
const knownCollectible = allNfts?.[userAddress]?.[
chainIdAsDecimal
]?.find(
// check if its a known NFT
const knownNft = allNfts?.[userAddress]?.[chainIdAsDecimal]?.find(
({ address, tokenId }) =>
isEqualCaseInsensitive(address, contractAddress) &&
tokenId === transactionDataTokenId,
);

// if it is we check and update ownership status.
if (knownCollectible) {
if (knownNft) {
this.nftController.checkAndUpdateSingleNftOwnershipStatus(
knownCollectible,
knownNft,
false,
{ userAddress, chainId: chainIdAsDecimal },
);
Expand Down Expand Up @@ -1904,10 +1902,8 @@ export default class MetamaskController extends EventEmitter {
appStateController.setShowPortfolioTooltip.bind(appStateController),
setShowBetaHeader:
appStateController.setShowBetaHeader.bind(appStateController),
updateCollectibleDropDownState:
appStateController.updateCollectibleDropDownState.bind(
appStateController,
),
updateNftDropDownState:
appStateController.updateNftDropDownState.bind(appStateController),
setFirstTimeUsedNetwork:
appStateController.setFirstTimeUsedNetwork.bind(appStateController),
// EnsController
Expand Down Expand Up @@ -2144,7 +2140,7 @@ export default class MetamaskController extends EventEmitter {
detectTokensController,
),

// DetectCollectibleController
// DetectNftController
detectNfts: process.env.NFTS_V1
? nftDetectionController.detectNfts.bind(nftDetectionController)
: null,
Expand Down
31 changes: 31 additions & 0 deletions app/scripts/migrations/078.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { cloneDeep } from 'lodash';

const version = 78;

/**
* Remove collectiblesDropdownState and collectiblesDetectionNoticeDismissed:.
*/
export default {
version,
async migrate(originalVersionedData) {
const versionedData = cloneDeep(originalVersionedData);
versionedData.meta.version = version;
const state = versionedData.data;
const newState = transformState(state);
versionedData.data = newState;
return versionedData;
},
};

function transformState(state) {
if (
state?.AppStateController?.collectiblesDetectionNoticeDismissed !==
undefined
) {
delete state.AppStateController.collectiblesDetectionNoticeDismissed;
}
if (state?.metamask?.collectiblesDropdownState !== undefined) {
delete state.metamask.collectiblesDropdownState;
}
return state;
}
Loading