Browse Source

Bump live-common + add fee + soft reset

master
Gaëtan Renaudeau 7 years ago
parent
commit
35f9050e56
  1. 2
      package.json
  2. 2
      src/actions/accounts.js
  3. 2
      src/actions/settings.js
  4. 9
      src/bridge/EthereumJSBridge.js
  5. 6
      src/bridge/RippleJSBridge.js
  6. 1
      src/commands/libcoreSignAndBroadcast.js
  7. 49
      src/components/SettingsPage/sections/Profile.js
  8. 15
      src/components/modals/OperationDetails.js
  9. 11
      src/helpers/db.js
  10. 2
      src/helpers/libcore.js
  11. 7
      src/reducers/accounts.js
  12. 13
      static/i18n/en/settings.yml
  13. 10
      yarn.lock

2
package.json

@ -42,7 +42,7 @@
"@ledgerhq/hw-transport": "^4.12.0", "@ledgerhq/hw-transport": "^4.12.0",
"@ledgerhq/hw-transport-node-hid": "^4.12.0", "@ledgerhq/hw-transport-node-hid": "^4.12.0",
"@ledgerhq/ledger-core": "1.4.1", "@ledgerhq/ledger-core": "1.4.1",
"@ledgerhq/live-common": "2.24.0", "@ledgerhq/live-common": "^2.25.0",
"axios": "^0.18.0", "axios": "^0.18.0",
"babel-runtime": "^6.26.0", "babel-runtime": "^6.26.0",
"bcryptjs": "^2.4.3", "bcryptjs": "^2.4.3",

2
src/actions/accounts.js

@ -85,3 +85,5 @@ export const updateAccount: UpdateAccount = payload => (dispatch, getState) => {
dispatch(updateOrderAccounts(orderAccounts)) dispatch(updateOrderAccounts(orderAccounts))
// TODO should not be here IMO.. feels wrong for perf, probably better to move in reducer too // TODO should not be here IMO.. feels wrong for perf, probably better to move in reducer too
} }
export const cleanAccountsCache = () => ({ type: 'CLEAN_ACCOUNTS_CACHE' })

2
src/actions/settings.js

@ -22,7 +22,7 @@ type SetExchangePairs = (
Array<{ Array<{
from: Currency, from: Currency,
to: Currency, to: Currency,
exchange: string, exchange: ?string,
}>, }>,
) => * ) => *

9
src/bridge/EthereumJSBridge.js

@ -49,12 +49,14 @@ const txToOps = (account: Account) => (tx: Tx): Operation[] => {
const sending = freshAddress === from const sending = freshAddress === from
const receiving = freshAddress === to const receiving = freshAddress === to
const ops = [] const ops = []
const fee = tx.gas_price * tx.gas_used
if (sending) { if (sending) {
ops.push({ ops.push({
id: `${account.id}-${tx.hash}-OUT`, id: `${account.id}-${tx.hash}-OUT`,
hash: tx.hash, hash: tx.hash,
type: 'OUT', type: 'OUT',
value: tx.value + tx.gas_price * tx.gas_used, value: tx.value,
fee,
blockHeight: tx.block && tx.block.height, blockHeight: tx.block && tx.block.height,
blockHash: tx.block && tx.block.hash, blockHash: tx.block && tx.block.hash,
accountId: account.id, accountId: account.id,
@ -69,6 +71,7 @@ const txToOps = (account: Account) => (tx: Tx): Operation[] => {
hash: tx.hash, hash: tx.hash,
type: 'IN', type: 'IN',
value: tx.value, value: tx.value,
fee,
blockHeight: tx.block && tx.block.height, blockHeight: tx.block && tx.block.height,
blockHash: tx.block && tx.block.hash, blockHash: tx.block && tx.block.hash,
accountId: account.id, accountId: account.id,
@ -131,13 +134,13 @@ const EthereumBridge: WalletBridge<Transaction> = {
if (finished) return { complete: true } if (finished) return { complete: true }
const freshAddress = address const freshAddress = address
const accountId = `ethereumjs:${currency.id}:${address}`
if (txs.length === 0) { if (txs.length === 0) {
// this is an empty account // this is an empty account
if (isStandard) { if (isStandard) {
if (newAccountCount === 0) { if (newAccountCount === 0) {
// first zero account will emit one account as opportunity to create a new account.. // first zero account will emit one account as opportunity to create a new account..
const accountId = `${currency.id}_${address}`
const account: $Exact<Account> = { const account: $Exact<Account> = {
id: accountId, id: accountId,
xpub: '', xpub: '',
@ -161,7 +164,6 @@ const EthereumBridge: WalletBridge<Transaction> = {
return { complete: true } return { complete: true }
} }
const accountId = `${currency.id}_${address}`
const account: $Exact<Account> = { const account: $Exact<Account> = {
id: accountId, id: accountId,
xpub: '', xpub: '',
@ -332,6 +334,7 @@ const EthereumBridge: WalletBridge<Transaction> = {
hash, hash,
type: 'OUT', type: 'OUT',
value: t.amount, value: t.amount,
fee: t.gasPrice * t.gasLimit,
blockHeight: null, blockHeight: null,
blockHash: null, blockHash: null,
accountId: a.id, accountId: a.id,

6
src/bridge/RippleJSBridge.js

@ -126,8 +126,8 @@ const txToOperation = (account: Account) => ({
}: Tx): Operation => { }: Tx): Operation => {
const type = source.address === account.freshAddress ? 'OUT' : 'IN' const type = source.address === account.freshAddress ? 'OUT' : 'IN'
let value = deliveredAmount ? parseAPICurrencyObject(deliveredAmount) : 0 let value = deliveredAmount ? parseAPICurrencyObject(deliveredAmount) : 0
const feeValue = parseAPIValue(fee)
if (type === 'OUT') { if (type === 'OUT') {
const feeValue = parseAPIValue(fee)
if (!isNaN(feeValue)) { if (!isNaN(feeValue)) {
value += feeValue value += feeValue
} }
@ -139,6 +139,7 @@ const txToOperation = (account: Account) => ({
accountId: account.id, accountId: account.id,
type, type,
value, value,
fee: feeValue,
blockHash: null, blockHash: null,
blockHeight: ledgerVersion, blockHeight: ledgerVersion,
senders: [source.address], senders: [source.address],
@ -193,7 +194,7 @@ const RippleJSBridge: WalletBridge<Transaction> = {
.toPromise() .toPromise()
if (finished) return if (finished) return
const accountId = `${currency.id}_${address}` const accountId = `ripplejs:${currency.id}:${address}`
let info let info
try { try {
@ -440,6 +441,7 @@ const RippleJSBridge: WalletBridge<Transaction> = {
accountId: a.id, accountId: a.id,
type: 'OUT', type: 'OUT',
value: t.amount, value: t.amount,
fee: t.fee,
blockHash: null, blockHash: null,
blockHeight: null, blockHeight: null,
senders: [a.freshAddress], senders: [a.freshAddress],

1
src/commands/libcoreSignAndBroadcast.js

@ -78,6 +78,7 @@ const cmd: Command<Input, Result> = createCommand(
hash: txHash, hash: txHash,
type: 'OUT', type: 'OUT',
value: amount, value: amount,
fee: 0,
blockHash: null, blockHash: null,
blockHeight: null, blockHeight: null,
senders: [account.freshAddress], senders: [account.freshAddress],

49
src/components/SettingsPage/sections/Profile.js

@ -5,12 +5,14 @@ import { connect } from 'react-redux'
import { remote } from 'electron' import { remote } from 'electron'
import bcrypt from 'bcryptjs' import bcrypt from 'bcryptjs'
import { cleanAccountsCache } from 'actions/accounts'
import { unlock } from 'reducers/application' // FIXME should be in actions
import db, { setEncryptionKey } from 'helpers/db'
import { delay } from 'helpers/promise'
import type { SettingsState } from 'reducers/settings' import type { SettingsState } from 'reducers/settings'
import type { T } from 'types/common' import type { T } from 'types/common'
import { unlock } from 'reducers/application'
import db, { setEncryptionKey } from 'helpers/db'
import CheckBox from 'components/base/CheckBox' import CheckBox from 'components/base/CheckBox'
import Box from 'components/base/Box' import Box from 'components/base/Box'
import Button from 'components/base/Button' import Button from 'components/base/Button'
@ -28,6 +30,7 @@ import {
const mapDispatchToProps = { const mapDispatchToProps = {
unlock, unlock,
cleanAccountsCache,
} }
type Props = { type Props = {
@ -35,10 +38,12 @@ type Props = {
settings: SettingsState, settings: SettingsState,
unlock: Function, unlock: Function,
saveSettings: Function, saveSettings: Function,
cleanAccountsCache: () => *,
} }
type State = { type State = {
isHardResetModalOpened: boolean, isHardResetModalOpened: boolean,
isSoftResetModalOpened: boolean,
isPasswordModalOpened: boolean, isPasswordModalOpened: boolean,
isDisablePasswordModalOpened: boolean, isDisablePasswordModalOpened: boolean,
} }
@ -46,6 +51,7 @@ type State = {
class TabProfile extends PureComponent<Props, State> { class TabProfile extends PureComponent<Props, State> {
state = { state = {
isHardResetModalOpened: false, isHardResetModalOpened: false,
isSoftResetModalOpened: false,
isPasswordModalOpened: false, isPasswordModalOpened: false,
isDisablePasswordModalOpened: false, isDisablePasswordModalOpened: false,
} }
@ -65,6 +71,8 @@ class TabProfile extends PureComponent<Props, State> {
}) })
} }
handleOpenSoftResetModal = () => this.setState({ isSoftResetModalOpened: true })
handleCloseSoftResetModal = () => this.setState({ isSoftResetModalOpened: false })
handleOpenHardResetModal = () => this.setState({ isHardResetModalOpened: true }) handleOpenHardResetModal = () => this.setState({ isHardResetModalOpened: true })
handleCloseHardResetModal = () => this.setState({ isHardResetModalOpened: false }) handleCloseHardResetModal = () => this.setState({ isHardResetModalOpened: false })
handleOpenPasswordModal = () => this.setState({ isPasswordModalOpened: true }) handleOpenPasswordModal = () => this.setState({ isPasswordModalOpened: true })
@ -72,6 +80,14 @@ class TabProfile extends PureComponent<Props, State> {
handleDisablePassowrd = () => this.setState({ isDisablePasswordModalOpened: true }) handleDisablePassowrd = () => this.setState({ isDisablePasswordModalOpened: true })
handleCloseDisablePasswordModal = () => this.setState({ isDisablePasswordModalOpened: false }) handleCloseDisablePasswordModal = () => this.setState({ isDisablePasswordModalOpened: false })
handleSoftReset = async () => {
this.props.cleanAccountsCache()
await delay(500)
db.cleanCache()
remote.app.relaunch()
remote.app.exit()
}
handleHardReset = () => { handleHardReset = () => {
db.resetAll() db.resetAll()
remote.app.relaunch() remote.app.relaunch()
@ -105,6 +121,7 @@ class TabProfile extends PureComponent<Props, State> {
render() { render() {
const { t, settings } = this.props const { t, settings } = this.props
const { const {
isSoftResetModalOpened,
isHardResetModalOpened, isHardResetModalOpened,
isPasswordModalOpened, isPasswordModalOpened,
isDisablePasswordModalOpened, isDisablePasswordModalOpened,
@ -134,13 +151,35 @@ class TabProfile extends PureComponent<Props, State> {
> >
<CheckBox isChecked={settings.developerMode} onChange={this.handleDeveloperMode} /> <CheckBox isChecked={settings.developerMode} onChange={this.handleDeveloperMode} />
</Row> </Row>
<Row title={t('settings:profile.reset')} desc={t('settings:profile.resetDesc')}> <Row
title={t('settings:profile.softResetTitle')}
desc={t('settings:profile.softResetDesc')}
>
<Button primary onClick={this.handleOpenSoftResetModal}>
{t('settings:profile.softReset')}
</Button>
</Row>
<Row
title={t('settings:profile.hardResetTitle')}
desc={t('settings:profile.hardResetDesc')}
>
<Button danger onClick={this.handleOpenHardResetModal}> <Button danger onClick={this.handleOpenHardResetModal}>
{t('settings:profile.resetButton')} {t('settings:profile.hardReset')}
</Button> </Button>
</Row> </Row>
</Body> </Body>
<ConfirmModal
isDanger
isOpened={isSoftResetModalOpened}
onClose={this.handleCloseSoftResetModal}
onReject={this.handleCloseSoftResetModal}
onConfirm={this.handleSoftReset}
title={t('settings:softResetModal.title')}
subTitle={t('settings:softResetModal.subTitle')}
desc={t('settings:softResetModal.desc')}
/>
<ConfirmModal <ConfirmModal
isDanger isDanger
isOpened={isHardResetModalOpened} isOpened={isHardResetModalOpened}

15
src/components/modals/OperationDetails.js

@ -1,6 +1,6 @@
// @flow // @flow
import React from 'react' import React, { Fragment } from 'react'
import { connect } from 'react-redux' import { connect } from 'react-redux'
import { shell } from 'electron' import { shell } from 'electron'
import { translate } from 'react-i18next' import { translate } from 'react-i18next'
@ -70,7 +70,7 @@ type Props = {
const OperationDetails = connect(mapStateToProps)((props: Props) => { const OperationDetails = connect(mapStateToProps)((props: Props) => {
const { t, onClose, operation, account, marketColor, currencySettings } = props const { t, onClose, operation, account, marketColor, currencySettings } = props
const { hash, date, senders, recipients, type } = operation const { hash, date, senders, recipients, type, fee } = operation
const amount = getOperationAmountNumber(operation) const amount = getOperationAmountNumber(operation)
const { name, unit, currency } = account const { name, unit, currency } = account
@ -130,6 +130,17 @@ const OperationDetails = connect(mapStateToProps)((props: Props) => {
</ColRight> </ColRight>
</Line> </Line>
<B /> <B />
{fee ? (
<Fragment>
<Line>
<ColLeft>Fees</ColLeft>
<ColRight>
<FormattedVal unit={unit} showCode val={fee} />
</ColRight>
</Line>
<B />
</Fragment>
) : null}
<Line> <Line>
<ColLeft>From</ColLeft> <ColLeft>From</ColLeft>
<ColRight>{senders.map(v => <CanSelect key={v}> {v} </CanSelect>)}</ColRight> <ColRight>{senders.map(v => <CanSelect key={v}> {v} </CanSelect>)}</ColRight>

11
src/helpers/db.js

@ -85,8 +85,17 @@ export default {
return val return val
}, },
cleanCache: () => {
// Only remove cache store
const keys = ['countervalues']
keys.forEach(k => {
const db = store(k)
db.clear()
})
},
resetAll: () => { resetAll: () => {
const keys = ['settings', 'accounts'] const keys = ['settings', 'accounts', 'countervalues']
keys.forEach(k => { keys.forEach(k => {
const db = store(k) const db = store(k)
db.clear() db.clear()

2
src/helpers/libcore.js

@ -308,6 +308,7 @@ function buildOperationRaw({
const hash = bitcoinLikeTransaction.getHash() const hash = bitcoinLikeTransaction.getHash()
const operationType = op.getOperationType() const operationType = op.getOperationType()
const value = op.getAmount().toLong() const value = op.getAmount().toLong()
const fee = op.getFees().toLong()
const OperationTypeMap: { [_: $Keys<typeof core.OPERATION_TYPES>]: OperationType } = { const OperationTypeMap: { [_: $Keys<typeof core.OPERATION_TYPES>]: OperationType } = {
[core.OPERATION_TYPES.SEND]: 'OUT', [core.OPERATION_TYPES.SEND]: 'OUT',
@ -322,6 +323,7 @@ function buildOperationRaw({
hash, hash,
type, type,
value, value,
fee,
senders: op.getSenders(), senders: op.getSenders(),
recipients: op.getRecipients(), recipients: op.getRecipients(),
blockHeight: op.getBlockHeight(), blockHeight: op.getBlockHeight(),

7
src/reducers/accounts.js

@ -43,6 +43,13 @@ const handlers: Object = {
state: AccountsState, state: AccountsState,
{ payload: account }: { payload: Account }, { payload: account }: { payload: Account },
): AccountsState => state.filter(acc => acc.id !== account.id), ): AccountsState => state.filter(acc => acc.id !== account.id),
CLEAN_ACCOUNTS_CACHE: (state: AccountsState): AccountsState =>
state.map(acc => ({
...acc,
operations: [],
pendingOperations: [],
})),
} }
// Selectors // Selectors

13
static/i18n/en/settings.yml

@ -43,9 +43,12 @@ profile:
syncDesc: Lorem ipsum dolor sit amet syncDesc: Lorem ipsum dolor sit amet
export: Export logs export: Export logs
exportDesc: Lorem ipsum dolor sit amet exportDesc: Lorem ipsum dolor sit amet
reset: Reset application softResetTitle: Clean application cache
resetDesc: Lorem ipsum dolor sit amet softResetDesc: Lorem ipsum dolor sit amet
resetButton: Hard reset softReset: Clean cache
hardResetTitle: Reset application
hardResetDesc: Lorem ipsum dolor sit amet
hardReset: Hard reset
developerMode: Developer Mode developerMode: Developer Mode
developerModeDesc: Enable visibility of developer apps & currencies like Bitcoin Testnet developerModeDesc: Enable visibility of developer apps & currencies like Bitcoin Testnet
about: about:
@ -59,3 +62,7 @@ hardResetModal:
title: Hard reset title: Hard reset
subTitle: Are you sure houston? subTitle: Are you sure houston?
desc: Lorem ipsum dolor sit amet desc: Lorem ipsum dolor sit amet
softResetModal:
title: Clean application cache
subTitle: Are you sure houston?
desc: Lorem ipsum dolor sit amet

10
yarn.lock

@ -1495,16 +1495,16 @@
npm "^5.7.1" npm "^5.7.1"
prebuild-install "^2.2.2" prebuild-install "^2.2.2"
"@ledgerhq/live-common@2.24.0": "@ledgerhq/live-common@^2.25.0":
version "2.24.0" version "2.25.0"
resolved "https://registry.yarnpkg.com/@ledgerhq/live-common/-/live-common-2.24.0.tgz#0b2f3e5856708b86e0d42e248aab2721d900f42d" resolved "https://registry.yarnpkg.com/@ledgerhq/live-common/-/live-common-2.25.0.tgz#00cca102598c9b604922fc4047d2c009d316aede"
dependencies: dependencies:
axios "^0.18.0" axios "^0.18.0"
invariant "^2.2.2" invariant "^2.2.2"
lodash "^4.17.4" lodash "^4.17.4"
numeral "^2.0.6" numeral "^2.0.6"
prando "^3.0.1" prando "^3.0.1"
react "^16.3.2" react "^16.4.0"
react-redux "^5.0.7" react-redux "^5.0.7"
redux "^4.0.0" redux "^4.0.0"
reselect "^3.0.1" reselect "^3.0.1"
@ -11554,7 +11554,7 @@ react-treebeard@^2.1.0:
shallowequal "^0.2.2" shallowequal "^0.2.2"
velocity-react "^1.3.1" velocity-react "^1.3.1"
react@^16.2.0, react@^16.3.2: react@^16.2.0, react@^16.3.2, react@^16.4.0:
version "16.4.0" version "16.4.0"
resolved "https://registry.yarnpkg.com/react/-/react-16.4.0.tgz#402c2db83335336fba1962c08b98c6272617d585" resolved "https://registry.yarnpkg.com/react/-/react-16.4.0.tgz#402c2db83335336fba1962c08b98c6272617d585"
dependencies: dependencies:

Loading…
Cancel
Save