Skip to content

Commit

Permalink
Fix to return proper error string when public address not found in su…
Browse files Browse the repository at this point in the history
…bgraph
  • Loading branch information
jferas committed Jul 11, 2024
1 parent 7fc2c24 commit 798d512
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
26 changes: 15 additions & 11 deletions umbra-js/src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,19 +329,23 @@ export async function getMostRecentSubgraphStealthKeyChangedEventFromAddress(
chainConfig
);
let theEvent: SubgraphStealthKeyChangedEvent | undefined;
for await (const event of stealthKeyChangedEvents) {
for (let i = 0; i < event.length; i++) {
if (theEvent) {
console.log(
`We found a previous StealthKeyChangedEvent for address ${address} in the subgraph at block ${event[i].block} with transaction hash ${event[i].txHash}`
);
} else {
theEvent = event[i];
console.log(
`We found a StealthKeyChangedEvent for address ${address} in the subgraph at block ${event[i].block} with transaction hash ${event[i].txHash}`
);
try {
for await (const event of stealthKeyChangedEvents) {
for (let i = 0; i < event.length; i++) {
if (theEvent) {
console.log(
`We found a previous StealthKeyChangedEvent for address ${address} in the subgraph at block ${event[i].block} with transaction hash ${event[i].txHash}`
);
} else {
theEvent = event[i];
console.log(
`We found a StealthKeyChangedEvent for address ${address} in the subgraph at block ${event[i].block} with transaction hash ${event[i].txHash}`
);
}
}
}
} catch (error) {
throw new Error(`Address ${address} has not registered stealth keys. Please ask them to setup their Umbra account`); // prettier-ignore
}

if (!theEvent) {
Expand Down
1 change: 1 addition & 0 deletions umbra-js/test/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ describe('Utilities', () => {
);
});

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

0 comments on commit 798d512

Please sign in to comment.