Skip to content

Commit

Permalink
chore: set max length to 120 and object imported to multiline
Browse files Browse the repository at this point in the history
  • Loading branch information
Keith-CY committed Feb 20, 2019
1 parent b515a0e commit 85566b1
Show file tree
Hide file tree
Showing 15 changed files with 137 additions and 90 deletions.
5 changes: 3 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ insert_final_newline = true
# Use 4 spaces for the Python files
[*.py]
indent_size = 4
max_line_length = 80
max_line_length = 120

# The JSON files contain newlines inconsistently
[*.json]
Expand All @@ -21,12 +21,13 @@ insert_final_newline = ignore
# The JavaScript file
[*.js]
indent_size = 2
max_line_length = 80
max_line_length = 120

# The TypeScript file
[*.{ts,tsx}]
indent_size = 2
trim_trailing_whitespace = true
max_line_length = 120

# Minified JavaScript files shouldn't be changed
[**.min.js]
Expand Down
27 changes: 26 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ module.exports = {
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"rules": {
"prettier/prettier": [2, {
"printWidth": 120
}],
"semi": [2, "never"],
"comma-dangle": [2, {
"arrays": "always-multiline",
Expand All @@ -22,7 +25,29 @@ module.exports = {
"ignoreRestSiblings": false
}],
"operator-linebreak": [2, "after"],
"arrow-parens": [2, "as-needed"]
"arrow-parens": [2, "as-needed"],
"max-len": [2, {
"code": 120,
"ignoreComments": true,
"ignoreTrailingComments": true,
"ignoreUrls": true,
"ignoreStrings": true,
"ignoreTemplateLiterals": true,
"ignoreRegExpLiterals": true,
}],
"object-curly-newline": ["error", {
"ObjectExpression": "always",
"ObjectPattern": {
"multiline": true
},
"ImportDeclaration": {
"consistent": true,
},
"ExportDeclaration": {
"multiline": true,
"minProperties": 3
}
}]
},
"env": {
"jest": true,
Expand Down
12 changes: 5 additions & 7 deletions packages/neuron-ui/public/manifest.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
{
"short_name": "Neuron",
"name": "CKB Neuron Wallet",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
}
],
"icons": [{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
}],
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
Expand Down
16 changes: 13 additions & 3 deletions packages/neuron-ui/src/components/ActionFlow/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,13 @@ ActionStep.displayName = 'ActionStep'

const renderHeader = (child: ActionStep, i: number) => (
<ActionFlowHeaderStyle key={i}>
<div style={{ margin: '0 auto' }}>{i}</div>
<div
style={{
margin: '0 auto',
}}
>
{i}
</div>
<div>{child.props.title}</div>
</ActionFlowHeaderStyle>
)
Expand All @@ -83,7 +89,9 @@ const ActionFlow = ({ children }: { children: Array<ActionStep> }) => {
<div className="actionFlowBody">{children[step - 1]}</div>
<div className="actionFlowFooter">
<button
style={{ float: 'left' }}
style={{
float: 'left',
}}
type="button"
onKeyPress={() => {
// for users with physical disabilities who cannot use a mouse
Expand All @@ -100,7 +108,9 @@ const ActionFlow = ({ children }: { children: Array<ActionStep> }) => {
Back
</button>
<button
style={{ float: 'right' }}
style={{
float: 'right',
}}
type="button"
onKeyPress={() => {
// for users with physical disabilities who cannot use a mouse
Expand Down
9 changes: 6 additions & 3 deletions packages/neuron-ui/src/components/Network/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,16 @@ const NetworkStatusHeader = () => {
<Span>
<Status
style={{
color:
chain.network.status === NetworkStatus.Online ? 'green' : 'red',
color: chain.network.status === NetworkStatus.Online ? 'green' : 'red',
}}
/>
</Span>
<Span>{chain.network.ip || 'Not Connected'}</Span>
<Span style={{ display: chain.tipBlockNumber ? '' : 'none' }}>
<Span
style={{
display: chain.tipBlockNumber ? '' : 'none',
}}
>
{chain.tipBlockNumber || null}
</Span>
</FlexDiv>
Expand Down
37 changes: 18 additions & 19 deletions packages/neuron-ui/src/components/Providers/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import SettingsContext, { initSettings } from '../../contexts/settings'
import ipc, { ipcRenderer } from '../../utils/ipc'
import { Channel } from '../../utils/const'

const withProviders = (Comp: React.ComponentType) => (
props: React.Props<any>,
) => {
const withProviders = (Comp: React.ComponentType) => (props: React.Props<any>) => {
const [chain, setChain] = useState(initChain)
const [wallet, setWallet] = useState(initWallet)
const [settings] = useState(initSettings)
Expand All @@ -18,25 +16,26 @@ const withProviders = (Comp: React.ComponentType) => (
}, [])

ipcRenderer.on('ASW', (_e: any, args: { status: number; result: any }) => {
setWallet({ ...wallet, name: 'asw', wallet: args.result })
setWallet({
...wallet,
name: 'asw',
wallet: args.result,
})
})

ipcRenderer.on(
Channel.SendCapacity,
(_e: any, args: { status: number; msg: string }) => {
console.debug(args.msg)
},
)
ipcRenderer.on(Channel.SendCapacity, (_e: any, args: { status: number; msg: string }) => {
console.debug(args.msg)
})

ipcRenderer.on(
Channel.GetCellsByTypeHash,
(_e: Event, args: { status: number; result: ICell[] }) => {
// TODO:
if (args.status) {
setChain({ ...chain, cells: args.result })
}
},
)
ipcRenderer.on(Channel.GetCellsByTypeHash, (_e: Event, args: { status: number; result: ICell[] }) => {
// TODO:
if (args.status) {
setChain({
...chain,
cells: args.result,
})
}
})
return (
<SettingsContext.Provider value={settings}>
<ChainContext.Provider value={chain}>
Expand Down
37 changes: 22 additions & 15 deletions packages/neuron-ui/src/components/Transfer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,25 @@ interface Transfer {
submitting: boolean
}

const reducer = (
state: Transfer,
action: { type: TransferActionTypes; value?: any },
) => {
const reducer = (state: Transfer, action: { type: TransferActionTypes; value?: any }) => {
switch (action.type) {
case TransferActionTypes.Address: {
return { ...state, address: action.value }
return {
...state,
address: action.value,
}
}
case TransferActionTypes.Capacity: {
return { ...state, capacity: action.value }
return {
...state,
capacity: action.value,
}
}
case TransferActionTypes.Submit: {
return { ...state, submitting: true }
return {
...state,
submitting: true,
}
}
default: {
return state
Expand All @@ -82,26 +88,27 @@ const initState: Transfer = {
submitting: false,
}

function isMouseEvent(
e: React.ChangeEvent | React.MouseEvent,
): e is React.MouseEvent {
function isMouseEvent(e: React.ChangeEvent | React.MouseEvent): e is React.MouseEvent {
return e.type === 'click'
}

const Transfer = () => {
const [state, dispatch] = useReducer(reducer, initState)
const handleAction = (type: TransferActionTypes) => (
e:
| React.ChangeEvent<HTMLInputElement>
| React.MouseEvent<HTMLButtonElement>,
e: React.ChangeEvent<HTMLInputElement> | React.MouseEvent<HTMLButtonElement>,
) => {
if (type === TransferActionTypes.Submit) {
ipc.sendCapacity(state.address, state.capacity.toString(16))
}
if (isMouseEvent(e)) {
dispatch({ type })
dispatch({
type,
})
} else {
dispatch({ type, value: e.target.value ? e.target.value : '' })
dispatch({
type,
value: e.target.value ? e.target.value : '',
})
}
}

Expand Down
6 changes: 5 additions & 1 deletion packages/neuron-ui/src/components/WalletDetail/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ const WalletDetail = () => {
return wallet.name ? (
<>
<h1>{wallet.name}</h1>
<div style={{ height: '1200px' }}>
<div
style={{
height: '1200px',
}}
>
Simulate long content...
<div>{JSON.stringify(wallet)}</div>
</div>
Expand Down
14 changes: 11 additions & 3 deletions packages/neuron-ui/src/components/WalletWizard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,18 @@ export default (props: any) => {
}, [wallet && wallet.name])
return (
<Wizard>
<div style={{ textAlign: 'center' }}>
<div
style={{
textAlign: 'center',
}}
>
<Launch size="large" />
<h1>Create or import your first wallet</h1>
<div className="buttonGroup">
<button
style={{ float: 'left' }}
style={{
float: 'left',
}}
type="button"
onKeyPress={() => {
// for users with physical disabilities who cannot use a mouse
Expand All @@ -51,7 +57,9 @@ export default (props: any) => {
Create New Wallet
</button>
<button
style={{ float: 'right' }}
style={{
float: 'right',
}}
type="button"
onKeyPress={() => {
// for users with physical disabilities who cannot use a mouse
Expand Down
5 changes: 4 additions & 1 deletion packages/neuron-ui/src/containers/Sidebar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ const Sidebar = () => {

const walletRoutes = walletMenuItems.map(item => {
const entry = mainContents.find(route => route.name === item[0])!
return { icon: item[1], ...entry }
return {
icon: item[1],
...entry,
}
})
let menu
if (wallet) {
Expand Down
4 changes: 3 additions & 1 deletion packages/neuron-ui/src/setupTests.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { configure } from 'enzyme'
import Adapter from 'enzyme-adapter-react-16'

configure({ adapter: new Adapter() })
configure({
adapter: new Adapter(),
})

export default undefined
8 changes: 2 additions & 6 deletions packages/neuron-ui/src/utils/ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,10 @@ export const ipcRenderer = (() => {
}
return {
send: (channel: string, msg: any) => {
console.warn(
`Message: ${msg} to channel ${channel} failed due to Electron not loaded`,
)
console.warn(`Message: ${msg} to channel ${channel} failed due to Electron not loaded`)
},
on: (channel: string, cb: Function) => {
console.warn(
`Channel ${channel} and Function ${cb.toString()} failed due to Electron not laoded`,
)
console.warn(`Channel ${channel} and Function ${cb.toString()} failed due to Electron not laoded`)
},
}
})()
Expand Down
12 changes: 2 additions & 10 deletions packages/neuron-ui/src/widgets/Dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,9 @@ const Dialog = styled.dialog.attrs({
background-color: rgba(0, 0, 0, 0.7);
`

export default ({
children,
open,
}: {
children?: React.ReactNode | string
open?: boolean
}) => {
export default ({ children, open }: { children?: React.ReactNode | string; open?: boolean }) => {
if (open && children) {
return createPortal(<Dialog>{children}</Dialog>, document.querySelector(
'.modal',
) as HTMLElement)
return createPortal(<Dialog>{children}</Dialog>, document.querySelector('.modal') as HTMLElement)
}
return null
}
Loading

0 comments on commit 85566b1

Please sign in to comment.