mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-12-02 12:14:09 +01:00
TMP
This commit is contained in:
@@ -35,9 +35,11 @@ abstract class BalanceViewModelBase with Store {
|
||||
|
||||
if (_wallet is BitcoinWallet) {
|
||||
return WalletBalance(
|
||||
unlockedBalance: _wallet.balance.confirmedFormatted,
|
||||
totalBalance: _wallet.balance.unconfirmedFormatted);
|
||||
unlockedBalance: _wallet.balance.totalFormatted,
|
||||
totalBalance: _wallet.balance.totalFormatted);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
String _getFiatBalance({double price, String cryptoAmount}) {
|
||||
|
||||
@@ -29,24 +29,24 @@ part 'dashboard_view_model.g.dart';
|
||||
class DashboardViewModel = DashboardViewModelBase with _$DashboardViewModel;
|
||||
|
||||
abstract class DashboardViewModelBase with Store {
|
||||
DashboardViewModelBase({
|
||||
this.balanceViewModel,
|
||||
this.appStore,
|
||||
this.tradesStore,
|
||||
this.tradeFilterStore,
|
||||
this.transactionFilterStore,
|
||||
this.pageViewStore}) {
|
||||
|
||||
DashboardViewModelBase(
|
||||
{this.balanceViewModel,
|
||||
this.appStore,
|
||||
this.tradesStore,
|
||||
this.tradeFilterStore,
|
||||
this.transactionFilterStore,
|
||||
this.pageViewStore}) {
|
||||
name = appStore.wallet?.name;
|
||||
wallet ??= appStore.wallet;
|
||||
type = wallet.type;
|
||||
|
||||
transactions = ObservableList.of(wallet.transactionHistory.transactions
|
||||
transactions = ObservableList.of(wallet
|
||||
.transactionHistory.transactions.values
|
||||
.map((transaction) => TransactionListItem(
|
||||
transaction: transaction,
|
||||
price: price,
|
||||
fiatCurrency: appStore.settingsStore.fiatCurrency,
|
||||
displayMode: balanceDisplayMode)));
|
||||
transaction: transaction,
|
||||
price: price,
|
||||
fiatCurrency: appStore.settingsStore.fiatCurrency,
|
||||
displayMode: balanceDisplayMode)));
|
||||
|
||||
_reaction = reaction((_) => appStore.wallet, _onWalletChange);
|
||||
|
||||
@@ -83,15 +83,11 @@ abstract class DashboardViewModelBase with Store {
|
||||
var statusText = '';
|
||||
|
||||
if (status is SyncingSyncStatus) {
|
||||
statusText = S.current
|
||||
.Blocks_remaining(
|
||||
status.toString());
|
||||
statusText = S.current.Blocks_remaining(status.toString());
|
||||
}
|
||||
|
||||
if (status is FailedSyncStatus) {
|
||||
statusText = S
|
||||
.current
|
||||
.please_try_to_connect_to_another_node;
|
||||
statusText = S.current.please_try_to_connect_to_another_node;
|
||||
}
|
||||
|
||||
return statusText;
|
||||
@@ -111,8 +107,7 @@ abstract class DashboardViewModelBase with Store {
|
||||
List<ActionListItem> get items {
|
||||
final _items = <ActionListItem>[];
|
||||
|
||||
_items
|
||||
.addAll(transactionFilterStore.filtered(transactions: transactions));
|
||||
_items.addAll(transactionFilterStore.filtered(transactions: transactions));
|
||||
_items.addAll(tradeFilterStore.filtered(trades: trades));
|
||||
|
||||
return formattedItemsList(_items);
|
||||
@@ -137,11 +132,11 @@ abstract class DashboardViewModelBase with Store {
|
||||
void _onWalletChange(WalletBase wallet) {
|
||||
name = wallet.name;
|
||||
transactions.clear();
|
||||
transactions.addAll(wallet.transactionHistory.transactions
|
||||
.map((transaction) => TransactionListItem(
|
||||
transaction: transaction,
|
||||
price: price,
|
||||
fiatCurrency: appStore.settingsStore.fiatCurrency,
|
||||
displayMode: balanceDisplayMode)));
|
||||
transactions.addAll(wallet.transactionHistory.transactions.values.map(
|
||||
(transaction) => TransactionListItem(
|
||||
transaction: transaction,
|
||||
price: price,
|
||||
fiatCurrency: appStore.settingsStore.fiatCurrency,
|
||||
displayMode: balanceDisplayMode)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,171 @@
|
||||
import 'package:cake_wallet/src/domain/common/calculate_fiat_amount.dart';
|
||||
import 'package:cake_wallet/store/dashboard/fiat_convertation_store.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:mobx/mobx.dart';
|
||||
import 'package:cake_wallet/core/address_validator.dart';
|
||||
import 'package:cake_wallet/core/amount_validator.dart';
|
||||
import 'package:cake_wallet/core/pending_transaction.dart';
|
||||
import 'package:cake_wallet/core/validator.dart';
|
||||
import 'package:cake_wallet/core/wallet_base.dart';
|
||||
import 'package:cake_wallet/bitcoin/bitcoin_wallet.dart';
|
||||
import 'package:cake_wallet/monero/monero_wallet.dart';
|
||||
import 'package:cake_wallet/src/domain/common/sync_status.dart';
|
||||
import 'package:cake_wallet/src/domain/common/crypto_currency.dart';
|
||||
import 'package:cake_wallet/src/domain/common/fiat_currency.dart';
|
||||
import 'package:cake_wallet/src/domain/common/transaction_priority.dart';
|
||||
import 'package:cake_wallet/store/settings_store.dart';
|
||||
import 'package:cake_wallet/view_model/send/send_view_model_state.dart';
|
||||
import 'package:cake_wallet/src/domain/common/wallet_type.dart';
|
||||
import 'package:cake_wallet/bitcoin/bitcoin_transaction_credentials.dart';
|
||||
|
||||
part 'send_view_model.g.dart';
|
||||
|
||||
class SendViewModel = SendViewModelBase with _$SendViewModel;
|
||||
|
||||
abstract class SendViewModelBase with Store {
|
||||
SendViewModelBase(
|
||||
this._wallet, this._settingsStore, this._fiatConversationStore)
|
||||
: state = InitialSendViewModelState(),
|
||||
_cryptoNumberFormat = NumberFormat()..maximumFractionDigits = 12,
|
||||
all = false;
|
||||
|
||||
@observable
|
||||
SendViewModelState state;
|
||||
|
||||
@observable
|
||||
String fiatAmount;
|
||||
|
||||
@observable
|
||||
String cryptoAmount;
|
||||
|
||||
@observable
|
||||
String address;
|
||||
|
||||
@observable
|
||||
bool all;
|
||||
|
||||
FiatCurrency get fiat => _settingsStore.fiatCurrency;
|
||||
|
||||
TransactionPriority get transactionPriority =>
|
||||
_settingsStore.transactionPriority;
|
||||
|
||||
double get estimatedFee =>
|
||||
_wallet.calculateEstimatedFee(_settingsStore.transactionPriority);
|
||||
|
||||
CryptoCurrency get currency => _wallet.currency;
|
||||
|
||||
Validator get amountValidator => AmountValidator(type: _wallet.type);
|
||||
|
||||
Validator get addressValidator => AddressValidator(type: _wallet.currency);
|
||||
|
||||
PendingTransaction pendingTransaction;
|
||||
|
||||
@computed
|
||||
String get balance {
|
||||
if (_wallet is MoneroWallet) {
|
||||
_wallet.balance.formattedUnlockedBalance;
|
||||
}
|
||||
|
||||
if (_wallet is BitcoinWallet) {
|
||||
_wallet.balance.confirmedFormatted;
|
||||
}
|
||||
|
||||
return '0.0';
|
||||
}
|
||||
|
||||
@computed
|
||||
bool get isReadyForSend => _wallet.syncStatus is SyncedSyncStatus;
|
||||
|
||||
final WalletBase _wallet;
|
||||
final SettingsStore _settingsStore;
|
||||
final FiatConvertationStore _fiatConversationStore;
|
||||
NumberFormat _cryptoNumberFormat;
|
||||
|
||||
@action
|
||||
void setAll() => all = true;
|
||||
|
||||
@action
|
||||
void reset() {
|
||||
cryptoAmount = '';
|
||||
fiatAmount = '';
|
||||
address = '';
|
||||
}
|
||||
|
||||
@action
|
||||
Future<void> createTransaction() async {
|
||||
try {
|
||||
state = TransactionIsCreating();
|
||||
pendingTransaction = await _wallet.createTransaction(_credentials());
|
||||
state = TransactionCreatedSuccessfully();
|
||||
} catch (e) {
|
||||
state = SendingFailed(error: e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@action
|
||||
Future<void> commitTransaction() async {
|
||||
try {
|
||||
state = TransactionCommitting();
|
||||
await pendingTransaction.commit();
|
||||
state = TransactionCommitted();
|
||||
} catch (e) {
|
||||
state = SendingFailed(error: e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@action
|
||||
void setCryptoAmount(String amount) {
|
||||
cryptoAmount = amount;
|
||||
_updateFiatAmount();
|
||||
}
|
||||
|
||||
@action
|
||||
void setFiatAmount(String amount) {
|
||||
fiatAmount = amount;
|
||||
_updateCryptoAmount();
|
||||
}
|
||||
|
||||
@action
|
||||
void _updateFiatAmount() {
|
||||
try {
|
||||
final fiat = calculateFiatAmount(
|
||||
price: _fiatConversationStore.price, cryptoAmount: cryptoAmount);
|
||||
if (fiatAmount != fiat) {
|
||||
fiatAmount = fiat;
|
||||
}
|
||||
} catch (_) {
|
||||
fiatAmount = '';
|
||||
}
|
||||
}
|
||||
|
||||
@action
|
||||
void _updateCryptoAmount() {
|
||||
try {
|
||||
final crypto = double.parse(fiatAmount) / _fiatConversationStore.price;
|
||||
final cryptoAmountTmp = _cryptoNumberFormat.format(crypto);
|
||||
|
||||
if (cryptoAmount != cryptoAmountTmp) {
|
||||
cryptoAmount = cryptoAmountTmp;
|
||||
}
|
||||
} catch (e) {
|
||||
cryptoAmount = '';
|
||||
}
|
||||
}
|
||||
|
||||
Object _credentials() {
|
||||
final amount =
|
||||
!all ? double.parse(cryptoAmount.replaceAll(',', '.')) : null;
|
||||
|
||||
switch (_wallet.type) {
|
||||
case WalletType.bitcoin:
|
||||
return BitcoinTransactionCredentials(
|
||||
address, amount, _settingsStore.transactionPriority);
|
||||
case WalletType.monero:
|
||||
// FIXME: Wrong credentials
|
||||
return BitcoinTransactionCredentials(
|
||||
address, amount, _settingsStore.transactionPriority);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
abstract class SendViewModelState {}
|
||||
|
||||
class InitialSendViewModelState extends SendViewModelState {}
|
||||
|
||||
class TransactionIsCreating extends SendViewModelState {}
|
||||
class TransactionCreatedSuccessfully extends SendViewModelState {}
|
||||
|
||||
class TransactionCommitting extends SendViewModelState {}
|
||||
|
||||
class TransactionCommitted extends SendViewModelState {}
|
||||
|
||||
class SendingFailed extends SendViewModelState {
|
||||
SendingFailed({@required this.error});
|
||||
|
||||
String error;
|
||||
}
|
||||
@@ -1,94 +0,0 @@
|
||||
import 'package:cake_wallet/core/address_validator.dart';
|
||||
import 'package:cake_wallet/core/amount_validator.dart';
|
||||
import 'package:cake_wallet/core/validator.dart';
|
||||
import 'package:cake_wallet/core/wallet_base.dart';
|
||||
import 'package:cake_wallet/bitcoin/bitcoin_wallet.dart';
|
||||
import 'package:cake_wallet/monero/monero_wallet.dart';
|
||||
import 'package:cake_wallet/src/domain/common/balance.dart';
|
||||
import 'package:cake_wallet/src/domain/common/calculate_estimated_fee.dart';
|
||||
import 'package:cake_wallet/src/domain/common/crypto_currency.dart';
|
||||
import 'package:cake_wallet/src/domain/common/fiat_currency.dart';
|
||||
import 'package:cake_wallet/src/domain/common/transaction_priority.dart';
|
||||
import 'package:cake_wallet/store/settings_store.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:mobx/mobx.dart';
|
||||
import 'package:cake_wallet/monero/monero_wallet_service.dart';
|
||||
import 'package:cake_wallet/bitcoin/bitcoin_wallet_creation_credentials.dart';
|
||||
import 'package:cake_wallet/core/wallet_creation_service.dart';
|
||||
import 'package:cake_wallet/core/wallet_credentials.dart';
|
||||
import 'package:cake_wallet/src/domain/common/wallet_type.dart';
|
||||
import 'package:cake_wallet/view_model/wallet_creation_vm.dart';
|
||||
|
||||
part 'send_view_model.g.dart';
|
||||
|
||||
abstract class SendViewModelState {}
|
||||
|
||||
class InitialSendViewModelState extends SendViewModelState {}
|
||||
|
||||
class TransactionIsCreating extends SendViewModelState {}
|
||||
|
||||
class TransactionCreatedSuccessfully extends SendViewModelState {}
|
||||
|
||||
class TransactionCommitting extends SendViewModelState {}
|
||||
|
||||
class TransactionCommitted extends SendViewModelState {}
|
||||
|
||||
class SendingFailed extends SendViewModelState {
|
||||
SendingFailed({@required this.error});
|
||||
|
||||
String error;
|
||||
}
|
||||
|
||||
class SendViewModel = SendViewModelBase with _$SendViewModel;
|
||||
|
||||
abstract class SendViewModelBase with Store {
|
||||
SendViewModelBase(this._wallet, this._settingsStore)
|
||||
: state = InitialSendViewModelState();
|
||||
|
||||
@observable
|
||||
SendViewModelState state;
|
||||
|
||||
@observable
|
||||
String fiatAmount;
|
||||
|
||||
@observable
|
||||
String cryptoAmount;
|
||||
|
||||
@observable
|
||||
String address;
|
||||
|
||||
FiatCurrency get fiat => _settingsStore.fiatCurrency;
|
||||
|
||||
TransactionPriority get transactionPriority =>
|
||||
_settingsStore.transactionPriority;
|
||||
|
||||
double get estimatedFee =>
|
||||
calculateEstimatedFee(priority: transactionPriority);
|
||||
|
||||
CryptoCurrency get currency => _wallet.currency;
|
||||
|
||||
Validator get amountValidator => AmountValidator(type: _wallet.type);
|
||||
|
||||
Validator get addressValidator => AddressValidator(type: _wallet.currency);
|
||||
|
||||
@computed
|
||||
String get balance {
|
||||
if (_wallet is MoneroWallet) {
|
||||
_wallet.balance.formattedUnlockedBalance;
|
||||
}
|
||||
|
||||
if (_wallet is BitcoinWallet) {
|
||||
_wallet.balance.confirmedFormatted;
|
||||
}
|
||||
|
||||
return '0.0';
|
||||
}
|
||||
|
||||
WalletBase _wallet;
|
||||
|
||||
SettingsStore _settingsStore;
|
||||
|
||||
Future<void> createTransaction() async {}
|
||||
|
||||
Future<void> commitTransaction() async {}
|
||||
}
|
||||
@@ -4,10 +4,19 @@ import 'package:cake_wallet/view_model/settings/settings_list_item.dart';
|
||||
class PickerListItem<ItemType> extends SettingsListItem {
|
||||
PickerListItem(
|
||||
{@required String title,
|
||||
@required this.selectedItem,
|
||||
@required this.items})
|
||||
: super(title);
|
||||
@required this.selectedItem,
|
||||
@required this.items,
|
||||
void Function(ItemType item) onItemSelected})
|
||||
: _onItemSelected = onItemSelected,
|
||||
super(title);
|
||||
|
||||
final ItemType Function() selectedItem;
|
||||
final List<ItemType> items;
|
||||
final void Function(ItemType item) _onItemSelected;
|
||||
|
||||
void onItemSelected(dynamic item) {
|
||||
if (item is ItemType) {
|
||||
_onItemSelected?.call(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import 'package:cake_wallet/core/wallet_base.dart';
|
||||
import 'package:cake_wallet/src/domain/common/wallet_type.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:mobx/mobx.dart';
|
||||
import 'package:cake_wallet/routes.dart';
|
||||
@@ -20,7 +22,8 @@ part 'settings_view_model.g.dart';
|
||||
class SettingsViewModel = SettingsViewModelBase with _$SettingsViewModel;
|
||||
|
||||
abstract class SettingsViewModelBase with Store {
|
||||
SettingsViewModelBase(this._settingsStore) : itemHeaders = {} {
|
||||
SettingsViewModelBase(this._settingsStore, WalletBase wallet)
|
||||
: itemHeaders = {} {
|
||||
sections = [
|
||||
[
|
||||
PickerListItem(
|
||||
@@ -33,8 +36,10 @@ abstract class SettingsViewModelBase with Store {
|
||||
selectedItem: () => fiatCurrency),
|
||||
PickerListItem(
|
||||
title: S.current.settings_fee_priority,
|
||||
items: TransactionPriority.all,
|
||||
selectedItem: () => transactionPriority),
|
||||
items: _transactionPriorities(wallet.type),
|
||||
selectedItem: () => transactionPriority,
|
||||
onItemSelected: (TransactionPriority priority) =>
|
||||
_settingsStore.transactionPriority = priority),
|
||||
SwitcherListItem(
|
||||
title: S.current.settings_save_recipient_address,
|
||||
value: () => shouldSaveRecipientAddress,
|
||||
@@ -146,12 +151,9 @@ abstract class SettingsViewModelBase with Store {
|
||||
_settingsStore.allowBiometricalAuthentication = value;
|
||||
|
||||
// @observable
|
||||
// bool isDarkTheme;
|
||||
//
|
||||
// @observable
|
||||
// int defaultPinLength;
|
||||
|
||||
// @observable
|
||||
|
||||
final Map<String, String> itemHeaders;
|
||||
List<List<SettingsListItem>> sections;
|
||||
final SettingsStore _settingsStore;
|
||||
@@ -182,4 +184,24 @@ abstract class SettingsViewModelBase with Store {
|
||||
|
||||
@action
|
||||
void _showTrades() => actionlistDisplayMode.add(ActionListDisplayMode.trades);
|
||||
|
||||
//
|
||||
// @observable
|
||||
// int defaultPinLength;
|
||||
// bool isDarkTheme;
|
||||
|
||||
static List<TransactionPriority> _transactionPriorities(WalletType type) {
|
||||
switch (type) {
|
||||
case WalletType.monero:
|
||||
return TransactionPriority.all;
|
||||
case WalletType.bitcoin:
|
||||
return [
|
||||
TransactionPriority.slow,
|
||||
TransactionPriority.regular,
|
||||
TransactionPriority.fast
|
||||
];
|
||||
default:
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user