Skip to content

Commit

Permalink
Refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
kackogut committed Sep 17, 2023
1 parent 7dd0fb3 commit f4c3552
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 101 deletions.
2 changes: 1 addition & 1 deletion lib/data/token/spl_tokens.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const Map<String, String?> SPL_TOKENS = {
const Map<String, String?> splTokens = {
"SOL": null,
"USD": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"
};
6 changes: 3 additions & 3 deletions lib/data/transfer/transfer_request_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ abstract class TransferRequestRepository {
class DefaultTransferRequestRepository extends TransferRequestRepository {
@override
String getLink(SolanaPayRequest solanaPayRequest) {
Map<String, dynamic> queryParameters = _getQueryParameters(solanaPayRequest);
Map<String, dynamic> queryParameters =
_getQueryParameters(solanaPayRequest);

return Uri(
scheme: solanaProtocol,
path: solanaPayRequest.address,
queryParameters: queryParameters,
)
.toString();
).toString();
}

Map<String, dynamic> _getQueryParameters(SolanaPayRequest solanaPayRequest) {
Expand Down
21 changes: 10 additions & 11 deletions lib/feature/input/bloc/parameters_input_cubit.dart
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
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,
splTokenAddress: 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 Down
19 changes: 9 additions & 10 deletions lib/feature/input/bloc/parameters_input_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@ class ParametersInputState extends Equatable {
final String? memo;
final String? splTokenAddress;

const ParametersInputState({
required this.address,
required this.amount,
required this.reference,
required this.label,
required this.message,
required this.memo,
required this.splTokenAddress
});
const ParametersInputState(
{required this.address,
required this.amount,
required this.reference,
required this.label,
required this.message,
required this.memo,
required this.splTokenAddress});

@override
List<Object?> get props => [
Expand All @@ -27,7 +26,7 @@ class ParametersInputState extends Equatable {
label,
message,
memo,
splTokenAddress,
splTokenAddress,
];

ParametersInputState copyWith({
Expand Down
148 changes: 73 additions & 75 deletions lib/feature/input/parameters_input_screen.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
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 @@ -40,81 +39,80 @@ class InputBody extends StatelessWidget {

@override
Widget build(BuildContext context) => Column(
mainAxisSize: MainAxisSize.max,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Padding(
padding: const EdgeInsets.all(24.0),
child: ListView(
shrinkWrap: true,
children: [
BaseInput(
labelText: 'Receive wallet address',
onChanged: (address) => context
.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',
onChanged: (text) =>
context.read<ParametersInputCubit>().onLabelChange(text),
),
const Padding(padding: EdgeInsets.only(top: 16.0)),
BaseInput(
labelText: 'Message',
onChanged: (text) =>
context.read<ParametersInputCubit>().onMessageChange(text),
),
const Padding(padding: EdgeInsets.only(top: 16.0)),
BaseInput(
labelText: 'Reference',
onChanged: (address) => context
.read<ParametersInputCubit>()
.onReferenceChange(address),
mainAxisSize: MainAxisSize.max,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Padding(
padding: const EdgeInsets.all(24.0),
child: ListView(
shrinkWrap: true,
children: [
BaseInput(
labelText: 'Receive wallet address',
onChanged: (address) => context
.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',
onChanged: (text) =>
context.read<ParametersInputCubit>().onLabelChange(text),
),
const Padding(padding: EdgeInsets.only(top: 16.0)),
BaseInput(
labelText: 'Message',
onChanged: (text) => context
.read<ParametersInputCubit>()
.onMessageChange(text),
),
const Padding(padding: EdgeInsets.only(top: 16.0)),
BaseInput(
labelText: 'Reference',
onChanged: (address) => context
.read<ParametersInputCubit>()
.onReferenceChange(address),
),
const Padding(padding: EdgeInsets.only(top: 16.0)),
BaseInput(
labelText: 'Memo',
onChanged: (memo) =>
context.read<ParametersInputCubit>().onMemoChange(memo),
),
const Padding(padding: EdgeInsets.only(top: 16.0)),
BaseInput(
labelText: 'SPL token',
onChanged: (token) => context
.read<ParametersInputCubit>()
.onSplTokenChange(token),
),
],
),
),
const Spacer(),
Padding(
padding: const EdgeInsets.all(24.0),
child: MaterialButton(
onPressed: () => context.read<QrGeneratorCubit>().onGenerate(),
color: Colors.blueAccent,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16.0),
),
const Padding(padding: EdgeInsets.only(top: 16.0)),
BaseInput(
labelText: 'Memo',
onChanged: (memo) => context
.read<ParametersInputCubit>()
.onMemoChange(memo),
height: 56.0,
child: const Text(
"Let's go",
style: TextStyle(color: Colors.white),
),
const Padding(padding: EdgeInsets.only(top: 16.0)),

BaseInput(
labelText: 'SPL token',
onChanged: (token) => context
.read<ParametersInputCubit>()
.onSplTokenChange(token),
),
],
),
),
const Spacer(),
Padding(
padding: const EdgeInsets.all(24.0),
child: MaterialButton(
onPressed: () => context.read<QrGeneratorCubit>().onGenerate(),
color: Colors.blueAccent,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16.0),
),
height: 56.0,
child: const Text(
"Let's go",
style: TextStyle(color: Colors.white),
),
),
)
],
);
)
],
);
}
1 change: 0 additions & 1 deletion lib/feature/qr/bloc/qr_generator_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import 'package:equatable/equatable.dart';
sealed class QrGeneratorState extends Equatable {}

final class Empty extends QrGeneratorState {

@override
List<Object?> get props => [];
}
Expand Down

0 comments on commit f4c3552

Please sign in to comment.