diff --git a/app/components/views/TransactionsPage/SendTab/SendOutputRow/SendOutputRow.jsx b/app/components/views/TransactionsPage/SendTab/SendOutputRow/SendOutputRow.jsx index 2d61bf59a5..9d81b24774 100644 --- a/app/components/views/TransactionsPage/SendTab/SendOutputRow/SendOutputRow.jsx +++ b/app/components/views/TransactionsPage/SendTab/SendOutputRow/SendOutputRow.jsx @@ -56,7 +56,7 @@ const getSendAllFundsIcon = ({ + )} onClick={onHideSendAll} /> ); diff --git a/app/components/views/TransactionsPage/SendTab/SendTab.jsx b/app/components/views/TransactionsPage/SendTab/SendTab.jsx index 1a18bfc619..a367af8d5e 100644 --- a/app/components/views/TransactionsPage/SendTab/SendTab.jsx +++ b/app/components/views/TransactionsPage/SendTab/SendTab.jsx @@ -61,7 +61,8 @@ const SendTab = () => { onAddOutput, onUpdateOutput, onRemoveOutput, - onSetOutputs + onSetOutputs, + prevOutputs } = useOutputs(); const { walletService } = useService(); @@ -76,6 +77,7 @@ const SendTab = () => { const prevPublishTxResponse = usePrevious(publishTxResponse); const prevNextAddress = usePrevious(nextAddress); const prevIsSendSelf = usePrevious(isSendSelf); + const prevAccount = usePrevious(account); const onValidateAddress = async ({ address, index }) => { let error; @@ -95,7 +97,6 @@ const SendTab = () => { } ref.data.error.address = error; onUpdateOutput(ref); - onAttemptConstructTransaction(); } catch (err) { return err; } @@ -120,26 +121,33 @@ const SendTab = () => { ref.data.amount = atomValue; ref.data.error.amount = error; onUpdateOutput(ref); - onAttemptConstructTransaction(); }; const onChangeAccount = (account) => { setAccount(account); - onAttemptConstructTransaction(); + + if (isSendAll) { + const newOutputs = [{ + ...outputs[0], + data: { + ...outputs[0].data, + amount: account.spendable + } + }]; + onSetOutputs(newOutputs); + } }; const onShowSendSelf = () => { const newOutputs = [{ ...outputs[0], data: baseOutput().data }]; setIsSendSelf(true); onSetOutputs(newOutputs); - onAttemptConstructTransaction(); }; const onShowSendOthers = () => { const newOutputs = [{ ...outputs[0], data: baseOutput().data }]; setIsSendSelf(false); onSetOutputs(newOutputs); - onAttemptConstructTransaction(); }; const onShowSendAll = () => { @@ -147,12 +155,15 @@ const SendTab = () => { ...outputs[0], data: { ...outputs[0].data, - amount: account.spendable + amount: account.spendable, + error: { + ...outputs[0].data.error, + amount: null + } } }]; setIsSendAll(true); onSetOutputs(newOutputs); - onAttemptConstructTransaction(); }; const onKeyDown = (e) => { @@ -171,7 +182,6 @@ const SendTab = () => { }]; setIsSendAll(false); onSetOutputs(newOutputs); - onAttemptConstructTransaction(); }; const hasError = useCallback(() => { @@ -293,15 +303,17 @@ const SendTab = () => { } if (newOutputs) { onSetOutputs(newOutputs); - onAttemptConstructTransaction(); } + if (constructTxLowBalance) { setInsuficientFunds(true); } else { setInsuficientFunds(false); } - return () => onClearTransaction(); + if(prevOutputs != outputs || prevAccount != account) { + onAttemptConstructTransaction(); + } }, [ publishTxResponse, prevPublishTxResponse, @@ -312,12 +324,19 @@ const SendTab = () => { constructTxLowBalance, nextAddressAccount.value, outputs, + prevOutputs, onSetOutputs, onAttemptConstructTransaction, onClearTransaction, - onGetNextAddressAttempt + onGetNextAddressAttempt, + account, + prevAccount ]); + useEffect(() => { + return () => onClearTransaction; + }); + return !walletService ? : ( { const newOutputs = [ ...outputs ]; @@ -83,6 +85,7 @@ export function useOutputs() { onAddOutput, onUpdateOutput, onRemoveOutput, - onSetOutputs: setOutputs + onSetOutputs: setOutputs, + prevOutputs }; }