Skip to content

Commit

Permalink
Merge pull request #1559 from AmbireTech/fix/unknown-address-warning
Browse files Browse the repository at this point in the history
Fix/unknown address warning error
  • Loading branch information
JIOjosBG authored Feb 16, 2024
2 parents 07e1236 + c1f54b6 commit b450875
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
30 changes: 24 additions & 6 deletions src/components/common/TxnPreview/TxnPreview.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,33 @@ 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 !Array.isArray(summary)
? []
: 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 +139,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 b450875

Please sign in to comment.