mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-10-23 06:38:35 +02:00
Flutter upgrade
This commit is contained in:
@@ -25,10 +25,16 @@ class Output = OutputBase with _$Output;
|
||||
|
||||
abstract class OutputBase with Store {
|
||||
OutputBase(this._wallet, this._settingsStore, this._fiatConversationStore, this.cryptoCurrencyHandler)
|
||||
: _cryptoNumberFormat = NumberFormat(cryptoNumberPattern) {
|
||||
reset();
|
||||
: _cryptoNumberFormat = NumberFormat(cryptoNumberPattern),
|
||||
key = UniqueKey(),
|
||||
sendAll = false,
|
||||
cryptoAmount = '',
|
||||
fiatAmount = '',
|
||||
address = '',
|
||||
note = '',
|
||||
extractedAddress = '',
|
||||
parsedAddress = ParsedAddress(addresses: []) {
|
||||
_setCryptoNumMaximumFractionDigits();
|
||||
key = UniqueKey();
|
||||
}
|
||||
|
||||
Key key;
|
||||
@@ -69,18 +75,18 @@ abstract class OutputBase with Store {
|
||||
int _amount = 0;
|
||||
switch (walletType) {
|
||||
case WalletType.monero:
|
||||
_amount = monero.formatterMoneroParseAmount(amount: _cryptoAmount);
|
||||
_amount = monero!.formatterMoneroParseAmount(amount: _cryptoAmount);
|
||||
break;
|
||||
case WalletType.bitcoin:
|
||||
_amount =
|
||||
bitcoin.formatterStringDoubleToBitcoinAmount(_cryptoAmount);
|
||||
bitcoin!.formatterStringDoubleToBitcoinAmount(_cryptoAmount);
|
||||
break;
|
||||
case WalletType.litecoin:
|
||||
_amount =
|
||||
bitcoin.formatterStringDoubleToBitcoinAmount(_cryptoAmount);
|
||||
bitcoin!.formatterStringDoubleToBitcoinAmount(_cryptoAmount);
|
||||
break;
|
||||
case WalletType.haven:
|
||||
_amount = haven.formatterMoneroParseAmount(amount: _cryptoAmount);
|
||||
_amount = haven!.formatterMoneroParseAmount(amount: _cryptoAmount);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -101,19 +107,19 @@ abstract class OutputBase with Store {
|
||||
double get estimatedFee {
|
||||
try {
|
||||
final fee = _wallet.calculateEstimatedFee(
|
||||
_settingsStore.priority[_wallet.type], formattedCryptoAmount);
|
||||
_settingsStore.priority[_wallet.type]!, formattedCryptoAmount);
|
||||
|
||||
if (_wallet.type == WalletType.bitcoin ||
|
||||
_wallet.type == WalletType.litecoin) {
|
||||
return bitcoin.formatterBitcoinAmountToDouble(amount: fee);
|
||||
return bitcoin!.formatterBitcoinAmountToDouble(amount: fee);
|
||||
}
|
||||
|
||||
if (_wallet.type == WalletType.monero) {
|
||||
return monero.formatterMoneroAmountToDouble(amount: fee);
|
||||
return monero!.formatterMoneroAmountToDouble(amount: fee);
|
||||
}
|
||||
|
||||
if (_wallet.type == WalletType.haven) {
|
||||
return haven.formatterMoneroAmountToDouble(amount: fee);
|
||||
return haven!.formatterMoneroAmountToDouble(amount: fee);
|
||||
}
|
||||
} catch (e) {
|
||||
print(e.toString());
|
||||
@@ -126,7 +132,7 @@ abstract class OutputBase with Store {
|
||||
String get estimatedFeeFiatAmount {
|
||||
try {
|
||||
final fiat = calculateFiatAmountRaw(
|
||||
price: _fiatConversationStore.prices[cryptoCurrencyHandler()],
|
||||
price: _fiatConversationStore.prices[cryptoCurrencyHandler()]!,
|
||||
cryptoAmount: estimatedFee);
|
||||
return fiat;
|
||||
} catch (_) {
|
||||
@@ -179,7 +185,7 @@ abstract class OutputBase with Store {
|
||||
void _updateFiatAmount() {
|
||||
try {
|
||||
final fiat = calculateFiatAmount(
|
||||
price: _fiatConversationStore.prices[cryptoCurrencyHandler()],
|
||||
price: _fiatConversationStore.prices[cryptoCurrencyHandler()]!,
|
||||
cryptoAmount: cryptoAmount.replaceAll(',', '.'));
|
||||
if (fiatAmount != fiat) {
|
||||
fiatAmount = fiat;
|
||||
@@ -193,7 +199,7 @@ abstract class OutputBase with Store {
|
||||
void _updateCryptoAmount() {
|
||||
try {
|
||||
final crypto = double.parse(fiatAmount.replaceAll(',', '.')) /
|
||||
_fiatConversationStore.prices[cryptoCurrencyHandler()];
|
||||
_fiatConversationStore.prices[cryptoCurrencyHandler()]!;
|
||||
final cryptoAmountTmp = _cryptoNumberFormat.format(crypto);
|
||||
|
||||
if (cryptoAmount != cryptoAmountTmp) {
|
||||
|
||||
@@ -19,8 +19,8 @@ class SendTemplateViewModel = SendTemplateViewModelBase
|
||||
|
||||
abstract class SendTemplateViewModelBase with Store {
|
||||
SendTemplateViewModelBase(this._wallet, this._settingsStore,
|
||||
this._sendTemplateStore, this._fiatConversationStore) {
|
||||
|
||||
this._sendTemplateStore, this._fiatConversationStore)
|
||||
: output = Output(_wallet, _settingsStore, _fiatConversationStore, () => _wallet.currency) {
|
||||
output = Output(_wallet, _settingsStore, _fiatConversationStore, () => currency);
|
||||
}
|
||||
|
||||
@@ -65,13 +65,13 @@ abstract class SendTemplateViewModelBase with Store {
|
||||
void updateTemplate() => _sendTemplateStore.update();
|
||||
|
||||
void addTemplate(
|
||||
{String name,
|
||||
bool isCurrencySelected,
|
||||
String address,
|
||||
String cryptoCurrency,
|
||||
String fiatCurrency,
|
||||
String amount,
|
||||
String amountFiat}) {
|
||||
{required String name,
|
||||
required bool isCurrencySelected,
|
||||
required String address,
|
||||
required String cryptoCurrency,
|
||||
required String fiatCurrency,
|
||||
required String amount,
|
||||
required String amountFiat}) {
|
||||
_sendTemplateStore.addTemplate(
|
||||
name: name,
|
||||
isCurrencySelected: isCurrencySelected,
|
||||
@@ -83,7 +83,7 @@ abstract class SendTemplateViewModelBase with Store {
|
||||
updateTemplate();
|
||||
}
|
||||
|
||||
void removeTemplate({Template template}) {
|
||||
void removeTemplate({required Template template}) {
|
||||
_sendTemplateStore.remove(template: template);
|
||||
updateTemplate();
|
||||
}
|
||||
|
||||
@@ -39,18 +39,18 @@ abstract class SendViewModelBase with Store {
|
||||
this._fiatConversationStore,
|
||||
this.balanceViewModel,
|
||||
this.transactionDescriptionBox)
|
||||
: state = InitialExecutionState() {
|
||||
: state = InitialExecutionState(),
|
||||
currencies = _wallet.balance.keys.toList(),
|
||||
selectedCryptoCurrency = _wallet.currency,
|
||||
outputs = ObservableList<Output>() {
|
||||
final priority = _settingsStore.priority[_wallet.type];
|
||||
final priorities = priorityForWalletType(_wallet.type);
|
||||
selectedCryptoCurrency = _wallet.currency;
|
||||
currencies = _wallet.balance.keys.toList();
|
||||
|
||||
if (!priorityForWalletType(_wallet.type).contains(priority)) {
|
||||
_settingsStore.priority[_wallet.type] = priorities.first;
|
||||
}
|
||||
|
||||
outputs = ObservableList<Output>()
|
||||
..add(Output(_wallet, _settingsStore, _fiatConversationStore, () => selectedCryptoCurrency));
|
||||
|
||||
outputs.add(Output(_wallet, _settingsStore, _fiatConversationStore, () => selectedCryptoCurrency));
|
||||
}
|
||||
|
||||
@observable
|
||||
@@ -84,8 +84,8 @@ abstract class SendViewModelBase with Store {
|
||||
try {
|
||||
if (pendingTransaction != null) {
|
||||
final fiat = calculateFiatAmount(
|
||||
price: _fiatConversationStore.prices[selectedCryptoCurrency],
|
||||
cryptoAmount: pendingTransaction.amountFormatted);
|
||||
price: _fiatConversationStore.prices[selectedCryptoCurrency]!,
|
||||
cryptoAmount: pendingTransaction!.amountFormatted);
|
||||
return fiat;
|
||||
} else {
|
||||
return '0.00';
|
||||
@@ -100,8 +100,8 @@ abstract class SendViewModelBase with Store {
|
||||
try {
|
||||
if (pendingTransaction != null) {
|
||||
final fiat = calculateFiatAmount(
|
||||
price: _fiatConversationStore.prices[selectedCryptoCurrency],
|
||||
cryptoAmount: pendingTransaction.feeFormatted);
|
||||
price: _fiatConversationStore.prices[selectedCryptoCurrency]!,
|
||||
cryptoAmount: pendingTransaction!.feeFormatted);
|
||||
return fiat;
|
||||
} else {
|
||||
return '0.00';
|
||||
@@ -113,8 +113,15 @@ abstract class SendViewModelBase with Store {
|
||||
|
||||
FiatCurrency get fiat => _settingsStore.fiatCurrency;
|
||||
|
||||
TransactionPriority get transactionPriority =>
|
||||
_settingsStore.priority[_wallet.type];
|
||||
TransactionPriority get transactionPriority {
|
||||
final priority = _settingsStore.priority[_wallet.type];
|
||||
|
||||
if (priority == null) {
|
||||
throw Exception('Unexpected type ${_wallet.type}');
|
||||
}
|
||||
|
||||
return priority;
|
||||
}
|
||||
|
||||
CryptoCurrency get currency => _wallet.currency;
|
||||
|
||||
@@ -127,7 +134,7 @@ abstract class SendViewModelBase with Store {
|
||||
Validator get textValidator => TextValidator();
|
||||
|
||||
@observable
|
||||
PendingTransaction pendingTransaction;
|
||||
PendingTransaction? pendingTransaction;
|
||||
|
||||
@computed
|
||||
String get balance => balanceViewModel.availableBalance ?? '0.0';
|
||||
@@ -179,6 +186,10 @@ abstract class SendViewModelBase with Store {
|
||||
|
||||
@action
|
||||
Future<void> commitTransaction() async {
|
||||
if (pendingTransaction == null) {
|
||||
throw Exception("Pending transaction doesn't exist. It should not be happened.");
|
||||
}
|
||||
|
||||
String address = outputs.fold('', (acc, value) {
|
||||
return value.isParsedAddress
|
||||
? acc + value.address + '\n' + value.extractedAddress + '\n\n'
|
||||
@@ -195,16 +206,16 @@ abstract class SendViewModelBase with Store {
|
||||
|
||||
try {
|
||||
state = TransactionCommitting();
|
||||
await pendingTransaction.commit();
|
||||
await pendingTransaction!.commit();
|
||||
|
||||
if (pendingTransaction.id?.isNotEmpty ?? false) {
|
||||
if (pendingTransaction!.id?.isNotEmpty ?? false) {
|
||||
_settingsStore.shouldSaveRecipientAddress
|
||||
? await transactionDescriptionBox.add(TransactionDescription(
|
||||
id: pendingTransaction.id,
|
||||
id: pendingTransaction!.id,
|
||||
recipientAddress: address,
|
||||
transactionNote: note))
|
||||
: await transactionDescriptionBox.add(TransactionDescription(
|
||||
id: pendingTransaction.id, transactionNote: note));
|
||||
id: pendingTransaction!.id, transactionNote: note));
|
||||
}
|
||||
|
||||
state = TransactionCommitted();
|
||||
@@ -222,23 +233,39 @@ abstract class SendViewModelBase with Store {
|
||||
case WalletType.bitcoin:
|
||||
final priority = _settingsStore.priority[_wallet.type];
|
||||
|
||||
return bitcoin.createBitcoinTransactionCredentials(outputs, priority: priority);
|
||||
if (priority == null) {
|
||||
throw Exception('Priority is null for wallet type: ${_wallet.type}');
|
||||
}
|
||||
|
||||
return bitcoin!.createBitcoinTransactionCredentials(outputs, priority: priority);
|
||||
case WalletType.litecoin:
|
||||
final priority = _settingsStore.priority[_wallet.type];
|
||||
|
||||
return bitcoin.createBitcoinTransactionCredentials(outputs, priority: priority);
|
||||
if (priority == null) {
|
||||
throw Exception('Priority is null for wallet type: ${_wallet.type}');
|
||||
}
|
||||
|
||||
return bitcoin!.createBitcoinTransactionCredentials(outputs, priority: priority);
|
||||
case WalletType.monero:
|
||||
final priority = _settingsStore.priority[_wallet.type];
|
||||
|
||||
return monero.createMoneroTransactionCreationCredentials(
|
||||
if (priority == null) {
|
||||
throw Exception('Priority is null for wallet type: ${_wallet.type}');
|
||||
}
|
||||
|
||||
return monero!.createMoneroTransactionCreationCredentials(
|
||||
outputs: outputs, priority: priority);
|
||||
case WalletType.haven:
|
||||
final priority = _settingsStore.priority[_wallet.type];
|
||||
|
||||
return haven.createHavenTransactionCreationCredentials(
|
||||
if (priority == null) {
|
||||
throw Exception('Priority is null for wallet type: ${_wallet.type}');
|
||||
}
|
||||
|
||||
return haven!.createHavenTransactionCreationCredentials(
|
||||
outputs: outputs, priority: priority, assetType: selectedCryptoCurrency.title);
|
||||
default:
|
||||
return null;
|
||||
throw Exception('Unexpected wallet type: ${_wallet.type}');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -247,8 +274,10 @@ abstract class SendViewModelBase with Store {
|
||||
final wallet = _wallet;
|
||||
|
||||
if (isElectrumWallet) {
|
||||
final rate = bitcoin.getFeeRate(wallet, _priority);
|
||||
return '${priority.labelWithRate(rate)}';
|
||||
final rate = bitcoin!.getFeeRate(wallet, _priority);
|
||||
// FIX-ME: labelWithRate
|
||||
// return '${priority.labelWithRate(rate)}';
|
||||
return '';
|
||||
}
|
||||
|
||||
return priority.toString();
|
||||
|
||||
Reference in New Issue
Block a user