Browse Source

Merge branch 'master' into remove-libcore-queue

master
Gaëtan Renaudeau 7 years ago
committed by GitHub
parent
commit
3c6efe38f2
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      scripts/release.sh
  2. 6
      src/api/Ledger.js
  3. 5
      src/commands/libcoreSignAndBroadcast.js
  4. 3
      src/components/EnsureDeviceApp/index.js
  5. 7
      src/components/layout/Default.js
  6. 3
      src/components/modals/Receive/index.js
  7. 2
      src/config/constants.js
  8. 7
      src/helpers/bip32.js
  9. 3
      src/helpers/deviceAccess.js
  10. 3
      src/helpers/libcore.js
  11. 74
      src/main/app.js
  12. 4
      src/renderer/init.js

5
scripts/release.sh

@ -7,6 +7,11 @@ if [ -z "$GH_TOKEN" ]; then
exit 1
fi
if [ ! -d "static/fonts/museosans" ]; then
echo "static/fonts/museosans is required for a release" >&2
exit 1
fi
if ! git diff-index --quiet HEAD --; then
echo "you have uncommitted local changes!" >&2
exit 1

6
src/api/Ledger.js

@ -11,14 +11,14 @@ export const userFriendlyError = <A>(p: Promise<A>): Promise<A> =>
// that falls out of the range of 2xx
const { data } = error.response
if (data && typeof data.error === 'string') {
const msg = data.error || data.message
let msg = data.error || data.message
if (typeof msg === 'string') {
const m = msg.match(/^JsDefined\((.*)\)$/)
if (m) {
try {
const { message } = JSON.parse(m[1])
if (typeof message === 'string') {
throw new Error(message)
msg = message
}
} catch (e) {
logger.warn("can't parse server result", e)
@ -28,7 +28,7 @@ export const userFriendlyError = <A>(p: Promise<A>): Promise<A> =>
}
}
logger.log('Ledger API: HTTP status', error.response.status, 'data: ', error.response.data)
throw new Error('A problem occurred with Ledger Servers. Please try again later.')
throw new Error('A problem occurred with Ledger API. Please try again later.')
} else if (error.request) {
// The request was made but no response was received
// `error.request` is an instance of XMLHttpRequest in the browser and an instance of

5
src/commands/libcoreSignAndBroadcast.js

@ -5,6 +5,7 @@ import type { AccountRaw, OperationRaw } from '@ledgerhq/live-common/lib/types'
import Btc from '@ledgerhq/hw-app-btc'
import { Observable } from 'rxjs'
import { getCryptoCurrencyById } from '@ledgerhq/live-common/lib/helpers/currencies'
import { isSegwitAccount } from 'helpers/bip32'
import withLibcore from 'helpers/withLibcore'
import { createCommand, Command } from 'helpers/ipc'
@ -158,7 +159,7 @@ export async function doSignAndBroadcast({
const WALLET_IDENTIFIER = await getWalletIdentifier({
hwApp,
isSegwit: !!account.isSegwit,
isSegwit: isSegwitAccount(account),
currencyId: account.currencyId,
devicePath: deviceId,
})
@ -197,7 +198,7 @@ export async function doSignAndBroadcast({
transaction: builded,
sigHashType: parseInt(sigHashType, 16),
supportsSegwit: !!currency.supportsSegwit,
isSegwit: !!account.isSegwit,
isSegwit: isSegwitAccount(account),
hasTimestamp,
})
})

3
src/components/EnsureDeviceApp/index.js

@ -2,6 +2,7 @@
import { PureComponent } from 'react'
import { connect } from 'react-redux'
import logger from 'logger'
import { isSegwitAccount } from 'helpers/bip32'
import type { Account, CryptoCurrency } from '@ledgerhq/live-common/lib/types'
import type { Device } from 'types/common'
@ -121,7 +122,7 @@ class EnsureDeviceApp extends PureComponent<Props, State> {
devicePath: deviceSelected.path,
currencyId: account.currency.id,
path: account.freshAddressPath,
segwit: !!account.isSegwit,
segwit: isSegwitAccount(account),
})
.toPromise()
const { freshAddress } = account

7
src/components/layout/Default.js

@ -2,7 +2,6 @@
import React, { Fragment, Component } from 'react'
import { compose } from 'redux'
import { ipcRenderer } from 'electron'
import styled from 'styled-components'
import { Route, withRouter } from 'react-router'
import { translate } from 'react-i18next'
@ -39,12 +38,6 @@ class Default extends Component<Props> {
window.requestAnimationFrame(() => (this._timeout = setTimeout(() => window.onAppReady(), 300)))
}
componentWillReceiveProps(nextProps: Props) {
if (process.platform === 'darwin' && nextProps.location !== this.props.location) {
ipcRenderer.send('touch-bar-update', { clear: true })
}
}
componentDidUpdate(prevProps) {
if (this.props.location !== prevProps.location) {
if (this._scrollContainer) {

3
src/components/modals/Receive/index.js

@ -7,6 +7,7 @@ import type { Account } from '@ledgerhq/live-common/lib/types'
import type { T, Device } from 'types/common'
import { MODAL_RECEIVE } from 'config/constants'
import { isSegwitAccount } from 'helpers/bip32'
import getAddress from 'commands/getAddress'
import SyncSkipUnderPriority from 'components/SyncSkipUnderPriority'
@ -202,7 +203,7 @@ class ReceiveModal extends PureComponent<Props, State> {
currencyId: account.currency.id,
devicePath: device.path,
path: account.freshAddressPath,
segwit: !!account.isSegwit,
segwit: isSegwitAccount(account),
verify: true,
})
.toPromise()

2
src/config/constants.js

@ -14,7 +14,7 @@ export const CHECK_APP_INTERVAL_WHEN_INVALID = 600
export const CHECK_APP_INTERVAL_WHEN_VALID = 1200
export const CHECK_UPDATE_DELAY = 5e3
export const DEVICE_DISCONNECT_DEBOUNCE = intFromEnv('LEDGER_DEVICE_DISCONNECT_DEBOUNCE', 1000)
export const DEVICE_DISCONNECT_DEBOUNCE = intFromEnv('LEDGER_DEVICE_DISCONNECT_DEBOUNCE', 500)
export const MODAL_ADD_ACCOUNT = 'MODAL_ADD_ACCOUNT'
export const MODAL_OPERATION_DETAILS = 'MODAL_OPERATION_DETAILS'

7
src/helpers/bip32.js

@ -0,0 +1,7 @@
// @flow
import type { Account, AccountRaw } from '@ledgerhq/live-common/lib/types'
export const isSegwitPath = (path: string): boolean => path.startsWith("49'")
export const isSegwitAccount = (account: Account | AccountRaw): boolean =>
isSegwitPath(account.freshAddressPath)

3
src/helpers/deviceAccess.js

@ -2,6 +2,7 @@
import createSemaphore from 'semaphore'
import type Transport from '@ledgerhq/hw-transport'
import TransportNodeHid from '@ledgerhq/hw-transport-node-hid'
import { retry } from './promise'
// all open to device must use openDevice so we can prevent race conditions
// and guarantee we do one device access at a time. It also will handle the .close()
@ -17,7 +18,7 @@ export const withDevice: WithDevice = devicePath => {
return job =>
takeSemaphorePromise(sem, async () => {
const t = await TransportNodeHid.open(devicePath)
const t = await retry(() => TransportNodeHid.open(devicePath), { maxRetry: 1 })
try {
const res = await job(t)
// $FlowFixMe

3
src/helpers/libcore.js

@ -8,6 +8,7 @@ import { getCryptoCurrencyById } from '@ledgerhq/live-common/lib/helpers/currenc
import type { AccountRaw, OperationRaw, OperationType } from '@ledgerhq/live-common/lib/types'
import type { NJSAccount, NJSOperation } from '@ledgerhq/ledger-core/src/ledgercore_doc'
import { isSegwitAccount } from 'helpers/bip32'
import * as accountIdHelper from 'helpers/accountId'
import { getAccountPlaceholderName, getNewAccountPlaceholderName } from './accountName'
@ -368,7 +369,7 @@ export async function syncAccount({
const syncedRawAccount = await buildAccountRaw({
njsAccount,
isSegwit: rawAccount.isSegwit === true,
isSegwit: isSegwitAccount(rawAccount),
accountIndex: rawAccount.index,
wallet: njsWallet,
currencyId: rawAccount.currencyId,

74
src/main/app.js

@ -1,15 +1,11 @@
// @flow
import { app, BrowserWindow, Menu, screen, TouchBar, ipcMain } from 'electron'
import { app, BrowserWindow, Menu, screen } from 'electron'
import debounce from 'lodash/debounce'
import menu from 'main/menu'
import db from 'helpers/db'
import { MODAL_RECEIVE, MODAL_SEND } from 'config/constants'
const { TouchBarButton, TouchBarGroup, TouchBarLabel } = TouchBar
// necessary to prevent win from being garbage collected
let mainWindow = null
@ -59,70 +55,6 @@ const saveWindowSettings = window => {
)
}
function configureTouchBar(w) {
const defaultItems = [
new TouchBarButton({
label: 'Send funds',
click: () =>
w.webContents.send('msg', {
type: 'dispatch',
data: { type: 'MODAL_OPEN', payload: { name: MODAL_SEND } },
}),
}),
new TouchBarButton({
label: 'Receive funds',
click: () =>
w.webContents.send('msg', {
type: 'dispatch',
data: { type: 'MODAL_OPEN', payload: { name: MODAL_RECEIVE } },
}),
}),
]
w.setTouchBar(new TouchBar(defaultItems))
ipcMain.on('touch-bar-update', (e, d) => {
if (d.clear) {
w.setTouchBar(new TouchBar(defaultItems))
return
}
const items = [
new TouchBarLabel({
textColor: d.color,
label: d.text,
}),
]
if (d.balance.currency) {
items.push(
new TouchBarLabel({
textColor: d.color,
label: d.balance.currency,
}),
)
}
if (d.balance.counterValue) {
items.push(
new TouchBarLabel({
textColor: d.color,
label: d.balance.counterValue,
}),
)
}
w.setTouchBar(
new TouchBar([
...defaultItems,
new TouchBarGroup({
items,
}),
]),
)
})
}
const defaultWindowOptions = {
backgroundColor: '#fff',
webPreferences: {
@ -191,10 +123,6 @@ function createMainWindow() {
})
})
if (process.platform === 'darwin') {
configureTouchBar(window)
}
return window
}

4
src/renderer/init.js

@ -2,7 +2,7 @@
import logger from 'logger'
import React from 'react'
import { remote } from 'electron'
import { remote, webFrame } from 'electron'
import { render } from 'react-dom'
import { AppContainer } from 'react-hot-loader'
import createHistory from 'history/createHashHistory'
@ -71,6 +71,8 @@ async function init() {
// Only init events on MainWindow
if (isMainWindow) {
webFrame.setVisualZoomLevelLimits(1, 1)
events({ store, locked })
const libcoreVersion = await libcoreGetVersion.send().toPromise()

Loading…
Cancel
Save