mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-12-23 11:59:30 +00:00
fix node loading on initial start for desktop, only add default node back if there are no nodes exist for a certain coin
This commit is contained in:
parent
42aad5dcd5
commit
05bdc8c52f
3 changed files with 17 additions and 7 deletions
|
@ -7,9 +7,9 @@ import 'package:stackwallet/notifications/show_flush_bar.dart';
|
||||||
import 'package:stackwallet/pages_desktop_specific/home/desktop_home_view.dart';
|
import 'package:stackwallet/pages_desktop_specific/home/desktop_home_view.dart';
|
||||||
import 'package:stackwallet/providers/desktop/storage_crypto_handler_provider.dart';
|
import 'package:stackwallet/providers/desktop/storage_crypto_handler_provider.dart';
|
||||||
import 'package:stackwallet/providers/global/secure_store_provider.dart';
|
import 'package:stackwallet/providers/global/secure_store_provider.dart';
|
||||||
|
import 'package:stackwallet/providers/providers.dart';
|
||||||
import 'package:stackwallet/utilities/assets.dart';
|
import 'package:stackwallet/utilities/assets.dart';
|
||||||
import 'package:stackwallet/utilities/constants.dart';
|
import 'package:stackwallet/utilities/constants.dart';
|
||||||
import 'package:stackwallet/utilities/enums/flush_bar_type.dart';
|
|
||||||
import 'package:stackwallet/utilities/flutter_secure_storage_interface.dart';
|
import 'package:stackwallet/utilities/flutter_secure_storage_interface.dart';
|
||||||
import 'package:stackwallet/utilities/text_styles.dart';
|
import 'package:stackwallet/utilities/text_styles.dart';
|
||||||
import 'package:stackwallet/utilities/theme/stack_colors.dart';
|
import 'package:stackwallet/utilities/theme/stack_colors.dart';
|
||||||
|
@ -81,6 +81,10 @@ class _CreatePasswordViewState extends ConsumerState<CreatePasswordView> {
|
||||||
|
|
||||||
await ref.read(storageCryptoHandlerProvider).initFromNew(passphrase);
|
await ref.read(storageCryptoHandlerProvider).initFromNew(passphrase);
|
||||||
await (ref.read(secureStoreProvider).store as DesktopSecureStore).init();
|
await (ref.read(secureStoreProvider).store as DesktopSecureStore).init();
|
||||||
|
|
||||||
|
// load default nodes now as node service requires storage handler to exist
|
||||||
|
|
||||||
|
await ref.read(nodeServiceChangeNotifierProvider).updateDefaults();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
unawaited(showFloatingFlushBar(
|
unawaited(showFloatingFlushBar(
|
||||||
type: FlushBarType.warning,
|
type: FlushBarType.warning,
|
||||||
|
|
|
@ -24,11 +24,14 @@ class NodeService extends ChangeNotifier {
|
||||||
final savedNode = DB.instance
|
final savedNode = DB.instance
|
||||||
.get<NodeModel>(boxName: DB.boxNameNodeModels, key: defaultNode.id);
|
.get<NodeModel>(boxName: DB.boxNameNodeModels, key: defaultNode.id);
|
||||||
if (savedNode == null) {
|
if (savedNode == null) {
|
||||||
// save the default node to hive
|
// save the default node to hive only if no other nodes for the specific coin exist
|
||||||
await DB.instance.put<NodeModel>(
|
if (getNodesFor(coinFromPrettyName(defaultNode.coinName)).isEmpty) {
|
||||||
|
await DB.instance.put<NodeModel>(
|
||||||
boxName: DB.boxNameNodeModels,
|
boxName: DB.boxNameNodeModels,
|
||||||
key: defaultNode.id,
|
key: defaultNode.id,
|
||||||
value: defaultNode);
|
value: defaultNode,
|
||||||
|
);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// update all fields but copy over previously set enabled state
|
// update all fields but copy over previously set enabled state
|
||||||
await DB.instance.put<NodeModel>(
|
await DB.instance.put<NodeModel>(
|
||||||
|
@ -81,14 +84,16 @@ class NodeService extends ChangeNotifier {
|
||||||
final list = DB.instance
|
final list = DB.instance
|
||||||
.values<NodeModel>(boxName: DB.boxNameNodeModels)
|
.values<NodeModel>(boxName: DB.boxNameNodeModels)
|
||||||
.where((e) =>
|
.where((e) =>
|
||||||
e.coinName == coin.name && e.name != DefaultNodes.defaultName)
|
e.coinName == coin.name &&
|
||||||
|
!e.id.startsWith(DefaultNodes.defaultNodeIdPrefix))
|
||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
// add default to end of list
|
// add default to end of list
|
||||||
list.addAll(DB.instance
|
list.addAll(DB.instance
|
||||||
.values<NodeModel>(boxName: DB.boxNameNodeModels)
|
.values<NodeModel>(boxName: DB.boxNameNodeModels)
|
||||||
.where((e) =>
|
.where((e) =>
|
||||||
e.coinName == coin.name && e.name == DefaultNodes.defaultName)
|
e.coinName == coin.name &&
|
||||||
|
e.id.startsWith(DefaultNodes.defaultNodeIdPrefix))
|
||||||
.toList());
|
.toList());
|
||||||
|
|
||||||
// return reversed list so default node appears at beginning
|
// return reversed list so default node appears at beginning
|
||||||
|
|
|
@ -4,7 +4,8 @@ import 'package:stackwallet/models/node_model.dart';
|
||||||
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
||||||
|
|
||||||
abstract class DefaultNodes {
|
abstract class DefaultNodes {
|
||||||
static String _nodeId(Coin coin) => "default_${coin.name}";
|
static const String defaultNodeIdPrefix = "default_";
|
||||||
|
static String _nodeId(Coin coin) => "$defaultNodeIdPrefix${coin.name}";
|
||||||
static const String defaultName = "Stack Default";
|
static const String defaultName = "Stack Default";
|
||||||
|
|
||||||
static List<NodeModel> get all => [
|
static List<NodeModel> get all => [
|
||||||
|
|
Loading…
Reference in a new issue