Skip to content

Commit

Permalink
fix(stacking): missing stacking error state, closes #416
Browse files Browse the repository at this point in the history
  • Loading branch information
kyranjamie committed Jan 6, 2021
1 parent 033ae22 commit d07e3f9
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 6 deletions.
24 changes: 24 additions & 0 deletions app/components/home/stacking-error-card.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React, { FC } from 'react';
import { Flex, Text } from '@blockstack/ui';

export const StackingError: FC = () => (
<Flex
flexDirection="column"
flex={1}
justifyContent="center"
textAlign="center"
alignItems="center"
mt="extra-loose"
borderRadius="8px"
boxShadow="0px 1px 2px rgba(0, 0, 0, 0.04);"
border="1px solid #F0F0F5"
px="loose"
minHeight="180px"
>
<Flex>
<Text display="block" textStyle="body.small" color="ink.600" width="100%">
Unable to fetch stacking details
</Text>
</Flex>
</Flex>
);
2 changes: 2 additions & 0 deletions app/pages/home/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import { TransactionListItemPending } from '@components/home/transaction-list/tr
import { StackingCard } from '@components/home/stacking-card';
import { StackingLoading } from '@components/home/stacking-loading';
import { StackingBeginsSoonCard } from '@components/home/stacking-begins-soon-card';
import { StackingError } from '@components/home/stacking-error-card';

import { HomeLayout } from './home-layout';

Expand Down Expand Up @@ -168,6 +169,7 @@ export const Home: FC = () => {
<StackingBeginsSoonCard blocksTillNextCycle={nextCycleInfo?.blocksToNextCycle} />
),
[HomeCardState.StackingActive]: <StackingCard />,
[HomeCardState.StackingError]: <StackingError error="sldkjfslfd" />,
[HomeCardState.PostStacking]: <></>,
};

Expand Down
18 changes: 17 additions & 1 deletion app/store/home/home.reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
selectLoadingStacking,
selectPoxInfo,
selectStackerInfo,
selectStackingError,
} from '@store/stacking';
import BigNumber from 'bignumber.js';

Expand Down Expand Up @@ -50,6 +51,7 @@ export enum HomeCardState {
StackingPreCycle,
StackingActive,
PostStacking,
StackingError,
}

const selectLoadingCardResources = createSelector(
Expand All @@ -67,13 +69,27 @@ const selectMeetsMinStackingThreshold = createSelector(
}
);

const selectShowErrorCard = createSelector(selectStackingError, state => {
const errorToCheck = [state.blockTimeInfo, state.coreNodeInfo, state.poxInfo];
return errorToCheck.some(val => val === true);
});

export const selectHomeCardState = createSelector(
selectLoadingCardResources,
selectActiveStackingTxId,
selectMeetsMinStackingThreshold,
selectIsStackingCallPending,
selectStackerInfo,
(loadingResources, activeStackingTxId, meetsMinThreshold, stackingCallPending, stackerInfo) => {
selectShowErrorCard,
(
loadingResources,
activeStackingTxId,
meetsMinThreshold,
stackingCallPending,
stackerInfo,
stackingErr
) => {
if (stackingErr) return HomeCardState.StackingError;
if (loadingResources) return HomeCardState.LoadingResources;
if (!meetsMinThreshold) return HomeCardState.NotEnoughStx;
if (stackingCallPending || typeof activeStackingTxId === 'string')
Expand Down
26 changes: 21 additions & 5 deletions app/store/stacking/stacking.reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export interface StackingState {
'poxInfo' | 'coreNodeInfo' | 'blockTimeInfo' | 'stackerInfo',
boolean
>;
error: string | null;
errors: Record<'poxInfo' | 'coreNodeInfo' | 'blockTimeInfo' | 'stackerInfo', boolean>;
contractCallTx: string | null;
poxInfo: CoreNodePoxResponse | null;
coreNodeInfo: CoreNodeInfoResponse | null;
Expand All @@ -54,7 +54,12 @@ const initialState: StackingState = {
blockTimeInfo: false,
stackerInfo: false,
},
error: null,
errors: {
poxInfo: false,
coreNodeInfo: false,
blockTimeInfo: false,
stackerInfo: false,
},
contractCallTx: null,
poxInfo: null,
coreNodeInfo: null,
Expand All @@ -79,33 +84,44 @@ export const stackingSlice = createSlice({
action: PayloadAction<CoreNodeInfoResponse>
) => {
state.initialRequestsComplete.coreNodeInfo = true;
state.errors.coreNodeInfo = false;
state.coreNodeInfo = action.payload;
},
[fetchCoreDetails.rejected.toString()]: state => {
state.errors.coreNodeInfo = true;
},
[fetchBlockTimeInfo.fulfilled.toString()]: (
state,
action: PayloadAction<NetworkBlockTimesResponse>
) => {
state.errors.blockTimeInfo = false;
state.initialRequestsComplete.blockTimeInfo = true;
state.blockTimeInfo = action.payload;
},
[fetchBlockTimeInfo.rejected.toString()]: state => {
state.errors.blockTimeInfo = true;
},
[fetchStackerInfo.fulfilled.toString()]: (
state,
action: PayloadAction<Required<StackerInfo>>
) => {
state.initialRequestsComplete.stackerInfo = true;
if ('error' in action.payload || !action.payload.stacked) {
state.error = 'There was an error stacking';
state.errors.stackerInfo = true;
return;
}
state.stackerInfo = action.payload.details;
state.error = null;
state.errors.stackerInfo = false;
},
[fetchStackerInfo.rejected.toString()]: state => {
state.initialRequestsComplete.stackerInfo = true;
},
[activeStackingTx.toString()]: (state, action: PayloadAction<{ txId: string }>) => {
state.contractCallTx = action.payload.txId;
},
// [activeStackingTx]: (state, action: PayloadAction<{ txId: string }>) => {
// state.contractCallTx = action.payload.txId;
// },
[removeStackingTx.toString()]: state => {
state.contractCallTx = null;
},
Expand All @@ -121,7 +137,7 @@ export const selectBlockTimeInfo = createSelector(
state => state.blockTimeInfo
);

export const selectStackingError = createSelector(selectStackingState, state => state.error);
export const selectStackingError = createSelector(selectStackingState, state => state.errors);

export const selectLoadingStacking = createSelector(
selectStackingState,
Expand Down

0 comments on commit d07e3f9

Please sign in to comment.