From 35f9050e56a19f78d4d9d105f9caa81ae9bf7559 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Renaudeau?= Date: Sun, 3 Jun 2018 09:22:47 +0200 Subject: [PATCH] Bump live-common + add fee + soft reset --- package.json | 2 +- src/actions/accounts.js | 2 + src/actions/settings.js | 2 +- src/bridge/EthereumJSBridge.js | 9 ++-- src/bridge/RippleJSBridge.js | 6 ++- src/commands/libcoreSignAndBroadcast.js | 1 + .../SettingsPage/sections/Profile.js | 49 +++++++++++++++++-- src/components/modals/OperationDetails.js | 15 +++++- src/helpers/db.js | 11 ++++- src/helpers/libcore.js | 2 + src/reducers/accounts.js | 7 +++ static/i18n/en/settings.yml | 13 +++-- yarn.lock | 10 ++-- 13 files changed, 106 insertions(+), 23 deletions(-) diff --git a/package.json b/package.json index d445f66c..c4f6fd25 100644 --- a/package.json +++ b/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", diff --git a/src/actions/accounts.js b/src/actions/accounts.js index 03f92870..971832b2 100644 --- a/src/actions/accounts.js +++ b/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' }) diff --git a/src/actions/settings.js b/src/actions/settings.js index 15170c6d..381000a8 100644 --- a/src/actions/settings.js +++ b/src/actions/settings.js @@ -22,7 +22,7 @@ type SetExchangePairs = ( Array<{ from: Currency, to: Currency, - exchange: string, + exchange: ?string, }>, ) => * diff --git a/src/bridge/EthereumJSBridge.js b/src/bridge/EthereumJSBridge.js index 59737643..127e64db 100644 --- a/src/bridge/EthereumJSBridge.js +++ b/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 = { 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 = { id: accountId, xpub: '', @@ -161,7 +164,6 @@ const EthereumBridge: WalletBridge = { return { complete: true } } - const accountId = `${currency.id}_${address}` const account: $Exact = { id: accountId, xpub: '', @@ -332,6 +334,7 @@ const EthereumBridge: WalletBridge = { hash, type: 'OUT', value: t.amount, + fee: t.gasPrice * t.gasLimit, blockHeight: null, blockHash: null, accountId: a.id, diff --git a/src/bridge/RippleJSBridge.js b/src/bridge/RippleJSBridge.js index 90f5f6d6..d7972496 100644 --- a/src/bridge/RippleJSBridge.js +++ b/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 = { .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 = { accountId: a.id, type: 'OUT', value: t.amount, + fee: t.fee, blockHash: null, blockHeight: null, senders: [a.freshAddress], diff --git a/src/commands/libcoreSignAndBroadcast.js b/src/commands/libcoreSignAndBroadcast.js index 5727b9f7..3253a61d 100644 --- a/src/commands/libcoreSignAndBroadcast.js +++ b/src/commands/libcoreSignAndBroadcast.js @@ -78,6 +78,7 @@ const cmd: Command = createCommand( hash: txHash, type: 'OUT', value: amount, + fee: 0, blockHash: null, blockHeight: null, senders: [account.freshAddress], diff --git a/src/components/SettingsPage/sections/Profile.js b/src/components/SettingsPage/sections/Profile.js index b71ee462..8c9e6e31 100644 --- a/src/components/SettingsPage/sections/Profile.js +++ b/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 { state = { isHardResetModalOpened: false, + isSoftResetModalOpened: false, isPasswordModalOpened: false, isDisablePasswordModalOpened: false, } @@ -65,6 +71,8 @@ class TabProfile extends PureComponent { }) } + 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 { 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 { render() { const { t, settings } = this.props const { + isSoftResetModalOpened, isHardResetModalOpened, isPasswordModalOpened, isDisablePasswordModalOpened, @@ -134,13 +151,35 @@ class TabProfile extends PureComponent { > - + + + + + + { 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) => { + {fee ? ( + + + Fees + + + + + + + ) : null} From {senders.map(v => {v} )} diff --git a/src/helpers/db.js b/src/helpers/db.js index b1bdf7fb..d5198ce4 100644 --- a/src/helpers/db.js +++ b/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() diff --git a/src/helpers/libcore.js b/src/helpers/libcore.js index ef1476f4..d37699da 100644 --- a/src/helpers/libcore.js +++ b/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]: 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(), diff --git a/src/reducers/accounts.js b/src/reducers/accounts.js index 5e12bd16..6536bc51 100644 --- a/src/reducers/accounts.js +++ b/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 diff --git a/static/i18n/en/settings.yml b/static/i18n/en/settings.yml index 6d6c9df0..e03a2ced 100644 --- a/static/i18n/en/settings.yml +++ b/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 diff --git a/yarn.lock b/yarn.lock index d0e3b30c..7cfd6e34 100644 --- a/yarn.lock +++ b/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: