Skip to content

Commit

Permalink
- remove safearea usage
Browse files Browse the repository at this point in the history
- implement wallet delete and rename
- implement wallet screen as it is in cake
- don't show recovery screen for restored wallet
- settings screen [WIP]
  • Loading branch information
MrCyjaneK committed Oct 16, 2024
1 parent 95b1003 commit 0d891e7
Show file tree
Hide file tree
Showing 15 changed files with 333 additions and 126 deletions.
2 changes: 2 additions & 0 deletions lib/coins/abstract.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ class CoinWalletInfo {
throw UnimplementedError("unknown coin");
}
}
Future<void> deleteWallet() => throw UnimplementedError();
Future<void> renameWallet(String newName) => throw UnimplementedError();
}

class CoinStrings {
Expand Down
27 changes: 27 additions & 0 deletions lib/coins/monero/coin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import 'package:path/path.dart' as p;
import 'package:cup_cake/gen/assets.gen.dart';
import 'package:polyseed/polyseed.dart';

List<monero.wallet> wPtrList = [];

class Monero implements Coin {
@override
bool get isEnabled {
Expand Down Expand Up @@ -93,6 +95,7 @@ class Monero implements Coin {
monero.Wallet_setCacheAttribute(newWptr,
key: seedOffsetCacheKey, value: seedOffsetOrEncryption);
monero.Wallet_store(newWptr);
wPtrList.add(newWptr);
print("wallet created in: $walletPath");
progressCallback?.call(description: "Wallet created");
await Future.delayed(Duration.zero);
Expand Down Expand Up @@ -128,6 +131,7 @@ class Monero implements Coin {
restoreHeight: 0,
kdfRounds: 1,
);
wPtrList.add(newWptr);
progressCallback?.call(description: "Checking status");
final status = monero.Wallet_status(newWptr);
if (status != 0) {
Expand Down Expand Up @@ -160,6 +164,7 @@ class Monero implements Coin {
restoreHeight: 0,
kdfRounds: 1,
);
wPtrList.add(newWptr);
progressCallback?.call(description: "Checking status");
final status = monero.Wallet_status(newWptr);
if (status != 0) {
Expand Down Expand Up @@ -363,4 +368,26 @@ class MoneroWalletInfo extends CoinWalletInfo {
password: password,
);
}

@override
Future<void> deleteWallet() async {
wPtrList.forEach((element) {
monero.WalletManager_closeWallet(Monero.wmPtr, element, true);
});
wPtrList.clear();
File(walletName).deleteSync();
File("$walletName.keys").deleteSync();
}


@override
Future<void> renameWallet(String newName) async {
wPtrList.forEach((element) {
monero.WalletManager_closeWallet(Monero.wmPtr, element, true);
});
wPtrList.clear();
final basePath = p.dirname(walletName);
File(walletName).rename(p.join(basePath,newName));
File("$walletName.keys").rename(p.join(basePath,"$newName.keys"));
}
}
26 changes: 1 addition & 25 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ class MyApp extends StatelessWidget {
return Stack(
alignment: AlignmentDirectional.bottomStart,
children: [
child ?? Text("null"),
_getInfoWidget(),
child ?? const Text("null"),
],
);
},
Expand All @@ -63,27 +62,4 @@ class MyApp extends StatelessWidget {
: InitialSetupScreen(),
);
}

Widget _getInfoWidget() {
String notice = "";
if (signingKeyFound != signingKeyExpected) {
notice += "\ninvalid signing key";
}
return Material(
color: Colors.transparent,
child: Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
notice.trim(),
style: TextStyle(
color: Colors.red,
),
),
],
),
);
}
}
27 changes: 14 additions & 13 deletions lib/utils/alert.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,21 @@ Future<void> showAlertWidgetMinimal({
context: context,
barrierDismissible: true,
builder: (BuildContext context) {
return Material(
color: Colors.transparent,
child: Column(mainAxisSize: MainAxisSize.min, children: [
const Spacer(),
// TODO: Make this look good
Container(
color: Colors.transparent,
child: Column(
mainAxisSize: MainAxisSize.min,
children: body,
return SizedBox(
height: 360,
child: Material(
color: Colors.transparent,
child: Column(mainAxisSize: MainAxisSize.min, children: [
// TODO: Make this look good
Container(
color: Colors.transparent,
child: Column(
mainAxisSize: MainAxisSize.min,
children: body,
),
),
),
const Spacer(),
]),
]),
),
);
},
);
Expand Down
23 changes: 17 additions & 6 deletions lib/view_model/create_wallet_view_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class CreateWalletViewModel extends ViewModel {
);

late PinFormElement walletPassword = PinFormElement(
label: "Wallet password",
password: true,
valueOutcome: FlutterSecureStorageValueOutcome(
"secure.wallet_password",
Expand Down Expand Up @@ -335,10 +336,14 @@ class CreateWalletViewModel extends ViewModel {
if (!context.mounted) {
throw Exception("context is not mounted, unable to show next screen");
}
NewWalletInfoScreen.staticPush(
context,
NewWalletInfoViewModel(pages),
);
if (currentForm != _createForm) {
WalletHome.pushStatic(context, cw);
} else {
NewWalletInfoScreen.staticPush(
context,
NewWalletInfoViewModel(pages),
);
}
}
}

Expand Down Expand Up @@ -401,7 +406,7 @@ class FlutterSecureStorageValueOutcome implements ValueOutcome {
valInput = await secureStorage.read(
key: "FlutterSecureStorageValueOutcome._$key");
}
if (input != valInput) {
if (input != valInput && verifyMatching) {
throw Exception("Input doesn't match the secure element value");
}

Expand All @@ -428,7 +433,7 @@ class FlutterSecureStorageValueOutcome implements ValueOutcome {
Future<String> decode(String output) async {
var valInput =
await secureStorage.read(key: "FlutterSecureStorageValueOutcome._$key");
if (output != valInput) {
if (output != valInput && verifyMatching) {
throw Exception("Input doesn't match the secure element value");
}
final input = await secureStorage.read(key: key);
Expand All @@ -447,10 +452,16 @@ class PinFormElement extends FormElement {
required this.valueOutcome,
this.onChanged,
this.onConfirm,
this.showNumboard = true,
required this.label,
}) : ctrl = TextEditingController(text: initialText);

TextEditingController ctrl;
bool password;
bool showNumboard;

@override
String label;

ValueOutcome valueOutcome;

Expand Down
34 changes: 18 additions & 16 deletions lib/view_model/open_wallet_view_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,24 @@ class OpenWalletViewModel extends ViewModel {
String get screenName => L.enter_password;

late PinFormElement walletPassword = PinFormElement(
password: true,
valueOutcome: FlutterSecureStorageValueOutcome(
"secure.wallet_password",
canWrite: false,
verifyMatching: true,
),
validator: (String? input) {
if (input == null) return L.warning_input_cannot_be_null;
if (input == "") return L.warning_input_cannot_be_empty;
if (input.length < 4) {
return L.warning_password_too_short;
}
return null;
},
onChanged: openWalletIfPasswordCorrect,
onConfirm: openWallet);
label: "Wallet password",
password: true,
valueOutcome: FlutterSecureStorageValueOutcome(
"secure.wallet_password",
canWrite: false,
verifyMatching: true,
),
validator: (String? input) {
if (input == null) return L.warning_input_cannot_be_null;
if (input == "") return L.warning_input_cannot_be_empty;
if (input.length < 4) {
return L.warning_password_too_short;
}
return null;
},
onChanged: openWalletIfPasswordCorrect,
onConfirm: openWallet,
);

Future<void> openWallet(BuildContext context) async {
callThrowable(
Expand Down
10 changes: 10 additions & 0 deletions lib/view_model/settings_view_model.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import 'package:cup_cake/coins/abstract.dart';
import 'package:cup_cake/coins/list.dart';
import 'package:cup_cake/view_model/abstract.dart';

class SettingsViewModel extends ViewModel {
SettingsViewModel();

@override
String get screenName => "Settings";
}
61 changes: 61 additions & 0 deletions lib/view_model/wallet_edit_view_model.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import 'package:cup_cake/coins/abstract.dart';
import 'package:cup_cake/view_model/create_wallet_view_model.dart';
import 'package:flutter/material.dart';
import 'package:cup_cake/view_model/abstract.dart';
import 'package:path/path.dart' as p;

class WalletEditViewModel extends ViewModel {
WalletEditViewModel({
required this.walletInfo,
});

CoinWalletInfo walletInfo;

late StringFormElement walletName = StringFormElement("Wallet name",
initialText: p.basename(walletInfo.walletName),);

late PinFormElement walletPassword = PinFormElement(
label: "Wallet password",
password: true,
valueOutcome: FlutterSecureStorageValueOutcome(
"secure.wallet_password",
canWrite: false,
verifyMatching: true,
),
validator: (String? input) {
if (input == null) return L.warning_input_cannot_be_null;
if (input == "") return L.warning_input_cannot_be_empty;
if (input.length < 4) {
return L.warning_password_too_short;
}
return null;
},
showNumboard: false,);

late final List<FormElement> form = [
walletName,
walletPassword,
];

@override
String get screenName => "Edit wallet";

Future<void> deleteWallet(BuildContext context) async {
if (!(await walletInfo.checkWalletPassword(await walletPassword.value))) {
throw Exception("Invalid wallet password");
}
walletInfo.deleteWallet();
if (!context.mounted) return;
Navigator.of(context).pop();
}


Future<void> renameWallet(BuildContext context) async {
if (!(await walletInfo.checkWalletPassword(await walletPassword.value))) {
throw Exception("Invalid wallet password");
}
walletInfo.renameWallet(await walletName.value);
if (!context.mounted) return;
Navigator.of(context).pop();
}
}
14 changes: 6 additions & 8 deletions lib/views/abstract.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,12 @@ class AbstractView extends StatefulWidget {
onPopInvoked: (bool pop) {
print(pop);
},
child: SafeArea(
child: Scaffold(
appBar: appBar,
body: body(context),
endDrawer: drawer,
floatingActionButton: floatingActionButton(context),
bottomNavigationBar: bottomNavigationBar(context),
),
child: Scaffold(
appBar: appBar,
body: body(context),
endDrawer: drawer,
floatingActionButton: floatingActionButton(context),
bottomNavigationBar: bottomNavigationBar(context),
),
);
}
Expand Down
Loading

0 comments on commit 0d891e7

Please sign in to comment.