Browse Source

Merge pull request #129 from loeck/master

Add debug with lwd*, add start and stop sync in DevTools
master
Meriadec Pillet 7 years ago
committed by GitHub
parent
commit
a29775901b
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 15
      package.json
  2. 2
      scripts/start.sh
  3. 39
      src/components/DevTools.js
  4. 4
      src/components/layout/Dev.js
  5. 41
      src/renderer/events.js

15
package.json

@ -40,17 +40,17 @@
"webpack-sources": "1.0.1"
},
"dependencies": {
"@fortawesome/fontawesome": "^1.1.3",
"@fortawesome/fontawesome-free-brands": "^5.0.6",
"@fortawesome/fontawesome-free-regular": "^5.0.6",
"@fortawesome/fontawesome-free-solid": "^5.0.6",
"@fortawesome/fontawesome": "^1.1.3",
"@fortawesome/react-fontawesome": "^0.0.17",
"@ledgerhq/common": "2.3.0",
"@ledgerhq/currencies": "^2.3.0",
"@ledgerhq/hw-app-btc": "^4.0.0",
"@ledgerhq/hw-app-eth": "^4.0.0",
"@ledgerhq/hw-transport": "^4.0.0",
"@ledgerhq/hw-transport-node-hid": "^4.0.0",
"@ledgerhq/hw-transport": "^4.0.0",
"axios": "^0.17.1",
"babel-runtime": "^6.26.0",
"bcryptjs": "^2.4.3",
@ -58,35 +58,36 @@
"bs58check": "^2.1.1",
"color": "^3.0.0",
"cross-env": "^5.1.3",
"debug": "^3.1.0",
"downshift": "^1.28.0",
"electron-store": "^1.3.0",
"electron-updater": "^2.20.1",
"fuse.js": "^3.2.0",
"history": "^4.7.2",
"i18next": "^10.2.2",
"i18next-node-fs-backend": "^1.0.0",
"i18next": "^10.2.2",
"lodash": "^4.17.5",
"moment": "^2.20.1",
"object-path": "^0.11.4",
"qrcode": "^1.2.0",
"query-string": "^5.1.0",
"raven": "^2.4.1",
"raven-js": "^3.22.3",
"react": "^16.2.0",
"raven": "^2.4.1",
"react-dom": "^16.2.0",
"react-i18next": "^7.3.6",
"react-mortal": "^3.2.0",
"react-motion": "^0.5.2",
"react-qr-reader": "^2.0.1",
"react-redux": "^5.0.6",
"react-router": "^4.2.0",
"react-router-dom": "^4.2.2",
"react-router-redux": "5.0.0-alpha.9",
"react-router": "^4.2.0",
"react-smooth-scrollbar": "^8.0.6",
"react": "^16.2.0",
"recharts": "^1.0.0-beta.10",
"redux": "^3.7.2",
"redux-actions": "^2.2.1",
"redux-thunk": "^2.2.0",
"redux": "^3.7.2",
"smooth-scrollbar": "^8.2.6",
"source-map-support": "^0.5.3",
"styled-components": "^3.1.6",

2
scripts/start.sh

@ -2,4 +2,4 @@
concurrently --raw \
"cross-env NODE_ENV=development webpack --watch --config webpack/internals.config.js" \
"cross-env NODE_ENV=development electron-webpack dev"
"cross-env DEBUG=lwd* NODE_ENV=development electron-webpack dev"

39
src/components/DevToolbar.js → src/components/DevTools.js

@ -116,7 +116,7 @@ type State = {
cpuUsage: Object,
}
class DevToolbar extends PureComponent<any, State> {
class DevTools extends PureComponent<any, State> {
state = {
cpuUsage: {},
}
@ -155,20 +155,22 @@ class DevToolbar extends PureComponent<any, State> {
})
}
handleStartSync = () =>
mainWindow.webContents.send('msg', {
type: 'accounts.sync.start',
})
handleStopSync = () =>
mainWindow.webContents.send('msg', {
type: 'accounts.sync.stop',
})
render() {
const { cpuUsage } = this.state
return (
<Container>
<Box grow flow={4}>
<Section title="Languages" horizontal>
{languages.map(lang => (
<Item key={lang} onClick={this.handleChangeLanguage(lang)} style={{ flex: 0 }}>
{lang}
</Item>
))}
</Section>
<Bar size={2} color="white" />
<Section title="Colors">
{chunk(colors, 5).map((c, i) => (
<Items
@ -215,6 +217,23 @@ class DevToolbar extends PureComponent<any, State> {
))}
</Section>
<Bar size={2} color="white" />
<Section title="Languages" horizontal>
{languages.map(lang => (
<Item key={lang} onClick={this.handleChangeLanguage(lang)} style={{ flex: 0 }}>
{lang}
</Item>
))}
</Section>
<Bar size={2} color="white" />
<Section title="Sync Accounts" horizontal>
<Item onClick={this.handleStartSync} style={{ flex: 0 }}>
Start
</Item>
<Item onClick={this.handleStopSync} style={{ flex: 0 }}>
Stop
</Item>
</Section>
<Bar size={2} color="white" />
<Section title="CPU Usage">
{chunk(Object.keys(cpuUsage).sort(), 2).map((l, i) => (
<Items
@ -284,4 +303,4 @@ Section.defaultProps = {
horizontal: false,
}
export default translate()(DevToolbar)
export default translate()(DevTools)

4
src/components/layout/Dev.js

@ -6,7 +6,7 @@ import styled from 'styled-components'
import Box from 'components/base/Box'
import GrowScroll from 'components/base/GrowScroll'
import DevToolbar from 'components/DevToolbar'
import DevTools from 'components/DevTools'
const Container = styled(Box).attrs({
grow: true,
@ -19,7 +19,7 @@ class Dev extends PureComponent<{}> {
return (
<Container>
<GrowScroll>
<DevToolbar />
<DevTools />
</GrowScroll>
</Container>
)

41
src/renderer/events.js

@ -4,6 +4,7 @@ import { ipcRenderer } from 'electron'
import objectPath from 'object-path'
import get from 'lodash/get'
import uniqBy from 'lodash/uniqBy'
import debug from 'debug'
import type { Accounts } from 'types/common'
@ -12,10 +13,17 @@ import { CHECK_UPDATE_TIMEOUT, SYNC_ACCOUNT_TIMEOUT } from 'constants'
import { updateDevices, addDevice, removeDevice } from 'actions/devices'
import { updateAccount } from 'actions/accounts'
import { setUpdateStatus } from 'reducers/update'
import { getAccountData, getAccounts } from 'reducers/accounts'
import { getAccountData, getAccounts, getAccountById } from 'reducers/accounts'
import { isLocked } from 'reducers/application'
import i18n from 'renderer/i18n'
const d = {
device: debug('lwd:device'),
sync: debug('lwd:sync'),
update: debug('lwd:update'),
}
const { DISABLED_SYNC, DISABLED_AUTO_SYNC } = process.env
type MsgPayload = {
@ -41,6 +49,7 @@ export function sendSyncEvent(channel: string, msgType: string, data: any): any
}
export function startSyncAccounts(accounts: Accounts) {
d.sync('Sync accounts - start')
syncAccounts = true
sendEvent('accounts', 'sync.all', {
accounts: accounts.map(account => {
@ -56,11 +65,13 @@ export function startSyncAccounts(accounts: Accounts) {
}
export function stopSyncAccounts() {
d.sync('Sync accounts - stop')
syncAccounts = false
clearTimeout(syncTimeout)
}
export function checkUpdates() {
d.update('Update - check')
setTimeout(() => sendEvent('msg', 'updater.init'), CHECK_UPDATE_TIMEOUT)
}
@ -74,7 +85,9 @@ export default ({ store, locked }: { store: Object, locked: boolean }) => {
sync: {
success: account => {
if (syncAccounts) {
const currentAccountData = getAccountData(store.getState(), account.id) || {}
const state = store.getState()
const currentAccount = getAccountById(state, account.id) || {}
const currentAccountData = getAccountData(state, account.id) || {}
const currentAccountTransactions = get(currentAccountData, 'transactions', [])
const transactions = uniqBy(
@ -83,6 +96,7 @@ export default ({ store, locked }: { store: Object, locked: boolean }) => {
)
if (currentAccountTransactions.length !== transactions.length) {
d.sync(`Update account - ${currentAccount.name}`)
store.dispatch(
updateAccount({
...account,
@ -99,8 +113,21 @@ export default ({ store, locked }: { store: Object, locked: boolean }) => {
},
accounts: {
sync: {
start: () => {
if (!syncAccounts) {
const state = store.getState()
const accounts = getAccounts(state)
const locked = isLocked(state)
if (!locked && !DISABLED_SYNC) {
startSyncAccounts(accounts)
}
}
},
stop: stopSyncAccounts,
success: () => {
if (syncAccounts && !DISABLED_AUTO_SYNC) {
d.sync('Sync accounts - success')
syncTimeout = setTimeout(() => {
const accounts = getAccounts(store.getState())
startSyncAccounts(accounts)
@ -115,8 +142,14 @@ export default ({ store, locked }: { store: Object, locked: boolean }) => {
},
},
device: {
add: device => store.dispatch(addDevice(device)),
remove: device => store.dispatch(removeDevice(device)),
add: device => {
d.device('Device - add')
store.dispatch(addDevice(device))
},
remove: device => {
d.device('Device - remove')
store.dispatch(removeDevice(device))
},
},
updater: {
checking: () => store.dispatch(setUpdateStatus('checking')),

Loading…
Cancel
Save