/* * This file is part of Stack Wallet. * * Copyright (c) 2023 Cypher Stack * All Rights Reserved. * The code is distributed under GPLv3 license, see LICENSE file for details. * Generated by Cypher Stack on 2023-05-26 * */ import 'dart:convert'; import 'package:flutter/material.dart'; import 'package:stackwallet/db/hive/db.dart'; import 'package:stackwallet/utilities/enums/coin_enum.dart'; import 'package:stackwallet/utilities/logger.dart'; @Deprecated("Legacy support only. Do not use.") class WalletInfo { final Coin coin; final String walletId; final String name; @Deprecated("Legacy support only. Do not use.") const WalletInfo({ required this.coin, required this.walletId, required this.name, }); @Deprecated("Legacy support only. Do not use.") factory WalletInfo.fromJson(Map jsonObject) { return WalletInfo( coin: Coin.values.byName(jsonObject["coin"] as String), walletId: jsonObject["id"] as String, name: jsonObject["name"] as String, ); } @Deprecated("Legacy support only. Do not use.") Map toMap() { return { "name": name, "id": walletId, "coin": coin.name, }; } @Deprecated("Legacy support only. Do not use.") String toJsonString() { return jsonEncode(toMap()); } @override @Deprecated("Legacy support only. Do not use.") String toString() { return "WalletInfo: ${toJsonString()}"; } } @Deprecated("Legacy support only. Do not use.") class WalletsService extends ChangeNotifier { @Deprecated("Legacy support only. Do not use.") Future>? _walletNames; @Deprecated("Legacy support only. Do not use.") Future> get walletNames => _walletNames ??= _fetchWalletNames(); @Deprecated("Legacy support only. Do not use.") WalletsService(); @Deprecated("Legacy support only. Do not use.") Future> _fetchWalletNames() async { final names = DB.instance .get(boxName: DB.boxNameAllWalletsData, key: 'names') as Map?; if (names == null) { Logging.instance.log( "Fetched wallet 'names' returned null. Setting initializing 'names'", level: LogLevel.Info); await DB.instance.put( boxName: DB.boxNameAllWalletsData, key: 'names', value: {}); return {}; } Logging.instance.log("Fetched wallet names: $names", level: LogLevel.Info); final mapped = Map.from(names); mapped.removeWhere((name, dyn) { final jsonObject = Map.from(dyn as Map); try { Coin.values.byName(jsonObject["coin"] as String); return false; } catch (e, s) { Logging.instance.log("Error, ${jsonObject["coin"]} does not exist", level: LogLevel.Error); return true; } }); return mapped.map((name, dyn) => MapEntry( name, WalletInfo.fromJson(Map.from(dyn as Map)))); } }