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
9 changes: 2 additions & 7 deletions lib/app_config/app_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ const List<String> excludedAssetList = [
'FENIX',
'AWR',
'BOT',
// Pirate activation params are not yet implemented, so we need to
// exclude it from the list of coins for now.
'ARRR',
'ZOMBIE',
'SMTF-v2',
Expand Down Expand Up @@ -128,13 +130,6 @@ List<String> get enabledByDefaultCoins => [
'FTM',
if (kDebugMode) 'DOC',
if (kDebugMode) 'MARTY',

// NFT v2 methods require the new NFT coins to be enabled by default.
'NFT_ETH',
'NFT_AVAX',
'NFT_BNB',
'NFT_FTM',
'NFT_MATIC',
];

List<String> get enabledByDefaultTrezorCoins => [
Expand Down
7 changes: 7 additions & 0 deletions lib/bloc/bridge_form/bridge_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:komodo_defi_sdk/komodo_defi_sdk.dart';
import 'package:komodo_defi_types/komodo_defi_types.dart';
import 'package:rational/rational.dart';
import 'package:web_dex/app_config/app_config.dart';
import 'package:web_dex/bloc/bridge_form/bridge_event.dart';
import 'package:web_dex/bloc/bridge_form/bridge_repository.dart';
import 'package:web_dex/bloc/bridge_form/bridge_state.dart';
Expand Down Expand Up @@ -257,6 +258,12 @@ class BridgeBloc extends Bloc<BridgeEvent, BridgeState> {
number: 1,
));


/// Unsupported coins like ARRR cause downstream errors, so we need to
/// remove them from the list here
bestOrders.result
?.removeWhere((coinId, _) => excludedAssetList.contains(coinId));

Comment on lines +261 to +266
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Critical bugfix: Filter out unsupported coins to prevent crashes.

This change prevents downstream errors by filtering out coins like 'ARRR' that lack proper activation parameters, addressing the crash mentioned in the PR title.

The implementation correctly uses removeWhere to filter out all coins listed in the excludedAssetList before updating the state with the best orders.

emit(state.copyWith(
bestOrders: () => bestOrders,
));
Expand Down
18 changes: 10 additions & 8 deletions lib/bloc/coins_manager/coins_manager_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'dart:async';
import 'package:equatable/equatable.dart';
import 'package:flutter_bloc/flutter_bloc.dart' show Bloc, Emitter;
import 'package:komodo_defi_sdk/komodo_defi_sdk.dart';
import 'package:web_dex/app_config/app_config.dart';
import 'package:web_dex/bloc/coins_bloc/coins_repo.dart';
import 'package:web_dex/model/coin.dart';
import 'package:web_dex/model/coin_type.dart';
Expand Down Expand Up @@ -35,18 +36,18 @@ class CoinsManagerBloc extends Bloc<CoinsManagerEvent, CoinsManagerState> {
final KomodoDefiSdk _sdk;

List<Coin> mergeCoinLists(List<Coin> originalList, List<Coin> newList) {
Map<String, Coin> coinMap = {};
final Map<String, Coin> coinMap = {};

for (Coin coin in originalList) {
for (final Coin coin in originalList) {
coinMap[coin.abbr] = coin;
}

for (Coin coin in newList) {
for (final Coin coin in newList) {
coinMap[coin.abbr] = coin;
}

final list = coinMap.values.toList();
list.sort((a, b) => a.abbr.compareTo(b.abbr));
final list = coinMap.values.toList()
..sort((a, b) => a.abbr.compareTo(b.abbr));

return list;
}
Expand Down Expand Up @@ -213,9 +214,9 @@ Future<List<Coin>> _getOriginalCoinList(

switch (action) {
case CoinsManagerAction.add:
return await _getDeactivatedCoins(coinsRepo, sdk, walletType);
return _getDeactivatedCoins(coinsRepo, sdk, walletType);
case CoinsManagerAction.remove:
return await coinsRepo.getWalletCoins();
return coinsRepo.getWalletCoins();
case CoinsManagerAction.none:
return [];
}
Expand All @@ -228,7 +229,8 @@ Future<List<Coin>> _getDeactivatedCoins(
) async {
final Iterable<String> enabledCoins = await sdk.assets.getEnabledCoins();
final Map<String, Coin> disabledCoins = coinsRepo.getKnownCoinsMap()
..removeWhere((key, coin) => enabledCoins.contains(key));
..removeWhere((coinId, coin) => enabledCoins.contains(coinId))
..removeWhere((coinId, coin) => excludedAssetList.contains(coinId));

switch (walletType) {
case WalletType.iguana:
Expand Down
3 changes: 3 additions & 0 deletions lib/bloc/fiat/fiat_onramp_form/fiat_form_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:formz/formz.dart';
import 'package:komodo_defi_sdk/komodo_defi_sdk.dart';
import 'package:komodo_defi_types/komodo_defi_types.dart';
import 'package:logging/logging.dart';
import 'package:web_dex/app_config/app_config.dart';
import 'package:web_dex/bloc/coins_bloc/asset_coin_extension.dart';
import 'package:web_dex/bloc/fiat/base_fiat_provider.dart';
import 'package:web_dex/bloc/fiat/fiat_order_status.dart';
Expand Down Expand Up @@ -319,6 +320,8 @@ class FiatFormBloc extends Bloc<FiatFormEvent, FiatFormState> {
try {
final fiatList = await _fiatRepository.getFiatList();
final coinList = await _fiatRepository.getCoinList();
coinList
.removeWhere((coin) => excludedAssetList.contains(coin.getAbbr()));
emit(state.copyWith(fiatList: fiatList, coinList: coinList));
} catch (e, s) {
_log.shout('Error loading currency list', e, s);
Expand Down
5 changes: 5 additions & 0 deletions lib/bloc/taker_form/taker_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,11 @@ class TakerBloc extends Bloc<TakerEvent, TakerState> {
),
);

/// Unsupported coins like ARRR cause downstream errors, so we need to
/// remove them from the list here
bestOrders.result
?.removeWhere((coinId, _) => excludedAssetList.contains(coinId));

Comment on lines +296 to +300
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Critical bugfix: Filter out unsupported coins to prevent crashes.

This change applies the same fix as in BridgeBloc to filter out unsupported coins from the best orders list, ensuring consistency between the two implementations and preventing crashes during coin selection.

The implementation correctly uses removeWhere to filter out all coins listed in the excludedAssetList before updating the state with the best orders.

emit(state.copyWith(bestOrders: () => bestOrders));

final buyCoin = event.autoSelectOrderAbbr;
Expand Down
4 changes: 2 additions & 2 deletions lib/blocs/wallets_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class WalletsRepository {
}

Future<List<Wallet>> _getLegacyWallets() async {
var newVariable =
final newVariable =
await _legacyWalletStorage.read(allWalletsStorageKey) as List?;
final List<Map<String, dynamic>> json =
newVariable?.cast<Map<String, dynamic>>() ?? <Map<String, dynamic>>[];
Expand Down Expand Up @@ -115,7 +115,7 @@ class WalletsRepository {
type: LoadFileType.text,
);
} catch (e) {
throw Exception('Failed to download encrypted wallet: ${e.toString()}');
throw Exception('Failed to download encrypted wallet: $e');
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ import 'package:web_dex/views/dex/simple/form/tables/coins_table/coins_table_ite

class GroupedListView<T> extends StatelessWidget {
const GroupedListView({
super.key,
required this.items,
required this.onSelect,
required this.maxHeight,
super.key,
});

final List<T> items;
final Function(T) onSelect;
final void Function(T) onSelect;
final double maxHeight;

@override
Expand All @@ -35,7 +35,7 @@ class GroupedListView<T> extends StatelessWidget {
.isNotEmpty;
final rightPadding = areGroupedItemsPresent
? const EdgeInsets.only(right: 52)
: const EdgeInsets.all(0);
: EdgeInsets.zero;

return Flexible(
child: ConstrainedBox(
Expand Down Expand Up @@ -83,8 +83,8 @@ class GroupedListView<T> extends StatelessWidget {
Widget buildItem(
BuildContext context,
T item,
dynamic onSelect, {
EdgeInsets padding = const EdgeInsets.all(0),
void Function(T) onSelect, {
EdgeInsets padding = EdgeInsets.zero,
}) {
return Padding(
padding: padding,
Expand All @@ -106,7 +106,7 @@ class GroupedListView<T> extends StatelessWidget {
}

Map<String, List<T>> _groupList(BuildContext context, List<T> list) {
Map<String, List<T>> grouped = {};
final Map<String, List<T>> grouped = {};
for (final item in list) {
final coin = getCoin(context, item);
grouped.putIfAbsent(coin.name, () => []).add(item);
Expand Down
Loading