Skip to content

Commit

Permalink
Merge pull request #1530 from AmbireTech/fix/unknown-address-warning
Browse files Browse the repository at this point in the history
Display warning for unknown address in txn summary (humanization)
  • Loading branch information
stojnovsky authored Jan 29, 2024
2 parents 8313edc + 47d9506 commit a2f517b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
28 changes: 22 additions & 6 deletions src/components/common/TxnPreview/TxnPreview.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,31 @@ export default function TxnPreview({
} = useConstants()
const [isExpanded, setExpanded] = useState(false)
const contractName = getName(humanizerInfo, txn[0])
const isUnknown = !isFirstFailing && !mined && !isKnown(humanizerInfo, txn, account)
const isNFTApprovalForAll = (txn.length && !!txn[2])
? txn[2].slice(0, 10) === SIG_HASH_NFT_APPROVAL_FOR_ALL
: null

const isNFTApprovalForAll =
txn.length && !!txn[2] ? txn[2].slice(0, 10) === SIG_HASH_NFT_APPROVAL_FOR_ALL : null

const networkDetails = networks.find(({ id }) => id === network)
const extendedSummary = getTransactionSummary(humanizerInfo, tokenList, txn, network, account, {
mined,
extended: true,
meta
})

const hasUnknownAddress = extendedSummary
.map((summary) => {
return summary
.map((item) => {
if (['address', 'token'].includes(item.type) && item.address) {
return !isKnown(humanizerInfo, item.address, account)
}
return false
})
.includes(true)
})
.includes(true)

const isUnknown = !mined && (!isKnown(humanizerInfo, txn[0], account) || hasUnknownAddress)

useEffect(() => !!addressLabel && setKnownAddressNames(addressLabel), [addressLabel])

return (
Expand Down Expand Up @@ -124,7 +137,10 @@ export default function TxnPreview({
)}
{isNFTApprovalForAll && (
<p className={styles.warning}>
Warning: Be careful while approving this permission, as it will allow access to all NFTs on the contract, including those that you may own in the future. The recipient of this permission can transfer NFTs from your wallet without seeking your permission until you withdraw this authorization. Proceed with caution and stay safe!
Warning: Be careful while approving this permission, as it will allow access to all
NFTs on the contract, including those that you may own in the future. The recipient of
this permission can transfer NFTs from your wallet without seeking your permission
until you withdraw this authorization. Proceed with caution and stay safe!
</p>
)}
</button>
Expand Down
8 changes: 4 additions & 4 deletions src/lib/humanReadableTransactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export function getTransactionSummary(
.filter((sig) => sig.length > 10)
.find((item) => item === `${sigHash}:${to}`)

const humanizer = !!sigHashWithAddress
const humanizer = sigHashWithAddress
? humanizers({ humanizerInfo, tokenList })[sigHashWithAddress]
: humanizers({ humanizerInfo, tokenList })[sigHash]

Expand Down Expand Up @@ -193,10 +193,10 @@ export function setKnownTokens(tokens) {
)
}

export function isKnown(humanizerInfo, txn, from) {
export function isKnown(humanizerInfo, address, from) {
address = address.toLowerCase()
const { tokens, names } = humanizerInfo
if (txn[0] === from) return true
const address = txn[0].toLowerCase()
if (address === from.toLowerCase()) return true
return !!(knownAliases[address] || names[address] || tokens[address] || knownTokens[address])
}

Expand Down

0 comments on commit a2f517b

Please sign in to comment.