/* * 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 'package:flutter/cupertino.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import '../utilities/enums/stack_restoring_status.dart'; import '../wallets/wallet/wallet.dart'; import 'wallet_restore_state.dart'; class StackRestoringUIState extends ChangeNotifier { bool _walletsWasSet = false; bool get done { if (!_walletsWasSet) { return false; } bool _done = (_decryption == StackRestoringStatus.success) || (_decryption == StackRestoringStatus.failed); _done &= (_addressBook == StackRestoringStatus.success) || (_addressBook == StackRestoringStatus.failed); _done &= (_preferences == StackRestoringStatus.success) || (_preferences == StackRestoringStatus.failed); _done &= (_trades == StackRestoringStatus.success) || (_trades == StackRestoringStatus.failed); _done &= (_nodes == StackRestoringStatus.success) || (_nodes == StackRestoringStatus.failed); for (final wallet in _walletStates.values) { _done &= (wallet.restoringState == StackRestoringStatus.success) || (wallet.restoringState == StackRestoringStatus.failed); } return _done; } bool get succeeded { if (!_walletsWasSet) { return false; } bool _succeeded = _decryption == StackRestoringStatus.success; _succeeded &= _addressBook == StackRestoringStatus.success; _succeeded &= _preferences == StackRestoringStatus.success; _succeeded &= _trades == StackRestoringStatus.success; _succeeded &= _nodes == StackRestoringStatus.success; for (final wallet in _walletStates.values) { _succeeded &= wallet.restoringState == StackRestoringStatus.success; } return _succeeded; } StackRestoringStatus _decryption = StackRestoringStatus.waiting; StackRestoringStatus get decryption => _decryption; set decryption(StackRestoringStatus state) { _decryption = state; notifyListeners(); } StackRestoringStatus _addressBook = StackRestoringStatus.waiting; StackRestoringStatus get addressBook => _addressBook; set addressBook(StackRestoringStatus state) { _addressBook = state; notifyListeners(); } StackRestoringStatus _preferences = StackRestoringStatus.waiting; StackRestoringStatus get preferences => _preferences; set preferences(StackRestoringStatus state) { _preferences = state; notifyListeners(); } StackRestoringStatus _trades = StackRestoringStatus.waiting; StackRestoringStatus get trades => _trades; set trades(StackRestoringStatus state) { _trades = state; notifyListeners(); } StackRestoringStatus _nodes = StackRestoringStatus.waiting; StackRestoringStatus get nodes => _nodes; set nodes(StackRestoringStatus state) { _nodes = state; notifyListeners(); } List get wallets { final List _wallets = []; for (final item in _walletStates.values) { if (item.wallet != null) { _wallets.add(item.wallet!); } } return _wallets; } Map _walletStates = {}; set walletStates(Map state) { _walletStates = state; _walletStateProviders = {}; for (final wallet in _walletStates.values) { _walletStateProviders[wallet.walletId] = ChangeNotifierProvider((_) => wallet); } _walletsWasSet = true; notifyListeners(); } Map> _walletStateProviders = {}; Map> get walletStateProviders => _walletStateProviders; WalletRestoreState getWalletRestoreState(String walletId) { return _walletStates[walletId]!; } ChangeNotifierProvider getWalletRestoreStateProvider( String walletId, ) { return _walletStateProviders[walletId]!; } void update({ required String walletId, required StackRestoringStatus restoringStatus, Wallet? wallet, String? address, String? mnemonic, String? mnemonicPassphrase, int? height, }) { _walletStates[walletId]!.restoringState = restoringStatus; _walletStates[walletId]!.wallet = wallet ?? _walletStates[walletId]!.wallet; _walletStates[walletId]!.address = address ?? _walletStates[walletId]!.address; _walletStates[walletId]!.mnemonic = mnemonic ?? _walletStates[walletId]!.mnemonic; _walletStates[walletId]!.mnemonicPassphrase = mnemonicPassphrase ?? _walletStates[walletId]!.mnemonicPassphrase; _walletStates[walletId]!.height = height ?? _walletStates[walletId]!.height; notifyListeners(); } }