Skip to content

Commit 055a457

Browse files
authored
Merge pull request #1624 from SatoshiPortal/remove-dialpad-for-amounts
refactor: remove dialpad for amounts
2 parents 836e673 + f7ab723 commit 055a457

5 files changed

Lines changed: 78 additions & 243 deletions

File tree

Lines changed: 0 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import 'package:bb_mobile/core/themes/app_theme.dart';
2-
import 'package:bb_mobile/core/widgets/inputs/amount_input_formatter.dart';
32
import 'package:bb_mobile/core/widgets/text/text.dart';
43
import 'package:flutter/material.dart';
54

@@ -99,136 +98,3 @@ class DialPad extends StatelessWidget {
9998
);
10099
}
101100
}
102-
103-
/// DialPad widget for amount entry with built-in formatting
104-
class AmountDialPad extends StatelessWidget {
105-
const AmountDialPad({
106-
super.key,
107-
required this.controller,
108-
required this.inputCurrencyCode,
109-
this.disableFeedback = false,
110-
this.onAmountChanged,
111-
});
112-
113-
final TextEditingController controller;
114-
final String inputCurrencyCode;
115-
final bool disableFeedback;
116-
final VoidCallback? onAmountChanged;
117-
118-
void _handleNumberPressed(String number) {
119-
final formatter = AmountInputFormatter(inputCurrencyCode);
120-
final currentValue = controller.value;
121-
final selectionStart = currentValue.selection.baseOffset;
122-
final selectionEnd = currentValue.selection.extentOffset;
123-
final currentText = currentValue.text;
124-
125-
// Build new text by inserting/replacing at selection
126-
final String newText;
127-
final int newCursorPos;
128-
129-
if (selectionStart == -1) {
130-
// Field is not focused, add to end
131-
newText = currentText + number;
132-
newCursorPos = newText.length;
133-
} else if (selectionStart == selectionEnd) {
134-
// No selection, insert at cursor
135-
newText =
136-
currentText.substring(0, selectionStart) +
137-
number +
138-
currentText.substring(selectionStart);
139-
newCursorPos = selectionStart + number.length;
140-
} else {
141-
// Replace selection
142-
newText =
143-
currentText.substring(0, selectionStart) +
144-
number +
145-
currentText.substring(selectionEnd);
146-
newCursorPos = selectionStart + number.length;
147-
}
148-
149-
// Apply formatter (it handles cursor positioning)
150-
final formattedValue = formatter.formatEditUpdate(
151-
currentValue,
152-
TextEditingValue(
153-
text: newText,
154-
selection: TextSelection.collapsed(offset: newCursorPos),
155-
),
156-
);
157-
158-
if (formattedValue.text != currentText) {
159-
controller.value = formattedValue;
160-
onAmountChanged?.call();
161-
}
162-
}
163-
164-
void _handleBackspacePressed() {
165-
final formatter = AmountInputFormatter(inputCurrencyCode);
166-
final currentValue = controller.value;
167-
final selectionStart = currentValue.selection.baseOffset;
168-
final selectionEnd = currentValue.selection.extentOffset;
169-
final currentText = currentValue.text;
170-
171-
// Build new text by removing at selection
172-
final String newText;
173-
final int newCursorPos;
174-
175-
if (selectionStart == -1) {
176-
// Field is not focused, remove from end
177-
newText =
178-
currentText.isNotEmpty
179-
? currentText.substring(0, currentText.length - 1)
180-
: currentText;
181-
newCursorPos = newText.length;
182-
} else if (selectionStart == selectionEnd) {
183-
// No selection, remove before cursor
184-
if (selectionStart > 0) {
185-
newText =
186-
currentText.substring(0, selectionStart - 1) +
187-
currentText.substring(selectionStart);
188-
newCursorPos = selectionStart - 1;
189-
} else {
190-
newText = currentText;
191-
newCursorPos = 0;
192-
}
193-
} else {
194-
// Remove selection
195-
newText =
196-
currentText.substring(0, selectionStart) +
197-
currentText.substring(selectionEnd);
198-
newCursorPos = selectionStart;
199-
}
200-
201-
// Apply formatter (it handles cursor positioning)
202-
final formattedValue = formatter.formatEditUpdate(
203-
currentValue,
204-
TextEditingValue(
205-
text: newText,
206-
selection: TextSelection.collapsed(offset: newCursorPos),
207-
),
208-
);
209-
210-
if (formattedValue.text != currentText) {
211-
controller.value = formattedValue;
212-
onAmountChanged?.call();
213-
}
214-
}
215-
216-
@override
217-
Widget build(BuildContext context) {
218-
// Check if decimals are allowed
219-
final decimalPlaces =
220-
inputCurrencyCode == 'sats'
221-
? 0
222-
: inputCurrencyCode == 'BTC'
223-
? 8
224-
: 2;
225-
final onlyDigits = decimalPlaces == 0;
226-
227-
return DialPad(
228-
onNumberPressed: _handleNumberPressed,
229-
onBackspacePressed: _handleBackspacePressed,
230-
disableFeedback: disableFeedback,
231-
onlyDigits: onlyDigits,
232-
);
233-
}
234-
}

lib/features/ark/ui/send_amount_page.dart

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@ import 'package:bb_mobile/core/settings/domain/settings_entity.dart';
22
import 'package:bb_mobile/core/themes/app_theme.dart';
33
import 'package:bb_mobile/core/utils/build_context_x.dart';
44
import 'package:bb_mobile/core/widgets/buttons/button.dart';
5-
import 'package:bb_mobile/core/widgets/dialpad/dial_pad.dart';
65
import 'package:bb_mobile/core/widgets/loading/fading_linear_progress.dart';
76
import 'package:bb_mobile/core/widgets/price_input/balance_row.dart';
87
import 'package:bb_mobile/core/widgets/price_input/price_input.dart';
98
import 'package:bb_mobile/core/widgets/scrollable_column.dart';
109
import 'package:bb_mobile/features/ark/presentation/cubit.dart';
1110
import 'package:flutter/material.dart';
1211
import 'package:flutter_bloc/flutter_bloc.dart';
13-
import 'package:gap/gap.dart';
1412

1513
class SendAmountPage extends StatefulWidget {
1614
const SendAmountPage({
@@ -124,8 +122,10 @@ class _SendAmountPageState extends State<SendAmountPage> {
124122
final inputAmount = _controller.text;
125123
final exchangeRate = context.read<ArkCubit>().state.exchangeRate;
126124
final bitcoinUnit = context.read<ArkCubit>().state.preferredBitcoinUnit;
127-
final equivalentCurrencyCode =
128-
context.read<ArkCubit>().state.equivalentCurrencyCode;
125+
final equivalentCurrencyCode = context
126+
.read<ArkCubit>()
127+
.state
128+
.equivalentCurrencyCode;
129129
String equivalentValue = '0';
130130
if (_currencyCode == BitcoinUnit.sats.code) {
131131
final amountSat = int.tryParse(inputAmount) ?? 0;
@@ -135,10 +135,9 @@ class _SendAmountPageState extends State<SendAmountPage> {
135135
equivalentValue = (amountBtc * exchangeRate).toStringAsFixed(2);
136136
} else {
137137
final amountFiat = double.tryParse(inputAmount) ?? 0;
138-
equivalentValue =
139-
bitcoinUnit == BitcoinUnit.sats
140-
? (amountFiat * 1e8 / exchangeRate).toStringAsFixed(0)
141-
: (amountFiat / exchangeRate).toStringAsFixed(8);
138+
equivalentValue = bitcoinUnit == BitcoinUnit.sats
139+
? (amountFiat * 1e8 / exchangeRate).toStringAsFixed(0)
140+
: (amountFiat / exchangeRate).toStringAsFixed(8);
142141
}
143142
return '$equivalentValue $equivalentCurrencyCode';
144143
}
@@ -168,15 +167,14 @@ class _SendAmountPageState extends State<SendAmountPage> {
168167
),
169168
bottom: PreferredSize(
170169
preferredSize: const Size.fromHeight(3),
171-
child:
172-
_isLoading
173-
? FadingLinearProgress(
174-
height: 3,
175-
trigger: _isLoading,
176-
backgroundColor: context.appColors.surface,
177-
foregroundColor: context.appColors.primary,
178-
)
179-
: const SizedBox(height: 3),
170+
child: _isLoading
171+
? FadingLinearProgress(
172+
height: 3,
173+
trigger: _isLoading,
174+
backgroundColor: context.appColors.surface,
175+
foregroundColor: context.appColors.primary,
176+
)
177+
: const SizedBox(height: 3),
180178
),
181179
),
182180
body: SafeArea(
@@ -204,14 +202,11 @@ class _SendAmountPageState extends State<SendAmountPage> {
204202
Padding(
205203
padding: const EdgeInsets.symmetric(vertical: 16),
206204
child: BalanceRow(
207-
balance:
208-
_preferredBitcoinUnit == BitcoinUnit.btc
209-
? (_maxSpendableSat != null
210-
? (_maxSpendableSat! / 1e8).toStringAsFixed(
211-
8,
212-
)
213-
: '0.00000000')
214-
: (_maxSpendableSat?.toString() ?? '0'),
205+
balance: _preferredBitcoinUnit == BitcoinUnit.btc
206+
? (_maxSpendableSat != null
207+
? (_maxSpendableSat! / 1e8).toStringAsFixed(8)
208+
: '0.00000000')
209+
: (_maxSpendableSat?.toString() ?? '0'),
215210
currencyCode: _preferredBitcoinUnit.code,
216211
onMaxPressed: () async {
217212
await context
@@ -224,11 +219,6 @@ class _SendAmountPageState extends State<SendAmountPage> {
224219
walletLabel: context.loc.arkInstantPayments,
225220
),
226221
),
227-
const Gap(24),
228-
AmountDialPad(
229-
controller: _controller,
230-
inputCurrencyCode: _currencyCode,
231-
),
232222
],
233223
),
234224
BBButton.big(

lib/features/receive/ui/screens/receive_amount_screen.dart

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import 'package:bb_mobile/core/utils/build_context_x.dart';
33
import 'package:bb_mobile/core/widgets/buttons/button.dart';
44
import 'package:bb_mobile/features/receive/presentation/bloc/receive_bloc.dart';
55
import 'package:bb_mobile/features/receive/ui/widgets/receive_amount_entry.dart';
6-
import 'package:bb_mobile/features/receive/ui/widgets/receive_numberpad.dart';
76
import 'package:flutter/material.dart';
87
import 'package:flutter_bloc/flutter_bloc.dart';
98
import 'package:go_router/go_router.dart';
@@ -16,14 +15,13 @@ class ReceiveAmountScreen extends StatelessWidget {
1615
@override
1716
Widget build(BuildContext context) {
1817
return BlocListener<ReceiveBloc, ReceiveState>(
19-
listenWhen:
20-
(previous, current) =>
21-
// Only listen on confirmed amount changes
22-
previous.confirmedAmountSat != current.confirmedAmountSat &&
23-
// Only listen when no amount exception is present
24-
current.amountException == null &&
25-
// Prevent using the amount from a previous receive type
26-
previous.type == current.type,
18+
listenWhen: (previous, current) =>
19+
// Only listen on confirmed amount changes
20+
previous.confirmedAmountSat != current.confirmedAmountSat &&
21+
// Only listen when no amount exception is present
22+
current.amountException == null &&
23+
// Prevent using the amount from a previous receive type
24+
previous.type == current.type,
2725
listener: (context, state) {
2826
onContinueNavigation?.call() ?? context.pop();
2927
},
@@ -84,10 +82,8 @@ class _AmountPageState extends State<AmountPage> {
8482
@override
8583
Widget build(BuildContext context) {
8684
return BlocListener<ReceiveBloc, ReceiveState>(
87-
listenWhen:
88-
(previous, current) =>
89-
previous.inputAmountCurrencyCode !=
90-
current.inputAmountCurrencyCode,
85+
listenWhen: (previous, current) =>
86+
previous.inputAmountCurrencyCode != current.inputAmountCurrencyCode,
9187
listener: (context, state) {
9288
// Clear the controller when currency changes
9389
_amountController.clear();
@@ -105,7 +101,6 @@ class _AmountPageState extends State<AmountPage> {
105101
amountController: _amountController,
106102
focusNode: _amountFocusNode,
107103
),
108-
ReceiveNumberPad(amountController: _amountController),
109104
ReceiveAmountContinueButton(
110105
onContinueNavigation: widget.onContinueNavigation,
111106
),

lib/features/receive/ui/widgets/receive_numberpad.dart

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)