mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-03 17:40:43 +00:00
fix: wallet seed display
fix: wownero not refreshing
This commit is contained in:
parent
442bae17cc
commit
4c061addab
5 changed files with 177 additions and 108 deletions
|
@ -43,6 +43,15 @@ String getSeed() {
|
||||||
return legacy;
|
return legacy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String getSeedLegacy(String? language) {
|
||||||
|
var legacy = monero.Wallet_seed(wptr!, seedOffset: '');
|
||||||
|
if (monero.Wallet_status(wptr!) != 0) {
|
||||||
|
monero.Wallet_setSeedLanguage(wptr!, language: language ?? "English");
|
||||||
|
legacy = monero.Wallet_seed(wptr!, seedOffset: '');
|
||||||
|
}
|
||||||
|
return legacy;
|
||||||
|
}
|
||||||
|
|
||||||
String getAddress({int accountIndex = 0, int addressIndex = 1}) =>
|
String getAddress({int accountIndex = 0, int addressIndex = 1}) =>
|
||||||
monero.Wallet_address(wptr!,
|
monero.Wallet_address(wptr!,
|
||||||
accountIndex: accountIndex, addressIndex: addressIndex);
|
accountIndex: accountIndex, addressIndex: addressIndex);
|
||||||
|
|
|
@ -19,6 +19,7 @@ import 'package:cw_core/transaction_priority.dart';
|
||||||
import 'package:cw_core/unspent_coins_info.dart';
|
import 'package:cw_core/unspent_coins_info.dart';
|
||||||
import 'package:cw_core/wallet_base.dart';
|
import 'package:cw_core/wallet_base.dart';
|
||||||
import 'package:cw_core/wallet_info.dart';
|
import 'package:cw_core/wallet_info.dart';
|
||||||
|
import 'package:cw_monero/api/account_list.dart';
|
||||||
import 'package:cw_monero/api/coins_info.dart';
|
import 'package:cw_monero/api/coins_info.dart';
|
||||||
import 'package:cw_monero/api/monero_output.dart';
|
import 'package:cw_monero/api/monero_output.dart';
|
||||||
import 'package:cw_monero/api/structs/pending_transaction.dart';
|
import 'package:cw_monero/api/structs/pending_transaction.dart';
|
||||||
|
@ -105,6 +106,9 @@ abstract class MoneroWalletBase
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get seed => monero_wallet.getSeed();
|
String get seed => monero_wallet.getSeed();
|
||||||
|
String seedLegacy(String? language) {
|
||||||
|
return monero_wallet.getSeedLegacy(language);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
MoneroWalletKeys get keys => MoneroWalletKeys(
|
MoneroWalletKeys get keys => MoneroWalletKeys(
|
||||||
|
|
|
@ -15,15 +15,17 @@ int getSyncingHeight() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isNeededToRefresh() {
|
bool isNeededToRefresh() {
|
||||||
final ret = wownero.WOWNERO_cw_WalletListener_isNeedToRefresh(getWlptr());
|
// final ret = wownero.WOWNERO_cw_WalletListener_isNeedToRefresh(getWlptr());
|
||||||
wownero.WOWNERO_cw_WalletListener_resetNeedToRefresh(getWlptr());
|
// wownero.WOWNERO_cw_WalletListener_resetNeedToRefresh(getWlptr());
|
||||||
return ret;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isNewTransactionExist() {
|
bool isNewTransactionExist() {
|
||||||
final ret = wownero.WOWNERO_cw_WalletListener_isNewTransactionExist(getWlptr());
|
// final ret =
|
||||||
wownero.WOWNERO_cw_WalletListener_resetIsNewTransactionExist(getWlptr());
|
// wownero.WOWNERO_cw_WalletListener_isNewTransactionExist(getWlptr());
|
||||||
return ret;
|
// wownero.WOWNERO_cw_WalletListener_resetIsNewTransactionExist(getWlptr());
|
||||||
|
// NOTE: I don't know why wownero is being funky, but
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
String getFilename() => wownero.Wallet_filename(wptr!);
|
String getFilename() => wownero.Wallet_filename(wptr!);
|
||||||
|
@ -43,6 +45,15 @@ String getSeed() {
|
||||||
return legacy;
|
return legacy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String getSeedLegacy(String? language) {
|
||||||
|
var legacy = wownero.Wallet_seed(wptr!, seedOffset: '');
|
||||||
|
if (wownero.Wallet_status(wptr!) != 0) {
|
||||||
|
wownero.Wallet_setSeedLanguage(wptr!, language: language ?? "English");
|
||||||
|
legacy = wownero.Wallet_seed(wptr!, seedOffset: '');
|
||||||
|
}
|
||||||
|
return legacy;
|
||||||
|
}
|
||||||
|
|
||||||
String getAddress({int accountIndex = 0, int addressIndex = 1}) =>
|
String getAddress({int accountIndex = 0, int addressIndex = 1}) =>
|
||||||
wownero.Wallet_address(wptr!,
|
wownero.Wallet_address(wptr!,
|
||||||
accountIndex: accountIndex, addressIndex: addressIndex);
|
accountIndex: accountIndex, addressIndex: addressIndex);
|
||||||
|
|
|
@ -5,8 +5,6 @@ import 'dart:isolate';
|
||||||
|
|
||||||
import 'package:cw_core/account.dart';
|
import 'package:cw_core/account.dart';
|
||||||
import 'package:cw_core/crypto_currency.dart';
|
import 'package:cw_core/crypto_currency.dart';
|
||||||
import 'package:cw_core/wownero_amount_format.dart';
|
|
||||||
import 'package:cw_core/wownero_balance.dart';
|
|
||||||
import 'package:cw_core/monero_transaction_priority.dart';
|
import 'package:cw_core/monero_transaction_priority.dart';
|
||||||
import 'package:cw_core/monero_wallet_keys.dart';
|
import 'package:cw_core/monero_wallet_keys.dart';
|
||||||
import 'package:cw_core/monero_wallet_utils.dart';
|
import 'package:cw_core/monero_wallet_utils.dart';
|
||||||
|
@ -19,20 +17,22 @@ import 'package:cw_core/transaction_priority.dart';
|
||||||
import 'package:cw_core/unspent_coins_info.dart';
|
import 'package:cw_core/unspent_coins_info.dart';
|
||||||
import 'package:cw_core/wallet_base.dart';
|
import 'package:cw_core/wallet_base.dart';
|
||||||
import 'package:cw_core/wallet_info.dart';
|
import 'package:cw_core/wallet_info.dart';
|
||||||
|
import 'package:cw_core/wownero_amount_format.dart';
|
||||||
|
import 'package:cw_core/wownero_balance.dart';
|
||||||
import 'package:cw_wownero/api/coins_info.dart';
|
import 'package:cw_wownero/api/coins_info.dart';
|
||||||
import 'package:cw_wownero/api/wownero_output.dart';
|
|
||||||
import 'package:cw_wownero/api/structs/pending_transaction.dart';
|
import 'package:cw_wownero/api/structs/pending_transaction.dart';
|
||||||
import 'package:cw_wownero/api/transaction_history.dart' as transaction_history;
|
import 'package:cw_wownero/api/transaction_history.dart' as transaction_history;
|
||||||
import 'package:cw_wownero/api/wallet.dart' as wownero_wallet;
|
import 'package:cw_wownero/api/wallet.dart' as wownero_wallet;
|
||||||
import 'package:cw_wownero/api/wallet_manager.dart';
|
import 'package:cw_wownero/api/wallet_manager.dart';
|
||||||
|
import 'package:cw_wownero/api/wownero_output.dart';
|
||||||
import 'package:cw_wownero/exceptions/wownero_transaction_creation_exception.dart';
|
import 'package:cw_wownero/exceptions/wownero_transaction_creation_exception.dart';
|
||||||
import 'package:cw_wownero/exceptions/wownero_transaction_no_inputs_exception.dart';
|
import 'package:cw_wownero/exceptions/wownero_transaction_no_inputs_exception.dart';
|
||||||
|
import 'package:cw_wownero/pending_wownero_transaction.dart';
|
||||||
import 'package:cw_wownero/wownero_transaction_creation_credentials.dart';
|
import 'package:cw_wownero/wownero_transaction_creation_credentials.dart';
|
||||||
import 'package:cw_wownero/wownero_transaction_history.dart';
|
import 'package:cw_wownero/wownero_transaction_history.dart';
|
||||||
import 'package:cw_wownero/wownero_transaction_info.dart';
|
import 'package:cw_wownero/wownero_transaction_info.dart';
|
||||||
import 'package:cw_wownero/wownero_unspent.dart';
|
import 'package:cw_wownero/wownero_unspent.dart';
|
||||||
import 'package:cw_wownero/wownero_wallet_addresses.dart';
|
import 'package:cw_wownero/wownero_wallet_addresses.dart';
|
||||||
import 'package:cw_wownero/pending_wownero_transaction.dart';
|
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:hive/hive.dart';
|
import 'package:hive/hive.dart';
|
||||||
import 'package:mobx/mobx.dart';
|
import 'package:mobx/mobx.dart';
|
||||||
|
@ -46,10 +46,11 @@ const MIN_RESTORE_HEIGHT = 1000;
|
||||||
|
|
||||||
class WowneroWallet = WowneroWalletBase with _$WowneroWallet;
|
class WowneroWallet = WowneroWalletBase with _$WowneroWallet;
|
||||||
|
|
||||||
abstract class WowneroWalletBase
|
abstract class WowneroWalletBase extends WalletBase<WowneroBalance,
|
||||||
extends WalletBase<WowneroBalance, WowneroTransactionHistory, WowneroTransactionInfo> with Store {
|
WowneroTransactionHistory, WowneroTransactionInfo> with Store {
|
||||||
WowneroWalletBase(
|
WowneroWalletBase(
|
||||||
{required WalletInfo walletInfo, required Box<UnspentCoinsInfo> unspentCoinsInfo})
|
{required WalletInfo walletInfo,
|
||||||
|
required Box<UnspentCoinsInfo> unspentCoinsInfo})
|
||||||
: balance = ObservableMap<CryptoCurrency, WowneroBalance>.of({
|
: balance = ObservableMap<CryptoCurrency, WowneroBalance>.of({
|
||||||
CryptoCurrency.xmr: WowneroBalance(
|
CryptoCurrency.xmr: WowneroBalance(
|
||||||
fullBalance: wownero_wallet.getFullBalance(accountIndex: 0),
|
fullBalance: wownero_wallet.getFullBalance(accountIndex: 0),
|
||||||
|
@ -65,13 +66,17 @@ abstract class WowneroWalletBase
|
||||||
transactionHistory = WowneroTransactionHistory();
|
transactionHistory = WowneroTransactionHistory();
|
||||||
walletAddresses = WowneroWalletAddresses(walletInfo, transactionHistory);
|
walletAddresses = WowneroWalletAddresses(walletInfo, transactionHistory);
|
||||||
|
|
||||||
_onAccountChangeReaction = reaction((_) => walletAddresses.account, (Account? account) {
|
_onAccountChangeReaction =
|
||||||
|
reaction((_) => walletAddresses.account, (Account? account) {
|
||||||
if (account == null) return;
|
if (account == null) return;
|
||||||
|
|
||||||
balance = ObservableMap<CryptoCurrency, WowneroBalance>.of(<CryptoCurrency, WowneroBalance>{
|
balance = ObservableMap<CryptoCurrency,
|
||||||
|
WowneroBalance>.of(<CryptoCurrency, WowneroBalance>{
|
||||||
currency: WowneroBalance(
|
currency: WowneroBalance(
|
||||||
fullBalance: wownero_wallet.getFullBalance(accountIndex: account.id),
|
fullBalance:
|
||||||
unlockedBalance: wownero_wallet.getUnlockedBalance(accountIndex: account.id))
|
wownero_wallet.getFullBalance(accountIndex: account.id),
|
||||||
|
unlockedBalance:
|
||||||
|
wownero_wallet.getUnlockedBalance(accountIndex: account.id))
|
||||||
});
|
});
|
||||||
_updateSubAddress(isEnabledAutoGenerateSubaddress, account: account);
|
_updateSubAddress(isEnabledAutoGenerateSubaddress, account: account);
|
||||||
_askForUpdateTransactionHistory();
|
_askForUpdateTransactionHistory();
|
||||||
|
@ -106,6 +111,10 @@ abstract class WowneroWalletBase
|
||||||
@override
|
@override
|
||||||
String get seed => wownero_wallet.getSeed();
|
String get seed => wownero_wallet.getSeed();
|
||||||
|
|
||||||
|
String seedLegacy(String? language) {
|
||||||
|
return wownero_wallet.getSeedLegacy(language);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
MoneroWalletKeys get keys => MoneroWalletKeys(
|
MoneroWalletKeys get keys => MoneroWalletKeys(
|
||||||
privateSpendKey: wownero_wallet.getSecretSpendKey(),
|
privateSpendKey: wownero_wallet.getSecretSpendKey(),
|
||||||
|
@ -122,11 +131,13 @@ abstract class WowneroWalletBase
|
||||||
|
|
||||||
Future<void> init() async {
|
Future<void> init() async {
|
||||||
await walletAddresses.init();
|
await walletAddresses.init();
|
||||||
balance = ObservableMap<CryptoCurrency, WowneroBalance>.of(<CryptoCurrency, WowneroBalance>{
|
balance = ObservableMap<CryptoCurrency, WowneroBalance>.of(<CryptoCurrency,
|
||||||
|
WowneroBalance>{
|
||||||
currency: WowneroBalance(
|
currency: WowneroBalance(
|
||||||
fullBalance: wownero_wallet.getFullBalance(accountIndex: walletAddresses.account!.id),
|
fullBalance: wownero_wallet.getFullBalance(
|
||||||
unlockedBalance:
|
accountIndex: walletAddresses.account!.id),
|
||||||
wownero_wallet.getUnlockedBalance(accountIndex: walletAddresses.account!.id))
|
unlockedBalance: wownero_wallet.getUnlockedBalance(
|
||||||
|
accountIndex: walletAddresses.account!.id))
|
||||||
});
|
});
|
||||||
_setListeners();
|
_setListeners();
|
||||||
await updateTransactions();
|
await updateTransactions();
|
||||||
|
@ -135,12 +146,13 @@ abstract class WowneroWalletBase
|
||||||
wownero_wallet.setRecoveringFromSeed(isRecovery: walletInfo.isRecovery);
|
wownero_wallet.setRecoveringFromSeed(isRecovery: walletInfo.isRecovery);
|
||||||
|
|
||||||
if (wownero_wallet.getCurrentHeight() <= 1) {
|
if (wownero_wallet.getCurrentHeight() <= 1) {
|
||||||
wownero_wallet.setRefreshFromBlockHeight(height: walletInfo.restoreHeight);
|
wownero_wallet.setRefreshFromBlockHeight(
|
||||||
|
height: walletInfo.restoreHeight);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_autoSaveTimer =
|
_autoSaveTimer = Timer.periodic(
|
||||||
Timer.periodic(Duration(seconds: _autoSaveInterval), (_) async => await save());
|
Duration(seconds: _autoSaveInterval), (_) async => await save());
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -212,8 +224,8 @@ abstract class WowneroWalletBase
|
||||||
final inputs = <String>[];
|
final inputs = <String>[];
|
||||||
final outputs = _credentials.outputs;
|
final outputs = _credentials.outputs;
|
||||||
final hasMultiDestination = outputs.length > 1;
|
final hasMultiDestination = outputs.length > 1;
|
||||||
final unlockedBalance =
|
final unlockedBalance = wownero_wallet.getUnlockedBalance(
|
||||||
wownero_wallet.getUnlockedBalance(accountIndex: walletAddresses.account!.id);
|
accountIndex: walletAddresses.account!.id);
|
||||||
var allInputsAmount = 0;
|
var allInputsAmount = 0;
|
||||||
|
|
||||||
PendingTransactionDescription pendingTransactionDescription;
|
PendingTransactionDescription pendingTransactionDescription;
|
||||||
|
@ -235,16 +247,20 @@ abstract class WowneroWalletBase
|
||||||
final spendAllCoins = inputs.length == unspentCoins.length;
|
final spendAllCoins = inputs.length == unspentCoins.length;
|
||||||
|
|
||||||
if (hasMultiDestination) {
|
if (hasMultiDestination) {
|
||||||
if (outputs.any((item) => item.sendAll || (item.formattedCryptoAmount ?? 0) <= 0)) {
|
if (outputs.any(
|
||||||
throw WowneroTransactionCreationException('You do not have enough XMR to send this amount.');
|
(item) => item.sendAll || (item.formattedCryptoAmount ?? 0) <= 0)) {
|
||||||
|
throw WowneroTransactionCreationException(
|
||||||
|
'You do not have enough XMR to send this amount.');
|
||||||
}
|
}
|
||||||
|
|
||||||
final int totalAmount =
|
final int totalAmount = outputs.fold(
|
||||||
outputs.fold(0, (acc, value) => acc + (value.formattedCryptoAmount ?? 0));
|
0, (acc, value) => acc + (value.formattedCryptoAmount ?? 0));
|
||||||
|
|
||||||
final estimatedFee = calculateEstimatedFee(_credentials.priority, totalAmount);
|
final estimatedFee =
|
||||||
|
calculateEstimatedFee(_credentials.priority, totalAmount);
|
||||||
if (unlockedBalance < totalAmount) {
|
if (unlockedBalance < totalAmount) {
|
||||||
throw WowneroTransactionCreationException('You do not have enough XMR to send this amount.');
|
throw WowneroTransactionCreationException(
|
||||||
|
'You do not have enough XMR to send this amount.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!spendAllCoins && (allInputsAmount < totalAmount + estimatedFee)) {
|
if (!spendAllCoins && (allInputsAmount < totalAmount + estimatedFee)) {
|
||||||
|
@ -252,22 +268,28 @@ abstract class WowneroWalletBase
|
||||||
}
|
}
|
||||||
|
|
||||||
final wowneroOutputs = outputs.map((output) {
|
final wowneroOutputs = outputs.map((output) {
|
||||||
final outputAddress = output.isParsedAddress ? output.extractedAddress : output.address;
|
final outputAddress =
|
||||||
|
output.isParsedAddress ? output.extractedAddress : output.address;
|
||||||
|
|
||||||
return WowneroOutput(
|
return WowneroOutput(
|
||||||
address: outputAddress!, amount: output.cryptoAmount!.replaceAll(',', '.'));
|
address: outputAddress!,
|
||||||
|
amount: output.cryptoAmount!.replaceAll(',', '.'));
|
||||||
}).toList();
|
}).toList();
|
||||||
|
|
||||||
pendingTransactionDescription = await transaction_history.createTransactionMultDest(
|
pendingTransactionDescription =
|
||||||
outputs: wowneroOutputs,
|
await transaction_history.createTransactionMultDest(
|
||||||
priorityRaw: _credentials.priority.serialize(),
|
outputs: wowneroOutputs,
|
||||||
accountIndex: walletAddresses.account!.id,
|
priorityRaw: _credentials.priority.serialize(),
|
||||||
preferredInputs: inputs);
|
accountIndex: walletAddresses.account!.id,
|
||||||
|
preferredInputs: inputs);
|
||||||
} else {
|
} else {
|
||||||
final output = outputs.first;
|
final output = outputs.first;
|
||||||
final address = output.isParsedAddress ? output.extractedAddress : output.address;
|
final address =
|
||||||
final amount = output.sendAll ? null : output.cryptoAmount!.replaceAll(',', '.');
|
output.isParsedAddress ? output.extractedAddress : output.address;
|
||||||
final formattedAmount = output.sendAll ? null : output.formattedCryptoAmount;
|
final amount =
|
||||||
|
output.sendAll ? null : output.cryptoAmount!.replaceAll(',', '.');
|
||||||
|
final formattedAmount =
|
||||||
|
output.sendAll ? null : output.formattedCryptoAmount;
|
||||||
|
|
||||||
if ((formattedAmount != null && unlockedBalance < formattedAmount) ||
|
if ((formattedAmount != null && unlockedBalance < formattedAmount) ||
|
||||||
(formattedAmount == null && unlockedBalance <= 0)) {
|
(formattedAmount == null && unlockedBalance <= 0)) {
|
||||||
|
@ -277,19 +299,22 @@ abstract class WowneroWalletBase
|
||||||
'You do not have enough unlocked balance. Unlocked: $formattedBalance. Transaction amount: ${output.cryptoAmount}.');
|
'You do not have enough unlocked balance. Unlocked: $formattedBalance. Transaction amount: ${output.cryptoAmount}.');
|
||||||
}
|
}
|
||||||
|
|
||||||
final estimatedFee = calculateEstimatedFee(_credentials.priority, formattedAmount);
|
final estimatedFee =
|
||||||
|
calculateEstimatedFee(_credentials.priority, formattedAmount);
|
||||||
if (!spendAllCoins &&
|
if (!spendAllCoins &&
|
||||||
((formattedAmount != null && allInputsAmount < (formattedAmount + estimatedFee)) ||
|
((formattedAmount != null &&
|
||||||
|
allInputsAmount < (formattedAmount + estimatedFee)) ||
|
||||||
formattedAmount == null)) {
|
formattedAmount == null)) {
|
||||||
throw WowneroTransactionNoInputsException(inputs.length);
|
throw WowneroTransactionNoInputsException(inputs.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
pendingTransactionDescription = await transaction_history.createTransaction(
|
pendingTransactionDescription =
|
||||||
address: address!,
|
await transaction_history.createTransaction(
|
||||||
amount: amount,
|
address: address!,
|
||||||
priorityRaw: _credentials.priority.serialize(),
|
amount: amount,
|
||||||
accountIndex: walletAddresses.account!.id,
|
priorityRaw: _credentials.priority.serialize(),
|
||||||
preferredInputs: inputs);
|
accountIndex: walletAddresses.account!.id,
|
||||||
|
preferredInputs: inputs);
|
||||||
}
|
}
|
||||||
|
|
||||||
return PendingWowneroTransaction(pendingTransactionDescription);
|
return PendingWowneroTransaction(pendingTransactionDescription);
|
||||||
|
@ -347,18 +372,17 @@ abstract class WowneroWalletBase
|
||||||
final waddr = openedWalletsByPath["$currentWalletDirPath/$name"]!.address;
|
final waddr = openedWalletsByPath["$currentWalletDirPath/$name"]!.address;
|
||||||
await Isolate.run(() {
|
await Isolate.run(() {
|
||||||
wownero.WalletManager_closeWallet(
|
wownero.WalletManager_closeWallet(
|
||||||
Pointer.fromAddress(wmaddr),
|
Pointer.fromAddress(wmaddr), Pointer.fromAddress(waddr), true);
|
||||||
Pointer.fromAddress(waddr),
|
|
||||||
true
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
openedWalletsByPath.remove("$currentWalletDirPath/$name");
|
openedWalletsByPath.remove("$currentWalletDirPath/$name");
|
||||||
print("wallet closed");
|
print("wallet closed");
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
// -- rename the waller folder --
|
// -- rename the waller folder --
|
||||||
final currentWalletDir = Directory(await pathForWalletDir(name: name, type: type));
|
final currentWalletDir =
|
||||||
final newWalletDirPath = await pathForWalletDir(name: newWalletName, type: type);
|
Directory(await pathForWalletDir(name: name, type: type));
|
||||||
|
final newWalletDirPath =
|
||||||
|
await pathForWalletDir(name: newWalletName, type: type);
|
||||||
await currentWalletDir.rename(newWalletDirPath);
|
await currentWalletDir.rename(newWalletDirPath);
|
||||||
|
|
||||||
// -- use new waller folder to rename files with old names still --
|
// -- use new waller folder to rename files with old names still --
|
||||||
|
@ -368,7 +392,8 @@ abstract class WowneroWalletBase
|
||||||
final currentKeysFile = File('$renamedWalletPath.keys');
|
final currentKeysFile = File('$renamedWalletPath.keys');
|
||||||
final currentAddressListFile = File('$renamedWalletPath.address.txt');
|
final currentAddressListFile = File('$renamedWalletPath.address.txt');
|
||||||
|
|
||||||
final newWalletPath = await pathForWallet(name: newWalletName, type: type);
|
final newWalletPath =
|
||||||
|
await pathForWallet(name: newWalletName, type: type);
|
||||||
|
|
||||||
if (currentCacheFile.existsSync()) {
|
if (currentCacheFile.existsSync()) {
|
||||||
await currentCacheFile.rename(newWalletPath);
|
await currentCacheFile.rename(newWalletPath);
|
||||||
|
@ -388,7 +413,8 @@ abstract class WowneroWalletBase
|
||||||
final currentKeysFile = File('$currentWalletPath.keys');
|
final currentKeysFile = File('$currentWalletPath.keys');
|
||||||
final currentAddressListFile = File('$currentWalletPath.address.txt');
|
final currentAddressListFile = File('$currentWalletPath.address.txt');
|
||||||
|
|
||||||
final newWalletPath = await pathForWallet(name: newWalletName, type: type);
|
final newWalletPath =
|
||||||
|
await pathForWallet(name: newWalletName, type: type);
|
||||||
|
|
||||||
// Copies current wallet files into new wallet name's dir and files
|
// Copies current wallet files into new wallet name's dir and files
|
||||||
if (currentCacheFile.existsSync()) {
|
if (currentCacheFile.existsSync()) {
|
||||||
|
@ -407,7 +433,8 @@ abstract class WowneroWalletBase
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> changePassword(String password) async => wownero_wallet.setPasswordSync(password);
|
Future<void> changePassword(String password) async =>
|
||||||
|
wownero_wallet.setPasswordSync(password);
|
||||||
|
|
||||||
Future<int> getNodeHeight() async => wownero_wallet.getNodeHeight();
|
Future<int> getNodeHeight() async => wownero_wallet.getNodeHeight();
|
||||||
|
|
||||||
|
@ -452,7 +479,8 @@ abstract class WowneroWalletBase
|
||||||
wownero.CoinsInfo_unlocked(coin),
|
wownero.CoinsInfo_unlocked(coin),
|
||||||
);
|
);
|
||||||
if (unspent.hash.isNotEmpty) {
|
if (unspent.hash.isNotEmpty) {
|
||||||
unspent.isChange = transaction_history.getTransaction(unspent.hash) == 1;
|
unspent.isChange =
|
||||||
|
transaction_history.getTransaction(unspent.hash) == 1;
|
||||||
}
|
}
|
||||||
unspentCoins.add(unspent);
|
unspentCoins.add(unspent);
|
||||||
}
|
}
|
||||||
|
@ -514,13 +542,15 @@ abstract class WowneroWalletBase
|
||||||
Future<void> _refreshUnspentCoinsInfo() async {
|
Future<void> _refreshUnspentCoinsInfo() async {
|
||||||
try {
|
try {
|
||||||
final List<dynamic> keys = <dynamic>[];
|
final List<dynamic> keys = <dynamic>[];
|
||||||
final currentWalletUnspentCoins = unspentCoinsInfo.values.where((element) =>
|
final currentWalletUnspentCoins = unspentCoinsInfo.values.where(
|
||||||
element.walletId.contains(id) && element.accountIndex == walletAddresses.account!.id);
|
(element) =>
|
||||||
|
element.walletId.contains(id) &&
|
||||||
|
element.accountIndex == walletAddresses.account!.id);
|
||||||
|
|
||||||
if (currentWalletUnspentCoins.isNotEmpty) {
|
if (currentWalletUnspentCoins.isNotEmpty) {
|
||||||
currentWalletUnspentCoins.forEach((element) {
|
currentWalletUnspentCoins.forEach((element) {
|
||||||
final existUnspentCoins =
|
final existUnspentCoins = unspentCoins
|
||||||
unspentCoins.where((coin) => element.keyImage!.contains(coin.keyImage!));
|
.where((coin) => element.keyImage!.contains(coin.keyImage!));
|
||||||
|
|
||||||
if (existUnspentCoins.isEmpty) {
|
if (existUnspentCoins.isEmpty) {
|
||||||
keys.add(element.key);
|
keys.add(element.key);
|
||||||
|
@ -537,14 +567,17 @@ abstract class WowneroWalletBase
|
||||||
}
|
}
|
||||||
|
|
||||||
String getTransactionAddress(int accountIndex, int addressIndex) =>
|
String getTransactionAddress(int accountIndex, int addressIndex) =>
|
||||||
wownero_wallet.getAddress(accountIndex: accountIndex, addressIndex: addressIndex);
|
wownero_wallet.getAddress(
|
||||||
|
accountIndex: accountIndex, addressIndex: addressIndex);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<Map<String, WowneroTransactionInfo>> fetchTransactions() async {
|
Future<Map<String, WowneroTransactionInfo>> fetchTransactions() async {
|
||||||
transaction_history.refreshTransactions();
|
transaction_history.refreshTransactions();
|
||||||
return _getAllTransactionsOfAccount(walletAddresses.account?.id)
|
return _getAllTransactionsOfAccount(walletAddresses.account?.id)
|
||||||
.fold<Map<String, WowneroTransactionInfo>>(<String, WowneroTransactionInfo>{},
|
.fold<Map<String, WowneroTransactionInfo>>(
|
||||||
(Map<String, WowneroTransactionInfo> acc, WowneroTransactionInfo tx) {
|
<String, WowneroTransactionInfo>{},
|
||||||
|
(Map<String, WowneroTransactionInfo> acc,
|
||||||
|
WowneroTransactionInfo tx) {
|
||||||
acc[tx.id] = tx;
|
acc[tx.id] = tx;
|
||||||
return acc;
|
return acc;
|
||||||
});
|
});
|
||||||
|
@ -571,28 +604,32 @@ abstract class WowneroWalletBase
|
||||||
String getSubaddressLabel(int accountIndex, int addressIndex) =>
|
String getSubaddressLabel(int accountIndex, int addressIndex) =>
|
||||||
wownero_wallet.getSubaddressLabel(accountIndex, addressIndex);
|
wownero_wallet.getSubaddressLabel(accountIndex, addressIndex);
|
||||||
|
|
||||||
List<WowneroTransactionInfo> _getAllTransactionsOfAccount(int? accountIndex) => transaction_history
|
List<WowneroTransactionInfo> _getAllTransactionsOfAccount(
|
||||||
.getAllTransactions()
|
int? accountIndex) =>
|
||||||
.map((row) => WowneroTransactionInfo(
|
transaction_history
|
||||||
row.hash,
|
.getAllTransactions()
|
||||||
row.blockheight,
|
.map(
|
||||||
row.isSpend ? TransactionDirection.outgoing : TransactionDirection.incoming,
|
(row) => WowneroTransactionInfo(
|
||||||
row.timeStamp,
|
row.hash,
|
||||||
row.isPending,
|
row.blockheight,
|
||||||
row.amount,
|
row.isSpend
|
||||||
row.accountIndex,
|
? TransactionDirection.outgoing
|
||||||
0,
|
: TransactionDirection.incoming,
|
||||||
row.fee,
|
row.timeStamp,
|
||||||
row.confirmations,
|
row.isPending,
|
||||||
|
row.amount,
|
||||||
)..additionalInfo = <String, dynamic>{
|
row.accountIndex,
|
||||||
'key': row.key,
|
0,
|
||||||
'accountIndex': row.accountIndex,
|
row.fee,
|
||||||
'addressIndex': row.addressIndex
|
row.confirmations,
|
||||||
},
|
)..additionalInfo = <String, dynamic>{
|
||||||
)
|
'key': row.key,
|
||||||
.where((element) => element.accountIndex == (accountIndex ?? 0))
|
'accountIndex': row.accountIndex,
|
||||||
.toList();
|
'addressIndex': row.addressIndex
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.where((element) => element.accountIndex == (accountIndex ?? 0))
|
||||||
|
.toList();
|
||||||
|
|
||||||
void _setListeners() {
|
void _setListeners() {
|
||||||
_listener?.stop();
|
_listener?.stop();
|
||||||
|
@ -630,7 +667,8 @@ abstract class WowneroWalletBase
|
||||||
}
|
}
|
||||||
|
|
||||||
int _getHeightDistance(DateTime date) {
|
int _getHeightDistance(DateTime date) {
|
||||||
final distance = DateTime.now().millisecondsSinceEpoch - date.millisecondsSinceEpoch;
|
final distance =
|
||||||
|
DateTime.now().millisecondsSinceEpoch - date.millisecondsSinceEpoch;
|
||||||
final daysTmp = (distance / 86400).round();
|
final daysTmp = (distance / 86400).round();
|
||||||
final days = daysTmp < 1 ? 1 : daysTmp;
|
final days = daysTmp < 1 ? 1 : daysTmp;
|
||||||
|
|
||||||
|
@ -658,22 +696,27 @@ abstract class WowneroWalletBase
|
||||||
balance[currency]!.unlockedBalance != unlockedBalance ||
|
balance[currency]!.unlockedBalance != unlockedBalance ||
|
||||||
balance[currency]!.frozenBalance != frozenBalance) {
|
balance[currency]!.frozenBalance != frozenBalance) {
|
||||||
balance[currency] = WowneroBalance(
|
balance[currency] = WowneroBalance(
|
||||||
fullBalance: fullBalance, unlockedBalance: unlockedBalance, frozenBalance: frozenBalance);
|
fullBalance: fullBalance,
|
||||||
|
unlockedBalance: unlockedBalance,
|
||||||
|
frozenBalance: frozenBalance);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _askForUpdateTransactionHistory() async => await updateTransactions();
|
Future<void> _askForUpdateTransactionHistory() async =>
|
||||||
|
await updateTransactions();
|
||||||
|
|
||||||
int _getFullBalance() => wownero_wallet.getFullBalance(accountIndex: walletAddresses.account!.id);
|
int _getFullBalance() =>
|
||||||
|
wownero_wallet.getFullBalance(accountIndex: walletAddresses.account!.id);
|
||||||
|
|
||||||
int _getUnlockedBalance() =>
|
int _getUnlockedBalance() => wownero_wallet.getUnlockedBalance(
|
||||||
wownero_wallet.getUnlockedBalance(accountIndex: walletAddresses.account!.id);
|
accountIndex: walletAddresses.account!.id);
|
||||||
|
|
||||||
int _getFrozenBalance() {
|
int _getFrozenBalance() {
|
||||||
var frozenBalance = 0;
|
var frozenBalance = 0;
|
||||||
|
|
||||||
for (var coin in unspentCoinsInfo.values.where((element) =>
|
for (var coin in unspentCoinsInfo.values.where((element) =>
|
||||||
element.walletId == id && element.accountIndex == walletAddresses.account!.id)) {
|
element.walletId == id &&
|
||||||
|
element.accountIndex == walletAddresses.account!.id)) {
|
||||||
if (coin.isFrozen) frozenBalance += coin.value;
|
if (coin.isFrozen) frozenBalance += coin.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,8 @@ import 'package:cw_core/transaction_direction.dart';
|
||||||
import 'package:cw_core/transaction_info.dart';
|
import 'package:cw_core/transaction_info.dart';
|
||||||
import 'package:cw_core/wallet_base.dart';
|
import 'package:cw_core/wallet_base.dart';
|
||||||
import 'package:cw_core/wallet_type.dart';
|
import 'package:cw_core/wallet_type.dart';
|
||||||
|
import 'package:cw_monero/monero_wallet.dart';
|
||||||
|
import 'package:cw_wownero/wownero_wallet.dart';
|
||||||
import 'package:mobx/mobx.dart';
|
import 'package:mobx/mobx.dart';
|
||||||
import 'package:polyseed/polyseed.dart';
|
import 'package:polyseed/polyseed.dart';
|
||||||
|
|
||||||
|
@ -76,13 +78,13 @@ abstract class WalletKeysViewModelBase with Store {
|
||||||
StandartListItem(title: S.current.wallet_seed, value: _appStore.wallet!.seed!),
|
StandartListItem(title: S.current.wallet_seed, value: _appStore.wallet!.seed!),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if (_appStore.wallet?.seed != null && Polyseed.isValidSeed(_appStore.wallet!.seed!)) {
|
if (_appStore.wallet?.seed != null &&
|
||||||
|
Polyseed.isValidSeed(_appStore.wallet!.seed!)) {
|
||||||
final lang = PolyseedLang.getByPhrase(_appStore.wallet!.seed!);
|
final lang = PolyseedLang.getByPhrase(_appStore.wallet!.seed!);
|
||||||
final legacyLang = _getLegacySeedLang(lang);
|
items.add(StandartListItem(
|
||||||
final legacySeed =
|
title: S.current.wallet_seed_legacy,
|
||||||
Polyseed.decode(_appStore.wallet!.seed!, lang, PolyseedCoin.POLYSEED_MONERO)
|
value: (_appStore.wallet as MoneroWalletBase)
|
||||||
.toLegacySeed(legacyLang);
|
.seedLegacy(lang.nameEnglish)));
|
||||||
items.add(StandartListItem(title: S.current.wallet_seed_legacy, value: legacySeed));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final restoreHeight = monero!.getRestoreHeight(_appStore.wallet!);
|
final restoreHeight = monero!.getRestoreHeight(_appStore.wallet!);
|
||||||
|
@ -123,13 +125,13 @@ abstract class WalletKeysViewModelBase with Store {
|
||||||
StandartListItem(title: S.current.wallet_seed, value: _appStore.wallet!.seed!),
|
StandartListItem(title: S.current.wallet_seed, value: _appStore.wallet!.seed!),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if (_appStore.wallet?.seed != null && Polyseed.isValidSeed(_appStore.wallet!.seed!)) {
|
if (_appStore.wallet?.seed != null &&
|
||||||
|
Polyseed.isValidSeed(_appStore.wallet!.seed!)) {
|
||||||
final lang = PolyseedLang.getByPhrase(_appStore.wallet!.seed!);
|
final lang = PolyseedLang.getByPhrase(_appStore.wallet!.seed!);
|
||||||
final legacyLang = _getLegacySeedLang(lang);
|
items.add(StandartListItem(
|
||||||
final legacySeed =
|
title: S.current.wallet_seed_legacy,
|
||||||
Polyseed.decode(_appStore.wallet!.seed!, lang, PolyseedCoin.POLYSEED_WOWNERO)
|
value: (_appStore.wallet as WowneroWalletBase)
|
||||||
.toLegacySeed(legacyLang);
|
.seedLegacy(lang.nameEnglish)));
|
||||||
items.add(StandartListItem(title: S.current.wallet_seed_legacy, value: legacySeed));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue