mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-10-27 06:18:50 +01:00
TMP 0
This commit is contained in:
@@ -129,6 +129,11 @@ abstract class DashboardViewModelBase with Store {
|
||||
|
||||
ReactionDisposer _reaction;
|
||||
|
||||
Future<void> reconnect() async {
|
||||
final node = appStore.settingsStore.getCurrentNode(wallet.type);
|
||||
await wallet.connectToNode(node: node);
|
||||
}
|
||||
|
||||
void _onWalletChange(WalletBase wallet) {
|
||||
name = wallet.name;
|
||||
transactions.clear();
|
||||
|
||||
@@ -1,26 +1,92 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:mobx/mobx.dart';
|
||||
import 'package:cake_wallet/core/wallet_base.dart';
|
||||
import 'package:cake_wallet/src/domain/common/node.dart';
|
||||
import 'package:cake_wallet/src/domain/common/node_list.dart';
|
||||
import 'package:cake_wallet/store/node_list_store.dart';
|
||||
import 'package:cake_wallet/store/settings_store.dart';
|
||||
import 'package:cake_wallet/src/domain/common/default_settings_migration.dart';
|
||||
import 'package:cake_wallet/src/domain/common/wallet_type.dart';
|
||||
import 'package:cake_wallet/utils/mobx.dart';
|
||||
|
||||
part 'node_list_view_model.g.dart';
|
||||
|
||||
class NodeListViewModel = NodeListViewModelBase with _$NodeListViewModel;
|
||||
|
||||
abstract class NodeListViewModelBase with Store {
|
||||
NodeListViewModelBase(this._nodeListStore, this._nodeSource, this._wallet);
|
||||
class ItemCell<Item> {
|
||||
ItemCell(this.value, {@required this.isSelected});
|
||||
|
||||
@computed
|
||||
ObservableList<Node> get nodes => ObservableList<Node>.of(
|
||||
_nodeListStore.nodes.where((node) => node.type == _wallet.type));
|
||||
final Item value;
|
||||
final bool isSelected;
|
||||
}
|
||||
|
||||
abstract class NodeListViewModelBase with Store {
|
||||
NodeListViewModelBase(
|
||||
this._nodeListStore, this._nodeSource, this._wallet, this._settingsStore)
|
||||
: nodes = ObservableList<ItemCell<Node>>() {
|
||||
final currentNode = _settingsStore.getCurrentNode(_wallet.type);
|
||||
final values = _nodeListStore.nodes;
|
||||
nodes.clear();
|
||||
nodes.addAll(values.where((Node node) => node.type == _wallet.type).map(
|
||||
(Node val) =>
|
||||
ItemCell<Node>(val, isSelected: val.key == currentNode.key)));
|
||||
connectDifferent(
|
||||
_nodeListStore.nodes,
|
||||
nodes,
|
||||
(Node val) =>
|
||||
ItemCell<Node>(val, isSelected: val.key == currentNode.key),
|
||||
filter: (Node val) {
|
||||
return val.type == _wallet.type;
|
||||
});
|
||||
}
|
||||
|
||||
ObservableList<ItemCell<Node>> nodes;
|
||||
|
||||
final WalletBase _wallet;
|
||||
final Box<Node> _nodeSource;
|
||||
final NodeListStore _nodeListStore;
|
||||
final SettingsStore _settingsStore;
|
||||
|
||||
Future<void> reset() async => await resetToDefault(_nodeSource);
|
||||
Future<void> reset() async {
|
||||
await resetToDefault(_nodeSource);
|
||||
|
||||
Future<void> delete(Node node) async => node.delete();
|
||||
Node node;
|
||||
|
||||
switch (_wallet.type) {
|
||||
case WalletType.bitcoin:
|
||||
node = getBitcoinDefaultElectrumServer(nodes: _nodeSource);
|
||||
break;
|
||||
case WalletType.monero:
|
||||
node = getMoneroDefaultNode(
|
||||
nodes: _nodeSource,
|
||||
);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
await _wallet.connectToNode(node: node);
|
||||
}
|
||||
|
||||
Future<void> delete(Node node) async => _nodeSource.delete(node.key);
|
||||
|
||||
Future<void> setAsCurrent(Node node) async {
|
||||
await _wallet.connectToNode(node: node);
|
||||
await _settingsStore.setCurrentNode(node, _wallet.type);
|
||||
_updateCurrentNode();
|
||||
}
|
||||
|
||||
void _updateCurrentNode() {
|
||||
final currentNode = _settingsStore.getCurrentNode(_wallet.type);
|
||||
|
||||
for (var i = 0; i < nodes.length; i++) {
|
||||
final item = nodes[i];
|
||||
final isSelected = item.value.key == currentNode.key;
|
||||
|
||||
if (item.isSelected != isSelected) {
|
||||
nodes[i] = ItemCell<Node>(item.value, isSelected: isSelected);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ abstract class SendViewModelBase with Store {
|
||||
this._wallet, this._settingsStore, this._fiatConversationStore)
|
||||
: state = InitialSendViewModelState(),
|
||||
_cryptoNumberFormat = NumberFormat()..maximumFractionDigits = 12,
|
||||
// FIXME: need to be based on wallet type.
|
||||
all = false;
|
||||
|
||||
@observable
|
||||
@@ -79,7 +80,7 @@ abstract class SendViewModelBase with Store {
|
||||
final WalletBase _wallet;
|
||||
final SettingsStore _settingsStore;
|
||||
final FiatConvertationStore _fiatConversationStore;
|
||||
NumberFormat _cryptoNumberFormat;
|
||||
final NumberFormat _cryptoNumberFormat;
|
||||
|
||||
@action
|
||||
void setAll() => all = true;
|
||||
@@ -129,7 +130,8 @@ abstract class SendViewModelBase with Store {
|
||||
void _updateFiatAmount() {
|
||||
try {
|
||||
final fiat = calculateFiatAmount(
|
||||
price: _fiatConversationStore.price, cryptoAmount: cryptoAmount);
|
||||
price: _fiatConversationStore.price,
|
||||
cryptoAmount: cryptoAmount.replaceAll(',', '.'));
|
||||
if (fiatAmount != fiat) {
|
||||
fiatAmount = fiat;
|
||||
}
|
||||
@@ -141,7 +143,8 @@ abstract class SendViewModelBase with Store {
|
||||
@action
|
||||
void _updateCryptoAmount() {
|
||||
try {
|
||||
final crypto = double.parse(fiatAmount) / _fiatConversationStore.price;
|
||||
final crypto = double.parse(fiatAmount.replaceAll(',', '.')) /
|
||||
_fiatConversationStore.price;
|
||||
final cryptoAmountTmp = _cryptoNumberFormat.format(crypto);
|
||||
|
||||
if (cryptoAmount != cryptoAmountTmp) {
|
||||
|
||||
@@ -23,7 +23,8 @@ class SettingsViewModel = SettingsViewModelBase with _$SettingsViewModel;
|
||||
|
||||
abstract class SettingsViewModelBase with Store {
|
||||
SettingsViewModelBase(this._settingsStore, WalletBase wallet)
|
||||
: itemHeaders = {} {
|
||||
: itemHeaders = {},
|
||||
_walletType = wallet.type {
|
||||
sections = [
|
||||
[
|
||||
PickerListItem(
|
||||
@@ -117,7 +118,7 @@ abstract class SettingsViewModelBase with Store {
|
||||
}
|
||||
|
||||
@computed
|
||||
Node get node => _settingsStore.node;
|
||||
Node get node => _settingsStore.getCurrentNode(_walletType);
|
||||
|
||||
@computed
|
||||
FiatCurrency get fiatCurrency => _settingsStore.fiatCurrency;
|
||||
@@ -150,13 +151,10 @@ abstract class SettingsViewModelBase with Store {
|
||||
set allowBiometricalAuthentication(bool value) =>
|
||||
_settingsStore.allowBiometricalAuthentication = value;
|
||||
|
||||
// @observable
|
||||
|
||||
// @observable
|
||||
|
||||
final Map<String, String> itemHeaders;
|
||||
List<List<SettingsListItem>> sections;
|
||||
final SettingsStore _settingsStore;
|
||||
final WalletType _walletType;
|
||||
List<List<SettingsListItem>> sections;
|
||||
|
||||
@action
|
||||
void toggleTransactionsDisplay() =>
|
||||
|
||||
@@ -3,9 +3,10 @@ import 'package:cake_wallet/src/domain/common/wallet_type.dart';
|
||||
|
||||
class WalletListItem {
|
||||
const WalletListItem(
|
||||
{@required this.name, @required this.type, this.isCurrent = false});
|
||||
{@required this.name, @required this.type, @required this.key, this.isCurrent = false});
|
||||
|
||||
final String name;
|
||||
final WalletType type;
|
||||
final bool isCurrent;
|
||||
final dynamic key;
|
||||
}
|
||||
|
||||
@@ -17,11 +17,7 @@ abstract class WalletListViewModelBase with Store {
|
||||
WalletListViewModelBase(
|
||||
this._walletInfoSource, this._appStore, this._keyService) {
|
||||
wallets = ObservableList<WalletListItem>();
|
||||
wallets.addAll(_walletInfoSource.values.map((info) => WalletListItem(
|
||||
name: info.name,
|
||||
type: info.type,
|
||||
isCurrent: info.name == _appStore.wallet.name &&
|
||||
info.type == _appStore.wallet.type)));
|
||||
_updateList();
|
||||
}
|
||||
|
||||
@observable
|
||||
@@ -40,7 +36,12 @@ abstract class WalletListViewModelBase with Store {
|
||||
}
|
||||
|
||||
@action
|
||||
Future<void> remove(WalletListItem wallet) async {}
|
||||
Future<void> remove(WalletListItem wallet) async {
|
||||
final walletService = _getWalletService(wallet.type);
|
||||
await walletService.remove(wallet.name);
|
||||
await _walletInfoSource.delete(wallet.key);
|
||||
_updateList();
|
||||
}
|
||||
|
||||
WalletService _getWalletService(WalletType type) {
|
||||
switch (type) {
|
||||
@@ -52,4 +53,14 @@ abstract class WalletListViewModelBase with Store {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
void _updateList() {
|
||||
wallets.clear();
|
||||
wallets.addAll(_walletInfoSource.values.map((info) => WalletListItem(
|
||||
name: info.name,
|
||||
type: info.type,
|
||||
key: info.key,
|
||||
isCurrent: info.name == _appStore.wallet.name &&
|
||||
info.type == _appStore.wallet.type)));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user