Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CW-873 automatically export outputs #1885

Merged
merged 7 commits into from
Jan 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions cw_monero/lib/api/wallet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,10 @@ Future<bool> setupNodeSync(

if (status != 0) {
final error = monero.Wallet_errorString(wptr!);
printV("error: $error");
throw SetupWalletException(message: error);
if (error != "no tx keys found for this txid") {
printV("error: $error");
throw SetupWalletException(message: error);
}
}

if (kDebugMode) {
Expand Down
8 changes: 8 additions & 0 deletions cw_monero/lib/monero_wallet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,14 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance,
return str;
}

bool needExportOutputs(int amount) {
// viewOnlyBalance - balance that we can spend
// TODO(mrcyjanek): remove hasUnknownKeyImages when we cleanup coin control
return (monero.Wallet_viewOnlyBalance(wptr!,
accountIndex: walletAddresses.account!.id) < amount) ||
monero.Wallet_hasUnknownKeyImages(wptr!);
}

@override
Future<PendingTransaction> createTransaction(Object credentials) async {
final _credentials = credentials as MoneroTransactionCreationCredentials;
Expand Down
6 changes: 6 additions & 0 deletions lib/monero/cw_monero.dart
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,12 @@ class CWMonero extends Monero {
return moneroWallet.exportOutputsUR(all);
}

@override
bool needExportOutputs(Object wallet, int amount) {
final moneroWallet = wallet as MoneroWallet;
return moneroWallet.needExportOutputs(amount);
}

@override
void monerocCheck() {
checkIfMoneroCIsFine();
Expand Down
15 changes: 15 additions & 0 deletions lib/src/screens/send/send_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:cake_wallet/entities/contact_record.dart';
import 'package:cake_wallet/core/execution_state.dart';
import 'package:cake_wallet/entities/fiat_currency.dart';
import 'package:cake_wallet/entities/template.dart';
import 'package:cake_wallet/monero/monero.dart';
import 'package:cake_wallet/reactions/wallet_connect.dart';
import 'package:cake_wallet/generated/i18n.dart';
import 'package:cake_wallet/routes.dart';
Expand Down Expand Up @@ -412,6 +413,20 @@ class SendPage extends BasePage {
}
}

if (sendViewModel.wallet.type == WalletType.monero) {
int amount = 0;
for (var item in sendViewModel.outputs) {
amount += item.formattedCryptoAmount;
}
if (monero!.needExportOutputs(sendViewModel.wallet, amount)) {
await Navigator.of(context).pushNamed(Routes.urqrAnimatedPage, arguments: 'export-outputs');
await Future.delayed(Duration(seconds: 1)); // wait for monero to refresh the state
}
if (monero!.needExportOutputs(sendViewModel.wallet, amount)) {
return;
}
}

final check = sendViewModel.shouldDisplayTotp();
authService.authenticateAction(
context,
Expand Down
2 changes: 2 additions & 0 deletions tool/configure.dart
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,8 @@ abstract class Monero {

String exportOutputsUR(Object wallet, bool all);

bool needExportOutputs(Object wallet, int amount);

bool importKeyImagesUR(Object wallet, String ur);

WalletCredentials createMoneroRestoreWalletFromKeysCredentials({
Expand Down