Skip to content
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

V7.7.5 Upstream Changes #124

Merged
merged 12 commits into from Feb 25, 2020

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
  • Loading branch information
danfinlay authored and ryanml committed Feb 14, 2020
commit 385b2ba4afbf19f403f4fe94588d8d6ed6b690c6
@@ -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,
}
}

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.