Skip to content
This repository has been archived by the owner on Sep 17, 2024. It is now read-only.

Commit

Permalink
fix: other chains dapps & instant loading
Browse files Browse the repository at this point in the history
  • Loading branch information
reasje committed May 23, 2024
1 parent 0b4e9d9 commit 0655f6e
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 14 deletions.
9 changes: 7 additions & 2 deletions lib/features/dapps/domain/dapp_store_use_case.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,17 @@ class DappStoreUseCase extends ReactiveUseCase {

late final ValueStream<List<Dapp>> dapps = reactive([]);

loadLocalDApps() async {
Future<void> loadDapps() async {
loadLocalDApps();
await loadRemoteDApps();
}

Future<void> loadLocalDApps() async {
final result = await _repository.dappStoreRepository.getAllDappsFromLocal();
update(dapps, result);
}

Future<void> getAllDapps() async {
Future<void> loadRemoteDApps() async {
final result = await _repository.dappStoreRepository.getAllDapps();

update(dapps, result);
Expand Down
3 changes: 0 additions & 3 deletions lib/features/dapps/helpers/reorder_helper.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import 'dart:async';

import 'package:datadashwallet/features/dapps/presentation/responsive_layout/dapp_utils.dart';
import 'package:flutter/material.dart';
import 'package:mxc_logic/mxc_logic.dart';

import '../domain/domain.dart';
Expand Down
8 changes: 4 additions & 4 deletions lib/features/dapps/presentation/dapps_page.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'package:datadashwallet/common/common.dart';
import 'package:datadashwallet/core/core.dart';
import 'package:datadashwallet/features/common/common.dart';
import 'package:datadashwallet/features/dapps/dapps.dart';
import 'package:datadashwallet/features/settings/settings.dart';
import 'package:datadashwallet/features/wallet/wallet.dart';
import 'package:flutter/material.dart';
Expand Down Expand Up @@ -29,7 +28,8 @@ class DAppsPage extends HookConsumerWidget {
return MxcPage(
layout: LayoutType.column,
useContentPadding: false,
childrenPadding: const EdgeInsets.symmetric(horizontal: 12, vertical: 16),
childrenPadding: const EdgeInsets.symmetric(
horizontal: Sizes.spaceSmall, vertical: Sizes.spaceNormal),
backgroundColor: ColorsTheme.of(context).screenBackground,
presenter: ref.watch(presenter),
appBar: Column(
Expand All @@ -44,7 +44,7 @@ class DAppsPage extends HookConsumerWidget {
leading: IconButton(
key: const ValueKey('settingsButton'),
icon: const Icon(MxcIcons.settings),
iconSize: 32,
iconSize: Sizes.space2XLarge,
onPressed: () {
Navigator.of(context).push(
route(
Expand All @@ -57,7 +57,7 @@ class DAppsPage extends HookConsumerWidget {
action: IconButton(
key: const ValueKey('walletButton'),
icon: const Icon(MxcIcons.wallet),
iconSize: 32,
iconSize: Sizes.space2XLarge,
onPressed: () => Navigator.of(context).replaceAll(
route(const WalletPage()),
),
Expand Down
7 changes: 5 additions & 2 deletions lib/features/dapps/presentation/dapps_presenter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ class DAppsPagePresenter extends CompletePresenter<DAppsState> {
listen(_chainConfigurationUseCase.selectedNetwork, (value) {
if (value != null) {
if (state.network != null && state.network!.chainId != value.chainId) {
DappUtils.loadingOnce = true;
notify(() => state.loading = true);
reorderHelper.resetDappsMerge();
}
notify(() => state.network = value);
Expand Down Expand Up @@ -157,7 +159,7 @@ class DAppsPagePresenter extends CompletePresenter<DAppsState> {

void initializeDapps() async {
try {
await _dappStoreUseCase.getAllDapps();
await _dappStoreUseCase.loadDapps();
} catch (e, s) {
addError(e, s);
}
Expand All @@ -171,7 +173,8 @@ class DAppsPagePresenter extends CompletePresenter<DAppsState> {

void addBookmark() async => bookmarksHelper.addBookmark();

void updateBookmarkFavIcon(Bookmark item) async => bookmarksHelper.updateBookmarkFavIcon(item);
void updateBookmarkFavIcon(Bookmark item) async =>
bookmarksHelper.updateBookmarkFavIcon(item);

void onPageChage(int index) => notify(() => state.pageIndex = index);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ class DappUtils {
if (e is Bookmark) {
return true;
} else {
return (e.store!.chainid == chainId) &&
return (!MXCChains.isMXCChains(chainId)
? MXCChains.isMXCMainnet(e.store!.chainid!)
: e.store!.chainid == chainId) &&
isSupported(e.app!.supportedPlatforms!);
}
}).toList();
Expand All @@ -44,8 +46,8 @@ class DappUtils {

// Sort the DApps list based on the order specified in dappsOrder
dapps.sort((a, b) {
final aUrl = a is Bookmark ? a.url : a.app!.url!;
final bUrl = b is Bookmark ? b.url : b.app!.url!;
final aUrl = a is Bookmark ? a.url : a.app!.url!;
final bUrl = b is Bookmark ? b.url : b.app!.url!;
int indexA = urlIndices[aUrl] ?? dapps.length;
int indexB = urlIndices[bUrl] ?? dapps.length;
return dappsOrder.indexOf(aUrl) - dappsOrder.indexOf(bUrl);
Expand Down

0 comments on commit 0655f6e

Please sign in to comment.