-
Notifications
You must be signed in to change notification settings - Fork 5k
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
Conversation
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. |
event: 'Token Added', | ||
category: 'Wallet', | ||
sensitiveProperties: { | ||
token_symbol: '', |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed here
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @segun ☝️
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
Builds ready [7b46558]Page Load Metrics (1445 ± 57 ms)
|
There was a problem hiding this 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?
1fd0762
to
2f959d8
Compare
There was a problem hiding this 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, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
name: newCollectible.name ? newCollectible.name : null, | |
name: newCollectible.name || null, |
nit: we could shorten this. Same comment for the description
prop below
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed here
221d864
to
64993fa
Compare
Builds ready [64993fa]Page Load Metrics (1315 ± 45 ms)
|
|
||
const newCollectible = collectibles.find( | ||
(collectible) => | ||
collectible.address === address && |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed here
Builds ready [d68dc95]Page Load Metrics (1324 ± 31 ms)
|
There was a problem hiding this 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
|
||
const newCollectible = collectibles.find( | ||
(collectible) => | ||
collectible.address.toLowerCase() === address.toLowerCase() && |
There was a problem hiding this comment.
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
There was a problem hiding this 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', |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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"
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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', |
There was a problem hiding this comment.
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.
- This is not a "detected" add token event. This is a manually added token.
and
- 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 ofcollectibles
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)?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
It's added when the token is added to the wallet. |
Builds ready [0e9facd]Page Load Metrics (1323 ± 31 ms)
|
e7cba3e
to
cbd6e1a
Compare
Builds ready [cbd6e1a]Page Load Metrics (1288 ± 24 ms)
|
sensitiveProperties: { | ||
token_contract_address: address, | ||
tokenId: tokenId.toString(), | ||
source: 'manual', |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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 () => { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed here
address, | ||
selectedAddress, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed here
…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]>
Signed-off-by: Akintayo A. Olusegun <[email protected]>
Signed-off-by: Akintayo A. Olusegun <[email protected]>
Signed-off-by: Akintayo A. Olusegun <[email protected]>
b2b69c0
to
2aa736a
Compare
Builds ready [2aa736a]Page Load Metrics (1717 ± 56 ms)
|
@segun another comment still to address here: #14279 (comment) |
tokenId: tokenId.toString(), | ||
asset_type: ASSET_TYPES.COLLECTIBLE, | ||
token_standard: tokenDetails?.standard, | ||
source: 'custom', |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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'
There was a problem hiding this 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
There was a problem hiding this 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"
@brad-decker have your "requested changes" been addressed? Currently this PR is only blocked by that request. |
me: Welp, this is good to go..why aren't they merging it. |
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