on master help sign in
store: distinguish SR failure state from loading

As it turns out, trying to fetch star release details for an account may unexpectedly throw "invalid opcode" errors, if the account in question does not have any stars in lockup. This in turn would result in the points list screen staying stuck on "loading...". We were already handling such exceptions, but were handling them incorrectly*. We were setting the star release state to `Nothing()`, which the points list was interpreting as "still loading". Now, when we encounter any exception, we set the star release state to `Just(null)`. This means the points list needs to do a little bit more work to interpret the state, but lets it distinguish between "loading" and "failed to load". (* One can argue that "failure to load" does indeed imply we still do not know what the actual state is, and so we should not set it yet. Even if that's correct, it's not as practical/convenient as the changes herein. At least for the time being, we choose "better" over "perfect".)

commit5d0ea536316866e87a20214ac4a58c2e4d0659c4 authorFang <git@fang.io> dateThu 1 Jul 2021, 11:17 (5 years ago) parent602866e
2 files changed+5−4
src/store/lib/useStarReleaseStore.js+2−2 src/views/Points.js+3−2
src/store/lib/useStarReleaseStore.js+2−2
@@ -49,8 +49,8 @@ export default function useStarRelease() {
4949
5050 _setDetails(Just(result));
5151 } catch (e) {
52− _setDetails(Nothing());
53− console.error(e);
52+ _setDetails(Just(null));
53+ console.error('error fetching star release details', e);
5454 }
5555 }, [contracts, wallet]);
5656
src/views/Points.js+3−2
@@ -151,7 +151,8 @@ export default function Points() {
151151 all.length === 1 &&
152152 incoming.length === 0 &&
153153 maybeOutgoingPoints.value.length === 0 &&
154− starReleaseDetails.value.total === 0
154+ (starReleaseDetails.value === null ||
155+ starReleaseDetails.value.total === 0)
155156 ) {
156157 setPointCursor(Just(all[0]));
157158 popAndPush(names.POINT);
@@ -196,7 +197,7 @@ export default function Points() {
196197 !loading && incomingPoints.length === 0 && allPoints.length === 0;
197198
198199 const starReleasing = starReleaseDetails
199− .map(s => s.total > 0)
200+ .map(s => (s ? s.total > 0 : false))
200201 .getOrElse(false);
201202
202203 useEffect(() => {