Skip to content

Commit

Permalink
feat: remove skip data and type toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
Keith-CY committed Nov 8, 2019
1 parent c6b57f9 commit 879d227
Show file tree
Hide file tree
Showing 14 changed files with 10 additions and 163 deletions.
32 changes: 4 additions & 28 deletions packages/neuron-ui/src/components/GeneralSetting/index.tsx
Original file line number Diff line number Diff line change
@@ -1,32 +1,8 @@
import React, { useMemo } from 'react'
import { Stack, Toggle } from 'office-ui-fabric-react'
import { useTranslation } from 'react-i18next'
import React from 'react'
import { Stack } from 'office-ui-fabric-react'

import { StateWithDispatch } from 'states/stateProvider/reducer'
import { setSkipDataAndType } from 'states/stateProvider/actionCreators'

const GeneralSetting = ({
settings: {
general: { skipDataAndType },
},
dispatch,
}: React.PropsWithoutRef<StateWithDispatch>) => {
const [t] = useTranslation()
const [onSetSkipDataAndType] = useMemo(() => [() => setSkipDataAndType(!skipDataAndType)(dispatch)], [
dispatch,
skipDataAndType,
])
return (
<Stack tokens={{ childrenGap: 15 }}>
<Toggle
checked={skipDataAndType}
label={t('settings.general.skip-data-and-type')}
onText={t('common.toggle.on')}
offText={t('common.toggle.off')}
onChange={onSetSkipDataAndType}
/>
</Stack>
)
const GeneralSetting = () => {
return <Stack tokens={{ childrenGap: 15 }} />
}

GeneralSetting.displayName = 'GeneralSetting'
Expand Down
1 change: 0 additions & 1 deletion packages/neuron-ui/src/services/remote/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ export * from './app'
export * from './wallets'
export * from './networks'
export * from './transactions'
export * from './skipDataAndType'

const REMOTE_MODULE_NOT_FOUND =
'The remote module is not found, please make sure the UI is running inside the Electron App'
Expand Down
7 changes: 0 additions & 7 deletions packages/neuron-ui/src/services/remote/skipDataAndType.ts

This file was deleted.

4 changes: 1 addition & 3 deletions packages/neuron-ui/src/states/initStates/settings.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { wallets, networks } from 'services/localCache'

export const settingsState: State.Settings = {
general: {
skipDataAndType: false,
},
general: {},
networks: networks.load(),
wallets: wallets.load(),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export const initAppState = () => (dispatch: StateDispatch, history: any) => {
syncedBlockNumber = '',
connectionStatus = false,
codeHash = '',
skipDataAndType = false,
} = res.result
dispatch({
type: NeuronWalletActions.InitAppState,
Expand All @@ -39,7 +38,6 @@ export const initAppState = () => (dispatch: StateDispatch, history: any) => {
syncedBlockNumber,
connectionStatus,
codeHash,
skipDataAndType,
},
})
if (!wallet) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,16 @@ import app from './app'
import wallets from './wallets'
import transactions from './transactions'
import settings from './settings'
import skipDataAndType from './skipDataAndType'

export * from './app'
export * from './wallets'
export * from './transactions'
export * from './settings'
export * from './skipDataAndType'
export const actionCreators = {
...app,
...wallets,
...transactions,
...settings,
...skipDataAndType,
}

export default actionCreators

This file was deleted.

16 changes: 0 additions & 16 deletions packages/neuron-ui/src/states/stateProvider/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ export enum NeuronWalletActions {
// Connection
UpdateConnectionStatus = 'updateConnectionStatus',
UpdateSyncedBlockNumber = 'updateSyncedBlockNumber',
// settings
UpdateSkipDataAndType = 'updateSkipDataAndType',
}
export enum AppActions {
UpdateTransactionID = 'updateTransactionID',
Expand Down Expand Up @@ -79,7 +77,6 @@ export const reducer = (
syncedBlockNumber,
connectionStatus,
codeHash,
skipDataAndType,
} = payload
return {
...state,
Expand All @@ -95,25 +92,12 @@ export const reducer = (
settings: {
general: {
...state.settings.general,
skipDataAndType,
},
networks,
wallets,
},
}
}
case NeuronWalletActions.UpdateSkipDataAndType: {
return {
...state,
settings: {
...settings,
general: {
...settings.general,
skipDataAndType: payload,
},
},
}
}
case NeuronWalletActions.UpdateCodeHash: {
return {
...state,
Expand Down
9 changes: 1 addition & 8 deletions packages/neuron-ui/src/stories/GeneralSetting.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,9 @@ import React from 'react'
import { storiesOf } from '@storybook/react'
import { withKnobs } from '@storybook/addon-knobs'
import GeneralSetting from 'components/GeneralSetting'
import initStates from 'states/initStates'

const stories = storiesOf('GeneralSettings', module)

stories.addDecorator(withKnobs).add('With knobs', () => {
const props = {
...initStates,
settings: {
...initStates.settings,
},
}
return <GeneralSetting {...props} dispatch={() => {}} />
return <GeneralSetting />
})
4 changes: 1 addition & 3 deletions packages/neuron-ui/src/types/App/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,7 @@ declare namespace State {
}
}
interface Settings {
general: {
skipDataAndType: boolean
}
general: {}
networks: Network[]
wallets: WalletIdentity[]
}
Expand Down
19 changes: 1 addition & 18 deletions packages/neuron-wallet/src/controllers/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,10 @@ import env from 'env'
import i18n from 'utils/i18n'
import { popContextMenu } from './app/menu'
import { showWindow } from './app/show-window'
import {
TransactionsController,
WalletsController,
SyncInfoController,
SkipDataAndTypeController,
NetworksController
} from 'controllers'
import { TransactionsController, WalletsController, SyncInfoController, NetworksController } from 'controllers'
import { NetworkType, NetworkID, Network } from 'types/network'
import NetworksService from 'services/networks'
import WalletsService from 'services/wallets'
import SkipDataAndType from 'services/settings/skip-data-and-type'
import { ConnectionStatusSubject } from 'models/subjects/node'
import { SystemScriptSubject } from 'models/subjects/system-script'
import { MapApiResponse } from 'decorators'
Expand Down Expand Up @@ -82,8 +75,6 @@ export default class ApiController {
}).then(res => res.result)
: []

const skipDataAndType = SkipDataAndType.getInstance().get()

const initState = {
currentWallet,
wallets: [...wallets.map(({ name, id }) => ({ id, name }))],
Expand All @@ -94,7 +85,6 @@ export default class ApiController {
syncedBlockNumber,
connectionStatus,
codeHash,
skipDataAndType,
}

return { status: ResponseCode.Success, result: initState }
Expand Down Expand Up @@ -265,11 +255,4 @@ export default class ApiController {
public static async showTransactionDetails(hash: string) {
showWindow(`${env.mainURL}#/transaction/${hash}`, i18n.t(`messageBox.transaction.title`, { hash }))
}

// Misc

@MapApiResponse
public static async updateSkipDataAndType(skip: boolean) {
return SkipDataAndTypeController.update(skip)
}
}
4 changes: 1 addition & 3 deletions packages/neuron-wallet/src/controllers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import NetworksController from './networks'
import WalletsController from './wallets'
import TransactionsController from './transactions'
import SyncInfoController from './sync-info'
import SkipDataAndTypeController from './skip-data-and-type'
import UpdateController from './update'

import ApiController from './api'
Expand All @@ -14,7 +13,6 @@ export {
WalletsController,
TransactionsController,
SyncInfoController,
SkipDataAndTypeController,
UpdateController,
ApiController
ApiController,
}
22 changes: 0 additions & 22 deletions packages/neuron-wallet/src/controllers/skip-data-and-type.ts

This file was deleted.

29 changes: 1 addition & 28 deletions packages/neuron-wallet/tests-e2e/tests/generalSettings.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,10 @@
import Application from '../application'

/**
* 1. navigate to the general settings handleViewError
* 2. the toggle of skip data and type script should be off
* 3. click on the toggles and their statuses should be updated
* 4. refresh the view and the statuses should be preserved
*/
export default (app: Application) => {
beforeAll(async () => {
await app.gotoSettingPageFromMenu()
await app.waitUntilLoaded()
})

describe('Test general settings', () => {
app.test('Check the initialized statuses', async () => {
const { client } = app.spectron
const toggles = await client.$$('button[role=switch]')
expect((await client.elementIdAttribute(toggles[0].value.ELEMENT, 'aria-checked')).value).toBe('true')
})

app.test('toggle SkipDataAndType to false', async () => {
const { client } = app.spectron
await app.waitUntilLoaded()
const toggles = await client.$$('button[role=switch]')

toggles.forEach((_, idx) => {
client.elementIdClick(toggles[idx].value.ELEMENT)
})

await app.waitUntilLoaded()
expect((await client.elementIdAttribute(toggles[0].value.ELEMENT, 'aria-checked')).value).toBe('false')
})

test.skip('Toggle statuses should be preserved', async () => {})
})
describe.skip('Test general settings', () => {})
}

0 comments on commit 879d227

Please sign in to comment.