Skip to content

Commit

Permalink
fix(router): frozen layout on navigation and resize (#2521)
Browse files Browse the repository at this point in the history
* chore(deps): bump SDK version hash

* fix(router): use ValueKey for MainLayout

fixes non-responsive UI due to immutable MainLayout ignoring routing and layout size changes

* fix(price-charts): filter out CEX coins not in known assets list

the use of `.single` in `getSdkAsset` would result in exceptions for coins that were not in the known assets list

* chore(deps): bump SDK version hash

* refactor: remove isMobile from ValueKey and update filter comment

* fix(charts): Allow edge-case for multiple assets for a given ticker.

Although unlikely anytime soon, if the coins repo has a change pushed to it where this assumption no longer holds true, then we want to error out because there are many instances where we've assumed a given ticker will have exactly 1 or 0 coins/assets, which may wreak havoc if it's not treated as a breaking change.

---------

Co-authored-by: Charl (Nitride) <[email protected]>
  • Loading branch information
takenagain and CharlVS authored Feb 7, 2025
1 parent 73ac363 commit 869c8fa
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 15 deletions.
6 changes: 4 additions & 2 deletions lib/bloc/app_bloc_root.dart
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,10 @@ class AppBlocRoot extends StatelessWidget {
)..add(CoinsStarted()),
),
BlocProvider<PriceChartBloc>(
create: (context) => PriceChartBloc(binanceRepository)
..add(
create: (context) => PriceChartBloc(
binanceRepository,
komodoDefiSdk,
)..add(
const PriceChartStarted(
symbols: ['KMD'],
period: Duration(days: 30),
Expand Down
10 changes: 9 additions & 1 deletion lib/bloc/cex_market_data/price_chart/price_chart_bloc.dart
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:komodo_cex_market_data/komodo_cex_market_data.dart';
import 'package:komodo_defi_sdk/komodo_defi_sdk.dart';
import 'package:web_dex/shared/utils/utils.dart';

import 'models/price_chart_data.dart';
import 'price_chart_event.dart';
import 'price_chart_state.dart';

class PriceChartBloc extends Bloc<PriceChartEvent, PriceChartState> {
PriceChartBloc(this.cexPriceRepository) : super(const PriceChartState()) {
PriceChartBloc(this.cexPriceRepository, this.sdk)
: super(const PriceChartState()) {
on<PriceChartStarted>(_onStarted);
on<PriceChartPeriodChanged>(_onIntervalChanged);
on<PriceChartCoinsSelected>(_onSymbolChanged);
}

final BinanceRepository cexPriceRepository;
final KomodoDefiSdk sdk;
final KomodoPriceRepository _komodoPriceRepository = KomodoPriceRepository(
cexPriceProvider: KomodoPriceProvider(),
);
Expand All @@ -30,6 +33,11 @@ class PriceChartBloc extends Bloc<PriceChartEvent, PriceChartState> {
if (state.availableCoins.isEmpty) {
final coins = (await cexPriceRepository.getCoinList())
.where((coin) => coin.currencies.contains('USDT'))
// `cexPriceRepository.getCoinList()` returns coins from a CEX
// (e.g. Binance), some of which are not in our known/available
// assets/coins list. This filter ensures that we only attempt to
// fetch and display data for supported coins
.where((coin) => sdk.assets.assetsFromTicker(coin.id).length >= 1)
.map((coin) async {
double? dayChangePercent = coinPrices[coin.symbol]?.change24h;

Expand Down
4 changes: 3 additions & 1 deletion lib/router/navigators/app_router_delegate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ class AppRouterDelegate extends RouterDelegate<AppRoutePath>
materialPageContext = context;
return GestureDetector(
onTap: () => runDropdownDismiss(context),
child: const MainLayout(),
child: MainLayout(
key: ValueKey('${routingState.selectedMenu}'),
),
);
},
),
Expand Down
6 changes: 3 additions & 3 deletions packages/komodo_ui_kit/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ packages:
description:
path: "packages/komodo_defi_rpc_methods"
ref: dev
resolved-ref: "9c75bb7b2d3a556cec4119ad29fdb7fa93fe599e"
resolved-ref: afcdfd97b909b6f7cbd9f04c25f57a11031bcaf6
url: "https://github.com/KomodoPlatform/komodo-defi-sdk-flutter.git"
source: git
version: "0.2.0+0"
Expand All @@ -104,7 +104,7 @@ packages:
description:
path: "packages/komodo_defi_types"
ref: dev
resolved-ref: "9c75bb7b2d3a556cec4119ad29fdb7fa93fe599e"
resolved-ref: afcdfd97b909b6f7cbd9f04c25f57a11031bcaf6
url: "https://github.com/KomodoPlatform/komodo-defi-sdk-flutter.git"
source: git
version: "0.2.0+0"
Expand All @@ -113,7 +113,7 @@ packages:
description:
path: "packages/komodo_ui"
ref: dev
resolved-ref: "9c75bb7b2d3a556cec4119ad29fdb7fa93fe599e"
resolved-ref: afcdfd97b909b6f7cbd9f04c25f57a11031bcaf6
url: "https://github.com/KomodoPlatform/komodo-defi-sdk-flutter.git"
source: git
version: "0.2.0+0"
Expand Down
16 changes: 8 additions & 8 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ packages:
description:
path: "packages/komodo_coins"
ref: dev
resolved-ref: "9c75bb7b2d3a556cec4119ad29fdb7fa93fe599e"
resolved-ref: afcdfd97b909b6f7cbd9f04c25f57a11031bcaf6
url: "https://github.com/KomodoPlatform/komodo-defi-sdk-flutter.git"
source: git
version: "0.2.0+0"
Expand All @@ -675,7 +675,7 @@ packages:
description:
path: "packages/komodo_defi_framework"
ref: dev
resolved-ref: "9c75bb7b2d3a556cec4119ad29fdb7fa93fe599e"
resolved-ref: afcdfd97b909b6f7cbd9f04c25f57a11031bcaf6
url: "https://github.com/KomodoPlatform/komodo-defi-sdk-flutter.git"
source: git
version: "0.2.0"
Expand All @@ -684,7 +684,7 @@ packages:
description:
path: "packages/komodo_defi_local_auth"
ref: dev
resolved-ref: "9c75bb7b2d3a556cec4119ad29fdb7fa93fe599e"
resolved-ref: afcdfd97b909b6f7cbd9f04c25f57a11031bcaf6
url: "https://github.com/KomodoPlatform/komodo-defi-sdk-flutter.git"
source: git
version: "0.2.0+0"
Expand All @@ -693,7 +693,7 @@ packages:
description:
path: "packages/komodo_defi_rpc_methods"
ref: dev
resolved-ref: "9c75bb7b2d3a556cec4119ad29fdb7fa93fe599e"
resolved-ref: afcdfd97b909b6f7cbd9f04c25f57a11031bcaf6
url: "https://github.com/KomodoPlatform/komodo-defi-sdk-flutter.git"
source: git
version: "0.2.0+0"
Expand All @@ -702,7 +702,7 @@ packages:
description:
path: "packages/komodo_defi_sdk"
ref: dev
resolved-ref: "9c75bb7b2d3a556cec4119ad29fdb7fa93fe599e"
resolved-ref: afcdfd97b909b6f7cbd9f04c25f57a11031bcaf6
url: "https://github.com/KomodoPlatform/komodo-defi-sdk-flutter.git"
source: git
version: "0.2.0+0"
Expand All @@ -711,7 +711,7 @@ packages:
description:
path: "packages/komodo_defi_types"
ref: dev
resolved-ref: "9c75bb7b2d3a556cec4119ad29fdb7fa93fe599e"
resolved-ref: afcdfd97b909b6f7cbd9f04c25f57a11031bcaf6
url: "https://github.com/KomodoPlatform/komodo-defi-sdk-flutter.git"
source: git
version: "0.2.0+0"
Expand All @@ -727,7 +727,7 @@ packages:
description:
path: "packages/komodo_ui"
ref: dev
resolved-ref: "9c75bb7b2d3a556cec4119ad29fdb7fa93fe599e"
resolved-ref: afcdfd97b909b6f7cbd9f04c25f57a11031bcaf6
url: "https://github.com/KomodoPlatform/komodo-defi-sdk-flutter.git"
source: git
version: "0.2.0+0"
Expand All @@ -743,7 +743,7 @@ packages:
description:
path: "packages/komodo_wallet_build_transformer"
ref: dev
resolved-ref: "9c75bb7b2d3a556cec4119ad29fdb7fa93fe599e"
resolved-ref: afcdfd97b909b6f7cbd9f04c25f57a11031bcaf6
url: "https://github.com/KomodoPlatform/komodo-defi-sdk-flutter.git"
source: git
version: "0.2.0+0"
Expand Down

0 comments on commit 869c8fa

Please sign in to comment.