Skip to content

Commit

Permalink
added linkmode from merge request
Browse files Browse the repository at this point in the history
  • Loading branch information
quetool committed Aug 27, 2024
1 parent 17237f0 commit 6673f8c
Show file tree
Hide file tree
Showing 9 changed files with 159 additions and 89 deletions.
10 changes: 10 additions & 0 deletions example/dapp/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,16 @@
<data android:host="dev.lab.web3modal.com" />
<data android:pathPattern="/flutter_appkit_internal" />
</intent-filter>
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

<data android:scheme="https" />
<data android:host="web3modal-laboratory-git-chores-addedmore-3e0f2b-walletconnect1.vercel.app" />
<data android:pathPattern="/flutter_appkit_internal" />
</intent-filter>
</activity>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
Expand Down
1 change: 1 addition & 0 deletions example/dapp/ios/Runner/Runner.entitlements
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<array>
<string>applinks:lab.web3modal.com</string>
<string>applinks:dev.lab.web3modal.com</string>
<string>applinks:web3modal-laboratory-git-chores-addedmore-3e0f2b-walletconnect1.vercel.app</string>
</array>
</dict>
</plist>
23 changes: 14 additions & 9 deletions example/dapp/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,28 +67,33 @@ class _MyHomePageState extends State<MyHomePage> {
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,
);
}

Future<void> initialize() async {
final prefs = await SharedPreferences.getInstance();
final fromMR = prefs.getBool('_LM_from_MR') ?? false;
_web3App = Web3App(
core: Core(
projectId: DartDefines.projectId,
Expand All @@ -101,7 +106,7 @@ class _MyHomePageState extends State<MyHomePage> {
icons: [
'https://images.prismic.io/wallet-connect/65785a56531ac2845a260732_WalletConnect-App-Logo-1024X1024.png'
],
redirect: _constructRedirect(),
redirect: _constructRedirect(fromMR),
),
);

Expand Down
31 changes: 22 additions & 9 deletions example/dapp/lib/pages/connect_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -35,6 +36,7 @@ class ConnectPage extends StatefulWidget {

class ConnectPageState extends State<ConnectPage> {
bool _testnetOnly = false;
bool _testFromMR = true;
final List<ChainMetadata> _selectedChains = [];
bool _shouldDismissQrCode = true;
bool _initialized = false;
Expand All @@ -53,6 +55,9 @@ class ConnectPageState extends State<ConnectPage> {

await _walletConnectModalService.init();

final prefs = await SharedPreferences.getInstance();
_testFromMR = prefs.getBool('_LM_from_MR') ?? false;

setState(() => _initialized = true);

widget.web3App.onSessionConnect.subscribe(_onSessionConnect);
Expand All @@ -64,13 +69,6 @@ class ConnectPageState extends State<ConnectPage> {
super.dispose();
}

void setTestnet(bool value) {
if (value != _testnetOnly) {
_selectedChains.clear();
}
_testnetOnly = value;
}

void _selectChain(ChainMetadata chain) {
setState(() {
if (_selectedChains.contains(chain)) {
Expand Down Expand Up @@ -206,6 +204,19 @@ class ConnectPageState extends State<ConnectPage> {
});
},
),
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);
},
),
],
),
),
Expand Down Expand Up @@ -253,7 +264,8 @@ class ConnectPageState extends State<ConnectPage> {
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(
Expand Down Expand Up @@ -294,7 +306,8 @@ class ConnectPageState extends State<ConnectPage> {
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(
Expand Down
126 changes: 64 additions & 62 deletions example/dapp/lib/utils/sample_wallets.dart
Original file line number Diff line number Diff line change
@@ -1,69 +1,71 @@
import 'dart:io';

class WCSampleWallets {
static final List<Map<String, dynamic>> 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<Map<String, dynamic>> 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<Map<String, dynamic>> getSampleWallets() {
return sampleWallets.where((e) {
static List<Map<String, dynamic>> getSampleWallets(bool mr) {
return sampleWallets(mr).where((e) {
return (e['platform'] as List<String>).contains(Platform.operatingSystem);
}).toList();
}
Expand Down
10 changes: 10 additions & 0 deletions example/wallet/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,16 @@
<data android:host="dev.lab.web3modal.com" />
<data android:pathPattern="/flutter_walletkit_internal" />
</intent-filter>
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

<data android:scheme="https" />
<data android:host="web3modal-laboratory-git-chores-addedmore-3e0f2b-walletconnect1.vercel.app" />
<data android:pathPattern="/flutter_walletkit_internal" />
</intent-filter>
</activity>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
Expand Down
1 change: 1 addition & 0 deletions example/wallet/ios/Runner/Runner.entitlements
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<array>
<string>applinks:lab.web3modal.com</string>
<string>applinks:dev.lab.web3modal.com</string>
<string>applinks:web3modal-laboratory-git-chores-addedmore-3e0f2b-walletconnect1.vercel.app</string>
</array>
</dict>
</plist>
23 changes: 14 additions & 9 deletions example/wallet/lib/dependencies/web3wallet_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -52,6 +55,8 @@ class Web3WalletService extends IWeb3WalletService {

@override
Future<void> create() async {
final prefs = await SharedPreferences.getInstance();
final fromMR = prefs.getBool('_LM_from_MR') ?? false;
// Create the web3wallet
_web3Wallet = Web3Wallet(
core: Core(
Expand All @@ -65,7 +70,7 @@ class Web3WalletService extends IWeb3WalletService {
icons: [
'https://docs.walletconnect.com/assets/images/web3walletLogo-54d3b546146931ceaf47a3500868a73a.png'
],
redirect: _constructRedirect(),
redirect: _constructRedirect(fromMR),
),
);

Expand Down
Loading

0 comments on commit 6673f8c

Please sign in to comment.