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
@@ -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);
@@ -16,12 +16,13 @@ import 'package:mobx/mobx.dart';
part 'balance_view_model.g.dart';
class BalanceRecord {
const BalanceRecord({this.availableBalance,
this.additionalBalance,
this.fiatAvailableBalance,
this.fiatAdditionalBalance,
this.asset,
this.formattedAssetTitle});
const BalanceRecord({
required this.availableBalance,
required this.additionalBalance,
required this.fiatAvailableBalance,
required this.fiatAdditionalBalance,
required this.asset,
required this.formattedAssetTitle});
final String fiatAdditionalBalance;
final String fiatAvailableBalance;
final String additionalBalance;
@@ -34,12 +35,12 @@ class BalanceViewModel = BalanceViewModelBase with _$BalanceViewModel;
abstract class BalanceViewModelBase with Store {
BalanceViewModelBase(
{@required this.appStore,
@required this.settingsStore,
@required this.fiatConvertationStore}) {
isReversing = false;
wallet ??= appStore.wallet;
isShowCard = wallet.walletInfo.isShowIntroCakePayCard;
{required this.appStore,
required this.settingsStore,
required this.fiatConvertationStore})
: isReversing = false,
isShowCard = appStore.wallet!.walletInfo.isShowIntroCakePayCard,
wallet = appStore.wallet! {
reaction((_) => appStore.wallet, _onWalletChange);
}
@@ -57,14 +58,22 @@ abstract class BalanceViewModelBase with Store {
wallet;
@computed
double get price => fiatConvertationStore.prices[appStore.wallet.currency];
double get price {
final price = fiatConvertationStore.prices[appStore.wallet!.currency];
if (price == null) {
throw Exception('No price for ${appStore.wallet!.currency} (current wallet)');
}
return price;
}
@computed
BalanceDisplayMode get savedDisplayMode => settingsStore.balanceDisplayMode;
@computed
String get asset {
final typeFormatted = walletTypeToString(appStore.wallet.type);
final typeFormatted = walletTypeToString(appStore.wallet!.type);
switch(wallet.type) {
case WalletType.haven:
@@ -110,7 +119,7 @@ abstract class BalanceViewModelBase with Store {
}
@computed
bool get hasMultiBalance => appStore.wallet.type == WalletType.haven;
bool get hasMultiBalance => appStore.wallet!.type == WalletType.haven;
@computed
String get availableBalance {
@@ -177,16 +186,22 @@ abstract class BalanceViewModelBase with Store {
formattedAssetTitle: _formatterAsset(key)));
}
final fiatCurrency = settingsStore.fiatCurrency;
final price = fiatConvertationStore.prices[key] ?? 0;
// if (price == null) {
// throw Exception('Price is null for: $key');
// }
final additionalFiatBalance = fiatCurrency.toString()
+ ' '
+ _getFiatBalance(
price: fiatConvertationStore.prices[key],
price: price,
cryptoAmount: value.formattedAdditionalBalance);
final availableFiatBalance = fiatCurrency.toString()
+ ' '
+ _getFiatBalance(
price: fiatConvertationStore.prices[key],
price: price,
cryptoAmount: value.formattedAvailableBalance);
return MapEntry(key, BalanceRecord(
@@ -231,23 +246,35 @@ abstract class BalanceViewModelBase with Store {
}
@computed
Balance get _walletBalance => wallet.balance[wallet.currency];
Balance get _walletBalance {
final balance = wallet.balance[wallet.currency];
if (balance == null) {
throw Exception('No balance for ${wallet.currency}');
}
return balance;
}
@computed
CryptoCurrency get currency => appStore.wallet.currency;
CryptoCurrency get currency => appStore.wallet!.currency;
@observable
bool isShowCard;
ReactionDisposer _onCurrentWalletChangeReaction;
ReactionDisposer? _onCurrentWalletChangeReaction;
@action
void _onWalletChange(
WalletBase<Balance, TransactionHistoryBase<TransactionInfo>,
TransactionInfo>
TransactionInfo>?
wallet) {
this.wallet = wallet;
_onCurrentWalletChangeReaction?.reaction?.dispose();
if (wallet == null) {
return;
}
this.wallet = wallet;
_onCurrentWalletChangeReaction?.reaction.dispose();
isShowCard = wallet.walletInfo.isShowIntroCakePayCard;
}
@@ -259,7 +286,7 @@ abstract class BalanceViewModelBase with Store {
isShowCard = cardDisplayStatus;
}
String _getFiatBalance({double price, String cryptoAmount}) {
String _getFiatBalance({required double price, String? cryptoAmount}) {
if (cryptoAmount == null) {
return '0.00';
}
@@ -39,14 +39,24 @@ class DashboardViewModel = DashboardViewModelBase with _$DashboardViewModel;
abstract class DashboardViewModelBase with Store {
DashboardViewModelBase(
{this.balanceViewModel,
this.appStore,
this.tradesStore,
this.tradeFilterStore,
this.transactionFilterStore,
this.settingsStore,
this.yatStore,
this.ordersStore}) {
{required this.balanceViewModel,
required this.appStore,
required this.tradesStore,
required this.tradeFilterStore,
required this.transactionFilterStore,
required this.settingsStore,
required this.yatStore,
required this.ordersStore})
: isOutdatedElectrumWallet = false,
hasSellAction = false,
isEnabledSellAction = false,
hasBuyAction = false,
isEnabledBuyAction = false,
hasExchangeAction = false,
isEnabledExchangeAction = false,
isShowFirstYatIntroduction = false,
isShowSecondYatIntroduction = false,
isShowThirdYatIntroduction = false,
filterItems = {
S.current.transactions: [
FilterItem(
@@ -69,10 +79,13 @@ abstract class DashboardViewModelBase with Store {
onChanged: (value) => tradeFilterStore
.toggleDisplayExchange(ExchangeProviderDescription.changeNow)),
]
};
name = appStore.wallet?.name;
wallet ??= appStore.wallet;
},
subname = '',
name = appStore.wallet!.name,
type = appStore.wallet!.type,
transactions = ObservableList<TransactionListItem>(),
wallet = appStore.wallet! {
name = wallet.name;
type = wallet.type;
isOutdatedElectrumWallet =
wallet.type == WalletType.bitcoin && wallet.seed.split(' ').length < 24;
@@ -84,17 +97,17 @@ abstract class DashboardViewModelBase with Store {
final _wallet = wallet;
if (_wallet.type == WalletType.monero) {
subname = monero.getCurrentAccount(_wallet)?.label;
subname = monero!.getCurrentAccount(_wallet).label;
_onMoneroAccountChangeReaction = reaction((_) => monero.getMoneroWalletDetails(wallet)
_onMoneroAccountChangeReaction = reaction((_) => monero!.getMoneroWalletDetails(wallet)
.account, (Account account) => _onMoneroAccountChange(_wallet));
_onMoneroBalanceChangeReaction = reaction((_) => monero.getMoneroWalletDetails(wallet).balance,
_onMoneroBalanceChangeReaction = reaction((_) => monero!.getMoneroWalletDetails(wallet).balance,
(MoneroBalance balance) => _onMoneroTransactionsUpdate(_wallet));
final _accountTransactions = _wallet
.transactionHistory.transactions.values
.where((tx) => monero.getTransactionInfoAccountId(tx) == monero.getCurrentAccount(wallet).id)
.where((tx) => monero!.getTransactionInfoAccountId(tx) == monero!.getCurrentAccount(wallet).id)
.toList();
transactions = ObservableList.of(_accountTransactions.map((transaction) =>
@@ -114,19 +127,23 @@ abstract class DashboardViewModelBase with Store {
reaction((_) => appStore.wallet, _onWalletChange);
connectMapToListWithTransform(
appStore.wallet.transactionHistory.transactions,
appStore.wallet!.transactionHistory.transactions,
transactions,
(TransactionInfo val) => TransactionListItem(
transaction: val,
(TransactionInfo? transaction) => TransactionListItem(
transaction: transaction!,
balanceViewModel: balanceViewModel,
settingsStore: appStore.settingsStore),
filter: (TransactionInfo tx) {
final wallet = _wallet;
if (wallet.type == WalletType.monero) {
return monero.getTransactionInfoAccountId(tx) == monero.getCurrentAccount(wallet).id;
}
filter: (TransactionInfo? transaction) {
if (transaction == null) {
return false;
}
return true;
final wallet = _wallet;
if (wallet.type == WalletType.monero) {
return monero!.getTransactionInfoAccountId(transaction) == monero!.getCurrentAccount(wallet).id;
}
return true;
});
}
@@ -250,9 +267,9 @@ abstract class DashboardViewModelBase with Store {
@observable
bool hasSellAction;
ReactionDisposer _onMoneroAccountChangeReaction;
ReactionDisposer? _onMoneroAccountChangeReaction;
ReactionDisposer _onMoneroBalanceChangeReaction;
ReactionDisposer? _onMoneroBalanceChangeReaction;
@observable
bool isOutdatedElectrumWallet;
@@ -265,8 +282,12 @@ abstract class DashboardViewModelBase with Store {
@action
void _onWalletChange(
WalletBase<Balance, TransactionHistoryBase<TransactionInfo>,
TransactionInfo>
TransactionInfo>?
wallet) {
if (wallet == null) {
return;
}
this.wallet = wallet;
type = wallet.type;
name = wallet.name;
@@ -275,20 +296,22 @@ abstract class DashboardViewModelBase with Store {
updateActions();
if (wallet.type == WalletType.monero) {
subname = monero.getCurrentAccount(wallet)?.label;
subname = monero!.getCurrentAccount(wallet).label;
_onMoneroAccountChangeReaction?.reaction?.dispose();
_onMoneroBalanceChangeReaction?.reaction?.dispose();
_onMoneroAccountChangeReaction?.reaction.dispose();
_onMoneroBalanceChangeReaction?.reaction.dispose();
_onMoneroAccountChangeReaction = reaction((_) => monero.getMoneroWalletDetails(wallet)
_onMoneroAccountChangeReaction = reaction((_) => monero!.getMoneroWalletDetails(wallet)
.account, (Account account) => _onMoneroAccountChange(wallet));
_onMoneroBalanceChangeReaction = reaction((_) => monero.getMoneroWalletDetails(wallet).balance,
_onMoneroBalanceChangeReaction = reaction((_) => monero!.getMoneroWalletDetails(wallet).balance,
(MoneroBalance balance) => _onMoneroTransactionsUpdate(wallet));
_onMoneroTransactionsUpdate(wallet);
} else {
subname = null;
// FIX-ME: Check for side effects
// subname = null;
subname = '';
transactions.clear();
@@ -300,24 +323,29 @@ abstract class DashboardViewModelBase with Store {
}
connectMapToListWithTransform(
appStore.wallet.transactionHistory.transactions,
appStore.wallet!.transactionHistory.transactions,
transactions,
(TransactionInfo val) => TransactionListItem(
transaction: val,
(TransactionInfo? transaction)
=> TransactionListItem(
transaction: transaction!,
balanceViewModel: balanceViewModel,
settingsStore: appStore.settingsStore),
filter: (TransactionInfo tx) {
if (wallet.type == WalletType.monero) {
return monero.getTransactionInfoAccountId(tx) == monero.getCurrentAccount(wallet).id;
}
filter: (TransactionInfo? tx) {
if (tx == null) {
return false;
}
return true;
if (wallet.type == WalletType.monero) {
return monero!.getTransactionInfoAccountId(tx) == monero!.getCurrentAccount(wallet).id;
}
return true;
});
}
@action
void _onMoneroAccountChange(WalletBase wallet) {
subname = monero.getCurrentAccount(wallet)?.label;
subname = monero!.getCurrentAccount(wallet).label;
_onMoneroTransactionsUpdate(wallet);
}
@@ -325,8 +353,8 @@ abstract class DashboardViewModelBase with Store {
void _onMoneroTransactionsUpdate(WalletBase wallet) {
transactions.clear();
final _accountTransactions = monero.getTransactionHistory(wallet).transactions.values
.where((tx) => monero.getTransactionInfoAccountId(tx) == monero.getCurrentAccount(wallet).id)
final _accountTransactions = monero!.getTransactionHistory(wallet).transactions.values
.where((tx) => monero!.getTransactionInfoAccountId(tx) == monero!.getCurrentAccount(wallet).id)
.toList();
transactions.addAll(_accountTransactions.map((transaction) =>
+4 -1
View File
@@ -1,5 +1,8 @@
class FilterItem {
FilterItem({this.value, this.caption, this.onChanged});
FilterItem({
required this.value,
required this.caption,
required this.onChanged});
bool Function() value;
String caption;
@@ -3,7 +3,7 @@ import 'package:cake_wallet/view_model/dashboard/date_section_item.dart';
List<ActionListItem> formattedItemsList(List<ActionListItem> items) {
final formattedList = <ActionListItem>[];
DateTime lastDate;
DateTime? lastDate;
items.sort((a, b) => b.date.compareTo(a.date));
for (var i = 0; i < items.length; i++) {
@@ -4,7 +4,9 @@ import 'package:cake_wallet/view_model/dashboard/action_list_item.dart';
import 'package:cake_wallet/entities/balance_display_mode.dart';
class OrderListItem extends ActionListItem {
OrderListItem({this.order, this.settingsStore});
OrderListItem({
required this.order,
required this.settingsStore});
final Order order;
final SettingsStore settingsStore;
@@ -4,7 +4,9 @@ import 'package:cake_wallet/view_model/dashboard/action_list_item.dart';
import 'package:cake_wallet/entities/balance_display_mode.dart';
class TradeListItem extends ActionListItem {
TradeListItem({this.trade, this.settingsStore});
TradeListItem({
required this.trade,
required this.settingsStore});
final Trade trade;
final SettingsStore settingsStore;
@@ -20,5 +22,5 @@ class TradeListItem extends ActionListItem {
}
@override
DateTime get date => trade.createdAt;
DateTime get date => trade.createdAt!;
}
@@ -13,7 +13,9 @@ import 'package:cw_core/wallet_type.dart';
class TransactionListItem extends ActionListItem with Keyable {
TransactionListItem(
{this.transaction, this.balanceViewModel, this.settingsStore});
{required this.transaction,
required this.balanceViewModel,
required this.settingsStore});
final TransactionInfo transaction;
final BalanceViewModel balanceViewModel;
@@ -40,20 +42,20 @@ class TransactionListItem extends ActionListItem with Keyable {
switch(balanceViewModel.wallet.type) {
case WalletType.monero:
amount = calculateFiatAmountRaw(
cryptoAmount: monero.formatterMoneroAmountToDouble(amount: transaction.amount),
cryptoAmount: monero!.formatterMoneroAmountToDouble(amount: transaction.amount),
price: price);
break;
case WalletType.bitcoin:
case WalletType.litecoin:
amount = calculateFiatAmountRaw(
cryptoAmount: bitcoin.formatterBitcoinAmountToDouble(amount: transaction.amount),
cryptoAmount: bitcoin!.formatterBitcoinAmountToDouble(amount: transaction.amount),
price: price);
break;
case WalletType.haven:
final asset = haven.assetOfTransaction(transaction);
final price = balanceViewModel.fiatConvertationStore.prices[asset];
final asset = haven!.assetOfTransaction(transaction);
final price = balanceViewModel.fiatConvertationStore.prices[asset]!;
amount = calculateFiatAmountRaw(
cryptoAmount: haven.formatterMoneroAmountToDouble(amount: transaction.amount),
cryptoAmount: haven!.formatterMoneroAmountToDouble(amount: transaction.amount),
price: price);
break;
default:
+1 -1
View File
@@ -1,5 +1,5 @@
class WalletBalance {
WalletBalance({this.unlockedBalance, this.totalBalance});
WalletBalance({required this.unlockedBalance, required this.totalBalance});
String unlockedBalance;
String totalBalance;