Skip to content

Commit

Permalink
Merge pull request #75 from WalletConnect/bugfix/fix_android_bug_send…
Browse files Browse the repository at this point in the history
…_request_different_device

[HOTFIX] Android bug when sending a request from a dapp on a different device than the Wallet
  • Loading branch information
quetool authored Jan 8, 2024
2 parents c69a71b + 53bb7ab commit bd7d5c5
Show file tree
Hide file tree
Showing 17 changed files with 188 additions and 204 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 3.0.21

- Fix an Android bug happening when sending a request from a dApp in a different device than the paired wallet

## 3.0.20

- Minor 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.0.20
versionCode=20
versionName=3.0.21
versionCode=21
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 = 20;
CURRENT_PROJECT_VERSION = 21;
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 = 20;
CURRENT_PROJECT_VERSION = 21;
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 = 20;
CURRENT_PROJECT_VERSION = 21;
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 = 20;
CURRENT_PROJECT_VERSION = 21;
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 = 20;
CURRENT_PROJECT_VERSION = 21;
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 = 20;
CURRENT_PROJECT_VERSION = 21;
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.0.20</string>
<string>3.0.21</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleURLTypes</key>
Expand All @@ -34,7 +34,7 @@
</dict>
</array>
<key>CFBundleVersion</key>
<string>20</string>
<string>21</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 @@ -1115,7 +1115,7 @@ packages:
path: ".."
relative: true
source: path
version: "3.0.20"
version: "3.0.21"
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.0.20
version: 3.0.21

environment:
sdk: ">=3.0.1 <4.0.0"
Expand Down
2 changes: 1 addition & 1 deletion lib/constants/string_constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class StringConstants {

// Storage
static const String recentWalletId = 'w3m_recentWallet';
static const String walletData = 'w3m_walletData';
static const String connectedWalletData = 'w3m_walletData';
static const String selectedChainId = 'w3m_selectedChainId';

// Urls
Expand Down
4 changes: 3 additions & 1 deletion lib/pages/connect_wallet_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ class _ConnectWalletPageState extends State<ConnectWalletPage>
kNavbarHeight -
(kPadding16 * 2);
//
final walletRedirect = _service!.selectedWalletRedirect;
final walletRedirect = explorerService.instance?.getWalletRedirect(
_service!.selectedWallet,
);
final webOnlyWallet = walletRedirect?.webOnly == true;
final mobileOnlyWallet = walletRedirect?.mobileOnly == true;
//
Expand Down
57 changes: 32 additions & 25 deletions lib/services/explorer_service/explorer_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class ExplorerService implements IExplorerService {
Future<void> _getRecentWalletAndOrder() async {
W3MWalletInfo? walletInfo;
final walletString = storageService.instance.getString(
StringConstants.walletData,
StringConstants.connectedWalletData,
);
final recentWalletId = storageService.instance.getString(
StringConstants.recentWalletId,
Expand Down Expand Up @@ -234,16 +234,41 @@ class ExplorerService implements IExplorerService {
}

@override
Future<void> storeConnectedWalletData(W3MWalletInfo? walletInfo) async {
Future<void> storeConnectedWallet(W3MWalletInfo? walletInfo) async {
if (walletInfo == null) return;
final walletDataString = jsonEncode(walletInfo.toJson());
await storageService.instance.setString(
StringConstants.walletData,
StringConstants.connectedWalletData,
walletDataString,
);
await _updateRecentWalletId(walletInfo);
}

@override
W3MWalletInfo? getConnectedWallet() {
try {
final walletString = storageService.instance.getString(
StringConstants.connectedWalletData,
defaultValue: '',
);
if (walletString!.isNotEmpty) {
return W3MWalletInfo.fromJson(jsonDecode(walletString));
}
} catch (e, s) {
W3MLoggerUtil.logger.e(
'[$runtimeType] error getConnectedWallet:',
error: e,
stackTrace: s,
);
}
return null;
}

@override
Future<void> deleteConnectedWallet() async {
await storageService.instance.clearKey(StringConstants.connectedWalletData);
}

Future<void> _updateRecentWalletId(
W3MWalletInfo? walletInfo, {
String? walletId,
Expand Down Expand Up @@ -322,29 +347,11 @@ class ExplorerService implements IExplorerService {
}

@override
WalletRedirect? getWalletRedirect(Listing listing) {
final wallet = listings.value.firstWhereOrNull(
(item) => listing.id == item.listing.id,
);
if (wallet == null) {
return null;
}
return WalletRedirect(
mobile: wallet.listing.mobileLink,
desktop: wallet.listing.desktopLink,
web: wallet.listing.webappLink,
);
}
WalletRedirect? getWalletRedirect(W3MWalletInfo? walletInfo) {
if (walletInfo == null) return null;

@override
Future<WalletRedirect?> tryWalletRedirectByName(String? name) async {
if (name == null) return null;
final results = await _fetchListings(
params: RequestParams(page: 1, entries: 100, search: name),
updateCount: false,
);
final wallet = results.firstWhereOrNull(
(item) => item.listing.name.toLowerCase() == name.toLowerCase(),
final wallet = listings.value.firstWhereOrNull(
(item) => walletInfo.listing.id == item.listing.id,
);
if (wallet == null) {
return null;
Expand Down
18 changes: 12 additions & 6 deletions lib/services/explorer_service/i_explorer_service.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:flutter/material.dart';
import 'package:web3modal_flutter/services/explorer_service/models/api_response.dart';
import 'package:web3modal_flutter/services/explorer_service/models/redirect.dart';
import 'package:web3modal_flutter/web3modal_flutter.dart';

Expand Down Expand Up @@ -38,13 +37,20 @@ abstract class IExplorerService {
String get searchValue;

/// update the recently used position to the top list
Future<void> storeConnectedWalletData(W3MWalletInfo? walletInfo);
Future<void> storeConnectedWallet(W3MWalletInfo? walletInfo);

String getWalletImageUrl(String imageId);
/// Get connected wallet data from local storage
W3MWalletInfo? getConnectedWallet();

String getAssetImageUrl(String imageId);
/// Removes connected wallet data from local storage
Future<void> deleteConnectedWallet();

WalletRedirect? getWalletRedirect(Listing listing);
/// Gets the WalletRedirect object from a wallet info data
WalletRedirect? getWalletRedirect(W3MWalletInfo? walletInfo);

Future<WalletRedirect?> tryWalletRedirectByName(String? name);
/// Given an imageId it return the wallet app icon from our services
String getWalletImageUrl(String imageId);

/// Given an imageId it return the chain icon from our services
String getAssetImageUrl(String imageId);
}
1 change: 1 addition & 0 deletions lib/services/storage_service/i_storage_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ abstract class IStorageService {
Future<void> init();
String? getString(String key, {String? defaultValue});
Future<bool> setString(String key, String value);
Future<bool> clearKey(String key);
}
5 changes: 5 additions & 0 deletions lib/services/storage_service/storage_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,9 @@ class StorageService implements IStorageService {
Future<bool> setString(String key, String value) async {
return _prefs!.setString(key, value);
}

@override
Future<bool> clearKey(String key) async {
return _prefs!.remove(key);
}
}
21 changes: 9 additions & 12 deletions lib/services/w3m_service/i_w3m_service.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'package:event/event.dart';
import 'package:flutter/material.dart';
import 'package:web3modal_flutter/services/explorer_service/models/redirect.dart';
import 'package:web3modal_flutter/web3modal_flutter.dart';

enum W3MServiceStatus {
Expand Down Expand Up @@ -99,14 +98,6 @@ abstract class IW3MService with ChangeNotifier {
/// This will do nothing if [isConnected] is true.
Future<void> buildConnectionUri();

/// Subscribe to listen to pairing expirations
final Event<EventArgs> onPairingExpire = Event();

WalletRedirect? get selectedWalletRedirect;

/// When users rejects connection or an error occurs this will event
final Event<WalletErrorEvent> onWalletConnectionError = Event();

/// Connects the [selectedWallet] previously selected
Future<void> connectSelectedWallet({bool inBrowser = false});

Expand All @@ -121,13 +112,19 @@ abstract class IW3MService with ChangeNotifier {
/// Gets the name of the currently connected wallet.
String getReferer();

/// Closes the modal.
void closeModal();

/// Disconnects the session and pairing, if any.
/// If there is no session, this does nothing.
Future<void> disconnect({bool disconnectAllSessions = true});

/// Closes the modal.
void closeModal();

@override
void dispose();

/// Subscribe to listen to pairing expirations
final Event<EventArgs> onPairingExpire = Event();

/// When users rejects connection or an error occurs this will event
final Event<WalletErrorEvent> onWalletConnectionError = Event();
}
Loading

0 comments on commit bd7d5c5

Please sign in to comment.