on master help sign in
Merge pull request #247 from urbit/fix/null-block
52e0d3eMatt Condon
src/store/lib/useRekeyDateStore.js+17−6
@@ -44,18 +44,29 @@ export default function useRekeyDateStore() {
44 },
44 },
45 });
45 });
46
46
47+ // NB(shrugs) using try-catch here to simplify our error handling
48+ try {
47− if (logs.length === 0) {
49+ if (logs.length === 0) {
48− //TODO: better encoding for "no rekeyDate" state?
49− addToRekeyDateCache({
50− [point]: Just(Result.Error('No rekey date available.')),
50+ throw new Error('No logs available.');
51− });
51+ }
52− } else {
52+
53 // last log is most recent
53 // last log is most recent
54 const blockNumber = logs[logs.length - 1].blockNumber;
54 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+
55 const block = await _web3.eth.getBlock(blockNumber);
61 const block = await _web3.eth.getBlock(blockNumber);
56 addToRekeyDateCache({
62 addToRekeyDateCache({
57 [point]: Just(Result.Ok(new Date(block.timestamp * 1000))),
63 [point]: Just(Result.Ok(new Date(block.timestamp * 1000))),
58 });
64 });
65+ } catch {
66+ //TODO: better encoding for "no rekeyDate" state?
67+ addToRekeyDateCache({
68+ [point]: Just(Result.Error('No rekey date available.')),
69+ });
59 }
70 }
60 },
71 },
61 [web3, contracts, addToRekeyDateCache]
72 [web3, contracts, addToRekeyDateCache]