From 5884ff072aa676c41b22163522f182deba8c37cb Mon Sep 17 00:00:00 2001 From: kacper Date: Thu, 3 Aug 2023 18:00:40 +0200 Subject: [PATCH 1/5] SPL token address input --- .idea/libraries/Dart_Packages.xml | 260 ------------------ .idea/solana_pay_generator.iml | 1 - lib/design/input/base_input.dart | 20 +- .../input/bloc/parameters_input_cubit.dart | 24 +- .../input/bloc/parameters_input_state.dart | 5 + .../input/parameters_input_screen.dart | 37 +-- 6 files changed, 50 insertions(+), 297 deletions(-) delete mode 100644 .idea/libraries/Dart_Packages.xml diff --git a/.idea/libraries/Dart_Packages.xml b/.idea/libraries/Dart_Packages.xml deleted file mode 100644 index fdcded5..0000000 --- a/.idea/libraries/Dart_Packages.xml +++ /dev/null @@ -1,260 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/solana_pay_generator.iml b/.idea/solana_pay_generator.iml index 6155e93..a2ffcc2 100644 --- a/.idea/solana_pay_generator.iml +++ b/.idea/solana_pay_generator.iml @@ -10,6 +10,5 @@ - \ No newline at end of file diff --git a/lib/design/input/base_input.dart b/lib/design/input/base_input.dart index 6796185..0f5b151 100644 --- a/lib/design/input/base_input.dart +++ b/lib/design/input/base_input.dart @@ -4,12 +4,18 @@ class BaseInput extends StatelessWidget { final String _labelText; final ValueChanged? _onChanged; final TextInputType? _keyboardType; + final bool _focusable; - const BaseInput( - {super.key, required labelText, required onChanged, keyboardType}) - : _labelText = labelText, + const BaseInput({ + super.key, + required labelText, + required onChanged, + keyboardType, + focusable, + }) : _labelText = labelText, _onChanged = onChanged, - _keyboardType = keyboardType; + _keyboardType = keyboardType, + _focusable = focusable ?? true; @override Widget build(BuildContext context) { @@ -20,6 +26,12 @@ class BaseInput extends StatelessWidget { ), onChanged: _onChanged, keyboardType: _keyboardType, + focusNode: _focusable ? null : AlwaysDisabledFocusNode(), ); } } + +class AlwaysDisabledFocusNode extends FocusNode { + @override + bool get hasFocus => false; +} diff --git a/lib/feature/input/bloc/parameters_input_cubit.dart b/lib/feature/input/bloc/parameters_input_cubit.dart index e1d7167..6faf423 100644 --- a/lib/feature/input/bloc/parameters_input_cubit.dart +++ b/lib/feature/input/bloc/parameters_input_cubit.dart @@ -1,18 +1,20 @@ import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:sol_pay_gen/data/token/spl_tokens.dart'; import 'package:sol_pay_gen/feature/input/bloc/parameters_input_state.dart'; class ParametersInputCubit extends Cubit { ParametersInputCubit() : super( - const ParametersInputState( - address: "", - amount: null, - reference: null, - memo: null, - message: null, - label: null, - ), - ); + const ParametersInputState( + address: "", + amount: null, + reference: null, + memo: null, + message: null, + label: null, + splTokenAddress: null, + ), + ); void onAddressChange(String address) { emit(state.copyWith(address: address)); @@ -33,4 +35,8 @@ class ParametersInputCubit extends Cubit { void onReferenceChange(String reference) { emit(state.copyWith(reference: reference)); } + + void onSplTokenChange(String token) { + emit(state.copyWith(splTokenAddress: token)); + } } diff --git a/lib/feature/input/bloc/parameters_input_state.dart b/lib/feature/input/bloc/parameters_input_state.dart index 2e8f70d..43723c5 100644 --- a/lib/feature/input/bloc/parameters_input_state.dart +++ b/lib/feature/input/bloc/parameters_input_state.dart @@ -7,6 +7,7 @@ class ParametersInputState extends Equatable { final String? label; final String? message; final String? memo; + final String? splTokenAddress; const ParametersInputState({ required this.address, @@ -15,6 +16,7 @@ class ParametersInputState extends Equatable { required this.label, required this.message, required this.memo, + required this.splTokenAddress }); @override @@ -25,6 +27,7 @@ class ParametersInputState extends Equatable { label, message, memo, + splTokenAddress, ]; ParametersInputState copyWith({ @@ -34,6 +37,7 @@ class ParametersInputState extends Equatable { String? message, String? reference, String? memo, + String? splTokenAddress, }) => ParametersInputState( address: address ?? this.address, @@ -42,5 +46,6 @@ class ParametersInputState extends Equatable { message: message ?? this.message, reference: reference ?? this.reference, memo: memo ?? this.memo, + splTokenAddress: splTokenAddress ?? this.splTokenAddress, ); } diff --git a/lib/feature/input/parameters_input_screen.dart b/lib/feature/input/parameters_input_screen.dart index 9e5649d..8d9b86a 100644 --- a/lib/feature/input/parameters_input_screen.dart +++ b/lib/feature/input/parameters_input_screen.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:sol_pay_gen/data/token/spl_tokens.dart'; import 'package:sol_pay_gen/feature/input/bloc/parameters_input_cubit.dart'; import 'package:sol_pay_gen/feature/qr/bloc/qr_generator_cubit.dart'; import 'package:sol_pay_gen/feature/qr/bloc/qr_generator_state.dart'; @@ -38,8 +39,7 @@ class InputBody extends StatelessWidget { final ParametersInputState state; @override - Widget build(BuildContext context) { - return Column( + Widget build(BuildContext context) => Column( mainAxisSize: MainAxisSize.max, crossAxisAlignment: CrossAxisAlignment.stretch, children: [ @@ -54,9 +54,7 @@ class InputBody extends StatelessWidget { .read() .onAddressChange(address), ), - const Padding(padding: EdgeInsets.only(top: 16.0)), - BaseInput( labelText: 'Amount', keyboardType: TextInputType.number, @@ -64,46 +62,40 @@ class InputBody extends StatelessWidget { .read() .onAmountChange(address), ), - const Padding(padding: EdgeInsets.only(top: 16.0)), - BaseInput( labelText: 'Label', - keyboardType: TextInputType.number, - onChanged: (text) => context - .read() - .onLabelChange(text), + onChanged: (text) => + context.read().onLabelChange(text), ), - const Padding(padding: EdgeInsets.only(top: 16.0)), - BaseInput( labelText: 'Message', - keyboardType: TextInputType.number, - onChanged: (text) => context - .read() - .onMessageChange(text), + onChanged: (text) => + context.read().onMessageChange(text), ), - const Padding(padding: EdgeInsets.only(top: 16.0)), - BaseInput( labelText: 'Reference', - keyboardType: TextInputType.number, onChanged: (address) => context .read() .onReferenceChange(address), ), - const Padding(padding: EdgeInsets.only(top: 16.0)), - BaseInput( labelText: 'Memo', - keyboardType: TextInputType.number, onChanged: (address) => context .read() .onReferenceChange(address), ), + const Padding(padding: EdgeInsets.only(top: 16.0)), + + BaseInput( + labelText: 'SPL token', + onChanged: (token) => context + .read() + .onSplTokenChange(token), + ), ], ), ), @@ -125,5 +117,4 @@ class InputBody extends StatelessWidget { ) ], ); - } } From 6781573a5d42311513ec4ee83eeb9fbfa44dfb75 Mon Sep 17 00:00:00 2001 From: kacper Date: Thu, 3 Aug 2023 18:10:51 +0200 Subject: [PATCH 2/5] Add SPL token model --- .idea/solana_pay_generator.iml | 1 + lib/data/token/spl_tokens.dart | 4 ++++ lib/design/input/base_input.dart | 5 +++++ 3 files changed, 10 insertions(+) create mode 100644 lib/data/token/spl_tokens.dart diff --git a/.idea/solana_pay_generator.iml b/.idea/solana_pay_generator.iml index a2ffcc2..6155e93 100644 --- a/.idea/solana_pay_generator.iml +++ b/.idea/solana_pay_generator.iml @@ -10,5 +10,6 @@ + \ No newline at end of file diff --git a/lib/data/token/spl_tokens.dart b/lib/data/token/spl_tokens.dart new file mode 100644 index 0000000..5e836ca --- /dev/null +++ b/lib/data/token/spl_tokens.dart @@ -0,0 +1,4 @@ +const Map SPL_TOKENS = { + "SOL": null, + "USD": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v" +}; diff --git a/lib/design/input/base_input.dart b/lib/design/input/base_input.dart index 0f5b151..5f61e7f 100644 --- a/lib/design/input/base_input.dart +++ b/lib/design/input/base_input.dart @@ -35,3 +35,8 @@ class AlwaysDisabledFocusNode extends FocusNode { @override bool get hasFocus => false; } + +class AlwaysDisabledFocusNode extends FocusNode { + @override + bool get hasFocus => false; +} From 881fe0a0450ad27119f2aa97157def7266876f6d Mon Sep 17 00:00:00 2001 From: kacper Date: Mon, 7 Aug 2023 13:36:38 +0200 Subject: [PATCH 3/5] Pass SPL token input --- .idea/misc.xml | 3 +++ lib/data/solana_pay_request.dart | 1 + lib/design/input/base_input.dart | 5 ----- lib/feature/qr/bloc/qr_generator_cubit.dart | 1 + 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index 6e86672..374f537 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -2,4 +2,7 @@ + + \ No newline at end of file diff --git a/lib/data/solana_pay_request.dart b/lib/data/solana_pay_request.dart index e5def7b..fe21801 100644 --- a/lib/data/solana_pay_request.dart +++ b/lib/data/solana_pay_request.dart @@ -6,6 +6,7 @@ class SolanaPayRequest { this.amount, this.reference, this.memo, + this.splToken, }); String address; diff --git a/lib/design/input/base_input.dart b/lib/design/input/base_input.dart index 5f61e7f..0f5b151 100644 --- a/lib/design/input/base_input.dart +++ b/lib/design/input/base_input.dart @@ -35,8 +35,3 @@ class AlwaysDisabledFocusNode extends FocusNode { @override bool get hasFocus => false; } - -class AlwaysDisabledFocusNode extends FocusNode { - @override - bool get hasFocus => false; -} diff --git a/lib/feature/qr/bloc/qr_generator_cubit.dart b/lib/feature/qr/bloc/qr_generator_cubit.dart index 770c809..a5828f8 100644 --- a/lib/feature/qr/bloc/qr_generator_cubit.dart +++ b/lib/feature/qr/bloc/qr_generator_cubit.dart @@ -26,6 +26,7 @@ class QrGeneratorCubit extends Cubit { amount: inputState.amount, reference: inputState.reference, memo: inputState.memo, + splToken: inputState.splTokenAddress, ); String qrCode = _generateTransferRequestQrUseCase.execute(request); From 203060a15623c9236ac967dc356e1940234cd3aa Mon Sep 17 00:00:00 2001 From: kacper Date: Mon, 7 Aug 2023 13:45:04 +0200 Subject: [PATCH 4/5] Fix spl token query params name --- lib/data/transfer/transfer_request_repository.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/data/transfer/transfer_request_repository.dart b/lib/data/transfer/transfer_request_repository.dart index 3754881..69351c4 100644 --- a/lib/data/transfer/transfer_request_repository.dart +++ b/lib/data/transfer/transfer_request_repository.dart @@ -25,7 +25,7 @@ class DefaultTransferRequestRepository extends TransferRequestRepository { queryParameters["amount"] = solanaPayRequest.amount!; } if (solanaPayRequest.splToken != null) { - queryParameters["splToken"] = solanaPayRequest.splToken!; + queryParameters["spl-token"] = solanaPayRequest.splToken!; } if (solanaPayRequest.reference != null) { queryParameters["reference"] = solanaPayRequest.reference; From 4cabe8bf8355ad1dcdf6f0dd5253864dd090edd3 Mon Sep 17 00:00:00 2001 From: kacper Date: Wed, 9 Aug 2023 18:12:13 +0200 Subject: [PATCH 5/5] Don't pass empty values --- lib/data/transfer/transfer_request_repository.dart | 12 ++++++------ lib/feature/input/bloc/parameters_input_cubit.dart | 4 ++++ lib/feature/input/parameters_input_screen.dart | 4 ++-- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/data/transfer/transfer_request_repository.dart b/lib/data/transfer/transfer_request_repository.dart index 69351c4..f7e5606 100644 --- a/lib/data/transfer/transfer_request_repository.dart +++ b/lib/data/transfer/transfer_request_repository.dart @@ -21,22 +21,22 @@ class DefaultTransferRequestRepository extends TransferRequestRepository { Map _getQueryParameters(SolanaPayRequest solanaPayRequest) { Map queryParameters = {}; - if (solanaPayRequest.amount != null) { + if (solanaPayRequest.amount?.isNotEmpty == true) { queryParameters["amount"] = solanaPayRequest.amount!; } - if (solanaPayRequest.splToken != null) { + if (solanaPayRequest.splToken?.isNotEmpty == true) { queryParameters["spl-token"] = solanaPayRequest.splToken!; } - if (solanaPayRequest.reference != null) { + if (solanaPayRequest.reference?.isNotEmpty == true) { queryParameters["reference"] = solanaPayRequest.reference; } - if (solanaPayRequest.label != null) { + if (solanaPayRequest.label?.isNotEmpty == true) { queryParameters["label"] = solanaPayRequest.label; } - if (solanaPayRequest.message != null) { + if (solanaPayRequest.message?.isNotEmpty == true) { queryParameters["message"] = solanaPayRequest.message; } - if (solanaPayRequest.memo != null) { + if (solanaPayRequest.memo?.isNotEmpty == true) { queryParameters["memo"] = solanaPayRequest.memo; } diff --git a/lib/feature/input/bloc/parameters_input_cubit.dart b/lib/feature/input/bloc/parameters_input_cubit.dart index 6faf423..c0e7809 100644 --- a/lib/feature/input/bloc/parameters_input_cubit.dart +++ b/lib/feature/input/bloc/parameters_input_cubit.dart @@ -39,4 +39,8 @@ class ParametersInputCubit extends Cubit { void onSplTokenChange(String token) { emit(state.copyWith(splTokenAddress: token)); } + + void onMemoChange(String memo) { + emit(state.copyWith(memo: memo)); + } } diff --git a/lib/feature/input/parameters_input_screen.dart b/lib/feature/input/parameters_input_screen.dart index 8d9b86a..d50595d 100644 --- a/lib/feature/input/parameters_input_screen.dart +++ b/lib/feature/input/parameters_input_screen.dart @@ -84,9 +84,9 @@ class InputBody extends StatelessWidget { const Padding(padding: EdgeInsets.only(top: 16.0)), BaseInput( labelText: 'Memo', - onChanged: (address) => context + onChanged: (memo) => context .read() - .onReferenceChange(address), + .onMemoChange(memo), ), const Padding(padding: EdgeInsets.only(top: 16.0)),