Skip to content
Open
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
11 changes: 9 additions & 2 deletions app/lib/screens/wallets/wallet_details.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,23 @@ import 'package:threebotlogin/screens/wallets/wallet_assets.dart';
import 'package:threebotlogin/screens/wallets/wallet_info.dart';

class WalletDetailsScreen extends ConsumerStatefulWidget {
const WalletDetailsScreen({super.key, required this.wallet});
const WalletDetailsScreen({super.key, required this.wallet, this.initialTabIndex = 0});
final Wallet wallet;
final int initialTabIndex;

@override
ConsumerState<WalletDetailsScreen> createState() =>
_WalletDetailsScreenState();
}

class _WalletDetailsScreenState extends ConsumerState<WalletDetailsScreen> {
int currentScreenIndex = 0;
late int currentScreenIndex;

@override
void initState() {
super.initState();
currentScreenIndex = widget.initialTabIndex;
}

void _selectScreen(int index) {
setState(() {
Expand Down
1 change: 1 addition & 0 deletions app/lib/screens/wallets/wallet_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class _WalletScreenState extends ConsumerState<WalletScreen> {
itemBuilder: (context, i) {
final wallet = wallets[i];
return WalletCardWidget(
key: ValueKey(wallet.name),
wallet: wallet,
);
}));
Expand Down
102 changes: 98 additions & 4 deletions app/lib/widgets/wallets/wallet_card.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_slidable/flutter_slidable.dart';
import 'package:threebotlogin/helpers/globals.dart';
import 'package:threebotlogin/helpers/kyc_helpers.dart';
import 'package:threebotlogin/helpers/logger.dart';
Expand All @@ -11,6 +12,7 @@ import 'package:threebotlogin/screens/wallets/wallet_details.dart';
import 'package:threebotlogin/services/stellar_service.dart' as StellarService;
import 'package:threebotlogin/services/tfchain_service.dart' as TFChainService;
import 'package:threebotlogin/services/wallet_service.dart';
import 'package:threebotlogin/widgets/wallets/warning_dialog.dart';

class WalletCardWidget extends ConsumerStatefulWidget {
const WalletCardWidget({super.key, required this.wallet});
Expand Down Expand Up @@ -164,7 +166,8 @@ class _WalletCardWidgetState extends ConsumerState<WalletCardWidget> {
)
];
}
return Card(

final card = Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(5),
side: BorderSide(color: Theme.of(context).colorScheme.primary)),
Expand Down Expand Up @@ -201,16 +204,16 @@ class _WalletCardWidgetState extends ConsumerState<WalletCardWidget> {
const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
decoration: BoxDecoration(
border: Border.all(
color: wallet!.verificationStatus ==
color: (wallet?.verificationStatus ?? widget.wallet.verificationStatus) ==
VerificationState.VERIFIED
? Theme.of(context).colorScheme.primary
: Theme.of(context).colorScheme.error,
),
borderRadius: BorderRadius.circular(20),
),
child: Text(capitalize(wallet.verificationStatus.name),
child: Text(capitalize((wallet?.verificationStatus ?? widget.wallet.verificationStatus).name),
style: Theme.of(context).textTheme.bodySmall!.copyWith(
color: wallet.verificationStatus ==
color: (wallet?.verificationStatus ?? widget.wallet.verificationStatus) ==
VerificationState.VERIFIED
? Theme.of(context).colorScheme.primary
: Theme.of(context).colorScheme.error,
Expand All @@ -225,5 +228,96 @@ class _WalletCardWidgetState extends ConsumerState<WalletCardWidget> {
),
),
);

final canDelete = widget.wallet.type == WalletType.IMPORTED;
final actions = <Widget>[];

if (canDelete) {
actions.add(
SlidableAction(
onPressed: (_) => _showDeleteConfirmationDialog(),
backgroundColor: Theme.of(context).colorScheme.error,
foregroundColor: Theme.of(context).colorScheme.onError,
icon: Icons.delete,
label: 'Delete',
),
);
}

actions.add(
SlidableAction(
onPressed: (_) => _editWallet(),
backgroundColor: Theme.of(context).colorScheme.primaryContainer,
foregroundColor: Theme.of(context).colorScheme.onPrimaryContainer,
icon: Icons.edit,
label: 'Edit',
),
);

return Slidable(
key: ValueKey(widget.wallet.name),
endActionPane: ActionPane(
motion: const DrawerMotion(),
extentRatio: canDelete ? 0.3 : 0.2,
children: actions,
),
child: card,
);
}

void _showDeleteConfirmationDialog() {
showDialog(
context: context,
builder: (BuildContext context) => WarningDialogWidget(
title: 'Are you sure?',
description: 'If you confirm, your wallet will be removed from this device.',
onAgree: _deleteWallet,
),
);
}

Future<bool> _deleteWallet() async {
if (context.mounted) {
Navigator.of(context).pop();
}

try {
await deleteWallet(widget.wallet.name);
await ref.read(walletsNotifier.notifier).removeWallet(widget.wallet.name);
if (mounted && context.mounted) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: const Text('Wallet deleted'),
duration: const Duration(seconds: 2),
),
);
}
return true;
} catch (e) {
logger.e('Failed to delete wallet due to $e');
if (mounted && context.mounted) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(
'Failed to delete',
style: Theme.of(context).textTheme.bodyMedium!.copyWith(
color: Theme.of(context).colorScheme.errorContainer,
),
),
duration: const Duration(seconds: 3),
),
);
}
return false;
}
}

void _editWallet() {
Navigator.of(context).push(MaterialPageRoute(
builder: (context) => WalletDetailsScreen(
wallet: widget.wallet,
initialTabIndex: 2, // Navigate to Info tab
),
));
}
}
8 changes: 8 additions & 0 deletions app/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.6.1"
flutter_slidable:
dependency: "direct main"
description:
name: flutter_slidable
sha256: a857de7ea701f276fd6a6c4c67ae885b60729a3449e42766bb0e655171042801
url: "https://pub.dev"
source: hosted
version: "3.1.2"
flutter_staggered_grid_view:
dependency: transitive
description:
Expand Down
1 change: 1 addition & 0 deletions app/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ dependencies:
background_fetch: ^1.3.8
connectivity_plus: ^6.1.4
awesome_notifications: ^0.10.1
flutter_slidable: ^3.1.1
dev_dependencies:
flutter_test:
sdk: flutter
Expand Down