2020-01-04 19:31:52 +00:00
|
|
|
import 'package:flutter/services.dart';
|
|
|
|
import 'package:hive/hive.dart';
|
|
|
|
import "package:yaml/yaml.dart";
|
|
|
|
import 'package:cake_wallet/src/domain/common/node.dart';
|
|
|
|
|
|
|
|
Future<List<Node>> loadDefaultNodes() async {
|
2020-01-08 12:26:34 +00:00
|
|
|
final nodesRaw = await rootBundle.loadString('assets/node_list.yml');
|
2020-01-08 16:38:38 +00:00
|
|
|
final nodes = loadYaml(nodesRaw) as YamlList;
|
|
|
|
|
|
|
|
return nodes.map((dynamic raw) {
|
|
|
|
if (raw is Map) {
|
|
|
|
return Node.fromMap(raw);
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}).toList();
|
2020-01-04 19:31:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Future resetToDefault(Box<Node> nodeSource) async {
|
|
|
|
final nodes = await loadDefaultNodes();
|
2020-01-08 12:26:34 +00:00
|
|
|
final enteties = Map<int, Node>();
|
2020-01-04 19:31:52 +00:00
|
|
|
|
2020-01-08 12:26:34 +00:00
|
|
|
await nodeSource.clear();
|
2020-01-04 19:31:52 +00:00
|
|
|
|
|
|
|
for (var i = 0; i < nodes.length; i++) {
|
|
|
|
enteties[i] = nodes[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
await nodeSource.putAll(enteties);
|
2020-01-08 12:26:34 +00:00
|
|
|
}
|