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/core/src/providers/providers_use_cases.dart b/lib/core/src/providers/providers_use_cases.dart index dbffc736..535d2d63 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), ), ); @@ -242,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/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/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/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..8d54c0b2 --- /dev/null +++ b/lib/features/common/contract/ipfs_gateway_use_case.dart @@ -0,0 +1,85 @@ +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 { + processIpfsGatewayListLocal(); + Utils.retryFunction(processIpfsGatewayList); + } + + Future processIpfsGatewayListLocal() async => + checkIpfsGatewaysWrapper(getIpfsGateWaysLocal); + + Future processIpfsGatewayList() async => + checkIpfsGatewaysWrapper(getIpfsGateWays); + + Future> getDefaultIpfsGateWaysLocal() async => + getDefaultIpfsGateWaysWrapper( + _repository.ipfsRepository.getDefaultIpfsGatewaysFromLocal); + + Future> getDefaultIpfsGateWays() async => + getDefaultIpfsGateWaysWrapper( + _repository.ipfsRepository.getDefaultIpfsGateways); + + Future> getDefaultIpfsGateWaysWrapper( + Future Function() function) async { + final result = await function(); + final List list = []; + + list.addAll(result.gateways ?? []); + + return list; + } + + Future checkIpfsGatewayStatus(String url) async { + 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); + + 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]; + 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/common/contract/token_contract_use_case.dart b/lib/features/common/contract/token_contract_use_case.dart index e1beb78d..1839a9b7 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 { + final result = + defaultTokens ?? await _repository.tokenContract.getDefaultTokens(); tokensList.value.clear(); tokensList.value.addAll(customTokenList); - final result = await _repository.tokenContract.getDefaultTokens(); final cNetwork = _repository.tokenContract.getCurrentNetwork(); @@ -176,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/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 2f0a8797..60e1671b 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'; @@ -20,7 +22,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 +30,10 @@ class DAppsPagePresenter extends CompletePresenter { void initState() { super.initState(); + // Initializing providers ref.read(mxcWebsocketUseCaseProvider); + ref.read(ipfsUseCaseProvider); + ref.read(tweetsUseCaseProvider); SystemChrome.setPreferredOrientations([ DeviceOrientation.portraitUp, @@ -48,6 +52,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(); }, ); @@ -77,35 +85,15 @@ class DAppsPagePresenter extends CompletePresenter { }); } - @override - Future dispose() async { - super.dispose(); - } - void loadPage() { initializeDapps(); - initializeIpfsGateways(); } 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); - } - } - - void initializeIpfsGateways() async { - final List? list = await getIpfsGateWays(); - - if (list != null) { - checkIpfsGateways(list); - } else { - initializeIpfsGateways(); } } @@ -118,61 +106,40 @@ 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 setGesturesInstruction() { + _gesturesInstructionUseCase.setEducated(true); } - void checkIpfsGateways(List list) async { - for (int i = 0; i < list.length; i++) { - final cUrl = list[i]; - final response = await _nftContractUseCase.checkIpfsGatewayStatus(cUrl); + 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 (response != false) { - _chainConfigurationUseCase.changeIpfsGateWay(cUrl); - break; + if (keys.contains('location')) { + await checkLocationService(); + } + if (needPermissions.isNotEmpty) { + await needPermissions.request(); + await PermissionUtils.permissionsStatus(); } } } - void setGesturesInstruction() { - _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(); - // } - // } - void refreshApp() { _chainConfigurationUseCase.refresh(); _accountUseCase.refresh(); @@ -191,17 +158,21 @@ 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; - // } + try { + _serviceEnabled = await geoLocatorPlatform.isLocationServiceEnabled(); + if (!_serviceEnabled) { + await geoLocatorPlatform.getCurrentPosition(); + _serviceEnabled = await geoLocatorPlatform.isLocationServiceEnabled(); + } + return _serviceEnabled; + } catch (e) { + return 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/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/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/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/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/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/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/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/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/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 ac682c95..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,6 +164,10 @@ class ChainConfigurationUseCase extends ReactiveUseCase { } bool isMXCChains() { - return Config.isMxcChains(selectedNetwork.value!.chainId); + return MXCChains.isMXCChains(selectedNetwork.value!.chainId); + } + + bool isEthereumMainnet() { + return MXCChains.isEthereumMainnet(selectedNetwork.value!.chainId); } } 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'; 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..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) { @@ -57,7 +61,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(); } @@ -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) { @@ -88,8 +94,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 +154,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 +181,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 { @@ -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( @@ -315,7 +312,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 6adabea7..f21fc2f0 160000 --- a/packages/shared +++ b/packages/shared @@ -1 +1 @@ -Subproject commit 6adabea7a35eb51f2a30bbf66c41faeb3720cabf +Subproject commit f21fc2f0a37e5088802558dcabe8484335f15fc2 diff --git a/pubspec.lock b/pubspec.lock index e7d9c55d..c8417460 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: @@ -1171,10 +1163,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: @@ -1572,14 +1564,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 259094af..d7a55cf7 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