Skip to content

Commit a7c007d

Browse files
committed
Migrate view models to MobX for state management
Note that this is a initial implementation, and mobx may be used inneficiently at the moment
1 parent de9b265 commit a7c007d

35 files changed

+510
-597
lines changed

.env

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
MONERO_C_TAG=v0.18.3.4-RC12
1+
MONERO_C_TAG=v0.18.4.0-RC1
22
COIN=monero

build.yaml

-16
This file was deleted.

docs/README.md

-67
This file was deleted.

lib/coins/monero/creation/common.dart

-4
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,6 @@ class MoneroWalletCreation extends WalletCreation {
161161
}
162162
}
163163

164-
print(await walletAddress.value);
165-
print(await secretSpendKey.value);
166-
print(await secretViewKey.value);
167-
168164
return RestoreFromKeysMoneroWalletCreationMethod(
169165
L,
170166
walletPath: coin.getPathForWallet(walletName),

lib/coins/monero/wallet.dart

-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ class MoneroWallet implements CoinWallet {
8989

9090
@override
9191
Future<void> handleUR(final BuildContext context, final URQRData ur) async {
92-
print("handling: ${ur.tag}");
9392
switch (ur.tag) {
9493
case "xmr-keyimage" || "xmr-txsigned":
9594
throw Exception("Unable to handle ${ur.tag}. This is a offline wallet");

lib/dev/generate_rebuild.dart

-23
This file was deleted.

lib/dev/rebuild_generator.dart

-174
This file was deleted.

lib/utils/get_signing_key.dart

-12
This file was deleted.

lib/view_model/abstract.dart

+1-8
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import 'package:cupcake/l10n/app_localizations.dart';
66
import 'package:cupcake/utils/alerts/basic.dart';
77
import 'package:flutter/material.dart';
88

9-
class ViewModel {
9+
mixin ViewModel {
1010
bool canPop = true;
1111
String get screenName => "screenName";
1212

@@ -38,13 +38,6 @@ class ViewModel {
3838
return c?.mounted ?? false;
3939
}
4040

41-
void markNeedsBuild() {
42-
if (c == null) {
43-
throw Exception("c is null, did you forget to register(context)?");
44-
}
45-
(c as Element).markNeedsBuild();
46-
}
47-
4841
Future<void> errorHandler(final Object e) => callThrowable(() => throw e, L.create_wallet);
4942

5043
Future<bool> callThrowable(final Future<void> Function() function, final String title) async {

lib/view_model/barcode_scanner_view_model.dart

+18-13
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
11
import 'package:cupcake/coins/abstract/wallet.dart';
2-
import 'package:cupcake/dev/generate_rebuild.dart';
32
import 'package:cupcake/utils/urqr.dart';
43
import 'package:cupcake/view_model/abstract.dart';
54
import 'package:cupcake/views/widgets/barcode_scanner/urqr_progress.dart';
65
import 'package:fast_scanner/fast_scanner.dart';
6+
import 'package:mobx/mobx.dart';
77

88
part 'barcode_scanner_view_model.g.dart';
99

10-
@GenerateRebuild()
11-
class BarcodeScannerViewModel extends ViewModel {
12-
BarcodeScannerViewModel({required this.wallet});
10+
class BarcodeScannerViewModel = BarcodeScannerViewModelBase with _$BarcodeScannerViewModel;
11+
12+
abstract class BarcodeScannerViewModelBase with ViewModel, Store {
13+
BarcodeScannerViewModelBase({required this.wallet});
1314
@override
1415
String get screenName => L.scan;
1516

16-
@RebuildOnChange()
17-
Barcode? $barcode;
17+
@observable
18+
Barcode? barcode;
1819

19-
@RebuildOnChange()
20-
bool $popped = false;
20+
@observable
21+
bool popped = false;
2122

22-
@RebuildOnChange()
23-
List<String> $urCodes = [];
23+
@observable
24+
List<String> urCodes = [];
2425

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

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

38-
@ThrowOnUI(L: "error_handling_urqr_scan")
39-
Future<void> $handleUR() async {
40-
await wallet.handleUR(c!, ur);
39+
Future<void> handleUR() async {
40+
await callThrowable(
41+
() async {
42+
await wallet.handleUR(c!, ur);
43+
},
44+
L.error_handling_urqr_scan,
45+
);
4146
}
4247

4348
Future<void> handleBarcode(final BarcodeCapture barcodes) async {

0 commit comments

Comments
 (0)