Skip to content

Commit 564f4c1

Browse files
5K1PYLemonexe
authored andcommitted
fix(suite): Show base currency amount even for bitcoin base currency
1 parent 97468d8 commit 564f4c1

File tree

1 file changed

+51
-39
lines changed
  • packages/suite/src/views/wallet/send/Outputs/Amount

1 file changed

+51
-39
lines changed

packages/suite/src/views/wallet/send/Outputs/Amount/Amount.tsx

Lines changed: 51 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { formInputsMaxLength } from '@suite-common/validators';
22
import { getNetworkDisplaySymbol } from '@suite-common/wallet-config';
3-
import { useDisplayBaseCurrency } from '@suite-common/wallet-core';
43
import { Output, TokenAddress } from '@suite-common/wallet-types';
54
import {
65
convertAmountUnitsToSubunits,
@@ -49,21 +48,24 @@ export const Amount = ({ output, outputId }: AmountProps) => {
4948
setMax,
5049
composeTransaction,
5150
getCurrentFiatRate,
51+
watch,
5252
} = useSendFormContext();
5353
const { symbol, tokens } = account;
5454
const { shouldSendInSats } = useBitcoinAmountUnit(symbol);
5555
const { isBelowLaptop } = useLayoutSize();
56-
const { shallDisplayBaseCurrency } = useDisplayBaseCurrency(symbol);
5756

5857
const locale = useSelector(selectLanguage);
5958

6059
const amountName = `outputs.${outputId}.amount` as const;
6160
const tokenInputName = `outputs.${outputId}.token`;
61+
const currencyInputName = `outputs.${outputId}.currency` as const;
6262
const maxOutputId = getDefaultValue('setMaxOutputId');
6363
const isSendMaxActive = maxOutputId === outputId;
6464
const outputError = errors.outputs ? errors.outputs[outputId] : undefined;
6565
const error = outputError ? outputError.amount : undefined;
6666

67+
const selectedBaseCurrency = watch(currencyInputName);
68+
6769
// corner-case: do not display "setMax" button if FormState got ANY error (setMax probably cannot be calculated)
6870
const isSendMaxVisible = isSendMaxActive && !error && !Object.keys(errors).length;
6971
const maxSwitchId = `outputs.${outputId}.setMax`;
@@ -77,8 +79,8 @@ export const Amount = ({ output, outputId }: AmountProps) => {
7779
currencyCode: (output.currency?.value ?? '') as BaseCurrencyCode,
7880
});
7981

80-
const isWithBaseCurrency =
81-
shallDisplayBaseCurrency && (!!currentRate?.rate || !!currentRate?.isLoading);
82+
const showBaseCurrency = !!currentRate?.rate || !!currentRate?.isLoading;
83+
const showTokenCurrency = selectedBaseCurrency.value !== symbol || !showBaseCurrency; // Show always at least one currency
8284

8385
let decimals: number;
8486
if (token) {
@@ -155,46 +157,56 @@ export const Amount = ({ output, outputId }: AmountProps) => {
155157
alignItems={isBelowLaptop ? 'center' : 'normal'}
156158
gap={spacings.sm}
157159
>
158-
<NumberInput
159-
inputState={inputState}
160-
locale={locale}
161-
labelHoverRight={
162-
!isSendMaxVisible && (!isWithBaseCurrency || isBelowLaptop) && sendMaxSwitch
163-
}
164-
labelRight={
165-
isSendMaxVisible && (!isWithBaseCurrency || isBelowLaptop) && sendMaxSwitch
166-
}
167-
labelLeft={
168-
<Row>
169-
<Translation id="AMOUNT" />
170-
</Row>
171-
}
172-
bottomText={bottomText || null}
173-
onChange={handleInputChange}
174-
name={amountName}
175-
data-testid={amountName}
176-
defaultValue={amountValue}
177-
maxLength={formInputsMaxLength.amount}
178-
rules={cryptoAmountRules}
179-
control={control}
180-
innerAddon={
181-
<Text variant="tertiary">
182-
{withTokens && token ? token?.symbol?.toUpperCase() : displayTicker}
183-
</Text>
184-
}
185-
/>
160+
{showTokenCurrency && (
161+
<NumberInput
162+
inputState={inputState}
163+
locale={locale}
164+
labelHoverRight={
165+
!isSendMaxVisible &&
166+
(!showBaseCurrency || isBelowLaptop) &&
167+
sendMaxSwitch
168+
}
169+
labelRight={
170+
isSendMaxVisible &&
171+
(!showBaseCurrency || isBelowLaptop) &&
172+
sendMaxSwitch
173+
}
174+
labelLeft={
175+
<Row>
176+
<Translation id="AMOUNT" />
177+
</Row>
178+
}
179+
bottomText={bottomText || null}
180+
onChange={handleInputChange}
181+
name={amountName}
182+
data-testid={amountName}
183+
defaultValue={amountValue}
184+
maxLength={formInputsMaxLength.amount}
185+
rules={cryptoAmountRules}
186+
control={control}
187+
innerAddon={
188+
<Text variant="tertiary">
189+
{withTokens && token ? token?.symbol?.toUpperCase() : displayTicker}
190+
</Text>
191+
}
192+
/>
193+
)}
186194

187-
{isWithBaseCurrency && (
195+
{showBaseCurrency && (
188196
<BaseCurrencyValue amount="1" symbol={symbol}>
189197
{({ rate }) =>
190198
rate && (
191199
<>
192-
<Icon
193-
name={isBelowLaptop ? 'arrowsDownUp' : 'arrowsLeftRight'}
194-
size={20}
195-
variant="tertiary"
196-
margin={{ top: isBelowLaptop ? 0 : spacings.xxxxl }}
197-
/>
200+
{showTokenCurrency && (
201+
<Icon
202+
name={
203+
isBelowLaptop ? 'arrowsDownUp' : 'arrowsLeftRight'
204+
}
205+
size={20}
206+
variant="tertiary"
207+
margin={{ top: isBelowLaptop ? 0 : spacings.xxxxl }}
208+
/>
209+
)}
198210
<BaseCurrencyInput
199211
output={output}
200212
outputId={outputId}

0 commit comments

Comments
 (0)