1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-10-22 11:22:43 +02:00

Track a new schema event when adding a token (#9810)

Co-authored-by: Mark Stacey <markjstacey@gmail.com>
This commit is contained in:
Brad Decker 2020-11-17 11:39:21 -06:00 committed by GitHub
parent c4d71a3211
commit daf783a0d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 62 additions and 5 deletions

View File

@ -5,6 +5,7 @@ import { isValidAddress, sha3, bufferToHex } from 'ethereumjs-util'
import ethers from 'ethers'
import log from 'loglevel'
import { isPrefixedFormattedHexString } from '../lib/util'
import { LISTED_CONTRACT_ADDRESSES } from '../../../shared/constants/tokens'
import { addInternalMethodPrefix } from './permissions'
import { NETWORK_TYPE_TO_ID_MAP } from './network/enums'
@ -175,7 +176,13 @@ export default class PreferencesController {
const suggested = this.getSuggestedTokens()
const { rawAddress, symbol, decimals, image } = tokenOpts
const address = normalizeAddress(rawAddress)
const newEntry = { address, symbol, decimals, image }
const newEntry = {
address,
symbol,
decimals,
image,
unlisted: !LISTED_CONTRACT_ADDRESSES.includes(address.toLowerCase()),
}
suggested[address] = newEntry
this.store.updateState({ suggestedTokens: suggested })
}

View File

@ -0,0 +1,10 @@
import contractMap from 'eth-contract-metadata'
/**
* A normalized list of addresses exported as part of the contractMap in
* eth-contract-metadata. Used primarily to validate if manually entered
* contract addresses do not match one of our listed tokens
*/
export const LISTED_CONTRACT_ADDRESSES = Object.keys(
contractMap,
).map((address) => address.toLowerCase())

View File

@ -9,6 +9,7 @@ import { ENVIRONMENT_TYPE_NOTIFICATION } from '../../../../app/scripts/lib/enums
export default class ConfirmAddSuggestedToken extends Component {
static contextTypes = {
t: PropTypes.func,
trackEvent: PropTypes.func,
}
static propTypes = {
@ -139,6 +140,19 @@ export default class ConfirmAddSuggestedToken extends Component {
onClick={() => {
addToken(pendingToken)
.then(() => removeSuggestedTokens())
.then(() => {
this.context.trackEvent({
event: 'Token Added',
category: 'Wallet',
sensitiveProperties: {
token_symbol: pendingToken.symbol,
token_contract_address: pendingToken.address,
token_decimal_precision: pendingToken.decimals,
unlisted: pendingToken.unlisted,
source: 'dapp',
},
})
})
.then(() => history.push(mostRecentOverviewPage))
}}
>

View File

@ -8,6 +8,7 @@ import TokenBalance from '../../components/ui/token-balance'
export default class ConfirmAddToken extends Component {
static contextTypes = {
t: PropTypes.func,
trackEvent: PropTypes.func,
}
static propTypes = {
@ -103,10 +104,22 @@ export default class ConfirmAddToken extends Component {
className="page-container__footer-button"
onClick={() => {
addTokens(pendingTokens).then(() => {
const pendingTokenValues = Object.values(pendingTokens)
pendingTokenValues.forEach((pendingToken) => {
this.context.trackEvent({
event: 'Token Added',
category: 'Wallet',
sensitiveProperties: {
token_symbol: pendingToken.symbol,
token_contract_address: pendingToken.address,
token_decimal_precision: pendingToken.decimals,
unlisted: pendingToken.unlisted,
source: pendingToken.isCustom ? 'custom' : 'list',
},
})
})
clearPendingTokens()
const firstTokenAddress = Object.values(
pendingTokens,
)?.[0].address?.toLowerCase()
const firstTokenAddress = pendingTokenValues?.[0].address?.toLowerCase()
if (firstTokenAddress) {
history.push(`${ASSET_ROUTE}/${firstTokenAddress}`)
} else {

View File

@ -23,6 +23,7 @@ import {
} from '../selectors'
import { switchedToUnconnectedAccount } from '../ducks/alerts/unconnected-account'
import { getUnconnectedAccountAlertEnabledness } from '../ducks/metamask/metamask'
import { LISTED_CONTRACT_ADDRESSES } from '../../../shared/constants/tokens'
import * as actionConstants from './actionConstants'
let background = null
@ -2210,9 +2211,21 @@ export function setPendingTokens(pendingTokens) {
const { address, symbol, decimals } = customToken
const tokens =
address && symbol && decimals
? { ...selectedTokens, [address]: { ...customToken, isCustom: true } }
? {
...selectedTokens,
[address]: {
...customToken,
isCustom: true,
},
}
: selectedTokens
Object.keys(tokens).forEach((tokenAddress) => {
tokens[tokenAddress].unlisted = !LISTED_CONTRACT_ADDRESSES.includes(
tokenAddress.toLowerCase(),
)
})
return {
type: actionConstants.SET_PENDING_TOKENS,
payload: tokens,