feat: warn when sending to address with zero tx history (#82)
All checks were successful
check / check (push) Successful in 9s
All checks were successful
check / check (push) Successful in 9s
On the confirm-tx screen, asynchronously check the recipient address via Blockscout API. If the address has never sent or received any transactions, display a prominent red warning banner. Closes #82
This commit is contained in:
@@ -251,4 +251,36 @@ function filterTransactions(txs, filters = {}) {
|
||||
return { transactions: filtered, newFraudContracts: newFraud };
|
||||
}
|
||||
|
||||
module.exports = { fetchRecentTransactions, filterTransactions };
|
||||
async function hasTransactionHistory(address, blockscoutUrl) {
|
||||
try {
|
||||
const resp = await debugFetch(blockscoutUrl + "/addresses/" + address);
|
||||
if (!resp.ok) {
|
||||
// If Blockscout returns 404, the address has never been seen on-chain.
|
||||
if (resp.status === 404) return false;
|
||||
log.errorf(
|
||||
"blockscout address check:",
|
||||
resp.status,
|
||||
resp.statusText,
|
||||
);
|
||||
return null; // unknown
|
||||
}
|
||||
const data = await resp.json();
|
||||
// Blockscout v2 address endpoint returns tx counts.
|
||||
// An address with no history may still exist (e.g. received ETH once
|
||||
// but shows 0 outgoing). We check both transactions_count and
|
||||
// token_transfers_count to be thorough.
|
||||
const txCount =
|
||||
(parseInt(data.transactions_count, 10) || 0) +
|
||||
(parseInt(data.token_transfers_count, 10) || 0);
|
||||
return txCount > 0;
|
||||
} catch (e) {
|
||||
log.errorf("hasTransactionHistory error:", e.message);
|
||||
return null; // unknown, don't block the user
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
fetchRecentTransactions,
|
||||
filterTransactions,
|
||||
hasTransactionHistory,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user