refresh eth wallets list on adding new token wallet

This commit is contained in:
julian 2023-03-28 13:47:17 -06:00
parent 24904f3476
commit 9ad0343d63
3 changed files with 51 additions and 7 deletions

View file

@ -15,7 +15,7 @@ import 'package:stackwallet/pages/add_wallet_views/add_wallet_view/sub_widgets/a
import 'package:stackwallet/pages/add_wallet_views/add_wallet_view/sub_widgets/expanding_sub_list_item.dart'; import 'package:stackwallet/pages/add_wallet_views/add_wallet_view/sub_widgets/expanding_sub_list_item.dart';
import 'package:stackwallet/pages/add_wallet_views/add_wallet_view/sub_widgets/next_button.dart'; import 'package:stackwallet/pages/add_wallet_views/add_wallet_view/sub_widgets/next_button.dart';
import 'package:stackwallet/pages_desktop_specific/my_stack_view/exit_to_my_stack_button.dart'; import 'package:stackwallet/pages_desktop_specific/my_stack_view/exit_to_my_stack_button.dart';
import 'package:stackwallet/providers/global/prefs_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/default_eth_tokens.dart'; import 'package:stackwallet/utilities/default_eth_tokens.dart';
@ -124,6 +124,10 @@ class _AddWalletViewState extends ConsumerState<AddWalletView> {
tokenEntities.addAll(contracts.map((e) => EthTokenEntity(e))); tokenEntities.addAll(contracts.map((e) => EthTokenEntity(e)));
WidgetsBinding.instance.addPostFrameCallback((_) {
ref.refresh(addWalletSelectedEntityStateProvider);
});
super.initState(); super.initState();
} }

View file

@ -5,7 +5,11 @@ import 'package:stackwallet/models/add_wallet_list_entity/sub_classes/coin_entit
import 'package:stackwallet/models/add_wallet_list_entity/sub_classes/eth_token_entity.dart'; import 'package:stackwallet/models/add_wallet_list_entity/sub_classes/eth_token_entity.dart';
import 'package:stackwallet/pages/add_wallet_views/create_or_restore_wallet_view/create_or_restore_wallet_view.dart'; import 'package:stackwallet/pages/add_wallet_views/create_or_restore_wallet_view/create_or_restore_wallet_view.dart';
import 'package:stackwallet/pages/add_wallet_views/verify_recovery_phrase_view/verify_recovery_phrase_view.dart'; import 'package:stackwallet/pages/add_wallet_views/verify_recovery_phrase_view/verify_recovery_phrase_view.dart';
import 'package:stackwallet/pages/home_view/home_view.dart';
import 'package:stackwallet/providers/global/wallets_provider.dart';
import 'package:stackwallet/providers/global/wallets_service_provider.dart'; import 'package:stackwallet/providers/global/wallets_service_provider.dart';
import 'package:stackwallet/services/coins/ethereum/ethereum_wallet.dart';
import 'package:stackwallet/services/wallets_service.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';
import 'package:stackwallet/utilities/util.dart'; import 'package:stackwallet/utilities/util.dart';
@ -17,6 +21,9 @@ import 'package:stackwallet/widgets/rounded_container.dart';
import 'package:stackwallet/widgets/rounded_white_container.dart'; import 'package:stackwallet/widgets/rounded_white_container.dart';
import 'package:stackwallet/widgets/wallet_info_row/wallet_info_row.dart'; import 'package:stackwallet/widgets/wallet_info_row/wallet_info_row.dart';
final newEthWalletTriggerTempUntilHiveCompletelyDeleted =
StateProvider((ref) => false);
class SelectWalletForTokenView extends ConsumerStatefulWidget { class SelectWalletForTokenView extends ConsumerStatefulWidget {
const SelectWalletForTokenView({ const SelectWalletForTokenView({
Key? key, Key? key,
@ -40,7 +47,16 @@ class _SelectWalletForTokenViewState
String? _selectedWalletId; String? _selectedWalletId;
void _onContinue() { void _onContinue() {
// final wallet = ref
.read(walletsChangeNotifierProvider)
.getManager(_selectedWalletId!)
.wallet as EthereumWallet;
final tokenSet = wallet.getWalletTokenContractAddresses().toSet();
tokenSet.add(widget.entity.token.address);
wallet.updateWalletTokenContractAddresses(tokenSet.toList());
Navigator.of(context).pushNamed(HomeView.routeName);
} }
void _onAddNewEthWallet() { void _onAddNewEthWallet() {
@ -51,12 +67,13 @@ class _SelectWalletForTokenViewState
); );
} }
@override late int _cachedWalletCount;
void initState() {
final walletsData = void _updateWalletsList(Map<String, WalletInfo> walletsData) {
ref.read(walletsServiceChangeNotifierProvider).fetchWalletsData(); _cachedWalletCount = walletsData.length;
walletsData.removeWhere((key, value) => value.coin != widget.entity.coin); walletsData.removeWhere((key, value) => value.coin != widget.entity.coin);
ethWalletIds = []; ethWalletIds.clear();
// TODO: proper wallet data class instead of this Hive silliness // TODO: proper wallet data class instead of this Hive silliness
for (final walletId in walletsData.values.map((e) => e.walletId).toList()) { for (final walletId in walletsData.values.map((e) => e.walletId).toList()) {
@ -69,12 +86,29 @@ class _SelectWalletForTokenViewState
ethWalletIds.add(walletId); ethWalletIds.add(walletId);
} }
} }
}
@override
void initState() {
ethWalletIds = [];
final walletsData =
ref.read(walletsServiceChangeNotifierProvider).fetchWalletsData();
_updateWalletsList(walletsData);
super.initState(); super.initState();
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
// dumb hack
ref.watch(newEthWalletTriggerTempUntilHiveCompletelyDeleted);
final walletsData =
ref.read(walletsServiceChangeNotifierProvider).fetchWalletsData();
if (walletsData.length != _cachedWalletCount) {
_updateWalletsList(walletsData);
}
return WillPopScope( return WillPopScope(
onWillPop: () async { onWillPop: () async {
ref.read(createSpecialEthWalletRoutingFlag.notifier).state = false; ref.read(createSpecialEthWalletRoutingFlag.notifier).state = false;

View file

@ -102,6 +102,12 @@ class _VerifyRecoveryPhraseViewState
ref.read(createSpecialEthWalletRoutingFlag); ref.read(createSpecialEthWalletRoutingFlag);
if (isCreateSpecialEthWallet) { if (isCreateSpecialEthWallet) {
ref.read(createSpecialEthWalletRoutingFlag.notifier).state = false; ref.read(createSpecialEthWalletRoutingFlag.notifier).state = false;
ref
.read(newEthWalletTriggerTempUntilHiveCompletelyDeleted.state)
.state =
!ref
.read(newEthWalletTriggerTempUntilHiveCompletelyDeleted.state)
.state;
} }
if (mounted) { if (mounted) {