Flutter upgrade

This commit is contained in:
M
2022-10-12 13:09:57 -04:00
parent c921ad890a
commit 1beb18b045
505 changed files with 6657 additions and 5875 deletions
+1 -1
View File
@@ -18,7 +18,7 @@ int serializeActionlistDisplayModes(List<ActionListDisplayMode> modes) {
}
List<ActionListDisplayMode> deserializeActionlistDisplayModes(int raw) {
final modes = List<ActionListDisplayMode>();
final modes = <ActionListDisplayMode>[];
if (raw == 1 || raw - 10 == 1) {
modes.add(ActionListDisplayMode.trades);
+3 -3
View File
@@ -3,7 +3,7 @@ import 'package:cake_wallet/generated/i18n.dart';
import 'package:cw_core/enumerable_item.dart';
class BalanceDisplayMode extends EnumerableItem<int> with Serializable<int> {
const BalanceDisplayMode({@required String title, @required int raw})
const BalanceDisplayMode({required String title, required int raw})
: super(title: title, raw: raw);
static const all = [
@@ -18,7 +18,7 @@ class BalanceDisplayMode extends EnumerableItem<int> with Serializable<int> {
static const displayableBalance =
BalanceDisplayMode(raw: 3, title: 'Displayable Balance');
static BalanceDisplayMode deserialize({int raw}) {
static BalanceDisplayMode deserialize({required int raw}) {
switch (raw) {
case 0:
return fullBalance;
@@ -29,7 +29,7 @@ class BalanceDisplayMode extends EnumerableItem<int> with Serializable<int> {
case 3:
return displayableBalance;
default:
return null;
throw Exception('Unexpected token: $raw for BalanceDisplayMode deserialize');
}
}
+3 -2
View File
@@ -9,8 +9,9 @@ class BiometricAuth {
try {
return await _localAuth.authenticate(
localizedReason: S.current.biometric_auth_reason,
useErrorDialogs: true,
stickyAuth: false);
options: AuthenticationOptions(
useErrorDialogs: true,
stickyAuth: false));
} on PlatformException catch (e) {
print(e);
}
+1 -1
View File
@@ -1,4 +1,4 @@
String calculateFiatAmount({double price, String cryptoAmount}) {
String calculateFiatAmount({double? price, String? cryptoAmount}) {
if (price == null || cryptoAmount == null) {
return '0.00';
}
+1 -1
View File
@@ -1,4 +1,4 @@
String calculateFiatAmountRaw({double price, double cryptoAmount}) {
String calculateFiatAmountRaw({required double cryptoAmount, double? price}) {
if (price == null) {
return '0.00';
}
+7 -4
View File
@@ -8,8 +8,11 @@ part 'contact.g.dart';
@HiveType(typeId: Contact.typeId)
class Contact extends HiveObject with Keyable {
Contact({@required this.name, @required this.address, CryptoCurrency type})
: raw = type?.raw;
Contact({required this.name, required this.address, CryptoCurrency? type}) {
if (type != null) {
raw = type.raw;
}
}
static const typeId = 0;
static const boxName = 'Contacts';
@@ -21,7 +24,7 @@ class Contact extends HiveObject with Keyable {
String address;
@HiveField(2)
int raw;
late int raw;
CryptoCurrency get type => CryptoCurrency.deserialize(raw: raw);
@@ -34,6 +37,6 @@ class Contact extends HiveObject with Keyable {
@override
int get hashCode => key.hashCode;
void updateCryptoCurrency({@required CryptoCurrency currency}) =>
void updateCryptoCurrency({required CryptoCurrency currency}) =>
raw = currency.raw;
}
+2
View File
@@ -1,6 +1,8 @@
import 'package:cw_core/crypto_currency.dart';
abstract class ContactBase {
ContactBase(this.name, this.address, this.type);
String name;
String address;
+4 -1
View File
@@ -13,7 +13,10 @@ abstract class ContactRecordBase extends Record<Contact>
with Store
implements ContactBase {
ContactRecordBase(Box<Contact> source, Contact original)
: super(source, original);
: name = original.name,
address = original.address,
type = original.type,
super(source, original);
@override
@observable
+60 -68
View File
@@ -18,6 +18,7 @@ import 'package:cake_wallet/entities/fs_migration.dart';
import 'package:cw_core/wallet_info.dart';
import 'package:cake_wallet/exchange/trade.dart';
import 'package:encrypt/encrypt.dart' as encrypt;
import 'package:collection/collection.dart';
const newCakeWalletMoneroUri = 'xmr-node.cakewallet.com:18081';
const cakeWalletBitcoinElectrumUri = 'electrum.cakewallet.com:50002';
@@ -25,13 +26,13 @@ const cakeWalletLitecoinElectrumUri = 'ltc-electrum.cakewallet.com:50002';
const havenDefaultNodeUri = 'nodes.havenprotocol.org:443';
Future defaultSettingsMigration(
{@required int version,
@required SharedPreferences sharedPreferences,
@required FlutterSecureStorage secureStorage,
@required Box<Node> nodes,
@required Box<WalletInfo> walletInfoSource,
@required Box<Trade> tradeSource,
@required Box<Contact> contactSource}) async {
{required int version,
required SharedPreferences sharedPreferences,
required FlutterSecureStorage secureStorage,
required Box<Node> nodes,
required Box<WalletInfo> walletInfoSource,
required Box<Trade> tradeSource,
required Box<Contact> contactSource}) async {
if (Platform.isIOS) {
await ios_migrate_v1(walletInfoSource, tradeSource, contactSource);
}
@@ -56,7 +57,7 @@ Future defaultSettingsMigration(
FiatCurrency.usd.toString());
await sharedPreferences.setInt(
PreferencesKey.currentTransactionPriorityKeyLegacy,
monero.getDefaultTransactionPriority().raw);
monero!.getDefaultTransactionPriority().raw);
await sharedPreferences.setInt(
PreferencesKey.currentBalanceDisplayModeKey,
BalanceDisplayMode.availableBalance.raw);
@@ -147,7 +148,7 @@ Future defaultSettingsMigration(
'current_default_settings_migration_version', version);
}
Future<void> replaceNodesMigration({@required Box<Node> nodes}) async {
Future<void> replaceNodesMigration({required Box<Node> nodes}) async {
final replaceNodes = <String, Node>{
'eu-node.cakewallet.io:18081':
Node(uri: 'xmr-node-eu.cakewallet.com:18081', type: WalletType.monero),
@@ -170,39 +171,33 @@ Future<void> replaceNodesMigration({@required Box<Node> nodes}) async {
}
Future<void> changeMoneroCurrentNodeToDefault(
{@required SharedPreferences sharedPreferences,
@required Box<Node> nodes}) async {
{required SharedPreferences sharedPreferences,
required Box<Node> nodes}) async {
final node = getMoneroDefaultNode(nodes: nodes);
final nodeId = node?.key as int ?? 0; // 0 - England
await sharedPreferences.setInt('current_node_id', nodeId);
}
Node getBitcoinDefaultElectrumServer({@required Box<Node> nodes}) {
return nodes.values.firstWhere(
(Node node) => node.uri == cakeWalletBitcoinElectrumUri,
orElse: () => null) ??
nodes.values.firstWhere((node) => node.type == WalletType.bitcoin,
orElse: () => null);
Node? getBitcoinDefaultElectrumServer({required Box<Node> nodes}) {
return nodes.values.firstWhereOrNull(
(Node node) => node.uriRaw == cakeWalletBitcoinElectrumUri)
?? nodes.values.firstWhereOrNull((node) => node.type == WalletType.bitcoin);
}
Node getLitecoinDefaultElectrumServer({@required Box<Node> nodes}) {
return nodes.values.firstWhere(
(Node node) => node.uri == cakeWalletLitecoinElectrumUri,
orElse: () => null) ??
nodes.values.firstWhere((node) => node.type == WalletType.litecoin,
orElse: () => null);
Node? getLitecoinDefaultElectrumServer({required Box<Node> nodes}) {
return nodes.values.firstWhereOrNull(
(Node node) => node.uriRaw == cakeWalletLitecoinElectrumUri)
?? nodes.values.firstWhereOrNull((node) => node.type == WalletType.litecoin);
}
Node getHavenDefaultNode({@required Box<Node> nodes}) {
return nodes.values.firstWhere(
(Node node) => node.uriRaw == havenDefaultNodeUri,
orElse: () => null) ??
nodes.values.firstWhere((node) => node.type == WalletType.haven,
orElse: () => null);
Node? getHavenDefaultNode({required Box<Node> nodes}) {
return nodes.values.firstWhereOrNull(
(Node node) => node.uriRaw == havenDefaultNodeUri)
?? nodes.values.firstWhereOrNull((node) => node.type == WalletType.haven);
}
Node getMoneroDefaultNode({@required Box<Node> nodes}) {
Node getMoneroDefaultNode({required Box<Node> nodes}) {
final timeZone = DateTime.now().timeZoneOffset.inHours;
var nodeUri = '';
@@ -214,14 +209,17 @@ Node getMoneroDefaultNode({@required Box<Node> nodes}) {
nodeUri = 'xmr-node-usa-east.cakewallet.com:18081';
}
return nodes.values
.firstWhere((Node node) => node.uri == nodeUri, orElse: () => null) ??
nodes.values.first;
try {
return nodes.values
.firstWhere((Node node) => node.uriRaw == nodeUri);
} catch(_) {
return nodes.values.first;
}
}
Future<void> changeBitcoinCurrentElectrumServerToDefault(
{@required SharedPreferences sharedPreferences,
@required Box<Node> nodes}) async {
{required SharedPreferences sharedPreferences,
required Box<Node> nodes}) async {
final server = getBitcoinDefaultElectrumServer(nodes: nodes);
final serverId = server?.key as int ?? 0;
@@ -229,8 +227,8 @@ Future<void> changeBitcoinCurrentElectrumServerToDefault(
}
Future<void> changeLitecoinCurrentElectrumServerToDefault(
{@required SharedPreferences sharedPreferences,
@required Box<Node> nodes}) async {
{required SharedPreferences sharedPreferences,
required Box<Node> nodes}) async {
final server = getLitecoinDefaultElectrumServer(nodes: nodes);
final serverId = server?.key as int ?? 0;
@@ -238,8 +236,8 @@ Future<void> changeLitecoinCurrentElectrumServerToDefault(
}
Future<void> changeHavenCurrentNodeToDefault(
{@required SharedPreferences sharedPreferences,
@required Box<Node> nodes}) async {
{required SharedPreferences sharedPreferences,
required Box<Node> nodes}) async {
final node = getHavenDefaultNode(nodes: nodes);
final nodeId = node?.key as int ?? 0;
@@ -247,8 +245,8 @@ Future<void> changeHavenCurrentNodeToDefault(
}
Future<void> replaceDefaultNode(
{@required SharedPreferences sharedPreferences,
@required Box<Node> nodes}) async {
{required SharedPreferences sharedPreferences,
required Box<Node> nodes}) async {
const nodesForReplace = <String>[
'xmr-node-uk.cakewallet.com:18081',
'eu-node.cakewallet.io:18081',
@@ -256,9 +254,9 @@ Future<void> replaceDefaultNode(
];
final currentNodeId = sharedPreferences.getInt('current_node_id');
final currentNode =
nodes.values.firstWhere((Node node) => node.key == currentNodeId);
nodes.values.firstWhereOrNull((Node node) => node.key == currentNodeId);
final needToReplace =
currentNode == null ? true : nodesForReplace.contains(currentNode.uri);
currentNode == null ? true : nodesForReplace.contains(currentNode.uriRaw);
if (!needToReplace) {
return;
@@ -268,7 +266,7 @@ Future<void> replaceDefaultNode(
sharedPreferences: sharedPreferences, nodes: nodes);
}
Future<void> updateNodeTypes({@required Box<Node> nodes}) async {
Future<void> updateNodeTypes({required Box<Node> nodes}) async {
nodes.values.forEach((node) async {
if (node.type == null) {
node.type = WalletType.monero;
@@ -277,17 +275,17 @@ Future<void> updateNodeTypes({@required Box<Node> nodes}) async {
});
}
Future<void> addBitcoinElectrumServerList({@required Box<Node> nodes}) async {
Future<void> addBitcoinElectrumServerList({required Box<Node> nodes}) async {
final serverList = await loadBitcoinElectrumServerList();
await nodes.addAll(serverList);
}
Future<void> addLitecoinElectrumServerList({@required Box<Node> nodes}) async {
Future<void> addLitecoinElectrumServerList({required Box<Node> nodes}) async {
final serverList = await loadLitecoinElectrumServerList();
await nodes.addAll(serverList);
}
Future<void> addHavenNodeList({@required Box<Node> nodes}) async {
Future<void> addHavenNodeList({required Box<Node> nodes}) async {
final nodeList = await loadDefaultHavenNodes();
await nodes.addAll(nodeList);
}
@@ -318,7 +316,7 @@ Future<void> addAddressesForMoneroWallets(
Future<void> updateDisplayModes(SharedPreferences sharedPreferences) async {
final currentBalanceDisplayMode =
sharedPreferences.getInt(PreferencesKey.currentBalanceDisplayModeKey);
sharedPreferences.getInt(PreferencesKey.currentBalanceDisplayModeKey) ?? -1;
final balanceDisplayMode = currentBalanceDisplayMode < 2 ? 3 : 2;
await sharedPreferences.setInt(
PreferencesKey.currentBalanceDisplayModeKey, balanceDisplayMode);
@@ -338,11 +336,11 @@ Future<void> generateBackupPassword(FlutterSecureStorage secureStorage) async {
Future<void> changeTransactionPriorityAndFeeRateKeys(
SharedPreferences sharedPreferences) async {
final legacyTransactionPriority = sharedPreferences
.getInt(PreferencesKey.currentTransactionPriorityKeyLegacy);
.getInt(PreferencesKey.currentTransactionPriorityKeyLegacy)!;
await sharedPreferences.setInt(
PreferencesKey.moneroTransactionPriority, legacyTransactionPriority);
await sharedPreferences.setInt(PreferencesKey.bitcoinTransactionPriority,
bitcoin.getMediumTransactionPriority().serialize());
bitcoin!.getMediumTransactionPriority().serialize());
}
Future<void> changeDefaultMoneroNode(
@@ -383,18 +381,14 @@ Future<void> checkCurrentNodes(
.getInt(PreferencesKey.currentLitecoinElectrumSererIdKey);
final currentHavenNodeId = sharedPreferences
.getInt(PreferencesKey.currentHavenNodeIdKey);
final currentMoneroNode = nodeSource.values.firstWhere(
(node) => node.key == currentMoneroNodeId,
orElse: () => null);
final currentBitcoinElectrumServer = nodeSource.values.firstWhere(
(node) => node.key == currentBitcoinElectrumSeverId,
orElse: () => null);
final currentLitecoinElectrumServer = nodeSource.values.firstWhere(
(node) => node.key == currentLitecoinElectrumSeverId,
orElse: () => null);
final currentHavenNodeServer = nodeSource.values.firstWhere(
(node) => node.key == currentHavenNodeId,
orElse: () => null);
final currentMoneroNode = nodeSource.values.firstWhereOrNull(
(node) => node.key == currentMoneroNodeId);
final currentBitcoinElectrumServer = nodeSource.values.firstWhereOrNull(
(node) => node.key == currentBitcoinElectrumSeverId);
final currentLitecoinElectrumServer = nodeSource.values.firstWhereOrNull(
(node) => node.key == currentLitecoinElectrumSeverId);
final currentHavenNodeServer = nodeSource.values.firstWhereOrNull(
(node) => node.key == currentHavenNodeId);
if (currentMoneroNode == null) {
final newCakeWalletNode =
@@ -435,12 +429,10 @@ Future<void> resetBitcoinElectrumServer(
Box<Node> nodeSource, SharedPreferences sharedPreferences) async {
final currentElectrumSeverId =
sharedPreferences.getInt(PreferencesKey.currentBitcoinElectrumSererIdKey);
final oldElectrumServer = nodeSource.values.firstWhere(
(node) => node.uri.toString().contains('electrumx.cakewallet.com'),
orElse: () => null);
var cakeWalletNode = nodeSource.values.firstWhere(
(node) => node.uri.toString() == cakeWalletBitcoinElectrumUri,
orElse: () => null);
final oldElectrumServer = nodeSource.values.firstWhereOrNull(
(node) => node.uri.toString().contains('electrumx.cakewallet.com'));
var cakeWalletNode = nodeSource.values.firstWhereOrNull(
(node) => node.uri.toString() == cakeWalletBitcoinElectrumUri);
if (cakeWalletNode == null) {
cakeWalletNode =
+13 -11
View File
@@ -1,8 +1,8 @@
import 'package:encrypt/encrypt.dart';
import 'package:password/password.dart';
// import 'package:password/password.dart';
import 'package:cake_wallet/.secrets.g.dart' as secrets;
String encrypt({String source, String key, int keyLength = 16}) {
String encrypt({required String source, required String key, int keyLength = 16}) {
final _key = Key.fromUtf8(key);
final iv = IV.fromLength(keyLength);
final encrypter = Encrypter(AES(_key));
@@ -11,7 +11,7 @@ String encrypt({String source, String key, int keyLength = 16}) {
return encrypted.base64;
}
String decrypt({String source, String key, int keyLength = 16}) {
String decrypt({required String source, required String key, int keyLength = 16}) {
final _key = Key.fromUtf8(key);
final iv = IV.fromLength(keyLength);
final encrypter = Encrypter(AES(_key));
@@ -20,33 +20,35 @@ String decrypt({String source, String key, int keyLength = 16}) {
return decrypted;
}
String hash({String source}) {
final algorithm = PBKDF2();
final hash = Password.hash(source, algorithm);
String hash({required String source}) {
// FIX-ME: Uninplemented
throw Exception('Unimplemented');
// final algorithm = PBKDF2();
// final hash = Password.hash(source, algorithm);
return hash;
// return hash;
}
String encodedPinCode({String pin}) {
String encodedPinCode({required String pin}) {
final source = '${secrets.salt}$pin';
return encrypt(source: source, key: secrets.key);
}
String decodedPinCode({String pin}) {
String decodedPinCode({required String pin}) {
final decrypted = decrypt(source: pin, key: secrets.key);
return decrypted.substring(secrets.key.length, decrypted.length);
}
String encodeWalletPassword({String password}) {
String encodeWalletPassword({required String password}) {
final source = password;
final _key = secrets.shortKey + secrets.walletSalt;
return encrypt(source: source, key: _key);
}
String decodeWalletPassword({String password}) {
String decodeWalletPassword({required String password}) {
final source = password;
final _key = secrets.shortKey + secrets.walletSalt;
+2 -2
View File
@@ -1,7 +1,7 @@
import 'package:cw_core/enumerable_item.dart';
class FiatCurrency extends EnumerableItem<String> with Serializable<String> {
const FiatCurrency({String symbol, this.countryCode, this.fullName}) : super(title: symbol, raw: symbol);
const FiatCurrency({required String symbol, required this.countryCode, required this.fullName}) : super(title: symbol, raw: symbol);
final String countryCode;
final String fullName;
@@ -81,7 +81,7 @@ class FiatCurrency extends EnumerableItem<String> with Serializable<String> {
FiatCurrency.vef.raw: FiatCurrency.vef
};
static FiatCurrency deserialize({String raw}) => _all[raw];
static FiatCurrency deserialize({required String raw}) => _all[raw]!;
@override
bool operator ==(Object other) => other is FiatCurrency && other.raw == raw;
+1 -1
View File
@@ -46,7 +46,7 @@ class FioAddressProvider {
}
if (response.statusCode != 200) {
return null;
throw Exception('Unexpected response http status: ${response.statusCode}');
}
final responseJSON = json.decode(response.body) as Map<String, dynamic>;
+53 -26
View File
@@ -1,5 +1,6 @@
import 'dart:io';
import 'dart:convert';
import 'package:collection/collection.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:hive/hive.dart';
@@ -61,31 +62,45 @@ Future<void> ios_migrate_user_defaults() async {
//should we provide default btc node key?
final activeCurrency = await ios_legacy_helper.getInt('currency');
final convertedCurrency = convertFiatLegacy(activeCurrency);
if (convertedCurrency != null) {
await prefs.setString(
if (activeCurrency != null) {
final convertedCurrency = convertFiatLegacy(activeCurrency);
if (convertedCurrency != null) {
await prefs.setString(
'current_fiat_currency', convertedCurrency.serialize());
}
}
//translate fee priority
final activeFeeTier = await ios_legacy_helper.getInt('saved_fee_priority');
await prefs.setInt('current_fee_priority', activeFeeTier);
if (activeFeeTier != null) {
await prefs.setInt('current_fee_priority', activeFeeTier);
}
//translate current balance mode
final currentBalanceMode =
await ios_legacy_helper.getInt('display_balance_mode');
await prefs.setInt('current_balance_display_mode', currentBalanceMode);
if (currentBalanceMode != null) {
await prefs.setInt('current_balance_display_mode', currentBalanceMode);
}
//translate should save recipient address
final shouldSave =
await ios_legacy_helper.getBool('should_save_recipient_address');
await prefs.setBool('save_recipient_address', shouldSave);
if (shouldSave != null) {
await prefs.setBool('save_recipient_address', shouldSave);
}
//translate biometric
final biometricOn =
await ios_legacy_helper.getBool('biometric_authentication_on');
await prefs.setBool('allow_biometrical_authentication', biometricOn);
if (biometricOn != null) {
await prefs.setBool('allow_biometrical_authentication', biometricOn);
}
//read the current theme as integer, write it back as a bool
final currentTheme = prefs.getInt('current-theme');
@@ -97,11 +112,17 @@ Future<void> ios_migrate_user_defaults() async {
//assign the pin length
final pinLength = await ios_legacy_helper.getInt('pin-length');
await prefs.setInt(PreferencesKey.currentPinLength, pinLength);
if (pinLength != null) {
await prefs.setInt(PreferencesKey.currentPinLength, pinLength);
}
//default value for display list key?
final walletName = await ios_legacy_helper.getString('current_wallet_name');
await prefs.setString('current_wallet_name', walletName);
if (walletName != null) {
await prefs.setString('current_wallet_name', walletName);
}
await prefs.setInt('current_wallet_type', serializeToInt(WalletType.monero));
@@ -117,7 +138,13 @@ Future<void> ios_migrate_pin() async {
final flutterSecureStorage = FlutterSecureStorage();
final pinPassword = await flutterSecureStorage.read(
key: 'pin_password', iOptions: IOSOptions(syncFlag: "syna"));
key: 'pin_password', iOptions: IOSOptions());
// No pin
if (pinPassword == null) {
await prefs.setBool('ios_migration_pin_completed', true);
return;
}
final key = generateStoreKeyFor(key: SecretStoreKey.pinCodePassword);
final encodedPassword = encodedPinCode(pin: pinPassword);
await flutterSecureStorage.write(key: key, value: encodedPassword);
@@ -148,9 +175,9 @@ Future<void> ios_migrate_wallet_passwords() async {
final name = item.path.split('/').last;
final oldKey = 'wallet_monero_' + name + '_password';
final password = await flutterSecureStorage.read(
key: oldKey, iOptions: IOSOptions(syncFlag: "syna"));
key: oldKey, iOptions: IOSOptions());
await keyService.saveWalletPassword(
walletName: name, password: password);
walletName: name, password: password!);
}
} catch (e) {
print(e.toString());
@@ -197,14 +224,14 @@ FiatCurrency convertFiatLegacy(int raw) {
32: 'zar',
33: 'vef'
};
final fiatAsString = _map[raw];
final fiatAsString = _map[raw]!;
return FiatCurrency.deserialize(raw: fiatAsString.toUpperCase());
}
Future<void> android_migrate_hives({Directory appDocDir}) async {
Future<void> android_migrate_hives({required Directory appDocDir}) async {
final dbDir = Directory('${appDocDir.path}/db');
final files = List<File>();
final files = <File>[];
appDocDir.listSync().forEach((FileSystemEntity item) {
final ext = item.path.split('.').last;
@@ -225,10 +252,10 @@ Future<void> android_migrate_hives({Directory appDocDir}) async {
});
}
Future<void> android_migrate_wallets({Directory appDocDir}) async {
Future<void> android_migrate_wallets({required Directory appDocDir}) async {
final walletsDir = Directory('${appDocDir.path}/wallets');
final moneroWalletsDir = Directory('${walletsDir.path}/monero');
final dirs = List<Directory>();
final dirs = <Directory>[];
appDocDir.listSync().forEach((FileSystemEntity item) {
final name = item.path.split('/').last;
@@ -292,9 +319,8 @@ Future<void> ios_migrate_wallet_info(Box<WalletInfo> walletsInfoSource) async {
'_' +
name;
final exist = walletsInfoSource.values
.firstWhere((el) => el.id == id, orElse: () => null) !=
null;
.firstWhereOrNull((el) => el.id == id) != null;
if (exist) {
return null;
}
@@ -307,7 +333,8 @@ Future<void> ios_migrate_wallet_info(Box<WalletInfo> walletsInfoSource) async {
restoreHeight: 0,
date: date,
dirPath: item.path,
path: '${item.path}/$name');
path: '${item.path}/$name',
address: '');
return walletInfo;
}
@@ -317,8 +344,8 @@ Future<void> ios_migrate_wallet_info(Box<WalletInfo> walletsInfoSource) async {
}
})
.where((el) => el != null)
.whereType<WalletInfo>()
.toList();
print(infoRecords);
await walletsInfoSource.addAll(infoRecords);
await prefs.setBool('ios_migration_wallet_info_completed', true);
} catch (e) {
@@ -346,8 +373,8 @@ Future<void> ios_migrate_trades_list(Box<Trade> tradeSource) async {
final content = file.readAsBytesSync();
final flutterSecureStorage = FlutterSecureStorage();
final masterPassword = await flutterSecureStorage.read(
key: 'master_password', iOptions: IOSOptions(syncFlag: "syna"));
final key = masterPassword.replaceAll('-', '');
key: 'master_password', iOptions: IOSOptions());
final key = masterPassword!.replaceAll('-', '');
final decoded =
await ios_legacy_helper.decrypt(content, key: key, salt: secrets.salt);
final decodedJson = json.decode(decoded) as List<dynamic>;
@@ -362,7 +389,7 @@ Future<void> ios_migrate_trades_list(Box<Trade> tradeSource) async {
final from = CryptoCurrency.fromString(fromAsString);
final timestamp = dateAsDouble.toInt() * 1000;
final date = DateTime.fromMillisecondsSinceEpoch(timestamp);
ExchangeProviderDescription provider;
ExchangeProviderDescription? provider;
switch (providerAsString.toLowerCase()) {
case 'changenow':
@@ -379,7 +406,7 @@ Future<void> ios_migrate_trades_list(Box<Trade> tradeSource) async {
}
return Trade(
id: tradeId, provider: provider, from: from, to: to, createdAt: date);
id: tradeId, provider: provider!, from: from, to: to, createdAt: date, amount: '');
});
await tradeSource.addAll(trades);
await prefs.setBool('ios_migration_trade_list_completed', true);
+1 -1
View File
@@ -2,7 +2,7 @@ import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:hive/hive.dart';
Future<List<int>> getEncryptionKey(
{String forKey, FlutterSecureStorage secureStorage}) async {
{required String forKey, required FlutterSecureStorage secureStorage}) async {
final stringifiedKey =
await secureStorage.read(key: 'transactionDescriptionsBoxKey');
List<int> key;
+10 -10
View File
@@ -7,19 +7,19 @@ const platform =
const MethodChannel('com.cakewallet.cakewallet/legacy_wallet_migration');
Future<String> decrypt(Uint8List bytes,
{@required String key, @required String salt}) async =>
await platform
.invokeMethod('decrypt', {'bytes': bytes, 'key': key, 'salt': salt});
{required String key, required String salt}) async =>
(await platform
.invokeMethod<String>('decrypt', {'bytes': bytes, 'key': key, 'salt': salt}))!;
Future<dynamic> readUserDefaults(String key, {@required String type}) async =>
Future<dynamic> readUserDefaults(String key, {required String type}) async =>
await platform
.invokeMethod<dynamic>('read_user_defaults', {'key': key, 'type': type});
Future<String> getString(String key) async =>
await readUserDefaults(key, type: 'string') as String;
Future<String?> getString(String key) async =>
await readUserDefaults(key, type: 'string') as String?;
Future<bool> getBool(String key) async =>
await readUserDefaults(key, type: 'bool') as bool;
Future<bool?> getBool(String key) async =>
await readUserDefaults(key, type: 'bool') as bool?;
Future<int> getInt(String key) async =>
await readUserDefaults(key, type: 'int') as int;
Future<int?> getInt(String key) async =>
await readUserDefaults(key, type: 'int') as int?;
+1 -1
View File
@@ -50,7 +50,7 @@ class LanguageService {
}
static Future<String> localeDetection() async {
var locale = await Devicelocale.currentLocale;
var locale = await Devicelocale.currentLocale ?? '';
locale = Intl.shortLocale(locale);
return list.keys.contains(locale) ? locale : 'en';
+5
View File
@@ -15,6 +15,11 @@ Future<void> loadCurrentWallet() async {
final typeRaw =
getIt.get<SharedPreferences>().getInt(PreferencesKey.currentWalletType) ??
0;
if (name == null) {
throw Exception('Incorrect current wallet name: $name');
}
final type = deserializeFromInt(typeRaw);
final walletLoadingService = getIt.get<WalletLoadingService>();
final wallet = await walletLoadingService.load(type, name);
+1 -1
View File
@@ -1,5 +1,5 @@
class MnemonicItem {
MnemonicItem({String text}) : _text = text;
MnemonicItem({required String text}) : _text = text;
String get text => _text;
String _text;
+34 -34
View File
@@ -6,68 +6,68 @@ import 'package:cw_core/wallet_type.dart';
Future<List<Node>> loadDefaultNodes() async {
final nodesRaw = await rootBundle.loadString('assets/node_list.yml');
final nodes = loadYaml(nodesRaw) as YamlList;
final loadedNodes = loadYaml(nodesRaw) as YamlList;
final nodes = <Node>[];
return nodes.map((dynamic raw) {
for (final raw in loadedNodes) {
if (raw is Map) {
final node = Node.fromMap(raw);
node?.type = WalletType.monero;
return node;
final node = Node.fromMap(raw as Map<String, Object>);
node.type = WalletType.monero;
nodes.add(node);
}
}
return null;
}).toList();
return nodes;
}
Future<List<Node>> loadBitcoinElectrumServerList() async {
final serverListRaw =
await rootBundle.loadString('assets/bitcoin_electrum_server_list.yml');
final serverList = loadYaml(serverListRaw) as YamlList;
final loadedServerList = loadYaml(serverListRaw) as YamlList;
final serverList = <Node>[];
return serverList.map((dynamic raw) {
if (raw is Map) {
final node = Node.fromMap(raw);
node?.type = WalletType.bitcoin;
return node;
for (final raw in loadedServerList) {
if (raw is Map) {
final node = Node.fromMap(raw as Map<String, Object>);
node.type = WalletType.bitcoin;
serverList.add(node);
}
}
return null;
}).toList();
return serverList;
}
Future<List<Node>> loadLitecoinElectrumServerList() async {
final serverListRaw =
await rootBundle.loadString('assets/litecoin_electrum_server_list.yml');
final serverList = loadYaml(serverListRaw) as YamlList;
final loadedServerList = loadYaml(serverListRaw) as YamlList;
final serverList = <Node>[];
return serverList.map((dynamic raw) {
for (final raw in loadedServerList) {
if (raw is Map) {
final node = Node.fromMap(raw);
node?.type = WalletType.litecoin;
return node;
final node = Node.fromMap(raw as Map<String, Object>);
node.type = WalletType.litecoin;
serverList.add(node);
}
}
return null;
}).toList();
return serverList;
}
Future<List<Node>> loadDefaultHavenNodes() async {
final nodesRaw = await rootBundle.loadString('assets/haven_node_list.yml');
final nodes = loadYaml(nodesRaw) as YamlList;
final loadedNodes = loadYaml(nodesRaw) as YamlList;
final nodes = <Node>[];
return nodes.map((dynamic raw) {
for (final raw in loadedNodes) {
if (raw is Map) {
final node = Node.fromMap(raw);
node?.type = WalletType.haven;
return node;
final node = Node.fromMap(raw as Map<String, Object>);
node.type = WalletType.haven;
nodes.add(node);
}
return null;
}).toList();
}
return nodes;
}
Future resetToDefault(Box<Node> nodeSource) async {
+5 -6
View File
@@ -1,12 +1,11 @@
import 'package:basic_utils/basic_utils.dart';
import 'package:cw_core/wallet_type.dart';
import 'package:flutter/material.dart';
class OpenaliasRecord {
OpenaliasRecord({
this.address,
this.name,
this.description,
required this.address,
required this.name,
required this.description,
});
final String name;
@@ -24,8 +23,8 @@ class OpenaliasRecord {
}
static Future<OpenaliasRecord> fetchAddressAndName({
@required String formattedName,
@required String ticker,
required String formattedName,
required String ticker,
}) async {
String address = formattedName;
String name = formattedName;
+1 -1
View File
@@ -9,7 +9,7 @@ import 'package:cake_wallet/entities/fio_address_provider.dart';
class AddressResolver {
AddressResolver({@required this.yatService, this.walletType});
AddressResolver({required this.yatService, required this.walletType});
final YatService yatService;
final WalletType walletType;
+16 -17
View File
@@ -6,47 +6,42 @@ enum ParseFrom { unstoppableDomains, openAlias, yatRecord, fio, notParsed }
class ParsedAddress {
ParsedAddress({
this.addresses,
required this.addresses,
this.name = '',
this.description = '',
this.parseFrom = ParseFrom.notParsed,
});
final List<String> addresses;
final String name;
final String description;
final ParseFrom parseFrom;
factory ParsedAddress.fetchEmojiAddress({
@required List<YatRecord> addresses,
@required String name,
List<YatRecord>? addresses,
required String name,
}){
if (addresses?.isEmpty ?? true) {
return ParsedAddress(
addresses: [name], parseFrom: ParseFrom.yatRecord);
}
}
return ParsedAddress(
addresses: addresses.map((e) => e.address).toList(),
addresses: addresses!.map((e) => e.address).toList(),
name: name,
parseFrom: ParseFrom.yatRecord,
);
}
factory ParsedAddress.fetchUnstoppableDomainAddress({
@required String address,
@required String name,
String? address,
required String name,
}){
if (address?.isEmpty ?? true) {
if (address?.isEmpty ?? true) {
return ParsedAddress(addresses: [name]);
}
return ParsedAddress(
addresses: [address],
addresses: [address!],
name: name,
parseFrom: ParseFrom.unstoppableDomains,
);
}
factory ParsedAddress.fetchOpenAliasAddress({@required OpenaliasRecord record, @required String name}){
factory ParsedAddress.fetchOpenAliasAddress({OpenaliasRecord? record, required String name}){
final formattedName = OpenaliasRecord.formatDomainName(name);
if (record == null || record.address.contains(formattedName)) {
return ParsedAddress(addresses: [name]);
@@ -59,12 +54,16 @@ class ParsedAddress {
);
}
factory ParsedAddress.fetchFioAddress({@required String address, @required String name}){
factory ParsedAddress.fetchFioAddress({required String address, required String name}){
return ParsedAddress(
addresses: [address],
name: name,
parseFrom: ParseFrom.fio,
);
}
final List<String> addresses;
final String name;
final String description;
final ParseFrom parseFrom;
}
+11 -9
View File
@@ -1,15 +1,17 @@
import 'package:barcode_scan/barcode_scan.dart';
// import 'package:barcode_scan/barcode_scan.dart';
var isQrScannerShown = false;
Future<String> presentQRScanner() async {
isQrScannerShown = true;
try {
final result = await BarcodeScanner.scan();
isQrScannerShown = false;
return result.rawContent;
} catch (e) {
isQrScannerShown = false;
rethrow;
}
// FIX-ME: BarcodeScanner
throw Exception('Unimplemented');
// try {
// final result = await BarcodeScanner.scan();
// isQrScannerShown = false;
// return result.rawContent;
// } catch (e) {
// isQrScannerShown = false;
// rethrow;
// }
}
+1 -1
View File
@@ -27,7 +27,7 @@ abstract class Record<T extends HiveObject> with Keyable {
final Box<T> _source;
StreamSubscription<BoxEvent> _listener;
StreamSubscription<BoxEvent>? _listener;
void fromBind(T original);
+1 -1
View File
@@ -5,7 +5,7 @@ const pinCodePassword = "PIN_CODE_PASSWORD";
const backupPassword = "BACKUP_CODE_PASSWORD";
String generateStoreKeyFor({
SecretStoreKey key,
required SecretStoreKey key,
String walletName = "",
}) {
var _key = "";
+8 -1
View File
@@ -4,7 +4,14 @@ part 'template.g.dart';
@HiveType(typeId: Template.typeId)
class Template extends HiveObject {
Template({this.name,this.isCurrencySelected, this.address, this.cryptoCurrency, this.amount, this.fiatCurrency, this.amountFiat});
Template({
required this.name,
required this.isCurrencySelected,
required this.address,
required this.cryptoCurrency,
required this.amount,
required this.fiatCurrency,
required this.amountFiat});
static const typeId = 6;
static const boxName = 'Template';
+3 -3
View File
@@ -4,7 +4,7 @@ part 'transaction_description.g.dart';
@HiveType(typeId: TransactionDescription.typeId)
class TransactionDescription extends HiveObject {
TransactionDescription({this.id, this.recipientAddress, this.transactionNote});
TransactionDescription({required this.id, this.recipientAddress, this.transactionNote});
static const typeId = 2;
static const boxName = 'TransactionDescriptions';
@@ -14,10 +14,10 @@ class TransactionDescription extends HiveObject {
String id;
@HiveField(1)
String recipientAddress;
String? recipientAddress;
@HiveField(2)
String transactionNote;
String? transactionNote;
String get note => transactionNote ?? '';
}
+3
View File
@@ -2,6 +2,9 @@ import 'package:mobx/mobx.dart';
import 'package:cw_core/transaction_info.dart';
abstract class TransactionHistory {
TransactionHistory()
: transactions = Observable<List<TransactionInfo>>([]);
Observable<List<TransactionInfo>> transactions;
Future<List<TransactionInfo>> getAll();
Future update();
+2 -2
View File
@@ -6,13 +6,13 @@ Future<String> fetchUnstoppableDomainAddress(String domain, String ticker) async
var address = '';
try {
address = await channel.invokeMethod(
address = await channel.invokeMethod<String>(
'getUnstoppableDomainAddress',
<String, String> {
'domain' : domain,
'ticker' : ticker
}
);
) ?? '';
} catch (e) {
print('Unstoppable domain error: ${e.toString()}');
address = '';
+17 -12
View File
@@ -4,18 +4,23 @@ import 'package:cw_core/monero_amount_format.dart';
import 'package:cake_wallet/haven/haven.dart';
Future<void> updateHavenRate(FiatConversionStore fiatConversionStore) async {
final rate = haven.getAssetRate();
final base = rate.firstWhere((row) => row.asset == 'XUSD', orElse: () => null);
rate.forEach((row) {
final cur = CryptoCurrency.fromString(row.asset);
final baseRate = moneroAmountToDouble(amount: base.rate);
final rowRate = moneroAmountToDouble(amount: row.rate);
try {
final rate = haven!.getAssetRate();
final base = rate.firstWhere((row) => row.asset == 'XUSD');
if (cur == CryptoCurrency.xusd) {
fiatConversionStore.prices[cur] = 1.0;
return;
}
rate.forEach((row) {
final cur = CryptoCurrency.fromString(row.asset);
final baseRate = moneroAmountToDouble(amount: base.rate);
final rowRate = moneroAmountToDouble(amount: row.rate);
fiatConversionStore.prices[cur] = baseRate / rowRate;
});
if (cur == CryptoCurrency.xusd) {
fiatConversionStore.prices[cur] = 1.0;
return;
}
fiatConversionStore.prices[cur] = baseRate / rowRate;
});
} catch(_) {
// FIX-ME: handle exception
}
}
+1
View File
@@ -3,6 +3,7 @@ import 'package:cw_core/crypto_currency.dart';
class WalletContact implements ContactBase {
WalletContact(this.address, this.name, this.type);
//: super(name, address, type);
@override
String address;
+1 -1
View File
@@ -1,7 +1,7 @@
import 'package:cw_core/wallet_type.dart';
class WalletDescription {
WalletDescription({this.name, this.type});
WalletDescription({required this.name, required this.type});
final String name;
final WalletType type;
+7 -10
View File
@@ -1,16 +1,13 @@
class YatRecord {
String category;
String address;
YatRecord({
this.category,
this.address,
required this.category,
required this.address,
});
YatRecord.fromJson(Map<String, dynamic> json) {
address = json['address'] as String;
category = json['category'] as String;
}
YatRecord.fromJson(Map<String, dynamic> json)
: address = json['address'] as String,
category = json['category'] as String;
String category;
String address;
}