@@ -44,18 +44,29 @@ export default function useRekeyDateStore() {
4444 },
4545 });
4646
47− if (logs.length === 0) {
48− //TODO: better encoding for "no rekeyDate" state?
49− addToRekeyDateCache({
50− [point]: Just(Result.Error('No rekey date available.')),
51− });
52− } else {
47+ // NB(shrugs) using try-catch here to simplify our error handling
48+ try {
49+ if (logs.length === 0) {
50+ throw new Error('No logs available.');
51+ }
52+
5353 // last log is most recent
5454 const blockNumber = logs[logs.length - 1].blockNumber;
55+ if (blockNumber === null) {
56+ // the "latest" parameter includes pending blocks,
57+ // which won't have a blockNumber just yet
58+ throw new Error('Latest rekey is still pending');
59+ }
60+
5561 const block = await _web3.eth.getBlock(blockNumber);
5662 addToRekeyDateCache({
5763 [point]: Just(Result.Ok(new Date(block.timestamp * 1000))),
5864 });
65+ } catch {
66+ //TODO: better encoding for "no rekeyDate" state?
67+ addToRekeyDateCache({
68+ [point]: Just(Result.Error('No rekey date available.')),
69+ });
5970 }
6071 },
6172 [web3, contracts, addToRekeyDateCache]