From c4c26c3a48c1ab58a72276f5f0ef8d4ebfb94543 Mon Sep 17 00:00:00 2001 From: fosse Date: Mon, 20 Nov 2023 11:50:54 -0500 Subject: [PATCH] fixes post merge --- lib/di.dart | 2 +- lib/nano/nano.dart | 78 ++++++++++++++++--- lib/src/screens/dashboard/dashboard_page.dart | 5 +- .../screens/restore/wallet_restore_page.dart | 2 + .../transaction_details_view_model.dart | 14 ---- lib/view_model/wallet_restore_view_model.dart | 6 +- 6 files changed, 76 insertions(+), 31 deletions(-) diff --git a/lib/di.dart b/lib/di.dart index cd9315636..fb07a7378 100644 --- a/lib/di.dart +++ b/lib/di.dart @@ -38,7 +38,6 @@ import 'package:cake_wallet/src/screens/restore/wallet_restore_choose_derivation import 'package:cake_wallet/src/screens/settings/display_settings_page.dart'; import 'package:cake_wallet/src/screens/settings/domain_lookups_page.dart'; import 'package:cake_wallet/src/screens/settings/manage_nodes_page.dart'; -import 'package:cake_wallet/src/screens/settings/manage_pow_nodes_page.dart'; import 'package:cake_wallet/src/screens/settings/other_settings_page.dart'; import 'package:cake_wallet/src/screens/settings/privacy_page.dart'; import 'package:cake_wallet/src/screens/settings/security_backup_page.dart'; @@ -87,6 +86,7 @@ import 'package:cake_wallet/view_model/ionia/ionia_gift_cards_list_view_model.da import 'package:cake_wallet/view_model/ionia/ionia_purchase_merch_view_model.dart'; import 'package:cake_wallet/view_model/nano_account_list/nano_account_edit_or_create_view_model.dart'; import 'package:cake_wallet/view_model/nano_account_list/nano_account_list_view_model.dart'; +import 'package:cake_wallet/view_model/node_list/pow_node_create_or_edit_view_model.dart'; import 'package:cake_wallet/view_model/node_list/pow_node_list_view_model.dart'; import 'package:cake_wallet/view_model/set_up_2fa_viewmodel.dart'; import 'package:cake_wallet/view_model/restore/restore_from_qr_vm.dart'; diff --git a/lib/nano/nano.dart b/lib/nano/nano.dart index e8b9977ac..bf21abbd0 100644 --- a/lib/nano/nano.dart +++ b/lib/nano/nano.dart @@ -1,23 +1,38 @@ - +import 'package:cw_core/cake_hive.dart'; import 'package:cw_core/nano_account.dart'; -import 'package:cw_nano/nano_mnemonic.dart'; -import 'package:cw_nano/nano_wallet.dart'; -import 'package:cw_nano/nano_wallet_service.dart'; -import 'package:cake_wallet/view_model/send/output.dart'; import 'package:cw_core/account.dart'; -import 'package:mobx/mobx.dart'; +import 'package:cw_core/node.dart'; import 'package:cw_core/wallet_credentials.dart'; import 'package:cw_core/wallet_info.dart'; +import 'package:cw_core/transaction_info.dart'; import 'package:cw_core/transaction_history.dart'; import 'package:cw_core/wallet_service.dart'; import 'package:cw_core/output_info.dart'; +import 'package:cw_core/nano_account_info_response.dart'; +import 'package:mobx/mobx.dart'; import 'package:hive/hive.dart'; +import 'package:cake_wallet/view_model/send/output.dart'; + +import 'package:cw_nano/nano_client.dart'; +import 'package:cw_nano/nano_mnemonic.dart'; +import 'package:cw_nano/nano_wallet.dart'; +import 'package:cw_nano/nano_wallet_service.dart'; +import 'package:cw_nano/nano_transaction_info.dart'; import 'package:cw_nano/nano_transaction_credentials.dart'; import 'package:cw_nano/nano_wallet_creation_credentials.dart'; +// needed for nano_util: +import 'dart:convert'; +import 'dart:typed_data'; +import 'package:convert/convert.dart'; +import "package:ed25519_hd_key/ed25519_hd_key.dart"; +import 'package:libcrypto/libcrypto.dart'; +import 'package:nanodart/nanodart.dart' as ND; +import 'package:decimal/decimal.dart'; part 'cw_nano.dart'; Nano? nano = CWNano(); +NanoUtil? nanoUtil = CWNanoUtil(); abstract class Nano { NanoAccountList getAccountList(Object wallet); @@ -28,8 +43,6 @@ abstract class Nano { WalletService createNanoWalletService(Box walletInfoSource); - TransactionHistoryBase getTransactionHistory(Object wallet); - WalletCredentials createNanoNewWalletCredentials({ required String name, String password, @@ -49,13 +62,13 @@ abstract class Nano { DerivationType? derivationType, }); - String getTransactionAddress(Object wallet, int accountIndex, int addressIndex); - - void onStartup(); - List getNanoWordList(String language); Map getKeys(Object wallet); Object createNanoTransactionCredentials(List outputs); + Future changeRep(Object wallet, String address); + Future updateTransactions(Object wallet); + BigInt getTransactionAmountRaw(TransactionInfo transactionInfo); + String getRepresentative(Object wallet); } abstract class NanoAccountList { @@ -66,4 +79,45 @@ abstract class NanoAccountList { Future addAccount(Object wallet, {required String label}); Future setLabelAccount(Object wallet, {required int accountIndex, required String label}); } + +abstract class NanoUtil { + String seedToPrivate(String seed, int index); + String seedToAddress(String seed, int index); + String seedToMnemonic(String seed); + Future mnemonicToSeed(String mnemonic); + String privateKeyToPublic(String privateKey); + String addressToPublicKey(String publicAddress); + String privateKeyToAddress(String privateKey); + String publicKeyToAddress(String publicKey); + bool isValidSeed(String seed); + Future hdMnemonicListToSeed(List words); + Future hdSeedToPrivate(String seed, int index); + Future hdSeedToAddress(String seed, int index); + Future uniSeedToAddress(String seed, int index, String type); + Future uniSeedToPrivate(String seed, int index, String type); + bool isValidBip39Seed(String seed); + static const int maxDecimalDigits = 6; // Max digits after decimal + BigInt rawPerNano = BigInt.parse("1000000000000000000000000000000"); + BigInt rawPerNyano = BigInt.parse("1000000000000000000000000"); + BigInt rawPerBanano = BigInt.parse("100000000000000000000000000000"); + BigInt rawPerXMR = BigInt.parse("1000000000000"); + BigInt convertXMRtoNano = BigInt.parse("1000000000000000000"); + String getRawAsDecimalString(String? raw, BigInt? rawPerCur); + String getRawAsUsableString(String? raw, BigInt rawPerCur); + String getRawAccuracy(String? raw, BigInt rawPerCur); + String getAmountAsRaw(String amount, BigInt rawPerCur); + + // derivationInfo: + Future getInfoFromSeedOrMnemonic( + DerivationType derivationType, { + String? seedKey, + String? mnemonic, + required Node node, + }); + Future> compareDerivationMethods({ + String? mnemonic, + String? privateKey, + required Node node, + }); +} \ No newline at end of file diff --git a/lib/src/screens/dashboard/dashboard_page.dart b/lib/src/screens/dashboard/dashboard_page.dart index d4662c625..e880d41dc 100644 --- a/lib/src/screens/dashboard/dashboard_page.dart +++ b/lib/src/screens/dashboard/dashboard_page.dart @@ -193,7 +193,10 @@ class _DashboardPageView extends BasePage { radius: 6.0, dotWidth: 6.0, dotHeight: 6.0, - dotColor: Theme.of(context).indicatorColor, + dotColor: Theme.of(context) + .extension()! + .indicatorDotTheme + .indicatorColor, activeDotColor: Theme.of(context) .extension()! .indicatorDotTheme diff --git a/lib/src/screens/restore/wallet_restore_page.dart b/lib/src/screens/restore/wallet_restore_page.dart index 744dccd2d..481176707 100644 --- a/lib/src/screens/restore/wallet_restore_page.dart +++ b/lib/src/screens/restore/wallet_restore_page.dart @@ -1,9 +1,11 @@ import 'package:cake_wallet/di.dart'; +import 'package:cake_wallet/nano/nano.dart'; import 'package:cake_wallet/routes.dart'; import 'package:cake_wallet/store/app_store.dart'; import 'package:cake_wallet/themes/extensions/keyboard_theme.dart'; import 'package:cake_wallet/src/widgets/keyboard_done_button.dart'; import 'package:cake_wallet/utils/responsive_layout_util.dart'; +import 'package:cw_core/nano_account_info_response.dart'; import 'package:cw_core/wallet_info.dart'; import 'package:cw_core/wallet_type.dart'; import 'package:flutter/material.dart'; diff --git a/lib/view_model/transaction_details_view_model.dart b/lib/view_model/transaction_details_view_model.dart index 29e2e8169..a8c892284 100644 --- a/lib/view_model/transaction_details_view_model.dart +++ b/lib/view_model/transaction_details_view_model.dart @@ -250,18 +250,4 @@ abstract class TransactionDetailsViewModelBase with Store { items.addAll(_items); } - - - void _addNanoListItems(TransactionInfo tx, DateFormat dateFormat) { - final _items = [ - StandartListItem(title: S.current.transaction_details_transaction_id, value: tx.id), - StandartListItem( - title: S.current.transaction_details_date, value: dateFormat.format(tx.date)), - // StandartListItem(title: S.current.confirmed, value: (tx.confirmations > 0).toString()), - StandartListItem(title: S.current.transaction_details_height, value: '${tx.height}'), - StandartListItem(title: S.current.transaction_details_amount, value: tx.amountFormatted()), - ]; - - items.addAll(_items); - } } diff --git a/lib/view_model/wallet_restore_view_model.dart b/lib/view_model/wallet_restore_view_model.dart index 030801412..2810218a0 100644 --- a/lib/view_model/wallet_restore_view_model.dart +++ b/lib/view_model/wallet_restore_view_model.dart @@ -180,15 +180,15 @@ abstract class WalletRestoreViewModelBase extends WalletCreationVM with Store { // return bitcoin!.createBitcoinRestoreWalletFromSeedCredentials( // name: name, mnemonic: seed, password: password); case WalletType.nano: - return await nanoUtil.compareDerivationMethods( + return await nanoUtil!.compareDerivationMethods( mnemonic: mnemonic, - seedKey: seedKey, + privateKey: seedKey, node: node, ); default: break; } - + return [DerivationType.def]; }