Skip to content
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

Receive flow #260

Merged
merged 5 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/core/di/bloc_module.dart
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ void _registerBlocsModule() {
),
);

_registerFactoryWithParams<ReceiveBloc, WalletTokenData, void>(
(tokenData, _) => ReceiveBloc(tokenData, _getIt<SendTokenUseCase>()),
);

_registerFactory(
() => PushNotificationsBloc(
_getIt<FirebasePushNotificationsService>(),
Expand Down
5 changes: 3 additions & 2 deletions lib/core/di/di_setup.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ import 'package:hypha_wallet/ui/profile/usecases/set_image_use_case.dart';
import 'package:hypha_wallet/ui/profile/usecases/set_name_use_case.dart';
import 'package:hypha_wallet/ui/search_user/interactor/search_user_bloc.dart';
import 'package:hypha_wallet/ui/search_user/usecases/search_for_user_use_case.dart';
import 'package:hypha_wallet/ui/send/interactor/send_bloc.dart';
import 'package:hypha_wallet/ui/send/usecases/send_token_use_case.dart';
import 'package:hypha_wallet/ui/settings/interactor/settings_bloc.dart';
import 'package:hypha_wallet/ui/settings/usecases/delete_account_use_case.dart';
import 'package:hypha_wallet/ui/shared/usercases/get_user_profiles_from_accounts_use_case.dart';
Expand All @@ -82,6 +80,9 @@ import 'package:hypha_wallet/ui/token/token_settings/interactor/token_settings_b
import 'package:hypha_wallet/ui/token/token_settings/usecases/add_token_to_user_use_case.dart';
import 'package:hypha_wallet/ui/token/token_settings/usecases/get_all_tokens_use_case.dart';
import 'package:hypha_wallet/ui/token/token_settings/usecases/remove_token_from_user_use_case.dart';
import 'package:hypha_wallet/ui/transfer_tokens/receive/interactor/receive_bloc.dart';
import 'package:hypha_wallet/ui/transfer_tokens/send/interactor/send_bloc.dart';
import 'package:hypha_wallet/ui/transfer_tokens/send/usecases/send_token_use_case.dart';
import 'package:hypha_wallet/ui/wallet/data/wallet_token_data.dart';
import 'package:hypha_wallet/ui/wallet/interactor/wallet_bloc.dart';
import 'package:hypha_wallet/ui/wallet/usecases/get_transaction_history_data_use_case.dart';
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/search_user/components/search_user_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'package:hypha_wallet/ui/architecture/interactor/page_states.dart';
import 'package:hypha_wallet/ui/search_user/components/search_result_row.dart';
import 'package:hypha_wallet/ui/search_user/components/search_user_text_field.dart';
import 'package:hypha_wallet/ui/search_user/interactor/search_user_bloc.dart';
import 'package:hypha_wallet/ui/send/send_page.dart';
import 'package:hypha_wallet/ui/transfer_tokens/send/send_page.dart';
import 'package:hypha_wallet/ui/wallet/data/wallet_token_data.dart';

class SearchUserView extends StatelessWidget {
Expand Down
63 changes: 0 additions & 63 deletions lib/ui/send/components/send_memo_field.dart

This file was deleted.

37 changes: 17 additions & 20 deletions lib/ui/token/token_details/components/token_details_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import 'package:hypha_wallet/design/progress_indicator/hypha_progress_indicator.
import 'package:hypha_wallet/design/themes/extensions/theme_extension_provider.dart';
import 'package:hypha_wallet/ui/search_user/search_user_page.dart';
import 'package:hypha_wallet/ui/token/token_details/interactor/token_details_bloc.dart';
import 'package:hypha_wallet/ui/transfer_tokens/receive/receive_page.dart';
import 'package:hypha_wallet/ui/wallet/components/recent_transactions_view.dart';
import 'package:hypha_wallet/ui/wallet/data/wallet_token_data.dart';

Expand Down Expand Up @@ -60,27 +61,23 @@ class TokenDetailsView extends StatelessWidget {
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
// TODO(gguij): Complete receive
// Expanded(
// child: HyphaAppButton(
// title: 'Receive',
// onPressed: () {},
// buttonType: ButtonType.secondary,
// ),
// ),
// const SizedBox(width: 22),
Expanded(
child: BlocBuilder<TokenDetailsBloc, TokenDetailsState>(
builder: (context, state) {
return HyphaAppButton(
title: 'Send',
buttonType: ButtonType.primary,
onPressed: () {
Get.to(
() => SearchUserPage(pageTitle: 'Send ${state.token.name}', tokenModel: state.token),
);
},
);
child: HyphaAppButton(
title: 'Receive',
onPressed: () {
Get.to(() => ReceivePage(tokenData: context.read<TokenDetailsBloc>().state.token));
},
buttonType: ButtonType.secondary,
),
),
const SizedBox(width: 22),
Expanded(
child: HyphaAppButton(
title: 'Send',
buttonType: ButtonType.primary,
onPressed: () {
final token = context.read<TokenDetailsBloc>().state.token;
Get.to(() => SearchUserPage(pageTitle: 'Send ${token.name}', tokenModel: token));
},
),
),
Expand Down
59 changes: 59 additions & 0 deletions lib/ui/transfer_tokens/components/memo_field.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import 'package:flutter/material.dart';
import 'package:hypha_wallet/design/hypha_card.dart';
import 'package:hypha_wallet/design/hypha_colors.dart';
import 'package:hypha_wallet/design/themes/extensions/theme_extension_provider.dart';
import 'package:hypha_wallet/ui/shared/components/text_request_bottom_sheet.dart';
import 'package:hypha_wallet/ui/shared/ui_constants.dart';

class MemoField extends StatelessWidget {
final Function(String? text) onPressed;
final String? memo;

const MemoField({
super.key,
this.memo,
required this.onPressed,
});

@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () {
showModalBottomSheet(
isScrollControlled: true,
clipBehavior: Clip.hardEdge,
context: context,
builder: (modelContext) => FractionallySizedBox(
heightFactor: UIConstants.bottomSheetHeightFraction,
child: TextRequestBottomSheet(
title: 'Enter Memo',
initialText: memo ?? '',
onPressed: onPressed,
),
),
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(top: Radius.circular(30)),
),
);
},
child: HyphaCard(
child: Padding(
padding: const EdgeInsets.all(16),
child: Row(
children: [
Expanded(
child: Text(
memo ?? 'Memo (optional)',
style: context.hyphaTextTheme.regular.copyWith(color: memo == null ? HyphaColors.midGrey : null),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
memo == null ? const SizedBox.shrink() : const Icon(Icons.edit)
],
),
),
),
);
}
}
43 changes: 43 additions & 0 deletions lib/ui/transfer_tokens/components/number_keyboard_grid.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import 'package:collection/collection.dart';
import 'package:flutter/material.dart';
import 'package:hypha_wallet/design/hypha_card.dart';
import 'package:hypha_wallet/design/themes/extensions/theme_extension_provider.dart';
import 'package:hypha_wallet/ui/transfer_tokens/components/keypad_key.dart';

class NumberKeyboardGrid extends StatelessWidget {
final ValueChanged<KeypadKey> onKeyTapped;
const NumberKeyboardGrid({super.key, required this.onKeyTapped});

@override
Widget build(BuildContext context) {
return GridView.count(
crossAxisCount: 3,
shrinkWrap: true,
childAspectRatio: 1.8,
physics: const NeverScrollableScrollPhysics(),
children: KeypadKey.values.mapIndexed((index, element) {
final text = switch (element) {
KeypadKey.dot => '.',
KeypadKey.delete => '<-',
_ => element.value.toString(),
};
return GestureDetector(
onTap: (){
onKeyTapped(element);
},
child: Padding(
padding: EdgeInsets.only(top: 8, bottom: 8, left: index % 3 == 0 ? 0 : 8, right: index % 3 == 2 ? 0 : 8),
child: HyphaCard(
borderRadius: BorderRadius.circular(14),
child: Center(
child: Text(
text,
style: context.hyphaTextTheme.mediumTitles,
),
),
),
),
);
}).toList());
}
}
89 changes: 89 additions & 0 deletions lib/ui/transfer_tokens/receive/components/receive_view.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:get/get.dart';
import 'package:hypha_wallet/design/background/hypha_page_background.dart';
import 'package:hypha_wallet/design/bottom_component/hypha_safe_bottom_navigation_bar.dart';
import 'package:hypha_wallet/design/buttons/button_type.dart';
import 'package:hypha_wallet/design/buttons/hypha_app_button.dart';
import 'package:hypha_wallet/design/hypha_colors.dart';
import 'package:hypha_wallet/design/themes/extensions/theme_extension_provider.dart';
import 'package:hypha_wallet/ui/transfer_tokens/components/memo_field.dart';
import 'package:hypha_wallet/ui/transfer_tokens/components/number_keyboard_grid.dart';
import 'package:hypha_wallet/ui/transfer_tokens/receive/interactor/receive_bloc.dart';

class ReceiveView extends StatelessWidget {
const ReceiveView({super.key});

@override
Widget build(BuildContext context) {
return HyphaPageBackground(
withGradient: true,
child: Scaffold(
backgroundColor: Colors.transparent,
appBar: AppBar(
title: Text('Receive ${context.read<ReceiveBloc>().state.tokenData.name}'),
),
bottomNavigationBar: BlocBuilder<ReceiveBloc, ReceiveState>(
buildWhen: (p, c) => p.userEnteredAmount != c.userEnteredAmount,
builder: (context, state) {
return HyphaSafeBottomNavigationBar(
child: HyphaAppButton(
onPressed: () {
/// Navigate to receive screen
},
title: 'Next',
buttonType: ButtonType.primary,
isActive: state.isSubmitEnabled,
),
);
},
),
body: Padding(
padding: const EdgeInsets.symmetric(horizontal: 24),
child: Column(
children: [
BlocBuilder<ReceiveBloc, ReceiveState>(
buildWhen: (p, c) => p.userEnteredAmount != c.userEnteredAmount,
builder: (context, state) {
return Text(
state.userEnteredAmount ?? '0',
textAlign: TextAlign.center,
style: context.hyphaTextTheme.popsExtraLargeAndLight,
);
},
),
Row(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('Amount to ', style: Theme.of(context).textTheme.bodyMedium),
Text(
'receive',
style: Theme.of(context).textTheme.bodyMedium?.copyWith(color: HyphaColors.primaryBlu),
),
],
),
const SizedBox(height: 24),
BlocBuilder<ReceiveBloc, ReceiveState>(
buildWhen: (c, p) => c.memo != p.memo,
builder: (context, state) {
return MemoField(
onPressed: (value) {
context.read<ReceiveBloc>().add(ReceiveEvent.onMemoEntered(value));
Get.back();
},
memo: state.memo,
);
},
),
const SizedBox(height: 24),
NumberKeyboardGrid(onKeyTapped: (element) {
context.read<ReceiveBloc>().add(ReceiveEvent.onKeypadTapped(element));
}),
],
),
),
),
);
}
}
6 changes: 6 additions & 0 deletions lib/ui/transfer_tokens/receive/interactor/page_command.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
part of 'receive_bloc.dart';

@freezed
class PageCommand with _$PageCommand {
const factory PageCommand.navigateToSendSuccess(String transactionId) = _NavigateToSendSuccess;
}
Loading
Loading