Skip to content

Commit

Permalink
Merge branch 'develop' into beta-long-logo
Browse files Browse the repository at this point in the history
  • Loading branch information
darkwing authored Nov 16, 2022
2 parents 0e1fe6f + a9085a8 commit 9099c10
Show file tree
Hide file tree
Showing 77 changed files with 1,695 additions and 560 deletions.
1 change: 1 addition & 0 deletions .browserslistrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
chrome >= 66, firefox >= 68
4 changes: 2 additions & 2 deletions .storybook/initial-states/transactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1454,7 +1454,7 @@ export const MOCK_TRANSACTION_BY_TYPE = {
dappSuggestedGasFees: null,
sendFlowHistory: [
{
entry: 'sendFlow - user set asset type to COLLECTIBLE',
entry: 'sendFlow - user set asset type to NFT',
timestamp: 1653457317999,
},
{
Expand Down Expand Up @@ -1504,7 +1504,7 @@ export const MOCK_TRANSACTION_BY_TYPE = {
dappSuggestedGasFees: null,
sendFlowHistory: [
{
entry: 'sendFlow - user set asset type to COLLECTIBLE',
entry: 'sendFlow - user set asset type to NFT',
timestamp: 1653457317999,
},
{
Expand Down
9 changes: 9 additions & 0 deletions app/_locales/en/messages.json

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

35 changes: 18 additions & 17 deletions app/scripts/controllers/metametrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ const exceptionsToFilter = {
* @property {Array} [eventsBeforeMetricsOptIn] - Array of queued events added before
* a user opts into metrics.
* @property {object} [traits] - Traits that are not derived from other state keys.
* @property {Record<string any>} [previousUserTraits] - The user traits the last
* time they were computed.
*/

export default class MetaMetricsController {
Expand Down Expand Up @@ -685,7 +687,7 @@ export default class MetaMetricsController {
* @returns {MetaMetricsTraits | null} traits that have changed since last update
*/
_buildUserTraitsObject(metamaskState) {
const { traits } = this.store.getState();
const { traits, previousUserTraits } = this.store.getState();
/** @type {MetaMetricsTraits} */
const currentTraits = {
[TRAITS.ADDRESS_BOOK_ENTRIES]: sum(
Expand All @@ -706,33 +708,32 @@ export default class MetaMetricsController {
},
[],
),
[TRAITS.NFT_AUTODETECTION_ENABLED]: metamaskState.useCollectibleDetection,
[TRAITS.NFT_AUTODETECTION_ENABLED]: metamaskState.useNftDetection,
[TRAITS.NUMBER_OF_ACCOUNTS]: Object.values(metamaskState.identities)
.length,
[TRAITS.NUMBER_OF_NFT_COLLECTIONS]: this._getAllUniqueNFTAddressesLength(
metamaskState.allCollectibles,
metamaskState.allNfts,
),
[TRAITS.NUMBER_OF_NFTS]: this._getAllNFTsFlattened(
metamaskState.allCollectibles,
).length,
[TRAITS.NUMBER_OF_NFTS]: this._getAllNFTsFlattened(metamaskState.allNfts)
.length,
[TRAITS.NUMBER_OF_TOKENS]: this._getNumberOfTokens(metamaskState),
[TRAITS.OPENSEA_API_ENABLED]: metamaskState.openSeaEnabled,
[TRAITS.THREE_BOX_ENABLED]: false, // deprecated, hard-coded as false
[TRAITS.THEME]: metamaskState.theme || 'default',
[TRAITS.TOKEN_DETECTION_ENABLED]: metamaskState.useTokenDetection,
};

if (!this.previousTraits) {
this.previousTraits = currentTraits;
if (!previousUserTraits) {
this.store.updateState({ previousUserTraits: currentTraits });
return currentTraits;
}

if (this.previousTraits && !isEqual(this.previousTraits, currentTraits)) {
if (previousUserTraits && !isEqual(previousUserTraits, currentTraits)) {
const updates = pickBy(
currentTraits,
(v, k) => !isEqual(this.previousTraits[k], v),
(v, k) => !isEqual(previousUserTraits[k], v),
);
this.previousTraits = currentTraits;
this.store.updateState({ previousUserTraits: currentTraits });
return updates;
}

Expand Down Expand Up @@ -765,11 +766,11 @@ export default class MetaMetricsController {
* Returns an array of all of the collectibles/NFTs the user
* possesses across all networks and accounts.
*
* @param {object} allCollectibles
* @param {object} allNfts
* @returns {[]}
*/
_getAllNFTsFlattened = memoize((allCollectibles = {}) => {
return Object.values(allCollectibles).reduce((result, chainNFTs) => {
_getAllNFTsFlattened = memoize((allNfts = {}) => {
return Object.values(allNfts).reduce((result, chainNFTs) => {
return result.concat(...Object.values(chainNFTs));
}, []);
});
Expand All @@ -778,11 +779,11 @@ export default class MetaMetricsController {
* Returns the number of unique collectible/NFT addresses the user
* possesses across all networks and accounts.
*
* @param {object} allCollectibles
* @param {object} allNfts
* @returns {number}
*/
_getAllUniqueNFTAddressesLength(allCollectibles = {}) {
const allNFTAddresses = this._getAllNFTsFlattened(allCollectibles).map(
_getAllUniqueNFTAddressesLength(allNfts = {}) {
const allNFTAddresses = this._getAllNFTsFlattened(allNfts).map(
(nft) => nft.address,
);
const uniqueAddresses = new Set(allNFTAddresses);
Expand Down
12 changes: 6 additions & 6 deletions app/scripts/controllers/metametrics.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ describe('MetaMetricsController', function () {
[CHAIN_IDS.MAINNET]: [{ address: '0x' }],
[CHAIN_IDS.GOERLI]: [{ address: '0x' }, { address: '0x0' }],
},
allCollectibles: {
allNfts: {
'0xac706cE8A9BF27Afecf080fB298d0ee13cfb978A': {
56: [
{
Expand Down Expand Up @@ -752,7 +752,7 @@ describe('MetaMetricsController', function () {
identities: [{}, {}],
ledgerTransportType: 'web-hid',
openSeaEnabled: true,
useCollectibleDetection: false,
useNftDetection: false,
theme: 'default',
useTokenDetection: true,
});
Expand Down Expand Up @@ -790,7 +790,7 @@ describe('MetaMetricsController', function () {
ledgerTransportType: 'web-hid',
openSeaEnabled: true,
identities: [{}, {}],
useCollectibleDetection: false,
useNftDetection: false,
theme: 'default',
useTokenDetection: true,
});
Expand All @@ -810,7 +810,7 @@ describe('MetaMetricsController', function () {
ledgerTransportType: 'web-hid',
openSeaEnabled: false,
identities: [{}, {}, {}],
useCollectibleDetection: false,
useNftDetection: false,
theme: 'default',
useTokenDetection: true,
});
Expand Down Expand Up @@ -838,7 +838,7 @@ describe('MetaMetricsController', function () {
ledgerTransportType: 'web-hid',
openSeaEnabled: true,
identities: [{}, {}],
useCollectibleDetection: true,
useNftDetection: true,
theme: 'default',
useTokenDetection: true,
});
Expand All @@ -856,7 +856,7 @@ describe('MetaMetricsController', function () {
ledgerTransportType: 'web-hid',
openSeaEnabled: true,
identities: [{}, {}],
useCollectibleDetection: true,
useNftDetection: true,
theme: 'default',
useTokenDetection: true,
});
Expand Down
10 changes: 5 additions & 5 deletions app/scripts/controllers/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default class PreferencesController {
// set to true means the dynamic list from the API is being used
// set to false will be using the static list from contract-metadata
useTokenDetection: false,
useCollectibleDetection: false,
useNftDetection: false,
openSeaEnabled: false,
advancedGasFee: null,

Expand Down Expand Up @@ -142,12 +142,12 @@ export default class PreferencesController {
}

/**
* Setter for the `useCollectibleDetection` property
* Setter for the `useNftDetection` property
*
* @param {boolean} useCollectibleDetection - Whether or not the user prefers to autodetect collectibles.
* @param {boolean} useNftDetection - Whether or not the user prefers to autodetect collectibles.
*/
setUseCollectibleDetection(useCollectibleDetection) {
this.store.updateState({ useCollectibleDetection });
setUseNftDetection(useNftDetection) {
this.store.updateState({ useNftDetection });
}

/**
Expand Down
12 changes: 6 additions & 6 deletions app/scripts/controllers/preferences.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,21 +308,21 @@ describe('preferences controller', function () {
});
});

describe('setUseCollectibleDetection', function () {
describe('setUseNftDetection', function () {
it('should default to false', function () {
const state = preferencesController.store.getState();
assert.equal(state.useCollectibleDetection, false);
assert.equal(state.useNftDetection, false);
});

it('should set the useCollectibleDetection property in state', function () {
it('should set the useNftDetection property in state', function () {
assert.equal(
preferencesController.store.getState().useCollectibleDetection,
preferencesController.store.getState().useNftDetection,
false,
);
preferencesController.setOpenSeaEnabled(true);
preferencesController.setUseCollectibleDetection(true);
preferencesController.setUseNftDetection(true);
assert.equal(
preferencesController.store.getState().useCollectibleDetection,
preferencesController.store.getState().useNftDetection,
true,
);
});
Expand Down
Loading

0 comments on commit 9099c10

Please sign in to comment.