From 3b4b0d65ebe24d7a1c83fcaa7fa1b7a4e908c96a Mon Sep 17 00:00:00 2001 From: reasje Date: Wed, 10 Apr 2024 17:12:28 +0330 Subject: [PATCH 01/11] fix: Permissions check for dapps only android --- .../dapps/presentation/dapps_presenter.dart | 79 ++++++++++--------- .../responsive_layout/dapp_card_layout.dart | 8 +- pubspec.lock | 4 +- 3 files changed, 48 insertions(+), 43 deletions(-) diff --git a/lib/features/dapps/presentation/dapps_presenter.dart b/lib/features/dapps/presentation/dapps_presenter.dart index 2f0a8797..9e791662 100644 --- a/lib/features/dapps/presentation/dapps_presenter.dart +++ b/lib/features/dapps/presentation/dapps_presenter.dart @@ -1,3 +1,5 @@ +import 'dart:io'; + import 'package:datadashwallet/common/utils/utils.dart'; import 'package:datadashwallet/core/core.dart'; import 'package:datadashwallet/features/dapps/dapps.dart'; @@ -146,32 +148,35 @@ class DAppsPagePresenter extends CompletePresenter { _gesturesInstructionUseCase.setEducated(true); } - // Future requestPermissions(Dapp dapp) async { - // final permissions = dapp.app!.permissions!.toMap(); - // final keys = permissions.keys.toList(); - // final values = permissions.values.toList(); - // List needPermissions = []; - - // for (int i = 0; i < permissions.length; i++) { - // final key = keys[i]; - // final value = values[i]; - - // if (value == 'required') { - // final permission = PermissionUtils.permissions[key]; - // if (permission != null) { - // needPermissions.add(permission); - // } - // } - // } - - // if (keys.contains('location')) { - // await checkLocationService(); - // } - // if (needPermissions.isNotEmpty) { - // await needPermissions.request(); - // await PermissionUtils.permissionsStatus(); - // } - // } + Future requestPermissions(Dapp dapp) async { + // Permission request will be only on Android + if (Platform.isAndroid) { + final permissions = dapp.app!.permissions!.toMap(); + final keys = permissions.keys.toList(); + final values = permissions.values.toList(); + List needPermissions = []; + + for (int i = 0; i < permissions.length; i++) { + final key = keys[i]; + final value = values[i]; + + if (value == 'required') { + final permission = PermissionUtils.permissions[key]; + if (permission != null) { + needPermissions.add(permission); + } + } + } + + if (keys.contains('location')) { + await checkLocationService(); + } + if (needPermissions.isNotEmpty) { + await needPermissions.request(); + await PermissionUtils.permissionsStatus(); + } + } + } void refreshApp() { _chainConfigurationUseCase.refresh(); @@ -191,17 +196,17 @@ class DAppsPagePresenter extends CompletePresenter { } } - // Future checkLocationService() async { - // final geo.GeolocatorPlatform geoLocatorPlatform = - // geo.GeolocatorPlatform.instance; + Future checkLocationService() async { + final geo.GeolocatorPlatform geoLocatorPlatform = + geo.GeolocatorPlatform.instance; - // bool _serviceEnabled; + bool _serviceEnabled; - // _serviceEnabled = await geoLocatorPlatform.isLocationServiceEnabled(); - // if (!_serviceEnabled) { - // await geoLocatorPlatform.getCurrentPosition(); - // _serviceEnabled = await geoLocatorPlatform.isLocationServiceEnabled(); - // } - // return _serviceEnabled; - // } + _serviceEnabled = await geoLocatorPlatform.isLocationServiceEnabled(); + if (!_serviceEnabled) { + await geoLocatorPlatform.getCurrentPosition(); + _serviceEnabled = await geoLocatorPlatform.isLocationServiceEnabled(); + } + return _serviceEnabled; + } } diff --git a/lib/features/dapps/presentation/responsive_layout/dapp_card_layout.dart b/lib/features/dapps/presentation/responsive_layout/dapp_card_layout.dart index c5f34abb..acc90ed1 100644 --- a/lib/features/dapps/presentation/responsive_layout/dapp_card_layout.dart +++ b/lib/features/dapps/presentation/responsive_layout/dapp_card_layout.dart @@ -77,8 +77,8 @@ class DappCardLayout extends HookConsumerWidget { onTap: state.isEditMode ? null : () async { - // await actions - // .requestPermissions(item); + await actions + .requestPermissions(item); actions.openDapp( item.app!.url!, ); @@ -94,8 +94,8 @@ class DappCardLayout extends HookConsumerWidget { onTap: state.isEditMode ? null : () async { - // await actions - // .requestPermissions(item); + await actions + .requestPermissions(item); actions.openDapp( item.app!.url!, ); diff --git a/pubspec.lock b/pubspec.lock index e7d9c55d..1f99c59d 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1171,10 +1171,10 @@ packages: dependency: transitive description: name: plugin_platform_interface - sha256: "43798d895c929056255600343db8f049921cbec94d31ec87f1dc5c16c01935dd" + sha256: da3fdfeccc4d4ff2da8f8c556704c08f912542c5fb3cf2233ed75372384a034d url: "https://pub.dev" source: hosted - version: "2.1.5" + version: "2.1.6" pointycastle: dependency: transitive description: From 9d4dfdc7dc180d3ab6d7bd2ce20c460e5c7191a5 Mon Sep 17 00:00:00 2001 From: reasje Date: Thu, 11 Apr 2024 11:11:27 +0330 Subject: [PATCH 02/11] refactor: Remove unnecessary wallet connect --- pubspec.lock | 24 ++++++++---------------- pubspec.yaml | 1 - 2 files changed, 8 insertions(+), 17 deletions(-) diff --git a/pubspec.lock b/pubspec.lock index e7d9c55d..14cf1e8d 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -224,14 +224,6 @@ packages: url: "https://pub.dev" source: hosted version: "3.0.3" - cryptography: - dependency: transitive - description: - name: cryptography - sha256: df156c5109286340817d21fa7b62f9140f17915077127dd70f8bd7a2a0997a35 - url: "https://pub.dev" - source: hosted - version: "2.5.0" cupertino_icons: dependency: "direct main" description: @@ -343,6 +335,14 @@ packages: url: "https://pub.dev" source: hosted version: "0.2.1" + fast_cached_network_image: + dependency: "direct main" + description: + name: fast_cached_network_image + sha256: "0b1acb2c36c7266547ebcba8cbd838c127238ed9081cabe8ab21bea7647e56d6" + url: "https://pub.dev" + source: hosted + version: "1.0.1" ffi: dependency: transitive description: @@ -1572,14 +1572,6 @@ packages: url: "https://pub.dev" source: hosted version: "0.0.12+1" - wallet_connect: - dependency: "direct main" - description: - name: wallet_connect - sha256: b294400c9aef22379183a3cd3e6c7ca89191bc53e5afb0b521a0ba65cbdc7d78 - url: "https://pub.dev" - source: hosted - version: "1.0.4" web3_provider: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index 1b1959a2..d9060af1 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -89,7 +89,6 @@ dependencies: sliver_tools: ^0.2.5 url_launcher: ^6.1.11 vibration: ^1.7.7 - wallet_connect: ^1.0.4 web3_provider: path: packages/web3_provider wifi_scan: ^0.4.1 From e42c26d0a1adeb3e89b60a837179f6bf119a8722 Mon Sep 17 00:00:00 2001 From: reasje Date: Fri, 12 Apr 2024 10:53:36 +0330 Subject: [PATCH 03/11] feat: Handle DApp store local data --- lib/features/dapps/domain/dapp_store_use_case.dart | 9 ++++++++- lib/features/dapps/presentation/dapps_presenter.dart | 9 ++++----- lib/features/dapps/presentation/dapps_state.dart | 2 +- .../presentation/responsive_layout/dapp_card.dart | 10 ++++++---- packages/shared | 2 +- pubspec.lock | 8 -------- 6 files changed, 20 insertions(+), 20 deletions(-) diff --git a/lib/features/dapps/domain/dapp_store_use_case.dart b/lib/features/dapps/domain/dapp_store_use_case.dart index d56eccd5..2fd26dbd 100644 --- a/lib/features/dapps/domain/dapp_store_use_case.dart +++ b/lib/features/dapps/domain/dapp_store_use_case.dart @@ -6,12 +6,19 @@ import 'package:mxc_logic/mxc_logic.dart'; class DappStoreUseCase extends ReactiveUseCase { DappStoreUseCase( this._repository, - ); + ) { + loadLocalDApps(); + } final Web3Repository _repository; late final ValueStream> dapps = reactive([]); + loadLocalDApps() async { + final result = await _repository.dappStoreRepository.getAllDappsFromLocal(); + update(dapps, result); + } + Future getAllDapps() async { final result = await _repository.dappStoreRepository.getAllDapps(); diff --git a/lib/features/dapps/presentation/dapps_presenter.dart b/lib/features/dapps/presentation/dapps_presenter.dart index e06b0bff..cd498766 100644 --- a/lib/features/dapps/presentation/dapps_presenter.dart +++ b/lib/features/dapps/presentation/dapps_presenter.dart @@ -29,7 +29,6 @@ class DAppsPagePresenter extends CompletePresenter { void initState() { super.initState(); - ref.read(mxcWebsocketUseCaseProvider); SystemChrome.setPreferredOrientations([ @@ -49,6 +48,10 @@ class DAppsPagePresenter extends CompletePresenter { state.dapps = v; state.dappsAndBookmarks.clear(); state.dappsAndBookmarks = [...v, ...state.bookmarks]; + if (v.isNotEmpty) { + DappUtils.loadingOnce = false; + notify(() => state.loading = false); + } notify(); }, ); @@ -89,14 +92,10 @@ class DAppsPagePresenter extends CompletePresenter { } void initializeDapps() async { - notify(() => state.loading = true); try { await _dappStoreUseCase.getAllDapps(); } catch (e, s) { addError(e, s); - } finally { - DappUtils.loadingOnce = false; - notify(() => state.loading = false); } } diff --git a/lib/features/dapps/presentation/dapps_state.dart b/lib/features/dapps/presentation/dapps_state.dart index cfc45345..beb777aa 100644 --- a/lib/features/dapps/presentation/dapps_state.dart +++ b/lib/features/dapps/presentation/dapps_state.dart @@ -9,7 +9,7 @@ class DAppsState with EquatableMixin { List dapps = []; List dappsAndBookmarks = []; - bool loading = false; + bool loading = true; Network? network; diff --git a/lib/features/dapps/presentation/responsive_layout/dapp_card.dart b/lib/features/dapps/presentation/responsive_layout/dapp_card.dart index 4b912b8c..bc5c324c 100644 --- a/lib/features/dapps/presentation/responsive_layout/dapp_card.dart +++ b/lib/features/dapps/presentation/responsive_layout/dapp_card.dart @@ -49,10 +49,12 @@ class DappCard extends StatelessWidget { return ClipRRect( borderRadius: BorderRadius.circular(22), - child: CachedNetworkImage( - imageUrl: '${Urls.dappRoot}/$image', - fit: BoxFit.cover, - )); + child: image!.contains('https') + ? CachedNetworkImage( + imageUrl: image, + fit: BoxFit.cover, + ) + : Image.asset(image)); } } diff --git a/packages/shared b/packages/shared index 6adabea7..a2089b79 160000 --- a/packages/shared +++ b/packages/shared @@ -1 +1 @@ -Subproject commit 6adabea7a35eb51f2a30bbf66c41faeb3720cabf +Subproject commit a2089b7958f58fcd4abc50cad26567f99ef86a1f diff --git a/pubspec.lock b/pubspec.lock index 14cf1e8d..ec04425f 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -335,14 +335,6 @@ packages: url: "https://pub.dev" source: hosted version: "0.2.1" - fast_cached_network_image: - dependency: "direct main" - description: - name: fast_cached_network_image - sha256: "0b1acb2c36c7266547ebcba8cbd838c127238ed9081cabe8ab21bea7647e56d6" - url: "https://pub.dev" - source: hosted - version: "1.0.1" ffi: dependency: transitive description: From f769a46da164e767af7683b7b4959fd84244491a Mon Sep 17 00:00:00 2001 From: reasje Date: Mon, 15 Apr 2024 12:11:31 +0330 Subject: [PATCH 04/11] feat: Support local tokens --- .../src/providers/providers_use_cases.dart | 3 ++ .../common/app/function_use_case.dart | 8 ++++ .../contract/token_contract_use_case.dart | 41 +++++++++++++++++-- .../widgets/token_balance_item.dart | 4 +- .../domain/chain_configuration_use_case.dart | 4 ++ 5 files changed, 54 insertions(+), 6 deletions(-) diff --git a/lib/core/src/providers/providers_use_cases.dart b/lib/core/src/providers/providers_use_cases.dart index dbffc736..0774ca56 100644 --- a/lib/core/src/providers/providers_use_cases.dart +++ b/lib/core/src/providers/providers_use_cases.dart @@ -46,6 +46,9 @@ final Provider gesturesInstructionUseCaseProvider = final Provider tokenContractUseCaseProvider = Provider( (ref) => TokenContractUseCase( ref.watch(web3RepositoryProvider), + ref.watch(chainConfigurationUseCaseProvider), + ref.watch(accountUseCaseProvider), + ref.watch(functionUseCaseProvider), ), ); diff --git a/lib/features/common/app/function_use_case.dart b/lib/features/common/app/function_use_case.dart index 9995b6a5..d14b9a98 100644 --- a/lib/features/common/app/function_use_case.dart +++ b/lib/features/common/app/function_use_case.dart @@ -19,6 +19,14 @@ class FunctionUseCase extends ReactiveUseCase { } } + void mxcChainsAndEthereumFuncWrapper( + Function func, + ) { + if (_chainConfigurationUseCase.isMXCChains() || _chainConfigurationUseCase.isEthereumMainnet()) { + func(); + } + } + void chainsFuncWrapper(Function mxcChainsFunc, Function noneMXCChainsFunc) { if (_chainConfigurationUseCase.isMXCChains()) { mxcChainsFunc(); diff --git a/lib/features/common/contract/token_contract_use_case.dart b/lib/features/common/contract/token_contract_use_case.dart index e1beb78d..770b5f66 100644 --- a/lib/features/common/contract/token_contract_use_case.dart +++ b/lib/features/common/contract/token_contract_use_case.dart @@ -1,6 +1,7 @@ import 'dart:async'; -import 'package:datadashwallet/common/common.dart'; import 'package:datadashwallet/core/core.dart'; +import 'package:datadashwallet/features/common/common.dart'; +import 'package:datadashwallet/features/settings/subfeatures/chain_configuration/domain/chain_configuration_use_case.dart'; import 'package:flutter/services.dart'; import 'package:mxc_logic/mxc_logic.dart'; import 'package:web3dart/web3dart.dart'; @@ -16,9 +17,39 @@ extension Unique on List { class TokenContractUseCase extends ReactiveUseCase { TokenContractUseCase( this._repository, - ); + this._chainConfigurationUseCase, + this._accountUseCase, + this._functionUseCase, + ) { + initListeners(); + } + + void initListeners() { + _accountUseCase.account.listen((v) { + account = v; + }); + + _chainConfigurationUseCase.selectedNetwork.listen((v) { + if (v != null) { + _functionUseCase.mxcChainsAndEthereumFuncWrapper( + () => loadLocalTokenList(v.chainId)); + } + }); + } + + void loadLocalTokenList(int chainId) async { + final stringData = await MXCFileHelpers.getTokenList(chainId); + DefaultTokens data = + DefaultTokens.fromJson(stringData).changeAssetsRemoteToLocal(); + getDefaultTokens(account!.address, defaultTokens: data); + } final Web3Repository _repository; + final ChainConfigurationUseCase _chainConfigurationUseCase; + final AccountUseCase _accountUseCase; + final FunctionUseCase _functionUseCase; + + Account? account; late final ValueStream online = reactive(false); @@ -55,10 +86,12 @@ class TokenContractUseCase extends ReactiveUseCase { .getTokenTransfersByAddress(address, TokenType.erc_20); } - Future> getDefaultTokens(String walletAddress) async { + Future> getDefaultTokens(String walletAddress, + {DefaultTokens? defaultTokens}) async { tokensList.value.clear(); tokensList.value.addAll(customTokenList); - final result = await _repository.tokenContract.getDefaultTokens(); + final result = + defaultTokens ?? await _repository.tokenContract.getDefaultTokens(); final cNetwork = _repository.tokenContract.getCurrentNetwork(); diff --git a/lib/features/portfolio/subfeatures/tokens_balance_list/widgets/token_balance_item.dart b/lib/features/portfolio/subfeatures/tokens_balance_list/widgets/token_balance_item.dart index 445999da..bb435c76 100644 --- a/lib/features/portfolio/subfeatures/tokens_balance_list/widgets/token_balance_item.dart +++ b/lib/features/portfolio/subfeatures/tokens_balance_list/widgets/token_balance_item.dart @@ -26,7 +26,7 @@ class TokenBalanceItem extends HookConsumerWidget { @override Widget build(BuildContext context, WidgetRef ref) { - final _accountUseCase = ref.watch(accountUseCaseProvider); + final accountUseCase = ref.watch(accountUseCaseProvider); final walletState = ref.watch(walletContainer.state); String balanceInXSDConverter = walletState.xsdConversionRate == 1.0 ? balanceInXsd @@ -88,7 +88,7 @@ class TokenBalanceItem extends HookConsumerWidget { color: ColorsTheme.of(context).white400), ), Text( - '$balanceInXSDConverter ${_accountUseCase.getXsdUnit()}', + '$balanceInXSDConverter ${accountUseCase.getXsdUnit()}', style: FontTheme.of(context).subtitle1().copyWith( color: walletState.hideBalance == true ? null diff --git a/lib/features/settings/subfeatures/chain_configuration/domain/chain_configuration_use_case.dart b/lib/features/settings/subfeatures/chain_configuration/domain/chain_configuration_use_case.dart index ac682c95..86c613dd 100644 --- a/lib/features/settings/subfeatures/chain_configuration/domain/chain_configuration_use_case.dart +++ b/lib/features/settings/subfeatures/chain_configuration/domain/chain_configuration_use_case.dart @@ -166,4 +166,8 @@ class ChainConfigurationUseCase extends ReactiveUseCase { bool isMXCChains() { return Config.isMxcChains(selectedNetwork.value!.chainId); } + + bool isEthereumMainnet() { + return Config.isEthereumMainnet(selectedNetwork.value!.chainId); + } } From da6dfe3a691f3dffef69c4b4a227ab75418bcd8e Mon Sep 17 00:00:00 2001 From: reasje Date: Mon, 15 Apr 2024 17:03:44 +0330 Subject: [PATCH 05/11] refactor: Config => MXC chains --- .../domain/transactions_history_use_case.dart | 4 ++-- .../receive_bottom_sheet_utils.dart | 2 +- .../src/background_process/dapp_hooks_service.dart | 4 ++-- .../background_process/notifications_service.dart | 2 +- .../subfeatures/open_dapp/open_dapp_presenter.dart | 2 +- .../choose_crypto/choose_crypto_presenter.dart | 2 +- .../send_crypto/send_crypto_presenter.dart | 2 +- .../transaction_history_presenter.dart | 4 ++-- .../domain/chain_configuration_repository.dart | 2 +- .../domain/chain_configuration_use_case.dart | 4 ++-- .../subfeatures/dapp_hooks/dapp_hooks_page.dart | 2 +- .../dapp_hooks/domain/dapp_hooks_use_case.dart | 2 +- .../domain/background_fetch_config_use_case.dart | 2 +- .../notifications/notificaitons_page.dart | 3 ++- .../wallet/presentation/wallet_page_presenter.dart | 14 +++++++------- packages/shared | 2 +- 16 files changed, 27 insertions(+), 26 deletions(-) diff --git a/lib/common/components/recent_transactions/domain/transactions_history_use_case.dart b/lib/common/components/recent_transactions/domain/transactions_history_use_case.dart index 55ba2d1c..0b4c4e1b 100644 --- a/lib/common/components/recent_transactions/domain/transactions_history_use_case.dart +++ b/lib/common/components/recent_transactions/domain/transactions_history_use_case.dart @@ -38,7 +38,7 @@ class TransactionsHistoryUseCase extends ReactiveUseCase { if (selectedNetwork != null) { final chainId = selectedNetwork.chainId; checkChainChange(chainId); - if (!Config.isMxcChains(chainId)) { + if (!MXCChains.isMXCChains(chainId)) { checkForPendingTransactions(); } } @@ -172,7 +172,7 @@ class TransactionsHistoryUseCase extends ReactiveUseCase { TransactionModel newPendingTransaction, int chainId, TransactionActions transactionActions) { - if (!Config.isMxcChains(chainId)) { + if (!MXCChains.isMXCChains(chainId)) { newPendingTransaction = newPendingTransaction.copyWith(action: transactionActions); diff --git a/lib/common/dialogs/receive_bottom_sheet/receive_bottom_sheet_utils.dart b/lib/common/dialogs/receive_bottom_sheet/receive_bottom_sheet_utils.dart index 036df6f2..16e63432 100644 --- a/lib/common/dialogs/receive_bottom_sheet/receive_bottom_sheet_utils.dart +++ b/lib/common/dialogs/receive_bottom_sheet/receive_bottom_sheet_utils.dart @@ -11,7 +11,7 @@ void showReceiveBottomSheet( VoidCallback onL3Tap, void Function(String url) launchUrlInPlatformDefault, bool showError) { - if (Config.isMxcChains(chainId)) { + if (MXCChains.isMXCChains(chainId)) { showWalletAddressDialogMXCChains( context: context, walletAddress: walletAddress, diff --git a/lib/core/src/background_process/dapp_hooks_service.dart b/lib/core/src/background_process/dapp_hooks_service.dart index 616ce231..eb335b97 100644 --- a/lib/core/src/background_process/dapp_hooks_service.dart +++ b/lib/core/src/background_process/dapp_hooks_service.dart @@ -30,7 +30,7 @@ class DAppHooksService { final wifiHooksEnabled = dappHooksData.wifiHooks.enabled; // Make sure user is logged in - if (isLoggedIn && Config.isMxcChains(chainId) && serviceEnabled) { + if (isLoggedIn && MXCChains.isMXCChains(chainId) && serviceEnabled) { await AXSNotification() .setupFlutterNotifications(shouldInitFirebase: false); await contextLessTranslationUseCase.setupTranslator(); @@ -76,7 +76,7 @@ class DAppHooksService { final minerHooksTime = dappHooksData.minerHooks.time; final selectedMiners = dappHooksData.minerHooks.selectedMiners; // Make sure user is logged in - if (isLoggedIn && Config.isMxcChains(chainId) && minerHooksEnabled) { + if (isLoggedIn && MXCChains.isMXCChains(chainId) && minerHooksEnabled) { await AXSNotification() .setupFlutterNotifications(shouldInitFirebase: false); await contextLessTranslationUseCase.setupTranslator(); diff --git a/lib/core/src/background_process/notifications_service.dart b/lib/core/src/background_process/notifications_service.dart index 2fe11a38..1e6f387c 100644 --- a/lib/core/src/background_process/notifications_service.dart +++ b/lib/core/src/background_process/notifications_service.dart @@ -40,7 +40,7 @@ class NotificationsService { final serviceEnabled = periodicalCallData.serviceEnabled; // Make sure user is logged in - if (isLoggedIn && Config.isMxcChains(chainId) && serviceEnabled) { + if (isLoggedIn && MXCChains.isMXCChains(chainId) && serviceEnabled) { await AXSNotification() .setupFlutterNotifications(shouldInitFirebase: false); await contextLessTranslationUseCase.setupTranslator(); diff --git a/lib/features/dapps/subfeatures/open_dapp/open_dapp_presenter.dart b/lib/features/dapps/subfeatures/open_dapp/open_dapp_presenter.dart index 00821b8b..454e72ed 100644 --- a/lib/features/dapps/subfeatures/open_dapp/open_dapp_presenter.dart +++ b/lib/features/dapps/subfeatures/open_dapp/open_dapp_presenter.dart @@ -133,7 +133,7 @@ class OpenDAppPresenter extends CompletePresenter { amount: amount, data: data, estimatedGasFee: estimatedGasFee); - if (!Config.isMxcChains(state.network!.chainId)) { + if (!MXCChains.isMXCChains(state.network!.chainId)) { recordTransaction(res); } diff --git a/lib/features/portfolio/subfeatures/token/send_token/choose_crypto/choose_crypto_presenter.dart b/lib/features/portfolio/subfeatures/token/send_token/choose_crypto/choose_crypto_presenter.dart index 40d013df..79bd41e0 100644 --- a/lib/features/portfolio/subfeatures/token/send_token/choose_crypto/choose_crypto_presenter.dart +++ b/lib/features/portfolio/subfeatures/token/send_token/choose_crypto/choose_crypto_presenter.dart @@ -49,7 +49,7 @@ class ChooseCryptoPresenter extends CompletePresenter { Future loadPage() async { final chainId = state.network!.chainId; final shouldGetPrice = - Config.isMxcChains(chainId) || Config.isEthereumMainnet(chainId); + MXCChains.isMXCChains(chainId) || MXCChains.isEthereumMainnet(chainId); await _tokenContractUseCase.getTokensBalance( null, state.account!.address, shouldGetPrice); } diff --git a/lib/features/portfolio/subfeatures/token/send_token/send_crypto/send_crypto_presenter.dart b/lib/features/portfolio/subfeatures/token/send_token/send_crypto/send_crypto_presenter.dart index 2032f360..2b53439b 100644 --- a/lib/features/portfolio/subfeatures/token/send_token/send_crypto/send_crypto_presenter.dart +++ b/lib/features/portfolio/subfeatures/token/send_token/send_crypto/send_crypto_presenter.dart @@ -300,7 +300,7 @@ class SendCryptoPresenter extends CompletePresenter { token: token, ); - if (!Config.isMxcChains(state.network!.chainId)) { + if (!MXCChains.isMXCChains(state.network!.chainId)) { final tx = res; _transactionHistoryUseCase.updateItem( diff --git a/lib/features/portfolio/subfeatures/transaction_history/transaction_history_presenter.dart b/lib/features/portfolio/subfeatures/transaction_history/transaction_history_presenter.dart index 646d3699..b2b48270 100644 --- a/lib/features/portfolio/subfeatures/transaction_history/transaction_history_presenter.dart +++ b/lib/features/portfolio/subfeatures/transaction_history/transaction_history_presenter.dart @@ -40,7 +40,7 @@ class TransactionHistoryPresenter listen(_transactionHistoryUseCase.transactionsHistory, (value) { if (state.network != null) { - if (!Config.isMxcChains(state.network!.chainId)) { + if (!MXCChains.isMXCChains(state.network!.chainId)) { getCustomChainsTransactions(value); } } @@ -57,7 +57,7 @@ class TransactionHistoryPresenter } void getTransactions() async { - if (Config.isMxcChains(state.network!.chainId)) { + if (MXCChains.isMXCChains(state.network!.chainId)) { getMXCTransactions(); } else { getCustomChainsTransactions(null); diff --git a/lib/features/settings/subfeatures/chain_configuration/domain/chain_configuration_repository.dart b/lib/features/settings/subfeatures/chain_configuration/domain/chain_configuration_repository.dart index 23fb4fd8..954e0894 100644 --- a/lib/features/settings/subfeatures/chain_configuration/domain/chain_configuration_repository.dart +++ b/lib/features/settings/subfeatures/chain_configuration/domain/chain_configuration_repository.dart @@ -47,7 +47,7 @@ class ChainConfigurationRepository extends GlobalCacheRepository { String? get selectedIpfsGatewayItem => selectedIpfsGateWay.value; /// Add - void addItem(Network item) => Config.isMxcChains(item.chainId) + void addItem(Network item) => MXCChains.isMXCChains(item.chainId) ? networks.value = [item, ...networks.value] : networks.value = [...networks.value, item]; diff --git a/lib/features/settings/subfeatures/chain_configuration/domain/chain_configuration_use_case.dart b/lib/features/settings/subfeatures/chain_configuration/domain/chain_configuration_use_case.dart index 86c613dd..a0930ede 100644 --- a/lib/features/settings/subfeatures/chain_configuration/domain/chain_configuration_use_case.dart +++ b/lib/features/settings/subfeatures/chain_configuration/domain/chain_configuration_use_case.dart @@ -164,10 +164,10 @@ class ChainConfigurationUseCase extends ReactiveUseCase { } bool isMXCChains() { - return Config.isMxcChains(selectedNetwork.value!.chainId); + return MXCChains.isMXCChains(selectedNetwork.value!.chainId); } bool isEthereumMainnet() { - return Config.isEthereumMainnet(selectedNetwork.value!.chainId); + return MXCChains.isEthereumMainnet(selectedNetwork.value!.chainId); } } diff --git a/lib/features/settings/subfeatures/dapp_hooks/dapp_hooks_page.dart b/lib/features/settings/subfeatures/dapp_hooks/dapp_hooks_page.dart index 820f89d3..386d68e5 100644 --- a/lib/features/settings/subfeatures/dapp_hooks/dapp_hooks_page.dart +++ b/lib/features/settings/subfeatures/dapp_hooks/dapp_hooks_page.dart @@ -27,7 +27,7 @@ class DAppHooksPage extends HookConsumerWidget { final frequency = getPeriodicalCallDurationFromInt( dappHooksState.dAppHooksData!.duration); - final isMXCChains = Config.isMxcChains(dappHooksState.network!.chainId); + final isMXCChains = MXCChains.isMXCChains(dappHooksState.network!.chainId); final dappHooksServiceServiceEnabled = dappHooksState.dAppHooksData!.enabled; diff --git a/lib/features/settings/subfeatures/dapp_hooks/domain/dapp_hooks_use_case.dart b/lib/features/settings/subfeatures/dapp_hooks/domain/dapp_hooks_use_case.dart index 57249119..1d78aa0c 100644 --- a/lib/features/settings/subfeatures/dapp_hooks/domain/dapp_hooks_use_case.dart +++ b/lib/features/settings/subfeatures/dapp_hooks/domain/dapp_hooks_use_case.dart @@ -62,7 +62,7 @@ class DAppHooksUseCase extends ReactiveUseCase { void initialize() { _chainConfigurationUseCase.selectedNetwork.listen((network) { final isMXCChains = - network != null && !Config.isMxcChains(network.chainId); + network != null && !MXCChains.isMXCChains(network.chainId); final dappHooksData = _repository.item; if (!isMXCChains) { bgFetch.BackgroundFetch.stop(BackgroundExecutionConfig.dappHookTasks); diff --git a/lib/features/settings/subfeatures/notifications/domain/background_fetch_config_use_case.dart b/lib/features/settings/subfeatures/notifications/domain/background_fetch_config_use_case.dart index 480d8fd9..ae8cabc4 100644 --- a/lib/features/settings/subfeatures/notifications/domain/background_fetch_config_use_case.dart +++ b/lib/features/settings/subfeatures/notifications/domain/background_fetch_config_use_case.dart @@ -44,7 +44,7 @@ class BackgroundFetchConfigUseCase extends ReactiveUseCase { void initialize() { _chainConfigurationUseCase.selectedNetwork.listen((network) { final isMXCChains = - network != null && !Config.isMxcChains(network.chainId); + network != null && !MXCChains.isMXCChains(network.chainId); final periodicalCallData = _repository.item; if (!isMXCChains) { bgFetch.BackgroundFetch.stop( diff --git a/lib/features/settings/subfeatures/notifications/notificaitons_page.dart b/lib/features/settings/subfeatures/notifications/notificaitons_page.dart index 9e7d96d9..98a48e0f 100644 --- a/lib/features/settings/subfeatures/notifications/notificaitons_page.dart +++ b/lib/features/settings/subfeatures/notifications/notificaitons_page.dart @@ -31,7 +31,8 @@ class NotificationsPage extends HookConsumerWidget { final frequency = getPeriodicalCallDurationFromInt( notificationsState.periodicalCallData!.duration); - final isMXCChains = Config.isMxcChains(notificationsState.network!.chainId); + final isMXCChains = + MXCChains.isMXCChains(notificationsState.network!.chainId); final bgServiceEnabled = notificationsState.periodicalCallData!.serviceEnabled; diff --git a/lib/features/wallet/presentation/wallet_page_presenter.dart b/lib/features/wallet/presentation/wallet_page_presenter.dart index 84ab9641..38b5e383 100644 --- a/lib/features/wallet/presentation/wallet_page_presenter.dart +++ b/lib/features/wallet/presentation/wallet_page_presenter.dart @@ -57,7 +57,7 @@ class WalletPresenter extends CompletePresenter { listen(_transactionHistoryUseCase.transactionsHistory, (value) { if (state.network != null && - !Config.isMxcChains(state.network!.chainId)) { + !MXCChains.isMXCChains(state.network!.chainId)) { getCustomChainsTransactions(value); initBalanceUpdateStream(); } @@ -88,8 +88,8 @@ class WalletPresenter extends CompletePresenter { _tokenContractUseCase.addCustomTokens( customTokens, state.account?.address ?? _accountUserCase.account.value!.address, - Config.isMxcChains(state.network!.chainId) || - Config.isEthereumMainnet(state.network!.chainId)); + MXCChains.isMXCChains(state.network!.chainId) || + MXCChains.isEthereumMainnet(state.network!.chainId)); initializeBalancePanelAndTokens(); }); @@ -148,7 +148,7 @@ class WalletPresenter extends CompletePresenter { } void getTransactions() async { - if (Config.isMxcChains(state.network!.chainId)) { + if (MXCChains.isMXCChains(state.network!.chainId)) { getMXCTransactions(); } else { getCustomChainsTransactions(null); @@ -175,8 +175,8 @@ class WalletPresenter extends CompletePresenter { initializeBalancePanelAndTokens() { getDefaultTokens().then((tokenList) => getWalletTokensBalance( tokenList, - Config.isMxcChains(state.network!.chainId) || - Config.isEthereumMainnet(state.network!.chainId))); + MXCChains.isMXCChains(state.network!.chainId) || + MXCChains.isEthereumMainnet(state.network!.chainId))); } Future> getDefaultTokens() async { @@ -315,7 +315,7 @@ class WalletPresenter extends CompletePresenter { } void resetBalanceUpdateStream() { - if (Config.isMxcChains(state.network!.chainId) && + if (MXCChains.isMXCChains(state.network!.chainId) && state.balancesUpdateSubscription != null) { state.balancesUpdateSubscription!.cancel(); state.balancesUpdateSubscription = null; diff --git a/packages/shared b/packages/shared index a2089b79..b48afe04 160000 --- a/packages/shared +++ b/packages/shared @@ -1 +1 @@ -Subproject commit a2089b7958f58fcd4abc50cad26567f99ef86a1f +Subproject commit b48afe0471d9ca4c36438ff996f8b4b585f8f22f From 859fc9c26142408a9f2577a187055feb3a69e4b5 Mon Sep 17 00:00:00 2001 From: reasje Date: Mon, 15 Apr 2024 17:31:42 +0330 Subject: [PATCH 06/11] refactor: get nft markets url --- lib/features/common/app/launcher_use_case.dart | 9 +-------- lib/features/portfolio/presentation/portfolio_page.dart | 2 +- packages/shared | 2 +- 3 files changed, 3 insertions(+), 10 deletions(-) diff --git a/lib/features/common/app/launcher_use_case.dart b/lib/features/common/app/launcher_use_case.dart index a7ee5fee..0385e123 100644 --- a/lib/features/common/app/launcher_use_case.dart +++ b/lib/features/common/app/launcher_use_case.dart @@ -83,14 +83,7 @@ class LauncherUseCase extends ReactiveUseCase { } String? getNftMarketPlaceUrl() { - final enabledNetwork = _chainConfigurationUseCase.selectedNetwork.value!; - if (enabledNetwork.chainId == Config.mxcTestnetChainId) { - return Urls.mxcTestnetNftMarketPlace; - } else if (enabledNetwork.chainId == Config.mxcMainnetChainId) { - return Urls.mxcMainnetNftMarketPlace; - } else { - return null; - } + return _repository.launcherRepository.getNftMarketPlaceUrl(); } Future launchEmailApp() async { diff --git a/lib/features/portfolio/presentation/portfolio_page.dart b/lib/features/portfolio/presentation/portfolio_page.dart index edb5306f..478953b4 100644 --- a/lib/features/portfolio/presentation/portfolio_page.dart +++ b/lib/features/portfolio/presentation/portfolio_page.dart @@ -22,7 +22,7 @@ class PortfolioPage extends HookConsumerWidget { Widget build(BuildContext context, WidgetRef ref) { final presenter = ref.read(portfolioContainer.actions); final state = ref.watch(portfolioContainer.state); - + return MxcPage( presenter: presenter, resizeToAvoidBottomInset: true, diff --git a/packages/shared b/packages/shared index b48afe04..2d0e0566 160000 --- a/packages/shared +++ b/packages/shared @@ -1 +1 @@ -Subproject commit b48afe0471d9ca4c36438ff996f8b4b585f8f22f +Subproject commit 2d0e0566e488783926a9c0cf948c11d4c8ca6f38 From e24ac2ce787ba0407162461ffec0ce723018f7af Mon Sep 17 00:00:00 2001 From: reasje Date: Tue, 16 Apr 2024 09:05:53 +0330 Subject: [PATCH 07/11] refactor: chain config import --- lib/features/settings/settings.dart | 1 + .../chain_configuration/chain_configuration.dart | 10 ++++++++++ .../chain_configuration/chain_configuration_page.dart | 5 +---- .../subfeatures/chain_configuration/domain/domain.dart | 2 ++ .../add_custom_network/add_custom_network.dart | 3 +++ .../subfeatures/add_network/add_network.dart | 5 +++++ .../{add_netwrok_page.dart => add_network_page.dart} | 0 .../subfeatures/add_network/utils/utils.dart | 1 + .../subfeatures/add_network/widgets/widgets.dart | 1 + .../delete_custom_network/delete_custom_network.dart | 3 +++ .../widgets/{chians_dialog.dart => chains_dialog.dart} | 0 .../chain_configuration/widgets/widgets.dart | 5 +++++ 12 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 lib/features/settings/subfeatures/chain_configuration/chain_configuration.dart create mode 100644 lib/features/settings/subfeatures/chain_configuration/domain/domain.dart create mode 100644 lib/features/settings/subfeatures/chain_configuration/subfeatures/add_custom_network/add_custom_network.dart create mode 100644 lib/features/settings/subfeatures/chain_configuration/subfeatures/add_network/add_network.dart rename lib/features/settings/subfeatures/chain_configuration/subfeatures/add_network/{add_netwrok_page.dart => add_network_page.dart} (100%) create mode 100644 lib/features/settings/subfeatures/chain_configuration/subfeatures/add_network/utils/utils.dart create mode 100644 lib/features/settings/subfeatures/chain_configuration/subfeatures/add_network/widgets/widgets.dart create mode 100644 lib/features/settings/subfeatures/chain_configuration/subfeatures/delete_custom_network/delete_custom_network.dart rename lib/features/settings/subfeatures/chain_configuration/widgets/{chians_dialog.dart => chains_dialog.dart} (100%) create mode 100644 lib/features/settings/subfeatures/chain_configuration/widgets/widgets.dart diff --git a/lib/features/settings/settings.dart b/lib/features/settings/settings.dart index f4dd8c24..95bb1f60 100644 --- a/lib/features/settings/settings.dart +++ b/lib/features/settings/settings.dart @@ -6,6 +6,7 @@ export 'subfeatures/language/language.dart'; export 'subfeatures/about_page/about_page.dart'; export 'subfeatures/theme/presentation/theme_settings/theme_settings_page.dart'; export 'subfeatures/language/presentation/language_page/language_page.dart'; +export 'subfeatures/chain_configuration/chain_configuration.dart'; export 'subfeatures/address_book/presentation/select_recipient/select_recipient_page.dart'; export 'subfeatures/qr_code/show_qa_code/qr_code_page.dart'; export 'subfeatures/xsd_conversion_rate/xsd_conversion_rate_page.dart'; diff --git a/lib/features/settings/subfeatures/chain_configuration/chain_configuration.dart b/lib/features/settings/subfeatures/chain_configuration/chain_configuration.dart new file mode 100644 index 00000000..25e58e72 --- /dev/null +++ b/lib/features/settings/subfeatures/chain_configuration/chain_configuration.dart @@ -0,0 +1,10 @@ +export 'chain_configuration_page.dart'; +export 'chain_configuration_presenter.dart'; +export 'chain_configuration_state.dart'; +export 'widgets/widgets.dart'; +export 'subfeatures/add_network/add_network.dart'; +export 'subfeatures/add_network/widgets/widgets.dart'; +export 'subfeatures/add_network/utils/utils.dart'; +export 'subfeatures/delete_custom_network/delete_custom_network.dart'; +export 'subfeatures/add_custom_network/add_custom_network.dart'; +export 'domain/domain.dart'; \ No newline at end of file diff --git a/lib/features/settings/subfeatures/chain_configuration/chain_configuration_page.dart b/lib/features/settings/subfeatures/chain_configuration/chain_configuration_page.dart index 437a8a6e..d9fed9f8 100644 --- a/lib/features/settings/subfeatures/chain_configuration/chain_configuration_page.dart +++ b/lib/features/settings/subfeatures/chain_configuration/chain_configuration_page.dart @@ -1,10 +1,7 @@ import 'package:datadashwallet/common/common.dart'; import 'package:datadashwallet/core/core.dart'; import 'package:datadashwallet/features/common/common.dart'; -import 'package:datadashwallet/features/settings/subfeatures/chain_configuration/chain_configuration_presenter.dart'; -import 'package:datadashwallet/features/settings/subfeatures/chain_configuration/subfeatures/add_network/add_netwrok_page.dart'; -import 'package:datadashwallet/features/settings/subfeatures/chain_configuration/widgets/ipfs_gate_ways_dialog.dart'; -import 'package:datadashwallet/features/settings/subfeatures/chain_configuration/widgets/network_item.dart'; +import 'package:datadashwallet/features/settings/subfeatures/chain_configuration/chain_configuration.dart'; import 'package:flutter/material.dart'; import 'package:flutter_hooks/flutter_hooks.dart'; import 'package:flutter_i18n/flutter_i18n.dart'; diff --git a/lib/features/settings/subfeatures/chain_configuration/domain/domain.dart b/lib/features/settings/subfeatures/chain_configuration/domain/domain.dart new file mode 100644 index 00000000..51ce7969 --- /dev/null +++ b/lib/features/settings/subfeatures/chain_configuration/domain/domain.dart @@ -0,0 +1,2 @@ +export 'chain_configuration_repository.dart'; +export 'chain_configuration_use_case.dart'; \ No newline at end of file diff --git a/lib/features/settings/subfeatures/chain_configuration/subfeatures/add_custom_network/add_custom_network.dart b/lib/features/settings/subfeatures/chain_configuration/subfeatures/add_custom_network/add_custom_network.dart new file mode 100644 index 00000000..5e5348e3 --- /dev/null +++ b/lib/features/settings/subfeatures/chain_configuration/subfeatures/add_custom_network/add_custom_network.dart @@ -0,0 +1,3 @@ +export 'add_custom_network_state.dart'; +export 'add_custom_network_presenter.dart'; +export 'add_custom_network_page.dart'; \ No newline at end of file diff --git a/lib/features/settings/subfeatures/chain_configuration/subfeatures/add_network/add_network.dart b/lib/features/settings/subfeatures/chain_configuration/subfeatures/add_network/add_network.dart new file mode 100644 index 00000000..0c97b216 --- /dev/null +++ b/lib/features/settings/subfeatures/chain_configuration/subfeatures/add_network/add_network.dart @@ -0,0 +1,5 @@ +export 'add_network_state.dart'; +export 'add_network_presenter.dart'; +export 'add_network_page.dart'; +export 'widgets/widgets.dart'; +export 'utils/utils.dart'; diff --git a/lib/features/settings/subfeatures/chain_configuration/subfeatures/add_network/add_netwrok_page.dart b/lib/features/settings/subfeatures/chain_configuration/subfeatures/add_network/add_network_page.dart similarity index 100% rename from lib/features/settings/subfeatures/chain_configuration/subfeatures/add_network/add_netwrok_page.dart rename to lib/features/settings/subfeatures/chain_configuration/subfeatures/add_network/add_network_page.dart diff --git a/lib/features/settings/subfeatures/chain_configuration/subfeatures/add_network/utils/utils.dart b/lib/features/settings/subfeatures/chain_configuration/subfeatures/add_network/utils/utils.dart new file mode 100644 index 00000000..3adc995c --- /dev/null +++ b/lib/features/settings/subfeatures/chain_configuration/subfeatures/add_network/utils/utils.dart @@ -0,0 +1 @@ +export 'add_network_utils.dart'; \ No newline at end of file diff --git a/lib/features/settings/subfeatures/chain_configuration/subfeatures/add_network/widgets/widgets.dart b/lib/features/settings/subfeatures/chain_configuration/subfeatures/add_network/widgets/widgets.dart new file mode 100644 index 00000000..babfb144 --- /dev/null +++ b/lib/features/settings/subfeatures/chain_configuration/subfeatures/add_network/widgets/widgets.dart @@ -0,0 +1 @@ +export 'switch_network_dialog.dart'; \ No newline at end of file diff --git a/lib/features/settings/subfeatures/chain_configuration/subfeatures/delete_custom_network/delete_custom_network.dart b/lib/features/settings/subfeatures/chain_configuration/subfeatures/delete_custom_network/delete_custom_network.dart new file mode 100644 index 00000000..71684e66 --- /dev/null +++ b/lib/features/settings/subfeatures/chain_configuration/subfeatures/delete_custom_network/delete_custom_network.dart @@ -0,0 +1,3 @@ +export 'delete_custom_network_state.dart'; +export 'delete_custom_network_presenter.dart'; +export 'delete_custom_network_page.dart'; diff --git a/lib/features/settings/subfeatures/chain_configuration/widgets/chians_dialog.dart b/lib/features/settings/subfeatures/chain_configuration/widgets/chains_dialog.dart similarity index 100% rename from lib/features/settings/subfeatures/chain_configuration/widgets/chians_dialog.dart rename to lib/features/settings/subfeatures/chain_configuration/widgets/chains_dialog.dart diff --git a/lib/features/settings/subfeatures/chain_configuration/widgets/widgets.dart b/lib/features/settings/subfeatures/chain_configuration/widgets/widgets.dart new file mode 100644 index 00000000..d4e42934 --- /dev/null +++ b/lib/features/settings/subfeatures/chain_configuration/widgets/widgets.dart @@ -0,0 +1,5 @@ +export 'chain_logo_widget.dart'; +export 'chains_dialog.dart'; +export 'ipfs_gate_ways_dialog.dart'; +export 'network_details_page.dart'; +export 'network_item.dart'; From ac65ef6db5a34e383e3d7c7eb126436ef3c18549 Mon Sep 17 00:00:00 2001 From: reasje Date: Tue, 16 Apr 2024 10:36:20 +0330 Subject: [PATCH 08/11] refactor: ipfs provider --- .../src/providers/providers_use_cases.dart | 7 ++ lib/features/common/contract/contract.dart | 1 + .../contract/ipfs_gateway_use_case.dart | 65 +++++++++++++++++++ .../contract/nft_contract_use_case.dart | 15 ----- .../dapps/presentation/dapps_presenter.dart | 42 +----------- packages/shared | 2 +- 6 files changed, 77 insertions(+), 55 deletions(-) create mode 100644 lib/features/common/contract/ipfs_gateway_use_case.dart diff --git a/lib/core/src/providers/providers_use_cases.dart b/lib/core/src/providers/providers_use_cases.dart index 0774ca56..535d2d63 100644 --- a/lib/core/src/providers/providers_use_cases.dart +++ b/lib/core/src/providers/providers_use_cases.dart @@ -245,3 +245,10 @@ final Provider mxcWebsocketUseCaseProvider = Provider( ref.watch(functionUseCaseProvider), ), ); + +final Provider ipfsUseCaseProvider = Provider( + (ref) => IPFSUseCase( + ref.watch(web3RepositoryProvider), + ref.watch(chainConfigurationUseCaseProvider), + ), +); diff --git a/lib/features/common/contract/contract.dart b/lib/features/common/contract/contract.dart index d34daa59..4d0fca88 100644 --- a/lib/features/common/contract/contract.dart +++ b/lib/features/common/contract/contract.dart @@ -6,3 +6,4 @@ export 'pricing_use_case.dart'; export 'token_contract_use_case.dart'; export 'transaction_controller.dart'; export 'tweets_use_case.dart'; +export 'ipfs_gateway_use_case.dart'; diff --git a/lib/features/common/contract/ipfs_gateway_use_case.dart b/lib/features/common/contract/ipfs_gateway_use_case.dart new file mode 100644 index 00000000..cf711874 --- /dev/null +++ b/lib/features/common/contract/ipfs_gateway_use_case.dart @@ -0,0 +1,65 @@ +import 'dart:async'; + +import 'package:datadashwallet/common/common.dart'; +import 'package:datadashwallet/core/core.dart'; +import 'package:datadashwallet/features/settings/settings.dart'; +import 'package:mxc_logic/mxc_logic.dart'; + +class IPFSUseCase extends ReactiveUseCase { + IPFSUseCase(this._repository, this._chainConfigurationUseCase) { + initializeIpfsGateways(); + } + + final Web3Repository _repository; + final ChainConfigurationUseCase _chainConfigurationUseCase; + + void initializeIpfsGateways() async { + Utils.retryFunction(() async { + final List? list = await getIpfsGateWays(); + + if (list != null) { + checkIpfsGateways(list); + } else { + throw 'Error while retrieving ipfs gateway list!'; + } + }); + } + + // Future> loadLocalData() { + + // } + + Future> getDefaultIpfsGateWays() async { + final result = await _repository.ipfsRepository.getDefaultIpfsGateways(); + final List list = []; + + if (result != null) { + list.addAll(result.gateways ?? []); + } + + return list; + } + + Future checkIpfsGatewayStatus(String url) async { + return await _repository.ipfsRepository.checkIpfsGateway(url); + } + + Future?> getIpfsGateWays() async { + final newList = await getDefaultIpfsGateWays(); + _chainConfigurationUseCase.updateIpfsGateWayList(newList); + + return newList; + } + + void checkIpfsGateways(List list) async { + for (int i = 0; i < list.length; i++) { + final cUrl = list[i]; + final response = await checkIpfsGatewayStatus(cUrl); + + if (response != false) { + _chainConfigurationUseCase.changeIpfsGateWay(cUrl); + break; + } + } + } +} diff --git a/lib/features/common/contract/nft_contract_use_case.dart b/lib/features/common/contract/nft_contract_use_case.dart index d0d4db69..2d4cc595 100644 --- a/lib/features/common/contract/nft_contract_use_case.dart +++ b/lib/features/common/contract/nft_contract_use_case.dart @@ -56,19 +56,4 @@ class NftContractUseCase extends ReactiveUseCase { ) async { return await _repository.nftContract.getNftsByAddress(address); } - - Future> getDefaultIpfsGateWays() async { - final result = await _repository.nftContract.getDefaultIpfsGateways(); - final List list = []; - - if (result != null) { - list.addAll(result.gateways ?? []); - } - - return list; - } - - Future checkIpfsGatewayStatus(String url) async { - return await _repository.nftContract.checkIpfsGateway(url); - } } diff --git a/lib/features/dapps/presentation/dapps_presenter.dart b/lib/features/dapps/presentation/dapps_presenter.dart index cd498766..cb3992ed 100644 --- a/lib/features/dapps/presentation/dapps_presenter.dart +++ b/lib/features/dapps/presentation/dapps_presenter.dart @@ -20,7 +20,6 @@ class DAppsPagePresenter extends CompletePresenter { late final _dappStoreUseCase = ref.read(dappStoreUseCaseProvider); late final _chainConfigurationUseCase = ref.read(chainConfigurationUseCaseProvider); - late final _nftContractUseCase = ref.read(nftContractUseCaseProvider); late final _gesturesInstructionUseCase = ref.read(gesturesInstructionUseCaseProvider); late final _accountUseCase = ref.read(accountUseCaseProvider); @@ -29,7 +28,10 @@ class DAppsPagePresenter extends CompletePresenter { void initState() { super.initState(); + // Initializing providers ref.read(mxcWebsocketUseCaseProvider); + ref.read(ipfsUseCaseProvider); + SystemChrome.setPreferredOrientations([ DeviceOrientation.portraitUp, @@ -81,14 +83,8 @@ class DAppsPagePresenter extends CompletePresenter { }); } - @override - Future dispose() async { - super.dispose(); - } - void loadPage() { initializeDapps(); - initializeIpfsGateways(); } void initializeDapps() async { @@ -99,15 +95,6 @@ class DAppsPagePresenter extends CompletePresenter { } } - void initializeIpfsGateways() async { - final List? list = await getIpfsGateWays(); - - if (list != null) { - checkIpfsGateways(list); - } else { - initializeIpfsGateways(); - } - } void removeBookmark(Bookmark item) { _bookmarksUseCase.removeItem(item); @@ -118,29 +105,6 @@ class DAppsPagePresenter extends CompletePresenter { void changeEditMode() => notify(() => state.isEditMode = !state.isEditMode); void resetEditMode() => notify(() => state.isEditMode = false); - Future?> getIpfsGateWays() async { - List? newList; - try { - newList = await _nftContractUseCase.getDefaultIpfsGateWays(); - _chainConfigurationUseCase.updateIpfsGateWayList(newList); - } catch (e) { - addError(e.toString()); - } - - return newList; - } - - void checkIpfsGateways(List list) async { - for (int i = 0; i < list.length; i++) { - final cUrl = list[i]; - final response = await _nftContractUseCase.checkIpfsGatewayStatus(cUrl); - - if (response != false) { - _chainConfigurationUseCase.changeIpfsGateWay(cUrl); - break; - } - } - } void setGesturesInstruction() { _gesturesInstructionUseCase.setEducated(true); diff --git a/packages/shared b/packages/shared index 2d0e0566..63650b06 160000 --- a/packages/shared +++ b/packages/shared @@ -1 +1 @@ -Subproject commit 2d0e0566e488783926a9c0cf948c11d4c8ca6f38 +Subproject commit 63650b06f744c1134a262f67d3212f585f8904b2 From c4a86c1b082b2951f53beebfff4728c425d2d318 Mon Sep 17 00:00:00 2001 From: reasje Date: Tue, 16 Apr 2024 19:41:26 +0330 Subject: [PATCH 09/11] feat: Ipfs gate way local data --- .../contract/ipfs_gateway_use_case.dart | 49 ++++++++++++++----- 1 file changed, 37 insertions(+), 12 deletions(-) diff --git a/lib/features/common/contract/ipfs_gateway_use_case.dart b/lib/features/common/contract/ipfs_gateway_use_case.dart index cf711874..8eb85ff5 100644 --- a/lib/features/common/contract/ipfs_gateway_use_case.dart +++ b/lib/features/common/contract/ipfs_gateway_use_case.dart @@ -14,20 +14,27 @@ class IPFSUseCase extends ReactiveUseCase { final ChainConfigurationUseCase _chainConfigurationUseCase; void initializeIpfsGateways() async { - Utils.retryFunction(() async { - final List? list = await getIpfsGateWays(); - - if (list != null) { - checkIpfsGateways(list); - } else { - throw 'Error while retrieving ipfs gateway list!'; - } - }); + processIpfsGatewayListLocal(); + Utils.retryFunction(processIpfsGatewayList); } - // Future> loadLocalData() { - - // } + Future processIpfsGatewayListLocal() async => + checkIpfsGatewaysWrapper(getIpfsGateWaysLocal); + + Future processIpfsGatewayList() async => + checkIpfsGatewaysWrapper(getIpfsGateWays); + + Future> getDefaultIpfsGateWaysLocal() async { + final result = await _repository.ipfsRepository.getDefaultIpfsGateways(); + + final List list = []; + + if (result != null) { + list.addAll(result.gateways ?? []); + } + + return list; + } Future> getDefaultIpfsGateWays() async { final result = await _repository.ipfsRepository.getDefaultIpfsGateways(); @@ -44,6 +51,13 @@ class IPFSUseCase extends ReactiveUseCase { return await _repository.ipfsRepository.checkIpfsGateway(url); } + Future?> getIpfsGateWaysLocal() async { + final newList = await getDefaultIpfsGateWaysLocal(); + _chainConfigurationUseCase.updateIpfsGateWayList(newList); + + return newList; + } + Future?> getIpfsGateWays() async { final newList = await getDefaultIpfsGateWays(); _chainConfigurationUseCase.updateIpfsGateWayList(newList); @@ -51,6 +65,17 @@ class IPFSUseCase extends ReactiveUseCase { return newList; } + void checkIpfsGatewaysWrapper( + Future?> Function() function) async { + final List? list = await function(); + + if (list != null) { + checkIpfsGateways(list); + } else { + throw 'Error while retrieving ipfs gateway list!'; + } + } + void checkIpfsGateways(List list) async { for (int i = 0; i < list.length; i++) { final cUrl = list[i]; From b22dcb31ff1e2fffeed2e9977a6d07fbbd66b117 Mon Sep 17 00:00:00 2001 From: reasje Date: Wed, 17 Apr 2024 20:23:47 +0330 Subject: [PATCH 10/11] feat: ipfs & tweets local data init --- .../contract/ipfs_gateway_use_case.dart | 25 ++++++++----------- .../contract/token_contract_use_case.dart | 16 ++++++------ .../common/contract/tweets_use_case.dart | 14 ++++++++++- .../dapps/presentation/dapps_presenter.dart | 18 +++++++------ .../portfolio_page_presenter.dart | 2 +- .../presentation/wallet_page_presenter.dart | 21 +++++++--------- packages/shared | 2 +- 7 files changed, 53 insertions(+), 45 deletions(-) diff --git a/lib/features/common/contract/ipfs_gateway_use_case.dart b/lib/features/common/contract/ipfs_gateway_use_case.dart index 8eb85ff5..8d54c0b2 100644 --- a/lib/features/common/contract/ipfs_gateway_use_case.dart +++ b/lib/features/common/contract/ipfs_gateway_use_case.dart @@ -24,25 +24,20 @@ class IPFSUseCase extends ReactiveUseCase { Future processIpfsGatewayList() async => checkIpfsGatewaysWrapper(getIpfsGateWays); - Future> getDefaultIpfsGateWaysLocal() async { - final result = await _repository.ipfsRepository.getDefaultIpfsGateways(); + Future> getDefaultIpfsGateWaysLocal() async => + getDefaultIpfsGateWaysWrapper( + _repository.ipfsRepository.getDefaultIpfsGatewaysFromLocal); - final List list = []; - - if (result != null) { - list.addAll(result.gateways ?? []); - } + Future> getDefaultIpfsGateWays() async => + getDefaultIpfsGateWaysWrapper( + _repository.ipfsRepository.getDefaultIpfsGateways); - return list; - } - - Future> getDefaultIpfsGateWays() async { - final result = await _repository.ipfsRepository.getDefaultIpfsGateways(); + Future> getDefaultIpfsGateWaysWrapper( + Future Function() function) async { + final result = await function(); final List list = []; - if (result != null) { - list.addAll(result.gateways ?? []); - } + list.addAll(result.gateways ?? []); return list; } diff --git a/lib/features/common/contract/token_contract_use_case.dart b/lib/features/common/contract/token_contract_use_case.dart index 770b5f66..1839a9b7 100644 --- a/lib/features/common/contract/token_contract_use_case.dart +++ b/lib/features/common/contract/token_contract_use_case.dart @@ -88,10 +88,10 @@ class TokenContractUseCase extends ReactiveUseCase { Future> getDefaultTokens(String walletAddress, {DefaultTokens? defaultTokens}) async { - tokensList.value.clear(); - tokensList.value.addAll(customTokenList); final result = defaultTokens ?? await _repository.tokenContract.getDefaultTokens(); + tokensList.value.clear(); + tokensList.value.addAll(customTokenList); final cNetwork = _repository.tokenContract.getCurrentNetwork(); @@ -209,11 +209,13 @@ class TokenContractUseCase extends ReactiveUseCase { customTokenList = customTokens; update(tokensList, tokensList.value); - getTokensBalance( - customTokens, - walletAddress, - shouldGetPrice, - ); + if (customTokenList.isNotEmpty) { + getTokensBalance( + customTokens, + walletAddress, + shouldGetPrice, + ); + } } Future getGasPrice() async => diff --git a/lib/features/common/contract/tweets_use_case.dart b/lib/features/common/contract/tweets_use_case.dart index 1a18c8df..1a454b08 100644 --- a/lib/features/common/contract/tweets_use_case.dart +++ b/lib/features/common/contract/tweets_use_case.dart @@ -6,9 +6,21 @@ import 'package:mxc_logic/mxc_logic.dart'; class TweetsUseCase extends ReactiveUseCase { TweetsUseCase( this._repository, - ); + ) { + initTweetsList(); + } final Web3Repository _repository; + late final ValueStream defaultTweets = reactive(null); + + void initTweetsList() async { + final data = await getDefaultTweetsLocal(); + update(defaultTweets, data); + } + + Future getDefaultTweetsLocal() async { + return await _repository.tweetsRepository.getDefaultTweetsLocal(); + } Future getDefaultTweets() async { return await _repository.tweetsRepository.getDefaultTweets(); diff --git a/lib/features/dapps/presentation/dapps_presenter.dart b/lib/features/dapps/presentation/dapps_presenter.dart index cb3992ed..dc04737d 100644 --- a/lib/features/dapps/presentation/dapps_presenter.dart +++ b/lib/features/dapps/presentation/dapps_presenter.dart @@ -28,10 +28,10 @@ class DAppsPagePresenter extends CompletePresenter { void initState() { super.initState(); - // Initializing providers + // Initializing providers ref.read(mxcWebsocketUseCaseProvider); ref.read(ipfsUseCaseProvider); - + ref.read(tweetsUseCaseProvider); SystemChrome.setPreferredOrientations([ DeviceOrientation.portraitUp, @@ -95,7 +95,6 @@ class DAppsPagePresenter extends CompletePresenter { } } - void removeBookmark(Bookmark item) { _bookmarksUseCase.removeItem(item); } @@ -105,7 +104,6 @@ class DAppsPagePresenter extends CompletePresenter { void changeEditMode() => notify(() => state.isEditMode = !state.isEditMode); void resetEditMode() => notify(() => state.isEditMode = false); - void setGesturesInstruction() { _gesturesInstructionUseCase.setEducated(true); } @@ -161,11 +159,15 @@ class DAppsPagePresenter extends CompletePresenter { bool _serviceEnabled; - _serviceEnabled = await geoLocatorPlatform.isLocationServiceEnabled(); - if (!_serviceEnabled) { - await geoLocatorPlatform.getCurrentPosition(); + try { _serviceEnabled = await geoLocatorPlatform.isLocationServiceEnabled(); + if (!_serviceEnabled) { + await geoLocatorPlatform.getCurrentPosition(); + _serviceEnabled = await geoLocatorPlatform.isLocationServiceEnabled(); + } + return _serviceEnabled; + } catch (e) { + return false; } - return _serviceEnabled; } } diff --git a/lib/features/portfolio/presentation/portfolio_page_presenter.dart b/lib/features/portfolio/presentation/portfolio_page_presenter.dart index a790c45a..fde06e35 100644 --- a/lib/features/portfolio/presentation/portfolio_page_presenter.dart +++ b/lib/features/portfolio/presentation/portfolio_page_presenter.dart @@ -49,7 +49,7 @@ class PortfolioPresenter extends CompletePresenter { }); listen(_tokenContractUseCase.tokensList, (newTokenList) { - if (state.tokensList != null) { + if (state.tokensList != null && newTokenList.isNotEmpty) { notify(() => state.tokensList = newTokenList); } else { state.tokensList = newTokenList; diff --git a/lib/features/wallet/presentation/wallet_page_presenter.dart b/lib/features/wallet/presentation/wallet_page_presenter.dart index 38b5e383..612149ae 100644 --- a/lib/features/wallet/presentation/wallet_page_presenter.dart +++ b/lib/features/wallet/presentation/wallet_page_presenter.dart @@ -35,7 +35,11 @@ class WalletPresenter extends CompletePresenter { void initState() { super.initState(); - getMXCTweets(); + listen(_tweetsUseCase.defaultTweets, (v) { + if (v != null) { + notify(() => state.embeddedTweets = v.tweets!); + } + }); listen(_accountUserCase.account, (value) { if (value != null) { @@ -74,8 +78,10 @@ class WalletPresenter extends CompletePresenter { }); listen(_tokenContractUseCase.tokensList, (newTokenList) { - state.tokensList.clear(); - state.tokensList.addAll(newTokenList); + if (newTokenList.isNotEmpty) { + state.tokensList.clear(); + state.tokensList.addAll(newTokenList); + } }); listen(_tokenContractUseCase.totalBalanceInXsd, (newValue) { @@ -286,15 +292,6 @@ class WalletPresenter extends CompletePresenter { } } - void getMXCTweets() async { - try { - final defaultTweets = await _tweetsUseCase.getDefaultTweets(); - notify(() => state.embeddedTweets = defaultTweets.tweets!); - } catch (e) { - addError(e.toString()); - } - } - void getWalletTokensBalance( List? tokenList, bool shouldGetPrice) async { _tokenContractUseCase.getTokensBalance( diff --git a/packages/shared b/packages/shared index 63650b06..dc84877f 160000 --- a/packages/shared +++ b/packages/shared @@ -1 +1 @@ -Subproject commit 63650b06f744c1134a262f67d3212f585f8904b2 +Subproject commit dc84877f56336991c5194df143a6ba19898cbd9d From e84498a9cdf1c4a14350c096b71437f13bb0b289 Mon Sep 17 00:00:00 2001 From: reasje Date: Fri, 19 Apr 2024 19:01:06 +0330 Subject: [PATCH 11/11] fix: Update shared --- packages/shared | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/shared b/packages/shared index dc84877f..f21fc2f0 160000 --- a/packages/shared +++ b/packages/shared @@ -1 +1 @@ -Subproject commit dc84877f56336991c5194df143a6ba19898cbd9d +Subproject commit f21fc2f0a37e5088802558dcabe8484335f15fc2