mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-27 04:56:02 +00:00
Restore wallet WIP
This commit is contained in:
parent
6d7a384a98
commit
9ea0caea64
4 changed files with 173 additions and 133 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -8,6 +8,7 @@
|
||||||
.buildlog/
|
.buildlog/
|
||||||
.history
|
.history
|
||||||
.svn/
|
.svn/
|
||||||
|
.fvm/
|
||||||
|
|
||||||
# IntelliJ related
|
# IntelliJ related
|
||||||
*.iml
|
*.iml
|
||||||
|
|
|
@ -28,7 +28,8 @@ final transactionCreateNative = moneroApi
|
||||||
.asFunction<TransactionCreate>();
|
.asFunction<TransactionCreate>();
|
||||||
|
|
||||||
final transactionCreateMultDestNative = moneroApi
|
final transactionCreateMultDestNative = moneroApi
|
||||||
.lookup<NativeFunction<transaction_create_mult_dest>>('transaction_create_mult_dest')
|
.lookup<NativeFunction<transaction_create_mult_dest>>(
|
||||||
|
'transaction_create_mult_dest')
|
||||||
.asFunction<TransactionCreateMultDest>();
|
.asFunction<TransactionCreateMultDest>();
|
||||||
|
|
||||||
final transactionCommitNative = moneroApi
|
final transactionCommitNative = moneroApi
|
||||||
|
@ -97,6 +98,7 @@ PendingTransactionDescription createTransactionSync(
|
||||||
if (!created) {
|
if (!created) {
|
||||||
final message = errorMessagePointer.ref.getValue();
|
final message = errorMessagePointer.ref.getValue();
|
||||||
calloc.free(errorMessagePointer);
|
calloc.free(errorMessagePointer);
|
||||||
|
print('Error message from creating transaction call $message');
|
||||||
throw CreationTransactionException(message: message);
|
throw CreationTransactionException(message: message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,15 +113,15 @@ PendingTransactionDescription createTransactionSync(
|
||||||
|
|
||||||
PendingTransactionDescription createTransactionMultDestSync(
|
PendingTransactionDescription createTransactionMultDestSync(
|
||||||
{required List<MoneroOutput> outputs,
|
{required List<MoneroOutput> outputs,
|
||||||
required String paymentId,
|
required String paymentId,
|
||||||
required int priorityRaw,
|
required int priorityRaw,
|
||||||
int accountIndex = 0}) {
|
int accountIndex = 0}) {
|
||||||
final int size = outputs.length;
|
final int size = outputs.length;
|
||||||
final List<Pointer<Utf8>> addressesPointers = outputs.map((output) =>
|
final List<Pointer<Utf8>> addressesPointers =
|
||||||
output.address.toNativeUtf8()).toList();
|
outputs.map((output) => output.address.toNativeUtf8()).toList();
|
||||||
final Pointer<Pointer<Utf8>> addressesPointerPointer = calloc(size);
|
final Pointer<Pointer<Utf8>> addressesPointerPointer = calloc(size);
|
||||||
final List<Pointer<Utf8>> amountsPointers = outputs.map((output) =>
|
final List<Pointer<Utf8>> amountsPointers =
|
||||||
output.amount.toNativeUtf8()).toList();
|
outputs.map((output) => output.amount.toNativeUtf8()).toList();
|
||||||
final Pointer<Pointer<Utf8>> amountsPointerPointer = calloc(size);
|
final Pointer<Pointer<Utf8>> amountsPointerPointer = calloc(size);
|
||||||
|
|
||||||
for (int i = 0; i < size; i++) {
|
for (int i = 0; i < size; i++) {
|
||||||
|
@ -131,14 +133,14 @@ PendingTransactionDescription createTransactionMultDestSync(
|
||||||
final errorMessagePointer = calloc<Utf8Box>();
|
final errorMessagePointer = calloc<Utf8Box>();
|
||||||
final pendingTransactionRawPointer = calloc<PendingTransactionRaw>();
|
final pendingTransactionRawPointer = calloc<PendingTransactionRaw>();
|
||||||
final created = transactionCreateMultDestNative(
|
final created = transactionCreateMultDestNative(
|
||||||
addressesPointerPointer,
|
addressesPointerPointer,
|
||||||
paymentIdPointer,
|
paymentIdPointer,
|
||||||
amountsPointerPointer,
|
amountsPointerPointer,
|
||||||
size,
|
size,
|
||||||
priorityRaw,
|
priorityRaw,
|
||||||
accountIndex,
|
accountIndex,
|
||||||
errorMessagePointer,
|
errorMessagePointer,
|
||||||
pendingTransactionRawPointer) !=
|
pendingTransactionRawPointer) !=
|
||||||
0;
|
0;
|
||||||
|
|
||||||
calloc.free(addressesPointerPointer);
|
calloc.free(addressesPointerPointer);
|
||||||
|
@ -164,10 +166,13 @@ PendingTransactionDescription createTransactionMultDestSync(
|
||||||
pointerAddress: pendingTransactionRawPointer.address);
|
pointerAddress: pendingTransactionRawPointer.address);
|
||||||
}
|
}
|
||||||
|
|
||||||
void commitTransactionFromPointerAddress({required int address}) => commitTransaction(
|
void commitTransactionFromPointerAddress({required int address}) =>
|
||||||
transactionPointer: Pointer<PendingTransactionRaw>.fromAddress(address));
|
commitTransaction(
|
||||||
|
transactionPointer:
|
||||||
|
Pointer<PendingTransactionRaw>.fromAddress(address));
|
||||||
|
|
||||||
void commitTransaction({required Pointer<PendingTransactionRaw> transactionPointer}) {
|
void commitTransaction(
|
||||||
|
{required Pointer<PendingTransactionRaw> transactionPointer}) {
|
||||||
final errorMessagePointer = calloc<Utf8Box>();
|
final errorMessagePointer = calloc<Utf8Box>();
|
||||||
final isCommited =
|
final isCommited =
|
||||||
transactionCommitNative(transactionPointer, errorMessagePointer) != 0;
|
transactionCommitNative(transactionPointer, errorMessagePointer) != 0;
|
||||||
|
@ -222,10 +227,10 @@ Future<PendingTransactionDescription> createTransaction(
|
||||||
});
|
});
|
||||||
|
|
||||||
Future<PendingTransactionDescription> createTransactionMultDest(
|
Future<PendingTransactionDescription> createTransactionMultDest(
|
||||||
{required List<MoneroOutput> outputs,
|
{required List<MoneroOutput> outputs,
|
||||||
required int priorityRaw,
|
required int priorityRaw,
|
||||||
String paymentId = '',
|
String paymentId = '',
|
||||||
int accountIndex = 0}) =>
|
int accountIndex = 0}) =>
|
||||||
compute(_createTransactionMultDestSync, {
|
compute(_createTransactionMultDestSync, {
|
||||||
'outputs': outputs,
|
'outputs': outputs,
|
||||||
'paymentId': paymentId,
|
'paymentId': paymentId,
|
||||||
|
|
|
@ -38,29 +38,29 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance,
|
||||||
MoneroTransactionHistory, MoneroTransactionInfo> with Store {
|
MoneroTransactionHistory, MoneroTransactionInfo> with Store {
|
||||||
MoneroWalletBase({required WalletInfo walletInfo})
|
MoneroWalletBase({required WalletInfo walletInfo})
|
||||||
: balance = ObservableMap<CryptoCurrency, MoneroBalance>.of({
|
: balance = ObservableMap<CryptoCurrency, MoneroBalance>.of({
|
||||||
CryptoCurrency.xmr: MoneroBalance(
|
CryptoCurrency.xmr: MoneroBalance(
|
||||||
fullBalance: monero_wallet.getFullBalance(accountIndex: 0),
|
fullBalance: monero_wallet.getFullBalance(accountIndex: 0),
|
||||||
unlockedBalance: monero_wallet.getFullBalance(accountIndex: 0))
|
unlockedBalance: monero_wallet.getFullBalance(accountIndex: 0))
|
||||||
}),
|
}),
|
||||||
_isTransactionUpdating = false,
|
_isTransactionUpdating = false,
|
||||||
_hasSyncAfterStartup = false,
|
_hasSyncAfterStartup = false,
|
||||||
walletAddresses = MoneroWalletAddresses(walletInfo),
|
walletAddresses = MoneroWalletAddresses(walletInfo),
|
||||||
syncStatus = NotConnectedSyncStatus(),
|
syncStatus = NotConnectedSyncStatus(),
|
||||||
super(walletInfo) {
|
super(walletInfo) {
|
||||||
transactionHistory = MoneroTransactionHistory();
|
transactionHistory = MoneroTransactionHistory();
|
||||||
_onAccountChangeReaction = reaction((_) => walletAddresses.account,
|
_onAccountChangeReaction =
|
||||||
(Account? account) {
|
reaction((_) => walletAddresses.account, (Account? account) {
|
||||||
if (account == null) {
|
if (account == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
balance = ObservableMap<CryptoCurrency, MoneroBalance>.of(
|
balance = ObservableMap<CryptoCurrency, MoneroBalance>.of(<CryptoCurrency,
|
||||||
<CryptoCurrency, MoneroBalance>{
|
MoneroBalance>{
|
||||||
currency: MoneroBalance(
|
currency: MoneroBalance(
|
||||||
fullBalance: monero_wallet.getFullBalance(accountIndex: account.id),
|
fullBalance: monero_wallet.getFullBalance(accountIndex: account.id),
|
||||||
unlockedBalance:
|
unlockedBalance:
|
||||||
monero_wallet.getUnlockedBalance(accountIndex: account.id))
|
monero_wallet.getUnlockedBalance(accountIndex: account.id))
|
||||||
});
|
});
|
||||||
walletAddresses.updateSubaddressList(accountIndex: account.id);
|
walletAddresses.updateSubaddressList(accountIndex: account.id);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -96,12 +96,14 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance,
|
||||||
|
|
||||||
Future<void> init() async {
|
Future<void> init() async {
|
||||||
await walletAddresses.init();
|
await walletAddresses.init();
|
||||||
balance = ObservableMap<CryptoCurrency, MoneroBalance>.of(
|
balance = ObservableMap<CryptoCurrency, MoneroBalance>.of(<CryptoCurrency,
|
||||||
<CryptoCurrency, MoneroBalance>{
|
MoneroBalance>{
|
||||||
currency: MoneroBalance(
|
currency: MoneroBalance(
|
||||||
fullBalance: monero_wallet.getFullBalance(accountIndex: walletAddresses.account!.id),
|
fullBalance: monero_wallet.getFullBalance(
|
||||||
unlockedBalance: monero_wallet.getUnlockedBalance(accountIndex: walletAddresses.account!.id))
|
accountIndex: walletAddresses.account!.id),
|
||||||
});
|
unlockedBalance: monero_wallet.getUnlockedBalance(
|
||||||
|
accountIndex: walletAddresses.account!.id))
|
||||||
|
});
|
||||||
_setListeners();
|
_setListeners();
|
||||||
await updateTransactions();
|
await updateTransactions();
|
||||||
|
|
||||||
|
@ -115,9 +117,9 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance,
|
||||||
}
|
}
|
||||||
|
|
||||||
_autoSaveTimer = Timer.periodic(
|
_autoSaveTimer = Timer.periodic(
|
||||||
Duration(seconds: _autoSaveInterval),
|
Duration(seconds: _autoSaveInterval), (_) async => await save());
|
||||||
(_) async => await save());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void>? updateBalance() => null;
|
Future<void>? updateBalance() => null;
|
||||||
|
|
||||||
|
@ -170,69 +172,68 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance,
|
||||||
final _credentials = credentials as MoneroTransactionCreationCredentials;
|
final _credentials = credentials as MoneroTransactionCreationCredentials;
|
||||||
final outputs = _credentials.outputs;
|
final outputs = _credentials.outputs;
|
||||||
final hasMultiDestination = outputs.length > 1;
|
final hasMultiDestination = outputs.length > 1;
|
||||||
final unlockedBalance =
|
final unlockedBalance = monero_wallet.getUnlockedBalance(
|
||||||
monero_wallet.getUnlockedBalance(accountIndex: walletAddresses.account!.id);
|
accountIndex: walletAddresses.account!.id);
|
||||||
|
|
||||||
PendingTransactionDescription pendingTransactionDescription;
|
PendingTransactionDescription pendingTransactionDescription;
|
||||||
|
|
||||||
// if (!(syncStatus is SyncedSyncStatus)) {
|
// if (!(syncStatus is SyncedSyncStatus)) {
|
||||||
|
// print('Wallet is not synced');
|
||||||
// throw MoneroTransactionCreationException('The wallet is not synced.');
|
// throw MoneroTransactionCreationException('The wallet is not synced.');
|
||||||
// }
|
// }
|
||||||
|
|
||||||
if (hasMultiDestination) {
|
if (hasMultiDestination) {
|
||||||
if (outputs.any((item) => item.sendAll
|
if (outputs.any(
|
||||||
|| (item.formattedCryptoAmount ?? 0) <= 0)) {
|
(item) => item.sendAll || (item.formattedCryptoAmount ?? 0) <= 0)) {
|
||||||
throw MoneroTransactionCreationException('You do not have enough XMR to send this amount.');
|
throw MoneroTransactionCreationException(
|
||||||
|
'You do not have enough XMR to send this amount.');
|
||||||
}
|
}
|
||||||
|
|
||||||
final int totalAmount = outputs.fold(0, (acc, value) =>
|
final int totalAmount = outputs.fold(
|
||||||
acc + (value.formattedCryptoAmount ?? 0));
|
0, (acc, value) => acc + (value.formattedCryptoAmount ?? 0));
|
||||||
|
|
||||||
if (unlockedBalance < totalAmount) {
|
if (unlockedBalance < totalAmount) {
|
||||||
throw MoneroTransactionCreationException('You do not have enough XMR to send this amount.');
|
throw MoneroTransactionCreationException(
|
||||||
|
'You do not have enough XMR to send this amount.');
|
||||||
}
|
}
|
||||||
|
|
||||||
final moneroOutputs = outputs.map((output) {
|
final moneroOutputs = outputs.map((output) {
|
||||||
final outputAddress = output.isParsedAddress
|
final outputAddress =
|
||||||
? output.extractedAddress
|
output.isParsedAddress ? output.extractedAddress : output.address;
|
||||||
: output.address;
|
|
||||||
|
|
||||||
return MoneroOutput(
|
return MoneroOutput(
|
||||||
address: outputAddress!,
|
address: outputAddress!,
|
||||||
amount: output.cryptoAmount!.replaceAll(',', '.'));
|
amount: output.cryptoAmount!.replaceAll(',', '.'));
|
||||||
}).toList();
|
}).toList();
|
||||||
|
|
||||||
pendingTransactionDescription =
|
pendingTransactionDescription =
|
||||||
await transaction_history.createTransactionMultDest(
|
await transaction_history.createTransactionMultDest(
|
||||||
outputs: moneroOutputs,
|
outputs: moneroOutputs,
|
||||||
priorityRaw: _credentials.priority.serialize(),
|
priorityRaw: _credentials.priority.serialize(),
|
||||||
accountIndex: walletAddresses.account!.id);
|
accountIndex: walletAddresses.account!.id);
|
||||||
} else {
|
} else {
|
||||||
final output = outputs.first;
|
final output = outputs.first;
|
||||||
final address = output.isParsedAddress
|
final address =
|
||||||
? output.extractedAddress
|
output.isParsedAddress ? output.extractedAddress : output.address;
|
||||||
: output.address;
|
final amount =
|
||||||
final amount = output.sendAll
|
output.sendAll ? null : output.cryptoAmount!.replaceAll(',', '.');
|
||||||
? null
|
final formattedAmount =
|
||||||
: output.cryptoAmount!.replaceAll(',', '.');
|
output.sendAll ? null : output.formattedCryptoAmount;
|
||||||
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)) {
|
||||||
final formattedBalance = moneroAmountToString(amount: unlockedBalance);
|
// final formattedBalance = moneroAmountToString(amount: unlockedBalance);
|
||||||
|
|
||||||
throw MoneroTransactionCreationException(
|
// throw MoneroTransactionCreationException(
|
||||||
'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}.');
|
||||||
}
|
// }
|
||||||
|
|
||||||
pendingTransactionDescription =
|
pendingTransactionDescription =
|
||||||
await transaction_history.createTransaction(
|
await transaction_history.createTransaction(
|
||||||
address: address!,
|
address: address!,
|
||||||
amount: amount,
|
amount: amount,
|
||||||
priorityRaw: _credentials.priority.serialize(),
|
priorityRaw: _credentials.priority.serialize(),
|
||||||
accountIndex: walletAddresses.account!.id);
|
accountIndex: walletAddresses.account!.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
return PendingMoneroTransaction(pendingTransactionDescription);
|
return PendingMoneroTransaction(pendingTransactionDescription);
|
||||||
|
@ -297,8 +298,7 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance,
|
||||||
|
|
||||||
String getTransactionAddress(int accountIndex, int addressIndex) =>
|
String getTransactionAddress(int accountIndex, int addressIndex) =>
|
||||||
monero_wallet.getAddress(
|
monero_wallet.getAddress(
|
||||||
accountIndex: accountIndex,
|
accountIndex: accountIndex, addressIndex: addressIndex);
|
||||||
addressIndex: addressIndex);
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<Map<String, MoneroTransactionInfo>> fetchTransactions() async {
|
Future<Map<String, MoneroTransactionInfo>> fetchTransactions() async {
|
||||||
|
@ -394,8 +394,8 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance,
|
||||||
int _getFullBalance() =>
|
int _getFullBalance() =>
|
||||||
monero_wallet.getFullBalance(accountIndex: walletAddresses.account!.id);
|
monero_wallet.getFullBalance(accountIndex: walletAddresses.account!.id);
|
||||||
|
|
||||||
int _getUnlockedBalance() =>
|
int _getUnlockedBalance() => monero_wallet.getUnlockedBalance(
|
||||||
monero_wallet.getUnlockedBalance(accountIndex: walletAddresses.account!.id);
|
accountIndex: walletAddresses.account!.id);
|
||||||
|
|
||||||
void _onNewBlock(int height, int blocksLeft, double ptc) async {
|
void _onNewBlock(int height, int blocksLeft, double ptc) async {
|
||||||
try {
|
try {
|
||||||
|
@ -412,9 +412,9 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance,
|
||||||
syncStatus = SyncedSyncStatus();
|
syncStatus = SyncedSyncStatus();
|
||||||
|
|
||||||
if (!_hasSyncAfterStartup) {
|
if (!_hasSyncAfterStartup) {
|
||||||
_hasSyncAfterStartup = true;
|
_hasSyncAfterStartup = true;
|
||||||
await save();
|
await save();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (walletInfo.isRecovery) {
|
if (walletInfo.isRecovery) {
|
||||||
await setAsRecovered();
|
await setAsRecovered();
|
||||||
|
|
|
@ -2,6 +2,7 @@ import 'dart:async';
|
||||||
|
|
||||||
import 'package:cake_wallet/core/wallet_creation_service.dart';
|
import 'package:cake_wallet/core/wallet_creation_service.dart';
|
||||||
import 'package:cake_wallet/store/dashboard/fiat_conversion_store.dart';
|
import 'package:cake_wallet/store/dashboard/fiat_conversion_store.dart';
|
||||||
|
import 'package:cake_wallet/view_model/restore/restore_mode.dart';
|
||||||
import 'package:cake_wallet/view_model/restore/restore_wallet.dart';
|
import 'package:cake_wallet/view_model/restore/restore_wallet.dart';
|
||||||
import 'package:cake_wallet/view_model/send/output.dart';
|
import 'package:cake_wallet/view_model/send/output.dart';
|
||||||
import 'package:cw_core/balance.dart';
|
import 'package:cw_core/balance.dart';
|
||||||
|
@ -27,7 +28,8 @@ part 'wallet_creation_vm.g.dart';
|
||||||
class WalletCreationVM = WalletCreationVMBase with _$WalletCreationVM;
|
class WalletCreationVM = WalletCreationVMBase with _$WalletCreationVM;
|
||||||
|
|
||||||
abstract class WalletCreationVMBase with Store {
|
abstract class WalletCreationVMBase with Store {
|
||||||
WalletCreationVMBase(this._appStore, this._walletInfoSource, this.walletCreationService, this._fiatConversationStore,
|
WalletCreationVMBase(this._appStore, this._walletInfoSource,
|
||||||
|
this.walletCreationService, this._fiatConversationStore,
|
||||||
{required this.type, required this.isRecovery})
|
{required this.type, required this.isRecovery})
|
||||||
: state = InitialExecutionState(),
|
: state = InitialExecutionState(),
|
||||||
name = '';
|
name = '';
|
||||||
|
@ -46,9 +48,9 @@ abstract class WalletCreationVMBase with Store {
|
||||||
final WalletCreationService walletCreationService;
|
final WalletCreationService walletCreationService;
|
||||||
final Box<WalletInfo> _walletInfoSource;
|
final Box<WalletInfo> _walletInfoSource;
|
||||||
final AppStore _appStore;
|
final AppStore _appStore;
|
||||||
final FiatConversionStore _fiatConversationStore;
|
final FiatConversionStore _fiatConversationStore;
|
||||||
|
|
||||||
Completer<void> syncCompleter = Completer<void>();
|
Completer<void> syncCompleter = Completer<void>();
|
||||||
|
|
||||||
bool nameExists(String name) => walletCreationService.exists(name);
|
bool nameExists(String name) => walletCreationService.exists(name);
|
||||||
|
|
||||||
|
@ -58,13 +60,16 @@ abstract class WalletCreationVMBase with Store {
|
||||||
final type = restoreWallet?.type ?? this.type;
|
final type = restoreWallet?.type ?? this.type;
|
||||||
try {
|
try {
|
||||||
//! Create a restoredWallet from the scanned wallet parameters
|
//! Create a restoredWallet from the scanned wallet parameters
|
||||||
final restoredWallet =
|
final restoredWallet = await createNewWalletWithoutSwitching(
|
||||||
await createNewWalletWithoutSwitching(options: options, restoreWallet: restoreWallet);
|
options: options, restoreWallet: restoreWallet);
|
||||||
print('Restored Wallet Address ' + restoredWallet.walletAddresses.address);
|
print(
|
||||||
|
'Restored Wallet Address ' + restoredWallet.walletAddresses.address);
|
||||||
|
|
||||||
//TODO Get transactions details to verify 10 confirmations
|
//TODO Get transactions details to verify 10 confirmations
|
||||||
|
|
||||||
//! Create the newWallet that will received the funds
|
// if (restoreWallet != null &&
|
||||||
|
// restoreWallet.restoreMode == WalletRestoreMode.txids) {
|
||||||
|
//* Create the newWallet that will received the funds
|
||||||
final newWallet = await createNewWalletWithoutSwitching(
|
final newWallet = await createNewWalletWithoutSwitching(
|
||||||
options: options,
|
options: options,
|
||||||
regenerateName: true,
|
regenerateName: true,
|
||||||
|
@ -72,31 +77,36 @@ abstract class WalletCreationVMBase with Store {
|
||||||
final newWalletAddress = newWallet.walletAddresses.address;
|
final newWalletAddress = newWallet.walletAddresses.address;
|
||||||
print('New Wallet Address ' + newWalletAddress);
|
print('New Wallet Address ' + newWalletAddress);
|
||||||
|
|
||||||
//! Switch to the restoredWallet in order to activate the node connection
|
//* Switch to the restoredWallet in order to activate the node connection
|
||||||
_appStore.changeCurrentWallet(restoredWallet);
|
_appStore.changeCurrentWallet(restoredWallet);
|
||||||
|
|
||||||
await restoredWallet.startSync();
|
await restoredWallet.startSync();
|
||||||
|
|
||||||
//! Sweep all funds from restoredWallet to newWallet
|
|
||||||
await sweepAllFundsToNewWallet(restoredWallet, type, newWalletAddress, restoreWallet?.txId ?? '');
|
|
||||||
|
|
||||||
//! Switch back to new wallet
|
//* Sweep all funds from restoredWallet to newWallet
|
||||||
_appStore.changeCurrentWallet(newWallet);
|
await sweepAllFundsToNewWallet(
|
||||||
|
restoredWallet,
|
||||||
//! Add the new Wallet info to the walletInfoSource
|
type,
|
||||||
await _walletInfoSource.add(newWallet.walletInfo);
|
newWalletAddress,
|
||||||
|
restoreWallet?.txId ?? '',
|
||||||
//! Approve authentication as successful
|
);
|
||||||
_appStore.authenticationStore.allowed();
|
// } else {
|
||||||
state = ExecutedSuccessfullyState();
|
// await _walletInfoSource.add(restoredWallet.walletInfo);
|
||||||
|
// _appStore.changeCurrentWallet(restoredWallet);
|
||||||
|
// _appStore.authenticationStore.allowed();
|
||||||
|
// state = ExecutedSuccessfullyState();
|
||||||
|
// }
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
print('Errorrrrr');
|
||||||
state = FailureState(e.toString());
|
state = FailureState(e.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<WalletBase<Balance, TransactionHistoryBase<TransactionInfo>, TransactionInfo>>
|
Future<
|
||||||
createNewWalletWithoutSwitching(
|
WalletBase<Balance, TransactionHistoryBase<TransactionInfo>,
|
||||||
{dynamic options, RestoredWallet? restoreWallet, bool regenerateName = false}) async {
|
TransactionInfo>> createNewWalletWithoutSwitching(
|
||||||
|
{dynamic options,
|
||||||
|
RestoredWallet? restoreWallet,
|
||||||
|
bool regenerateName = false}) async {
|
||||||
state = IsExecutingState();
|
state = IsExecutingState();
|
||||||
if (name.isEmpty) {
|
if (name.isEmpty) {
|
||||||
name = await generateName();
|
name = await generateName();
|
||||||
|
@ -122,35 +132,55 @@ abstract class WalletCreationVMBase with Store {
|
||||||
path: path,
|
path: path,
|
||||||
dirPath: dirPath,
|
dirPath: dirPath,
|
||||||
address: '',
|
address: '',
|
||||||
showIntroCakePayCard:
|
showIntroCakePayCard: (!walletCreationService.typeExists(type)) &&
|
||||||
(!walletCreationService.typeExists(type)) && type != WalletType.haven);
|
type != WalletType.haven);
|
||||||
credentials.walletInfo = walletInfo;
|
credentials.walletInfo = walletInfo;
|
||||||
|
|
||||||
final wallet = restoreWallet != null
|
final wallet = restoreWallet != null
|
||||||
? await processFromRestoredWallet(credentials, restoreWallet)
|
? await processFromRestoredWallet(credentials, restoreWallet)
|
||||||
: await process(credentials);
|
: await process(credentials);
|
||||||
walletInfo.address = wallet.walletAddresses.address;
|
walletInfo.address = wallet.walletAddresses.address;
|
||||||
|
|
||||||
|
|
||||||
return wallet;
|
return wallet;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> sweepAllFundsToNewWallet(WalletBase<Balance, TransactionHistoryBase<TransactionInfo>, TransactionInfo> wallet,
|
Future<void> sweepAllFundsToNewWallet(
|
||||||
WalletType type, String newWalletAddress, String paymentId) async {
|
WalletBase<Balance, TransactionHistoryBase<TransactionInfo>,
|
||||||
final output = Output(wallet, _appStore.settingsStore, _fiatConversationStore, () => wallet.currency);
|
TransactionInfo>
|
||||||
output.address = newWalletAddress;
|
wallet,
|
||||||
output.sendAll = true;
|
WalletType type,
|
||||||
output.note = 'testing the sweep all function';
|
String newWalletAddress,
|
||||||
final credentials = _credentials(type, wallet.currency.title, output);
|
String paymentId) async {
|
||||||
print('About to enter create function');
|
final output = Output(wallet, _appStore.settingsStore,
|
||||||
await createTransaction(wallet, credentials);
|
_fiatConversationStore, () => wallet.currency);
|
||||||
// final currentNode = _appStore.settingsStore.getCurrentNode(type);
|
output.address = newWalletAddress;
|
||||||
|
output.sendAll = true;
|
||||||
|
output.note = 'testing the sweep all function';
|
||||||
|
final credentials = _credentials(type, wallet.currency.title, output);
|
||||||
|
print('About to enter create function');
|
||||||
|
try {
|
||||||
|
await createTransaction(wallet, credentials);
|
||||||
|
// final currentNode = _appStore.settingsStore.getCurrentNode(type);
|
||||||
// final result = await walletCreationService.sweepAllFunds(currentNode, newWalletAddress, paymentId);
|
// final result = await walletCreationService.sweepAllFunds(currentNode, newWalletAddress, paymentId);
|
||||||
|
|
||||||
|
//* Switch back to new wallet
|
||||||
|
_appStore.changeCurrentWallet(wallet);
|
||||||
|
|
||||||
|
//* Add the new Wallet info to the walletInfoSource
|
||||||
|
await _walletInfoSource.add(wallet.walletInfo);
|
||||||
|
|
||||||
|
//* Approve authentication as successful
|
||||||
|
_appStore.authenticationStore.allowed();
|
||||||
|
print('Successfully done inisde sweep all');
|
||||||
|
state = ExecutedSuccessfullyState();
|
||||||
|
} catch (e) {
|
||||||
|
state = FailureState(e.toString());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Object _credentials(
|
||||||
Object _credentials(WalletType type,String cryptoCurrencyTitle,Output output ) {
|
WalletType type, String cryptoCurrencyTitle, Output output) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case WalletType.bitcoin:
|
case WalletType.bitcoin:
|
||||||
final priority = _appStore.settingsStore.priority[type];
|
final priority = _appStore.settingsStore.priority[type];
|
||||||
|
@ -159,7 +189,8 @@ abstract class WalletCreationVMBase with Store {
|
||||||
throw Exception('Priority is null for wallet type: ${type}');
|
throw Exception('Priority is null for wallet type: ${type}');
|
||||||
}
|
}
|
||||||
|
|
||||||
return bitcoin!.createBitcoinTransactionCredentials([output], priority: priority);
|
return bitcoin!
|
||||||
|
.createBitcoinTransactionCredentials([output], priority: priority);
|
||||||
case WalletType.litecoin:
|
case WalletType.litecoin:
|
||||||
final priority = _appStore.settingsStore.priority[type];
|
final priority = _appStore.settingsStore.priority[type];
|
||||||
|
|
||||||
|
@ -167,7 +198,8 @@ abstract class WalletCreationVMBase with Store {
|
||||||
throw Exception('Priority is null for wallet type: ${type}');
|
throw Exception('Priority is null for wallet type: ${type}');
|
||||||
}
|
}
|
||||||
|
|
||||||
return bitcoin!.createBitcoinTransactionCredentials([output], priority: priority);
|
return bitcoin!
|
||||||
|
.createBitcoinTransactionCredentials([output], priority: priority);
|
||||||
case WalletType.monero:
|
case WalletType.monero:
|
||||||
final priority = _appStore.settingsStore.priority[type];
|
final priority = _appStore.settingsStore.priority[type];
|
||||||
|
|
||||||
|
@ -176,16 +208,18 @@ abstract class WalletCreationVMBase with Store {
|
||||||
}
|
}
|
||||||
|
|
||||||
return monero!.createMoneroTransactionCreationCredentials(
|
return monero!.createMoneroTransactionCreationCredentials(
|
||||||
outputs:[output], priority: priority);
|
outputs: [output], priority: priority);
|
||||||
case WalletType.haven:
|
case WalletType.haven:
|
||||||
final priority = _appStore.settingsStore.priority[type];
|
final priority = _appStore.settingsStore.priority[type];
|
||||||
|
|
||||||
if (priority == null) {
|
if (priority == null) {
|
||||||
throw Exception('Priority is null for wallet type: ${type}');
|
throw Exception('Priority is null for wallet type: ${type}');
|
||||||
}
|
}
|
||||||
|
|
||||||
return haven!.createHavenTransactionCreationCredentials(
|
return haven!.createHavenTransactionCreationCredentials(
|
||||||
outputs: [output], priority: priority, assetType: cryptoCurrencyTitle);
|
outputs: [output],
|
||||||
|
priority: priority,
|
||||||
|
assetType: cryptoCurrencyTitle);
|
||||||
default:
|
default:
|
||||||
throw Exception('Unexpected wallet type: ${type}');
|
throw Exception('Unexpected wallet type: ${type}');
|
||||||
}
|
}
|
||||||
|
@ -194,7 +228,7 @@ abstract class WalletCreationVMBase with Store {
|
||||||
@action
|
@action
|
||||||
Future<void> createTransaction(WalletBase wallet, Object credentials) async {
|
Future<void> createTransaction(WalletBase wallet, Object credentials) async {
|
||||||
try {
|
try {
|
||||||
print('in here');
|
print('in here');
|
||||||
state = IsExecutingState();
|
state = IsExecutingState();
|
||||||
print('about to enter wallet create transaction function');
|
print('about to enter wallet create transaction function');
|
||||||
pendingTransaction = await wallet.createTransaction(credentials);
|
pendingTransaction = await wallet.createTransaction(credentials);
|
||||||
|
@ -207,15 +241,15 @@ abstract class WalletCreationVMBase with Store {
|
||||||
WalletCredentials getCredentials(dynamic options) {
|
WalletCredentials getCredentials(dynamic options) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case WalletType.monero:
|
case WalletType.monero:
|
||||||
return monero!
|
return monero!.createMoneroNewWalletCredentials(
|
||||||
.createMoneroNewWalletCredentials(name: name, language: options as String? ?? '');
|
name: name, language: options as String? ?? '');
|
||||||
case WalletType.bitcoin:
|
case WalletType.bitcoin:
|
||||||
return bitcoin!.createBitcoinNewWalletCredentials(name: name);
|
return bitcoin!.createBitcoinNewWalletCredentials(name: name);
|
||||||
case WalletType.litecoin:
|
case WalletType.litecoin:
|
||||||
return bitcoin!.createBitcoinNewWalletCredentials(name: name);
|
return bitcoin!.createBitcoinNewWalletCredentials(name: name);
|
||||||
case WalletType.haven:
|
case WalletType.haven:
|
||||||
return haven!
|
return haven!.createHavenNewWalletCredentials(
|
||||||
.createHavenNewWalletCredentials(name: name, language: options as String? ?? '');
|
name: name, language: options as String? ?? '');
|
||||||
default:
|
default:
|
||||||
throw Exception('Unexpected type: ${type.toString()}');
|
throw Exception('Unexpected type: ${type.toString()}');
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue