| 1 | import 'package:cake_wallet/generated/i18n.dart'; |
| 2 | import 'package:cake_wallet/view_model/wallet_restore_choose_derivation_view_model.dart'; |
| 3 | import 'package:cw_core/wallet_info.dart'; |
| 4 | import 'package:flutter/material.dart'; |
| 5 | import 'package:flutter_mobx/flutter_mobx.dart'; |
| 6 | import 'package:cake_wallet/src/screens/base_page.dart'; |
| 7 | |
| 8 | class WalletRestoreChooseDerivationPage extends BasePage { |
| 9 | WalletRestoreChooseDerivationPage(this.walletRestoreChooseDerivationViewModel) {} |
| 10 | |
| 11 | @override |
| 12 | Widget middle(BuildContext context) => Text( |
| 13 | S.current.choose_derivation, |
| 14 | style: Theme.of(context) |
| 15 | .textTheme |
| 16 | .titleLarge |
| 17 | ?.copyWith(fontWeight: FontWeight.bold, color: Theme.of(context).colorScheme.primary), |
| 18 | ); |
| 19 | |
| 20 | final WalletRestoreChooseDerivationViewModel walletRestoreChooseDerivationViewModel; |
| 21 | |
| 22 | @override |
| 23 | Widget body(BuildContext context) { |
| 24 | return Observer( |
| 25 | builder: (_) => FutureBuilder<List<DerivationInfo>>( |
| 26 | future: walletRestoreChooseDerivationViewModel.derivations, |
| 27 | builder: (context, snapshot) { |
| 28 | if (snapshot.connectionState == ConnectionState.waiting) { |
| 29 | return Center( |
| 30 | child: CircularProgressIndicator(), |
| 31 | ); |
| 32 | } else if (snapshot.hasError) { |
| 33 | return Center(child: Text('Error: ${snapshot.error}')); |
| 34 | } else if (!snapshot.hasData || snapshot.data!.isEmpty) { |
| 35 | return Center(child: Text('Error! No derivations available!')); |
| 36 | } else { |
| 37 | return ListView.separated( |
| 38 | shrinkWrap: true, |
| 39 | separatorBuilder: (_, __) => SizedBox(), |
| 40 | itemCount: snapshot.data!.length, |
| 41 | itemBuilder: (__, index) { |
| 42 | final derivation = snapshot.data![index]; |
| 43 | return Card( |
| 44 | margin: const EdgeInsets.all(8), |
| 45 | elevation: 3, |
| 46 | shape: RoundedRectangleBorder( |
| 47 | borderRadius: BorderRadius.circular(15), |
| 48 | ), |
| 49 | child: InkWell( |
| 50 | borderRadius: BorderRadius.circular(15), |
| 51 | onTap: () async { |
| 52 | Navigator.pop(context, derivation); |
| 53 | }, |
| 54 | child: ListTile( |
| 55 | contentPadding: EdgeInsets.all(16), |
| 56 | title: Center( |
| 57 | child: Text( |
| 58 | "${derivation.description ?? derivation.derivationType.toString().split('.').last}", |
| 59 | style: Theme.of(context).textTheme.bodyMedium!.copyWith( |
| 60 | fontSize: 18, |
| 61 | fontWeight: FontWeight.w800, |
| 62 | color: Theme.of(context).colorScheme.primary, |
| 63 | ), |
| 64 | ), |
| 65 | ), |
| 66 | subtitle: Column( |
| 67 | crossAxisAlignment: CrossAxisAlignment.start, |
| 68 | children: [ |
| 69 | if (derivation.derivationPath != null) |
| 70 | Text( |
| 71 | derivation.derivationPath!, |
| 72 | style: Theme.of(context).textTheme.bodyMedium!.copyWith( |
| 73 | fontWeight: FontWeight.w500, |
| 74 | color: Theme.of(context).colorScheme.onSurfaceVariant, |
| 75 | ), |
| 76 | ), |
| 77 | Text( |
| 78 | derivation.address, |
| 79 | style: Theme.of(context).textTheme.bodyMedium!.copyWith( |
| 80 | fontSize: 16, |
| 81 | fontWeight: FontWeight.w500, |
| 82 | color: Theme.of(context).colorScheme.onSurfaceVariant, |
| 83 | ), |
| 84 | ), |
| 85 | Text( |
| 86 | "${S.current.confirmed}: ${derivation.balance}", |
| 87 | style: Theme.of(context).textTheme.bodyMedium!.copyWith( |
| 88 | fontSize: 16, |
| 89 | fontWeight: FontWeight.w500, |
| 90 | color: Theme.of(context).colorScheme.onSurfaceVariant, |
| 91 | ), |
| 92 | ), |
| 93 | Text( |
| 94 | "${S.current.transactions}: ${derivation.transactionsCount}", |
| 95 | style: Theme.of(context).textTheme.bodyMedium!.copyWith( |
| 96 | fontSize: 16, |
| 97 | fontWeight: FontWeight.w500, |
| 98 | color: Theme.of(context).colorScheme.onSurfaceVariant, |
| 99 | ), |
| 100 | ), |
| 101 | ], |
| 102 | ), |
| 103 | ), |
| 104 | ), |
| 105 | ); |
| 106 | }, |
| 107 | ); |
| 108 | } |
| 109 | }, |
| 110 | ), |
| 111 | ); |
| 112 | } |
| 113 | } |