Skip to content

Commit 5dd9ccc

Browse files
committed
Fix to return proper error string when public address not found in subgraph
1 parent 6421bdc commit 5dd9ccc

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
@@ -236,6 +236,7 @@ describe('Utilities', () => {
236236
);
237237
});
238238

239+
// prove test failure is related to the ordering of RPC query vs subgraph query, and subgraph URL is not setup
239240
it('throws when looking up an address that has not sent a transaction', async () => {
240241
const address = '0x0000000000000000000000000000000000000002';
241242
const ethersProvider = new StaticJsonRpcProvider(`https://sepolia.infura.io/v3/${INFURA_ID}`); // otherwise throws with unsupported network since we're on localhost

0 commit comments

Comments
 (0)