Skip to content

Commit

Permalink
feat: Always show address book
Browse files Browse the repository at this point in the history
  • Loading branch information
ashchan committed Nov 2, 2019
1 parent 07dc1b3 commit 940e23a
Show file tree
Hide file tree
Showing 19 changed files with 26 additions and 162 deletions.
14 changes: 2 additions & 12 deletions packages/neuron-ui/src/components/Addresses/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, useEffect, useMemo } from 'react'
import React, { useState, useMemo } from 'react'
import { RouteComponentProps } from 'react-router-dom'
import { useTranslation } from 'react-i18next'
import {
Expand All @@ -18,7 +18,6 @@ import { ckbCore } from 'services/chain'
import { StateWithDispatch } from 'states/stateProvider/reducer'

import { useLocalDescription } from 'utils/hooks'
import { Routes } from 'utils/const'
import { localNumberFormatter, shannonToCKBFormatter } from 'utils/formatters'
import { onRenderRow } from 'utils/fabricUIRender'

Expand All @@ -28,22 +27,13 @@ const Addresses = ({
},
wallet: { addresses = [], id: walletID },
chain: { networkID },
settings: {
general: { showAddressBook = false },
networks = [],
},
history,
settings: { networks = [] },
dispatch,
}: React.PropsWithoutRef<StateWithDispatch & RouteComponentProps>) => {
const isMainnet =
(networks.find(n => n.id === networkID) || {}).chain === (process.env.REACT_APP_MAINNET_TAG || 'ckb')
const [showMainnetAddress, setShowMainnetAddress] = useState(false)
const [t] = useTranslation()
useEffect(() => {
if (!showAddressBook) {
history.push(Routes.Overview)
}
}, [showAddressBook, history])

const {
localDescription,
Expand Down
19 changes: 6 additions & 13 deletions packages/neuron-ui/src/components/GeneralSetting/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,21 @@ import { Stack, Toggle } from 'office-ui-fabric-react'
import { useTranslation } from 'react-i18next'

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

const GeneralSetting = ({
settings: {
general: { showAddressBook, skipDataAndType },
general: { skipDataAndType },
},
dispatch,
}: React.PropsWithoutRef<StateWithDispatch>) => {
const [t] = useTranslation()
const [onToggleAddressVisibility, onSetSkipDataAndType] = useMemo(
() => [() => dispatch(toggleAddressBook()), () => setSkipDataAndType(!skipDataAndType)(dispatch)],
[dispatch, skipDataAndType]
)
const [onSetSkipDataAndType] = useMemo(() => [() => setSkipDataAndType(!skipDataAndType)(dispatch)], [
dispatch,
skipDataAndType,
])
return (
<Stack tokens={{ childrenGap: 15 }}>
<Toggle
checked={showAddressBook}
label={t('settings.general.display-address-book-in-the-navbar')}
onText={t('common.toggle.on')}
offText={t('common.toggle.off')}
onChange={onToggleAddressVisibility}
/>
<Toggle
checked={skipDataAndType}
label={t('settings.general.skip-data-and-type')}
Expand Down
5 changes: 0 additions & 5 deletions packages/neuron-ui/src/containers/Main/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { useEffect } from 'react'

import { NeuronWalletActions, StateDispatch, AppActions } from 'states/stateProvider/reducer'
import {
toggleAddressBook,
updateTransactionList,
updateCurrentWallet,
updateWalletList,
Expand Down Expand Up @@ -214,10 +213,6 @@ export const useSubscription = ({
history.push(payload)
break
}
case 'toggle-address-book': {
dispatch(toggleAddressBook())
break
}
case 'delete-wallet': {
dispatch({
type: AppActions.RequestPassword,
Expand Down
9 changes: 2 additions & 7 deletions packages/neuron-ui/src/containers/Navbar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,11 @@ const Navbar = ({
}: React.PropsWithoutRef<StateWithDispatch & RouteComponentProps>) => {
const neuronWallet = useState()
const {
settings: {
wallets = [],
general: { showAddressBook = false },
},
settings: { wallets = [] },
} = neuronWallet
const [t] = useTranslation()

const pivotItems = useMemo(() => (showAddressBook ? menuItems : menuItems.slice(0, menuItems.length - 1)), [
showAddressBook,
])
const pivotItems = menuItems

const selectedKey = useMemo(() => {
const selectedTab = pivotItems.find(item => item.key === pathname.split('/')[1])
Expand Down
1 change: 0 additions & 1 deletion packages/neuron-ui/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@
"network": "Network"
},
"general": {
"display-address-book-in-the-navbar": "Show the address book",
"skip-data-and-type": "Skip the Cells which contain Data or Type Script",
"show": "Show",
"hide": "Hide"
Expand Down
1 change: 0 additions & 1 deletion packages/neuron-ui/src/locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@
"network": "网络"
},
"general": {
"display-address-book-in-the-navbar": "显示地址簿",
"skip-data-and-type": "忽略包含 Data 或 Type Script 的 Cells",
"show": "显示",
"hide": "隐藏"
Expand Down
20 changes: 0 additions & 20 deletions packages/neuron-ui/src/services/localCache.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,11 @@
export enum LocalCacheKey {
AddressBookVisibility = 'address-book-visibility',
Addresses = 'addresses',
Networks = 'networks',
Wallets = 'wallets',
CurrentWallet = 'currentWallet',
CurrentNetworkID = 'currentNetworkID',
SystemScript = 'systemScript',
}
enum AddressBookVisibility {
Invisible = '0',
Visible = '1',
}

export const addressBook = {
isVisible: () => {
const isVisible = window.localStorage.getItem(LocalCacheKey.AddressBookVisibility)
return AddressBookVisibility.Visible === isVisible
},

toggleVisibility: () => {
window.localStorage.setItem(
LocalCacheKey.AddressBookVisibility,
addressBook.isVisible() ? AddressBookVisibility.Invisible : AddressBookVisibility.Visible
)
},
}

export const addresses = {
save: (addressList: State.Address[]) => {
Expand Down Expand Up @@ -143,7 +124,6 @@ export const systemScript = {

export default {
LocalCacheKey,
addressBook,
addresses,
networks,
wallets,
Expand Down
3 changes: 1 addition & 2 deletions packages/neuron-ui/src/states/initStates/settings.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { addressBook, wallets, networks } from 'services/localCache'
import { wallets, networks } from 'services/localCache'

export const settingsState: State.Settings = {
general: {
skipDataAndType: false,
showAddressBook: addressBook.isVisible(),
},
networks: networks.load(),
wallets: wallets.load(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
import { createNetwork as createRemoteNetwork, updateNetwork as updateRemoteNetwork } from 'services/remote'
import { addressBook } from 'services/localCache'
import { Routes } from 'utils/const'
import { failureResToNotification } from 'utils/formatters'
import { addNotification, addPopup } from './app'

import { AppActions, StateDispatch } from '../reducer'

export const toggleAddressBook = () => {
addressBook.toggleVisibility()
return {
type: AppActions.ToggleAddressBookVisibility,
payload: null,
}
}

export const createNetwork = (params: Controller.CreateNetworkParams) => (dispatch: StateDispatch, history: any) => {
dispatch({
type: AppActions.UpdateLoadings,
Expand Down Expand Up @@ -67,7 +58,6 @@ export const updateNetwork = (params: Controller.UpdateNetworkParams) => (dispat
}

export default {
toggleAddressBook,
createNetwork,
updateNetwork,
}
13 changes: 0 additions & 13 deletions packages/neuron-ui/src/states/stateProvider/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export enum NeuronWalletActions {
UpdateSkipDataAndType = 'updateSkipDataAndType',
}
export enum AppActions {
ToggleAddressBookVisibility = 'toggleAddressBookVisibility',
UpdateTransactionID = 'updateTransactionID',
AddSendOutput = 'addSendOutput',
RemoveSendOutput = 'removeSendOutput',
Expand Down Expand Up @@ -103,18 +102,6 @@ export const reducer = (
},
}
}
case AppActions.ToggleAddressBookVisibility: {
return {
...state,
settings: {
...settings,
general: {
...settings.general,
showAddressBook: !settings.general.showAddressBook,
},
},
}
}
case NeuronWalletActions.UpdateSkipDataAndType: {
return {
...state,
Expand Down
13 changes: 1 addition & 12 deletions packages/neuron-ui/src/stories/GeneralSetting.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,16 @@
import React from 'react'
import { storiesOf } from '@storybook/react'
import { withKnobs, boolean } from '@storybook/addon-knobs'
import { withKnobs } from '@storybook/addon-knobs'
import GeneralSetting from 'components/GeneralSetting'
import initStates from 'states/initStates'

const states: { [title: string]: boolean } = {
'Show address book on': true,
'Show address book off': false,
}

const stories = storiesOf('GeneralSettings', module)

Object.entries(states).forEach(([title, showAddressBook]) => {
const props = { ...initStates, settings: { ...initStates.settings, showAddressBook }, dispatch: () => {} }
stories.add(title, () => <GeneralSetting {...props} />)
})

stories.addDecorator(withKnobs).add('With knobs', () => {
const props = {
...initStates,
settings: {
...initStates.settings,
showAddressBook: boolean('Show Address Book', false),
},
}
return <GeneralSetting {...props} dispatch={() => {}} />
Expand Down
1 change: 0 additions & 1 deletion packages/neuron-ui/src/types/App/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ declare namespace State {
interface Settings {
general: {
skipDataAndType: boolean
showAddressBook: boolean
}
networks: Network[]
wallets: WalletIdentity[]
Expand Down
2 changes: 1 addition & 1 deletion packages/neuron-ui/src/types/Subject/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ interface NeuronWalletSubject<T = any> {
}

declare namespace Command {
type Type = 'nav' | 'toggle-address-book' | 'delete-wallet' | 'backup-wallet'
type Type = 'nav' | 'delete-wallet' | 'backup-wallet'
type Payload = string | null
}

Expand Down
29 changes: 2 additions & 27 deletions packages/neuron-wallet/src/controllers/app/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,31 +186,6 @@ const updateApplicationMenu = (mainWindow: BrowserWindow | null) => {
],
}

const viewMenuItem: MenuItemConstructorOptions = {
id: 'view',
label: i18n.t('application-menu.view.label'),
submenu: [
{
label: i18n.t('application-menu.view.fullscreen'),
role: 'togglefullscreen',
},
{
label: i18n.t('application-menu.view.address-book'),
enabled: isMainWindow && hasCurrentWallet,
click: () => {
if (mainWindow) {
CommandSubject.next({
winID: mainWindow.id,
type: 'toggle-address-book',
payload: null,
})
}
},
accelerator: 'CmdOrCtrl+B',
},
],
}

const windowMenuItem: MenuItemConstructorOptions = {
id: 'window',
label: i18n.t('application-menu.window.label'),
Expand Down Expand Up @@ -289,8 +264,8 @@ const updateApplicationMenu = (mainWindow: BrowserWindow | null) => {
}

const applicationMenuTemplate = env.isDevMode
? [walletMenuItem, editMenuItem, viewMenuItem, developMenuItem, windowMenuItem, helpMenuItem]
: [walletMenuItem, editMenuItem, viewMenuItem, windowMenuItem, helpMenuItem]
? [walletMenuItem, editMenuItem, developMenuItem, windowMenuItem, helpMenuItem]
: [walletMenuItem, editMenuItem, windowMenuItem, helpMenuItem]

if (isMac) {
applicationMenuTemplate.unshift(appMenuItem)
Expand Down
5 changes: 0 additions & 5 deletions packages/neuron-wallet/src/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@ export default {
paste: 'Paste',
selectall: 'Select All',
},
view: {
label: 'View',
fullscreen: 'Enter Full Screen',
'address-book': 'Address Book',
},
window: {
label: 'Window',
minimize: 'Minimize',
Expand Down
5 changes: 0 additions & 5 deletions packages/neuron-wallet/src/locales/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@ export default {
paste: '粘贴',
selectall: '全部选中',
},
view: {
label: '视图',
fullscreen: '进入全屏模式',
'address-book': '地址簿',
},
window: {
label: '窗口',
minimize: '最小化',
Expand Down
2 changes: 1 addition & 1 deletion packages/neuron-wallet/src/models/subjects/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Subject } from 'rxjs'

const CommandSubject = new Subject<{
winID: number
type: 'nav' | 'toggle-address-book' | 'delete-wallet' | 'backup-wallet'
type: 'nav' | 'delete-wallet' | 'backup-wallet'
payload: string | null
}>()

Expand Down
24 changes: 5 additions & 19 deletions packages/neuron-wallet/tests-e2e/tests/addressBook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ import Application from '../application'
import { createWallet } from '../operations'

/**
* 1. toggle address book on
* 2. navigate to the address book
* 3. verify the count of receiving/changing addresses
* 4. verify default data of the first address
* 5. update description of the first address
* 6. refresh the view and verify the description
* 1. navigate to the address book
* 2. verify the count of receiving/changing addresses
* 3. verify default data of the first address
* 4. update description of the first address
* 5. refresh the view and verify the description
*/
export default (app: Application) => {
beforeAll(async () => {
Expand All @@ -21,19 +20,6 @@ export default (app: Application) => {
await app.waitUntilLoaded()
})

app.test('Toggle address book on', async () => {
const { client } = app.spectron
let addressTab = await client.$('button[name=Addresses]')
expect(addressTab.state).toBe('failure')
app.clickMenu(['View', 'Address Book'])
await app.waitUntilLoaded()
addressTab = await client.$('button[name=Addresses]')
expect(addressTab.state).not.toBe('failure')
client.click('button[name=Addresses]')
await app.waitUntilLoaded()
await app.wait(1000)
})

app.test('Address book should have 20 receiving addresses and 10 change addresses', async () => {
const { client } = app.spectron
const countOfReceivingAddresses = await client
Expand Down
Loading

0 comments on commit 940e23a

Please sign in to comment.