Skip to content

Commit

Permalink
feat: home & payment improved buttons (#1468)
Browse files Browse the repository at this point in the history
Co-authored-by: Kirill Bubochkin <ookami.kb@gmail.com>
  • Loading branch information
Jaxiii and ookami-kb authored Jun 3, 2024
1 parent 7bd20c4 commit 606a84f
Show file tree
Hide file tree
Showing 16 changed files with 162 additions and 124 deletions.
4 changes: 4 additions & 0 deletions packages/espressocash_app/assets/icons/add_alternative.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions packages/espressocash_app/assets/icons/dolar.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions packages/espressocash_app/assets/icons/withdrawn.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import '../../../gen/assets.gen.dart';
import '../../../ui/loader.dart';
import '../../../ui/navigation_bar/navigation_bar.dart';
import '../../../ui/navigation_bar/navigation_button.dart';
import '../../../utils/routing.dart';
import '../../activities/screens/activities_screen.dart';
import '../../dynamic_links/services/dynamic_links_notifier.dart';
import '../../incoming_link_payments/widgets/pending_ilp_listener.dart';
Expand All @@ -21,17 +20,25 @@ class HomeScreen extends StatefulWidget {
const HomeScreen({super.key});

static void openWalletTab(BuildContext context) {
context.openFirstScreen();
context.read<TabNotifier>().value = 1;
final _HomeScreenState? state =
context.findAncestorStateOfType<_HomeScreenState>();
if (state != null) {
state._pageController.jumpToPage(1);
state._tabNotifier.value = 1;
}
}

static void openActivitiesTab(
BuildContext context, {
// ignore: avoid-unused-parameters, fix later
ActivitiesTab tab = ActivitiesTab.pending,
}) {
context.openFirstScreen();
context.read<TabNotifier>().value = 2;
final _HomeScreenState? state =
context.findAncestorStateOfType<_HomeScreenState>();
if (state != null) {
state._pageController.jumpToPage(2);
state._tabNotifier.value = 2;
}
}

@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class _HomeCarouselWidgetState extends State<HomeCarouselWidget> {
controller: _controller,
count: items.length,
effect: const ExpandingDotsEffect(
activeDotColor: CpColors.primaryColor,
activeDotColor: CpColors.carouselDotColor,
dotColor: Colors.white,
dotHeight: 7,
dotWidth: 25,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,12 @@ class _Buttons extends StatelessWidget {
create: () =>
sl<WatchUserCashBalance>().call().map((it) => it.isZero),
builder: (context, isZeroAmount) => Padding(
padding:
const EdgeInsets.only(left: 18, top: 20, right: 18, bottom: 8),
padding: const EdgeInsets.only(
left: 18,
top: 20,
right: 18,
bottom: 8,
),
child: Column(
mainAxisSize: MainAxisSize.max,
crossAxisAlignment: CrossAxisAlignment.center,
Expand All @@ -93,24 +97,21 @@ class _Buttons extends StatelessWidget {
),
const SizedBox(height: 8),
Row(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
if (!isZeroAmount) ...[
Flexible(
child: CpButton(
minWidth: 250,
size: CpButtonSize.wide,
text: context.l10n.sendMoney,
onPressed: onSendMoneyPressed,
if (!isZeroAmount)
Expanded(
child: PayOrRequestButton(
voidCallback: onSendMoneyPressed,
),
),
const SizedBox(width: 8),
],
const AddCashButton(size: CpButtonSize.wide),
if (!isZeroAmount) ...[
const SizedBox(width: 8),
const CashOutButton(size: CpButtonSize.wide),
],
const Expanded(
child: AddCashButton(size: CpButtonSize.wide),
),
if (!isZeroAmount)
const Expanded(
child: CashOutButton(size: CpButtonSize.wide),
),
],
),
],
Expand Down
112 changes: 82 additions & 30 deletions packages/espressocash_app/lib/features/ramp/widgets/ramp_buttons.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import 'package:flutter/material.dart';

import '../../../../../l10n/l10n.dart';
import '../../../di.dart';
import '../../../gen/assets.gen.dart';
import '../../../ui/button.dart';
import '../../../ui/icon_button.dart';
import '../../accounts/models/account.dart';
import '../../country_picker/models/country.dart';
import '../../profile/data/profile_repository.dart';
Expand All @@ -22,6 +24,36 @@ import '../screens/ramp_onboarding_screen.dart';
import '../screens/ramp_partner_select_screen.dart';
import 'off_ramp_bottom_sheet.dart';

class PayOrRequestButton extends StatelessWidget {
const PayOrRequestButton({
super.key,
required this.voidCallback,
this.size = CpButtonSize.normal,
});

final CpButtonSize size;
final VoidCallback voidCallback;
@override
Widget build(BuildContext context) => Column(
children: [
CpIconButton(
icon: Assets.icons.dolar.svg(color: Colors.black),
variant: CpIconButtonVariant.dark,
size: CpIconButtonSize.large,
onPressed: voidCallback,
),
const SizedBox(height: 8),
Text(
context.l10n.requestOrSendPayment,
style: Theme.of(context)
.textTheme
.bodyLarge
?.copyWith(fontWeight: FontWeight.w500),
),
],
);
}

class AddCashButton extends StatelessWidget {
const AddCashButton({
super.key,
Expand All @@ -31,21 +63,31 @@ class AddCashButton extends StatelessWidget {
final CpButtonSize size;

@override
Widget build(BuildContext context) => Flexible(
child: CpButton(
size: size,
minWidth: 250,
text: context.l10n.ramp_btnAddCash,
onPressed: () async {
final data = await context.ensureProfileData(RampType.onRamp);
if (context.mounted && data != null) {
context.launchOnRampFlow(
profile: data,
address: sl<MyAccount>().wallet.publicKey.toBase58(),
);
}
},
),
Widget build(BuildContext context) => Column(
children: [
CpIconButton(
icon: Assets.icons.addAlternative.svg(color: Colors.black),
variant: CpIconButtonVariant.dark,
size: CpIconButtonSize.large,
onPressed: () async {
final data = await context.ensureProfileData(RampType.onRamp);
if (context.mounted && data != null) {
context.launchOnRampFlow(
profile: data,
address: sl<MyAccount>().wallet.publicKey.toBase58(),
);
}
},
),
const SizedBox(height: 8),
Text(
context.l10n.ramp_btnAddCash,
style: Theme.of(context)
.textTheme
.bodyLarge
?.copyWith(fontWeight: FontWeight.w500),
),
],
);
}

Expand All @@ -58,21 +100,31 @@ class CashOutButton extends StatelessWidget {
final CpButtonSize size;

@override
Widget build(BuildContext context) => Flexible(
child: CpButton(
size: size,
minWidth: 250,
text: context.l10n.ramp_btnCashOut,
onPressed: () async {
final data = await context.ensureProfileData(RampType.offRamp);
if (context.mounted && data != null) {
context.launchOffRampFlow(
profile: data,
address: sl<MyAccount>().wallet.publicKey.toBase58(),
);
}
},
),
Widget build(BuildContext context) => Column(
children: [
CpIconButton(
icon: Assets.icons.withdrawn.svg(color: Colors.black),
variant: CpIconButtonVariant.dark,
size: CpIconButtonSize.large,
onPressed: () async {
final data = await context.ensureProfileData(RampType.offRamp);
if (context.mounted && data != null) {
context.launchOffRampFlow(
profile: data,
address: sl<MyAccount>().wallet.publicKey.toBase58(),
);
}
},
),
const SizedBox(height: 8),
Text(
context.l10n.ramp_btnCashOut,
style: Theme.of(context)
.textTheme
.bodyLarge
?.copyWith(fontWeight: FontWeight.w500),
),
],
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import '../../../ui/app_bar.dart';
import '../../../ui/button.dart';
import '../../../ui/icon_button.dart';
import '../../../ui/number_formatter.dart';
import '../../../ui/size.dart';
import '../../../ui/tab_bar.dart';
import '../../../ui/theme.dart';
import '../../conversion_rates/widgets/amount_with_equivalent.dart';
import '../../currency/models/amount.dart';
Expand Down Expand Up @@ -44,9 +42,6 @@ class WalletMainScreen extends StatefulWidget {

class _ScreenState extends State<WalletMainScreen> {
late final TextEditingController _amountController;
TabController? _tabController;

WalletOperation _action = WalletOperation.pay;

@override
void initState() {
Expand All @@ -60,7 +55,6 @@ class _ScreenState extends State<WalletMainScreen> {
_amountController
..removeListener(_updateValue)
..dispose();
_tabController?.removeListener(_handleTabUpdate);
super.dispose();
}

Expand All @@ -76,29 +70,12 @@ class _ScreenState extends State<WalletMainScreen> {
}
}

@override
void didChangeDependencies() {
super.didChangeDependencies();
_tabController?.removeListener(_handleTabUpdate);
_tabController = DefaultTabController.of(context)
..addListener(_handleTabUpdate);
_updateAction();
}

void _updateValue() {
final locale = DeviceLocale.localeOf(context);
final amount = _amountController.text.toDecimalOrZero(locale);
widget.onAmountChanged(amount);
}

void _handleTabUpdate() => setState(_updateAction);

void _updateAction() {
final tab = _tabController?.index ?? 0;

_action = WalletOperation.values[tab];
}

@override
Widget build(BuildContext context) {
final width = MediaQuery.sizeOf(context).width;
Expand All @@ -109,7 +86,6 @@ class _ScreenState extends State<WalletMainScreen> {
body: SafeArea(
child: Column(
children: [
SizedBox(height: context.isSmall ? 24 : 32),
AmountWithEquivalent(
inputController: _amountController,
token: widget.token,
Expand All @@ -126,20 +102,27 @@ class _ScreenState extends State<WalletMainScreen> {
),
const SizedBox(height: 8),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 32),
child: CpButton(
text: _action.buttonLabel(context),
minWidth: width,
onPressed: () {
switch (_action) {
case WalletOperation.pay:
widget.onPay();
case WalletOperation.request:
widget.onRequest();
}
},
size:
context.isSmall ? CpButtonSize.normal : CpButtonSize.big,
padding: const EdgeInsets.all(16.0),
child: Row(
children: [
Expanded(
child: CpButton(
text: context.l10n.receive,
minWidth: width,
onPressed: widget.onRequest,
size: CpButtonSize.big,
),
),
const SizedBox(width: 27.0),
Expanded(
child: CpButton(
text: context.l10n.pay,
minWidth: width,
onPressed: widget.onPay,
size: CpButtonSize.big,
),
),
],
),
),
const SizedBox(height: 24),
Expand Down Expand Up @@ -170,32 +153,8 @@ class _AppBar extends StatelessWidget implements PreferredSizeWidget {
variant: CpIconButtonVariant.black,
),
),
title: Padding(
padding: const EdgeInsets.only(top: 12),
child: SizedBox(
width: 220,
child: CpTabBar(
tabs: [
Tab(text: context.l10n.pay),
Tab(text: context.l10n.receive),
],
variant: CpTabBarVariant.black,
),
),
),
),
);
}

extension on WalletOperation {
String buttonLabel(BuildContext context) {
switch (this) {
case WalletOperation.pay:
return context.l10n.pay;
case WalletOperation.request:
return context.l10n.receive;
}
}
}

enum WalletOperation { pay, request }
Loading

0 comments on commit 606a84f

Please sign in to comment.