Skip to content
This repository was archived by the owner on Jan 6, 2023. It is now read-only.

Commit 803ce2f

Browse files
committed
refactor: Move selectors to their own file
fix: CAN REBASE AMEND, Infer status from state feat: Infer status
1 parent 1e0f4da commit 803ce2f

File tree

5 files changed

+40
-40
lines changed

5 files changed

+40
-40
lines changed

components/maker/status/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ const Status = ({ app, status }) => {
7070

7171
{isReady ? <AppMiningComplete /> : <AppMiningIncomplete/>}
7272

73-
<ItemToCompleteField label="Payment details" status={status.paymentDetailsComplete || hasPaymentDetails(app)} />
74-
<ItemToCompleteField label="Identity Verification" status={status.kycComplete || app.hasCollectedKYC} />
73+
<ItemToCompleteField label="Payment details" status={hasPaymentDetails(app)} />
74+
<ItemToCompleteField label="Identity Verification" status={app.hasCollectedKYC} />
7575
<ItemToCompleteField label="Tax Documents" status={app.isKYCVerified} />
7676
<ItemToCompleteField label="SEC Participation Agreement" status={app.hasAcceptedSECTerms} />
7777
</Box>

pages/maker/index.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { useEffect } from 'react'
22
import { Flex, Box, Type } from 'blockstack-ui'
33
import { connect } from 'react-redux'
44

5-
import { selectMaker, selectAppList, selectCurrentApp } from '@stores/maker/reducer'
5+
import { selectMaker, selectAppList, selectCurrentApp, selectCompetionStatus } from '@stores/maker/selectors'
66
import { fetchApps, selectAppAction } from '@stores/maker/actions'
77
import { selectApiServer, selectUser } from '@stores/apps/selectors'
88
import { Page } from '@components/page'
@@ -12,9 +12,8 @@ import { MakerContainer, MakerContentBox, MakerStickyStatusBox } from '@componen
1212

1313
const MakerPortal = ({ apiServer, user, maker, loading, errorMessage, appList, selectedApp, dispatch }) => {
1414

15-
useEffect(() => {
16-
fetchApps({ apiServer, user })(dispatch)
17-
}, [])
15+
const MakerPortal = ({ query, params, apiServer, user, maker, errorMessage, appList, selectedApp, competionStatus, dispatch }) => {
16+
console.log('Rendering component')
1817

1918
const app = selectedApp
2019

@@ -55,7 +54,7 @@ const MakerPortal = ({ apiServer, user, maker, loading, errorMessage, appList, s
5554
<Maker.Status
5655
app={app}
5756
apiServer={apiServer}
58-
status={maker.status}
57+
status={competionStatus}
5958
/>
6059
</MakerStickyStatusBox>
6160
<Box>
@@ -96,7 +95,8 @@ const mapStateToProps = (state) => ({
9695
apiServer: selectApiServer(state),
9796
maker: selectMaker(state),
9897
appList: selectAppList(state),
99-
selectedApp: selectCurrentApp(state)
98+
selectedApp: selectCurrentApp(state),
99+
competionStatus: selectCompetionStatus(state)
100100
})
101101

102102
export default connect(mapStateToProps)(MakerPortal)

stores/maker/actions.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@ export const SELECT_APP = '[Maker Page] SELECT_APP'
1717

1818
export const errorAction = () => ({ type: MAKER_AUTH_ERROR })
1919
export const setLoadingDoneAction = () => ({ type: SET_LOADING_DONE })
20-
export const setPaymentDetailsComplete = () => ({ type: SET_PAYMENT_DETAILS_COMPLETE })
2120
export const savePaymentDetailsAction = () => ({ type: SAVE_PAYMENT_DETAILS })
22-
export const savePaymentDetailsDoneAction = () => ({ type: SAVE_PAYMENT_DETAILS_DONE })
21+
export const savePaymentDetailsDoneAction = addresses => ({
22+
type: SAVE_PAYMENT_DETAILS_DONE,
23+
payload: addresses
24+
})
2325
export const savePaymentDetailsFailAction = () => ({ type: SAVE_PAYMENT_DETAILS_FAIL })
2426

2527
export const setKycComplete = () => ({ type: SET_KYC_COMPLETE })
@@ -46,14 +48,12 @@ export const savePaymentDetails = ({ apiServer, appId, jwt, btcAddress, stxAddre
4648
})
4749
})
4850
await response.json()
49-
dispatch(setPaymentDetailsComplete())
50-
dispatch(savePaymentDetailsDoneAction())
51+
dispatch(savePaymentDetailsDoneAction({ appId, btcAddress, stxAddress }))
5152
} catch (error) {
5253
dispatch(savePaymentDetailsFailAction(error))
5354
}
5455
}
5556

56-
5757
export const fetchApps = ({ user, apiServer }) => async dispatch => {
5858
dispatch(fetchAppsAction())
5959
if (!(user && user.jwt)) {
@@ -74,4 +74,3 @@ export const fetchApps = ({ user, apiServer }) => async dispatch => {
7474
dispatch(fetchAppsFailAction())
7575
}
7676
}
77-

stores/maker/reducer.js

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,12 @@ const initialState = {
77
appIds: [],
88
appEntities: {},
99
selectedAppId: null,
10-
errorMessage: null,
11-
status: {
12-
paymentDetailsComplete: false,
13-
kycComplete: false,
14-
legalComplete: false
15-
}
10+
errorMessage: null
1611
}
1712

18-
const updateStatus = (state, props) => ({
19-
...state,
20-
status: { ...state.status, ...props }
21-
})
22-
2313
function makerReducer(state = initialState, action) {
2414
switch (action.type) {
15+
2516
case MakerActions.SET_LOADING_DONE:
2617
return {
2718
...state,
@@ -43,15 +34,6 @@ function makerReducer(state = initialState, action) {
4334
selectedAppId: action.payload.apps.length ? action.payload.apps[0].id : null
4435
}
4536

46-
case MakerActions.SET_PAYMENT_DETAILS_COMPLETE:
47-
return updateStatus(state, { paymentDetailsComplete: true })
48-
49-
case MakerActions.SET_KYC_COMPLETE:
50-
return updateStatus(state, { kycComplete: true })
51-
52-
case MakerActions.SET_LEGAL_COMPLETE:
53-
return updateStatus(state, { legalComplete: true })
54-
5537
case MakerActions.SELECT_APP:
5638
return { ...state, selectedAppId: action.payload }
5739

@@ -60,8 +42,8 @@ function makerReducer(state = initialState, action) {
6042
...state,
6143
appEntities: {
6244
...state.appEntities,
63-
[action.payload.id]: {
64-
...state.appEntities[action.payload.id],
45+
[action.payload.appId]: {
46+
...state.appEntities[action.payload.appId],
6547
BTCAddress: action.payload.btcAddress,
6648
stacksAddress: action.payload.stxAddress
6749
}
@@ -74,7 +56,3 @@ function makerReducer(state = initialState, action) {
7456
}
7557

7658
export default makerReducer
77-
78-
export const selectMaker = state => state.maker
79-
export const selectAppList = state => state.maker.appIds.map(id => state.maker.appEntities[id])
80-
export const selectCurrentApp = state => state.maker.appEntities[state.maker.selectedAppId]

stores/maker/selectors.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const updateEntity = (state, id, newProps) => ({
2+
...state,
3+
appEntities: {
4+
...state.appEntities,
5+
[id]: {
6+
...state.appEntities[id],
7+
...newProps
8+
}
9+
}
10+
})
11+
12+
export const selectMaker = state => state.maker
13+
14+
export const selectAppList = state => state.maker.appIds.map(id => state.maker.appEntities[id])
15+
16+
export const selectCurrentApp = state => state.maker.appEntities[state.maker.selectedAppId]
17+
18+
// export const selectCompetionStatus = state => {
19+
// const selectedApp = state.appEntities[state.selectedAppId]
20+
// return {
21+
// paymentDetailsComplete
22+
// }
23+
// }

0 commit comments

Comments
 (0)