Skip to content

Commit

Permalink
Bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
quetool committed Aug 22, 2024
1 parent 3f8b2a5 commit bdee541
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 23 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions example/android/gradle.properties
Original file line number Diff line number Diff line change
@@ -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
12 changes: 6 additions & 6 deletions example/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions example/ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>3.3.1</string>
<string>3.3.2</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleURLTypes</key>
Expand All @@ -36,7 +36,7 @@
</dict>
</array>
<key>CFBundleVersion</key>
<string>71</string>
<string>72</string>
<key>ITSAppUsesNonExemptEncryption</key>
<false/>
<key>LSApplicationQueriesSchemes</key>
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1163,7 +1163,7 @@ packages:
path: ".."
relative: true
source: path
version: "3.3.1"
version: "3.3.2"
web_socket_channel:
dependency: transitive
description:
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
18 changes: 12 additions & 6 deletions lib/services/blockchain_service/blockchain_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class BlockChainService implements IBlockChainService {
}
}

int _retries = 1;
@override
Future<dynamic> getRpcRequest({
required String method,
Expand Down Expand Up @@ -87,6 +88,7 @@ class BlockChainService implements IBlockChainService {
}),
);
if (response.statusCode == 200 && response.body.isNotEmpty) {
_retries = 1;
try {
final result = _parseRpcResultAs<String>(response.body);
final amount = EtherAmount.fromBigInt(EtherUnit.wei, hexToInt(result));
Expand All @@ -95,12 +97,16 @@ class BlockChainService implements IBlockChainService {
rethrow;
}
} else {
final result = jsonDecode(response.body) as Map<String, dynamic>;
final reasons = result['reasons'] as List;
final reason = reasons.first as Map<String, dynamic>;
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}',
);
}
}
}

Expand Down
8 changes: 5 additions & 3 deletions lib/services/w3m_service/w3m_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,8 @@ class W3MService with ChangeNotifier implements IW3MService {
Future<void> _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',
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -458,6 +458,7 @@ class W3MService with ChangeNotifier implements IW3MService {
}

Future<void> _setLocalEthChain(String chainId, {bool? logEvent}) async {
_currentSelectedChainId = chainId;
final caip2Chain = 'eip155:$_currentSelectedChainId';
_logger.i('[$runtimeType] set local chain $caip2Chain');
_currentSelectedChainId = chainId;
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion lib/version.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down

0 comments on commit bdee541

Please sign in to comment.