Browse Source

Merge branch 'master' into ledger-core-bump

master
Gaëtan Renaudeau 7 years ago
committed by GitHub
parent
commit
57bc906114
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 19
      src/components/MainSideBar/TopGradient.js
  2. 2
      src/components/MainSideBar/index.js
  3. 6
      src/components/SettingsPage/sections/Display.js
  4. 2
      src/helpers/db.js
  5. 15
      src/helpers/user.js
  6. 7
      src/init-sentry.js
  7. 9
      src/internals/index.js
  8. 21
      src/main/bridge.js
  9. 1
      src/main/index.js
  10. 14
      src/middlewares/sentry.js
  11. 3
      src/reducers/settings.js
  12. 4
      src/renderer/createStore.js
  13. 11
      src/renderer/index.js
  14. 4
      src/renderer/init.js
  15. 9
      src/sentry/browser.js
  16. 24
      src/sentry/install.js
  17. 8
      src/sentry/node.js
  18. 3
      webpack/plugins.js

19
src/components/MainSideBar/TopGradient.js

@ -0,0 +1,19 @@
// @flow
import React from 'react'
import styled from 'styled-components'
const TopGradientBox = styled.div`
width: 100%;
height: 80px;
position: absolute;
top: 0;
left: 0;
background: linear-gradient(#ffffff 40%, rgba(255, 255, 255, 0));
z-index: 2;
pointer-events: none;
`
const el = <TopGradientBox />
export default () => el

2
src/components/MainSideBar/index.js

@ -32,6 +32,7 @@ import IconExchange from 'icons/Exchange'
import AccountListItem from './AccountListItem'
import AddAccountButton from './AddAccountButton'
import TopGradient from './TopGradient'
const mapStateToProps = state => ({
accounts: accountsSelector(state),
@ -84,6 +85,7 @@ class MainSideBar extends PureComponent<Props> {
return (
<Box relative bg="white" style={{ width: 230 }}>
<TopGradient />
<GrowScroll>
<Space of={70} />
<SideBarList title={t('app:sidebar.menu')}>

6
src/components/SettingsPage/sections/Display.js

@ -173,12 +173,6 @@ class TabProfile extends PureComponent<Props, State> {
/>
</Box>
</Row>
<Row
title={t('app:settings.display.exchange', {
ticker: `${intermediaryCurrency.ticker}${counterValueCurrency.ticker}`,
})}
desc={t('app:settings.display.exchangeDesc')}
/>
<Row
title={t('app:settings.display.language')}
desc={t('app:settings.display.languageDesc')}

2
src/helpers/db.js

@ -6,7 +6,7 @@ import get from 'lodash/get'
import { decodeAccountsModel, encodeAccountsModel } from 'reducers/accounts'
type DBKey = 'settings' | 'accounts' | 'countervalues'
type DBKey = 'settings' | 'accounts' | 'countervalues' | 'user'
const encryptionKey = {}

15
src/helpers/user.js

@ -0,0 +1,15 @@
// @flow
import db from 'helpers/db'
import uuid from 'uuid/v4'
// a user is an anonymous way to identify a same instance of the app
export default () => {
let user = db.get('user')
if (!user) {
user = { id: uuid() }
db.set('user', user)
}
return user
}

7
src/init-sentry.js

@ -1,7 +0,0 @@
const { SENTRY_URL } = process.env
if (__PROD__ && SENTRY_URL) {
const Raven = require('raven')
const ravenConfig = { captureUnhandledRejections: true }
Raven.config(SENTRY_URL, ravenConfig).install()
}

9
src/internals/index.js

@ -3,14 +3,18 @@ import commands from 'commands'
import logger from 'logger'
import uuid from 'uuid/v4'
import { setImplementation } from 'api/network'
import sentry from 'sentry/node'
require('../env')
require('../init-sentry')
process.title = 'Internal'
const defers = {}
let sentryEnabled = process.env.INITIAL_SENTRY_ENABLED || false
sentry(() => sentryEnabled, process.env.SENTRY_USER_ID)
if (process.env.DEBUG_NETWORK) {
setImplementation(networkArg => {
const id = uuid()
@ -92,6 +96,9 @@ process.on('message', m => {
} else {
defer.reject(payload.error)
}
} else if (m.type === 'sentryLogsChanged') {
const { payload } = m
sentryEnabled = payload.value
}
})

21
src/main/bridge.js

@ -7,6 +7,8 @@ import { ipcMain, app } from 'electron'
import { ipcMainListenReceiveCommands } from 'helpers/ipc'
import path from 'path'
import logger from 'logger'
import sentry from 'sentry/node'
import user from 'helpers/user'
import setupAutoUpdater, { quitAndInstall } from './autoUpdate'
@ -17,6 +19,11 @@ const LEDGER_LIVE_SQLITE_PATH = path.resolve(app.getPath('userData'), 'sqlite')
let internalProcess
let sentryEnabled = false
const userId = user().id
sentry(() => sentryEnabled, userId)
const killInternalProcess = () => {
if (internalProcess) {
logger.log('killing internal process...')
@ -30,7 +37,12 @@ const forkBundlePath = path.resolve(__dirname, `${__DEV__ ? '../../' : './'}dist
const bootInternalProcess = () => {
logger.log('booting internal process...')
internalProcess = fork(forkBundlePath, {
env: { ...process.env, LEDGER_LIVE_SQLITE_PATH },
env: {
...process.env,
LEDGER_LIVE_SQLITE_PATH,
INITIAL_SENTRY_ENABLED: sentryEnabled,
SENTRY_USER_ID: userId,
},
})
internalProcess.on('message', handleGlobalInternalMessage)
internalProcess.on('exit', code => {
@ -102,6 +114,13 @@ ipcMain.on('executeHttpQueryPayload', (event, payload) => {
p.send({ type: 'executeHttpQueryPayload', payload })
})
ipcMain.on('sentryLogsChanged', (event, payload) => {
sentryEnabled = payload.value
const p = internalProcess
if (!p) return
p.send({ type: 'sentryLogsChanged', payload })
})
// TODO move this to "command" pattern
ipcMain.on('updater', (event, { type, data }) => {
const handler = {

1
src/main/index.js

@ -4,7 +4,6 @@ process.setMaxListeners(0)
require('../env')
require('../globals')
require('../init-sentry')
require('./app')
setImmediate(() => require('./bridge'))

14
src/middlewares/sentry.js

@ -0,0 +1,14 @@
import { ipcRenderer } from 'electron'
import { sentryLogsBooleanSelector } from 'reducers/settings'
let isSentryInstalled = false
export default store => next => action => {
next(action)
const state = store.getState()
const sentryLogs = sentryLogsBooleanSelector(state)
if (sentryLogs !== isSentryInstalled) {
isSentryInstalled = sentryLogs
ipcRenderer.send('sentryLogsChanged', { value: sentryLogs })
}
}

3
src/reducers/settings.js

@ -73,7 +73,7 @@ const INITIAL_STATE: SettingsState = {
developerMode: !!process.env.__DEV__,
loaded: false,
shareAnalytics: false,
sentryLogs: false,
sentryLogs: true,
lastUsedVersion: __APP_VERSION__,
}
@ -214,5 +214,6 @@ export const exchangeSettingsForAccountSelector: ESFAS = createSelector(
)
export const marketIndicatorSelector = (state: State) => state.settings.marketIndicator
export const sentryLogsBooleanSelector = (state: State) => state.settings.sentryLogs
export default handleActions(handlers, INITIAL_STATE)

4
src/renderer/createStore.js

@ -6,7 +6,7 @@ import thunk from 'redux-thunk'
import createHistory from 'history/createHashHistory'
import type { HashHistory } from 'history'
import logger from 'middlewares/logger'
import sentry from 'middlewares/sentry'
import reducers from 'reducers'
type Props = {
@ -20,7 +20,7 @@ export default ({ state, history, dbMiddleware }: Props) => {
if (!history) {
history = createHistory()
}
const middlewares = [routerMiddleware(history), thunk, logger]
const middlewares = [routerMiddleware(history), thunk, logger, sentry]
if (dbMiddleware) {
middlewares.push(dbMiddleware)
}

11
src/renderer/index.js

@ -1,14 +1,3 @@
require('@babel/polyfill')
const Raven = require('raven-js')
require('../env')
const { SENTRY_URL } = process.env
if (__PROD__ && SENTRY_URL) {
Raven.config(SENTRY_URL, { allowSecretKey: true }).install()
window.addEventListener('unhandledrejection', event => Raven.captureException(event.reason))
}
require('./init')

4
src/renderer/init.js

@ -14,7 +14,7 @@ import events from 'renderer/events'
import { fetchAccounts } from 'actions/accounts'
import { fetchSettings } from 'actions/settings'
import { isLocked } from 'reducers/application'
import { getLanguage } from 'reducers/settings'
import { getLanguage, sentryLogsBooleanSelector } from 'reducers/settings'
import libcoreGetVersion from 'commands/libcoreGetVersion'
import db from 'helpers/db'
@ -22,6 +22,7 @@ import dbMiddleware from 'middlewares/db'
import CounterValues from 'helpers/countervalues'
import hardReset from 'helpers/hardReset'
import sentry from 'sentry/browser'
import App from 'components/App'
import 'styles/global'
@ -50,6 +51,7 @@ async function init() {
const state = store.getState()
const language = getLanguage(state)
const locked = isLocked(state)
sentry(() => sentryLogsBooleanSelector(store.getState()))
moment.locale(language)

9
src/sentry/browser.js

@ -0,0 +1,9 @@
// @flow
import Raven from 'raven-js'
import user from 'helpers/user'
import install from './install'
export default (shouldSendCallback: () => boolean) => {
install(Raven, shouldSendCallback, user().id)
}

24
src/sentry/install.js

@ -0,0 +1,24 @@
// @flow
require('../env')
export default (Raven: any, shouldSendCallback: () => boolean, userId: string) => {
if (!__SENTRY_URL__) return
let r = Raven.config(__SENTRY_URL__, {
captureUnhandledRejections: true,
allowSecretKey: true,
release: __APP_VERSION__,
environment: __DEV__ ? 'development' : 'production',
shouldSendCallback,
})
const user = {
ip_address: null,
id: userId,
}
if (r.setUserContext) {
r = r.setUserContext(user)
} else if (r.setContext) {
r = r.setContext({ user })
}
r.install()
}

8
src/sentry/node.js

@ -0,0 +1,8 @@
// @flow
import Raven from 'raven'
import install from './install'
export default (shouldSendCallback: () => boolean, userId: string) => {
install(Raven, shouldSendCallback, userId)
}

3
webpack/plugins.js

@ -3,7 +3,7 @@ const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer')
const pkg = require('../package.json')
require('../src/globals')
const { BUNDLE_ANALYZER } = process.env
const { BUNDLE_ANALYZER, SENTRY_URL } = process.env
module.exports = type => {
const plugins = [
@ -12,6 +12,7 @@ module.exports = type => {
__GLOBAL_STYLES__: JSON.stringify(__GLOBAL_STYLES__),
__DEV__,
__PROD__,
__SENTRY_URL__: JSON.stringify(SENTRY_URL || null),
'process.env.NODE_ENV': JSON.stringify(__ENV__),
}),
]

Loading…
Cancel
Save