Skip to content

Commit

Permalink
fix alert for seed type picker, to look nicer
Browse files Browse the repository at this point in the history
  • Loading branch information
MrCyjaneK committed Oct 14, 2024
1 parent ef55595 commit d3999ab
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 11 deletions.
27 changes: 27 additions & 0 deletions lib/utils/alert.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,30 @@ Future<void> showAlertWidget({
},
);
}

Future<void> showAlertWidgetMinimal({
required BuildContext context,
required List<Widget> body,
}) async {
return showDialog<void>(
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,
),
),
const Spacer(),
]),
);
},
);
}
33 changes: 29 additions & 4 deletions lib/view_model/create_wallet_view_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import 'package:cup_cake/view_model/new_wallet_info_view_model.dart';
import 'package:cup_cake/views/new_wallet_info.dart';
import 'package:cup_cake/gen/assets.gen.dart';
import 'package:cup_cake/views/wallet_home.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:share_plus/share_plus.dart';
Expand Down Expand Up @@ -78,6 +79,7 @@ class CreateWalletViewModel extends ViewModel {
valueOutcome: FlutterSecureStorageValueOutcome(
"secure.wallet_password",
canWrite: true,
verifyMatching: false,
),
validator: (String? input) {
if (input == null) return L.warning_input_cannot_be_null;
Expand Down Expand Up @@ -382,35 +384,58 @@ class PlainValueOutcome implements ValueOutcome {
}

class FlutterSecureStorageValueOutcome implements ValueOutcome {
FlutterSecureStorageValueOutcome(this.key, {required this.canWrite});
FlutterSecureStorageValueOutcome(this.key,
{required this.canWrite, required this.verifyMatching});

final String key;
final bool canWrite;
final bool verifyMatching;

@override
Future<void> encode(String input) async {
var valInput =
await secureStorage.read(key: "FlutterSecureStorageValueOutcome._$key");
if (valInput == null) {
await secureStorage.write(
key: "FlutterSecureStorageValueOutcome._$key", value: input);
valInput = await secureStorage.read(
key: "FlutterSecureStorageValueOutcome._$key");
}
if (input != valInput) {
throw Exception("Input doesn't match the secure element value");
}

final input_ = await secureStorage.read(key: key);
// Do not update secret if it is already set.
if (input_ != null) {
return;
}
if (!canWrite) {
throw Exception("canWrite is false but we tried to flush the value");
if (kDebugMode) {
throw Exception(
"DEBUG_ONLY: canWrite is false but we tried to flush the value");
}
return;
}
var random = Random.secure();
var values = List<int>.generate(64, (i) => random.nextInt(256));
final pass = base64Url.encode(values) + input;
final pass = base64Url.encode(values);
await secureStorage.write(key: key, value: pass);
return;
}

@override
Future<String> decode(String output) async {
var valInput =
await secureStorage.read(key: "FlutterSecureStorageValueOutcome._$key");
if (output != valInput) {
throw Exception("Input doesn't match the secure element value");
}
final input = await secureStorage.read(key: key);
if (input == null) {
throw Exception("no secure storage $key found");
}
return input;
return "$input/$output";
}
}

Expand Down
1 change: 1 addition & 0 deletions lib/view_model/open_wallet_view_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class OpenWalletViewModel extends ViewModel {
valueOutcome: FlutterSecureStorageValueOutcome(
"secure.wallet_password",
canWrite: false,
verifyMatching: true,
),
validator: (String? input) {
if (input == null) return L.warning_input_cannot_be_null;
Expand Down
12 changes: 5 additions & 7 deletions lib/widgets/form_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,10 @@ class _FormBuilderState extends State<FormBuilder> {
rebuild: _rebuild,
showConfirm: () => e.isOk,
nextPage: () async {
_pinSet();
callThrowable(
context,
() async => await e.onConfirmInternal(context),
"Secure storage communication");
callThrowable(context, () async {
await e.onConfirmInternal(context);
_pinSet();
}, "Secure storage communication");
e.onConfirm?.call(context);
},
showComma: false,
Expand Down Expand Up @@ -129,9 +128,8 @@ class _FormBuilderState extends State<FormBuilder> {

Future<void> _changeSingleChoice(
BuildContext context, SingleChoiceFormElement e) async {
showAlertWidget(
await showAlertWidgetMinimal(
context: context,
title: e.title,
body: List.generate(
e.elements.length,
(index) {
Expand Down

0 comments on commit d3999ab

Please sign in to comment.