Skip to content

Commit

Permalink
Migrate view models to MobX for state management
Browse files Browse the repository at this point in the history
Note that this is a initial implementation, and mobx may be used inneficiently at the moment
  • Loading branch information
MrCyjaneK committed Feb 25, 2025
1 parent de9b265 commit a7c007d
Show file tree
Hide file tree
Showing 35 changed files with 510 additions and 597 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
MONERO_C_TAG=v0.18.3.4-RC12
MONERO_C_TAG=v0.18.4.0-RC1
COIN=monero
16 changes: 0 additions & 16 deletions build.yaml

This file was deleted.

67 changes: 0 additions & 67 deletions docs/README.md

This file was deleted.

4 changes: 0 additions & 4 deletions lib/coins/monero/creation/common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,6 @@ class MoneroWalletCreation extends WalletCreation {
}
}

print(await walletAddress.value);
print(await secretSpendKey.value);
print(await secretViewKey.value);

return RestoreFromKeysMoneroWalletCreationMethod(
L,
walletPath: coin.getPathForWallet(walletName),
Expand Down
1 change: 0 additions & 1 deletion lib/coins/monero/wallet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ class MoneroWallet implements CoinWallet {

@override
Future<void> handleUR(final BuildContext context, final URQRData ur) async {
print("handling: ${ur.tag}");
switch (ur.tag) {
case "xmr-keyimage" || "xmr-txsigned":
throw Exception("Unable to handle ${ur.tag}. This is a offline wallet");
Expand Down
23 changes: 0 additions & 23 deletions lib/dev/generate_rebuild.dart

This file was deleted.

174 changes: 0 additions & 174 deletions lib/dev/rebuild_generator.dart

This file was deleted.

12 changes: 0 additions & 12 deletions lib/utils/get_signing_key.dart

This file was deleted.

9 changes: 1 addition & 8 deletions lib/view_model/abstract.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'package:cupcake/l10n/app_localizations.dart';
import 'package:cupcake/utils/alerts/basic.dart';
import 'package:flutter/material.dart';

class ViewModel {
mixin ViewModel {
bool canPop = true;
String get screenName => "screenName";

Expand Down Expand Up @@ -38,13 +38,6 @@ class ViewModel {
return c?.mounted ?? false;
}

void markNeedsBuild() {
if (c == null) {
throw Exception("c is null, did you forget to register(context)?");
}
(c as Element).markNeedsBuild();
}

Future<void> errorHandler(final Object e) => callThrowable(() => throw e, L.create_wallet);

Future<bool> callThrowable(final Future<void> Function() function, final String title) async {
Expand Down
31 changes: 18 additions & 13 deletions lib/view_model/barcode_scanner_view_model.dart
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
import 'package:cupcake/coins/abstract/wallet.dart';
import 'package:cupcake/dev/generate_rebuild.dart';
import 'package:cupcake/utils/urqr.dart';
import 'package:cupcake/view_model/abstract.dart';
import 'package:cupcake/views/widgets/barcode_scanner/urqr_progress.dart';
import 'package:fast_scanner/fast_scanner.dart';
import 'package:mobx/mobx.dart';

part 'barcode_scanner_view_model.g.dart';

@GenerateRebuild()
class BarcodeScannerViewModel extends ViewModel {
BarcodeScannerViewModel({required this.wallet});
class BarcodeScannerViewModel = BarcodeScannerViewModelBase with _$BarcodeScannerViewModel;

abstract class BarcodeScannerViewModelBase with ViewModel, Store {
BarcodeScannerViewModelBase({required this.wallet});
@override
String get screenName => L.scan;

@RebuildOnChange()
Barcode? $barcode;
@observable
Barcode? barcode;

@RebuildOnChange()
bool $popped = false;
@observable
bool popped = false;

@RebuildOnChange()
List<String> $urCodes = [];
@observable
List<String> urCodes = [];

URQRData get ur => URQRData.parse(urCodes);

Expand All @@ -35,9 +36,13 @@ class BarcodeScannerViewModel extends ViewModel {
percentage: ur.progress,
);

@ThrowOnUI(L: "error_handling_urqr_scan")
Future<void> $handleUR() async {
await wallet.handleUR(c!, ur);
Future<void> handleUR() async {
await callThrowable(
() async {
await wallet.handleUR(c!, ur);
},
L.error_handling_urqr_scan,
);
}

Future<void> handleBarcode(final BarcodeCapture barcodes) async {
Expand Down
Loading

0 comments on commit a7c007d

Please sign in to comment.