Skip to content

Commit

Permalink
Merge branch 'main' into feature/ci
Browse files Browse the repository at this point in the history
# Conflicts:
#	.idea/libraries/Dart_Packages.xml
  • Loading branch information
kackogut committed Sep 17, 2023
2 parents 45b0747 + f305fdb commit 7dd0fb3
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 45 deletions.
3 changes: 3 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/data/solana_pay_request.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class SolanaPayRequest {
this.amount,
this.reference,
this.memo,
this.splToken,
});

String address;
Expand Down
4 changes: 4 additions & 0 deletions lib/data/token/spl_tokens.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const Map<String, String?> SPL_TOKENS = {
"SOL": null,
"USD": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"
};
14 changes: 7 additions & 7 deletions lib/data/transfer/transfer_request_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,22 @@ class DefaultTransferRequestRepository extends TransferRequestRepository {
Map<String, dynamic> _getQueryParameters(SolanaPayRequest solanaPayRequest) {
Map<String, dynamic> queryParameters = {};

if (solanaPayRequest.amount != null) {
if (solanaPayRequest.amount?.isNotEmpty == true) {
queryParameters["amount"] = solanaPayRequest.amount!;
}
if (solanaPayRequest.splToken != null) {
queryParameters["splToken"] = solanaPayRequest.splToken!;
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;
}

Expand Down
20 changes: 16 additions & 4 deletions lib/design/input/base_input.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@ class BaseInput extends StatelessWidget {
final String _labelText;
final ValueChanged<String>? _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) {
Expand All @@ -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;
}
28 changes: 19 additions & 9 deletions lib/feature/input/bloc/parameters_input_cubit.dart
Original file line number Diff line number Diff line change
@@ -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<ParametersInputState> {
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));
Expand All @@ -33,4 +35,12 @@ class ParametersInputCubit extends Cubit<ParametersInputState> {
void onReferenceChange(String reference) {
emit(state.copyWith(reference: reference));
}

void onSplTokenChange(String token) {
emit(state.copyWith(splTokenAddress: token));
}

void onMemoChange(String memo) {
emit(state.copyWith(memo: memo));
}
}
5 changes: 5 additions & 0 deletions lib/feature/input/bloc/parameters_input_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -15,6 +16,7 @@ class ParametersInputState extends Equatable {
required this.label,
required this.message,
required this.memo,
required this.splTokenAddress
});

@override
Expand All @@ -25,6 +27,7 @@ class ParametersInputState extends Equatable {
label,
message,
memo,
splTokenAddress,
];

ParametersInputState copyWith({
Expand All @@ -34,6 +37,7 @@ class ParametersInputState extends Equatable {
String? message,
String? reference,
String? memo,
String? splTokenAddress,
}) =>
ParametersInputState(
address: address ?? this.address,
Expand All @@ -42,5 +46,6 @@ class ParametersInputState extends Equatable {
message: message ?? this.message,
reference: reference ?? this.reference,
memo: memo ?? this.memo,
splTokenAddress: splTokenAddress ?? this.splTokenAddress,
);
}
41 changes: 16 additions & 25 deletions lib/feature/input/parameters_input_screen.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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: [
Expand All @@ -54,55 +54,47 @@ class InputBody extends StatelessWidget {
.read<ParametersInputCubit>()
.onAddressChange(address),
),

const Padding(padding: EdgeInsets.only(top: 16.0)),

BaseInput(
labelText: 'Amount',
keyboardType: TextInputType.number,
onChanged: (address) => context
.read<ParametersInputCubit>()
.onAmountChange(address),
),

const Padding(padding: EdgeInsets.only(top: 16.0)),

BaseInput(
labelText: 'Label',
keyboardType: TextInputType.number,
onChanged: (text) => context
.read<ParametersInputCubit>()
.onLabelChange(text),
onChanged: (text) =>
context.read<ParametersInputCubit>().onLabelChange(text),
),

const Padding(padding: EdgeInsets.only(top: 16.0)),

BaseInput(
labelText: 'Message',
keyboardType: TextInputType.number,
onChanged: (text) => context
.read<ParametersInputCubit>()
.onMessageChange(text),
onChanged: (text) =>
context.read<ParametersInputCubit>().onMessageChange(text),
),

const Padding(padding: EdgeInsets.only(top: 16.0)),

BaseInput(
labelText: 'Reference',
keyboardType: TextInputType.number,
onChanged: (address) => context
.read<ParametersInputCubit>()
.onReferenceChange(address),
),

const Padding(padding: EdgeInsets.only(top: 16.0)),

BaseInput(
labelText: 'Memo',
keyboardType: TextInputType.number,
onChanged: (address) => context
onChanged: (memo) => context
.read<ParametersInputCubit>()
.onReferenceChange(address),
.onMemoChange(memo),
),
const Padding(padding: EdgeInsets.only(top: 16.0)),

BaseInput(
labelText: 'SPL token',
onChanged: (token) => context
.read<ParametersInputCubit>()
.onSplTokenChange(token),
),
],
),
Expand All @@ -125,5 +117,4 @@ class InputBody extends StatelessWidget {
)
],
);
}
}
1 change: 1 addition & 0 deletions lib/feature/qr/bloc/qr_generator_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class QrGeneratorCubit extends Cubit<QrGeneratorState> {
amount: inputState.amount,
reference: inputState.reference,
memo: inputState.memo,
splToken: inputState.splTokenAddress,
);

String qrCode = _generateTransferRequestQrUseCase.execute(request);
Expand Down

0 comments on commit 7dd0fb3

Please sign in to comment.