From cb4515a8891a9ea0f9053d8b6f410f427be94db3 Mon Sep 17 00:00:00 2001 From: reasje Date: Mon, 25 Sep 2023 11:14:16 +0330 Subject: [PATCH 1/2] fix: Buy nft button webview not working --- .../presentation/portfolio_page_presenter.dart | 15 +++++---------- .../subfeatures/nft/nft_list/nft_list.dart | 14 +++++++++++++- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/lib/features/portfolio/presentation/portfolio_page_presenter.dart b/lib/features/portfolio/presentation/portfolio_page_presenter.dart index 18cd04e8..0bc9beb5 100644 --- a/lib/features/portfolio/presentation/portfolio_page_presenter.dart +++ b/lib/features/portfolio/presentation/portfolio_page_presenter.dart @@ -1,6 +1,5 @@ import 'package:datadashwallet/common/common.dart'; import 'package:datadashwallet/core/core.dart'; -import 'package:url_launcher/url_launcher.dart'; import 'portfolio_page_state.dart'; final portfolioContainer = @@ -80,20 +79,16 @@ class PortfolioPresenter extends CompletePresenter { } } - void buyNFt() { + String? getNftUrl() { final enabledNetwork = _chainConfigurationUseCase.networks.value .where((element) => element.enabled) .toList()[0]; if (enabledNetwork.chainId == Config.mxcTestnetChainId) { - openUrl(Urls.mxcTestnetNftMarketPlace); + return Urls.mxcTestnetNftMarketPlace; } else if (enabledNetwork.chainId == Config.mxcMainnetChainId) { - openUrl(Urls.mxcMainnetNftMarketPlace); + return Urls.mxcMainnetNftMarketPlace; + } else { + return null; } } - - void openUrl(String url) async { - (await canLaunchUrl(Uri.parse(url))) == true - ? launchUrl(Uri.parse(url), mode: LaunchMode.inAppWebView) - : null; - } } diff --git a/lib/features/portfolio/subfeatures/nft/nft_list/nft_list.dart b/lib/features/portfolio/subfeatures/nft/nft_list/nft_list.dart index 00740f2f..c51289fb 100644 --- a/lib/features/portfolio/subfeatures/nft/nft_list/nft_list.dart +++ b/lib/features/portfolio/subfeatures/nft/nft_list/nft_list.dart @@ -1,5 +1,7 @@ import 'dart:io'; +import 'package:datadashwallet/core/core.dart'; +import 'package:datadashwallet/features/dapps/dapps.dart'; import 'package:datadashwallet/features/portfolio/presentation/portfolio_page_presenter.dart'; import 'package:datadashwallet/features/portfolio/subfeatures/nft/nft_list/utils.dart'; import 'package:flutter/material.dart'; @@ -50,7 +52,17 @@ class NFTList extends HookConsumerWidget { key: const Key('buyNFTButton'), contentPadding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8), - onTap: () => presenter.buyNFt(), + onTap: () { + final launchUrl = presenter.getNftUrl(); + if (launchUrl != null) { + Navigator.of(context).push(route.featureDialog( + maintainState: false, + OpenAppPage( + url: launchUrl, + ), + )); + } + }, title: translate('buy_x').replaceFirst('{0}', 'NFT'), iconData: Icons.add, alignIconStart: true, From ec2dad645fbc2d26ce5b7595144d84266e98f67a Mon Sep 17 00:00:00 2001 From: reasje Date: Mon, 25 Sep 2023 15:16:44 +0330 Subject: [PATCH 2/2] fix: Swipe & Scroll same time & speed limitation --- .../subfeatures/open_dapp/open_dapp_page.dart | 61 ++++++++++++------- .../widgets/allow_multiple_gestures.dart | 20 ++++++ 2 files changed, 60 insertions(+), 21 deletions(-) create mode 100644 lib/features/dapps/subfeatures/open_dapp/widgets/allow_multiple_gestures.dart diff --git a/lib/features/dapps/subfeatures/open_dapp/open_dapp_page.dart b/lib/features/dapps/subfeatures/open_dapp/open_dapp_page.dart index 0da52fe4..ea536235 100644 --- a/lib/features/dapps/subfeatures/open_dapp/open_dapp_page.dart +++ b/lib/features/dapps/subfeatures/open_dapp/open_dapp_page.dart @@ -9,6 +9,7 @@ import 'package:web3_provider/web3_provider.dart'; import 'open_dapp_presenter.dart'; import 'open_dapp_state.dart'; import 'widgets/bridge_params.dart'; +import 'widgets/allow_multiple_gestures.dart'; class OpenAppPage extends HookConsumerWidget { const OpenAppPage({Key? key, required this.url}) : super(key: key); @@ -19,8 +20,7 @@ class OpenAppPage extends HookConsumerWidget { Widget build(BuildContext context, WidgetRef ref) { final presenter = ref.read(openDAppPageContainer.actions); final state = ref.watch(openDAppPageContainer.state); - const primaryVelocity = 500; - + const primaryVelocity = 2000; return Scaffold( backgroundColor: ColorsTheme.of(context).screenBackground, body: SafeArea( @@ -28,28 +28,44 @@ class OpenAppPage extends HookConsumerWidget { presenter: presenter, child: Stack( children: [ - GestureDetector( - onHorizontalDragEnd: (details) async { - final webViewController = state.webviewController!; - - if (details.primaryVelocity! < 0 - primaryVelocity && - (await webViewController.canGoForward())) { - webViewController.goForward(); - } + RawGestureDetector( + behavior: HitTestBehavior.opaque, + gestures: { + AllowMultipleHorizontalDrag: + GestureRecognizerFactoryWithHandlers< + AllowMultipleHorizontalDrag>( + () => AllowMultipleHorizontalDrag(), + (AllowMultipleHorizontalDrag instance) { + instance.onEnd = (details) async { + final webViewController = state.webviewController!; + if (details.primaryVelocity! < 0 - primaryVelocity && + (await webViewController.canGoForward())) { + webViewController.goForward(); + } - if (details.primaryVelocity! > primaryVelocity && - (await webViewController.canGoBack())) { - webViewController.goBack(); - } + if (details.primaryVelocity! > primaryVelocity && + (await webViewController.canGoBack())) { + webViewController.goBack(); + } - if (details.primaryVelocity! > primaryVelocity && - !(await webViewController.canGoBack())) { - if (BottomFlowDialog.maybeOf(context) != null) { - BottomFlowDialog.of(context).close(); - } - } + if (details.primaryVelocity! > primaryVelocity && + !(await webViewController.canGoBack())) { + if (BottomFlowDialog.maybeOf(context) != null) { + BottomFlowDialog.of(context).close(); + } + } + }; + }, + ), + AllowMultipleDoubleTap: GestureRecognizerFactoryWithHandlers< + AllowMultipleDoubleTap>( + () => AllowMultipleDoubleTap(), + (AllowMultipleDoubleTap instance) { + instance.onDoubleTap = + () => state.webviewController!.reload(); + }, + ) }, - onDoubleTap: () => state.webviewController!.reload(), child: InAppWebViewEIP1193( chainId: state.network?.chainId, rpcUrl: state.network?.web3RpcHttpUrl, @@ -122,6 +138,9 @@ class OpenAppPage extends HookConsumerWidget { Factory( () => VerticalDragGestureRecognizer(), ), + Factory( + () => HorizontalDragGestureRecognizer(), + ), }, androidOnPermissionRequest: (controller, origin, resources) async { diff --git a/lib/features/dapps/subfeatures/open_dapp/widgets/allow_multiple_gestures.dart b/lib/features/dapps/subfeatures/open_dapp/widgets/allow_multiple_gestures.dart new file mode 100644 index 00000000..aa0ac685 --- /dev/null +++ b/lib/features/dapps/subfeatures/open_dapp/widgets/allow_multiple_gestures.dart @@ -0,0 +1,20 @@ +import 'package:flutter/gestures.dart'; + +// Custom Gesture Recognizer. +// rejectGesture() is overridden. When a gesture is rejected, this is the function that is called. By default, it disposes of the +// Recognizer and runs clean up. However we modified it so that instead the Recognizer is disposed of, it is actually manually added. +// The result is instead you have one Recognizer winning the Arena, you have two. It is a win-win. +class AllowMultipleHorizontalDrag extends HorizontalDragGestureRecognizer { + @override + void rejectGesture(int pointer) { + acceptGesture(pointer); + } + +} + +class AllowMultipleDoubleTap extends DoubleTapGestureRecognizer { + @override + void rejectGesture(int pointer) { + acceptGesture(pointer); + } +} \ No newline at end of file