Skip to content

Commit

Permalink
Use const strings for key values in storage
Browse files Browse the repository at this point in the history
  • Loading branch information
cygnet3 committed Oct 4, 2024
1 parent 9542822 commit 2cea1b0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
13 changes: 8 additions & 5 deletions lib/repositories/settings_repository.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import 'package:danawallet/constants.dart';
import 'package:shared_preferences/shared_preferences.dart';

const String _keyBlindbitUrl = "blindbiturl";
const String _keyDustLimit = "dustlimit";

class SettingsRepository {
final SharedPreferencesAsync prefs = SharedPreferencesAsync();

Expand All @@ -11,22 +14,22 @@ class SettingsRepository {
}

Future<void> resetAll() async {
await prefs.clear(allowList: {'blindbitUrl', 'dustLimit'});
await prefs.clear(allowList: {_keyBlindbitUrl, _keyDustLimit});
}

Future<void> setBlindbitUrl(String url) async {
return await prefs.setString('blindbitUrl', url);
return await prefs.setString(_keyBlindbitUrl, url);
}

Future<String?> getBlindbitUrl() async {
return await prefs.getString('blindbitUrl');
return await prefs.getString(_keyBlindbitUrl);
}

Future<void> setDustLimit(int value) async {
return await prefs.setInt('dustLimit', value);
return await prefs.setInt(_keyDustLimit, value);
}

Future<int?> getDustLimit() async {
return await prefs.getInt('dustLimit');
return await prefs.getInt(_keyDustLimit);
}
}
13 changes: 7 additions & 6 deletions lib/repositories/wallet_repository.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import 'package:flutter_secure_storage/flutter_secure_storage.dart';

const String _keyWalletBlob = "wallet";
const String _keySeedPhrase = "seedphrase";

class WalletRepository {
final String keyWalletBlob = "wallet";
final String keySeedPhrase = "seedphrase";
final secureStorage = const FlutterSecureStorage();

WalletRepository();
Expand All @@ -12,18 +13,18 @@ class WalletRepository {
}

Future<String?> readWalletBlob() async {
return await secureStorage.read(key: keyWalletBlob);
return await secureStorage.read(key: _keyWalletBlob);
}

Future<void> saveWalletBlob(String wallet) async {
await secureStorage.write(key: keyWalletBlob, value: wallet);
await secureStorage.write(key: _keyWalletBlob, value: wallet);
}

Future<String?> readSeedPhrase() async {
return await secureStorage.read(key: keySeedPhrase);
return await secureStorage.read(key: _keySeedPhrase);
}

Future<void> saveSeedPhrase(String seedPhrase) async {
await secureStorage.write(key: keySeedPhrase, value: seedPhrase);
await secureStorage.write(key: _keySeedPhrase, value: seedPhrase);
}
}

0 comments on commit 2cea1b0

Please sign in to comment.