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

Add new token added event (duplicating the existing event structure) when collectible is manually added #14279

Merged
merged 6 commits into from
Apr 21, 2022

Conversation

segun
Copy link
Contributor

@segun segun commented Mar 30, 2022

Add new token added event (duplicating the existing event structure) when collectible is manually added

Set source property to custom on the new token added event,

More information

@segun segun requested a review from a team as a code owner March 30, 2022 20:29
@segun segun requested a review from brad-decker March 30, 2022 20:29
@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.

@segun segun self-assigned this Mar 30, 2022
@segun segun marked this pull request as draft March 30, 2022 20:33
event: 'Token Added',
category: 'Wallet',
sensitiveProperties: {
token_symbol: '',
Copy link
Contributor

Choose a reason for hiding this comment

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

best to leave these empty strings as undefined (just omit the properties), segment will strip them anyways.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed here

Copy link
Contributor

Choose a reason for hiding this comment

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

You could add this field back now since some NFTs have a symbol and it is returned by the getTokenStandardAndDetails method that you are using now.

Copy link
Contributor

Choose a reason for hiding this comment

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

cc @segun ☝️

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Somehow missed that....fixed here

Copy link
Contributor

Choose a reason for hiding this comment

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

@segun that commit doesn't see to re-add the token_symbol to the event?

@metamaskbot
Copy link
Collaborator

Builds ready [7b46558]
Page Load Metrics (1445 ± 57 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint75150100209
domContentLoaded12151687143511455
load12151687144511957
domInteractive12151687143511455

Copy link
Contributor

@digiwand digiwand left a comment

Choose a reason for hiding this comment

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

LGTM after updating the code based on what Brad commented

I see that the reused pattern from the codebase has been designed to support more events 👍 Can we get a reference to the related, event tracking pattern you found in the codebase?

@segun segun force-pushed the dev-olu-add-collectible-event-metrics branch from 1fd0762 to 2f959d8 Compare April 4, 2022 17:22
@segun segun marked this pull request as ready for review April 4, 2022 17:22
digiwand
digiwand previously approved these changes Apr 4, 2022
Copy link
Contributor

@digiwand digiwand left a comment

Choose a reason for hiding this comment

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

LGTM! left just a minor suggestion related to lines 95 & 96

sensitiveProperties: {
token_contract_address: newCollectible.address,
tokenId: newCollectible.tokenId,
name: newCollectible.name ? newCollectible.name : null,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
name: newCollectible.name ? newCollectible.name : null,
name: newCollectible.name || null,

nit: we could shorten this. Same comment for the description prop below

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed here

@segun segun force-pushed the dev-olu-add-collectible-event-metrics branch from 221d864 to 64993fa Compare April 5, 2022 08:27
@metamaskbot
Copy link
Collaborator

Builds ready [64993fa]
Page Load Metrics (1315 ± 45 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint7812695136
domContentLoaded1183152512939947
load1197153213159545
domInteractive1183152512939947


const newCollectible = collectibles.find(
(collectible) =>
collectible.address === address &&
Copy link
Contributor

@adonesky1 adonesky1 Apr 5, 2022

Choose a reason for hiding this comment

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

might be worth making this a case-insensitive check until we have thoroughly standardized storing addresses as checksummed across controllers.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed here

}

const alreadyTracked = eventTracked.find(
(et) => et.address === address && et.tracked === true,
Copy link
Contributor

Choose a reason for hiding this comment

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

same 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.

fixed here

@metamaskbot
Copy link
Collaborator

Builds ready [d68dc95]
Page Load Metrics (1324 ± 31 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint7913296115
domContentLoaded1184143713126431
load1198143713246631
domInteractive1184143713126431

digiwand
digiwand previously approved these changes Apr 5, 2022
Copy link
Contributor

@digiwand digiwand left a comment

Choose a reason for hiding this comment

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

Awesome, LGTM!

Good to know about @adonesky1's comment above:

might be worth making this a case-insensitive check until we have thoroughly standardized storing addresses as checksummed across controllers.

now I'm wondering if we want to normalize the addresses here and/or through Segment.
cc: @brad-decker

@segun segun requested review from adonesky1 and brad-decker April 5, 2022 21:20
jpuri
jpuri previously approved these changes Apr 6, 2022

const newCollectible = collectibles.find(
(collectible) =>
collectible.address.toLowerCase() === address.toLowerCase() &&
Copy link
Contributor

Choose a reason for hiding this comment

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

[nit] - you could/should use the isEqualCaseInsensitive util method

Copy link
Contributor

@brad-decker brad-decker left a comment

Choose a reason for hiding this comment

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

potentially blocking question: ... Is this tracking token added when the token is detected or when the token is added to the wallet? :

@@ -46,8 +50,68 @@ export default function AddCollectible() {
);
const [tokenId, setTokenId] = useState('');
const [disabled, setDisabled] = useState(true);
const [eventTracked, setEventTracked] = useState([
{
event: 'Token Added',
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be collectible/NFT added? Sorry I don't have context on the schema we're using, are we somehow indicating that this is an collectible/NFT elsewhere as a subcategory of token?

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 do you agree to change this to "Collectible Added"

Copy link
Contributor

Choose a reason for hiding this comment

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

No we should use the asset_type and token_standard properties that match the transaction events to indicate that this 'Added Token' is a collectible/NFT

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed here

tokenId: newCollectible.tokenId,
name: newCollectible.name || null,
description: newCollectible.description || null,
source: 'detected',
Copy link
Contributor

@adonesky1 adonesky1 Apr 6, 2022

Choose a reason for hiding this comment

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

A couple of broader questions adding to @brad-decker's point.

  1. This is not a "detected" add token event. This is a manually added token.

and

  1. I'm a bit confused about why this track event is being called in a useEffect on the page where the user is adding the collectible. Is the idea that the value of collectibles will change when the user submits the form to add the collectible and this effect will happen before the component dismounts from the history.push event called on line 132 (at the end of the submission handler)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For 2: Yes. I did test this. The useEffect is called before the component dismounts.
For 1: Do we have a "detected" flow for NFTs?

Copy link
Contributor

Choose a reason for hiding this comment

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

oh. interesting. I was also confused by the original request, "when auto detection occurs for NFTs".

The existing patterns for "Token Added" do not live in useEffect hooks. If we were following the pattern used for "Token Added", we could call trackEvent in the same method or callback that adds the token. In this case, could we call track in handleAddCollectible? I'm wondering where you found this pattern original pattern with useEffect

@segun
Copy link
Contributor Author

segun commented Apr 6, 2022

potentially blocking question: ... Is this tracking token added when the token is detected or when the token is added to the wallet? :

It's added when the token is added to the wallet.

@segun segun dismissed stale reviews from jpuri and digiwand via 0e9facd April 6, 2022 18:16
@metamaskbot
Copy link
Collaborator

Builds ready [0e9facd]
Page Load Metrics (1323 ± 31 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint83123100115
domContentLoaded1232147613156431
load1233147613236431
domInteractive1232147613156431

@segun segun force-pushed the dev-olu-add-collectible-event-metrics branch from e7cba3e to cbd6e1a Compare April 7, 2022 10:51
@metamaskbot
Copy link
Collaborator

Builds ready [cbd6e1a]
Page Load Metrics (1288 ± 24 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint831181150237114
domContentLoaded1186138512745426
load1197139512885124
domInteractive1186138512745426

@segun segun changed the title Add new token added event (duplicating the existing event structure) whe collectible is manually added Add new token added event (duplicating the existing event structure) when collectible is manually added Apr 8, 2022
sensitiveProperties: {
token_contract_address: address,
tokenId: tokenId.toString(),
source: 'manual',
Copy link
Contributor

Choose a reason for hiding this comment

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

we're missing properties here. asset_type, token_standard... and source should 'custom' (if this is when the user manually types in all the details of the token)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed here

@@ -47,6 +52,30 @@ export default function AddCollectible() {
const [tokenId, setTokenId] = useState('');
const [disabled, setDisabled] = useState(true);
const [collectibleAddFailed, setCollectibleAddFailed] = useState(false);
const trackEvent = useContext(MetaMetricsContext);

const getCollectibleStandard = async () => {
Copy link
Contributor

@adonesky1 adonesky1 Apr 12, 2022

Choose a reason for hiding this comment

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

There is an existing method getTokenStandardAndDetails on the AssetsContractController that we currently use elsewhere in the extension that could provide the standard as a returned value. It will query for more than just the standard, but perhaps we want to include more data like the asset name when available? cc @brad-decker @kevinghim

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed here

@metamaskbot
Copy link
Collaborator

Builds ready [a82b0a8]
Page Load Metrics (1532 ± 122 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint761142180225108
domContentLoaded114420871509257123
load117120871532255122
domInteractive114420871509257123

highlights:

storybook

address,
selectedAddress,
Copy link
Contributor

Choose a reason for hiding this comment

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

We actually don't need this here since it is not used for non-ERC20 tokens. Its a weird function signature that we will change (to accept an object) but for now you can and should put the second arg as null and no longer need to get the selectedAddress from state.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed here

@adonesky1
Copy link
Contributor

@segun just want to make sure you see my comment here

segun added 6 commits April 15, 2022 20:04
…when auto detection occurs for NFTs

Set source property to detected on the new token added event,

Signed-off-by: Akintayo A. Olusegun <[email protected]>

leave undefined properties undefined (not empty strings)

Signed-off-by: Akintayo A. Olusegun <[email protected]>

Lint fixes

Signed-off-by: Akintayo A. Olusegun <[email protected]>

Shorten checks.

Signed-off-by: Akintayo A. Olusegun <[email protected]>

Case insensitive address comparison

Signed-off-by: Akintayo A. Olusegun <[email protected]>

Use the isEqualCaseInsensitive of string-utils.

Signed-off-by: Akintayo A. Olusegun <[email protected]>

Change event name to Collectible Added and source to manual

Signed-off-by: Akintayo A. Olusegun <[email protected]>

Add collectible on handleAddCollectible.

Signed-off-by: Akintayo A. Olusegun <[email protected]>

Remove un-used code.

Signed-off-by: Akintayo A. Olusegun <[email protected]>

Lint fixes

Signed-off-by: Akintayo A. Olusegun <[email protected]>
Signed-off-by: Akintayo A. Olusegun <[email protected]>
Signed-off-by: Akintayo A. Olusegun <[email protected]>
@segun segun force-pushed the dev-olu-add-collectible-event-metrics branch from b2b69c0 to 2aa736a Compare April 15, 2022 16:04
@metamaskbot
Copy link
Collaborator

Builds ready [2aa736a]
Page Load Metrics (1717 ± 56 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint981981292311
domContentLoaded15051880169311254
load15061967171711656
domInteractive15051880169311254

@adonesky1
Copy link
Contributor

@segun another comment still to address here: #14279 (comment)

tokenId: tokenId.toString(),
asset_type: ASSET_TYPES.COLLECTIBLE,
token_standard: tokenDetails?.standard,
source: 'custom',
Copy link
Contributor

Choose a reason for hiding this comment

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

just a question what does source: 'custom' mean?

Copy link
Contributor

Choose a reason for hiding this comment

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

custom means its added manually. possible options right now are 'custom' | 'dapp' | 'list' | 'detected'

Copy link
Contributor

@adonesky1 adonesky1 left a comment

Choose a reason for hiding this comment

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

On non blocking question but LGTM

Copy link
Contributor

@digiwand digiwand left a comment

Choose a reason for hiding this comment

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

👍 can we update the description too please?

currently, it says:

Set source property to manual on the new token added event

and we've updated the code to set the source to "custom"

@adonesky1
Copy link
Contributor

@brad-decker have your "requested changes" been addressed? Currently this PR is only blocked by that request.

@brad-decker
Copy link
Contributor

me: Welp, this is good to go..why aren't they merging it.
also me: .... 🤦🏻‍♂️

@adonesky1 adonesky1 merged commit 095cc94 into develop Apr 21, 2022
@adonesky1 adonesky1 deleted the dev-olu-add-collectible-event-metrics branch April 21, 2022 18:29
@github-actions github-actions bot locked and limited conversation to collaborators Apr 21, 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.

6 participants