1515 * limitations under the License.
1616 */
1717
18- import { ChangeEvent , Component } from 'react' ;
18+ import { Component } from 'react' ;
1919import * as accountApi from '@/api/account' ;
2020import { syncdone } from '@/api/accountsync' ;
2121import { convertFromCurrency , convertToCurrency , parseExternalBtcAmount } from '@/api/coins' ;
@@ -26,7 +26,6 @@ import { HideAmountsButton } from '@/components/hideamountsbutton/hideamountsbut
2626import { Button } from '@/components/forms' ;
2727import { BackButton } from '@/components/backbutton/backbutton' ;
2828import { Column , ColumnButtons , Grid , GuideWrapper , GuidedContent , Header , Main } from '@/components/layout' ;
29- import { Status } from '@/components/status/status' ;
3029import { translate , TranslateProps } from '@/decorators/translate' ;
3130import { FeeTargets } from './feetargets' ;
3231import { isBitcoinBased } from '@/routes/account/utils' ;
@@ -39,7 +38,6 @@ import { FiatInput } from './components/inputs/fiat-input';
3938import { NoteInput } from './components/inputs/note-input' ;
4039import { TSelectedUTXOs } from './utxos' ;
4140import { TProposalError , txProposalErrorHandling } from './services' ;
42- import { ContentWrapper } from '@/components/contentwrapper/contentwrapper' ;
4341import { CoinControl } from './coin-control' ;
4442import style from './send.module.css' ;
4543
@@ -53,7 +51,6 @@ interface SendProps {
5351type Props = SendProps & TranslateProps ;
5452
5553export type State = {
56- account ?: accountApi . IAccount ;
5754 balance ?: accountApi . IBalance ;
5855 proposedFee ?: accountApi . IAmount ;
5956 proposedTotal ?: accountApi . IAmount ;
@@ -68,10 +65,7 @@ export type State = {
6865 isConfirming : boolean ;
6966 sendResult ?: accountApi . ISendTx ;
7067 isUpdatingProposal : boolean ;
71- addressError ?: TProposalError [ 'addressError' ] ;
72- amountError ?: TProposalError [ 'amountError' ] ;
73- feeError ?: TProposalError [ 'feeError' ] ;
74- paired ?: boolean ;
68+ errorHandling : TProposalError ;
7569 note : string ;
7670}
7771
@@ -93,6 +87,7 @@ class Send extends Component<Props, State> {
9387 isUpdatingProposal : false ,
9488 note : '' ,
9589 customFee : '' ,
90+ errorHandling : { } ,
9691 } ;
9792
9893 public componentDidMount ( ) {
@@ -173,9 +168,7 @@ class Send extends Component<Props, State> {
173168 private validateAndDisplayFee = ( updateFiat : boolean = true ) => {
174169 this . setState ( {
175170 proposedTotal : undefined ,
176- addressError : undefined ,
177- amountError : undefined ,
178- feeError : undefined ,
171+ errorHandling : { } ,
179172 } ) ;
180173 const txInput = this . getValidTxInputData ( ) ;
181174 if ( ! txInput ) {
@@ -209,23 +202,14 @@ class Send extends Component<Props, State> {
209202 } , 400 ) ; // Delay the proposal by 400 ms
210203 } ;
211204
212- private handleNoteInput = ( event : ChangeEvent < HTMLInputElement > ) => {
213- const target = event . target ;
214- this . setState ( {
215- 'note' : target . value ,
216- } ) ;
217- } ;
218-
219205 private txProposal = (
220206 updateFiat : boolean ,
221207 result : accountApi . TTxProposalResult ,
222208 ) => {
223209 this . setState ( { valid : result . success } ) ;
224210 if ( result . success ) {
225211 this . setState ( {
226- addressError : undefined ,
227- amountError : undefined ,
228- feeError : undefined ,
212+ errorHandling : { } ,
229213 proposedFee : result . fee ,
230214 proposedAmount : result . amount ,
231215 proposedTotal : result . total ,
@@ -236,7 +220,11 @@ class Send extends Component<Props, State> {
236220 }
237221 } else {
238222 const errorHandling = txProposalErrorHandling ( result . errorCode ) ;
239- this . setState ( { ...errorHandling , isUpdatingProposal : false } ) ;
223+ this . setState ( { errorHandling, isUpdatingProposal : false } ) ;
224+ if ( errorHandling . amountError
225+ || Object . keys ( errorHandling ) . length === 0 ) {
226+ this . setState ( { proposedFee : undefined } ) ;
227+ }
240228 }
241229 } ;
242230
@@ -256,7 +244,7 @@ class Send extends Component<Props, State> {
256244 if ( data . success ) {
257245 this . setState ( { fiatAmount : data . fiatAmount } ) ;
258246 } else {
259- this . setState ( { amountError : this . props . t ( 'send.error.invalidAmount' ) } ) ;
247+ this . setState ( { errorHandling : { amountError : this . props . t ( 'send.error.invalidAmount' ) } } ) ;
260248 }
261249 } else {
262250 this . setState ( { fiatAmount : '' } ) ;
@@ -274,7 +262,7 @@ class Send extends Component<Props, State> {
274262 if ( data . success ) {
275263 this . setState ( { amount : data . amount } , ( ) => this . validateAndDisplayFee ( false ) ) ;
276264 } else {
277- this . setState ( { amountError : this . props . t ( 'send.error.invalidAmount' ) } ) ;
265+ this . setState ( { errorHandling : { amountError : this . props . t ( 'send.error.invalidAmount' ) } } ) ;
278266 }
279267 } else {
280268 this . setState ( { amount : '' } ) ;
@@ -326,7 +314,7 @@ class Send extends Component<Props, State> {
326314 if ( result . success ) {
327315 updateState [ 'amount' ] = result . amount ;
328316 } else {
329- updateState [ 'amountError ' ] = this . props . t ( 'send.error.invalidAmount' ) ;
317+ updateState [ 'errorHandling ' ] = { amountError : this . props . t ( 'send.error.invalidAmount' ) } ;
330318 this . setState ( updateState ) ;
331319 return ;
332320 }
@@ -387,10 +375,7 @@ class Send extends Component<Props, State> {
387375 isConfirming,
388376 sendResult,
389377 isUpdatingProposal,
390- addressError,
391- amountError,
392- feeError,
393- paired,
378+ errorHandling,
394379 note,
395380 } = this . state ;
396381
@@ -408,11 +393,6 @@ class Send extends Component<Props, State> {
408393 < GuideWrapper >
409394 < GuidedContent >
410395 < Main >
411- < ContentWrapper >
412- < Status type = "warning" hidden = { paired !== false } >
413- { t ( 'warning.sendPairing' ) }
414- </ Status >
415- </ ContentWrapper >
416396 < Header
417397 title = { < h2 > { t ( 'send.title' , { accountName : account . coinName } ) } </ h2 > }
418398 >
@@ -438,7 +418,7 @@ class Send extends Component<Props, State> {
438418 < Column >
439419 < ReceiverAddressInput
440420 accountCode = { account . code }
441- addressError = { addressError }
421+ addressError = { errorHandling . addressError }
442422 onInputChange = { this . onReceiverAddressInputChange }
443423 recipientAddress = { recipientAddress }
444424 parseQRResult = { this . parseQRResult }
@@ -452,7 +432,7 @@ class Send extends Component<Props, State> {
452432 onAmountChange = { this . onCoinAmountChange }
453433 onSendAllChange = { this . onSendAllChange }
454434 sendAll = { sendAll }
455- amountError = { amountError }
435+ amountError = { errorHandling . amountError }
456436 proposedAmount = { proposedAmount }
457437 amount = { amount }
458438 hasSelectedUTXOs = { this . hasSelectedUTXOs ( ) }
@@ -462,7 +442,7 @@ class Send extends Component<Props, State> {
462442 < FiatInput
463443 onFiatChange = { this . handleFiatInput }
464444 disabled = { sendAll }
465- error = { amountError }
445+ error = { errorHandling . amountError }
466446 fiatAmount = { fiatAmount }
467447 label = { activeCurrency }
468448 />
@@ -480,12 +460,12 @@ class Send extends Component<Props, State> {
480460 showCalculatingFeeLabel = { isUpdatingProposal }
481461 onFeeTargetChange = { this . feeTargetChange }
482462 onCustomFee = { customFee => this . setState ( { customFee } , this . validateAndDisplayFee ) }
483- error = { feeError } />
463+ error = { errorHandling . feeError } />
484464 </ Column >
485465 < Column >
486466 < NoteInput
487467 note = { note }
488- onNoteChange = { this . handleNoteInput }
468+ onNoteChange = { note => this . setState ( { note : note } ) }
489469 />
490470 < ColumnButtons
491471 className = "m-top-default m-bottom-xlarge"
0 commit comments