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

Co-authored-by: Mark Stacey <markjstacey@gmail.com>
feature/default_network_editable
Brad Decker 4 years ago committed by GitHub
parent c4d71a3211
commit daf783a0d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      app/scripts/controllers/preferences.js
  2. 10
      shared/constants/tokens.js
  3. 14
      ui/app/pages/confirm-add-suggested-token/confirm-add-suggested-token.component.js
  4. 19
      ui/app/pages/confirm-add-token/confirm-add-token.component.js
  5. 15
      ui/app/store/actions.js

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

@ -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())

@ -9,6 +9,7 @@ import { ENVIRONMENT_TYPE_NOTIFICATION } from '../../../../app/scripts/lib/enums
export default class ConfirmAddSuggestedToken extends Component { export default class ConfirmAddSuggestedToken extends Component {
static contextTypes = { static contextTypes = {
t: PropTypes.func, t: PropTypes.func,
trackEvent: PropTypes.func,
} }
static propTypes = { static propTypes = {
@ -139,6 +140,19 @@ export default class ConfirmAddSuggestedToken extends Component {
onClick={() => { onClick={() => {
addToken(pendingToken) addToken(pendingToken)
.then(() => removeSuggestedTokens()) .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)) .then(() => history.push(mostRecentOverviewPage))
}} }}
> >

@ -8,6 +8,7 @@ import TokenBalance from '../../components/ui/token-balance'
export default class ConfirmAddToken extends Component { export default class ConfirmAddToken extends Component {
static contextTypes = { static contextTypes = {
t: PropTypes.func, t: PropTypes.func,
trackEvent: PropTypes.func,
} }
static propTypes = { static propTypes = {
@ -103,10 +104,22 @@ export default class ConfirmAddToken extends Component {
className="page-container__footer-button" className="page-container__footer-button"
onClick={() => { onClick={() => {
addTokens(pendingTokens).then(() => { 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() clearPendingTokens()
const firstTokenAddress = Object.values( const firstTokenAddress = pendingTokenValues?.[0].address?.toLowerCase()
pendingTokens,
)?.[0].address?.toLowerCase()
if (firstTokenAddress) { if (firstTokenAddress) {
history.push(`${ASSET_ROUTE}/${firstTokenAddress}`) history.push(`${ASSET_ROUTE}/${firstTokenAddress}`)
} else { } else {

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

Loading…
Cancel
Save