From 6673f8cd513b0e8b45686a5aadf11d7cca985127 Mon Sep 17 00:00:00 2001 From: Alfreedom <00tango.bromine@icloud.com> Date: Tue, 27 Aug 2024 11:06:56 +0200 Subject: [PATCH] added linkmode from merge request --- .../android/app/src/main/AndroidManifest.xml | 10 ++ example/dapp/ios/Runner/Runner.entitlements | 1 + example/dapp/lib/main.dart | 23 ++-- example/dapp/lib/pages/connect_page.dart | 31 +++-- example/dapp/lib/utils/sample_wallets.dart | 126 +++++++++--------- .../android/app/src/main/AndroidManifest.xml | 10 ++ example/wallet/ios/Runner/Runner.entitlements | 1 + .../lib/dependencies/web3wallet_service.dart | 23 ++-- example/wallet/lib/pages/settings_page.dart | 23 ++++ 9 files changed, 159 insertions(+), 89 deletions(-) diff --git a/example/dapp/android/app/src/main/AndroidManifest.xml b/example/dapp/android/app/src/main/AndroidManifest.xml index 4215461..ebfc9a9 100644 --- a/example/dapp/android/app/src/main/AndroidManifest.xml +++ b/example/dapp/android/app/src/main/AndroidManifest.xml @@ -72,6 +72,16 @@ + + + + + + + + + + diff --git a/example/dapp/ios/Runner/Runner.entitlements b/example/dapp/ios/Runner/Runner.entitlements index 84ca64b..64aad23 100644 --- a/example/dapp/ios/Runner/Runner.entitlements +++ b/example/dapp/ios/Runner/Runner.entitlements @@ -6,6 +6,7 @@ applinks:lab.web3modal.com applinks:dev.lab.web3modal.com + applinks:web3modal-laboratory-git-chores-addedmore-3e0f2b-walletconnect1.vercel.app diff --git a/example/dapp/lib/main.dart b/example/dapp/lib/main.dart index bcd564f..1356643 100644 --- a/example/dapp/lib/main.dart +++ b/example/dapp/lib/main.dart @@ -67,21 +67,24 @@ class _MyHomePageState extends State { return flavor.replaceAll('-production', ''); } - String _universalLink() { - Uri link = Uri.parse('https://lab.web3modal.com/flutter_appkit'); + String _universalLink(bool fromMR) { + Uri link = fromMR + ? Uri.parse( + 'https://web3modal-laboratory-git-chores-addedmore-3e0f2b-walletconnect1.vercel.app/flutter_appkit') + : Uri.parse('https://lab.web3modal.com/flutter_appkit'); if (_flavor.isNotEmpty) { - return link - .replace(path: '${link.path}_internal') - .replace(host: 'dev.${link.host}') - .toString(); + if (!fromMR) { + link = link.replace(host: 'dev.${link.host}'); + } + return link.replace(path: '${link.path}_internal').toString(); } return link.toString(); } - Redirect _constructRedirect() { + Redirect _constructRedirect(bool fromMR) { return Redirect( native: 'wcflutterdapp$_flavor://', - universal: _universalLink(), + universal: _universalLink(fromMR), // enable linkMode on Wallet so Dapps can use relay-less connection // universal: value must be set on cloud config as well linkMode: true, @@ -89,6 +92,8 @@ class _MyHomePageState extends State { } Future initialize() async { + final prefs = await SharedPreferences.getInstance(); + final fromMR = prefs.getBool('_LM_from_MR') ?? false; _web3App = Web3App( core: Core( projectId: DartDefines.projectId, @@ -101,7 +106,7 @@ class _MyHomePageState extends State { icons: [ 'https://images.prismic.io/wallet-connect/65785a56531ac2845a260732_WalletConnect-App-Logo-1024X1024.png' ], - redirect: _constructRedirect(), + redirect: _constructRedirect(fromMR), ), ); diff --git a/example/dapp/lib/pages/connect_page.dart b/example/dapp/lib/pages/connect_page.dart index d2e8d61..6581e75 100644 --- a/example/dapp/lib/pages/connect_page.dart +++ b/example/dapp/lib/pages/connect_page.dart @@ -2,6 +2,7 @@ import 'dart:async'; import 'dart:convert'; +import 'dart:io'; import 'package:fl_toast/fl_toast.dart'; import 'package:flutter/foundation.dart'; @@ -35,6 +36,7 @@ class ConnectPage extends StatefulWidget { class ConnectPageState extends State { bool _testnetOnly = false; + bool _testFromMR = true; final List _selectedChains = []; bool _shouldDismissQrCode = true; bool _initialized = false; @@ -53,6 +55,9 @@ class ConnectPageState extends State { await _walletConnectModalService.init(); + final prefs = await SharedPreferences.getInstance(); + _testFromMR = prefs.getBool('_LM_from_MR') ?? false; + setState(() => _initialized = true); widget.web3App.onSessionConnect.subscribe(_onSessionConnect); @@ -64,13 +69,6 @@ class ConnectPageState extends State { super.dispose(); } - void setTestnet(bool value) { - if (value != _testnetOnly) { - _selectedChains.clear(); - } - _testnetOnly = value; - } - void _selectChain(ChainMetadata chain) { setState(() { if (_selectedChains.contains(chain)) { @@ -206,6 +204,19 @@ class ConnectPageState extends State { }); }, ), + const Expanded(child: SizedBox()), + const Text( + 'LM from MR', + style: StyleConstants.buttonText, + ), + Switch( + value: _testFromMR, + onChanged: (value) async { + final prefs = await SharedPreferences.getInstance(); + await prefs.setBool('_LM_from_MR', value); + exit(0); + }, + ), ], ), ), @@ -253,7 +264,8 @@ class ConnectPageState extends State { Wrap( spacing: 8.0, runSpacing: 8.0, - children: WCSampleWallets.getSampleWallets().map((wallet) { + children: + WCSampleWallets.getSampleWallets(_testFromMR).map((wallet) { return SizedBox( width: (MediaQuery.of(context).size.width / 2) - 16, child: ElevatedButton( @@ -294,7 +306,8 @@ class ConnectPageState extends State { Wrap( spacing: 8.0, runSpacing: 8.0, - children: WCSampleWallets.getSampleWallets().map((wallet) { + children: + WCSampleWallets.getSampleWallets(_testFromMR).map((wallet) { return SizedBox( width: (MediaQuery.of(context).size.width / 2) - 16, child: ElevatedButton( diff --git a/example/dapp/lib/utils/sample_wallets.dart b/example/dapp/lib/utils/sample_wallets.dart index fd866f1..01d8fa1 100644 --- a/example/dapp/lib/utils/sample_wallets.dart +++ b/example/dapp/lib/utils/sample_wallets.dart @@ -1,69 +1,71 @@ import 'dart:io'; class WCSampleWallets { - static final List> sampleWallets = [ - { - 'name': 'Swift Wallet', - 'platform': ['ios'], - 'id': '123456789012345678901234567890', - 'schema': 'walletapp://', - 'bundleId': 'com.walletconnect.sample.wallet', - 'universal': 'https://lab.web3modal.com/wallet', - }, - { - 'name': 'Flutter Wallet', - 'platform': ['ios', 'android'], - 'id': '123456789012345678901234567891', - 'schema': 'wcflutterwallet://', - 'bundleId': 'com.walletconnect.flutterwallet', - 'universal': 'https://lab.web3modal.com/flutter_walletkit', - }, - { - 'name': 'Flutter Wallet (internal)', - 'platform': ['ios', 'android'], - 'id': '123456789012345678901234567895', - 'schema': 'wcflutterwallet-internal://', - 'bundleId': 'com.walletconnect.flutterwallet.internal', - 'universal': 'https://dev.lab.web3modal.com/flutter_walletkit_internal', - }, - { - 'name': 'RN Wallet', - 'platform': ['ios', 'android'], - 'id': '123456789012345678901234567892', - 'schema': 'rn-web3wallet://', - 'bundleId': 'com.walletconnect.web3wallet.rnsample', - 'universal': 'https://lab.web3modal.com/rn_walletkit', - }, - { - 'name': 'RN Wallet (internal)', - 'platform': ['ios', 'android'], - 'id': '1234567890123456789012345678922', - 'schema': 'rn-web3wallet://', - 'bundleId': 'com.walletconnect.web3wallet.rnsample.internal', - 'universal': 'https://lab.web3modal.com/rn_walletkit', - }, - { - 'name': 'Kotlin Wallet', - 'platform': ['android'], - 'id': '123456789012345678901234567893', - 'schema': 'kotlin-web3wallet://', - 'bundleId': 'com.walletconnect.sample.wallet', - 'universal': - 'https://web3modal-laboratory-git-chore-kotlin-assetlinks-walletconnect1.vercel.app/wallet_release', - }, - { - 'name': 'Kotlin Wallet (Internal)', - 'platform': ['android'], - 'id': '123456789012345678901234567894', - 'schema': 'kotlin-web3wallet://', - 'bundleId': 'com.walletconnect.sample.wallet.internal', - 'universal': - 'https://web3modal-laboratory-git-chore-kotlin-assetlinks-walletconnect1.vercel.app/wallet_internal', - }, - ]; + static List> sampleWallets(bool mr) => [ + { + 'name': 'Swift Wallet', + 'platform': ['ios'], + 'id': '123456789012345678901234567890', + 'schema': 'walletapp://', + 'bundleId': 'com.walletconnect.sample.wallet', + 'universal': 'https://lab.web3modal.com/wallet', + }, + { + 'name': 'Flutter Wallet', + 'platform': ['ios', 'android'], + 'id': '123456789012345678901234567891', + 'schema': 'wcflutterwallet://', + 'bundleId': 'com.walletconnect.flutterwallet', + 'universal': 'https://lab.web3modal.com/flutter_walletkit', + }, + { + 'name': 'Flutter Wallet (internal)', + 'platform': ['ios', 'android'], + 'id': '123456789012345678901234567895', + 'schema': 'wcflutterwallet-internal://', + 'bundleId': 'com.walletconnect.flutterwallet.internal', + 'universal': mr + ? 'https://web3modal-laboratory-git-chores-addedmore-3e0f2b-walletconnect1.vercel.app/flutter_walletkit_internal' + : 'https://dev.lab.web3modal.com/flutter_walletkit_internal', + }, + { + 'name': 'RN Wallet', + 'platform': ['ios', 'android'], + 'id': '123456789012345678901234567892', + 'schema': 'rn-web3wallet://', + 'bundleId': 'com.walletconnect.web3wallet.rnsample', + 'universal': 'https://lab.web3modal.com/rn_walletkit', + }, + { + 'name': 'RN Wallet (internal)', + 'platform': ['ios', 'android'], + 'id': '1234567890123456789012345678922', + 'schema': 'rn-web3wallet://', + 'bundleId': 'com.walletconnect.web3wallet.rnsample.internal', + 'universal': 'https://lab.web3modal.com/rn_walletkit', + }, + { + 'name': 'Kotlin Wallet', + 'platform': ['android'], + 'id': '123456789012345678901234567893', + 'schema': 'kotlin-web3wallet://', + 'bundleId': 'com.walletconnect.sample.wallet', + 'universal': + 'https://web3modal-laboratory-git-chore-kotlin-assetlinks-walletconnect1.vercel.app/wallet_release', + }, + { + 'name': 'Kotlin Wallet (Internal)', + 'platform': ['android'], + 'id': '123456789012345678901234567894', + 'schema': 'kotlin-web3wallet://', + 'bundleId': 'com.walletconnect.sample.wallet.internal', + 'universal': + 'https://web3modal-laboratory-git-chore-kotlin-assetlinks-walletconnect1.vercel.app/wallet_internal', + }, + ]; - static List> getSampleWallets() { - return sampleWallets.where((e) { + static List> getSampleWallets(bool mr) { + return sampleWallets(mr).where((e) { return (e['platform'] as List).contains(Platform.operatingSystem); }).toList(); } diff --git a/example/wallet/android/app/src/main/AndroidManifest.xml b/example/wallet/android/app/src/main/AndroidManifest.xml index 98f71ee..fe88527 100644 --- a/example/wallet/android/app/src/main/AndroidManifest.xml +++ b/example/wallet/android/app/src/main/AndroidManifest.xml @@ -70,6 +70,16 @@ + + + + + + + + + + diff --git a/example/wallet/ios/Runner/Runner.entitlements b/example/wallet/ios/Runner/Runner.entitlements index da67a55..e60b894 100644 --- a/example/wallet/ios/Runner/Runner.entitlements +++ b/example/wallet/ios/Runner/Runner.entitlements @@ -6,6 +6,7 @@ applinks:lab.web3modal.com applinks:dev.lab.web3modal.com + applinks:web3modal-laboratory-git-chores-addedmore-3e0f2b-walletconnect1.vercel.app diff --git a/example/wallet/lib/dependencies/web3wallet_service.dart b/example/wallet/lib/dependencies/web3wallet_service.dart index bf7b8bd..194cfcd 100644 --- a/example/wallet/lib/dependencies/web3wallet_service.dart +++ b/example/wallet/lib/dependencies/web3wallet_service.dart @@ -29,21 +29,24 @@ class Web3WalletService extends IWeb3WalletService { return flavor.replaceAll('-production', ''); } - String _universalLink() { - Uri link = Uri.parse('https://lab.web3modal.com/flutter_walletkit'); + String _universalLink(fromMR) { + Uri link = fromMR + ? Uri.parse( + 'https://web3modal-laboratory-git-chores-addedmore-3e0f2b-walletconnect1.vercel.app/flutter_walletkit') + : Uri.parse('https://lab.web3modal.com/flutter_walletkit'); if (_flavor.isNotEmpty) { - return link - .replace(path: '${link.path}_internal') - .replace(host: 'dev.${link.host}') - .toString(); + if (!fromMR) { + link = link.replace(host: 'dev.${link.host}'); + } + return link.replace(path: '${link.path}_internal').toString(); } return link.toString(); } - Redirect _constructRedirect() { + Redirect _constructRedirect(bool fromMR) { return Redirect( native: 'wcflutterwallet$_flavor://', - universal: _universalLink(), + universal: _universalLink(fromMR), // enable linkMode on Wallet so Dapps can use relay-less connection // universal: value must be set on cloud config as well linkMode: true, @@ -52,6 +55,8 @@ class Web3WalletService extends IWeb3WalletService { @override Future create() async { + final prefs = await SharedPreferences.getInstance(); + final fromMR = prefs.getBool('_LM_from_MR') ?? false; // Create the web3wallet _web3Wallet = Web3Wallet( core: Core( @@ -65,7 +70,7 @@ class Web3WalletService extends IWeb3WalletService { icons: [ 'https://docs.walletconnect.com/assets/images/web3walletLogo-54d3b546146931ceaf47a3500868a73a.png' ], - redirect: _constructRedirect(), + redirect: _constructRedirect(fromMR), ), ); diff --git a/example/wallet/lib/pages/settings_page.dart b/example/wallet/lib/pages/settings_page.dart index 8898a883..cea1564 100644 --- a/example/wallet/lib/pages/settings_page.dart +++ b/example/wallet/lib/pages/settings_page.dart @@ -1,5 +1,6 @@ // ignore_for_file: use_build_context_synchronously +import 'dart:io'; import 'dart:math'; import 'dart:ui'; @@ -76,6 +77,28 @@ class _SettingsPageState extends State { _Metadata(), const SizedBox(height: 20.0), const Divider(height: 1.0), + FutureBuilder( + future: SharedPreferences.getInstance(), + builder: (context, snapshot) { + if (!snapshot.hasData) { + return const SizedBox.shrink(); + } + final prefs = snapshot.data as SharedPreferences; + return Row( + children: [ + const SizedBox(width: 20.0), + const Text('LM from MR '), + Switch( + value: prefs.getBool('_LM_from_MR') ?? false, + onChanged: (value) async { + await prefs.setBool('_LM_from_MR', value); + exit(0); + }, + ), + ], + ); + }, + ), _Buttons( onRestoreFromSeed: () async { final mnemonic =