Skip to content

Commit

Permalink
- implement settings
Browse files Browse the repository at this point in the history
- fix visual UI glitch
  • Loading branch information
MrCyjaneK committed Oct 18, 2024
1 parent cb603f2 commit 36cdc55
Show file tree
Hide file tree
Showing 14 changed files with 298 additions and 29 deletions.
6 changes: 6 additions & 0 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ PODS:
- Flutter
- integration_test (0.0.1):
- Flutter
- package_info_plus (0.4.5):
- Flutter
- path_provider_foundation (0.0.1):
- Flutter
- FlutterMacOS
Expand All @@ -17,6 +19,7 @@ DEPENDENCIES:
- Flutter (from `Flutter`)
- flutter_secure_storage (from `.symlinks/plugins/flutter_secure_storage/ios`)
- integration_test (from `.symlinks/plugins/integration_test/ios`)
- package_info_plus (from `.symlinks/plugins/package_info_plus/ios`)
- path_provider_foundation (from `.symlinks/plugins/path_provider_foundation/darwin`)
- share_plus (from `.symlinks/plugins/share_plus/ios`)

Expand All @@ -29,6 +32,8 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/flutter_secure_storage/ios"
integration_test:
:path: ".symlinks/plugins/integration_test/ios"
package_info_plus:
:path: ".symlinks/plugins/package_info_plus/ios"
path_provider_foundation:
:path: ".symlinks/plugins/path_provider_foundation/darwin"
share_plus:
Expand All @@ -39,6 +44,7 @@ SPEC CHECKSUMS:
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
flutter_secure_storage: d33dac7ae2ea08509be337e775f6b59f1ff45f12
integration_test: 13825b8a9334a850581300559b8839134b124670
package_info_plus: 58f0028419748fad15bf008b270aaa8e54380b1c
path_provider_foundation: 2b6b4c569c0fb62ec74538f866245ac84301af46
share_plus: 8875f4f2500512ea181eef553c3e27dba5135aad

Expand Down
4 changes: 2 additions & 2 deletions lib/coins/abstract.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import 'dart:core';

import 'package:cup_cake/coins/monero/coin.dart';
import 'package:cup_cake/l10n/app_localizations.dart';
import 'package:cup_cake/utils/config.dart';
import 'package:cup_cake/view_model/barcode_scanner_view_model.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:path/path.dart' as p;

Expand Down Expand Up @@ -65,7 +65,7 @@ class CoinWalletInfo {
Map<String, dynamic> toJson() {
return {
"typeIndex": type.index,
if (kDebugMode) "typeIndex__debug": type.toString(),
if (config.debug) "typeIndex__debug": type.toString(),
"walletName": p.basename(walletName),
};
}
Expand Down
3 changes: 1 addition & 2 deletions lib/coins/monero/coin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import 'package:cup_cake/utils/config.dart';
import 'package:cup_cake/utils/filesystem.dart';
import 'package:cup_cake/views/open_wallet.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:monero/monero.dart' as monero;
import 'package:path/path.dart' as p;
Expand All @@ -22,7 +21,7 @@ class Monero implements Coin {
monero.isLibOk();
return true;
} catch (e) {
if (kDebugMode) {
if (config.debug) {
print("monero.dart: isLibOk failed: $e");
return false;
}
Expand Down
30 changes: 17 additions & 13 deletions lib/coins/monero/wallet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'dart:convert';
import 'package:cup_cake/coins/abstract.dart';
import 'package:cup_cake/coins/monero/coin.dart';
import 'package:cup_cake/l10n/app_localizations.dart';
import 'package:cup_cake/utils/config.dart';
import 'package:cup_cake/utils/null_if_empty.dart';
import 'package:cup_cake/utils/secure_storage.dart';
import 'package:cup_cake/view_model/barcode_scanner_view_model.dart';
Expand All @@ -11,7 +12,6 @@ import 'package:cup_cake/view_model/urqr_view_model.dart';
import 'package:cup_cake/views/unconfirmed_transaction.dart';
import 'package:cup_cake/views/urqr.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:path/path.dart' as p;
import 'package:monero/monero.dart' as monero;
import 'package:polyseed/polyseed.dart';
Expand Down Expand Up @@ -70,10 +70,10 @@ class MoneroWallet implements CoinWallet {

Future<void> exportKeyImagesUR(BuildContext context) async {
final allImages = monero.Wallet_exportKeyImagesUR(wptr,
max_fragment_length: 130, all: true)
max_fragment_length: config.maxFragmentLength, all: true)
.split("\n");
final someImages = monero.Wallet_exportKeyImagesUR(wptr,
max_fragment_length: 130, all: false)
max_fragment_length: config.maxFragmentLength, all: false)
.split("\n");
await AnimatedURPage.staticPush(
context,
Expand Down Expand Up @@ -137,8 +137,9 @@ class MoneroWallet implements CoinWallet {
destMap: destMap,
fee: fee,
confirmCallback: (BuildContext context) async {
final signedTx =
monero.UnsignedTransaction_signUR(txptr, 130).split("\n");
final signedTx = monero.UnsignedTransaction_signUR(
txptr, config.maxFragmentLength)
.split("\n");
var status = monero.Wallet_status(wptr);
if (status != 0) {
final error = monero.Wallet_errorString(wptr);
Expand Down Expand Up @@ -281,14 +282,17 @@ class MoneroWallet implements CoinWallet {
"restoreHeight": monero.Wallet_getRefreshFromBlockHeight(wptr),
}),
),
if (kDebugMode)
...List.generate(secrets.keys.length, (index) {
final key = secrets.keys.elementAt(index);
return WalletSeedDetail(
type: WalletSeedDetailType.text,
name: key,
value: secrets[key] ?? "unknown");
}),
if (config.debug)
...List.generate(
secrets.keys.length,
(index) {
final key = secrets.keys.elementAt(index);
return WalletSeedDetail(
type: WalletSeedDetailType.text,
name: key,
value: secrets[key] ?? "unknown");
},
),
];
}
}
Expand Down
12 changes: 12 additions & 0 deletions lib/utils/config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,25 @@ class CupcakeConfig {
required this.lastWallet,
required this.initialSetupComplete,
required this.walletMigrationLevel,
required this.msForQrCode,
required this.maxFragmentLength,
required this.debug,
});
CoinWalletInfo? lastWallet;
bool initialSetupComplete;
int walletMigrationLevel;
int msForQrCode;
int maxFragmentLength;
bool debug;

factory CupcakeConfig.fromJson(Map<String, dynamic> json) {
return CupcakeConfig(
lastWallet: CoinWalletInfo.fromJson(json['lastWallet']),
initialSetupComplete: json['initialSetupComplete'] ?? false,
walletMigrationLevel: json['walletMigrationLevel'] ?? 0,
msForQrCode: json['msForQrCode'] ?? 1000 ~/ 3.5,
maxFragmentLength: json['maxFragmentLength'] ?? 130,
debug: json['debug'] ?? false,
);
}

Expand All @@ -29,6 +38,9 @@ class CupcakeConfig {
'lastWallet': lastWallet,
'initialSetupComplete': initialSetupComplete,
'walletMigrationLevel': walletMigrationLevel,
'msForQrCode': msForQrCode,
'maxFragmentLength': maxFragmentLength,
'debug': debug,
};
}

Expand Down
3 changes: 1 addition & 2 deletions lib/view_model/create_wallet_view_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ 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 @@ -416,7 +415,7 @@ class FlutterSecureStorageValueOutcome implements ValueOutcome {
return;
}
if (!canWrite) {
if (kDebugMode) {
if (config.debug) {
throw Exception(
"DEBUG_ONLY: canWrite is false but we tried to flush the value");
}
Expand Down
3 changes: 3 additions & 0 deletions lib/view_model/settings_view_model.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import 'package:cup_cake/utils/config.dart';
import 'package:cup_cake/view_model/abstract.dart';

class SettingsViewModel extends ViewModel {
SettingsViewModel();

@override
String get screenName => "Settings";

CupcakeConfig get appConfig => config;
}
4 changes: 2 additions & 2 deletions lib/views/create_wallet.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import 'package:cup_cake/gen/assets.gen.dart';
import 'package:cup_cake/utils/call_throwable.dart';
import 'package:cup_cake/utils/config.dart';
import 'package:cup_cake/view_model/create_wallet_view_model.dart';
import 'package:cup_cake/views/abstract.dart';
import 'package:cup_cake/views/initial_setup_screen.dart';
import 'package:cup_cake/widgets/form_builder.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

// ignore: must_be_immutable
Expand Down Expand Up @@ -145,7 +145,7 @@ class CreateWallet extends AbstractView {
bool isFormBad(List<FormElement> form) {
for (var element in form) {
if (!element.isOk) {
if (kDebugMode) {
if (config.debug) {
print("${element.label} is not valid: ");
}
return true;
Expand Down
Loading

0 comments on commit 36cdc55

Please sign in to comment.