-
Notifications
You must be signed in to change notification settings - Fork 1
Point of Sale (POS) mode #419
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| class PosPaymentRequest { | ||
| final String paymentUrl; | ||
| final String refId; | ||
| final String amount; | ||
|
|
||
| const PosPaymentRequest({required this.paymentUrl, required this.refId, required this.amount}); | ||
| } | ||
|
|
||
| class PosService { | ||
| String generateRefId() { | ||
| final now = DateTime.now().millisecondsSinceEpoch; | ||
| return now.toRadixString(36).toUpperCase(); | ||
| } | ||
|
|
||
| String buildPaymentUrl({required String accountId, required String amount, required String refId}) { | ||
| final uri = Uri.https('www.quantus.com', '/pay', {'to': accountId, 'amount': amount, 'ref': refId}); | ||
| return uri.toString(); | ||
| } | ||
|
|
||
| PosPaymentRequest createPaymentRequest({required String accountId, required String amount}) { | ||
| final refId = generateRefId(); | ||
| final url = buildPaymentUrl(accountId: accountId, amount: amount, refId: refId); | ||
| return PosPaymentRequest(paymentUrl: url, refId: refId, amount: amount); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,143 @@ | ||
| import 'package:flutter/material.dart'; | ||
| import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
| import 'package:intl/intl.dart'; | ||
| import 'package:quantus_sdk/quantus_sdk.dart'; | ||
| import 'package:resonance_network_wallet/features/components/button.dart'; | ||
| import 'package:resonance_network_wallet/v2/components/scaffold_base.dart'; | ||
| import 'package:resonance_network_wallet/v2/components/v2_app_bar.dart'; | ||
| import 'package:resonance_network_wallet/v2/screens/pos/pos_qr_screen.dart'; | ||
| import 'package:resonance_network_wallet/v2/theme/app_colors.dart'; | ||
| import 'package:resonance_network_wallet/v2/theme/app_text_styles.dart'; | ||
|
|
||
| class PosAmountScreen extends ConsumerStatefulWidget { | ||
| const PosAmountScreen({super.key}); | ||
|
|
||
| @override | ||
| ConsumerState<PosAmountScreen> createState() => _PosAmountScreenState(); | ||
| } | ||
|
|
||
| class _PosAmountScreenState extends ConsumerState<PosAmountScreen> { | ||
| String _input = '0'; | ||
| final _fmt = NumberFormattingService(); | ||
| final _decimalFilter = DecimalInputFilter(); | ||
|
|
||
| void _onDigit(String digit) { | ||
| final oldText = _input == '0' && digit != '.' && digit != ',' ? '' : _input; | ||
| final newText = oldText + digit; | ||
|
|
||
| final oldValue = TextEditingValue(text: oldText); | ||
| final newValue = TextEditingValue(text: newText); | ||
|
|
||
| final formatted = _decimalFilter.formatEditUpdate(oldValue, newValue); | ||
|
|
||
| setState(() { | ||
| _input = formatted.text.isEmpty ? '0' : formatted.text; | ||
| }); | ||
| } | ||
|
|
||
| void _onBackspace() { | ||
| setState(() { | ||
| if (_input.length <= 1) { | ||
| _input = '0'; | ||
| } else { | ||
| _input = _input.substring(0, _input.length - 1); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| void _onClear() => setState(() => _input = '0'); | ||
|
|
||
| void _onCharge() { | ||
| final amount = _fmt.parseAmount(_input); | ||
| if (amount == null || amount <= BigInt.zero) return; | ||
| Navigator.push(context, MaterialPageRoute(builder: (_) => PosQrScreen(amount: _input))); | ||
| } | ||
|
|
||
| bool get _isValid { | ||
| final amount = _fmt.parseAmount(_input); | ||
| return amount != null && amount > BigInt.zero; | ||
| } | ||
|
|
||
| @override | ||
| Widget build(BuildContext context) { | ||
| final colors = context.colors; | ||
| final text = context.themeText; | ||
|
|
||
| return ScaffoldBase( | ||
| appBar: const V2AppBar(title: 'New Charge'), | ||
| child: Column( | ||
| children: [ | ||
| Expanded( | ||
| child: Center( | ||
| child: FittedBox( | ||
| fit: BoxFit.scaleDown, | ||
| child: Text( | ||
| '$_input ${AppConstants.tokenSymbol}', | ||
| style: text.extraLargeTitle?.copyWith( | ||
| color: colors.textPrimary, | ||
| fontSize: 56, | ||
| fontWeight: FontWeight.w600, | ||
| ), | ||
| ), | ||
| ), | ||
| ), | ||
| ), | ||
| _buildKeypad(colors, text), | ||
| const SizedBox(height: 16), | ||
| _buildChargeButton(colors, text), | ||
| const SizedBox(height: 24), | ||
| ], | ||
| ), | ||
| ); | ||
| } | ||
|
|
||
| Widget _buildKeypad(AppColorsV2 colors, AppTextTheme text) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not really sure this is the best way to do this, because some locales use comma instead of dot to as decimal notation. |
||
| final decimalSeparator = NumberFormat().symbols.DECIMAL_SEP; | ||
| final keys = [ | ||
| ['1', '2', '3'], | ||
| ['4', '5', '6'], | ||
| ['7', '8', '9'], | ||
| [decimalSeparator, '0', 'backspace'], | ||
| ]; | ||
|
|
||
| return Column( | ||
| children: keys.map((row) { | ||
| return Padding( | ||
| padding: const EdgeInsets.symmetric(vertical: 6), | ||
| child: Row( | ||
| mainAxisAlignment: MainAxisAlignment.spaceEvenly, | ||
| children: row.map((key) => _buildKey(key, colors, text)).toList(), | ||
| ), | ||
| ); | ||
| }).toList(), | ||
| ); | ||
| } | ||
|
|
||
| Widget _buildKey(String key, AppColorsV2 colors, AppTextTheme text) { | ||
| return Expanded( | ||
| child: GestureDetector( | ||
| onTap: () => key == 'backspace' ? _onBackspace() : _onDigit(key), | ||
| onLongPress: key == 'backspace' ? _onClear : null, | ||
| behavior: HitTestBehavior.opaque, | ||
| child: Container( | ||
| height: 60, | ||
| alignment: Alignment.center, | ||
| child: key == 'backspace' | ||
| ? Icon(Icons.backspace_outlined, color: colors.textPrimary, size: 28) | ||
| : Text(key, style: text.mediumTitle?.copyWith(color: colors.textPrimary, fontSize: 28)), | ||
| ), | ||
| ), | ||
| ); | ||
| } | ||
|
|
||
| Widget _buildChargeButton(AppColorsV2 colors, AppTextTheme text) { | ||
| final disabled = !_isValid; | ||
| return Button( | ||
| label: _isValid ? 'Charge $_input ${AppConstants.tokenSymbol}' : 'Enter Amount', | ||
| variant: ButtonVariant.accent, | ||
| isDisabled: disabled, | ||
| onPressed: _onCharge, | ||
| textStyle: text.smallTitle?.copyWith(fontWeight: FontWeight.w700), | ||
| ); | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't we use the number formatting that we use in the usual send input?