From bdee541d1137bcf493f7be070ba643f309fc0c0f Mon Sep 17 00:00:00 2001
From: Alfreedom <00tango.bromine@icloud.com>
Date: Thu, 22 Aug 2024 11:30:39 +0200
Subject: [PATCH] Bug fix
---
CHANGELOG.md | 5 +++++
example/android/gradle.properties | 4 ++--
example/ios/Runner.xcodeproj/project.pbxproj | 12 ++++++------
example/ios/Runner/Info.plist | 4 ++--
example/pubspec.lock | 2 +-
example/pubspec.yaml | 2 +-
.../blockchain_service/blockchain_service.dart | 18 ++++++++++++------
lib/services/w3m_service/w3m_service.dart | 8 +++++---
lib/version.dart | 2 +-
pubspec.yaml | 2 +-
10 files changed, 36 insertions(+), 23 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3138ea6..1b771c5 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,8 @@
+## 3.3.2
+
+- Fix a bug where reading stored chainId failed
+- Added retry to blockchain call when response is empty
+
## 3.3.1
- Bug fixes and improvements
diff --git a/example/android/gradle.properties b/example/android/gradle.properties
index e23b88f..4384028 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.3.1
-versionCode=72
+versionName=3.3.2
+versionCode=73
diff --git a/example/ios/Runner.xcodeproj/project.pbxproj b/example/ios/Runner.xcodeproj/project.pbxproj
index c8fca1b..01d6a51 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 = 71;
+ CURRENT_PROJECT_VERSION = 72;
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 = 71;
+ CURRENT_PROJECT_VERSION = 72;
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 = 71;
+ CURRENT_PROJECT_VERSION = 72;
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 = 71;
+ CURRENT_PROJECT_VERSION = 72;
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 = 71;
+ CURRENT_PROJECT_VERSION = 72;
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 = 71;
+ CURRENT_PROJECT_VERSION = 72;
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 a9c6c1b..c13c93a 100644
--- a/example/ios/Runner/Info.plist
+++ b/example/ios/Runner/Info.plist
@@ -19,7 +19,7 @@
CFBundlePackageType
APPL
CFBundleShortVersionString
- 3.3.1
+ 3.3.2
CFBundleSignature
????
CFBundleURLTypes
@@ -36,7 +36,7 @@
CFBundleVersion
- 71
+ 72
ITSAppUsesNonExemptEncryption
LSApplicationQueriesSchemes
diff --git a/example/pubspec.lock b/example/pubspec.lock
index c9a5245..4555844 100644
--- a/example/pubspec.lock
+++ b/example/pubspec.lock
@@ -1163,7 +1163,7 @@ packages:
path: ".."
relative: true
source: path
- version: "3.3.1"
+ version: "3.3.2"
web_socket_channel:
dependency: transitive
description:
diff --git a/example/pubspec.yaml b/example/pubspec.yaml
index 351c790..99a357a 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.3.1
+version: 3.3.2
environment:
sdk: ">=3.0.1 <4.0.0"
diff --git a/lib/services/blockchain_service/blockchain_service.dart b/lib/services/blockchain_service/blockchain_service.dart
index 7480698..9898394 100644
--- a/lib/services/blockchain_service/blockchain_service.dart
+++ b/lib/services/blockchain_service/blockchain_service.dart
@@ -55,6 +55,7 @@ class BlockChainService implements IBlockChainService {
}
}
+ int _retries = 1;
@override
Future getRpcRequest({
required String method,
@@ -87,6 +88,7 @@ class BlockChainService implements IBlockChainService {
}),
);
if (response.statusCode == 200 && response.body.isNotEmpty) {
+ _retries = 1;
try {
final result = _parseRpcResultAs(response.body);
final amount = EtherAmount.fromBigInt(EtherUnit.wei, hexToInt(result));
@@ -95,12 +97,16 @@ class BlockChainService implements IBlockChainService {
rethrow;
}
} else {
- final result = jsonDecode(response.body) as Map;
- final reasons = result['reasons'] as List;
- final reason = reasons.first as Map;
- loggerService.instance.i(
- '[$runtimeType] Failed to get request $method. ${reason['description']}',
- );
+ if (response.body.isEmpty && _retries > 0) {
+ loggerService.instance.i('[$runtimeType] Empty body');
+ _retries -= 1;
+ await getRpcRequest(method: method, params: params, chain: chain);
+ } else {
+ loggerService.instance.i(
+ '[$runtimeType] Failed to get request $method. '
+ 'Response: ${response.body}, Status code: ${response.statusCode}',
+ );
+ }
}
}
diff --git a/lib/services/w3m_service/w3m_service.dart b/lib/services/w3m_service/w3m_service.dart
index 9bdeca4..38e5ca1 100644
--- a/lib/services/w3m_service/w3m_service.dart
+++ b/lib/services/w3m_service/w3m_service.dart
@@ -331,8 +331,8 @@ class W3MService with ChangeNotifier implements IW3MService {
Future _setSesionAndChainData(W3MSession w3mSession) async {
try {
await _storeSession(w3mSession);
- final chainId = _currentSelectedChainId ?? w3mSession.chainId;
- await _setLocalEthChain(chainId, logEvent: false);
+ _currentSelectedChainId = _currentSelectedChainId ?? w3mSession.chainId;
+ await _setLocalEthChain(_currentSelectedChainId!, logEvent: false);
} catch (e, s) {
_logger.e(
'[$runtimeType] _setSesionAndChainData error $e',
@@ -370,7 +370,7 @@ class W3MService with ChangeNotifier implements IW3MService {
if (_currentSession != null) {
final chainId = _savedChainId(null);
if (chainId != null && W3MChainPresets.chains.containsKey(chainId)) {
- await selectChain(W3MChainPresets.chains[chainId]!, logEvent: false);
+ await _setLocalEthChain(chainId, logEvent: false);
} else {
_currentSelectedChainId = chainId;
}
@@ -458,6 +458,7 @@ class W3MService with ChangeNotifier implements IW3MService {
}
Future _setLocalEthChain(String chainId, {bool? logEvent}) async {
+ _currentSelectedChainId = chainId;
final caip2Chain = 'eip155:$_currentSelectedChainId';
_logger.i('[$runtimeType] set local chain $caip2Chain');
_currentSelectedChainId = chainId;
@@ -1296,6 +1297,7 @@ class W3MService with ChangeNotifier implements IW3MService {
_logger.i('[$runtimeType] requestSwitchToChain error $e');
// if request errors due to user rejection then set the previous chain
if (_isUserRejectedError(e)) {
+ // fallback to current chain if rejected by user
await _setLocalEthChain(_currentSelectedChainId!);
throw JsonRpcError(code: 5002, message: 'User rejected methods.');
} else {
diff --git a/lib/version.dart b/lib/version.dart
index 0c4dca2..8f12974 100644
--- a/lib/version.dart
+++ b/lib/version.dart
@@ -1,2 +1,2 @@
// Generated code. Do not modify.
-const packageVersion = '3.3.1';
+const packageVersion = '3.3.2';
diff --git a/pubspec.yaml b/pubspec.yaml
index 5c7ab94..5b911f9 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.3.1
+version: 3.3.2
repository: https://github.com/WalletConnect/Web3ModalFlutter
environment: