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
+2 -2
View File
@@ -1,7 +1,7 @@
class Account {
Account({this.id, this.label});
Account({required this.id, required this.label});
Account.fromMap(Map map)
Account.fromMap(Map<String, Object> map)
: this.id = map['id'] == null ? 0 : int.parse(map['id'] as String),
this.label = (map['label'] ?? '') as String;
+2 -2
View File
@@ -8,9 +8,9 @@ abstract class AccountList<T> {
List<T> getAll();
Future addAccount({String label});
Future<void> addAccount({required String label});
Future setLabelAccount({int accountIndex, String label});
Future<void> setLabelAccount({required int accountIndex, required String label});
void refresh();
}
+1 -1
View File
@@ -1 +1 @@
double cryptoAmountToDouble({num amount, num divider}) => amount / divider;
double cryptoAmountToDouble({required num amount, required num divider}) => amount / divider;
+12 -10
View File
@@ -5,12 +5,17 @@ part 'crypto_currency.g.dart';
@HiveType(typeId: 0)
class CryptoCurrency extends EnumerableItem<int> with Serializable<int> {
const CryptoCurrency({final String title, this.tag, this.name, this.iconPath, final int raw})
const CryptoCurrency({
String title = '',
int raw = -1,
this.name,
this.iconPath,
this.tag,})
: super(title: title, raw: raw);
final String tag;
final String name;
final String iconPath;
final String? tag;
final String? name;
final String? iconPath;
static const all = [
CryptoCurrency.xmr,
@@ -97,10 +102,7 @@ class CryptoCurrency extends EnumerableItem<int> with Serializable<int> {
static const zen = CryptoCurrency(title: 'ZEN', iconPath: 'assets/images/zen_icon.png', raw: 44);
static const xvg = CryptoCurrency(title: 'XVG', name: 'Verge', iconPath: 'assets/images/xvg_icon.png', raw: 45);
static CryptoCurrency deserialize({int raw}) {
static CryptoCurrency deserialize({required int raw}) {
switch (raw) {
case 0:
return CryptoCurrency.xmr;
@@ -195,7 +197,7 @@ class CryptoCurrency extends EnumerableItem<int> with Serializable<int> {
case 45:
return CryptoCurrency.xvg;
default:
return null;
throw Exception('Unexpected token: $raw for CryptoCurrency deserialize');
}
}
@@ -294,7 +296,7 @@ class CryptoCurrency extends EnumerableItem<int> with Serializable<int> {
case 'xvg':
return CryptoCurrency.xvg;
default:
return null;
throw Exception('Unexpected token: $raw for CryptoCurrency fromString');
}
}
+1 -1
View File
@@ -12,6 +12,6 @@ CryptoCurrency currencyForWalletType(WalletType type) {
case WalletType.haven:
return CryptoCurrency.xhv;
default:
return null;
throw Exception('Unexpected wallet type: ${type.toString()} for CryptoCurrency currencyForWalletType');
}
}
+2 -2
View File
@@ -1,7 +1,7 @@
import 'package:flutter/foundation.dart';
abstract class EnumerableItem<T> {
const EnumerableItem({@required this.title, @required this.raw});
const EnumerableItem({required this.title, required this.raw});
final T raw;
final String title;
@@ -11,6 +11,6 @@ abstract class EnumerableItem<T> {
}
mixin Serializable<T> on EnumerableItem<T> {
static Serializable deserialize<T>({T raw}) => null;
static Serializable deserialize<T>({required T raw}) => throw Exception('Unimplemented');
T serialize() => raw;
}
+2 -2
View File
@@ -85,7 +85,7 @@ final dates = {
"2020-11": 2220000
};
int getMoneroHeigthByDate({DateTime date}) {
int getMoneroHeigthByDate({required DateTime date}) {
final raw = '${date.year}' + '-' + '${date.month}';
final lastHeight = dates.values.last;
int startHeight;
@@ -105,7 +105,7 @@ int getMoneroHeigthByDate({DateTime date}) {
final daysHeight = (differenceInDays * heightPerDay).round();
height = endHeight + daysHeight;
} else {
startHeight = dates[raw];
startHeight = dates[raw]!;
final index = dates.values.toList().indexOf(startHeight);
endHeight = dates.values.toList()[index + 1];
final heightPerDay = ((endHeight - startHeight) / 31).round();
+2 -2
View File
@@ -16,14 +16,14 @@ List<String> extractKeys(String key) {
return [_key, iv];
}
Future<String> encode({encrypt.Key key, encrypt.IV iv, String data}) async {
Future<String> encode({required encrypt.Key key, required encrypt.IV iv, required String data}) async {
final encrypter = encrypt.Encrypter(encrypt.Salsa20(key));
final encrypted = encrypter.encrypt(data, iv: iv);
return encrypted.base64;
}
Future<String> decode({String password, String data}) async {
Future<String> decode({required String password, required String data}) async {
final keys = extractKeys(password);
final key = encrypt.Key.fromBase64(keys.first);
final iv = encrypt.IV.fromBase64(keys.last);
+3 -3
View File
@@ -7,12 +7,12 @@ final moneroAmountFormat = NumberFormat()
..maximumFractionDigits = moneroAmountLength
..minimumFractionDigits = 1;
String moneroAmountToString({int amount}) => moneroAmountFormat
String moneroAmountToString({required int amount}) => moneroAmountFormat
.format(cryptoAmountToDouble(amount: amount, divider: moneroAmountDivider))
.replaceAll(',', '');
double moneroAmountToDouble({int amount}) =>
double moneroAmountToDouble({required int amount}) =>
cryptoAmountToDouble(amount: amount, divider: moneroAmountDivider);
int moneroParseAmount({String amount}) =>
int moneroParseAmount({required String amount}) =>
(double.parse(amount) * moneroAmountDivider).toInt();
+3 -4
View File
@@ -1,17 +1,16 @@
import 'package:cw_core/balance.dart';
import 'package:flutter/foundation.dart';
import 'package:cw_core/monero_amount_format.dart';
class MoneroBalance extends Balance {
MoneroBalance({@required this.fullBalance, @required this.unlockedBalance})
MoneroBalance({required this.fullBalance, required this.unlockedBalance})
: formattedFullBalance = moneroAmountToString(amount: fullBalance),
formattedUnlockedBalance =
moneroAmountToString(amount: unlockedBalance),
super(unlockedBalance, fullBalance);
MoneroBalance.fromString(
{@required this.formattedFullBalance,
@required this.formattedUnlockedBalance})
{required this.formattedFullBalance,
required this.formattedUnlockedBalance})
: fullBalance = moneroParseAmount(amount: formattedFullBalance),
unlockedBalance = moneroParseAmount(amount: formattedUnlockedBalance),
super(moneroParseAmount(amount: formattedUnlockedBalance),
+3 -3
View File
@@ -4,7 +4,7 @@ import 'package:cw_core/wallet_type.dart';
import 'package:cw_core/enumerable_item.dart';
class MoneroTransactionPriority extends TransactionPriority {
const MoneroTransactionPriority({String title, int raw})
const MoneroTransactionPriority({required String title, required int raw})
: super(title: title, raw: raw);
static const all = [
@@ -37,7 +37,7 @@ class MoneroTransactionPriority extends TransactionPriority {
}
}
static MoneroTransactionPriority deserialize({int raw}) {
static MoneroTransactionPriority deserialize({required int raw}) {
switch (raw) {
case 0:
return slow;
@@ -50,7 +50,7 @@ class MoneroTransactionPriority extends TransactionPriority {
case 4:
return fastest;
default:
return null;
throw Exception('Unexpected token: $raw for MoneroTransactionPriority deserialize');
}
}
+4 -4
View File
@@ -1,9 +1,9 @@
class MoneroWalletKeys {
const MoneroWalletKeys(
{this.privateSpendKey,
this.privateViewKey,
this.publicSpendKey,
this.publicViewKey});
{required this.privateSpendKey,
required this.privateViewKey,
required this.publicSpendKey,
required this.publicViewKey});
final String publicViewKey;
final String privateViewKey;
+19 -18
View File
@@ -1,7 +1,5 @@
import 'dart:io';
import 'package:cw_core/keyable.dart';
import 'package:flutter/foundation.dart';
import 'dart:convert';
import 'package:http/http.dart' as http;
import 'package:hive/hive.dart';
@@ -11,22 +9,26 @@ import 'package:http/io_client.dart' as ioc;
part 'node.g.dart';
Uri createUriFromElectrumAddress(String address) =>
Uri.tryParse('tcp://$address');
Uri.tryParse('tcp://$address')!;
@HiveType(typeId: Node.typeId)
class Node extends HiveObject with Keyable {
Node(
{@required String uri,
@required WalletType type,
this.login,
{this.login,
this.password,
this.useSSL}) {
uriRaw = uri;
this.type = type;
this.useSSL,
String? uri,
WalletType? type,}) {
if (uri != null) {
uriRaw = uri;
}
if (type != null) {
this.type = type;
}
}
Node.fromMap(Map map)
: uriRaw = map['uri'] as String ?? '',
Node.fromMap(Map<String, Object?> map)
: uriRaw = map['uri'] as String? ?? '',
login = map['login'] as String,
password = map['password'] as String,
typeRaw = map['typeRaw'] as int,
@@ -36,19 +38,19 @@ class Node extends HiveObject with Keyable {
static const boxName = 'Nodes';
@HiveField(0)
String uriRaw;
late String uriRaw;
@HiveField(1)
String login;
String? login;
@HiveField(2)
String password;
String? password;
@HiveField(3)
int typeRaw;
late int typeRaw;
@HiveField(4)
bool useSSL;
bool? useSSL;
bool get isSSL => useSSL ?? false;
@@ -63,7 +65,7 @@ class Node extends HiveObject with Keyable {
case WalletType.haven:
return Uri.http(uriRaw, '');
default:
return null;
throw Exception('Unexpected type ${type.toString()} for Node uri');
}
}
@@ -99,7 +101,6 @@ class Node extends HiveObject with Keyable {
}
Future<bool> requestMoneroNode() async {
final path = '/json_rpc';
final rpcUri = isSSL ? Uri.https(uri.authority, path) : Uri.http(uri.authority, path);
final realm = 'monero-rpc';
+13 -13
View File
@@ -1,20 +1,20 @@
class OutputInfo {
const OutputInfo(
{this.fiatAmount,
this.cryptoAmount,
this.address,
this.note,
this.sendAll,
this.extractedAddress,
this.isParsedAddress,
this.formattedCryptoAmount});
{required this.address,
required this.sendAll,
required this.isParsedAddress,
this.cryptoAmount,
this.formattedCryptoAmount,
this.fiatAmount,
this.note,
this.extractedAddress,});
final String fiatAmount;
final String cryptoAmount;
final String? fiatAmount;
final String? cryptoAmount;
final String address;
final String note;
final String extractedAddress;
final String? note;
final String? extractedAddress;
final bool sendAll;
final bool isParsedAddress;
final int formattedCryptoAmount;
final int? formattedCryptoAmount;
}
+3 -3
View File
@@ -3,7 +3,7 @@ import 'package:cw_core/wallet_type.dart';
import 'package:flutter/foundation.dart';
import 'package:path_provider/path_provider.dart';
Future<String> pathForWalletDir({@required String name, @required WalletType type}) async {
Future<String> pathForWalletDir({required String name, required WalletType type}) async {
final root = await getApplicationDocumentsDirectory();
final prefix = walletTypeToString(type).toLowerCase();
final walletsDir = Directory('${root.path}/wallets');
@@ -16,11 +16,11 @@ Future<String> pathForWalletDir({@required String name, @required WalletType ty
return walletDire.path;
}
Future<String> pathForWallet({@required String name, @required WalletType type}) async =>
Future<String> pathForWallet({required String name, required WalletType type}) async =>
await pathForWalletDir(name: name, type: type)
.then((path) => path + '/$name');
Future<String> outdatedAndroidPathForWalletDir({String name}) async {
Future<String> outdatedAndroidPathForWalletDir({required String name}) async {
final directory = await getApplicationDocumentsDirectory();
final pathDir = directory.path + '/$name';
+1 -1
View File
@@ -6,7 +6,7 @@ const utils = const MethodChannel('com.cake_wallet/native_utils');
Future<Uint8List> secRandom(int count) async {
try {
return await utils.invokeMethod<Uint8List>('sec_random', {'count': count});
return await utils.invokeMethod<Uint8List>('sec_random', {'count': count}) ?? Uint8List.fromList([]);
} on PlatformException catch (_) {
return Uint8List.fromList([]);
}
+2 -2
View File
@@ -1,7 +1,7 @@
class Subaddress {
Subaddress({this.id, this.address, this.label});
Subaddress({required this.id, required this.address, required this.label});
Subaddress.fromMap(Map map)
Subaddress.fromMap(Map<String, Object?> map)
: this.id = map['id'] == null ? 0 : int.parse(map['id'] as String),
this.address = (map['address'] ?? '') as String,
this.label = (map['label'] ?? '') as String;
+12 -6
View File
@@ -2,16 +2,22 @@ enum TransactionDirection { incoming, outgoing }
TransactionDirection parseTransactionDirectionFromInt(int raw) {
switch (raw) {
case 0: return TransactionDirection.incoming;
case 1: return TransactionDirection.outgoing;
default: return null;
case 0:
return TransactionDirection.incoming;
case 1:
return TransactionDirection.outgoing;
default:
throw Exception('Unexpected token: raw for TransactionDirection parseTransactionDirectionFromInt');
}
}
TransactionDirection parseTransactionDirectionFromNumber(String raw) {
switch (raw) {
case "0": return TransactionDirection.incoming;
case "1": return TransactionDirection.outgoing;
default: return null;
case "0":
return TransactionDirection.incoming;
case "1":
return TransactionDirection.outgoing;
default:
throw Exception('Unexpected token: raw for TransactionDirection parseTransactionDirectionFromNumber');
}
}
+2 -3
View File
@@ -1,10 +1,9 @@
import 'package:flutter/foundation.dart';
import 'package:mobx/mobx.dart';
import 'package:cw_core/transaction_info.dart';
abstract class TransactionHistoryBase<TransactionType extends TransactionInfo> {
TransactionHistoryBase();
// : _isUpdating = false;
TransactionHistoryBase()
: transactions = ObservableMap<String, TransactionType>();
@observable
ObservableMap<String, TransactionType> transactions;
+10 -10
View File
@@ -2,21 +2,21 @@ import 'package:cw_core/transaction_direction.dart';
import 'package:cw_core/keyable.dart';
abstract class TransactionInfo extends Object with Keyable {
String id;
int amount;
int fee;
TransactionDirection direction;
bool isPending;
DateTime date;
int height;
int confirmations;
late String id;
late int amount;
int? fee;
late TransactionDirection direction;
late bool isPending;
late DateTime date;
late int height;
late int confirmations;
String amountFormatted();
String fiatAmount();
String feeFormatted();
String? feeFormatted();
void changeFiatAmount(String amount);
@override
dynamic get keyIndex => id;
Map<String, dynamic> additionalInfo;
late Map<String, dynamic> additionalInfo;
}
+1 -1
View File
@@ -2,5 +2,5 @@ import 'package:cw_core/enumerable_item.dart';
abstract class TransactionPriority extends EnumerableItem<int>
with Serializable<int> {
const TransactionPriority({String title, int raw}) : super(title: title, raw: raw);
const TransactionPriority({required String title, required int raw}) : super(title: title, raw: raw);
}
+5 -5
View File
@@ -5,11 +5,11 @@ part 'unspent_coins_info.g.dart';
@HiveType(typeId: UnspentCoinsInfo.typeId)
class UnspentCoinsInfo extends HiveObject {
UnspentCoinsInfo({
this.walletId,
this.hash,
this.isFrozen,
this.isSending,
this.note});
required this.walletId,
required this.hash,
required this.isFrozen,
required this.isSending,
required this.note});
static const typeId = 9;
static const boxName = 'Unspent';
+2 -7
View File
@@ -1,9 +1,8 @@
import 'package:cw_core/wallet_info.dart';
abstract class WalletAddresses {
WalletAddresses(this.walletInfo) {
addressesMap = {};
}
WalletAddresses(this.walletInfo)
: addressesMap = {};
final WalletInfo walletInfo;
@@ -19,10 +18,6 @@ abstract class WalletAddresses {
Future<void> saveAddressesInBox() async {
try {
if (walletInfo == null) {
return;
}
walletInfo.address = address;
walletInfo.addresses = addressesMap;
@@ -5,9 +5,9 @@ import 'package:cw_core/wallet_info.dart';
abstract class WalletAddressesWithAccount<T> extends WalletAddresses {
WalletAddressesWithAccount(WalletInfo walletInfo) : super(walletInfo);
T get account;
// T get account;
set account(T account);
// set account(T account);
AccountList<T> get accountList;
}
+5 -5
View File
@@ -1,12 +1,12 @@
import 'package:mobx/mobx.dart';
import 'package:cw_core/balance.dart';
import 'package:cw_core/transaction_info.dart';
import 'package:cw_core/transaction_history.dart';
import 'package:cw_core/transaction_priority.dart';
import 'package:cw_core/wallet_addresses.dart';
import 'package:flutter/foundation.dart';
import 'package:cw_core/wallet_info.dart';
import 'package:cw_core/pending_transaction.dart';
import 'package:cw_core/transaction_history.dart';
import 'package:cw_core/currency_for_wallet_type.dart';
import 'package:cw_core/crypto_currency.dart';
import 'package:cw_core/sync_status.dart';
@@ -48,15 +48,15 @@ abstract class WalletBase<
WalletAddresses get walletAddresses;
HistoryType transactionHistory;
late HistoryType transactionHistory;
Future<void> connectToNode({@required Node node});
Future<void> connectToNode({required Node node});
Future<void> startSync();
Future<PendingTransaction> createTransaction(Object credentials);
int calculateEstimatedFee(TransactionPriority priority, int amount);
int calculateEstimatedFee(TransactionPriority priority, int? amount);
// void fetchTransactionsAsync(
// void Function(TransactionType transaction) onTransactionLoaded,
@@ -66,7 +66,7 @@ abstract class WalletBase<
Future<void> save();
Future<void> rescan({int height});
Future<void> rescan({required int height});
void close();
+8 -4
View File
@@ -1,10 +1,14 @@
import 'package:cw_core/wallet_info.dart';
abstract class WalletCredentials {
WalletCredentials({this.name, this.password, this.height, this.walletInfo});
WalletCredentials({
required this.name,
this.height,
this.walletInfo,
this.password});
final String name;
final int height;
String password;
WalletInfo walletInfo;
final int? height;
String? password;
WalletInfo? walletInfo;
}
+15 -15
View File
@@ -13,20 +13,20 @@ class WalletInfo extends HiveObject {
: _yatLastUsedAddressController = StreamController<String>.broadcast();
factory WalletInfo.external(
{@required String id,
@required String name,
@required WalletType type,
@required bool isRecovery,
@required int restoreHeight,
@required DateTime date,
@required String dirPath,
@required String path,
@required String address,
{required String id,
required String name,
required WalletType type,
required bool isRecovery,
required int restoreHeight,
required DateTime date,
required String dirPath,
required String path,
required String address,
bool? showIntroCakePayCard,
String yatEid ='',
String yatLastUsedAddressRaw = '',
bool showIntroCakePayCard}) {
String yatLastUsedAddressRaw = ''}) {
return WalletInfo(id, name, type, isRecovery, restoreHeight,
date.millisecondsSinceEpoch ?? 0, dirPath, path, address,
date.millisecondsSinceEpoch, dirPath, path, address,
yatEid, yatLastUsedAddressRaw, showIntroCakePayCard);
}
@@ -61,7 +61,7 @@ class WalletInfo extends HiveObject {
String address;
@HiveField(10)
Map<String, String> addresses;
Map<String, String>? addresses;
@HiveField(11)
String yatEid;
@@ -70,7 +70,7 @@ class WalletInfo extends HiveObject {
String yatLastUsedAddressRaw;
@HiveField(13)
bool showIntroCakePayCard;
bool? showIntroCakePayCard;
String get yatLastUsedAddress => yatLastUsedAddressRaw;
@@ -85,7 +85,7 @@ class WalletInfo extends HiveObject {
if(showIntroCakePayCard == null) {
return type != WalletType.haven;
}
return showIntroCakePayCard;
return showIntroCakePayCard!;
}
DateTime get date => DateTime.fromMillisecondsSinceEpoch(timestamp);
+2 -2
View File
@@ -55,7 +55,7 @@ WalletType deserializeFromInt(int raw) {
case 3:
return WalletType.haven;
default:
return null;
throw Exception('Unexpected token: $raw for WalletType deserializeFromInt');
}
}
@@ -100,6 +100,6 @@ CryptoCurrency walletTypeToCryptoCurrency(WalletType type) {
case WalletType.haven:
return CryptoCurrency.xhv;
default:
return null;
throw Exception('Unexpected wallet type: ${type.toString()} for CryptoCurrency walletTypeToCryptoCurrency');
}
}