mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-22 10:45:08 +00:00
nano fixes pt.2
This commit is contained in:
parent
2c9bd6c5da
commit
9697baa565
17 changed files with 90 additions and 140 deletions
|
@ -139,6 +139,7 @@ class Node extends HiveObject with Keyable {
|
|||
case WalletType.ethereum:
|
||||
return requestElectrumServer();
|
||||
case WalletType.nano:
|
||||
case WalletType.banano:
|
||||
return requestNanoNode();
|
||||
default:
|
||||
return false;
|
||||
|
@ -181,24 +182,20 @@ class Node extends HiveObject with Keyable {
|
|||
}
|
||||
|
||||
Future<bool> requestNanoNode() async {
|
||||
return http
|
||||
.post(
|
||||
http.Response response = await http.post(
|
||||
uri,
|
||||
headers: {'Content-type': 'application/json'},
|
||||
body: json.encode(
|
||||
{
|
||||
"action": "account_balance",
|
||||
"account": "nano_38713x95zyjsqzx6nm1dsom1jmm668owkeb9913ax6nfgj15az3nu8xkx579"
|
||||
"action": "block_count",
|
||||
},
|
||||
),
|
||||
)
|
||||
.then((http.Response response) {
|
||||
if (response.statusCode == 200) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
);
|
||||
if (response.statusCode == 200) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> requestNodeWithProxy(String proxy) async {
|
||||
|
|
|
@ -212,7 +212,6 @@ abstract class NanoWalletBase
|
|||
|
||||
return PendingNanoTransaction(
|
||||
amount: runningAmount,
|
||||
fee: 0,
|
||||
id: "",
|
||||
nanoClient: _client,
|
||||
blocks: blocks,
|
||||
|
@ -280,6 +279,9 @@ abstract class NanoWalletBase
|
|||
return NanoWalletKeys(seedKey: _seedKey!);
|
||||
}
|
||||
|
||||
@override
|
||||
String? get privateKey => _seedKey!;
|
||||
|
||||
@override
|
||||
Future<void> rescan({required int height}) async {
|
||||
fetchTransactions();
|
||||
|
|
|
@ -1,47 +1,41 @@
|
|||
import 'package:cw_core/wallet_credentials.dart';
|
||||
import 'package:cw_core/wallet_info.dart';
|
||||
|
||||
// class NanoNewWalletCredentials extends WalletCredentials {
|
||||
// NanoNewWalletCredentials({required String name, WalletInfo? walletInfo})
|
||||
// : super(name: name, walletInfo: walletInfo);
|
||||
// }
|
||||
class NanoNewWalletCredentials extends WalletCredentials {
|
||||
NanoNewWalletCredentials({required String name, String? password})
|
||||
: super(name: name, password: password);
|
||||
}
|
||||
|
||||
// class NanoRestoreWalletFromSeedCredentials extends WalletCredentials {
|
||||
// NanoRestoreWalletFromSeedCredentials(
|
||||
// {required String name,
|
||||
// required String password,
|
||||
// required this.mnemonic,
|
||||
// WalletInfo? walletInfo})
|
||||
// : super(name: name, password: password, walletInfo: walletInfo);
|
||||
class NanoRestoreWalletFromSeedCredentials extends WalletCredentials {
|
||||
NanoRestoreWalletFromSeedCredentials({
|
||||
required String name,
|
||||
required this.mnemonic,
|
||||
int height = 0,
|
||||
String? password,
|
||||
DerivationType? derivationType,
|
||||
}) : super(
|
||||
name: name,
|
||||
password: password,
|
||||
height: height,
|
||||
derivationType: derivationType,
|
||||
);
|
||||
|
||||
// final String mnemonic;
|
||||
// }
|
||||
final String mnemonic;
|
||||
}
|
||||
|
||||
// class NanoRestoreWalletFromWIFCredentials extends WalletCredentials {
|
||||
// NanoRestoreWalletFromWIFCredentials(
|
||||
// {required String name, required String password, required this.wif, WalletInfo? walletInfo})
|
||||
// : super(name: name, password: password, walletInfo: walletInfo);
|
||||
class NanoWalletLoadingException implements Exception {
|
||||
@override
|
||||
String toString() => 'Failure to load the wallet.';
|
||||
}
|
||||
|
||||
// final String wif;
|
||||
// }
|
||||
class NanoRestoreWalletFromKeysCredentials extends WalletCredentials {
|
||||
NanoRestoreWalletFromKeysCredentials({
|
||||
required String name,
|
||||
required String password,
|
||||
required this.seedKey,
|
||||
this.derivationType,
|
||||
}) : super(name: name, password: password);
|
||||
|
||||
|
||||
// class NanoNewWalletCredentials extends WalletCredentials {
|
||||
// NanoNewWalletCredentials({required String name, required this.language, String? password})
|
||||
// : super(name: name, password: password);
|
||||
|
||||
// final String language;
|
||||
// }
|
||||
|
||||
// class NanoRestoreWalletFromSeedCredentials extends WalletCredentials {
|
||||
// NanoRestoreWalletFromSeedCredentials(
|
||||
// {required String name, required this.mnemonic, int height = 0, String? password})
|
||||
// : super(name: name, password: password, height: height);
|
||||
|
||||
// final String mnemonic;
|
||||
// }
|
||||
|
||||
// class NanoWalletLoadingException implements Exception {
|
||||
// @override
|
||||
// String toString() => 'Failure to load the wallet.';
|
||||
// }
|
||||
final String seedKey;
|
||||
final DerivationType? derivationType;
|
||||
}
|
|
@ -3,58 +3,18 @@ import 'dart:io';
|
|||
import 'package:cw_core/node.dart';
|
||||
import 'package:cw_core/pathForWallet.dart';
|
||||
import 'package:cw_core/wallet_base.dart';
|
||||
import 'package:cw_core/wallet_credentials.dart';
|
||||
import 'package:cw_core/wallet_info.dart';
|
||||
import 'package:cw_core/wallet_service.dart';
|
||||
import 'package:cw_core/wallet_type.dart';
|
||||
import 'package:cw_nano/nano_balance.dart';
|
||||
import 'package:cw_nano/nano_client.dart';
|
||||
import 'package:cw_nano/nano_mnemonic.dart' as nm;
|
||||
import 'package:cw_nano/nano_util.dart';
|
||||
import 'package:cw_nano/nano_wallet.dart';
|
||||
import 'package:cw_nano/nano_wallet_creation_credentials.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:bip39/bip39.dart' as bip39;
|
||||
import 'package:nanodart/nanodart.dart';
|
||||
|
||||
class NanoNewWalletCredentials extends WalletCredentials {
|
||||
NanoNewWalletCredentials({required String name, String? password})
|
||||
: super(name: name, password: password);
|
||||
}
|
||||
|
||||
class NanoRestoreWalletFromSeedCredentials extends WalletCredentials {
|
||||
NanoRestoreWalletFromSeedCredentials({
|
||||
required String name,
|
||||
required this.mnemonic,
|
||||
int height = 0,
|
||||
String? password,
|
||||
DerivationType? derivationType,
|
||||
}) : super(
|
||||
name: name,
|
||||
password: password,
|
||||
height: height,
|
||||
derivationType: derivationType,
|
||||
);
|
||||
|
||||
final String mnemonic;
|
||||
}
|
||||
|
||||
class NanoWalletLoadingException implements Exception {
|
||||
@override
|
||||
String toString() => 'Failure to load the wallet.';
|
||||
}
|
||||
|
||||
class NanoRestoreWalletFromKeysCredentials extends WalletCredentials {
|
||||
NanoRestoreWalletFromKeysCredentials({
|
||||
required String name,
|
||||
required String password,
|
||||
required this.seedKey,
|
||||
this.derivationType,
|
||||
}) : super(name: name, password: password);
|
||||
|
||||
final String seedKey;
|
||||
final DerivationType? derivationType;
|
||||
}
|
||||
|
||||
class NanoWalletService extends WalletService<NanoNewWalletCredentials,
|
||||
NanoRestoreWalletFromSeedCredentials, NanoRestoreWalletFromKeysCredentials> {
|
||||
NanoWalletService(this.walletInfoSource);
|
||||
|
|
|
@ -6,14 +6,12 @@ class PendingNanoTransaction with PendingTransaction {
|
|||
PendingNanoTransaction({
|
||||
required this.nanoClient,
|
||||
required this.amount,
|
||||
required this.fee,
|
||||
required this.id,
|
||||
required this.blocks,
|
||||
});
|
||||
|
||||
final NanoClient nanoClient;
|
||||
final BigInt amount;
|
||||
final int fee;
|
||||
final String id;
|
||||
final List<Map<String, String>> blocks;
|
||||
String hex = "unused";
|
||||
|
|
|
@ -2,7 +2,6 @@ import 'package:cake_wallet/bitcoin/bitcoin.dart';
|
|||
import 'package:cake_wallet/ethereum/ethereum.dart';
|
||||
import 'package:cake_wallet/haven/haven.dart';
|
||||
import 'package:cake_wallet/monero/monero.dart';
|
||||
import 'package:cake_wallet/nano/nano.dart';
|
||||
import 'package:cw_core/transaction_priority.dart';
|
||||
import 'package:cw_core/wallet_type.dart';
|
||||
|
||||
|
@ -18,10 +17,10 @@ List<TransactionPriority> priorityForWalletType(WalletType type) {
|
|||
return haven!.getTransactionPriorities();
|
||||
case WalletType.ethereum:
|
||||
return ethereum!.getTransactionPriorities();
|
||||
// we just get ethereum's here since there's no transaction priority in nano
|
||||
// and so there's no point in bothering to implement it:
|
||||
// no such thing for nano/banano:
|
||||
case WalletType.nano:
|
||||
return ethereum!.getTransactionPriorities();
|
||||
case WalletType.banano:
|
||||
return [];
|
||||
default:
|
||||
return [];
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ import 'package:cw_core/wallet_service.dart';
|
|||
import 'package:cw_core/output_info.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:cw_nano/nano_transaction_credentials.dart';
|
||||
import 'package:cw_nano/nano_wallet_creation_credentials.dart';
|
||||
|
||||
part 'cw_nano.dart';
|
||||
|
||||
|
|
|
@ -33,6 +33,8 @@ class _DesktopWalletSelectionDropDownState extends State<DesktopWalletSelectionD
|
|||
final litecoinIcon = Image.asset('assets/images/litecoin_icon.png', height: 24, width: 24);
|
||||
final havenIcon = Image.asset('assets/images/haven_logo.png', height: 24, width: 24);
|
||||
final ethereumIcon = Image.asset('assets/images/eth_icon.png', height: 24, width: 24);
|
||||
final nanoIcon = Image.asset('assets/images/nano_icon.png', height: 24, width: 24);
|
||||
final bananoIcon = Image.asset('assets/images/nano_icon.png', height: 24, width: 24);
|
||||
final nonWalletTypeIcon = Image.asset('assets/images/close.png', height: 24, width: 24);
|
||||
|
||||
Image _newWalletImage(BuildContext context) => Image.asset(
|
||||
|
@ -141,6 +143,10 @@ class _DesktopWalletSelectionDropDownState extends State<DesktopWalletSelectionD
|
|||
return havenIcon;
|
||||
case WalletType.ethereum:
|
||||
return ethereumIcon;
|
||||
case WalletType.nano:
|
||||
return nanoIcon;
|
||||
case WalletType.banano:
|
||||
return bananoIcon;
|
||||
default:
|
||||
return nonWalletTypeIcon;
|
||||
}
|
||||
|
|
|
@ -1,18 +0,0 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:cake_wallet/palette.dart';
|
||||
|
||||
class NodeIndicator extends StatelessWidget {
|
||||
NodeIndicator({this.isLive = false});
|
||||
|
||||
final bool isLive;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
width: 12.0,
|
||||
height: 12.0,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle, color: isLive ? Palette.green : Palette.red),
|
||||
);
|
||||
}
|
||||
}
|
|
@ -68,16 +68,19 @@ class ConnectionSyncPage extends BasePage {
|
|||
const StandardListSeparator(padding: EdgeInsets.symmetric(horizontal: 24)),
|
||||
Observer(
|
||||
builder: (context) {
|
||||
if (!dashboardViewModel.hasPowNodes)
|
||||
return const SizedBox();
|
||||
|
||||
return SettingsCellWithArrow(
|
||||
title: S.current.manage_pow_nodes,
|
||||
handler: (context) => Navigator.of(context).pushNamed(Routes.managePowNodes),
|
||||
if (!dashboardViewModel.hasPowNodes) return const SizedBox();
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
SettingsCellWithArrow(
|
||||
title: S.current.manage_pow_nodes,
|
||||
handler: (context) => Navigator.of(context).pushNamed(Routes.managePowNodes),
|
||||
),
|
||||
const StandardListSeparator(padding: EdgeInsets.symmetric(horizontal: 24)),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
const StandardListSeparator(padding: EdgeInsets.symmetric(horizontal: 24)),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
|
|
@ -1 +1 @@
|
|||
enum WalletRestoreMode { seed, keys, txids, seedKey }
|
||||
enum WalletRestoreMode { seed, keys, txids }
|
|
@ -64,7 +64,7 @@ abstract class SendViewModelBase extends WalletChangeListenerViewModel with Stor
|
|||
final priority = _settingsStore.priority[wallet.type];
|
||||
final priorities = priorityForWalletType(wallet.type);
|
||||
|
||||
if (!priorityForWalletType(wallet.type).contains(priority)) {
|
||||
if (!priorityForWalletType(wallet.type).contains(priority) && priorities.isNotEmpty) {
|
||||
_settingsStore.priority[wallet.type] = priorities.first;
|
||||
}
|
||||
|
||||
|
|
|
@ -107,7 +107,6 @@ abstract class WalletKeysViewModelBase with Store {
|
|||
}
|
||||
|
||||
if (_appStore.wallet!.type == WalletType.nano || _appStore.wallet!.type == WalletType.banano) {
|
||||
final keys = nano!.getKeys(_appStore.wallet!);
|
||||
|
||||
// we don't necessarily have the seed phrase for nano / banano:
|
||||
if (_appStore.wallet!.seed != null) {
|
||||
|
@ -118,8 +117,8 @@ abstract class WalletKeysViewModelBase with Store {
|
|||
|
||||
// we always have the hex version of the seed:
|
||||
items.addAll([
|
||||
if (keys['private_key'] != null)
|
||||
StandartListItem(title: S.current.spend_key_private, value: keys['private_key']!),
|
||||
if (_appStore.wallet!.privateKey != null)
|
||||
StandartListItem(title: S.current.spend_key_private, value: _appStore.wallet!.privateKey!),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,19 +28,27 @@ abstract class WalletRestoreViewModelBase extends WalletCreationVM with Store {
|
|||
WalletRestoreViewModelBase(AppStore appStore, WalletCreationService walletCreationService,
|
||||
Box<WalletInfo> walletInfoSource,
|
||||
{required WalletType type})
|
||||
: availableModes =
|
||||
(type == WalletType.monero || type == WalletType.haven || type == WalletType.ethereum)
|
||||
? WalletRestoreMode.values
|
||||
: (type == WalletType.nano || type == WalletType.banano)
|
||||
? [WalletRestoreMode.seed, WalletRestoreMode.keys]
|
||||
: [WalletRestoreMode.seed],
|
||||
hasSeedLanguageSelector = type == WalletType.monero || type == WalletType.haven,
|
||||
: hasSeedLanguageSelector = type == WalletType.monero || type == WalletType.haven,
|
||||
hasBlockchainHeightLanguageSelector = type == WalletType.monero || type == WalletType.haven,
|
||||
hasRestoreFromPrivateKey =
|
||||
type == WalletType.ethereum || type == WalletType.nano || type == WalletType.banano,
|
||||
isButtonEnabled = false,
|
||||
mode = WalletRestoreMode.seed,
|
||||
super(appStore, walletInfoSource, walletCreationService, type: type, isRecovery: true) {
|
||||
switch (type) {
|
||||
case WalletType.monero:
|
||||
case WalletType.haven:
|
||||
case WalletType.ethereum:
|
||||
availableModes = WalletRestoreMode.values;
|
||||
break;
|
||||
case WalletType.nano:
|
||||
case WalletType.banano:
|
||||
availableModes = [WalletRestoreMode.seed, WalletRestoreMode.keys];
|
||||
break;
|
||||
default:
|
||||
availableModes = [WalletRestoreMode.seed];
|
||||
break;
|
||||
}
|
||||
isButtonEnabled = !hasSeedLanguageSelector && !hasBlockchainHeightLanguageSelector;
|
||||
walletCreationService.changeWalletType(type: type);
|
||||
}
|
||||
|
@ -49,7 +57,7 @@ abstract class WalletRestoreViewModelBase extends WalletCreationVM with Store {
|
|||
static const electrumSeedMnemonicLength = 24;
|
||||
static const electrumShortSeedMnemonicLength = 12;
|
||||
|
||||
final List<WalletRestoreMode> availableModes;
|
||||
late List<WalletRestoreMode> availableModes;
|
||||
final bool hasSeedLanguageSelector;
|
||||
final bool hasBlockchainHeightLanguageSelector;
|
||||
final bool hasRestoreFromPrivateKey;
|
||||
|
@ -158,7 +166,7 @@ abstract class WalletRestoreViewModelBase extends WalletCreationVM with Store {
|
|||
final mnemonic = options['seed'] as String?;
|
||||
WalletType walletType = options['walletType'] as WalletType;
|
||||
var appStore = getIt.get<AppStore>();
|
||||
var node = appStore.settingsStore.getCurrentNode(walletType) as Node;
|
||||
var node = appStore.settingsStore.getCurrentNode(walletType);
|
||||
|
||||
switch (type) {
|
||||
case WalletType.bitcoin:
|
||||
|
|
|
@ -23,7 +23,7 @@ case $APP_IOS_TYPE in
|
|||
CONFIG_ARGS="--monero"
|
||||
;;
|
||||
$CAKEWALLET)
|
||||
CONFIG_ARGS="--monero --bitcoin --haven --ethereum"
|
||||
CONFIG_ARGS="--monero --bitcoin --haven --ethereum --nano"
|
||||
;;
|
||||
$HAVEN)
|
||||
CONFIG_ARGS="--haven"
|
||||
|
|
|
@ -23,7 +23,7 @@ CONFIG_ARGS=""
|
|||
|
||||
case $APP_MACOS_TYPE in
|
||||
$CAKEWALLET)
|
||||
CONFIG_ARGS="--monero --bitcoin --ethereum";; #--haven
|
||||
CONFIG_ARGS="--monero --bitcoin --ethereum --nano";; #--haven
|
||||
esac
|
||||
|
||||
cp -rf pubspec_description.yaml pubspec.yaml
|
||||
|
|
|
@ -583,6 +583,7 @@ import 'package:cw_core/wallet_service.dart';
|
|||
import 'package:cw_core/output_info.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:cw_nano/nano_transaction_credentials.dart';
|
||||
import 'package:cw_nano/nano_wallet_creation_credentials.dart';
|
||||
""";
|
||||
const nanoCwPart = "part 'cw_nano.dart';";
|
||||
const nanoContent = """
|
||||
|
|
Loading…
Reference in a new issue