You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add error handling to SRC20 Search (SRC20Search.tsx) for:
CPID
address
tx hash
The error handling code from StampSearch.tsx should be able to work for token search as well.
CPID search kicks in if a/A+5chars (6chars total) so that should not conflict with search for tokens starting with A (5chars total).
I'm unsure how the SRC20 autosuggest vs StampSearch's EnterSearch will work with the error handling/messages...
StampSearch.tsx - line 38-145 ↓
const validateBitcoinAddress = async (address: string) => {
// First check format
const isValidFormat = /^(bc1|[13])[a-zA-HJ-NP-Z0-9]{25,62}$/.test(address);
if (!isValidFormat) return false;
try {
const response = await fetch(
`https://blockchain.info/rawaddr/${address}`,
);
if (!response.ok) return false;
const data = await response.json();
return data.n_tx > 0;
} catch (error) {
console.log("Stamp Search Error=========>", error);
return false;
}
};
const validateBitcoinTx = async (txHash: string) => {
try {
const response = await fetch(`https://blockchain.info/rawtx/${txHash}`);
if (!response.ok) return false;
const data = await response.json();
// Check if response has basic tx properties
return !!(data && data.hash && data.ver);
} catch (error) {
console.log("Stamp Search Error=========>", error);
return false;
}
};
// Helper function to validate if string contains only hex chars
const isHexString = (str: string): boolean => {
return /^[a-fA-F0-9]+$/.test(str);
};
const handleSearch = async () => {
const query = searchTerm.trim();
if (!query) return;
try {
setError("");
// Handle potential tx hash (any hex string > 16 chars that's not a CPID)
if (isHexString(query) && query.length > 16 && !query.startsWith("A")) {
// Check format and blockchain validity
if (query.length !== 64 || !(await validateBitcoinTx(query))) {
setError(
`NO TRANSACTION FOUND\n${query}\nThe transaction hash isn't valid`,
);
return;
}
try {
const stampResponse = await fetch(`/api/v2/stamps/${query}`);
const responseData = await stampResponse.json();
if (
stampResponse.ok && responseData.data && responseData.data.stamp
) {
globalThis.location.href = `/stamp/${query}`;
return;
}
} catch (error) {
console.log("Stamp Search Error=========>", error);
}
// Not a stamp but valid tx - open blockchain explorer
globalThis.open(
`https://www.blockchain.com/explorer/transactions/btc/${query}`,
"_blank",
);
return;
}
// Check for Bitcoin address formats
if (/^(bc1|[13])[a-zA-HJ-NP-Z0-9]{25,62}$/.test(query)) {
const isValidAndActive = await validateBitcoinAddress(query);
if (isValidAndActive) {
globalThis.location.href = `/wallet/${query}`;
return;
}
setError(
`NO ADDY FOUND\n${query}\nThe Bitcoin address doesn't seem to exist`,
);
return;
}
// Check for CPID format (starts with 'A' or 'a' followed by at least 5 numeric chars)
if (/^[Aa]\d{5,}$/.test(query)) {
try {
const response = await fetch(`/api/v2/stamps/${query.toUpperCase()}`);
const responseData = await response.json();
if (response.ok && responseData.data && responseData.data.stamp) {
globalThis.location.href = `/stamp/${query.toUpperCase()}`;
return;
}
} catch (error) {
console.log("Stamp Search Error=========>", error);
}
setError(
`NO STAMP FOUND\n${query}\nThe CPID doesn't seem to be valid`,
);
return;
}
The text was updated successfully, but these errors were encountered:
Add error handling to SRC20 Search (SRC20Search.tsx) for:
The error handling code from StampSearch.tsx should be able to work for token search as well.
CPID search kicks in if a/A+5chars (6chars total) so that should not conflict with search for tokens starting with A (5chars total).
I'm unsure how the SRC20 autosuggest vs StampSearch's EnterSearch will work with the error handling/messages...
StampSearch.tsx - line 38-145 ↓
The text was updated successfully, but these errors were encountered: