Skip to content

Commit

Permalink
Add warning when watchAsset attempts to reuse token symbol
Browse files Browse the repository at this point in the history
  • Loading branch information
danfinlay committed Feb 14, 2020
1 parent 206b208 commit ca95e85
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
3 changes: 3 additions & 0 deletions app/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,9 @@
"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"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export default class ConfirmAddSuggestedToken extends Component {
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">
Expand All @@ -52,6 +53,11 @@ export default class ConfirmAddSuggestedToken extends Component {
{ 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">
Expand Down Expand Up @@ -136,4 +142,21 @@ export default class ConfirmAddSuggestedToken extends Component {
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;
}

}

0 comments on commit ca95e85

Please sign in to comment.