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
@@ -23,12 +23,14 @@ class ExchangeTradeViewModel = ExchangeTradeViewModelBase
abstract class ExchangeTradeViewModelBase with Store {
ExchangeTradeViewModelBase(
{this.wallet, this.trades, this.tradesStore, this.sendViewModel}) {
trade = tradesStore.trade;
isSendable = trade.from == wallet.currency ||
trade.provider == ExchangeProviderDescription.xmrto;
{required this.wallet,
required this.trades,
required this.tradesStore,
required this.sendViewModel})
: trade = tradesStore.trade!,
isSendable = tradesStore.trade!.from == wallet.currency ||
tradesStore.trade!.provider == ExchangeProviderDescription.xmrto,
items = ObservableList<ExchangeTradeItem>() {
switch (trade.provider) {
case ExchangeProviderDescription.xmrto:
_provider = XMRTOExchangeProvider();
@@ -47,12 +49,8 @@ abstract class ExchangeTradeViewModelBase with Store {
break;
}
items = ObservableList<ExchangeTradeItem>();
_updateItems();
_updateTrade();
timer = Timer.periodic(Duration(seconds: 20), (_) async => _updateTrade());
}
@@ -77,9 +75,9 @@ abstract class ExchangeTradeViewModelBase with Store {
@observable
ObservableList<ExchangeTradeItem> items;
ExchangeProvider _provider;
ExchangeProvider? _provider;
Timer timer;
Timer? timer;
@action
Future confirmSending() async {
@@ -89,8 +87,7 @@ abstract class ExchangeTradeViewModelBase with Store {
sendViewModel.clearOutputs();
final output = sendViewModel.outputs.first;
output.address = trade.inputAddress;
output.address = trade.inputAddress ?? '';
output.setCryptoAmount(trade.amount);
await sendViewModel.createTransaction();
}
@@ -98,7 +95,7 @@ abstract class ExchangeTradeViewModelBase with Store {
@action
Future<void> _updateTrade() async {
try {
final updatedTrade = await _provider.findTradeById(id: trade.id);
final updatedTrade = await _provider!.findTradeById(id: trade.id);
if (updatedTrade.createdAt == null && trade.createdAt != null) {
updatedTrade.createdAt = trade.createdAt;
@@ -113,8 +110,7 @@ abstract class ExchangeTradeViewModelBase with Store {
}
void _updateItems() {
items?.clear();
items.clear();
items.add(ExchangeTradeItem(
title: "${trade.provider.title} ${S.current.id}", data: '${trade.id}', isCopied: true));
@@ -136,7 +132,7 @@ abstract class ExchangeTradeViewModelBase with Store {
title: S.current.status, data: '${trade.state}', isCopied: false),
ExchangeTradeItem(
title: S.current.widgets_address + ':',
data: trade.inputAddress,
data: trade.inputAddress ?? '',
isCopied: true),
]);
}
@@ -39,14 +39,32 @@ class ExchangeViewModel = ExchangeViewModelBase with _$ExchangeViewModel;
abstract class ExchangeViewModelBase with Store {
ExchangeViewModelBase(this.wallet, this.trades, this._exchangeTemplateStore,
this.tradesStore, this._settingsStore, this.sharedPreferences) {
this.tradesStore, this._settingsStore, this.sharedPreferences)
: _cryptoNumberFormat = NumberFormat(),
isReverse = false,
isFixedRateMode = false,
isReceiveAmountEntered = false,
depositAmount = '',
receiveAmount = '',
receiveAddress = '',
depositAddress = '',
isDepositAddressEnabled = false,
isReceiveAddressEnabled = false,
isReceiveAmountEditable = false,
receiveCurrencies = <CryptoCurrency>[],
depositCurrencies = <CryptoCurrency>[],
limits = Limits(min: 0, max: 0),
tradeState = ExchangeTradeStateInitial(),
limitsState = LimitsInitialState(),
receiveCurrency = wallet.currency,
depositCurrency = wallet.currency,
providerList = [ChangeNowExchangeProvider(), SideShiftExchangeProvider(), SimpleSwapExchangeProvider()],
selectedProviders = ObservableList<ExchangeProvider>(),
currentTradeAvailableProviders = SplayTreeMap<double, ExchangeProvider>() {
const excludeDepositCurrencies = [CryptoCurrency.btt, CryptoCurrency.nano];
const excludeReceiveCurrencies = [CryptoCurrency.xlm, CryptoCurrency.xrp,
CryptoCurrency.bnb, CryptoCurrency.btt, CryptoCurrency.nano];
providerList = [ChangeNowExchangeProvider(), SideShiftExchangeProvider(), SimpleSwapExchangeProvider()];
_initialPairBasedOnWallet();
currentTradeAvailableProviders = SplayTreeMap<double, ExchangeProvider>();
final Map<String, dynamic> exchangeProvidersSelection = json
.decode(sharedPreferences.getString(PreferencesKey.exchangeProvidersSelection) ?? "{}") as Map<String, dynamic>;
@@ -65,12 +83,10 @@ abstract class ExchangeViewModelBase with Store {
receiveAddress = '';
depositAddress = depositCurrency == wallet.currency
? wallet.walletAddresses.address : '';
limitsState = LimitsInitialState();
tradeState = ExchangeTradeStateInitial();
_cryptoNumberFormat = NumberFormat()..maximumFractionDigits = wallet.type == WalletType.bitcoin ? 8 : 12;
provider = providersForCurrentPair().first;
final initialProvider = provider;
provider.checkIsAvailable().then((bool isAvailable) {
provider!.checkIsAvailable().then((bool isAvailable) {
if (!isAvailable && provider == initialProvider) {
provider = providerList.firstWhere(
(provider) => provider is ChangeNowExchangeProvider,
@@ -84,9 +100,6 @@ abstract class ExchangeViewModelBase with Store {
depositCurrencies = CryptoCurrency.all
.where((cryptoCurrency) => !excludeDepositCurrencies.contains(cryptoCurrency))
.toList();
isReverse = false;
isFixedRateMode = false;
isReceiveAmountEntered = false;
_defineIsReceiveAmountEditable();
loadLimits();
reaction(
@@ -101,7 +114,7 @@ abstract class ExchangeViewModelBase with Store {
final SharedPreferences sharedPreferences;
@observable
ExchangeProvider provider;
ExchangeProvider? provider;
/// Maps in dart are not sorted by default
/// SplayTreeMap is a map sorted by keys
@@ -179,7 +192,7 @@ abstract class ExchangeViewModelBase with Store {
final SettingsStore _settingsStore;
@action
void changeDepositCurrency({CryptoCurrency currency}) {
void changeDepositCurrency({required CryptoCurrency currency}) {
depositCurrency = currency;
isFixedRateMode = false;
_onPairChange();
@@ -188,7 +201,7 @@ abstract class ExchangeViewModelBase with Store {
}
@action
void changeReceiveCurrency({CryptoCurrency currency}) {
void changeReceiveCurrency({required CryptoCurrency currency}) {
receiveCurrency = currency;
isFixedRateMode = false;
_onPairChange();
@@ -197,7 +210,7 @@ abstract class ExchangeViewModelBase with Store {
}
@action
void changeReceiveAmount({String amount}) {
void changeReceiveAmount({required String amount}) {
receiveAmount = amount;
isReverse = true;
@@ -254,7 +267,7 @@ abstract class ExchangeViewModelBase with Store {
}
@action
void changeDepositAmount({String amount}) {
void changeDepositAmount({required String amount}) {
depositAmount = amount;
isReverse = false;
@@ -344,7 +357,7 @@ abstract class ExchangeViewModelBase with Store {
/// set the limits with the maximum provider limit
/// if there is a provider with null max then it's the maximum limit
if ((tempLimits.max ?? double.maxFinite) > limits.max) {
if ((tempLimits.max ?? double.maxFinite) > limits.max!) {
limits = tempLimits;
}
}
@@ -357,9 +370,9 @@ abstract class ExchangeViewModelBase with Store {
}
@action
Future createTrade() async {
TradeRequest request;
String amount;
Future<void> createTrade() async {
TradeRequest? request;
String amount = '';
for (var provider in currentTradeAvailableProviders.values) {
if (!(await provider.checkIsAvailable())) {
@@ -370,7 +383,7 @@ abstract class ExchangeViewModelBase with Store {
request = SideShiftRequest(
depositMethod: depositCurrency,
settleMethod: receiveCurrency,
depositAmount: depositAmount?.replaceAll(',', '.'),
depositAmount: depositAmount?.replaceAll(',', '.') ?? '',
settleAddress: receiveAddress,
refundAddress: depositAddress,
);
@@ -381,7 +394,7 @@ abstract class ExchangeViewModelBase with Store {
request = SimpleSwapRequest(
from: depositCurrency,
to: receiveCurrency,
amount: depositAmount?.replaceAll(',', '.'),
amount: depositAmount?.replaceAll(',', '.') ?? '',
address: receiveAddress,
refundAddress: depositAddress,
);
@@ -392,8 +405,8 @@ abstract class ExchangeViewModelBase with Store {
request = XMRTOTradeRequest(
from: depositCurrency,
to: receiveCurrency,
amount: depositAmount?.replaceAll(',', '.'),
receiveAmount: receiveAmount?.replaceAll(',', '.'),
amount: depositAmount?.replaceAll(',', '.') ?? '',
receiveAmount: receiveAmount?.replaceAll(',', '.') ?? '',
address: receiveAddress,
refundAddress: depositAddress,
isBTCRequest: isReceiveAmountEntered);
@@ -404,8 +417,8 @@ abstract class ExchangeViewModelBase with Store {
request = ChangeNowRequest(
from: depositCurrency,
to: receiveCurrency,
fromAmount: depositAmount?.replaceAll(',', '.'),
toAmount: receiveAmount?.replaceAll(',', '.'),
fromAmount: depositAmount?.replaceAll(',', '.') ?? '',
toAmount: receiveAmount?.replaceAll(',', '.') ?? '',
refundAddress: depositAddress,
address: receiveAddress,
isReverse: isReverse);
@@ -416,7 +429,7 @@ abstract class ExchangeViewModelBase with Store {
request = MorphTokenRequest(
from: depositCurrency,
to: receiveCurrency,
amount: depositAmount?.replaceAll(',', '.'),
amount: depositAmount?.replaceAll(',', '.') ?? '',
refundAddress: depositAddress,
address: receiveAddress);
amount = depositAmount;
@@ -425,15 +438,15 @@ abstract class ExchangeViewModelBase with Store {
amount = amount.replaceAll(',', '.');
if (limitsState is LimitsLoadedSuccessfully && amount != null) {
if (double.parse(amount) < limits.min) {
if (double.parse(amount) < limits.min!) {
continue;
} else if (limits.max != null && double.parse(amount) > limits.max) {
} else if (limits.max != null && double.parse(amount) > limits.max!) {
continue;
} else {
try {
tradeState = TradeIsCreating();
final trade = await provider.createTrade(
request: request, isFixedRateMode: isFixedRateMode);
request: request!, isFixedRateMode: isFixedRateMode);
trade.walletId = wallet.id;
tradesStore.setTrade(trade);
await trades.add(trade);
@@ -472,8 +485,8 @@ abstract class ExchangeViewModelBase with Store {
@action
void calculateDepositAllAmount() {
if (wallet.type == WalletType.bitcoin) {
final availableBalance = wallet.balance[wallet.currency].available;
final priority = _settingsStore.priority[wallet.type];
final availableBalance = wallet.balance[wallet.currency]!.available;
final priority = _settingsStore.priority[wallet.type]!;
final fee = wallet.calculateEstimatedFee(priority, null);
if (availableBalance < fee || availableBalance == 0) {
@@ -481,19 +494,19 @@ abstract class ExchangeViewModelBase with Store {
}
final amount = availableBalance - fee;
changeDepositAmount(amount: bitcoin.formatterBitcoinAmountToString(amount: amount));
changeDepositAmount(amount: bitcoin!.formatterBitcoinAmountToString(amount: amount));
}
}
void updateTemplate() => _exchangeTemplateStore.update();
void addTemplate(
{String amount,
String depositCurrency,
String receiveCurrency,
String provider,
String depositAddress,
String receiveAddress}) =>
{required String amount,
required String depositCurrency,
required String receiveCurrency,
required String provider,
required String depositAddress,
required String receiveAddress}) =>
_exchangeTemplateStore.addTemplate(
amount: amount,
depositCurrency: depositCurrency,
@@ -502,7 +515,7 @@ abstract class ExchangeViewModelBase with Store {
depositAddress: depositAddress,
receiveAddress: receiveAddress);
void removeTemplate({ExchangeTemplate template}) =>
void removeTemplate({required ExchangeTemplate template}) =>
_exchangeTemplateStore.remove(template: template);
List<ExchangeProvider> providersForCurrentPair() {
@@ -510,7 +523,7 @@ abstract class ExchangeViewModelBase with Store {
}
List<ExchangeProvider> _providersForPair(
{CryptoCurrency from, CryptoCurrency to}) {
{required CryptoCurrency from, required CryptoCurrency to}) {
final providers = providerList
.where((provider) => provider.pairList
.where((pair) =>