mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Add warning to watchAsset API when editing a known token (#8049)
* Add warning when editing a known token with watchAsset API * Add warning when watchAsset attempts to reuse token symbol
This commit is contained in:
parent
39d944fd27
commit
bca4594f0a
@ -715,6 +715,12 @@
|
||||
"knownAddressRecipient": {
|
||||
"message": "Known contract address."
|
||||
},
|
||||
"knownTokenWarning": {
|
||||
"message": "This action will edit tokens that are already listed in your wallet, which can be used to phish you. Only approve if you are certain that you mean to change what these tokens represent."
|
||||
},
|
||||
"reusedTokenNameWarning": {
|
||||
"message": "A token here reuses a symbol from another token you watch, this can be confusing or deceptive."
|
||||
},
|
||||
"invalidAddressRecipientNotEthNetwork": {
|
||||
"message": "Not ETH network, set to lowercase"
|
||||
},
|
||||
|
@ -16,6 +16,7 @@ export default class ConfirmAddSuggestedToken extends Component {
|
||||
addToken: PropTypes.func,
|
||||
pendingTokens: PropTypes.object,
|
||||
removeSuggestedTokens: PropTypes.func,
|
||||
tokens: PropTypes.array,
|
||||
}
|
||||
|
||||
componentDidMount () {
|
||||
@ -33,9 +34,11 @@ export default class ConfirmAddSuggestedToken extends Component {
|
||||
}
|
||||
|
||||
render () {
|
||||
const { addToken, pendingTokens, removeSuggestedTokens, history } = this.props
|
||||
const { addToken, pendingTokens, tokens, removeSuggestedTokens, history } = this.props
|
||||
const pendingTokenKey = Object.keys(pendingTokens)[0]
|
||||
const pendingToken = pendingTokens[pendingTokenKey]
|
||||
const hasTokenDuplicates = this.checkTokenDuplicates(pendingTokens, tokens)
|
||||
const reusesName = this.checkNameReuse(pendingTokens, tokens)
|
||||
|
||||
return (
|
||||
<div className="page-container">
|
||||
@ -46,6 +49,20 @@ export default class ConfirmAddSuggestedToken extends Component {
|
||||
<div className="page-container__subtitle">
|
||||
{ this.context.t('likeToAddTokens') }
|
||||
</div>
|
||||
{ hasTokenDuplicates ?
|
||||
(
|
||||
<div className="warning">
|
||||
{ this.context.t('knownTokenWarning') }
|
||||
</div>
|
||||
) : null
|
||||
}
|
||||
{ reusesName ?
|
||||
(
|
||||
<div className="warning">
|
||||
{ this.context.t('reusedTokenNameWarning') }
|
||||
</div>
|
||||
) : null
|
||||
}
|
||||
</div>
|
||||
<div className="page-container__content">
|
||||
<div className="confirm-add-token">
|
||||
@ -119,4 +136,32 @@ export default class ConfirmAddSuggestedToken extends Component {
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
checkTokenDuplicates (pendingTokens, tokens) {
|
||||
const pending = Object.keys(pendingTokens)
|
||||
const existing = tokens.map(token => token.address)
|
||||
const dupes = pending.filter((proposed) => {
|
||||
return existing.includes(proposed)
|
||||
})
|
||||
|
||||
return dupes.length > 0
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if any pendingTokens both:
|
||||
* - Share a symbol with an existing `tokens` member.
|
||||
* - Does not share an address with that same `tokens` member.
|
||||
* This should be flagged as possibly deceptive or confusing.
|
||||
*/
|
||||
checkNameReuse (pendingTokens, tokens) {
|
||||
const duplicates = Object.keys(pendingTokens)
|
||||
.map((addr) => pendingTokens[addr])
|
||||
.filter((token) => {
|
||||
const dupes = tokens.filter(old => old.symbol === token.symbol)
|
||||
.filter(old => old.address !== token.address)
|
||||
return dupes.length > 0
|
||||
})
|
||||
return duplicates.length > 0
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -8,11 +8,12 @@ const extend = require('xtend')
|
||||
const { addToken, removeSuggestedTokens } = require('../../store/actions')
|
||||
|
||||
const mapStateToProps = ({ metamask }) => {
|
||||
const { pendingTokens, suggestedTokens } = metamask
|
||||
const { pendingTokens, suggestedTokens, tokens } = metamask
|
||||
const params = extend(pendingTokens, suggestedTokens)
|
||||
|
||||
return {
|
||||
pendingTokens: params,
|
||||
tokens,
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user