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-node-hid": "^4.12.0",
"@ledgerhq/ledger-core": "1.4.1",
"@ledgerhq/live-common": "2.24.0",
"@ledgerhq/live-common": "^2.25.0",
"axios": "^0.18.0",
"babel-runtime": "^6.26.0",
"bcryptjs": "^2.4.3",

2
src/actions/accounts.js

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

6
src/bridge/RippleJSBridge.js

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

1
src/commands/libcoreSignAndBroadcast.js

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

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

@ -5,12 +5,14 @@ import { connect } from 'react-redux'
import { remote } from 'electron'
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 { T } from 'types/common'
import { unlock } from 'reducers/application'
import db, { setEncryptionKey } from 'helpers/db'
import CheckBox from 'components/base/CheckBox'
import Box from 'components/base/Box'
import Button from 'components/base/Button'
@ -28,6 +30,7 @@ import {
const mapDispatchToProps = {
unlock,
cleanAccountsCache,
}
type Props = {
@ -35,10 +38,12 @@ type Props = {
settings: SettingsState,
unlock: Function,
saveSettings: Function,
cleanAccountsCache: () => *,
}
type State = {
isHardResetModalOpened: boolean,
isSoftResetModalOpened: boolean,
isPasswordModalOpened: boolean,
isDisablePasswordModalOpened: boolean,
}
@ -46,6 +51,7 @@ type State = {
class TabProfile extends PureComponent<Props, State> {
state = {
isHardResetModalOpened: false,
isSoftResetModalOpened: false,
isPasswordModalOpened: 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 })
handleCloseHardResetModal = () => this.setState({ isHardResetModalOpened: false })
handleOpenPasswordModal = () => this.setState({ isPasswordModalOpened: true })
@ -72,6 +80,14 @@ class TabProfile extends PureComponent<Props, State> {
handleDisablePassowrd = () => this.setState({ isDisablePasswordModalOpened: true })
handleCloseDisablePasswordModal = () => this.setState({ isDisablePasswordModalOpened: false })
handleSoftReset = async () => {
this.props.cleanAccountsCache()
await delay(500)
db.cleanCache()
remote.app.relaunch()
remote.app.exit()
}
handleHardReset = () => {
db.resetAll()
remote.app.relaunch()
@ -105,6 +121,7 @@ class TabProfile extends PureComponent<Props, State> {
render() {
const { t, settings } = this.props
const {
isSoftResetModalOpened,
isHardResetModalOpened,
isPasswordModalOpened,
isDisablePasswordModalOpened,
@ -134,13 +151,35 @@ class TabProfile extends PureComponent<Props, State> {
>
<CheckBox isChecked={settings.developerMode} onChange={this.handleDeveloperMode} />
</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}>
{t('settings:profile.resetButton')}
{t('settings:profile.hardReset')}
</Button>
</Row>
</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
isDanger
isOpened={isHardResetModalOpened}

15
src/components/modals/OperationDetails.js

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

11
src/helpers/db.js

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

2
src/helpers/libcore.js

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

7
src/reducers/accounts.js

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

13
static/i18n/en/settings.yml

@ -43,9 +43,12 @@ profile:
syncDesc: Lorem ipsum dolor sit amet
export: Export logs
exportDesc: Lorem ipsum dolor sit amet
reset: Reset application
resetDesc: Lorem ipsum dolor sit amet
resetButton: Hard reset
softResetTitle: Clean application cache
softResetDesc: Lorem ipsum dolor sit amet
softReset: Clean cache
hardResetTitle: Reset application
hardResetDesc: Lorem ipsum dolor sit amet
hardReset: Hard reset
developerMode: Developer Mode
developerModeDesc: Enable visibility of developer apps & currencies like Bitcoin Testnet
about:
@ -59,3 +62,7 @@ hardResetModal:
title: Hard reset
subTitle: Are you sure houston?
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"
prebuild-install "^2.2.2"
"@ledgerhq/live-common@2.24.0":
version "2.24.0"
resolved "https://registry.yarnpkg.com/@ledgerhq/live-common/-/live-common-2.24.0.tgz#0b2f3e5856708b86e0d42e248aab2721d900f42d"
"@ledgerhq/live-common@^2.25.0":
version "2.25.0"
resolved "https://registry.yarnpkg.com/@ledgerhq/live-common/-/live-common-2.25.0.tgz#00cca102598c9b604922fc4047d2c009d316aede"
dependencies:
axios "^0.18.0"
invariant "^2.2.2"
lodash "^4.17.4"
numeral "^2.0.6"
prando "^3.0.1"
react "^16.3.2"
react "^16.4.0"
react-redux "^5.0.7"
redux "^4.0.0"
reselect "^3.0.1"
@ -11554,7 +11554,7 @@ react-treebeard@^2.1.0:
shallowequal "^0.2.2"
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"
resolved "https://registry.yarnpkg.com/react/-/react-16.4.0.tgz#402c2db83335336fba1962c08b98c6272617d585"
dependencies:

Loading…
Cancel
Save