Skip to content
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

MetaMetrics: Identify 'number_of_tokens' user trait #14427

Merged
merged 5 commits into from
Apr 15, 2022

Conversation

digiwand
Copy link
Contributor

Explanation

Add two new user traits to Segment:

number_of_tokens - Number of Tokens

Note: We want the count of all of the tokens across all of the chains as mentioned by @brad-decker here: #14421 (comment)

More information

Progresses #13477

@digiwand digiwand requested a review from a team as a code owner April 12, 2022 15:14
@digiwand digiwand requested review from georgewrmarshall, brad-decker and segun and removed request for a team April 12, 2022 15:14
@github-actions
Copy link
Contributor

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

Comment on lines 613 to 627
_getNumberOfTokens(metamaskState) {
const allUniqueAddresses = Object.values(metamaskState.allTokens).reduce(
(result, tokensByAccountByChain) => {
Object.values(tokensByAccountByChain).forEach((tokensByAccount) => {
tokensByAccount.forEach((token) => {
result.add(token.address);
});
});

return result;
},
new Set(),
);

return allUniqueAddresses.size;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its not necessary to do a unique check here, The addresses represent contracts, even if a token manages to have the same address on many different networks (possible, I think, but difficult) the user would have different balances on each chain effectively making them different tokens. It's also possible for two different tokens to have the same address on different chains.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😮 Thank you for the catch and for explaining this. Maybe there is a guide I can read to help me better understand the structure of token contracts

Updating the code to not do the unique filter here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brad-decker updated here: 0bd0772

);

return allUniqueAddresses.size;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I got this right... "tokensByAccountByChain" is what I presumed from looking through the TokensController and the data produced. Please double-check me here 🙏

I am also wondering two other things:

  1. How large could the data set get, and would it be worth it to use lodash memoize?
  2. May we want to move this logic into the TokensController someday?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brad-decker Thoughts here? I'm not familiar enough with this controller to answer these questions.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. memoizing functions might be worth while, but that can happen down the road. We should discuss the proper level of memoization (should we memoize the entire build user trait function, only portions of the traits, etc)
  2. No, although it seems like we will end up with a bunch of methods related to other parts of state, they are building user traits which is specific to meta metrics. I feel all user traits should be built and established inside the metametrics controller regardless of where in state they come from

Copy link
Contributor Author

@digiwand digiwand Apr 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brad-decker

Thank you for the thoughts!

  1. 👍
  2. I thought, maybe, the total number of tokens could be shown in other places. Thanks for confirming that this method wouldn't be desirable in the TokenController. I am all for keeping the user trait logic inside the MetaMetrics controller

@metamaskbot
Copy link
Collaborator

Builds ready [2447399]
Page Load Metrics (1270 ± 41 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint811129094
domContentLoaded1172141512546230
load1172154312708641
domInteractive1172141512546230

@metamaskbot
Copy link
Collaborator

Builds ready [0bd0772]
Page Load Metrics (1252 ± 47 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint773761046431
domContentLoaded1152151112388340
load1152151112529747
domInteractive1152151112388340

brad-decker
brad-decker previously approved these changes Apr 13, 2022
Base automatically changed from metametrics-identify-nft-autodetection-enabled-and-count to develop April 15, 2022 13:39
do not filter by unique addresses.
Each token contract x chain id combo is a unique contract
@digiwand digiwand force-pushed the metametrics/identify-number-of-tokens branch from 5be5191 to 1227724 Compare April 15, 2022 13:55
@digiwand
Copy link
Contributor Author

There was a moment I forgot this branch was branching off #14367. After I force pushed on #14367, I had duplicate commits that I had to clean up. I force pushed a new version. There have been no changes in logic in the last couple of days; cc: @brad-decker

@metamaskbot
Copy link
Collaborator

Builds ready [76cdece]
Page Load Metrics (1378 ± 55 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint811364166275132
domContentLoaded12171669137011756
load12241669137811455
domInteractive12171669137011756

@digiwand digiwand merged commit 21e54f4 into develop Apr 15, 2022
@digiwand digiwand deleted the metametrics/identify-number-of-tokens branch April 15, 2022 16:35
@github-actions github-actions bot locked and limited conversation to collaborators Apr 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants