Skip to content

Commit eb275f9

Browse files
Respect bitcoin unit on amount entry
Update send and receive amount inputs to show sats labels when that display unit is selected.
1 parent b357a0d commit eb275f9

2 files changed

Lines changed: 36 additions & 8 deletions

File tree

client/src/screens/ReceiveScreen.tsx

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ import logger from "~/lib/log";
4242
import type { Bolt11Invoice } from "react-native-nitro-ark";
4343
import { queryClient } from "~/queryClient";
4444
import { BlinkingCaret } from "~/components/BlinkingCaret";
45-
import { useBitcoinAmountFormatter } from "~/hooks/useBitcoinAmountFormatter";
45+
import {
46+
useBitcoinAmountFormatter,
47+
useBitcoinAmountUnit,
48+
} from "~/hooks/useBitcoinAmountFormatter";
4649

4750
const minAmount = 1;
4851
const SUBSCRIPTION_RETRY_DELAY_MS = 1000;
@@ -185,6 +188,7 @@ const ReceiveScreen = () => {
185188
const iconColor = useIconColor();
186189
const colors = useThemeColors();
187190
const formatBitcoinAmount = useBitcoinAmountFormatter();
191+
const bitcoinAmountUnit = useBitcoinAmountUnit();
188192
const { amount, setAmount, currency, toggleCurrency, amountSat, btcPrice, fiatCurrency } =
189193
useReceiveScreen();
190194
const fiatCurrencyInfo = getFiatCurrencyInfo(fiatCurrency);
@@ -238,6 +242,9 @@ const ReceiveScreen = () => {
238242
const hasEnteredAmount = amount.trim().length > 0;
239243
const isEnteredAmountInvalid = hasEnteredAmount && amountSat < minAmount;
240244
const displayAmount = amount === "" ? (currency === "FIAT" ? "0.00" : "0") : amount;
245+
const amountPrefix =
246+
currency === "FIAT" ? fiatCurrencyInfo.symbol : bitcoinAmountUnit === "bip177" ? "₿" : null;
247+
const amountSuffix = currency === "SATS" && bitcoinAmountUnit === "sats" ? "sats" : null;
241248
const [isAmountFocused, setIsAmountFocused] = useState(false);
242249

243250
const stopSubscription = useCallback(
@@ -705,9 +712,11 @@ const ReceiveScreen = () => {
705712
<View className="self-center">
706713
<Pressable onPress={focusAmountInput} disabled={isAmountLocked}>
707714
<View className="flex-row items-center justify-center">
708-
<Text className="mr-3 text-[46px] font-bold leading-[52px] text-foreground">
709-
{currency === "FIAT" ? fiatCurrencyInfo.symbol : "₿"}
710-
</Text>
715+
{amountPrefix ? (
716+
<Text className="mr-3 text-[46px] font-bold leading-[52px] text-foreground">
717+
{amountPrefix}
718+
</Text>
719+
) : null}
711720
<Text className="text-[46px] font-bold leading-[52px] text-foreground">
712721
{displayAmount}
713722
</Text>
@@ -716,6 +725,11 @@ const ReceiveScreen = () => {
716725
height={40}
717726
visible={isAmountFocused && !isAmountLocked}
718727
/>
728+
{amountSuffix ? (
729+
<Text className="ml-3 text-2xl font-bold text-muted-foreground">
730+
{amountSuffix}
731+
</Text>
732+
) : null}
719733
</View>
720734
</Pressable>
721735
</View>

client/src/screens/SendScreen.tsx

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,18 @@ import { CurrencyToggle } from "~/components/CurrencyToggle";
2727
import { COLORS } from "~/lib/styleConstants";
2828
import { useBottomTabBarHeight } from "react-native-bottom-tabs";
2929
import { BlinkingCaret } from "~/components/BlinkingCaret";
30-
import { useBitcoinAmountFormatter } from "~/hooks/useBitcoinAmountFormatter";
30+
import {
31+
useBitcoinAmountFormatter,
32+
useBitcoinAmountUnit,
33+
} from "~/hooks/useBitcoinAmountFormatter";
3134

3235
const SendScreen = () => {
3336
const navigation = useNavigation();
3437
const isFocused = useIsFocused();
3538
const iconColor = useIconColor();
3639
const colors = useThemeColors();
3740
const formatBitcoinAmount = useBitcoinAmountFormatter();
41+
const bitcoinAmountUnit = useBitcoinAmountUnit();
3842
const bottomTabBarHeight = useBottomTabBarHeight();
3943
const destinationInputRef = React.useRef<TextInput>(null);
4044
const amountInputRef = React.useRef<TextInput>(null);
@@ -91,6 +95,9 @@ const SendScreen = () => {
9195
} = useSendScreen();
9296
const fiatCurrencyInfo = getFiatCurrencyInfo(fiatCurrency);
9397
const displayAmount = amount === "" ? (currency === "FIAT" ? "0.00" : "0") : amount;
98+
const amountPrefix =
99+
currency === "FIAT" ? fiatCurrencyInfo.symbol : bitcoinAmountUnit === "bip177" ? "₿" : null;
100+
const amountSuffix = currency === "SATS" && bitcoinAmountUnit === "sats" ? "sats" : null;
94101

95102
const handlePaste = async () => {
96103
const text = await Clipboard.getStringAsync();
@@ -179,9 +186,11 @@ const SendScreen = () => {
179186
<View className="self-center">
180187
<Pressable onPress={focusAmountInput} disabled={!isAmountEditable}>
181188
<View className="flex-row items-center justify-center">
182-
<Text className="mr-3 text-[46px] font-bold leading-[52px] text-foreground">
183-
{currency === "FIAT" ? fiatCurrencyInfo.symbol : "₿"}
184-
</Text>
189+
{amountPrefix ? (
190+
<Text className="mr-3 text-[46px] font-bold leading-[52px] text-foreground">
191+
{amountPrefix}
192+
</Text>
193+
) : null}
185194
<Text
186195
className={`text-[46px] font-bold leading-[52px] ${
187196
isAmountEditable ? "text-foreground" : "text-foreground/70"
@@ -194,6 +203,11 @@ const SendScreen = () => {
194203
height={40}
195204
visible={isAmountFocused && isAmountEditable}
196205
/>
206+
{amountSuffix ? (
207+
<Text className="ml-3 text-2xl font-bold text-muted-foreground">
208+
{amountSuffix}
209+
</Text>
210+
) : null}
197211
</View>
198212
</Pressable>
199213
</View>

0 commit comments

Comments
 (0)