Fix conflicts with master

update code to null safety
This commit is contained in:
OmarHatem 2022-11-21 16:44:01 +02:00
parent a27c5005d1
commit eb9b45360e
15 changed files with 43 additions and 38 deletions

View file

@ -8,13 +8,13 @@ class ElectrumFeeEstimate extends FeeEstimate {
ElectrumWalletBase _wallet;
int get({TransactionPriority priority, int amount, int outputsCount}) {
int get({TransactionPriority? priority, int? amount, int? outputsCount}) {
// Electrum doesn't require an async call to obtain the estimated fee.
// We don't bother caching and just obtain it directly.
return _wallet.calculateEstimatedFee(priority,amount, outputsCount: outputsCount);
}
void update({TransactionPriority priority, int amount, int outputsCount}) {}
void update({TransactionPriority? priority, int? amount, int? outputsCount}) {}
void set({TransactionPriority priority, int outputsCount, int fee}) {}
void set({TransactionPriority? priority, int? outputsCount, int? fee}) {}
}

View file

@ -68,12 +68,12 @@ abstract class ElectrumWalletBase extends WalletBase<ElectrumBalance,
? {currency: initialBalance ?? const ElectrumBalance(confirmed: 0, unconfirmed: 0)}
: {}),
this.unspentCoinsInfo = unspentCoinsInfo,
feeEstimate = ElectrumFeeEstimate(this),
super(walletInfo) {
this.electrumClient = electrumClient ?? ElectrumClient();
this.walletInfo = walletInfo;
transactionHistory =
ElectrumTransactionHistory(walletInfo: walletInfo, password: password);
feeEstimate = ElectrumFeeEstimate(this);
}
static int estimatedTransactionSize(int inputsCount, int outputsCounts) =>
@ -98,7 +98,7 @@ abstract class ElectrumWalletBase extends WalletBase<ElectrumBalance,
@override
@observable
ElectrumFeeEstimate feeEstimate;
late ElectrumFeeEstimate feeEstimate;
List<String> get scriptHashes => walletAddresses.addresses
.map((addr) => scriptHash(addr.address, networkType: networkType))

View file

@ -2,9 +2,9 @@ import 'package:cw_core/transaction_priority.dart';
abstract class FeeEstimate
{
void update({TransactionPriority priority, int outputsCount});
void update({required TransactionPriority priority, int outputsCount = 1});
int get({TransactionPriority priority, int amount, int outputsCount});
int get({required TransactionPriority priority, required int amount, int outputsCount = 1});
void set({TransactionPriority priority, int outputsCount, int fee});
void set({required TransactionPriority priority, required int outputsCount, required int fee});
}

View file

@ -366,6 +366,6 @@ int _estimateTransactionFee(Map args) {
return estimateTransactionFeeSync(outputsCount, priorityRaw);
}
Future<int> estimateTransactionFee({int priorityRaw, int outputsCount}) {
Future<int> estimateTransactionFee({required int priorityRaw, required int outputsCount}) {
return compute(_estimateTransactionFee, {'priorityRaw': priorityRaw, 'outputsCount': outputsCount});
}

View file

@ -15,7 +15,7 @@ abstract class _HavenFeeEstimate extends FeeEstimate with Store {
ObservableMap<String, int> _estimatedFee;
@override
void update({TransactionPriority priority, int outputsCount}) {
void update({required TransactionPriority priority, int outputsCount = 1}) {
Future(() async {
final fee = await haven_wallet.estimateTransactionFee(priorityRaw: priority.raw, outputsCount: outputsCount);
set(priority: priority, fee: fee, outputsCount: outputsCount);
@ -23,12 +23,12 @@ abstract class _HavenFeeEstimate extends FeeEstimate with Store {
}
@override
int get({TransactionPriority priority, int amount, int outputsCount}) {
int get({required TransactionPriority priority, required int amount, int outputsCount = 1}) {
return _estimatedFee[_key(priority, outputsCount)] ?? 0;
}
@override
void set({TransactionPriority priority, int outputsCount, int fee}) {
void set({required TransactionPriority priority, required int outputsCount, required int fee}) {
_estimatedFee[_key(priority, outputsCount)] = fee;
}

View file

@ -42,6 +42,7 @@ abstract class HavenWalletBase extends WalletBase<MoneroBalance,
_hasSyncAfterStartup = false,
walletAddresses = HavenWalletAddresses(walletInfo),
syncStatus = NotConnectedSyncStatus(),
feeEstimate = HavenFeeEstimate(),
super(walletInfo) {
transactionHistory = HavenTransactionHistory();
_onAccountChangeReaction = reaction((_) => walletAddresses.account,
@ -52,7 +53,6 @@ abstract class HavenWalletBase extends WalletBase<MoneroBalance,
balance.addAll(getHavenBalance(accountIndex: account.id));
walletAddresses.updateSubaddressList(accountIndex: account.id);
});
feeEstimate = HavenFeeEstimate();
}
static const int _autoSaveInterval = 30;

View file

@ -376,6 +376,6 @@ int _estimateTransactionFee(Map args) {
return estimateTransactionFeeSync(outputsCount, priorityRaw);
}
Future<int> estimateTransactionFee({int priorityRaw, int outputsCount}) {
return compute(_estimateTransactionFee, {'priorityRaw': priorityRaw, 'outputsCount': outputsCount});
Future<int> estimateTransactionFee({required int priorityRaw, int? outputsCount}) {
return compute(_estimateTransactionFee, {'priorityRaw': priorityRaw, 'outputsCount': outputsCount ?? 1});
}

View file

@ -15,7 +15,7 @@ abstract class _MoneroFeeEstimate extends FeeEstimate with Store {
ObservableMap<String, int> _estimatedFee;
@override
void update({TransactionPriority priority, int outputsCount}) {
void update({required TransactionPriority priority, int outputsCount = 1}) {
Future(() async {
final fee = await monero_wallet.estimateTransactionFee(priorityRaw: priority.raw, outputsCount: outputsCount);
set(priority: priority, fee: fee, outputsCount: outputsCount);
@ -23,12 +23,12 @@ abstract class _MoneroFeeEstimate extends FeeEstimate with Store {
}
@override
int get({TransactionPriority priority, int amount, int outputsCount}) {
int get({required TransactionPriority priority, required int amount, int outputsCount = 1}) {
return _estimatedFee[_key(priority, outputsCount)] ?? 0;
}
@override
void set({TransactionPriority priority, int outputsCount, int fee}) {
void set({required TransactionPriority priority, required int outputsCount, required int fee}) {
_estimatedFee[_key(priority, outputsCount)] = fee;
}

View file

@ -1,4 +1,6 @@
import 'dart:async';
import 'package:cw_core/monero_balance.dart';
import 'package:cw_core/monero_wallet_keys.dart';
import 'package:cw_core/transaction_priority.dart';
import 'package:cw_core/monero_amount_format.dart';
import 'package:cw_monero/monero_transaction_creation_exception.dart';
@ -16,8 +18,6 @@ import 'package:cw_monero/api/transaction_history.dart' as transaction_history;
import 'package:cw_monero/api/monero_output.dart';
import 'package:cw_monero/monero_transaction_creation_credentials.dart';
import 'package:cw_monero/pending_monero_transaction.dart';
import 'package:cw_monero/monero_wallet_keys.dart';
import 'package:cw_monero/monero_balance.dart';
import 'package:cw_monero/monero_fee_estimate.dart';
import 'package:cw_monero/monero_transaction_history.dart';
import 'package:cw_core/account.dart';
@ -26,7 +26,6 @@ import 'package:cw_core/wallet_base.dart';
import 'package:cw_core/sync_status.dart';
import 'package:cw_core/wallet_info.dart';
import 'package:cw_core/node.dart';
import 'package:cw_core/monero_transaction_priority.dart';
import 'package:cw_core/crypto_currency.dart';
part 'monero_wallet.g.dart';
@ -47,6 +46,7 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance,
_hasSyncAfterStartup = false,
walletAddresses = MoneroWalletAddresses(walletInfo),
syncStatus = NotConnectedSyncStatus(),
feeEstimate = MoneroFeeEstimate(),
super(walletInfo) {
transactionHistory = MoneroTransactionHistory();
_onAccountChangeReaction = reaction((_) => walletAddresses.account,
@ -64,7 +64,6 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance,
});
walletAddresses.updateSubaddressList(accountIndex: account.id);
});
feeEstimate = MoneroFeeEstimate();
}
static const int _autoSaveInterval = 30;

View file

@ -11,13 +11,13 @@ String formatAmount(String amount) {
return amount;
}
double formatAmountToDouble({WalletType type, int amount}) {
double formatAmountToDouble({required WalletType type, required int amount}) {
if (type == WalletType.bitcoin || type == WalletType.litecoin) {
return bitcoin.formatterBitcoinAmountToDouble(amount: amount);
return bitcoin!.formatterBitcoinAmountToDouble(amount: amount);
}
if (type == WalletType.monero) {
return monero.formatterMoneroAmountToDouble(amount: amount);
return monero!.formatterMoneroAmountToDouble(amount: amount);
}
return 0.0;

View file

@ -38,7 +38,7 @@ void startWalletSyncStatusChangeReaction(WalletBase<Balance, TransactionHistoryB
}
if (status is SyncedSyncStatus) {
wallet.feeEstimate.update(priority: settingsStore.priority[wallet.type], outputsCount: 1);
wallet.feeEstimate.update(priority: settingsStore.priority[wallet.type]!);
}
});
}

View file

@ -312,10 +312,10 @@ class IoniaBuyGiftCardDetailPage extends BasePage {
'${ioniaPurchaseViewModel.sendViewModel.fiat.title}',
fee: S.of(context).send_fee,
feeValue:
'${ioniaPurchaseViewModel.sendViewModel.outputs.first.estimatedFee} '
'${ioniaPurchaseViewModel.sendViewModel.estimatedFee} '
'${ioniaPurchaseViewModel.invoice!.chain}',
feeFiatAmount:
'${ioniaPurchaseViewModel.sendViewModel.outputs.first.estimatedFeeFiatAmount} '
'${ioniaPurchaseViewModel.sendViewModel.estimatedFeeFiatAmount} '
'${ioniaPurchaseViewModel.sendViewModel.fiat.title}',
outputs: ioniaPurchaseViewModel.sendViewModel.outputs,
rightButtonText: S.of(context).ok,

View file

@ -488,8 +488,7 @@ abstract class ExchangeViewModelBase with Store {
if (wallet.type == WalletType.bitcoin) {
final availableBalance = wallet.balance[wallet.currency]!.available;
final priority = _settingsStore.priority[wallet.type]!;
final fee = wallet.calculateEstimatedFee(priority, null);
final fee = wallet.feeEstimate.get(priority: priority);
final fee = wallet.feeEstimate.get(priority: priority, amount: availableBalance);
if (availableBalance < fee || availableBalance == 0) {
return;

View file

@ -150,7 +150,9 @@ abstract class OutputBase with Store {
try {
final fiat = calculateFiatAmount(
price: _fiatConversationStore.prices[cryptoCurrencyHandler()]!,
cryptoAmount: (cryptoAmount.toUpperCase() == S.current.all) ? _cryptoNumberFormat.format(formatAmountToDouble(type: _wallet.type, amount: _estimateAmountAll())) : cryptoAmount.replaceAll(',', '.'));
cryptoAmount: (cryptoAmount.toUpperCase() == S.current.all)
? _cryptoNumberFormat.format(formatAmountToDouble(type: _wallet.type, amount: _estimateAmountAll()))
: cryptoAmount.replaceAll(',', '.'));
if (fiatAmount != fiat) {
fiatAmount = fiat;
}
@ -198,8 +200,11 @@ abstract class OutputBase with Store {
}
int _estimateAmountAll() {
final fee = _wallet.feeEstimate.get(priority: _settingsStore.priority[_wallet.type], outputsCount: 1);
return max(0, _wallet.balance[cryptoCurrencyHandler()].available - fee);
final fee = _wallet.feeEstimate.get(
priority: _settingsStore.priority[_wallet.type]!,
amount: _wallet.balance[cryptoCurrencyHandler()]!.available,
);
return max(0, _wallet.balance[cryptoCurrencyHandler()]!.available - fee);
}
Future<void> fetchParsedAddress(BuildContext context) async {

View file

@ -54,7 +54,9 @@ abstract class SendViewModelBase with Store {
outputs.add(Output(_wallet, _settingsStore, _fiatConversationStore, () => selectedCryptoCurrency));
_settingsStore.priority.observe((change) async {
_wallet.feeEstimate.update(priority: change.newValue, outputsCount: outputs.length);
if (change.newValue != null) {
_wallet.feeEstimate.update(priority: change.newValue!, outputsCount: outputs.length);
}
});
estimateFee();
@ -90,7 +92,7 @@ abstract class SendViewModelBase with Store {
String get pendingTransactionFiatAmount {
try {
if (pendingTransaction != null) {
return _calculateFiatAmount(pendingTransaction.amountFormatted);
return _calculateFiatAmount(pendingTransaction!.amountFormatted);
} else {
return '0.00';
}
@ -103,7 +105,7 @@ abstract class SendViewModelBase with Store {
String get pendingTransactionFeeFiatAmount {
try {
if (pendingTransaction != null) {
return _calculateFiatAmount(pendingTransaction.feeFormatted);
return _calculateFiatAmount(pendingTransaction!.feeFormatted);
} else {
return '0.00';
}
@ -292,7 +294,7 @@ abstract class SendViewModelBase with Store {
currency.toLowerCase() == _wallet.currency.title.toLowerCase();
void estimateFee() {
_wallet.feeEstimate.update(priority: _settingsStore.priority[_wallet.type], outputsCount: outputs.length);
_wallet.feeEstimate.update(priority: _settingsStore.priority[_wallet.type]!, outputsCount: outputs.length);
}
@computed
@ -304,7 +306,7 @@ abstract class SendViewModelBase with Store {
}
final fee = _wallet.feeEstimate.get(
priority: _settingsStore.priority[_wallet.type],
priority: _settingsStore.priority[_wallet.type]!,
amount: totalFormattedCryptoAmount,
outputsCount: outputs.length,
);