From fa5a49610acb5344d736604e0d4505a2694c6ae2 Mon Sep 17 00:00:00 2001 From: Alfreedom <00tango.bromine@icloud.com> Date: Thu, 31 Oct 2024 13:04:10 +0100 Subject: [PATCH] fix on link mode --- .../example/base/lib/pages/connect_page.dart | 24 +++++++++++++++++++ .../example/modal/lib/home_page.dart | 24 +++++++++---------- .../lib/modal/appkit_modal_impl.dart | 18 ++++++++++---- packages/reown_appkit/pubspec.yaml | 12 +++++----- .../test/shared/shared_test_utils.mocks.dart | 7 +++--- packages/reown_core/lib/pairing/pairing.dart | 4 +++- packages/reown_sign/lib/sign_engine.dart | 24 +++++++++---------- packages/reown_sign/pubspec.yaml | 6 ++--- .../test/shared/shared_test_utils.mocks.dart | 7 +++--- .../lib/dependencies/deep_link_handler.dart | 2 +- .../example/lib/pages/settings_page.dart | 23 ++++++++++++++++++ packages/reown_walletkit/pubspec.yaml | 18 +++++++------- .../test/shared/shared_test_utils.mocks.dart | 7 +++--- 13 files changed, 117 insertions(+), 59 deletions(-) diff --git a/packages/reown_appkit/example/base/lib/pages/connect_page.dart b/packages/reown_appkit/example/base/lib/pages/connect_page.dart index 978b8c0..163af43 100644 --- a/packages/reown_appkit/example/base/lib/pages/connect_page.dart +++ b/packages/reown_appkit/example/base/lib/pages/connect_page.dart @@ -594,6 +594,30 @@ class __FooterWidgetState extends State<_FooterWidget> { }, ), const SizedBox(height: StyleConstants.linear8), + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Visibility( + visible: !widget.appKitModal.isConnected, + child: SizedBox( + height: 30.0, + child: ElevatedButton( + onPressed: () async { + await widget.appKitModal.appKit!.core.storage.deleteAll(); + ScaffoldMessenger.of(context).showSnackBar(SnackBar( + content: Text('Storage cleared'), + duration: Duration(seconds: 1), + )); + }, + child: Text( + 'CLEAR STORAGE', + style: TextStyle(fontSize: 10.0), + ), + ), + ), + ), + ], + ), ], ); } diff --git a/packages/reown_appkit/example/modal/lib/home_page.dart b/packages/reown_appkit/example/modal/lib/home_page.dart index 1391713..18a86ed 100644 --- a/packages/reown_appkit/example/modal/lib/home_page.dart +++ b/packages/reown_appkit/example/modal/lib/home_page.dart @@ -242,18 +242,18 @@ class _MyHomePageState extends State { metadata: _pairingMetadata(), siweConfig: _siweConfig(siweAuthValue), enableAnalytics: analyticsValue, // OPTIONAL - null by default - // featuresConfig: emailWalletValue - // ? FeaturesConfig( - // email: true, - // socials: [ - // AppKitSocialOption.Farcaster, - // AppKitSocialOption.X, - // AppKitSocialOption.Apple, - // AppKitSocialOption.Discord, - // ], - // // showMainWallets: false, // OPTIONAL - true by default - // ) - // : null, + featuresConfig: emailWalletValue + ? FeaturesConfig( + email: true, + socials: [ + AppKitSocialOption.Farcaster, + AppKitSocialOption.X, + AppKitSocialOption.Apple, + AppKitSocialOption.Discord, + ], + // showMainWallets: false, // OPTIONAL - true by default + ) + : null, // requiredNamespaces: {}, // optionalNamespaces: {}, // includedWalletIds: {}, diff --git a/packages/reown_appkit/lib/modal/appkit_modal_impl.dart b/packages/reown_appkit/lib/modal/appkit_modal_impl.dart index 9055be0..e456e56 100644 --- a/packages/reown_appkit/lib/modal/appkit_modal_impl.dart +++ b/packages/reown_appkit/lib/modal/appkit_modal_impl.dart @@ -809,11 +809,16 @@ class ReownAppKitModal with ChangeNotifier implements IReownAppKitModal { await _explorerService.storeConnectedWallet(_selectedWallet); } else { await buildConnectionUri(); - // await _uriService.openRedirect( - // walletRedirect, - // wcURI: wcUri!, - // pType: pType, - // ); + final linkMode = walletRedirect.linkMode ?? ''; + if (linkMode.isNotEmpty && _wcUri.startsWith(linkMode)) { + await ReownCoreUtils.openURL(_wcUri); + } else { + await _uriService.openRedirect( + walletRedirect, + wcURI: _wcUri, + pType: pType, + ); + } } } on LaunchUrlException catch (e) { if (e is CanNotLaunchUrl) { @@ -885,6 +890,9 @@ class ReownAppKitModal with ChangeNotifier implements IReownAppKitModal { ...p2, }); // One-Click Auth + _appKit.core.logger.d( + '[$runtimeType] authenticate ${jsonEncode(authParams.toJson())}, ${walletRedirect?.linkMode}', + ); final authResponse = await _appKit.authenticate( params: authParams, walletUniversalLink: walletRedirect?.linkMode, diff --git a/packages/reown_appkit/pubspec.yaml b/packages/reown_appkit/pubspec.yaml index 4b95d87..0bd66ae 100644 --- a/packages/reown_appkit/pubspec.yaml +++ b/packages/reown_appkit/pubspec.yaml @@ -26,12 +26,12 @@ dependencies: json_annotation: ^4.8.1 plugin_platform_interface: ^2.1.8 qr_flutter_wc: ^0.0.3 - # reown_core: ^1.0.3 - reown_core: - path: ../reown_core/ - # reown_sign: ^1.0.3 - reown_sign: - path: ../reown_sign/ + reown_core: ^1.0.3 + # reown_core: + # path: ../reown_core/ + reown_sign: ^1.0.3 + # reown_sign: + # path: ../reown_sign/ shimmer: ^3.0.0 uuid: ^4.5.1 webview_flutter: ^4.8.0 diff --git a/packages/reown_appkit/test/shared/shared_test_utils.mocks.dart b/packages/reown_appkit/test/shared/shared_test_utils.mocks.dart index fe4428e..a9cff43 100644 --- a/packages/reown_appkit/test/shared/shared_test_utils.mocks.dart +++ b/packages/reown_appkit/test/shared/shared_test_utils.mocks.dart @@ -1483,14 +1483,15 @@ class MockReownCore extends _i1.Mock implements _i28.ReownCore { ) as _i23.Future); @override - _i23.Future addLinkModeSupportedApp(String? universalLink) => + _i23.Future addLinkModeSupportedApp(String? universalLink) => (super.noSuchMethod( Invocation.method( #addLinkModeSupportedApp, [universalLink], ), - returnValue: _i23.Future.value(false), - ) as _i23.Future); + returnValue: _i23.Future.value(), + returnValueForMissingStub: _i23.Future.value(), + ) as _i23.Future); @override List getLinkModeSupportedApps() => (super.noSuchMethod( diff --git a/packages/reown_core/lib/pairing/pairing.dart b/packages/reown_core/lib/pairing/pairing.dart index e08fe5e..5a81282 100644 --- a/packages/reown_core/lib/pairing/pairing.dart +++ b/packages/reown_core/lib/pairing/pairing.dart @@ -877,7 +877,9 @@ class Pairing implements IPairing { required String topic, required String envelope, }) async { - core.logger.d('[$runtimeType] dispatchEnvelope $topic, $envelope'); + core.logger.d( + '[$runtimeType] dispatchEnvelope, topic: $topic, envelope: $envelope', + ); final message = Uri.decodeComponent(envelope); await core.relayClient.handleLinkModeMessage(topic, message); diff --git a/packages/reown_sign/lib/sign_engine.dart b/packages/reown_sign/lib/sign_engine.dart index 4bd48a6..0435a38 100644 --- a/packages/reown_sign/lib/sign_engine.dart +++ b/packages/reown_sign/lib/sign_engine.dart @@ -2283,7 +2283,7 @@ class ReownSign implements IReownSign { ttl: ttl, appLink: isLinkMode ? walletUniversalLink : null, // We don't want to open the appLink in this case as it will be opened by the host app - // openUrl: false, + openUrl: false, ); result = WcSessionAuthRequestResult.fromJson(response); } catch (error) { @@ -2673,15 +2673,15 @@ class ReownSign implements IReownSign { ); } - final request = WcSessionAuthRequestParams.fromJson(payload.params); + final saRequest = WcSessionAuthRequestParams.fromJson(payload.params); try { final cacaoPayload = CacaoRequestPayload.fromSessionAuthPayload( - request.authPayload, + saRequest.authPayload, ); final verifyContext = await _getVerifyContext( payload, - request.requester.metadata, + saRequest.requester.metadata, transportType, ); @@ -2690,15 +2690,15 @@ class ReownSign implements IReownSign { PendingSessionAuthRequest( id: payload.id, pairingTopic: topic, - requester: request.requester, + requester: saRequest.requester, authPayload: cacaoPayload, - expiryTimestamp: request.expiryTimestamp, + expiryTimestamp: saRequest.expiryTimestamp, verifyContext: verifyContext, transportType: transportType, ), ); - final appLink = (request.requester.metadata.redirect?.universal ?? ''); + final appLink = (saRequest.requester.metadata.redirect?.universal ?? ''); if (transportType.isLinkMode && appLink.isNotEmpty) { // save app as supported for link mode await core.addLinkModeSupportedApp(appLink); @@ -2708,14 +2708,14 @@ class ReownSign implements IReownSign { SessionAuthRequest( id: payload.id, topic: topic, - requester: request.requester, - authPayload: request.authPayload, + requester: saRequest.requester, + authPayload: saRequest.authPayload, verifyContext: verifyContext, transportType: transportType, ), ); } on ReownSignError catch (err) { - final receiverPublicKey = request.requester.publicKey; + final receiverPublicKey = saRequest.requester.publicKey; final senderPublicKey = await core.crypto.generateKeyPair(); final encodeOpts = EncodeOptions( @@ -2739,9 +2739,7 @@ class ReownSign implements IReownSign { Future dispatchEnvelope(String url) async { final topic = ReownCoreUtils.getSearchParamFromURL(url, 'topic'); final envelope = ReownCoreUtils.getSearchParamFromURL(url, 'wc_ev'); - core.logger.d( - '[$runtimeType] dispatchEnvelope $url, topic: $topic, envelope: $envelope', - ); + core.logger.d('[$runtimeType] dispatchEnvelope $url'); if (envelope.isEmpty) { throw ReownSignError(code: 0, message: 'Envelope not found'); diff --git a/packages/reown_sign/pubspec.yaml b/packages/reown_sign/pubspec.yaml index ff0475f..f01291f 100644 --- a/packages/reown_sign/pubspec.yaml +++ b/packages/reown_sign/pubspec.yaml @@ -15,9 +15,9 @@ dependencies: freezed_annotation: ^2.2.0 http: ^1.2.0 pointycastle: ^3.9.1 - # reown_core: ^1.0.3 - reown_core: - path: ../reown_core/ + reown_core: ^1.0.3 + # reown_core: + # path: ../reown_core/ web3dart: ^2.7.3 dev_dependencies: diff --git a/packages/reown_sign/test/shared/shared_test_utils.mocks.dart b/packages/reown_sign/test/shared/shared_test_utils.mocks.dart index 234edd8..300e3f7 100644 --- a/packages/reown_sign/test/shared/shared_test_utils.mocks.dart +++ b/packages/reown_sign/test/shared/shared_test_utils.mocks.dart @@ -1483,14 +1483,15 @@ class MockReownCore extends _i1.Mock implements _i28.ReownCore { ) as _i23.Future); @override - _i23.Future addLinkModeSupportedApp(String? universalLink) => + _i23.Future addLinkModeSupportedApp(String? universalLink) => (super.noSuchMethod( Invocation.method( #addLinkModeSupportedApp, [universalLink], ), - returnValue: _i23.Future.value(false), - ) as _i23.Future); + returnValue: _i23.Future.value(), + returnValueForMissingStub: _i23.Future.value(), + ) as _i23.Future); @override List getLinkModeSupportedApps() => (super.noSuchMethod( diff --git a/packages/reown_walletkit/example/lib/dependencies/deep_link_handler.dart b/packages/reown_walletkit/example/lib/dependencies/deep_link_handler.dart index f15c23b..7bcddd9 100644 --- a/packages/reown_walletkit/example/lib/dependencies/deep_link_handler.dart +++ b/packages/reown_walletkit/example/lib/dependencies/deep_link_handler.dart @@ -47,7 +47,7 @@ class DeepLinkHandler { try { return await _walletKit.dispatchEnvelope('$link'); } catch (e) { - final decodedUri = Uri.parse(Uri.decodeFull(link.toString())); + final decodedUri = Uri.parse(Uri.decodeFull('$link')); if (decodedUri.isScheme('wc')) { debugPrint('[SampleWallet] is legacy uri $decodedUri'); waiting.value = true; diff --git a/packages/reown_walletkit/example/lib/pages/settings_page.dart b/packages/reown_walletkit/example/lib/pages/settings_page.dart index abb1156..114b40a 100644 --- a/packages/reown_walletkit/example/lib/pages/settings_page.dart +++ b/packages/reown_walletkit/example/lib/pages/settings_page.dart @@ -81,6 +81,14 @@ class _SettingsPageState extends State { const SizedBox(height: 20.0), const Divider(height: 1.0), _Buttons( + onDeleteData: () async { + final walletKit = GetIt.I().walletKit; + await walletKit.core.storage.deleteAll(); + ScaffoldMessenger.of(context).showSnackBar(SnackBar( + content: Text('Storage cleared'), + duration: Duration(seconds: 1), + )); + }, onRestoreFromSeed: () async { final mnemonic = await GetIt.I().queueBottomSheet( @@ -624,9 +632,11 @@ class _DeviceData extends StatelessWidget { class _Buttons extends StatelessWidget { final VoidCallback onRestoreFromSeed; final VoidCallback onRestoreDefault; + final VoidCallback onDeleteData; const _Buttons({ required this.onRestoreFromSeed, required this.onRestoreDefault, + required this.onDeleteData, }); @override @@ -636,6 +646,19 @@ class _Buttons extends StatelessWidget { child: Column( children: [ const SizedBox(height: 8.0), + SizedBox( + width: double.infinity, + child: ElevatedButton( + onPressed: onDeleteData, + child: Text( + 'Clear local storage', + style: TextStyle( + fontWeight: FontWeight.bold, + ), + ), + ), + ), + const SizedBox(height: 12.0), Row( children: [ CustomButton( diff --git a/packages/reown_walletkit/pubspec.yaml b/packages/reown_walletkit/pubspec.yaml index 799f14c..60d46b7 100644 --- a/packages/reown_walletkit/pubspec.yaml +++ b/packages/reown_walletkit/pubspec.yaml @@ -12,12 +12,12 @@ dependencies: event: ^2.1.2 flutter: sdk: flutter - # reown_core: ^1.0.3 - reown_core: - path: ../reown_core/ - # reown_sign: ^1.0.3 - reown_sign: - path: ../reown_sign/ + reown_core: ^1.0.3 + # reown_core: + # path: ../reown_core/ + reown_sign: ^1.0.3 + # reown_sign: + # path: ../reown_sign/ dev_dependencies: build_runner: ^2.4.7 @@ -30,9 +30,9 @@ dev_dependencies: logger: ^2.2.0 mockito: ^5.4.3 package_info_plus: ^8.0.2 - # reown_appkit: ^1.0.2 - reown_appkit: - path: ../reown_appkit/ + reown_appkit: ^1.0.2 + # reown_appkit: + # path: ../reown_appkit/ platforms: android: diff --git a/packages/reown_walletkit/test/shared/shared_test_utils.mocks.dart b/packages/reown_walletkit/test/shared/shared_test_utils.mocks.dart index 7f5c83e..e36a4d0 100644 --- a/packages/reown_walletkit/test/shared/shared_test_utils.mocks.dart +++ b/packages/reown_walletkit/test/shared/shared_test_utils.mocks.dart @@ -1483,14 +1483,15 @@ class MockReownCore extends _i1.Mock implements _i28.ReownCore { ) as _i23.Future); @override - _i23.Future addLinkModeSupportedApp(String? universalLink) => + _i23.Future addLinkModeSupportedApp(String? universalLink) => (super.noSuchMethod( Invocation.method( #addLinkModeSupportedApp, [universalLink], ), - returnValue: _i23.Future.value(false), - ) as _i23.Future); + returnValue: _i23.Future.value(), + returnValueForMissingStub: _i23.Future.value(), + ) as _i23.Future); @override List getLinkModeSupportedApps() => (super.noSuchMethod(