From 1a73aacabaa175eb6865934225f045c82b257662 Mon Sep 17 00:00:00 2001 From: Alfreedom <00tango.bromine@icloud.com> Date: Wed, 24 Jul 2024 14:04:27 +0200 Subject: [PATCH 1/2] Flutter dapp now uses WalletConnectModal to connect --- CHANGELOG.md | 4 + example/dapp/ios/Podfile.lock | 12 + example/dapp/lib/main.dart | 6 +- example/dapp/lib/pages/auth_page.dart | 3 +- example/dapp/lib/pages/connect_page.dart | 367 ++++++++++-------- example/dapp/lib/pages/pairings_page.dart | 3 +- example/dapp/lib/pages/sessions_page.dart | 4 +- example/dapp/lib/utils/crypto/eip155.dart | 4 +- example/dapp/lib/utils/crypto/polkadot.dart | 2 +- example/dapp/lib/utils/crypto/solana.dart | 2 +- example/dapp/lib/widgets/auth_item.dart | 3 +- example/dapp/lib/widgets/chain_button.dart | 8 +- example/dapp/lib/widgets/pairing_item.dart | 4 +- example/dapp/lib/widgets/session_item.dart | 4 +- example/dapp/lib/widgets/session_widget.dart | 4 +- example/dapp/pubspec.yaml | 7 +- .../lib/src/qr_code_scanner.dart | 2 + .../lib/src/qr_scanner_overlay_shape.dart | 2 + .../lib/src/web/flutter_qr_web.dart | 16 +- ...de_scanner_dialog_method_channel_test.dart | 2 + lib/apis/utils/walletconnect_utils.dart | 25 +- lib/src/version.dart | 2 +- pubspec.yaml | 2 +- 23 files changed, 299 insertions(+), 189 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0c5a15d1..69578656 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2.3.1-beta01 + +- Minor changes + ## 2.3.0 - One-Click Auth support diff --git a/example/dapp/ios/Podfile.lock b/example/dapp/ios/Podfile.lock index 1e98c531..8279be30 100644 --- a/example/dapp/ios/Podfile.lock +++ b/example/dapp/ios/Podfile.lock @@ -1,5 +1,9 @@ PODS: + - appcheck (1.0.3): + - Flutter - Flutter (1.0.0) + - flutter_keyboard_visibility (0.0.1): + - Flutter - package_info_plus (0.4.5): - Flutter - shared_preferences_foundation (0.0.1): @@ -9,14 +13,20 @@ PODS: - Flutter DEPENDENCIES: + - appcheck (from `.symlinks/plugins/appcheck/ios`) - Flutter (from `Flutter`) + - flutter_keyboard_visibility (from `.symlinks/plugins/flutter_keyboard_visibility/ios`) - package_info_plus (from `.symlinks/plugins/package_info_plus/ios`) - shared_preferences_foundation (from `.symlinks/plugins/shared_preferences_foundation/darwin`) - url_launcher_ios (from `.symlinks/plugins/url_launcher_ios/ios`) EXTERNAL SOURCES: + appcheck: + :path: ".symlinks/plugins/appcheck/ios" Flutter: :path: Flutter + flutter_keyboard_visibility: + :path: ".symlinks/plugins/flutter_keyboard_visibility/ios" package_info_plus: :path: ".symlinks/plugins/package_info_plus/ios" shared_preferences_foundation: @@ -25,7 +35,9 @@ EXTERNAL SOURCES: :path: ".symlinks/plugins/url_launcher_ios/ios" SPEC CHECKSUMS: + appcheck: e1ab9d4e03736f03e0401554a134d1ed502d7629 Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7 + flutter_keyboard_visibility: 0339d06371254c3eb25eeb90ba8d17dca8f9c069 package_info_plus: 58f0028419748fad15bf008b270aaa8e54380b1c shared_preferences_foundation: fcdcbc04712aee1108ac7fda236f363274528f78 url_launcher_ios: 5334b05cef931de560670eeae103fd3e431ac3fe diff --git a/example/dapp/lib/main.dart b/example/dapp/lib/main.dart index 29b1c375..50823a50 100644 --- a/example/dapp/lib/main.dart +++ b/example/dapp/lib/main.dart @@ -1,7 +1,8 @@ import 'dart:convert'; import 'dart:developer'; -import 'package:walletconnect_flutter_v2/walletconnect_flutter_v2.dart'; +import 'package:flutter/material.dart'; + import 'package:walletconnect_flutter_v2_dapp/models/chain_metadata.dart'; import 'package:walletconnect_flutter_v2_dapp/models/page_data.dart'; import 'package:walletconnect_flutter_v2_dapp/pages/auth_page.dart'; @@ -9,13 +10,14 @@ import 'package:walletconnect_flutter_v2_dapp/pages/connect_page.dart'; import 'package:walletconnect_flutter_v2_dapp/pages/pairings_page.dart'; import 'package:walletconnect_flutter_v2_dapp/pages/sessions_page.dart'; import 'package:walletconnect_flutter_v2_dapp/utils/constants.dart'; -import 'package:flutter/material.dart'; import 'package:walletconnect_flutter_v2_dapp/utils/crypto/chain_data.dart'; import 'package:walletconnect_flutter_v2_dapp/utils/crypto/helpers.dart'; import 'package:walletconnect_flutter_v2_dapp/utils/dart_defines.dart'; import 'package:walletconnect_flutter_v2_dapp/utils/string_constants.dart'; import 'package:walletconnect_flutter_v2_dapp/widgets/event_widget.dart'; +import 'package:walletconnect_flutter_v2_dapp/imports.dart'; + void main() { runApp(const MyApp()); } diff --git a/example/dapp/lib/pages/auth_page.dart b/example/dapp/lib/pages/auth_page.dart index d6c5d28e..5ec10474 100644 --- a/example/dapp/lib/pages/auth_page.dart +++ b/example/dapp/lib/pages/auth_page.dart @@ -1,7 +1,8 @@ import 'package:flutter/material.dart'; -import 'package:walletconnect_flutter_v2/walletconnect_flutter_v2.dart'; + import 'package:walletconnect_flutter_v2_dapp/utils/constants.dart'; import 'package:walletconnect_flutter_v2_dapp/widgets/auth_item.dart'; +import 'package:walletconnect_flutter_v2_dapp/imports.dart'; class AuthPage extends StatefulWidget { const AuthPage({ diff --git a/example/dapp/lib/pages/connect_page.dart b/example/dapp/lib/pages/connect_page.dart index 7c67759f..73a6e258 100644 --- a/example/dapp/lib/pages/connect_page.dart +++ b/example/dapp/lib/pages/connect_page.dart @@ -8,7 +8,7 @@ import 'package:flutter/services.dart'; import 'package:package_info_plus/package_info_plus.dart'; import 'package:qr_flutter/qr_flutter.dart'; import 'package:url_launcher/url_launcher_string.dart'; -import 'package:walletconnect_flutter_v2/walletconnect_flutter_v2.dart'; + import 'package:walletconnect_flutter_v2_dapp/models/chain_metadata.dart'; import 'package:walletconnect_flutter_v2_dapp/utils/constants.dart'; import 'package:walletconnect_flutter_v2_dapp/utils/crypto/chain_data.dart'; @@ -17,6 +17,8 @@ import 'package:walletconnect_flutter_v2_dapp/utils/crypto/polkadot.dart'; import 'package:walletconnect_flutter_v2_dapp/utils/crypto/solana.dart'; import 'package:walletconnect_flutter_v2_dapp/utils/string_constants.dart'; import 'package:walletconnect_flutter_v2_dapp/widgets/chain_button.dart'; +import 'package:walletconnect_flutter_v2_dapp/imports.dart'; +import 'package:walletconnect_modal_flutter/walletconnect_modal_flutter.dart'; class ConnectPage extends StatefulWidget { const ConnectPage({ @@ -34,10 +36,24 @@ class ConnectPageState extends State { bool _testnetOnly = false; final List _selectedChains = []; bool _shouldDismissQrCode = true; + bool _initialized = false; + late IWalletConnectModalService _walletConnectModalService; @override void initState() { super.initState(); + _initializeWCM(); + } + + Future _initializeWCM() async { + _walletConnectModalService = WalletConnectModalService( + web3App: widget.web3App, + ); + + await _walletConnectModalService.init(); + + setState(() => _initialized = true); + widget.web3App.onSessionConnect.subscribe(_onSessionConnect); } @@ -62,11 +78,10 @@ class ConnectPageState extends State { _selectedChains.add(chain); } _updateNamespaces(); - - debugPrint('[SampleDapp] ${jsonEncode(optionalNamespaces)}'); }); } + Map requiredNamespaces = {}; Map optionalNamespaces = {}; void _updateNamespaces() { @@ -101,6 +116,31 @@ class ConnectPageState extends State { events: Polkadot.events.values.toList(), ); } + + if (optionalNamespaces.isEmpty) { + requiredNamespaces = {}; + } else { + // WalletConnectModal still requires to have requiredNamespaces + // this has to be changed in that SDK + requiredNamespaces = { + 'eip155': const RequiredNamespace( + chains: ['eip155:1'], + methods: ['personal_sign', 'eth_signTransaction'], + events: ['chainChanged'], + ), + }; + } + + _walletConnectModalService.setRequiredNamespaces( + requiredNamespaces: requiredNamespaces, + ); + debugPrint( + '[SampleDapp] requiredNamespaces ${jsonEncode(requiredNamespaces)}'); + _walletConnectModalService.setOptionalNamespaces( + optionalNamespaces: optionalNamespaces, + ); + debugPrint( + '[SampleDapp] optionalNamespaces ${jsonEncode(optionalNamespaces)}'); } @override @@ -110,11 +150,15 @@ class ConnectPageState extends State { final mainChains = ChainData.allChains.where((e) => !e.isTestnet).toList(); final List chains = _testnetOnly ? testChains : mainChains; - List children = []; + final List evmChainButtons = []; + final List nonEvmChainButtons = []; + + final evmChains = chains.where((e) => e.type == ChainType.eip155); + final nonEvmChains = chains.where((e) => e.type != ChainType.eip155); - for (final ChainMetadata chain in chains) { + for (final ChainMetadata chain in evmChains) { // Build the button - children.add( + evmChainButtons.add( ChainButton( chain: chain, onPressed: () => _selectChain(chain), @@ -123,165 +167,154 @@ class ConnectPageState extends State { ); } - children.add(const SizedBox.square(dimension: 12.0)); - - // Add a connect button - children.add( - ElevatedButton( - onPressed: _selectedChains.isEmpty - ? null - : () => _onConnect(showToast: (m) async { - await showPlatformToast(child: Text(m), context: context); - }, closeModal: () { - if (Navigator.canPop(context)) { - Navigator.of(context).pop(); - } - }), - style: ButtonStyle( - backgroundColor: MaterialStateProperty.resolveWith( - (states) { - if (states.contains(MaterialState.disabled)) { - return StyleConstants.grayColor; - } - return StyleConstants.primaryColor; - }, - ), - minimumSize: MaterialStateProperty.all(const Size( - 1000.0, - StyleConstants.linear48, - )), - shape: MaterialStateProperty.all( - RoundedRectangleBorder( - borderRadius: BorderRadius.circular( - StyleConstants.linear8, - ), - ), - ), - ), - child: const Text( - StringConstants.connect, - style: StyleConstants.buttonText, + for (final ChainMetadata chain in nonEvmChains) { + // Build the button + nonEvmChainButtons.add( + ChainButton( + chain: chain, + onPressed: () => _selectChain(chain), + selected: _selectedChains.contains(chain), ), - ), - ); + ); + } - children.add(const SizedBox(height: 16.0)); - - children.add( - ElevatedButton( - onPressed: _selectedChains.isEmpty - ? null - : () => _oneClickAuth( - closeModal: () { - if (Navigator.canPop(context)) { - Navigator.of(context).pop(); - } - }, - showToast: (message) { - showPlatformToast(child: Text(message), context: context); - }, - ), - style: ButtonStyle( - backgroundColor: MaterialStateProperty.resolveWith( - (states) { - if (states.contains(MaterialState.disabled)) { - return StyleConstants.grayColor; - } - return StyleConstants.primaryColor; - }, - ), - minimumSize: MaterialStateProperty.all(const Size( - 1000.0, - StyleConstants.linear48, - )), - shape: MaterialStateProperty.all( - RoundedRectangleBorder( - borderRadius: BorderRadius.circular( - StyleConstants.linear8, - ), + return ListView( + padding: const EdgeInsets.symmetric(horizontal: StyleConstants.linear8), + children: [ + Column( + children: [ + const Text( + 'Flutter Dapp', + style: StyleConstants.subtitleText, + textAlign: TextAlign.center, ), - ), + FutureBuilder( + future: PackageInfo.fromPlatform(), + builder: (context, snapshot) { + if (!snapshot.hasData) { + return const SizedBox.shrink(); + } + final v = snapshot.data!.version; + final b = snapshot.data!.buildNumber; + const f = String.fromEnvironment('FLUTTER_APP_FLAVOR'); + return Text('$v-$f ($b) - SDK v$packageVersion'); + }, + ), + ], ), - child: const Text( - 'One-Click Auth', - style: StyleConstants.buttonText, + SizedBox( + height: StyleConstants.linear48, + child: Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + const Text( + StringConstants.testnetsOnly, + style: StyleConstants.buttonText, + ), + Switch( + value: _testnetOnly, + onChanged: (value) { + setState(() { + _selectedChains.clear(); + _testnetOnly = value; + }); + }, + ), + ], + ), ), - ), - ); - - children.add(const SizedBox.square(dimension: 12.0)); - - return Center( - child: Container( - padding: const EdgeInsets.all( - StyleConstants.linear8, + const Text('EVM Chains:', style: StyleConstants.buttonText), + const SizedBox(height: StyleConstants.linear8), + Wrap( + spacing: 10.0, + children: evmChainButtons, ), - constraints: const BoxConstraints( - maxWidth: StyleConstants.maxWidth, + const Divider(), + const Text('Non EVM Chains:', style: StyleConstants.buttonText), + Wrap( + spacing: 10.0, + children: nonEvmChainButtons, ), - child: ListView( - children: [ - Column( - children: [ - const Text( - 'Flutter Dapp', - style: StyleConstants.subtitleText, - textAlign: TextAlign.center, - ), - FutureBuilder( - future: PackageInfo.fromPlatform(), - builder: (context, snapshot) { - if (!snapshot.hasData) { - return const SizedBox.shrink(); - } - final v = snapshot.data!.version; - final b = snapshot.data!.buildNumber; - const f = String.fromEnvironment('FLUTTER_APP_FLAVOR'); - return Text('$v-$f ($b) - SDK v$packageVersion'); - }, - ), - ], - ), - const SizedBox( - height: StyleConstants.linear16, - ), + const Divider(), + if (_initialized) + Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const SizedBox(height: StyleConstants.linear8), + const Text( + 'Use WalletConnectModal:', + style: StyleConstants.buttonText, + ), + const SizedBox(height: StyleConstants.linear8), + WalletConnectModalConnect( + service: _walletConnectModalService, + width: double.infinity, + height: 50.0, + ), + ], + ), + const SizedBox(height: StyleConstants.linear8), + const Divider(), + Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const SizedBox(height: StyleConstants.linear8), const Text( - StringConstants.selectChains, - style: StyleConstants.paragraph, - textAlign: TextAlign.center, - ), - const SizedBox( - height: StyleConstants.linear8, + 'Use custom connection:', + style: StyleConstants.buttonText, ), + const SizedBox(height: StyleConstants.linear8), SizedBox( - height: StyleConstants.linear48, - child: Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - const Text( - StringConstants.testnetsOnly, - style: StyleConstants.buttonText, - ), - Switch( - value: _testnetOnly, - onChanged: (value) { - setState(() { - _selectedChains.clear(); - _testnetOnly = value; - }); - }, - ), - ], + width: double.infinity, + child: ElevatedButton( + style: _buttonStyle, + onPressed: _selectedChains.isEmpty + ? null + : () => _onConnect( + showToast: (m) async { + await showPlatformToast( + child: Text(m), context: context); + }, + closeModal: () { + if (Navigator.canPop(context)) { + Navigator.of(context).pop(); + } + }, + ), + child: const Text( + StringConstants.connect, + style: StyleConstants.buttonText, + ), ), ), - Column( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.center, - children: children, + const SizedBox(height: StyleConstants.linear8), + SizedBox( + width: double.infinity, + child: ElevatedButton( + style: _buttonStyle, + onPressed: _selectedChains.isEmpty + ? null + : () => _oneClickAuth( + closeModal: () { + if (Navigator.canPop(context)) { + Navigator.of(context).pop(); + } + }, + showToast: (message) { + showPlatformToast( + child: Text(message), context: context); + }, + ), + child: const Text( + 'One-Click Auth', + style: StyleConstants.buttonText, + ), + ), ), ], ), - ), + const SizedBox(height: StyleConstants.linear16), + ], ); } @@ -307,6 +340,7 @@ class ConnectPageState extends State { // It is currently safer to send chains approvals on optionalNamespaces // but depending on Wallet implementation you may need to send some (for innstance eip155:1) as required final connectResponse = await widget.web3App.connect( + requiredNamespaces: requiredNamespaces, optionalNamespaces: optionalNamespaces, ); @@ -432,7 +466,7 @@ class ConnectPageState extends State { final authResponse = await widget.web3App.requestAuth( pairingTopic: pairingTopic, params: AuthRequestParams( - chainId: _selectedChains[0].chainId, + chainId: 'eip155:1', domain: Constants.domain, aud: Constants.aud, statement: 'Welcome to example flutter app', @@ -464,7 +498,8 @@ class ConnectPageState extends State { VoidCallback? closeModal, Function(String message)? showToast, }) async { - final methods = optionalNamespaces['eip155']?.methods ?? []; + final methods1 = requiredNamespaces['eip155']?.methods ?? []; + final methods2 = optionalNamespaces['eip155']?.methods ?? []; const flavor = String.fromEnvironment('FLUTTER_APP_FLAVOR'); final authResponse = await widget.web3App.authenticate( params: SessionAuthRequestParams( @@ -473,7 +508,7 @@ class ConnectPageState extends State { nonce: AuthUtils.generateNonce(), uri: Constants.aud, statement: 'Welcome to example flutter app', - methods: methods, + methods: {...methods1, ...methods2}.toList(), ), ); @@ -531,6 +566,10 @@ class ConnectPageState extends State { void _onSessionConnect(SessionConnect? event) async { if (event == null) return; + setState(() { + _selectedChains.clear(); + }); + if (_shouldDismissQrCode && Navigator.canPop(context)) { _shouldDismissQrCode = false; Navigator.pop(context); @@ -543,6 +582,28 @@ class ConnectPageState extends State { }, ); } + + ButtonStyle get _buttonStyle => ButtonStyle( + backgroundColor: MaterialStateProperty.resolveWith( + (states) { + if (states.contains(MaterialState.disabled)) { + return StyleConstants.grayColor; + } + return StyleConstants.primaryColor; + }, + ), + minimumSize: MaterialStateProperty.all(const Size( + 1000.0, + StyleConstants.linear48, + )), + shape: MaterialStateProperty.all( + RoundedRectangleBorder( + borderRadius: BorderRadius.circular( + StyleConstants.linear8, + ), + ), + ), + ); } class QRCodeScreen extends StatefulWidget { diff --git a/example/dapp/lib/pages/pairings_page.dart b/example/dapp/lib/pages/pairings_page.dart index 4a58f75a..eb5be822 100644 --- a/example/dapp/lib/pages/pairings_page.dart +++ b/example/dapp/lib/pages/pairings_page.dart @@ -1,8 +1,9 @@ import 'package:flutter/material.dart'; -import 'package:walletconnect_flutter_v2/walletconnect_flutter_v2.dart'; + import 'package:walletconnect_flutter_v2_dapp/utils/constants.dart'; import 'package:walletconnect_flutter_v2_dapp/utils/string_constants.dart'; import 'package:walletconnect_flutter_v2_dapp/widgets/pairing_item.dart'; +import 'package:walletconnect_flutter_v2_dapp/imports.dart'; class PairingsPage extends StatefulWidget { const PairingsPage({ diff --git a/example/dapp/lib/pages/sessions_page.dart b/example/dapp/lib/pages/sessions_page.dart index 8309e730..eea88085 100644 --- a/example/dapp/lib/pages/sessions_page.dart +++ b/example/dapp/lib/pages/sessions_page.dart @@ -1,10 +1,12 @@ import 'package:flutter/material.dart'; -import 'package:walletconnect_flutter_v2/walletconnect_flutter_v2.dart'; + import 'package:walletconnect_flutter_v2_dapp/utils/constants.dart'; import 'package:walletconnect_flutter_v2_dapp/utils/string_constants.dart'; import 'package:walletconnect_flutter_v2_dapp/widgets/session_item.dart'; import 'package:walletconnect_flutter_v2_dapp/widgets/session_widget.dart'; +import 'package:walletconnect_flutter_v2_dapp/imports.dart'; + class SessionsPage extends StatefulWidget { const SessionsPage({ super.key, diff --git a/example/dapp/lib/utils/crypto/eip155.dart b/example/dapp/lib/utils/crypto/eip155.dart index f5ce4dd0..6114c974 100644 --- a/example/dapp/lib/utils/crypto/eip155.dart +++ b/example/dapp/lib/utils/crypto/eip155.dart @@ -2,13 +2,13 @@ import 'dart:convert'; // ignore: depend_on_referenced_packages import 'package:convert/convert.dart'; -import 'package:intl/intl.dart'; -import 'package:walletconnect_flutter_v2/walletconnect_flutter_v2.dart'; import 'package:walletconnect_flutter_v2_dapp/models/chain_metadata.dart'; import 'package:walletconnect_flutter_v2_dapp/utils/crypto/chain_data.dart'; import 'package:walletconnect_flutter_v2_dapp/utils/smart_contracts.dart'; import 'package:walletconnect_flutter_v2_dapp/utils/test_data.dart'; +import 'package:walletconnect_flutter_v2_dapp/imports.dart'; + enum EIP155Methods { personalSign, ethSign, diff --git a/example/dapp/lib/utils/crypto/polkadot.dart b/example/dapp/lib/utils/crypto/polkadot.dart index de4ece79..2342f6df 100644 --- a/example/dapp/lib/utils/crypto/polkadot.dart +++ b/example/dapp/lib/utils/crypto/polkadot.dart @@ -1,4 +1,4 @@ -import 'package:walletconnect_flutter_v2/walletconnect_flutter_v2.dart'; +import 'package:walletconnect_flutter_v2_dapp/imports.dart'; enum PolkadotMethods { polkadotSignTransaction, diff --git a/example/dapp/lib/utils/crypto/solana.dart b/example/dapp/lib/utils/crypto/solana.dart index 9f001c1e..241309f3 100644 --- a/example/dapp/lib/utils/crypto/solana.dart +++ b/example/dapp/lib/utils/crypto/solana.dart @@ -2,8 +2,8 @@ import 'dart:convert'; // ignore: depend_on_referenced_packages import 'package:bs58/bs58.dart'; -import 'package:walletconnect_flutter_v2/walletconnect_flutter_v2.dart'; import 'package:walletconnect_flutter_v2_dapp/models/chain_metadata.dart'; +import 'package:walletconnect_flutter_v2_dapp/imports.dart'; enum SolanaMethods { solanaSignTransaction, diff --git a/example/dapp/lib/widgets/auth_item.dart b/example/dapp/lib/widgets/auth_item.dart index df27fd61..bd5372d9 100644 --- a/example/dapp/lib/widgets/auth_item.dart +++ b/example/dapp/lib/widgets/auth_item.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; -import 'package:walletconnect_flutter_v2/walletconnect_flutter_v2.dart'; + import 'package:walletconnect_flutter_v2_dapp/utils/constants.dart'; +import 'package:walletconnect_flutter_v2_dapp/imports.dart'; class AuthItem extends StatelessWidget { const AuthItem({ diff --git a/example/dapp/lib/widgets/chain_button.dart b/example/dapp/lib/widgets/chain_button.dart index 64c2eafd..c98b277e 100644 --- a/example/dapp/lib/widgets/chain_button.dart +++ b/example/dapp/lib/widgets/chain_button.dart @@ -17,7 +17,7 @@ class ChainButton extends StatelessWidget { @override Widget build(BuildContext context) { return Container( - width: double.infinity, + width: (MediaQuery.of(context).size.width / 2) - 14.0, height: StyleConstants.linear48, margin: const EdgeInsets.symmetric( vertical: StyleConstants.linear8, @@ -26,13 +26,13 @@ class ChainButton extends StatelessWidget { onPressed: onPressed, style: ButtonStyle( backgroundColor: MaterialStateProperty.all( - Colors.white, + selected ? Colors.grey.shade400 : Colors.white, ), shape: MaterialStateProperty.all( RoundedRectangleBorder( side: BorderSide( - color: chain.color, - width: selected ? 6 : 2, + color: selected ? Colors.grey.shade400 : chain.color, + width: selected ? 4 : 2, ), borderRadius: BorderRadius.circular( StyleConstants.linear8, diff --git a/example/dapp/lib/widgets/pairing_item.dart b/example/dapp/lib/widgets/pairing_item.dart index 74e1f1b2..4ed2dd02 100644 --- a/example/dapp/lib/widgets/pairing_item.dart +++ b/example/dapp/lib/widgets/pairing_item.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; -import 'package:intl/intl.dart'; -import 'package:walletconnect_flutter_v2/walletconnect_flutter_v2.dart'; + import 'package:walletconnect_flutter_v2_dapp/utils/constants.dart'; +import 'package:walletconnect_flutter_v2_dapp/imports.dart'; class PairingItem extends StatelessWidget { const PairingItem({ diff --git a/example/dapp/lib/widgets/session_item.dart b/example/dapp/lib/widgets/session_item.dart index 93a42531..f8dcb257 100644 --- a/example/dapp/lib/widgets/session_item.dart +++ b/example/dapp/lib/widgets/session_item.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; -import 'package:intl/intl.dart'; -import 'package:walletconnect_flutter_v2/walletconnect_flutter_v2.dart'; + import 'package:walletconnect_flutter_v2_dapp/utils/constants.dart'; +import 'package:walletconnect_flutter_v2_dapp/imports.dart'; class SessionItem extends StatelessWidget { const SessionItem({ diff --git a/example/dapp/lib/widgets/session_widget.dart b/example/dapp/lib/widgets/session_widget.dart index ee145372..1f20a008 100644 --- a/example/dapp/lib/widgets/session_widget.dart +++ b/example/dapp/lib/widgets/session_widget.dart @@ -1,7 +1,7 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:url_launcher/url_launcher_string.dart'; -import 'package:walletconnect_flutter_v2/walletconnect_flutter_v2.dart'; + import 'package:walletconnect_flutter_v2_dapp/models/chain_metadata.dart'; import 'package:walletconnect_flutter_v2_dapp/utils/constants.dart'; import 'package:walletconnect_flutter_v2_dapp/utils/crypto/eip155.dart'; @@ -11,6 +11,8 @@ import 'package:walletconnect_flutter_v2_dapp/utils/crypto/solana.dart'; import 'package:walletconnect_flutter_v2_dapp/utils/string_constants.dart'; import 'package:walletconnect_flutter_v2_dapp/widgets/method_dialog.dart'; +import 'package:walletconnect_flutter_v2_dapp/imports.dart'; + class SessionWidget extends StatefulWidget { const SessionWidget({ super.key, diff --git a/example/dapp/pubspec.yaml b/example/dapp/pubspec.yaml index eae8d8d7..22b8077c 100644 --- a/example/dapp/pubspec.yaml +++ b/example/dapp/pubspec.yaml @@ -17,10 +17,11 @@ dependencies: json_annotation: ^4.8.1 fl_toast: ^3.1.0 url_launcher: ^6.2.2 - intl: ^0.19.0 + # intl: ^0.19.0 package_info_plus: ^7.0.0 - walletconnect_flutter_v2: - path: ../.. + walletconnect_modal_flutter: ^2.1.19 + # walletconnect_flutter_v2: + # path: ../.. dev_dependencies: flutter_test: diff --git a/example/wallet/packages/qr-bar-code-scanner-dialog/packages/qr_code_scanner/lib/src/qr_code_scanner.dart b/example/wallet/packages/qr-bar-code-scanner-dialog/packages/qr_code_scanner/lib/src/qr_code_scanner.dart index 0a1deb3a..d92c75d1 100644 --- a/example/wallet/packages/qr-bar-code-scanner-dialog/packages/qr_code_scanner/lib/src/qr_code_scanner.dart +++ b/example/wallet/packages/qr-bar-code-scanner-dialog/packages/qr_code_scanner/lib/src/qr_code_scanner.dart @@ -1,3 +1,5 @@ +// ignore_for_file: no_leading_underscores_for_local_identifiers + import 'dart:async'; import 'package:flutter/foundation.dart'; diff --git a/example/wallet/packages/qr-bar-code-scanner-dialog/packages/qr_code_scanner/lib/src/qr_scanner_overlay_shape.dart b/example/wallet/packages/qr-bar-code-scanner-dialog/packages/qr_code_scanner/lib/src/qr_scanner_overlay_shape.dart index 83fc5efc..2d251621 100644 --- a/example/wallet/packages/qr-bar-code-scanner-dialog/packages/qr_code_scanner/lib/src/qr_scanner_overlay_shape.dart +++ b/example/wallet/packages/qr-bar-code-scanner-dialog/packages/qr_code_scanner/lib/src/qr_scanner_overlay_shape.dart @@ -1,3 +1,5 @@ +// ignore_for_file: no_leading_underscores_for_local_identifiers + import 'dart:math'; import 'package:flutter/material.dart'; diff --git a/example/wallet/packages/qr-bar-code-scanner-dialog/packages/qr_code_scanner/lib/src/web/flutter_qr_web.dart b/example/wallet/packages/qr-bar-code-scanner-dialog/packages/qr_code_scanner/lib/src/web/flutter_qr_web.dart index de368ace..ba6f5fe7 100644 --- a/example/wallet/packages/qr-bar-code-scanner-dialog/packages/qr_code_scanner/lib/src/web/flutter_qr_web.dart +++ b/example/wallet/packages/qr-bar-code-scanner-dialog/packages/qr_code_scanner/lib/src/web/flutter_qr_web.dart @@ -1,4 +1,4 @@ -// ignore_for_file: avoid_web_libraries_in_flutter +// ignore_for_file: avoid_web_libraries_in_flutter, library_private_types_in_public_api import 'dart:async'; import 'dart:core'; @@ -23,12 +23,12 @@ class WebQrView extends StatefulWidget { final PermissionSetCallback? onPermissionSet; final CameraFacing? cameraFacing; - const WebQrView( - {Key? key, - required this.onPlatformViewCreated, - this.onPermissionSet, - this.cameraFacing = CameraFacing.front}) - : super(key: key); + const WebQrView({ + Key? key, + required this.onPlatformViewCreated, + this.onPermissionSet, + this.cameraFacing = CameraFacing.front, + }) : super(key: key); @override _WebQrViewState createState() => _WebQrViewState(); @@ -64,7 +64,7 @@ class _WebQrViewState extends State { String? code; String? _errorMsg; html.VideoElement video = html.VideoElement(); - String viewID = 'QRVIEW-' + DateTime.now().millisecondsSinceEpoch.toString(); + String viewID = 'QRVIEW-${DateTime.now().millisecondsSinceEpoch}'; final StreamController _scanUpdateController = StreamController(); diff --git a/example/wallet/packages/qr-bar-code-scanner-dialog/test/qr_bar_code_scanner_dialog_method_channel_test.dart b/example/wallet/packages/qr-bar-code-scanner-dialog/test/qr_bar_code_scanner_dialog_method_channel_test.dart index 1f72e4aa..6914ffb1 100644 --- a/example/wallet/packages/qr-bar-code-scanner-dialog/test/qr_bar_code_scanner_dialog_method_channel_test.dart +++ b/example/wallet/packages/qr-bar-code-scanner-dialog/test/qr_bar_code_scanner_dialog_method_channel_test.dart @@ -1,3 +1,5 @@ +// ignore_for_file: deprecated_member_use + import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:qr_bar_code_scanner_dialog/qr_bar_code_scanner_dialog_method_channel.dart'; diff --git a/lib/apis/utils/walletconnect_utils.dart b/lib/apis/utils/walletconnect_utils.dart index 901b26f2..06e231cf 100644 --- a/lib/apis/utils/walletconnect_utils.dart +++ b/lib/apis/utils/walletconnect_utils.dart @@ -91,14 +91,31 @@ class WalletConnectUtils { }) { final Uri uri = Uri.parse(relayUrl); final Map queryParams = Uri.splitQueryString(uri.query); - String ua = formatUA(protocol, version, sdkVersion); + final userAgent = formatUA(protocol, version, sdkVersion); + // Add basic query params final Map relayParams = { 'auth': auth, - if ((projectId ?? '').isNotEmpty) 'projectId': projectId!, - 'ua': ua, - if ((packageName ?? '').isNotEmpty) 'origin': packageName!, + 'ua': userAgent, }; + + // Add projectId query param + if ((projectId ?? '').isNotEmpty) { + relayParams['projectId'] = projectId!; + } + + // Add bundleId, packageName or origin query param based on platform + if ((packageName ?? '').isNotEmpty) { + final platform = getId(); + if (platform == 'ios') { + relayParams['bundleId'] = packageName!; + } else if (platform == 'android') { + relayParams['packageName'] = packageName!; + } else { + relayParams['origin'] = packageName!; + } + } + queryParams.addAll(relayParams); return uri.replace(queryParameters: queryParams).toString(); } diff --git a/lib/src/version.dart b/lib/src/version.dart index 36925912..bc803013 100644 --- a/lib/src/version.dart +++ b/lib/src/version.dart @@ -1,2 +1,2 @@ // Generated code. Do not modify. -const packageVersion = '2.3.0'; +const packageVersion = '2.3.1-beta01'; diff --git a/pubspec.yaml b/pubspec.yaml index d35f5742..0ab97857 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: walletconnect_flutter_v2 description: WalletConnect's official Dart library v2 for WalletKit and AppKit. The communications protocol for web3. -version: 2.3.0 +version: 2.3.1-beta01 repository: https://github.com/WalletConnect/WalletConnectFlutterV2 environment: From e2219979a206bf11364d358a0e15ab713d120058 Mon Sep 17 00:00:00 2001 From: Alfreedom <00tango.bromine@icloud.com> Date: Wed, 24 Jul 2024 14:07:07 +0200 Subject: [PATCH 2/2] Flutter dapp now uses WalletConnectModal to connect --- example/dapp/lib/imports.dart | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 example/dapp/lib/imports.dart diff --git a/example/dapp/lib/imports.dart b/example/dapp/lib/imports.dart new file mode 100644 index 00000000..545d42a0 --- /dev/null +++ b/example/dapp/lib/imports.dart @@ -0,0 +1,4 @@ +// ignore_for_file: depend_on_referenced_packages + +export 'package:walletconnect_flutter_v2/walletconnect_flutter_v2.dart'; +export 'package:intl/intl.dart';