diff --git a/CHANGELOG.md b/CHANGELOG.md
index 93a7371e..b3af0266 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,7 @@
+## 3.2.2
+
+- Network change improvements
+
## 3.2.1
- Email Wallet improvements:
diff --git a/example/android/gradle.properties b/example/android/gradle.properties
index 1402382c..9c491cd5 100644
--- a/example/android/gradle.properties
+++ b/example/android/gradle.properties
@@ -1,5 +1,5 @@
org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true
android.enableJetifier=true
-versionName=3.2.1
-versionCode=59
+versionName=3.2.2
+versionCode=61
diff --git a/example/ios/Runner.xcodeproj/project.pbxproj b/example/ios/Runner.xcodeproj/project.pbxproj
index 2e28c337..71a9021d 100644
--- a/example/ios/Runner.xcodeproj/project.pbxproj
+++ b/example/ios/Runner.xcodeproj/project.pbxproj
@@ -470,7 +470,7 @@
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
CODE_SIGN_STYLE = Manual;
- CURRENT_PROJECT_VERSION = 59;
+ CURRENT_PROJECT_VERSION = 61;
DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = W5R8AG9K22;
ENABLE_BITCODE = NO;
@@ -496,7 +496,7 @@
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
CODE_SIGN_STYLE = Automatic;
- CURRENT_PROJECT_VERSION = 59;
+ CURRENT_PROJECT_VERSION = 61;
GENERATE_INFOPLIST_FILE = YES;
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = com.web3modal.flutterExample.RunnerTests;
@@ -514,7 +514,7 @@
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
CODE_SIGN_STYLE = Automatic;
- CURRENT_PROJECT_VERSION = 59;
+ CURRENT_PROJECT_VERSION = 61;
GENERATE_INFOPLIST_FILE = YES;
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = com.web3modal.flutterExample.RunnerTests;
@@ -530,7 +530,7 @@
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
CODE_SIGN_STYLE = Automatic;
- CURRENT_PROJECT_VERSION = 59;
+ CURRENT_PROJECT_VERSION = 61;
GENERATE_INFOPLIST_FILE = YES;
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = com.web3modal.flutterExample.RunnerTests;
@@ -655,7 +655,7 @@
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
CODE_SIGN_STYLE = Manual;
- CURRENT_PROJECT_VERSION = 59;
+ CURRENT_PROJECT_VERSION = 61;
DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = W5R8AG9K22;
ENABLE_BITCODE = NO;
@@ -686,7 +686,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution";
CODE_SIGN_STYLE = Manual;
- CURRENT_PROJECT_VERSION = 59;
+ CURRENT_PROJECT_VERSION = 61;
DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = W5R8AG9K22;
ENABLE_BITCODE = NO;
diff --git a/example/ios/Runner/Info.plist b/example/ios/Runner/Info.plist
index 7aa9cdcc..a0ec3ffc 100644
--- a/example/ios/Runner/Info.plist
+++ b/example/ios/Runner/Info.plist
@@ -19,7 +19,7 @@
CFBundlePackageType
APPL
CFBundleShortVersionString
- 3.2.1
+ 3.2.2
CFBundleSignature
????
CFBundleURLTypes
@@ -36,7 +36,7 @@
CFBundleVersion
- 59
+ 61
ITSAppUsesNonExemptEncryption
LSApplicationQueriesSchemes
diff --git a/example/lib/home_page.dart b/example/lib/home_page.dart
index d1ed4b0f..9c768ec9 100644
--- a/example/lib/home_page.dart
+++ b/example/lib/home_page.dart
@@ -171,13 +171,13 @@ class _MyHomePageState extends State {
ElevatedButton(
onPressed: () async {
_w3mService.launchConnectedWallet();
- _w3mService.requestAddChain(polygon).then(
- (value) {
- final success = value == true;
- debugPrint('[ExampleApp] then success $success');
- Navigator.of(context).pop();
- },
- );
+ try {
+ await _w3mService.requestSwitchToChain(polygon);
+ } catch (e) {
+ debugPrint('[ExampleApp] requestSwitchToChain $e');
+ }
+ // ignore: use_build_context_synchronously
+ Navigator.of(context).pop();
},
child: const Text('Switch'),
),
diff --git a/example/pubspec.lock b/example/pubspec.lock
index 46e1fba1..7946a7b8 100644
--- a/example/pubspec.lock
+++ b/example/pubspec.lock
@@ -1139,7 +1139,7 @@ packages:
path: ".."
relative: true
source: path
- version: "3.2.1"
+ version: "3.2.2"
web_socket_channel:
dependency: transitive
description:
diff --git a/example/pubspec.yaml b/example/pubspec.yaml
index 04d81ddb..99e1c1a9 100644
--- a/example/pubspec.yaml
+++ b/example/pubspec.yaml
@@ -3,7 +3,7 @@ description: A dApp showing how to use WalletConnect v2 with Flutter
publish_to: "none"
-version: 3.2.1
+version: 3.2.2
environment:
sdk: ">=3.0.1 <4.0.0"
diff --git a/lib/pages/connet_network_page.dart b/lib/pages/connet_network_page.dart
index b4f1fc38..3681cc56 100644
--- a/lib/pages/connet_network_page.dart
+++ b/lib/pages/connet_network_page.dart
@@ -39,22 +39,25 @@ class _ConnectNetworkPageState extends State
WidgetsBinding.instance.addPostFrameCallback((_) {
_service = Web3ModalProvider.of(context).service;
_service?.onModalError.subscribe(_errorListener);
- _service!.web3App!.onSessionEvent.subscribe(_onSessionEvent);
- _service!.web3App!.core.relayClient.onRelayClientMessage.subscribe(
- _onRelayClientMessage,
- );
setState(() {});
- Future.delayed(const Duration(milliseconds: 300), () {
- _connect();
- });
+ Future.delayed(const Duration(milliseconds: 300), () => _connect());
});
}
- void _connect() {
+ void _connect() async {
errorEvent = null;
_service!.launchConnectedWallet();
- _service!.requestSwitchToChain(widget.chainInfo);
- setState(() {});
+ try {
+ await _service!.requestSwitchToChain(widget.chainInfo);
+ final chainId = widget.chainInfo.chainId;
+ if (W3MChainPresets.chains.containsKey(chainId)) {
+ Future.delayed(const Duration(milliseconds: 300), () {
+ widgetStack.instance.pop();
+ });
+ }
+ } catch (e) {
+ setState(() {});
+ }
}
@override
@@ -68,38 +71,10 @@ class _ConnectNetworkPageState extends State
}
}
- void _onSessionEvent(SessionEvent? event) async {
- if (!mounted) return;
- if (event?.name == EventsConstants.chainChanged) {
- debugPrint('[$runtimeType] _onSessionEvent $event');
- final chainId = event?.data.toString() ?? '';
- if (W3MChainPresets.chains.containsKey(chainId)) {
- _service?.web3App?.onSessionEvent.unsubscribe(_onSessionEvent);
- widgetStack.instance.pop();
- }
- }
- }
-
- void _onRelayClientMessage(MessageEvent? event) async {
- if (!mounted) return;
- if (event != null) {
- final payloadString = await _service!.web3App!.core.crypto.decode(
- event.topic,
- event.message,
- );
- if (payloadString == null) return;
- debugPrint('[$runtimeType] payloadString $payloadString');
- }
- }
-
void _errorListener(ModalError? event) => setState(() => errorEvent = event);
@override
void dispose() {
- _service?.web3App?.core.relayClient.onRelayClientMessage.unsubscribe(
- _onRelayClientMessage,
- );
- _service?.web3App?.onSessionEvent.unsubscribe(_onSessionEvent);
_service?.onModalError.unsubscribe(_errorListener);
WidgetsBinding.instance.removeObserver(this);
super.dispose();
diff --git a/lib/pages/select_network_page.dart b/lib/pages/select_network_page.dart
index 82794db0..aaf797a8 100644
--- a/lib/pages/select_network_page.dart
+++ b/lib/pages/select_network_page.dart
@@ -22,17 +22,15 @@ class SelectNetworkPage extends StatelessWidget {
final Function(W3MChainInfo)? onTapNetwork;
- void _onSelectNetwork(BuildContext context, W3MChainInfo chainInfo) {
+ void _onSelectNetwork(BuildContext context, W3MChainInfo chainInfo) async {
final service = Web3ModalProvider.of(context).service;
if (service.isConnected) {
final approvedChains = service.session!.getApprovedChains() ?? [];
- final hasChainAlready = approvedChains.contains(
- chainInfo.namespace,
- );
+ final isChainApproved = approvedChains.contains(chainInfo.namespace);
if (chainInfo.chainId == service.selectedChain?.chainId) {
widgetStack.instance.pop();
- } else if (hasChainAlready || service.session!.sessionService.isMagic) {
- service.selectChain(chainInfo, switchChain: true);
+ } else if (isChainApproved || service.session!.sessionService.isMagic) {
+ await service.selectChain(chainInfo, switchChain: true);
widgetStack.instance.pop();
} else {
widgetStack.instance.push(ConnectNetworkPage(chainInfo: chainInfo));
diff --git a/lib/services/w3m_service/i_w3m_service.dart b/lib/services/w3m_service/i_w3m_service.dart
index a73d4183..2e50c068 100644
--- a/lib/services/w3m_service/i_w3m_service.dart
+++ b/lib/services/w3m_service/i_w3m_service.dart
@@ -131,8 +131,8 @@ abstract class IW3MService with ChangeNotifier {
required SessionRequestParams request,
});
- Future requestSwitchToChain(W3MChainInfo newChain);
- Future requestAddChain(W3MChainInfo newChain);
+ Future requestSwitchToChain(W3MChainInfo newChain);
+ Future requestAddChain(W3MChainInfo newChain);
/// Closes the modal.
void closeModal();
diff --git a/lib/services/w3m_service/w3m_service.dart b/lib/services/w3m_service/w3m_service.dart
index 045b232f..e8747a87 100644
--- a/lib/services/w3m_service/w3m_service.dart
+++ b/lib/services/w3m_service/w3m_service.dart
@@ -1108,15 +1108,16 @@ class W3MService with ChangeNotifier, CoinbaseService implements IW3MService {
}
@override
- Future requestSwitchToChain(W3MChainInfo newChain) async {
+ Future requestSwitchToChain(W3MChainInfo newChain) async {
if (_currentSession?.sessionService.isMagic == true) {
- return selectChain(newChain);
+ await selectChain(newChain);
+ return;
}
final currentChainId = _currentSelectedChain!.namespace;
final newChainId = newChain.namespace;
_logger.i('[$runtimeType] requesting switch to chain $newChainId');
try {
- final response = await request(
+ await request(
topic: _currentSession?.topic ?? '',
chainId: currentChainId,
switchToChainId: newChainId,
@@ -1129,29 +1130,32 @@ class W3MService with ChangeNotifier, CoinbaseService implements IW3MService {
);
_currentSelectedChain = newChain;
await _setSesionAndChainData(_currentSession!);
- return response ?? true;
+ return;
} catch (e) {
- _logger.i('[$runtimeType] requesting switchChain error $e');
+ _logger.i('[$runtimeType] requestSwitchToChain error $e');
// if request errors due to user rejection then set the previous chain
if (_isUserRejectedError(e)) {
- loggerService.instance.i('[$runtimeType] User declined connection');
await _setLocalEthChain(_currentSelectedChain!);
- return null;
+ throw JsonRpcError(code: 5002, message: 'User rejected methods.');
} else {
- // Otherwise it meas chain has to be added.
- return await requestAddChain(newChain);
+ try {
+ // Otherwise it meas chain has to be added.
+ return await requestAddChain(newChain);
+ } catch (e) {
+ rethrow;
+ }
}
}
}
@override
- Future requestAddChain(W3MChainInfo newChain) async {
+ Future requestAddChain(W3MChainInfo newChain) async {
final topic = _currentSession?.topic ?? '';
final currentChainId = _currentSelectedChain!.namespace;
final newChainId = newChain.namespace;
- _logger.i('[$runtimeType] requesting switch to chain $newChainId');
+ _logger.i('[$runtimeType] requesting switch to add chain $newChainId');
try {
- final response = await request(
+ await request(
topic: topic,
chainId: currentChainId,
switchToChainId: newChainId,
@@ -1162,11 +1166,11 @@ class W3MService with ChangeNotifier, CoinbaseService implements IW3MService {
);
_currentSelectedChain = newChain;
await _setSesionAndChainData(_currentSession!);
- return response ?? true;
+ return;
} catch (e) {
- _logger.i('[$runtimeType] requesting addChain error $e');
+ _logger.i('[$runtimeType] requestAddChain error $e');
await _setLocalEthChain(_currentSelectedChain!);
- return null;
+ throw JsonRpcError(code: 5002, message: 'User rejected methods.');
}
}
diff --git a/lib/utils/w3m_chains_presets.dart b/lib/utils/w3m_chains_presets.dart
index eaacc9d3..bd114bd8 100644
--- a/lib/utils/w3m_chains_presets.dart
+++ b/lib/utils/w3m_chains_presets.dart
@@ -33,7 +33,12 @@ class W3MChainPresets {
chainId: '137',
chainIcon: chainImagesId['137'],
tokenName: 'MATIC',
- rpcUrl: 'https://rpc-mainnet.maticvigil.com',
+ rpcUrl: 'https://polygon-bor-rpc.publicnode.com',
+ extraRpcUrls: [
+ 'https://polygon.drpc.org',
+ 'https://1rpc.io/matic',
+ 'https://endpoints.omniatech.io/v1/matic/mainnet/public',
+ ],
blockExplorer: W3MBlockExplorer(
name: 'Explorer',
url: 'https://polygonscan.com',
diff --git a/lib/version.dart b/lib/version.dart
index e11e1d06..cf4332e2 100644
--- a/lib/version.dart
+++ b/lib/version.dart
@@ -1,2 +1,2 @@
// Generated code. Do not modify.
-const packageVersion = '3.2.1';
+const packageVersion = '3.2.2';
diff --git a/pubspec.yaml b/pubspec.yaml
index 0fceec7d..d1a0da9d 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,6 +1,6 @@
name: web3modal_flutter
description: "WalletConnect Web3Modal: Simple, intuitive wallet login. With this drop-in UI SDK, enable any wallet's users to seamlessly log in to your app and enjoy a unified experience"
-version: 3.2.1
+version: 3.2.2
repository: https://github.com/WalletConnect/Web3ModalFlutter
environment:
diff --git a/test/mock_classes.mocks.dart b/test/mock_classes.mocks.dart
index 9bfece6d..1b473d2e 100644
--- a/test/mock_classes.mocks.dart
+++ b/test/mock_classes.mocks.dart
@@ -870,23 +870,25 @@ class MockW3MService extends _i1.Mock implements _i3.W3MService {
returnValueForMissingStub: _i14.Future.value(),
) as _i14.Future);
@override
- _i14.Future requestSwitchToChain(_i3.W3MChainInfo? newChain) =>
+ _i14.Future requestSwitchToChain(_i3.W3MChainInfo? newChain) =>
(super.noSuchMethod(
Invocation.method(
#requestSwitchToChain,
[newChain],
),
- returnValue: _i14.Future.value(),
- ) as _i14.Future);
+ returnValue: _i14.Future.value(),
+ returnValueForMissingStub: _i14.Future.value(),
+ ) as _i14.Future);
@override
- _i14.Future requestAddChain(_i3.W3MChainInfo? newChain) =>
+ _i14.Future requestAddChain(_i3.W3MChainInfo? newChain) =>
(super.noSuchMethod(
Invocation.method(
#requestAddChain,
[newChain],
),
- returnValue: _i14.Future.value(),
- ) as _i14.Future);
+ returnValue: _i14.Future.value(),
+ returnValueForMissingStub: _i14.Future.value(),
+ ) as _i14.Future);
@override
void addListener(_i17.VoidCallback? listener) => super.noSuchMethod(
Invocation.method(