Skip to content

Commit 8708597

Browse files
committed
Fix to return proper error string when public address not found in subgraph
1 parent 2d13d19 commit 8708597

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

umbra-js/src/utils/utils.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -329,19 +329,23 @@ export async function getMostRecentSubgraphStealthKeyChangedEventFromAddress(
329329
chainConfig
330330
);
331331
let theEvent: SubgraphStealthKeyChangedEvent | undefined;
332-
for await (const event of stealthKeyChangedEvents) {
333-
for (let i = 0; i < event.length; i++) {
334-
if (theEvent) {
335-
console.log(
336-
`We found a previous StealthKeyChangedEvent for address ${address} in the subgraph at block ${event[i].block} with transaction hash ${event[i].txHash}`
337-
);
338-
} else {
339-
theEvent = event[i];
340-
console.log(
341-
`We found a StealthKeyChangedEvent for address ${address} in the subgraph at block ${event[i].block} with transaction hash ${event[i].txHash}`
342-
);
332+
try {
333+
for await (const event of stealthKeyChangedEvents) {
334+
for (let i = 0; i < event.length; i++) {
335+
if (theEvent) {
336+
console.log(
337+
`We found a previous StealthKeyChangedEvent for address ${address} in the subgraph at block ${event[i].block} with transaction hash ${event[i].txHash}`
338+
);
339+
} else {
340+
theEvent = event[i];
341+
console.log(
342+
`We found a StealthKeyChangedEvent for address ${address} in the subgraph at block ${event[i].block} with transaction hash ${event[i].txHash}`
343+
);
344+
}
343345
}
344346
}
347+
} catch (error) {
348+
throw new Error(`Address ${address} has not registered stealth keys. Please ask them to setup their Umbra account`); // prettier-ignore
345349
}
346350

347351
if (!theEvent) {

umbra-js/test/utils.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ describe('Utilities', () => {
242242
);
243243
});
244244

245+
// prove test failure is related to the ordering of RPC query vs subgraph query, and subgraph URL is not setup
245246
it('throws when looking up an address that has not sent a transaction', async () => {
246247
const address = '0x0000000000000000000000000000000000000002';
247248
const ethersProvider = new StaticJsonRpcProvider(SEPOLIA_RPC_URL); // otherwise throws with unsupported network since we're on localhost

0 commit comments

Comments
 (0)