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
5 changes: 4 additions & 1 deletion lib/bloc/dex_tab_bar/dex_tab_bar_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:komodo_defi_types/komodo_defi_types.dart';
import 'package:web_dex/bloc/market_maker_bot/market_maker_order_list/market_maker_bot_order_list_repository.dart';
import 'package:web_dex/bloc/market_maker_bot/market_maker_order_list/trade_pair.dart';
import 'package:web_dex/blocs/trading_entities_bloc.dart';
import 'package:web_dex/model/dex_list_type.dart';
import 'package:web_dex/model/my_orders/my_order.dart';
import 'package:web_dex/model/swap.dart';
import 'package:web_dex/model/trading_entities_filter.dart';
Expand Down Expand Up @@ -91,7 +92,9 @@ class DexTabBarBloc extends Bloc<DexTabBarEvent, DexTabBarState> {
}

FutureOr<void> _onTabChanged(TabChanged event, Emitter<DexTabBarState> emit) {
emit(state.copyWith(tabIndex: event.tabIndex));
// Validate tabIndex to prevent out-of-bounds access
final validatedIndex = event.tabIndex.clamp(0, DexListType.values.length - 1);
emit(state.copyWith(tabIndex: validatedIndex));
}

void _onFilterChanged(FilterChanged event, Emitter<DexTabBarState> emit) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ class _TrezorHiddenWalletState extends State<_TrezorHiddenWallet> {
super.initState();
}

@override
void dispose() {
_passphraseController.dispose();
_passphraseFieldFocusNode.dispose();
super.dispose();
}

@override
Widget build(BuildContext context) {
return Column(
Expand Down
23 changes: 17 additions & 6 deletions lib/views/dex/dex_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,19 @@ class _DexPageState extends State<DexPage> {
],
child: BlocBuilder<DexTabBarBloc, DexTabBarState>(
builder: (context, state) {
final tab = DexListType.values[state.tabIndex];
final kind = tab == DexListType.orders
? TradingEntityKind.order
: TradingEntityKind.swap;
// Defensive bounds check for tabIndex
final bool inRange =
state.tabIndex >= 0 && state.tabIndex < DexListType.values.length;
final tab = inRange
? DexListType.values[state.tabIndex]
: DexListType.swap;
// Explicit mapping: only orders tab shows order entities, all others show swaps
final kind = switch (tab) {
DexListType.orders => TradingEntityKind.order,
DexListType.swap => TradingEntityKind.swap,
DexListType.inProgress => TradingEntityKind.swap,
DexListType.history => TradingEntityKind.swap,
};
return isTradingDetails
? TradingDetails(uuid: routingState.dexState.uuid, kind: kind)
: _DexContent();
Expand Down Expand Up @@ -116,7 +125,9 @@ class _DexContentState extends State<_DexContent> {
child: shouldShowTabContent(state.tabIndex)
? DexListWrapper(
key: Key('dex-list-wrapper-${state.tabIndex}'),
DexListType.values[state.tabIndex],
state.tabIndex >= 0 && state.tabIndex < DexListType.values.length
? DexListType.values[state.tabIndex]
: DexListType.swap,
)
: const SizedBox.shrink(),
),
Expand All @@ -138,6 +149,6 @@ class _DexContentState extends State<_DexContent> {
}

bool shouldShowTabContent(int tabIndex) {
return DexListType.values.length > tabIndex;
return tabIndex >= 0 && tabIndex < DexListType.values.length;
}
}
4 changes: 2 additions & 2 deletions lib/views/dex/entity_details/trading_details.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class TradingDetails extends StatefulWidget {
const TradingDetails({super.key, required this.uuid, this.kind = TradingEntityKind.swap});

final String uuid;
final TradingEntityKind? kind;
final TradingEntityKind kind;

@override
State<TradingDetails> createState() => _TradingDetailsState();
Expand Down Expand Up @@ -116,7 +116,7 @@ class _TradingDetailsState extends State<TradingDetails> {
} catch (e, s) {
log(
e.toString(),
path: 'trading_details =>_updateStatus ${widget.kind ?? TradingEntityKind.swap} error | uuid=${widget.uuid}',
path: 'trading_details =>_updateStatus ${widget.kind} error | uuid=${widget.uuid}',
trace: s,
isError: true,
);
Expand Down
17 changes: 13 additions & 4 deletions lib/views/market_maker_bot/market_maker_bot_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,19 @@ class _MarketMakerBotPageState extends State<MarketMakerBotPage> {
},
child: BlocBuilder<DexTabBarBloc, DexTabBarState>(
builder: (context, state) {
final tab = DexListType.values[state.tabIndex];
final kind = tab == DexListType.orders
? TradingEntityKind.order
: TradingEntityKind.swap;
// Defensive bounds check for tabIndex
final bool inRange =
state.tabIndex >= 0 && state.tabIndex < DexListType.values.length;
final tab = inRange
? DexListType.values[state.tabIndex]
: DexListType.swap;
// Explicit mapping: only orders tab shows order entities, all others show swaps
final kind = switch (tab) {
DexListType.orders => TradingEntityKind.order,
DexListType.swap => TradingEntityKind.swap,
DexListType.inProgress => TradingEntityKind.swap,
DexListType.history => TradingEntityKind.swap,
};
return isTradingDetails
? TradingDetails(uuid: routingState.marketMakerState.uuid, kind: kind)
: MarketMakerBotView();
Expand Down
Loading