mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-10-19 05:58:50 +02:00
TMP 0
This commit is contained in:
@@ -29,15 +29,19 @@ Future defaultSettingsMigration(
|
||||
switch (version) {
|
||||
case 1:
|
||||
await sharedPreferences.setString(
|
||||
SettingsStoreBase.currentFiatCurrencyKey, FiatCurrency.usd.toString());
|
||||
SettingsStoreBase.currentFiatCurrencyKey,
|
||||
FiatCurrency.usd.toString());
|
||||
await sharedPreferences.setInt(
|
||||
SettingsStoreBase.currentTransactionPriorityKey, TransactionPriority.standart.raw);
|
||||
SettingsStoreBase.currentTransactionPriorityKey,
|
||||
TransactionPriority.standart.raw);
|
||||
await sharedPreferences.setInt(
|
||||
SettingsStoreBase.currentBalanceDisplayModeKey,
|
||||
BalanceDisplayMode.availableBalance.raw);
|
||||
await sharedPreferences.setBool('save_recipient_address', true);
|
||||
await resetToDefault(nodes);
|
||||
await changeCurrentNodeToDefault(
|
||||
await changeMoneroCurrentNodeToDefault(
|
||||
sharedPreferences: sharedPreferences, nodes: nodes);
|
||||
await changeBitcoinCurrentElectrumServerToDefault(
|
||||
sharedPreferences: sharedPreferences, nodes: nodes);
|
||||
|
||||
break;
|
||||
@@ -50,6 +54,11 @@ Future defaultSettingsMigration(
|
||||
case 3:
|
||||
await updateNodeTypes(nodes: nodes);
|
||||
await addBitcoinElectrumServerList(nodes: nodes);
|
||||
|
||||
break;
|
||||
case 4:
|
||||
await changeBitcoinCurrentElectrumServerToDefault(
|
||||
sharedPreferences: sharedPreferences, nodes: nodes);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -69,10 +78,11 @@ Future defaultSettingsMigration(
|
||||
Future<void> replaceNodesMigration({@required Box<Node> nodes}) async {
|
||||
final replaceNodes = <String, Node>{
|
||||
'eu-node.cakewallet.io:18081':
|
||||
Node(uri: 'xmr-node-eu.cakewallet.com:18081'),
|
||||
'node.cakewallet.io:18081':
|
||||
Node(uri: 'xmr-node-usa-east.cakewallet.com:18081'),
|
||||
'node.xmr.ru:13666': Node(uri: 'node.monero.net:18081')
|
||||
Node(uri: 'xmr-node-eu.cakewallet.com:18081', type: WalletType.monero),
|
||||
'node.cakewallet.io:18081': Node(
|
||||
uri: 'xmr-node-usa-east.cakewallet.com:18081', type: WalletType.monero),
|
||||
'node.xmr.ru:13666':
|
||||
Node(uri: 'node.monero.net:18081', type: WalletType.monero)
|
||||
};
|
||||
|
||||
nodes.values.forEach((Node node) async {
|
||||
@@ -87,11 +97,27 @@ Future<void> replaceNodesMigration({@required Box<Node> nodes}) async {
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> changeCurrentNodeToDefault(
|
||||
Future<void> changeMoneroCurrentNodeToDefault(
|
||||
{@required SharedPreferences sharedPreferences,
|
||||
@required Box<Node> nodes}) async {
|
||||
final node = getMoneroDefaultNode(nodes: nodes);
|
||||
final nodeId = node?.key as int ?? 0; // 0 - England
|
||||
|
||||
await sharedPreferences.setInt('current_node_id', nodeId);
|
||||
}
|
||||
|
||||
Node getBitcoinDefaultElectrumServer({@required Box<Node> nodes}) {
|
||||
final uri = 'bitcoin.electrumx.multicoin.co:50002';
|
||||
|
||||
return nodes.values
|
||||
.firstWhere((Node node) => node.uri == uri, orElse: () => null) ??
|
||||
nodes.values.firstWhere((node) => node.type == WalletType.bitcoin,
|
||||
orElse: () => null);
|
||||
}
|
||||
|
||||
Node getMoneroDefaultNode({@required Box<Node> nodes}) {
|
||||
final timeZone = DateTime.now().timeZoneOffset.inHours;
|
||||
String nodeUri = '';
|
||||
var nodeUri = '';
|
||||
|
||||
if (timeZone >= 1) {
|
||||
// Eurasia
|
||||
@@ -101,11 +127,18 @@ Future<void> changeCurrentNodeToDefault(
|
||||
nodeUri = 'xmr-node-usa-east.cakewallet.com:18081';
|
||||
}
|
||||
|
||||
final node = nodes.values.firstWhere((Node node) => node.uri == nodeUri) ??
|
||||
return nodes.values
|
||||
.firstWhere((Node node) => node.uri == nodeUri, orElse: () => null) ??
|
||||
nodes.values.first;
|
||||
final nodeId = node != null ? node.key as int : 0; // 0 - England
|
||||
}
|
||||
|
||||
await sharedPreferences.setInt('current_node_id', nodeId);
|
||||
Future<void> changeBitcoinCurrentElectrumServerToDefault(
|
||||
{@required SharedPreferences sharedPreferences,
|
||||
@required Box<Node> nodes}) async {
|
||||
final server = getBitcoinDefaultElectrumServer(nodes: nodes);
|
||||
final serverId = server?.key as int ?? 0;
|
||||
|
||||
await sharedPreferences.setInt('current_node_id_btc', serverId);
|
||||
}
|
||||
|
||||
Future<void> replaceDefaultNode(
|
||||
@@ -126,7 +159,7 @@ Future<void> replaceDefaultNode(
|
||||
return;
|
||||
}
|
||||
|
||||
await changeCurrentNodeToDefault(
|
||||
await changeMoneroCurrentNodeToDefault(
|
||||
sharedPreferences: sharedPreferences, nodes: nodes);
|
||||
}
|
||||
|
||||
|
||||
@@ -9,12 +9,16 @@ part 'node.g.dart';
|
||||
|
||||
@HiveType(typeId: 1)
|
||||
class Node extends HiveObject {
|
||||
Node({@required this.uri, @required WalletType type, this.login, this.password}) {
|
||||
Node(
|
||||
{@required this.uri,
|
||||
@required WalletType type,
|
||||
this.login,
|
||||
this.password}) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
Node.fromMap(Map map)
|
||||
: uri = (map['uri'] ?? '') as String,
|
||||
: uri = map['uri'] as String ?? '',
|
||||
login = map['login'] as String,
|
||||
password = map['password'] as String,
|
||||
typeRaw = map['typeRaw'] as int;
|
||||
|
||||
@@ -10,7 +10,10 @@ Future<List<Node>> loadDefaultNodes() async {
|
||||
|
||||
return nodes.map((dynamic raw) {
|
||||
if (raw is Map) {
|
||||
return Node.fromMap(raw);
|
||||
final node = Node.fromMap(raw);
|
||||
node?.type = WalletType.monero;
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -38,13 +41,7 @@ Future resetToDefault(Box<Node> nodeSource) async {
|
||||
final moneroNodes = await loadDefaultNodes();
|
||||
final bitcoinElectrumServerList = await loadElectrumServerList();
|
||||
final nodes = moneroNodes + bitcoinElectrumServerList;
|
||||
final entities = <int, Node>{};
|
||||
|
||||
await nodeSource.clear();
|
||||
|
||||
for (var i = 0; i < nodes.length; i++) {
|
||||
entities[i] = nodes[i];
|
||||
}
|
||||
|
||||
await nodeSource.putAll(entities);
|
||||
await nodeSource.addAll(nodes);
|
||||
}
|
||||
|
||||
@@ -50,10 +50,7 @@ class DashboardPage extends BasePage {
|
||||
padding: EdgeInsets.all(0),
|
||||
onPressed: () async {
|
||||
await showDialog<void>(
|
||||
builder: (_) => MenuWidget(
|
||||
name: walletViewModel.name,
|
||||
subname: walletViewModel.subname,
|
||||
type: walletViewModel.type),
|
||||
builder: (_) => MenuWidget(walletViewModel),
|
||||
context: context);
|
||||
},
|
||||
child: menuButton
|
||||
|
||||
@@ -6,8 +6,10 @@ import 'package:cake_wallet/src/stores/wallet/wallet_store.dart';
|
||||
import 'package:cake_wallet/src/screens/auth/auth_page.dart';
|
||||
import 'package:cake_wallet/src/widgets/alert_with_two_actions.dart';
|
||||
|
||||
// FIXME: terrible design
|
||||
|
||||
class WalletMenu {
|
||||
WalletMenu(this.context);
|
||||
WalletMenu(this.context, this.reconnect);
|
||||
|
||||
final List<String> items = [
|
||||
S.current.reconnect,
|
||||
@@ -30,6 +32,7 @@ class WalletMenu {
|
||||
];
|
||||
|
||||
final BuildContext context;
|
||||
final Future<void> Function() reconnect;
|
||||
|
||||
void action(int index) {
|
||||
switch (index) {
|
||||
@@ -70,8 +73,6 @@ class WalletMenu {
|
||||
}
|
||||
|
||||
Future<void> _presentReconnectAlert(BuildContext context) async {
|
||||
final walletStore = Provider.of<WalletStore>(context);
|
||||
|
||||
await showDialog<void>(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
@@ -80,12 +81,11 @@ class WalletMenu {
|
||||
alertContent: S.of(context).reconnect_alert_text,
|
||||
leftButtonText: S.of(context).ok,
|
||||
rightButtonText: S.of(context).cancel,
|
||||
actionLeftButton: () {
|
||||
walletStore.reconnect();
|
||||
actionLeftButton: () async {
|
||||
await reconnect?.call();
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
actionRightButton: () => Navigator.of(context).pop()
|
||||
);
|
||||
actionRightButton: () => Navigator.of(context).pop());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
import 'dart:ui';
|
||||
import 'package:cake_wallet/view_model/dashboard/dashboard_view_model.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:cake_wallet/src/domain/common/wallet_type.dart';
|
||||
import 'package:cake_wallet/src/screens/dashboard/wallet_menu.dart';
|
||||
|
||||
class MenuWidget extends StatefulWidget {
|
||||
MenuWidget({this.type, this.name, this.subname});
|
||||
// FIXME: terrible design.
|
||||
|
||||
final WalletType type;
|
||||
final String name;
|
||||
final String subname;
|
||||
class MenuWidget extends StatefulWidget {
|
||||
MenuWidget(this.dashboardViewModel);
|
||||
|
||||
final DashboardViewModel dashboardViewModel;
|
||||
|
||||
@override
|
||||
MenuWidgetState createState() => MenuWidgetState();
|
||||
@@ -65,8 +66,8 @@ class MenuWidgetState extends State<MenuWidget> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final walletMenu = WalletMenu(context);
|
||||
// final walletStore = Provider.of<WalletStore>(context);
|
||||
final walletMenu =
|
||||
WalletMenu(context, () async => widget.dashboardViewModel.reconnect());
|
||||
final itemCount = walletMenu.items.length;
|
||||
|
||||
return Row(
|
||||
@@ -118,19 +119,20 @@ class MenuWidgetState extends State<MenuWidget> {
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
_iconFor(type: widget.type),
|
||||
_iconFor(type: widget.dashboardViewModel.type),
|
||||
SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: Container(
|
||||
height: 40,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: widget.subname != null
|
||||
? MainAxisAlignment.spaceBetween
|
||||
: MainAxisAlignment.center,
|
||||
mainAxisAlignment:
|
||||
widget.dashboardViewModel.subname != null
|
||||
? MainAxisAlignment.spaceBetween
|
||||
: MainAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
Text(
|
||||
widget.name,
|
||||
widget.dashboardViewModel.name,
|
||||
style: TextStyle(
|
||||
color: Theme.of(context)
|
||||
.primaryTextTheme
|
||||
@@ -141,9 +143,9 @@ class MenuWidgetState extends State<MenuWidget> {
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold),
|
||||
),
|
||||
if (widget.subname != null)
|
||||
if (widget.dashboardViewModel.subname != null)
|
||||
Text(
|
||||
widget.subname,
|
||||
widget.dashboardViewModel.subname,
|
||||
style: TextStyle(
|
||||
color: Theme.of(context)
|
||||
.primaryTextTheme
|
||||
|
||||
@@ -74,15 +74,41 @@ class NodeListPage extends BasePage {
|
||||
}
|
||||
|
||||
final node = nodeListViewModel.nodes[index];
|
||||
final isSelected = index == 1; // FIXME: hardcoded value.
|
||||
final nodeListRow = NodeListRow(
|
||||
title: node.uri,
|
||||
isSelected: isSelected,
|
||||
isAlive: node.requestNode(),
|
||||
onTap: (_) {});
|
||||
title: node.value.uri,
|
||||
isSelected: node.isSelected,
|
||||
isAlive: node.value.requestNode(),
|
||||
onTap: (_) async {
|
||||
if (node.isSelected) {
|
||||
return;
|
||||
}
|
||||
|
||||
await showDialog<void>(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return AlertDialog(
|
||||
content: Text(
|
||||
S.of(context).change_current_node(node.value.uri),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
actions: <Widget>[
|
||||
FlatButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: Text(S.of(context).cancel)),
|
||||
FlatButton(
|
||||
onPressed: () async {
|
||||
Navigator.of(context).pop();
|
||||
await nodeListViewModel
|
||||
.setAsCurrent(node.value);
|
||||
},
|
||||
child: Text(S.of(context).change)),
|
||||
],
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
final dismissibleRow = Dismissible(
|
||||
key: Key('${node.key}'),
|
||||
key: Key('${node.value.key}'),
|
||||
confirmDismiss: (direction) async {
|
||||
return await showDialog(
|
||||
context: context,
|
||||
@@ -99,7 +125,7 @@ class NodeListPage extends BasePage {
|
||||
});
|
||||
},
|
||||
onDismissed: (direction) async =>
|
||||
nodeListViewModel.delete(node),
|
||||
nodeListViewModel.delete(node.value),
|
||||
direction: DismissDirection.endToStart,
|
||||
background: Container(
|
||||
padding: EdgeInsets.only(right: 10.0),
|
||||
@@ -120,7 +146,7 @@ class NodeListPage extends BasePage {
|
||||
)),
|
||||
child: nodeListRow);
|
||||
|
||||
return isSelected ? nodeListRow : dismissibleRow;
|
||||
return node.isSelected ? nodeListRow : dismissibleRow;
|
||||
},
|
||||
itemCounter: (int sectionIndex) {
|
||||
if (sectionIndex == 0) {
|
||||
|
||||
@@ -63,14 +63,6 @@ class WalletListBodyState extends State<WalletListBody> {
|
||||
itemBuilder: (__, index) {
|
||||
final wallet = widget.walletListViewModel.wallets[index];
|
||||
final screenWidth = MediaQuery.of(context).size.width;
|
||||
// String shortAddress = '';
|
||||
|
||||
// if (wallet.isCurrent) {
|
||||
// shortAddress = wallet.address;
|
||||
// shortAddress = shortAddress.replaceRange(
|
||||
// 4, shortAddress.length - 4, '...');
|
||||
// }
|
||||
|
||||
final walletMenu = WalletMenu(context, widget.walletListViewModel);
|
||||
final items =
|
||||
walletMenu.generateItemsForWalletMenu(wallet.isCurrent);
|
||||
|
||||
@@ -109,7 +109,7 @@ class WalletMenu {
|
||||
try {
|
||||
auth.changeProcessText(
|
||||
S.of(context).wallet_list_removing_wallet(wallet.name));
|
||||
// await _walletListStore.remove(wallet);
|
||||
await walletListViewModel.remove(wallet);
|
||||
auth.close();
|
||||
} catch (e) {
|
||||
auth.changeProcessText(S
|
||||
|
||||
@@ -42,7 +42,7 @@ abstract class SettingsStoreBase with Store {
|
||||
_sharedPreferences = sharedPreferences;
|
||||
_nodes = nodes;
|
||||
allowBiometricalAuthentication = initialAllowBiometricalAuthentication;
|
||||
isDarkTheme = initialDarkTheme;
|
||||
isDarkTheme = true;
|
||||
defaultPinLength = initialPinLength;
|
||||
languageCode = initialLanguageCode;
|
||||
currentLocale = initialCurrentLocale;
|
||||
@@ -143,7 +143,7 @@ abstract class SettingsStoreBase with Store {
|
||||
bool allowBiometricalAuthentication;
|
||||
|
||||
@observable
|
||||
bool isDarkTheme;
|
||||
bool isDarkTheme = true;
|
||||
|
||||
@observable
|
||||
int defaultPinLength;
|
||||
@@ -285,7 +285,7 @@ abstract class SettingsStoreBase with Store {
|
||||
}
|
||||
|
||||
Future setCurrentNodeToDefault() async {
|
||||
await changeCurrentNodeToDefault(sharedPreferences: _sharedPreferences, nodes: _nodes);
|
||||
// await changeCurrentNodeToDefault(sharedPreferences: _sharedPreferences, nodes: _nodes);
|
||||
await loadSettings();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user