feat: Implement sweep all

This commit is contained in:
Blazebrain 2023-07-06 17:11:50 +01:00
parent 956a9d4fbe
commit 9f4e6f1a3a
2 changed files with 18 additions and 14 deletions

View file

@ -172,15 +172,15 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance,
final _credentials = credentials as MoneroTransactionCreationCredentials;
final outputs = _credentials.outputs;
final hasMultiDestination = outputs.length > 1;
final unlockedBalance = monero_wallet.getUnlockedBalance(
accountIndex: walletAddresses.account!.id);
// final unlockedBalance = monero_wallet.getUnlockedBalance(
// accountIndex: walletAddresses.accountList.accounts.first.id);
PendingTransactionDescription pendingTransactionDescription;
// if (!(syncStatus is SyncedSyncStatus)) {
// print('Wallet is not synced');
// throw MoneroTransactionCreationException('The wallet is not synced.');
// }
if (!(syncStatus is SyncedSyncStatus)) {
print('Wallet is not synced');
throw MoneroTransactionCreationException('The wallet is not synced.');
}
if (hasMultiDestination) {
if (outputs.any(
@ -192,10 +192,10 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance,
final int totalAmount = outputs.fold(
0, (acc, value) => acc + (value.formattedCryptoAmount ?? 0));
if (unlockedBalance < totalAmount) {
throw MoneroTransactionCreationException(
'You do not have enough XMR to send this amount.');
}
// if (unlockedBalance < totalAmount) {
// throw MoneroTransactionCreationException(
// 'You do not have enough XMR to send this amount.');
// }
final moneroOutputs = outputs.map((output) {
final outputAddress =
@ -217,8 +217,8 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance,
output.isParsedAddress ? output.extractedAddress : output.address;
final amount =
output.sendAll ? null : output.cryptoAmount!.replaceAll(',', '.');
final formattedAmount =
output.sendAll ? null : output.formattedCryptoAmount;
// final formattedAmount =
// output.sendAll ? null : output.formattedCryptoAmount;
// if ((formattedAmount != null && unlockedBalance < formattedAmount) ||
// (formattedAmount == null && unlockedBalance <= 0)) {

View file

@ -71,7 +71,6 @@ abstract class WalletCreationVMBase with Store {
// if (restoreWallet != null &&
// restoreWallet.restoreMode == WalletRestoreMode.txids) {
//* Switch to the restoredWallet in order to activate the node connection
await _walletInfoSource.add(restoredWallet.walletInfo);
await connectToNode(restoredWallet);
@ -93,6 +92,7 @@ abstract class WalletCreationVMBase with Store {
// * Sweep all funds from restoredWallet to newWallet
await sweepAllFundsToNewWallet(
restoredWallet,
newWallet,
type,
newWalletAddress,
restoreWallet?.txId ?? '',
@ -164,6 +164,9 @@ abstract class WalletCreationVMBase with Store {
WalletBase<Balance, TransactionHistoryBase<TransactionInfo>,
TransactionInfo>
wallet,
WalletBase<Balance, TransactionHistoryBase<TransactionInfo>,
TransactionInfo>
newWallet,
WalletType type,
String newWalletAddress,
String paymentId) async {
@ -182,8 +185,9 @@ abstract class WalletCreationVMBase with Store {
//* Switch back to new wallet
_appStore.changeCurrentWallet(wallet);
await _walletInfoSource.deleteAt(0);
//* Add the new Wallet info to the walletInfoSource
await _walletInfoSource.add(wallet.walletInfo);
await _walletInfoSource.add(newWallet.walletInfo);
//* Approve authentication as successful
_appStore.authenticationStore.allowed();