Skip to content

Commit 52c1929

Browse files
feat(explorer): add address existence check in getResultsForAddress for names (#8597)
Co-authored-by: Marc Espin <mespinsanz@gmail.com>
1 parent 4c68076 commit 52c1929

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

apps/explorer/src/hooks/useSearch.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,13 @@ const getResultsForAddress = async (
8484

8585
if (!nameRecord || !nameRecord.targetAddress) return null;
8686

87+
const addrHasActivity = await addressHasActivity(client, nameRecord.targetAddress);
88+
8789
return [
8890
{
8991
id: nameRecord.targetAddress,
9092
label: nameRecord.targetAddress,
91-
type: 'address',
93+
type: addrHasActivity ? 'address' : 'object',
9294
},
9395
];
9496
}
@@ -120,6 +122,28 @@ const getResultsForAddress = async (
120122
];
121123
};
122124

125+
async function addressHasActivity(client: IotaClient, address: string): Promise<boolean> {
126+
const normalized = normalizeIotaObjectId(address);
127+
if (!isValidIotaAddress(normalized)) return false;
128+
try {
129+
const fromOrTo = await client.queryTransactionBlocks({
130+
filter: { FromOrToAddress: { addr: normalized } },
131+
limit: 1,
132+
});
133+
if (fromOrTo?.data?.length > 0) return true;
134+
135+
const ownedObjects = await client.getOwnedObjects({
136+
owner: normalized,
137+
limit: 1,
138+
});
139+
if (ownedObjects.data.length > 0) return true;
140+
141+
return false;
142+
} catch (e) {
143+
return false;
144+
}
145+
}
146+
123147
// Query for validator by pool id or iota address.
124148
const getResultsForValidatorByPoolIdOrIotaAddress = async (
125149
systemStateSummary: LatestIotaSystemStateSummary | null,

0 commit comments

Comments
 (0)