Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@ class CoinDetailsPage extends HookConsumerWidget {
Widget build(BuildContext context, WidgetRef ref) {
final walletView = ref.watch(currentWalletViewDataProvider).requireValue;
final coinsGroup = walletView.coinGroups.firstWhere((e) => e.symbolGroup == symbolGroup);
final networkSelectorData = ref.watch(
networkSelectorNotifierProvider(symbolGroup: symbolGroup),
);
final networkSelectorData = ref
.watch(
networkSelectorNotifierProvider(symbolGroup: symbolGroup),
)
.valueOrNull;
final history = ref
.watch(
coinTransactionHistoryNotifierProvider(symbolGroup: symbolGroup),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class Balance extends ConsumerWidget {
.read(
networkSelectorNotifierProvider(symbolGroup: coinsGroup.symbolGroup),
)
.valueOrNull
?.selected
.mapOrNull(network: (network) => network.network);
final wallet = ref
Expand All @@ -84,6 +85,7 @@ class Balance extends ConsumerWidget {
.read(
networkSelectorNotifierProvider(symbolGroup: coinsGroup.symbolGroup),
)
.valueOrNull
?.selected
.mapOrNull(network: (n) => n.network);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class CoinBalanceNotifier extends _$CoinBalanceNotifier {
CoinBalanceState build({required String symbolGroup}) {
final currentNetwork = ref.watch(
networkSelectorNotifierProvider(symbolGroup: symbolGroup).select(
(state) => state?.selected.whenOrNull(network: (network) => network),
(asyncState) => asyncState.valueOrNull?.selected.whenOrNull(network: (network) => network),
),
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class CoinTransactionHistoryNotifier extends _$CoinTransactionHistoryNotifier {

_network = ref.watch(
networkSelectorNotifierProvider(symbolGroup: symbolGroup).select(
(state) => state?.selected.whenOrNull(network: (network) => network),
(asyncState) => asyncState.valueOrNull?.selected.whenOrNull(network: (network) => network),
),
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ part 'network_selector_notifier.r.g.dart';
@riverpod
class NetworkSelectorNotifier extends _$NetworkSelectorNotifier {
@override
NetworkSelectorData? build({required String symbolGroup}) {
Future<NetworkSelectorData?> build({required String symbolGroup}) async {
final networksValue = ref
.watch(
syncedCoinsBySymbolGroupProvider(symbolGroup),
Expand All @@ -25,20 +25,32 @@ class NetworkSelectorNotifier extends _$NetworkSelectorNotifier {
...wrappedNetworks,
];

// Get previous selection from state (safe with valueOrNull in async providers)
final previousState = state.valueOrNull;
final previousSelection = previousState?.selected;

// Preserve previous selection if it's still valid, otherwise use first item
final selectedItem = previousSelection != null && items.contains(previousSelection)
? previousSelection
: items.first;

return NetworkSelectorData(
items: items,
selected: items.first,
selected: selectedItem,
);
}

set selected(SelectedNetworkItem item) {
final currentState = state.valueOrNull;
if (currentState == null) return;

final canUpdate = item.map(
network: (item) => state?.items.contains(item) ?? false,
network: (item) => currentState.items.contains(item),
all: (_) => true,
);

if (canUpdate) {
state = state!.copyWith(selected: item);
state = AsyncData(currentState.copyWith(selected: item));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class SelectedCryptoWalletNotifier extends _$SelectedCryptoWalletNotifier {
SelectedCryptoWalletData build({required String symbolGroup}) {
final network = ref.watch(
networkSelectorNotifierProvider(symbolGroup: symbolGroup).select(
(state) => state?.selected.whenOrNull(network: (network) => network),
(asyncState) => asyncState.valueOrNull?.selected.whenOrNull(network: (network) => network),
),
);

Expand Down