From c6d937ca4ea57540067f479815e7aa75719d1287 Mon Sep 17 00:00:00 2001 From: fosse Date: Tue, 15 Aug 2023 15:05:38 -0400 Subject: [PATCH] fixes --- cw_core/lib/hive_type_ids.dart | 27 ++++--- cw_core/lib/nano_account.dart | 3 +- cw_nano/lib/nano_account_list.dart | 7 +- cw_nano/lib/nano_wallet.dart | 5 +- cw_nano/lib/nano_wallet_addresses.dart | 3 +- lib/di.dart | 9 +-- lib/main.dart | 2 +- lib/router.dart | 14 ++-- .../wallet_restore_choose_derivation.dart | 79 ++++++++++--------- ..._restore_choose_derivation_view_model.dart | 9 ++- tool/configure.dart | 1 - 11 files changed, 82 insertions(+), 77 deletions(-) diff --git a/cw_core/lib/hive_type_ids.dart b/cw_core/lib/hive_type_ids.dart index f6c70f042..d5494d342 100644 --- a/cw_core/lib/hive_type_ids.dart +++ b/cw_core/lib/hive_type_ids.dart @@ -1,14 +1,15 @@ -const CONTACT_TYPE_ID = 0; -const NODE_TYPE_ID = 1; -const TRANSACTION_TYPE_ID = 2; -const TRADE_TYPE_ID = 3; -const WALLET_INFO_TYPE_ID = 4; -const WALLET_TYPE_TYPE_ID = 5; -const TEMPLATE_TYPE_ID = 6; -const EXCHANGE_TEMPLATE_TYPE_ID = 7; -const ORDER_TYPE_ID = 8; -const UNSPENT_COINS_INFO_TYPE_ID = 9; -const ANONPAY_INVOICE_INFO_TYPE_ID = 10; -const DERIVATION_TYPE_TYPE_ID = 15; +const CONTACT_TYPE_ID = 0; +const NODE_TYPE_ID = 1; +const TRANSACTION_TYPE_ID = 2; +const TRADE_TYPE_ID = 3; +const WALLET_INFO_TYPE_ID = 4; +const WALLET_TYPE_TYPE_ID = 5; +const TEMPLATE_TYPE_ID = 6; +const EXCHANGE_TEMPLATE_TYPE_ID = 7; +const ORDER_TYPE_ID = 8; +const UNSPENT_COINS_INFO_TYPE_ID = 9; +const ANONPAY_INVOICE_INFO_TYPE_ID = 10; +const DERIVATION_TYPE_TYPE_ID = 15; -const ERC20_TOKEN_TYPE_ID = 12; +const ERC20_TOKEN_TYPE_ID = 12; +const NANO_ACCOUNT_TYPE_ID = 13; diff --git a/cw_core/lib/nano_account.dart b/cw_core/lib/nano_account.dart index 7f7c5f823..91df62e75 100644 --- a/cw_core/lib/nano_account.dart +++ b/cw_core/lib/nano_account.dart @@ -1,3 +1,4 @@ +import 'package:cw_core/hive_type_ids.dart'; import 'package:hive/hive.dart'; part 'nano_account.g.dart'; @@ -6,7 +7,7 @@ part 'nano_account.g.dart'; class NanoAccount extends HiveObject { NanoAccount({required this.label, required this.id, this.balance, this.isSelected = false}); - static const typeId = 13; + static const typeId = NANO_ACCOUNT_TYPE_ID; @HiveField(0) String label; diff --git a/cw_nano/lib/nano_account_list.dart b/cw_nano/lib/nano_account_list.dart index 947c2af84..7207eafe1 100644 --- a/cw_nano/lib/nano_account_list.dart +++ b/cw_nano/lib/nano_account_list.dart @@ -1,3 +1,4 @@ +import 'package:cw_core/cake_hive.dart'; import 'package:cw_core/nano_account.dart'; import 'package:mobx/mobx.dart'; import 'package:hive/hive.dart'; @@ -44,21 +45,21 @@ abstract class NanoAccountListBase with Store { } Future> getAll({String? address}) async { - final box = await Hive.openBox(address ?? this.address); + final box = await CakeHive.openBox(address ?? this.address); // get all accounts in box: return box.values.toList(); } Future addAccount({required String label}) async { - final box = await Hive.openBox(address); + final box = await CakeHive.openBox(address); final account = NanoAccount(id: box.length, label: label, balance: "0.00", isSelected: false); await box.add(account); await account.save(); } Future setLabelAccount({required int accountIndex, required String label}) async { - final box = await Hive.openBox(address); + final box = await CakeHive.openBox(address); final account = box.getAt(accountIndex); account!.label = label; await account.save(); diff --git a/cw_nano/lib/nano_wallet.dart b/cw_nano/lib/nano_wallet.dart index 6df5e4f9f..cd13680ce 100644 --- a/cw_nano/lib/nano_wallet.dart +++ b/cw_nano/lib/nano_wallet.dart @@ -1,6 +1,7 @@ import 'dart:convert'; import 'dart:io'; +import 'package:cw_core/cake_hive.dart'; import 'package:cw_core/crypto_currency.dart'; import 'package:cw_core/node.dart'; import 'package:cw_core/pathForWallet.dart'; @@ -54,8 +55,8 @@ abstract class NanoWalletBase super(walletInfo) { this.walletInfo = walletInfo; transactionHistory = NanoTransactionHistory(walletInfo: walletInfo, password: password); - if (!Hive.isAdapterRegistered(NanoAccount.typeId)) { - Hive.registerAdapter(NanoAccountAdapter()); + if (!CakeHive.isAdapterRegistered(NanoAccount.typeId)) { + CakeHive.registerAdapter(NanoAccountAdapter()); } } diff --git a/cw_nano/lib/nano_wallet_addresses.dart b/cw_nano/lib/nano_wallet_addresses.dart index f1b9c5905..d67e28055 100644 --- a/cw_nano/lib/nano_wallet_addresses.dart +++ b/cw_nano/lib/nano_wallet_addresses.dart @@ -1,3 +1,4 @@ +import 'package:cw_core/cake_hive.dart'; import 'package:cw_core/wallet_addresses.dart'; import 'package:cw_core/wallet_info.dart'; import 'package:cw_core/nano_account.dart'; @@ -27,7 +28,7 @@ abstract class NanoWalletAddressesBase extends WalletAddresses with Store { @override Future init() async { - var box = await Hive.openBox(walletInfo.address); + var box = await CakeHive.openBox(walletInfo.address); try { box.getAt(0); } catch (e) { diff --git a/lib/di.dart b/lib/di.dart index a6464d15f..eb19205ca 100644 --- a/lib/di.dart +++ b/lib/di.dart @@ -851,14 +851,13 @@ Future setup({ (type, _) => WalletRestorePage(getIt.get(param1: type))); getIt.registerFactoryParam( - (type, credentials) => - WalletRestoreChooseDerivationViewModel(type: type, credentials: credentials)); + (credentials, _) => + WalletRestoreChooseDerivationViewModel(credentials: credentials)); getIt.registerFactoryParam( - (type, credentials) => + (credentials, _) => WalletRestoreChooseDerivationPage(getIt.get( - param1: type, - param2: credentials, + param1: credentials, ))); getIt.registerFactoryParam( diff --git a/lib/main.dart b/lib/main.dart index 8040d3f48..cf28e2ba7 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -94,7 +94,7 @@ Future initializeAppConfigs() async { } if (!Hive.isAdapterRegistered(DERIVATION_TYPE_TYPE_ID)) { - Hive.registerAdapter(DerivationTypeAdapter()); + CakeHive.registerAdapter(DerivationTypeAdapter()); } if (!CakeHive.isAdapterRegistered(WALLET_TYPE_TYPE_ID)) { diff --git a/lib/router.dart b/lib/router.dart index 0dd84d4f6..33aa49c66 100644 --- a/lib/router.dart +++ b/lib/router.dart @@ -201,9 +201,8 @@ Route createRoute(RouteSettings settings) { case Routes.restoreWalletChooseDerivation: return MaterialPageRoute( - builder: (_) => getIt.get( - param1: (settings.arguments as dynamic)!["walletType"] as WalletType, - param2: (settings.arguments as dynamic)!["credentials"])); + builder: (_) => + getIt.get(param1: settings.arguments as dynamic)); case Routes.sweepingWalletPage: return CupertinoPageRoute(builder: (_) => getIt.get()); @@ -420,17 +419,14 @@ Route createRoute(RouteSettings settings) { fullscreenDialog: true, builder: (_) => getIt.get()); case Routes.support: - return CupertinoPageRoute( - builder: (_) => getIt.get()); + return CupertinoPageRoute(builder: (_) => getIt.get()); case Routes.supportLiveChat: - return CupertinoPageRoute( - builder: (_) => getIt.get()); + return CupertinoPageRoute(builder: (_) => getIt.get()); case Routes.supportOtherLinks: return CupertinoPageRoute( - fullscreenDialog: true, - builder: (_) => getIt.get()); + fullscreenDialog: true, builder: (_) => getIt.get()); case Routes.unspentCoinsList: return MaterialPageRoute(builder: (_) => getIt.get()); diff --git a/lib/src/screens/restore/wallet_restore_choose_derivation.dart b/lib/src/screens/restore/wallet_restore_choose_derivation.dart index 1378df250..bfc496866 100644 --- a/lib/src/screens/restore/wallet_restore_choose_derivation.dart +++ b/lib/src/screens/restore/wallet_restore_choose_derivation.dart @@ -45,46 +45,51 @@ class WalletRestoreChooseDerivationPage extends BasePage { itemCount: snapshot.data!.length, itemBuilder: (__, index) { final derivation = snapshot.data![index]; - return Container( - margin: const EdgeInsets.only(left: 16, right: 16), - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(30.0), - border: Border.all( - color: getIt.get().currentTheme.type == ThemeType.bright - ? Color.fromRGBO(255, 255, 255, 0.2) - : Colors.transparent, - width: 1, - ), - color: Theme.of(context).textTheme.titleLarge!.backgroundColor!, - ), + return InkWell( + onTap: () async { + Navigator.pop(context, derivation.derivationType); + }, child: Container( - margin: const EdgeInsets.only(top: 16, left: 24, right: 24, bottom: 24), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - derivation.address, - style: TextStyle( - fontSize: 16, - fontFamily: 'Lato', - fontWeight: FontWeight.w400, - color: - Theme.of(context).accentTextTheme.displayMedium!.backgroundColor!, - height: 1, + margin: const EdgeInsets.only(left: 16, right: 16), + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(30.0), + border: Border.all( + color: getIt.get().currentTheme.type == ThemeType.bright + ? Color.fromRGBO(255, 255, 255, 0.2) + : Colors.transparent, + width: 1, + ), + color: Theme.of(context).textTheme.titleLarge!.backgroundColor!, + ), + child: Container( + margin: const EdgeInsets.only(top: 16, left: 24, right: 24, bottom: 24), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + derivation.address, + style: TextStyle( + fontSize: 16, + fontFamily: 'Lato', + fontWeight: FontWeight.w400, + color: + Theme.of(context).accentTextTheme.displayMedium!.backgroundColor!, + height: 1, + ), ), - ), - Text( - "${S.current.confirmed}: ${derivation.balance}", - style: TextStyle( - fontSize: 18, - fontFamily: 'Lato', - fontWeight: FontWeight.w400, - color: - Theme.of(context).accentTextTheme.displayMedium!.backgroundColor!, - height: 2, + Text( + "${S.current.confirmed}: ${derivation.balance}", + style: TextStyle( + fontSize: 18, + fontFamily: 'Lato', + fontWeight: FontWeight.w400, + color: + Theme.of(context).accentTextTheme.displayMedium!.backgroundColor!, + height: 2, + ), ), - ), - ], + ], + ), ), ), ); diff --git a/lib/view_model/wallet_restore_choose_derivation_view_model.dart b/lib/view_model/wallet_restore_choose_derivation_view_model.dart index 9b55cd65a..141497f72 100644 --- a/lib/view_model/wallet_restore_choose_derivation_view_model.dart +++ b/lib/view_model/wallet_restore_choose_derivation_view_model.dart @@ -1,3 +1,5 @@ +import 'package:cake_wallet/di.dart'; +import 'package:cake_wallet/store/app_store.dart'; import 'package:cw_core/wallet_info.dart'; import 'package:cw_nano/nano_balance.dart'; import 'package:cw_nano/nano_util.dart'; @@ -21,20 +23,19 @@ class Derivation { } abstract class WalletRestoreChooseDerivationViewModelBase with Store { - WalletRestoreChooseDerivationViewModelBase({required this.credentials, required this.type}) + WalletRestoreChooseDerivationViewModelBase({required this.credentials}) : mode = WalletRestoreMode.seed {} - WalletType type; + dynamic credentials; @observable WalletRestoreMode mode; - @observable Future> get derivations async { var list = []; - switch (type) { + switch (getIt.get().wallet!.type) { case WalletType.nano: var seed = credentials['seed'] as String; var bip39Info = diff --git a/tool/configure.dart b/tool/configure.dart index 8705e5e4a..19f75e45e 100644 --- a/tool/configure.dart +++ b/tool/configure.dart @@ -587,7 +587,6 @@ import 'package:cake_wallet/view_model/send/output.dart'; import 'package:cw_core/account.dart'; import 'package:mobx/mobx.dart'; import 'package:cw_core/wallet_credentials.dart'; -import 'package:cw_nano/nano_wallet_info.dart'; import 'package:cw_core/wallet_info.dart'; import 'package:cw_core/transaction_history.dart'; import 'package:cw_core/wallet_service.dart';