mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-12-23 20:19:25 +00:00
feat: Implement sweep all
This commit is contained in:
parent
956a9d4fbe
commit
9f4e6f1a3a
2 changed files with 18 additions and 14 deletions
|
@ -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)) {
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue