Skip to content

Commit

Permalink
spending, urqr, wallet save()
Browse files Browse the repository at this point in the history
  • Loading branch information
MrCyjaneK committed Sep 20, 2024
1 parent 44aefed commit ed269e0
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 17 deletions.
1 change: 1 addition & 0 deletions android/app/src/main/jniLibs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
libmonero_libwallet2_api_c.so
42 changes: 37 additions & 5 deletions lib/coins/monero.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import 'package:cup_cake/coins/abstract.dart';
import 'package:cup_cake/utils/filesystem.dart';
import 'package:cup_cake/view_model/barcode_scanner_view_model.dart';
import 'package:cup_cake/view_model/unconfirmed_transaction_view_model.dart';
import 'package:cup_cake/view_model/urqr_view_model.dart';
import 'package:cup_cake/views/open_wallet.dart';
import 'package:cup_cake/views/unconfirmed_transaction.dart';
import 'package:cup_cake/views/urqr.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:monero/monero.dart' as monero;
Expand Down Expand Up @@ -224,7 +226,7 @@ class Monero implements Coin {
walletPath: walletPath,
walletPassword: walletPassword,
seed: seed!,
seedOffsetOrEncryption: seedOffsetOrEncryption!);
seedOffsetOrEncryption: seedOffsetOrEncryption ?? "");
// polyseed
// polyseed encrypted
// polyseed offset
Expand All @@ -235,7 +237,7 @@ class Monero implements Coin {
walletPath: walletPath,
walletPassword: walletPassword,
seed: seed!,
seedOffsetOrEncryption: seedOffsetOrEncryption!);
seedOffsetOrEncryption: seedOffsetOrEncryption ?? "");
// legacy seed
// legacy seed offset
} else if (createWallet == false && spendKey != "") {
Expand Down Expand Up @@ -325,6 +327,10 @@ class MoneroWallet implements CoinWallet {
MoneroWallet(this.wptr);
monero.wallet wptr;

void save() {
monero.Wallet_store(wptr);
}

@override
Coin coin = Monero();

Expand All @@ -342,6 +348,7 @@ class MoneroWallet implements CoinWallet {
throw Exception("Given index is larger than current account count");
}
_accountIndex = accountIndex;
save();
}

@override
Expand Down Expand Up @@ -372,6 +379,27 @@ class MoneroWallet implements CoinWallet {
throw Exception("Unable to handle ${ur.tag}. This is a offline wallet");
case "xmr-output":
monero.Wallet_importOutputsUR(wptr, ur.inputs.join("\n"));
var status = monero.Wallet_status(wptr);
if (status != 0) {
final error = monero.Wallet_errorString(wptr);
throw CoinException(error);
}
final allImages = monero.Wallet_exportKeyImagesUR(wptr,
max_fragment_length: 130, all: true)
.split("\n");
final someImages = monero.Wallet_exportKeyImagesUR(wptr,
max_fragment_length: 130, all: false)
.split("\n");
await AnimatedURPage.staticPush(
context,
URQRViewModel(
urqrList: {
"Partial Key Images": someImages,
"All Key Images": allImages,
},
),
);
save();
case "xmr-txunsigned":
final txptr =
monero.Wallet_loadUnsignedTxUR(wptr, input: ur.inputs.join("\n"));
Expand Down Expand Up @@ -406,12 +434,16 @@ class MoneroWallet implements CoinWallet {
wallet: this,
destMap: destMap,
fee: fee,
confirmCallback: () => {
// show the other URQR code.
confirmCallback: (BuildContext context) async {
final signedTx =
monero.UnsignedTransaction_signUR(txptr, 130).split("\n");
await AnimatedURPage.staticPush(
context, URQRViewModel(urqrList: {"signedTx": signedTx}));
},
cancelCallback: () => {},
cancelCallback: (BuildContext context) => {},
),
);
save();
default:
throw UnimplementedError("Unable to handle ${ur.tag}.");
}
Expand Down
10 changes: 3 additions & 7 deletions lib/view_model/barcode_scanner_view_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class BarcodeScannerViewModel extends ViewModel {
}
}

void handleBarcode(BuildContext context, BarcodeCapture barcodes) {
void handleBarcode(BuildContext context, BarcodeCapture barcodes) async {
for (final barcode in barcodes.barcodes) {
print(barcode.rawValue!);
if (barcode.rawValue!.startsWith("ur:")) {
Expand All @@ -46,10 +46,8 @@ class BarcodeScannerViewModel extends ViewModel {
markNeedsBuild();
if (ur.progress == 1) {
popped = true;
await handleUR(context);
markNeedsBuild();
SchedulerBinding.instance.addPostFrameCallback((_) {
Navigator.of(context).pop(ur.inputs.join("\n"));
});
return;
}
}
Expand All @@ -59,9 +57,7 @@ class BarcodeScannerViewModel extends ViewModel {
barcode = barcodes.barcodes.firstOrNull;
if (barcode != null && popped != true) {
popped = true;
SchedulerBinding.instance.addPostFrameCallback((_) {
Navigator.of(context).pop(barcode?.rawValue ?? "");
});
await handleUR(context);
}
markNeedsBuild();
}
Expand Down
10 changes: 8 additions & 2 deletions lib/view_model/unconfirmed_transaction_view_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@ import 'dart:async';

import 'package:cup_cake/coins/abstract.dart';
import 'package:cup_cake/view_model/abstract.dart';
import 'package:flutter/cupertino.dart';

class Address {
Address(this.address);
final String address;

@override
String toString() {
return address;
}
}

class Amount {
Expand All @@ -29,8 +35,8 @@ class UnconfirmedTransactionViewModel extends ViewModel {
@override
late String screenName = wallet.coin.strings.nameFull;

final FutureOr<void> Function() confirmCallback;
final FutureOr<void> Function() cancelCallback;
final FutureOr<void> Function(BuildContext context) confirmCallback;
final FutureOr<void> Function(BuildContext context) cancelCallback;

final Amount fee;
final Map<Address, Amount> destMap;
Expand Down
10 changes: 7 additions & 3 deletions lib/views/unconfirmed_transaction.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,22 @@ class UnconfirmedTransactionView extends AbstractView {
items: const [
BottomNavigationBarItem(
icon: Icon(Icons.cancel),
label: "Cancel",
),
BottomNavigationBarItem(
icon: Icon(Icons.check_circle),
label: "Confirm"
),
],
onTap: (int index) {
onTap: (int index) async {
if (index == 0) {
await viewModel.cancelCallback(context);
if (!context.mounted) return;
Navigator.of(context).pop();
viewModel.cancelCallback();
} else {
await viewModel.confirmCallback(context);
if (!context.mounted) return;
Navigator.of(context).pop();
viewModel.confirmCallback();
}
},
);
Expand Down
10 changes: 10 additions & 0 deletions lib/views/urqr.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,21 @@ import 'dart:async';

import 'package:cup_cake/view_model/urqr_view_model.dart';
import 'package:cup_cake/views/abstract.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:qr_flutter/qr_flutter.dart';

//ignore: must_be_immutable
class AnimatedURPage extends AbstractView {
static Future<void> staticPush(
BuildContext context, URQRViewModel viewModel) async {
await Navigator.of(context).push(
CupertinoPageRoute(
builder: (context) => AnimatedURPage(viewModel: viewModel),
),
);
}

AnimatedURPage({super.key, required this.viewModel});

@override
Expand Down

0 comments on commit ed269e0

Please sign in to comment.