Skip to content

Commit

Permalink
feat(neuron-ui): prevent updating tx and addr list when user is editi…
Browse files Browse the repository at this point in the history
…ng the description
  • Loading branch information
Keith-CY committed Sep 3, 2019
1 parent 031fed0 commit 6c4ea72
Show file tree
Hide file tree
Showing 13 changed files with 86 additions and 105 deletions.
11 changes: 3 additions & 8 deletions packages/neuron-ui/src/components/Addresses/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { onRenderRow } from 'utils/fabricUIRender'

const Addresses = ({
app: {
loadings: { addressList: isLoading, updateDescription: isUpdatingDescription },
loadings: { addressList: isLoading },
},
wallet: { addresses = [], id: walletID },
settings: { showAddressBook = false },
Expand Down Expand Up @@ -98,10 +98,6 @@ const Addresses = ({
onBlur={isSelected ? onDescriptionFieldBlur(item.address, item.description) : undefined}
onKeyPress={isSelected ? onDescriptionPress(item.address, item.description) : undefined}
onChange={isSelected ? onDescriptionChange(item.address) : undefined}
disabled={isSelected && isUpdatingDescription}
iconProps={{
iconName: isSelected && isUpdatingDescription ? 'Updating' : '',
}}
readOnly={!isSelected}
styles={{
root: {
Expand All @@ -110,7 +106,7 @@ const Addresses = ({
fieldGroup: {
backgroundColor: isSelected ? '#fff' : 'transparent',
borderColor: 'transparent',
border: isSelected ? '1px solid' : 'none',
border: isSelected ? `1px solid ${semanticColors.inputBorder}!important` : 'none',
},
}}
/>
Expand Down Expand Up @@ -161,8 +157,7 @@ const Addresses = ({
localDescription,
onDescriptionFieldBlur,
onDescriptionPress,
// onDescriptionFocus,
isUpdatingDescription,
onDescriptionSelected,
t,
semanticColors,
]
Expand Down
4 changes: 1 addition & 3 deletions packages/neuron-ui/src/components/History/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { useSearch } from './hooks'
const History = ({
app: {
tipBlockNumber: chainBlockNumber,
loadings: { transactionList: isLoading, updateDescription: isUpdatingDescription },
loadings: { transactionList: isLoading },
},
wallet: { id },
chain: {
Expand Down Expand Up @@ -54,7 +54,6 @@ const History = ({
</Stack>
<TransactionList
isLoading={isLoading}
isUpdatingDescription={isUpdatingDescription}
walletID={id}
items={items}
tipBlockNumber={tipBlockNumber}
Expand Down Expand Up @@ -87,7 +86,6 @@ const History = ({
onKeywordsChange,
onSearch,
isLoading,
isUpdatingDescription,
id,
items,
tipBlockNumber,
Expand Down
10 changes: 2 additions & 8 deletions packages/neuron-ui/src/components/TransactionList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { onRenderRow } from 'utils/fabricUIRender'
import { CONFIRMATION_THRESHOLD } from 'utils/const'

const theme = getTheme()
const { semanticColors } = theme

const MIN_CELL_WIDTH = 50

Expand Down Expand Up @@ -53,14 +54,12 @@ const onRenderHeader = ({ group }: any) => {

const TransactionList = ({
isLoading = false,
isUpdatingDescription = false,
items = [],
walletID,
tipBlockNumber,
dispatch,
}: {
isLoading?: boolean
isUpdatingDescription?: boolean
walletID: string
items: State.Transaction[]
tipBlockNumber: string
Expand Down Expand Up @@ -184,17 +183,13 @@ const TransactionList = ({
onBlur={isSelected ? onDescriptionFieldBlur(item.hash, item.description) : undefined}
onKeyPress={isSelected ? onDescriptionPress(item.hash, item.description) : undefined}
onChange={isSelected ? onDescriptionChange(item.hash) : undefined}
disabled={isSelected && isUpdatingDescription}
iconProps={{
iconName: isSelected && isUpdatingDescription ? 'Updating' : '',
}}
borderless
readOnly={!isSelected}
styles={{
fieldGroup: {
backgroundColor: isSelected ? '#fff' : 'transparent',
borderColor: 'transparent',
border: isSelected ? '1px solid' : 'none',
border: isSelected ? `1px solid ${semanticColors.inputBorder}!important` : 'none',
},
}}
/>
Expand Down Expand Up @@ -234,7 +229,6 @@ const TransactionList = ({
onDescriptionFieldBlur,
onDescriptionPress,
onDescriptionSelected,
isUpdatingDescription,
t,
]
)
Expand Down
10 changes: 9 additions & 1 deletion packages/neuron-ui/src/containers/Main/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,13 @@ export const useOnCurrentWalletChange = ({
export const useSubscription = ({
walletID,
chain,
isAllowedToFetchList,
history,
dispatch,
}: {
walletID: string
chain: State.Chain
isAllowedToFetchList: boolean
history: any
dispatch: StateDispatch
}) => {
Expand All @@ -139,10 +141,16 @@ export const useSubscription = ({
}
switch (dataType) {
case 'address': {
if (!isAllowedToFetchList) {
break
}
updateAddressListAndBalance(walletID)(dispatch)
break
}
case 'transaction': {
if (!isAllowedToFetchList) {
break
}
updateTransactionList({
walletID,
keywords,
Expand Down Expand Up @@ -239,7 +247,7 @@ export const useSubscription = ({
syncedBlockNumberSubscription.unsubscribe()
commandSubscription.unsubscribe()
}
}, [walletID, pageNo, pageSize, keywords, history, dispatch])
}, [walletID, pageNo, pageSize, keywords, isAllowedToFetchList, history, dispatch])
}

export default {
Expand Down
2 changes: 2 additions & 0 deletions packages/neuron-ui/src/containers/Main/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ const MainContent = ({
}: React.PropsWithoutRef<{ dispatch: StateDispatch } & RouteComponentProps>) => {
const neuronWalletState = useState()
const {
app: { isAllowedToFetchList = true },
wallet: { id: walletID = '' },
chain,
settings: { networks = [] },
Expand All @@ -125,6 +126,7 @@ const MainContent = ({
useSubscription({
walletID,
chain,
isAllowedToFetchList,
history,
dispatch,
})
Expand Down
2 changes: 1 addition & 1 deletion packages/neuron-ui/src/states/initStates/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ const appState: State.App = {
sending: false,
addressList: false,
transactionList: false,
updateDescription: false,
},
showTopAlert: false,
showAllNotifications: false,
isAllowedToFetchList: true,
}

export default appState
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,19 @@ export const toggleAllNotificationVisibility = (show?: boolean) => (dispatch: St
})
}

export const toggleIsAllowedToFetchList = (allowed?: boolean) => (dispatch: StateDispatch) => {
dispatch({
type: AppActions.ToggleIsAllowedToFetchList,
payload: allowed,
})
}

export default {
initAppState,
addNotification,
addPopup,
dismissNotification,
toggleTopAlertVisibility,
toggleAllNotificationVisibility,
toggleIsAllowedToFetchList,
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NeuronWalletActions, AppActions, StateDispatch } from 'states/stateProvider/reducer'
import { NeuronWalletActions, StateDispatch } from 'states/stateProvider/reducer'
import {
GetTransactionListParams,
getTransactionList,
Expand All @@ -23,12 +23,6 @@ export const updateTransactionList = (params: GetTransactionListParams) => (disp
export const updateTransactionDescription = (params: Controller.UpdateTransactionDescriptionParams) => (
dispatch: StateDispatch
) => {
dispatch({
type: AppActions.UpdateLoadings,
payload: {
updateDescription: true,
},
})
const descriptionParams = {
hash: params.hash,
description: params.description,
Expand All @@ -37,25 +31,16 @@ export const updateTransactionDescription = (params: Controller.UpdateTransactio
type: NeuronWalletActions.UpdateTransactionDescription,
payload: descriptionParams,
}) // update local description before remote description to avoid the flicker on the field
updateRemoteTransactionDescription(params)
.then(res => {
if (res.status) {
dispatch({
type: NeuronWalletActions.UpdateTransactionDescription,
payload: descriptionParams,
})
} else {
addNotification(failureResToNotification(res))(dispatch)
}
})
.finally(() => {
updateRemoteTransactionDescription(params).then(res => {
if (res.status) {
dispatch({
type: AppActions.UpdateLoadings,
payload: {
updateDescription: false,
},
type: NeuronWalletActions.UpdateTransactionDescription,
payload: descriptionParams,
})
})
} else {
addNotification(failureResToNotification(res))(dispatch)
}
})
}

export default {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,6 @@ export const updateAddressListAndBalance = (params: Controller.GetAddressesByWal
export const updateAddressDescription = (params: Controller.UpdateAddressDescriptionParams) => (
dispatch: StateDispatch
) => {
dispatch({
type: AppActions.UpdateLoadings,
payload: {
updateDescription: true,
},
})
const descriptionParams = {
address: params.address,
description: params.description,
Expand All @@ -217,25 +211,16 @@ export const updateAddressDescription = (params: Controller.UpdateAddressDescrip
type: NeuronWalletActions.UpdateAddressDescription,
payload: descriptionParams,
})
updateRemoteAddressDescription(params)
.then(res => {
if (res.status) {
dispatch({
type: NeuronWalletActions.UpdateAddressDescription,
payload: descriptionParams,
})
} else {
addNotification(failureResToNotification(res))(dispatch)
}
})
.finally(() => {
updateRemoteAddressDescription(params).then(res => {
if (res.status) {
dispatch({
type: AppActions.UpdateLoadings,
payload: {
updateDescription: false,
},
type: NeuronWalletActions.UpdateAddressDescription,
payload: descriptionParams,
})
})
} else {
addNotification(failureResToNotification(res))(dispatch)
}
})
}

export const deleteWallet = (params: Controller.DeleteWalletParams) => (dispatch: StateDispatch) => {
Expand Down
10 changes: 10 additions & 0 deletions packages/neuron-ui/src/states/stateProvider/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export enum AppActions {
PopOut = 'popOut',
ToggleTopAlertVisibility = 'toggleTopAlertVisibility',
ToggleAllNotificationVisibility = 'toggleAllNotificationVisibility',
ToggleIsAllowedToFetchList = 'toggleIsAllowedToFetchList',
Ignore = 'ignore',
}

Expand Down Expand Up @@ -538,6 +539,15 @@ export const reducer = (
},
}
}
case AppActions.ToggleIsAllowedToFetchList: {
return {
...state,
app: {
...app,
isAllowedToFetchList: payload === undefined ? !app.isAllowedToFetchList : payload,
},
}
}
default: {
return state
}
Expand Down
21 changes: 2 additions & 19 deletions packages/neuron-ui/src/stories/TransactionList.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,20 @@ import transactions from './data/transactions'
const stories = storiesOf('TransactionList', module)
Object.entries(transactions).forEach(([title, list]) => {
stories.add(title, () => (
<TransactionList
isLoading={false}
tipBlockNumber="123"
isUpdatingDescription={false}
walletID="1"
items={list}
dispatch={() => {}}
/>
<TransactionList isLoading={false} tipBlockNumber="123" walletID="1" items={list} dispatch={() => {}} />
))
})

stories.add('Wtih empty pending list', () => (
<TransactionList
isLoading={false}
tipBlockNumber="123"
isUpdatingDescription={false}
walletID="1"
items={transactions['Content List'].filter(item => item.status !== 'pending')}
dispatch={() => {}}
/>
))

stories.add('Shimmered List', () => {
return (
<TransactionList
isLoading={false}
tipBlockNumber="123"
isUpdatingDescription={false}
walletID="1"
items={[]}
dispatch={() => {}}
/>
)
return <TransactionList isLoading={false} tipBlockNumber="123" walletID="1" items={[]} dispatch={() => {}} />
})
2 changes: 1 addition & 1 deletion packages/neuron-ui/src/types/App/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ declare namespace State {
sending: boolean
addressList: boolean
transactionList: boolean
updateDescription: boolean
}
showTopAlert: boolean
showAllNotifications: boolean
isAllowedToFetchList: boolean
}

interface NetworkProperty {
Expand Down
Loading

0 comments on commit 6c4ea72

Please sign in to comment.