mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Track a new schema event when adding a token (#9810)
Co-authored-by: Mark Stacey <markjstacey@gmail.com>
This commit is contained in:
parent
c4d71a3211
commit
daf783a0d8
@ -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 })
|
||||
}
|
||||
|
10
shared/constants/tokens.js
Normal file
10
shared/constants/tokens.js
Normal 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())
|
@ -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))
|
||||
}}
|
||||
>
|
||||
|
@ -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 {
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user