Skip to content

Commit 0c3f44f

Browse files
committed
Merge branch 'frontend-cleanup-send'
2 parents 9a74ab4 + c5bf45c commit 0c3f44f

File tree

3 files changed

+30
-50
lines changed

3 files changed

+30
-50
lines changed

frontends/web/src/routes/account/send/components/inputs/note-input.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414
* limitations under the License.
1515
*/
1616

17+
import { ChangeEvent } from 'react';
1718
import { useTranslation } from 'react-i18next';
1819
import { Input } from '@/components/forms';
1920
import style from './note-input.module.css';
20-
import { ChangeEvent } from 'react';
2121

2222
type TProps = {
23-
onNoteChange: (event: ChangeEvent<HTMLInputElement>) => void;
23+
onNoteChange: (note: string) => void;
2424
note: string;
2525
}
2626

@@ -35,9 +35,9 @@ export const NoteInput = ({ onNoteChange, note }: TProps) => {
3535
</span>
3636
}
3737
id="note"
38-
onInput={onNoteChange}
38+
onInput={(e: ChangeEvent<HTMLInputElement>) => onNoteChange(e.target.value)}
3939
value={note}
4040
placeholder={t('note.input.placeholder')}
4141
/>
4242
);
43-
};
43+
};

frontends/web/src/routes/account/send/send.tsx

Lines changed: 19 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* limitations under the License.
1616
*/
1717

18-
import { ChangeEvent, Component } from 'react';
18+
import { Component } from 'react';
1919
import * as accountApi from '@/api/account';
2020
import { syncdone } from '@/api/accountsync';
2121
import { convertFromCurrency, convertToCurrency, parseExternalBtcAmount } from '@/api/coins';
@@ -26,7 +26,6 @@ import { HideAmountsButton } from '@/components/hideamountsbutton/hideamountsbut
2626
import { Button } from '@/components/forms';
2727
import { BackButton } from '@/components/backbutton/backbutton';
2828
import { Column, ColumnButtons, Grid, GuideWrapper, GuidedContent, Header, Main } from '@/components/layout';
29-
import { Status } from '@/components/status/status';
3029
import { translate, TranslateProps } from '@/decorators/translate';
3130
import { FeeTargets } from './feetargets';
3231
import { isBitcoinBased } from '@/routes/account/utils';
@@ -39,7 +38,6 @@ import { FiatInput } from './components/inputs/fiat-input';
3938
import { NoteInput } from './components/inputs/note-input';
4039
import { TSelectedUTXOs } from './utxos';
4140
import { TProposalError, txProposalErrorHandling } from './services';
42-
import { ContentWrapper } from '@/components/contentwrapper/contentwrapper';
4341
import { CoinControl } from './coin-control';
4442
import style from './send.module.css';
4543

@@ -53,7 +51,6 @@ interface SendProps {
5351
type Props = SendProps & TranslateProps;
5452

5553
export 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"

frontends/web/src/routes/account/send/services.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,26 @@ import { alertUser } from '@/components/alert/Alert';
1919
import { i18n } from '@/i18n/i18n';
2020

2121
export type TProposalError = {
22-
addressError: string;
23-
amountError: string;
24-
feeError: string;
22+
addressError?: string;
23+
amountError?: string;
24+
feeError?: string;
2525
}
2626

27-
export const txProposalErrorHandling = (errorCode?: string) => {
27+
export const txProposalErrorHandling = (errorCode?: string): TProposalError => {
2828
const { t } = i18n;
2929
switch (errorCode) {
3030
case 'invalidAddress':
3131
return { addressError: t('send.error.invalidAddress') };
3232
case 'invalidAmount':
3333
case 'insufficientFunds':
34-
return { amountError: t(`send.error.${errorCode}`), proposedFee: undefined };
34+
return { amountError: t(`send.error.${errorCode}`) };
3535
case 'feeTooLow':
3636
case 'feesNotAvailable':
3737
return { feeError: t(`send.error.${errorCode}`) };
3838
default:
3939
if (errorCode) {
4040
alertUser(errorCode);
4141
}
42-
return { proposedFee: undefined };
42+
return {};
4343
}
44-
};
44+
};

0 commit comments

Comments
 (0)