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

View file

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