From dd590854f3a740b5c0568ddb7b2ff7f6f63faccc Mon Sep 17 00:00:00 2001 From: "Valentin D. Pinkman" Date: Mon, 30 Jul 2018 16:14:35 +0200 Subject: [PATCH] fixes sent modal for ethereum/litecoin when no balance was set --- src/bridge/EthereumJSBridge.js | 5 ++++- src/bridge/LibcoreBridge.js | 2 +- src/components/FeesField/BitcoinKind.js | 9 ++++++--- src/components/base/InputCurrency/index.js | 6 ++++-- src/components/modals/Send/steps/01-step-amount.js | 2 +- 5 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/bridge/EthereumJSBridge.js b/src/bridge/EthereumJSBridge.js index fd02539a..b70991e3 100644 --- a/src/bridge/EthereumJSBridge.js +++ b/src/bridge/EthereumJSBridge.js @@ -403,7 +403,10 @@ const EthereumBridge: WalletBridge = { ? Promise.resolve() : Promise.reject(new NotEnoughBalance()), - getTotalSpent: (a, t) => Promise.resolve(t.amount.plus(t.gasPrice.times(t.gasLimit))), + getTotalSpent: (a, t) => + t.amount.isGreaterThan(0) && t.gasPrice.isGreaterThan(0) && t.gasLimit.isGreaterThan(0) + ? Promise.resolve(t.amount.plus(t.gasPrice.times(t.gasLimit))) + : Promise.resolve(BigNumber(0)), getMaxAmount: (a, t) => Promise.resolve(a.balance.minus(t.gasPrice.times(t.gasLimit))), diff --git a/src/bridge/LibcoreBridge.js b/src/bridge/LibcoreBridge.js index 40413e7c..fd11f02e 100644 --- a/src/bridge/LibcoreBridge.js +++ b/src/bridge/LibcoreBridge.js @@ -197,7 +197,7 @@ const LibcoreBridge: WalletBridge = { checkCanBeSpent, getTotalSpent: (a, t) => - !t.amount + t.amount.isZero() ? Promise.resolve(BigNumber(0)) : getFees(a, t) .then(totalFees => t.amount.plus(totalFees || 0)) diff --git a/src/components/FeesField/BitcoinKind.js b/src/components/FeesField/BitcoinKind.js index 3bae574c..d2ce95c0 100644 --- a/src/components/FeesField/BitcoinKind.js +++ b/src/components/FeesField/BitcoinKind.js @@ -53,7 +53,9 @@ const customItem = { type State = { isFocused: boolean, items: FeeItem[], selectedItem: FeeItem } -class FeesField extends Component { +type OwnProps = Props & { fees?: Fees, error?: Error } + +class FeesField extends Component { state = { items: [customItem], selectedItem: customItem, @@ -85,10 +87,10 @@ class FeesField extends Component return { items, selectedItem } } - componentDidUpdate() { + componentDidUpdate({ fees: prevFees }: OwnProps) { const { feePerByte, fees, onChange } = this.props const { items, isFocused } = this.state - if (fees && feePerByte.isZero() && !isFocused) { + if (fees && fees !== prevFees && feePerByte.isZero() && !isFocused) { // initialize with the median const feePerByte = (items.find(item => item.blockCount === defaultBlockCount) || items[0]) .feePerByte @@ -140,6 +142,7 @@ class FeesField extends Component {t('app:send.steps.amount.unitPerByte', { unit: satoshi.code })} } + allowZero /> ) diff --git a/src/components/base/InputCurrency/index.js b/src/components/base/InputCurrency/index.js index b7547439..db6c8c8e 100644 --- a/src/components/base/InputCurrency/index.js +++ b/src/components/base/InputCurrency/index.js @@ -84,6 +84,7 @@ type Props = { value: BigNumber, showAllDigits?: boolean, subMagnitude: number, + allowZero: boolean, } type State = { @@ -100,6 +101,7 @@ class InputCurrency extends PureComponent { value: BigNumber(0), showAllDigits: false, subMagnitude: 0, + allowZero: false, } state = { @@ -153,11 +155,11 @@ class InputCurrency extends PureComponent { } syncInput = ({ isFocused }: { isFocused: boolean }) => { - const { value, showAllDigits, subMagnitude, unit } = this.props + const { value, showAllDigits, subMagnitude, unit, allowZero } = this.props this.setState({ isFocused, displayValue: - !value || value.isZero() + (!value || value.isZero()) && !allowZero ? '' : format(unit, value, { isFocused, showAllDigits, subMagnitude }), }) diff --git a/src/components/modals/Send/steps/01-step-amount.js b/src/components/modals/Send/steps/01-step-amount.js index a058266a..959cd92e 100644 --- a/src/components/modals/Send/steps/01-step-amount.js +++ b/src/components/modals/Send/steps/01-step-amount.js @@ -138,7 +138,7 @@ export class StepAmountFooter extends PureComponent< .checkCanBeSpent(account, transaction) .then(() => true, () => false) if (syncId !== this.syncId) return - const canNext = isRecipientValid && canBeSpent + const canNext = isRecipientValid && canBeSpent && totalSpent.gt(0) this.setState({ totalSpent, canNext, isSyncing: false }) } catch (err) { logger.critical(err)