banano changes

This commit is contained in:
fosse 2023-08-08 09:49:13 -04:00
parent 27777d4918
commit ca03c846c2
3 changed files with 75 additions and 15 deletions

View file

@ -0,0 +1,39 @@
import 'package:cw_core/balance.dart';
import 'package:cw_core/currency.dart';
import 'package:cw_nano/nano_util.dart';
String rawToFormattedAmount(BigInt amount, Currency currency) {
return "";
}
BigInt stringAmountToBigInt(String amount) {
return BigInt.zero;
}
class BananoBalance extends Balance {
final BigInt currentBalance;
final BigInt receivableBalance;
late String formattedCurrentBalance;
late String formattedReceivableBalance;
BananoBalance({required this.currentBalance, required this.receivableBalance}) : super(0, 0) {
this.formattedCurrentBalance = "";
this.formattedReceivableBalance = "";
}
BananoBalance.fromString(
{required this.formattedCurrentBalance, required this.formattedReceivableBalance})
: currentBalance = stringAmountToBigInt(formattedCurrentBalance),
receivableBalance = stringAmountToBigInt(formattedReceivableBalance),
super(0, 0);
@override
String get formattedAvailableBalance {
return NanoUtil.getRawAsUsableString(currentBalance.toString(), NanoUtil.rawPerBanano);
}
@override
String get formattedAdditionalBalance {
return NanoUtil.getRawAsUsableString(receivableBalance.toString(), NanoUtil.rawPerBanano);
}
}

View file

@ -1,4 +1,5 @@
import 'dart:convert';
import 'dart:io';
import 'package:cw_core/crypto_currency.dart';
import 'package:cw_core/node.dart';
@ -26,7 +27,6 @@ import 'package:cw_core/wallet_base.dart';
import 'package:nanodart/nanodart.dart';
import 'package:web3dart/web3dart.dart';
import 'package:bip39/bip39.dart' as bip39;
import 'package:bip32/bip32.dart' as bip32;
part 'nano_wallet.g.dart';
@ -119,10 +119,6 @@ abstract class NanoWalletBase
throw Exception("Nano Node connection failed");
}
if (_publicAddress == null) {
await Future.delayed(Duration(seconds: 1));
}
try {
await _updateBalance();
await _updateRep();
@ -389,7 +385,23 @@ abstract class NanoWalletBase
@override
Future<void> renameWalletFiles(String newWalletName) async {
print("rename");
throw UnimplementedError();
final currentWalletPath = await pathForWallet(name: walletInfo.name, type: type);
final currentWalletFile = File(currentWalletPath);
final currentDirPath = await pathForWalletDir(name: walletInfo.name, type: type);
final currentTransactionsFile = File('$currentDirPath/$transactionsHistoryFileName');
// Copies current wallet files into new wallet name's dir and files
if (currentWalletFile.existsSync()) {
final newWalletPath = await pathForWallet(name: newWalletName, type: type);
await currentWalletFile.copy(newWalletPath);
}
if (currentTransactionsFile.existsSync()) {
final newDirPath = await pathForWalletDir(name: newWalletName, type: type);
await currentTransactionsFile.copy('$newDirPath/$transactionsHistoryFileName');
}
// Delete old name's dir and files
await Directory(currentDirPath).delete(recursive: true);
}
}

View file

@ -106,17 +106,26 @@ class NanoWalletService extends WalletService<NanoNewWalletCredentials,
@override
Future<void> rename(String currentName, String password, String newName) async {
// final currentWalletInfo = walletInfoSource.values
// .firstWhere((info) => info.id == WalletBase.idFor(currentName, getType()));
// final currentWallet = NanoWallet(walletInfo: currentWalletInfo);
final currentWalletInfo = walletInfoSource.values
.firstWhere((info) => info.id == WalletBase.idFor(currentName, getType()));
// await currentWallet.renameWalletFiles(newName);
final NanoWalletInfo nanoWalletInfo = NanoWalletInfo(
walletInfo: currentWalletInfo,
derivationType: DerivationType.nano, // doesn't matter for rename
);
// final newWalletInfo = currentWalletInfo;
// newWalletInfo.id = WalletBase.idFor(newName, getType());
// newWalletInfo.name = newName;
String randomWords =
(List<String>.from(nm.NanoMnemomics.WORDLIST)..shuffle()).take(24).join(' ');
final currentWallet =
NanoWallet(walletInfo: nanoWalletInfo, password: password, mnemonic: randomWords);
// await walletInfoSource.put(currentWalletInfo.key, newWalletInfo);
await currentWallet.renameWalletFiles(newName);
final newWalletInfo = currentWalletInfo;
newWalletInfo.id = WalletBase.idFor(newName, getType());
newWalletInfo.name = newName;
await walletInfoSource.put(currentWalletInfo.key, newWalletInfo);
}
Future<DerivationType> compareDerivationMethods({String? mnemonic, String? seedKey}) async {