Skip to content

Commit

Permalink
Merge pull request #80 from WalletConnect/bugfix/coinbase_wallet_actions
Browse files Browse the repository at this point in the history
Fix Coinbase Wallet not opening bug
  • Loading branch information
quetool authored Jan 12, 2024
2 parents 2013221 + e5d7841 commit 11d0a0e
Show file tree
Hide file tree
Showing 12 changed files with 68 additions and 60 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
## 3.1.0-beta03
## 3.1.0-beta02

- Improvements and bug fixes
Expand Down
2 changes: 1 addition & 1 deletion example/android/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true
android.enableJetifier=true
versionName=3.1.0
versionCode=26
versionCode=27
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 = 26;
CURRENT_PROJECT_VERSION = 27;
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 = 26;
CURRENT_PROJECT_VERSION = 27;
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 = 26;
CURRENT_PROJECT_VERSION = 27;
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 = 26;
CURRENT_PROJECT_VERSION = 27;
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 = 26;
CURRENT_PROJECT_VERSION = 27;
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 = 26;
CURRENT_PROJECT_VERSION = 27;
DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = W5R8AG9K22;
ENABLE_BITCODE = NO;
Expand Down
2 changes: 1 addition & 1 deletion example/ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
</dict>
</array>
<key>CFBundleVersion</key>
<string>26</string>
<string>27</string>
<key>ITSAppUsesNonExemptEncryption</key>
<false/>
<key>LSApplicationQueriesSchemes</key>
Expand Down
7 changes: 4 additions & 3 deletions example/lib/widgets/session_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,13 @@ class SessionWidgetState extends State<SessionWidget> {
final currentNamespace = widget.w3mService.selectedChain!.namespace;
final chainsNamespaces = NamespaceUtils.getChainsFromAccounts(accounts);
if (chainsNamespaces.contains(currentNamespace)) {
final account = accounts
.firstWhere((account) => account.contains(currentNamespace));
final account = accounts.firstWhere(
(account) => account.contains('$currentNamespace:'),
);
children.add(_buildAccountWidget(account));
}
} catch (e) {
debugPrint(e.toString());
debugPrint('[$runtimeType] ${e.toString()}');
}

return Padding(
Expand Down
6 changes: 3 additions & 3 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1065,10 +1065,10 @@ packages:
dependency: transitive
description:
name: walletconnect_flutter_v2
sha256: a3654aa71221f15be6b20663759fad3eb3a37dc486f72860d7eb69c1e39d682b
sha256: e26ca98cfd6b8d5dc9c5f7e581999ab314d5134c0ffcddb73ef750f13b322d9c
url: "https://pub.dev"
source: hosted
version: "2.1.12"
version: "2.1.13"
watcher:
dependency: transitive
description:
Expand Down Expand Up @@ -1099,7 +1099,7 @@ packages:
path: ".."
relative: true
source: path
version: "3.1.0-beta02"
version: "3.1.0-beta03"
web_socket_channel:
dependency: transitive
description:
Expand Down
58 changes: 27 additions & 31 deletions lib/services/explorer_service/explorer_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,6 @@ class ExplorerService implements IExplorerService {
StringConstants.connectedWalletData,
walletDataString,
);
await storeRecentWalletId(walletInfo.listing.id);
await _updateRecentWalletId(walletInfo, walletId: walletInfo.listing.id);
}

Expand Down Expand Up @@ -308,29 +307,32 @@ class ExplorerService implements IExplorerService {
W3MWalletInfo? walletInfo, {
String? walletId,
}) async {
final recentId = walletInfo?.listing.id ?? walletId ?? '';
// Set the recent
if (recentId.isNotEmpty) {
await storageService.instance.setString(
StringConstants.recentWalletId,
recentId,
try {
final recentId = walletInfo?.listing.id ?? walletId;
await storeRecentWalletId(recentId);

final currentListings = List<W3MWalletInfo>.from(
_listings.map((e) => e.copyWith(recent: false)).toList(),
);
final recentWallet = currentListings.firstWhereOrNull(
(e) => e.listing.id == recentId,
);
if (recentWallet != null) {
final rw = recentWallet.copyWith(recent: true);
currentListings.removeWhere((e) => e.listing.id == rw.listing.id);
currentListings.insert(0, rw);
}
_listings = currentListings;
listings.value = _listings;
W3MLoggerUtil.logger.t('[$runtimeType] _updateRecentWalletId $walletId '
'${walletInfo?.toJson()}');
} catch (e, s) {
W3MLoggerUtil.logger.e(
'[$runtimeType] _updateRecentWalletId',
error: e,
stackTrace: s,
);
}
final currentListings = List<W3MWalletInfo>.from(
_listings.map((e) => e.copyWith(recent: false)).toList(),
);
final recentWallet = currentListings.firstWhereOrNull(
(e) => e.listing.id == recentId,
);
if (recentWallet != null) {
final rw = recentWallet.copyWith(recent: true);
currentListings.removeWhere((e) => e.listing.id == rw.listing.id);
currentListings.insert(0, rw);
}
_listings = currentListings;
listings.value = _listings;
W3MLoggerUtil.logger.t(
'[$runtimeType] _updateRecentWalletId $walletId ${walletInfo?.toJson()}');
}

@override
Expand Down Expand Up @@ -406,16 +408,10 @@ class ExplorerService implements IExplorerService {
WalletRedirect? getWalletRedirect(W3MWalletInfo? walletInfo) {
if (walletInfo == null) return null;

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

Expand Down
19 changes: 9 additions & 10 deletions lib/services/w3m_service/models/w3m_session.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,19 @@ class W3MSession {
}

String? get address {
if (sessionData != null) {
if (sessionData!.namespaces.isNotEmpty) {
final accounts = sessionData!.namespaces.values.first.accounts;
if (accounts.isNotEmpty) {
return NamespaceUtils.getAccount(accounts.first);
}
W3MLoggerUtil.logger.e('[$runtimeType] empty accounts');
}
if (sessionService.noSession) {
return null;
}
if (coinbaseData != null) {
if (sessionService.isCoinbase) {
return coinbaseData!.address;
}
// if (magicData != null)
// if (sessionService.isMagic) {
//
final namespace = sessionData?.namespaces[EthConstants.namespace];
final accounts = namespace?.accounts ?? [];
if (accounts.isNotEmpty) {
return NamespaceUtils.getAccount(accounts.first);
}
W3MLoggerUtil.logger.e('[$runtimeType] no address found');
return null;
}
Expand Down
11 changes: 11 additions & 0 deletions lib/services/w3m_service/w3m_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,12 @@ class W3MService with ChangeNotifier, CoinbaseService implements IW3MService {
return false;
}

if (walletInfo.isCoinbase) {
// Coinbase Wallet is getting launched at every request by it's own SDK
// SO no need to do it here.
return false;
}

final redirect = explorerService.instance.getWalletRedirect(walletInfo);
if (redirect == null) {
return false;
Expand Down Expand Up @@ -956,6 +962,11 @@ extension _W3MServiceExtension on W3MService {
void onSessionConnect(SessionConnect? args) async {
W3MLoggerUtil.logger.t('[$runtimeType] onSessionConnect: $args');
if (args != null) {
if (_selectedWallet == null) {
await storageService.instance.clearKey(StringConstants.recentWalletId);
await storageService.instance
.clearKey(StringConstants.connectedWalletData);
}
await _storeSession(W3MSession(sessionData: args.session));
await _selectChainFromStoredId();
_loadAccountData();
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.

4 changes: 2 additions & 2 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1049,10 +1049,10 @@ packages:
dependency: "direct main"
description:
name: walletconnect_flutter_v2
sha256: a3654aa71221f15be6b20663759fad3eb3a37dc486f72860d7eb69c1e39d682b
sha256: e26ca98cfd6b8d5dc9c5f7e581999ab314d5134c0ffcddb73ef750f13b322d9c
url: "https://pub.dev"
source: hosted
version: "2.1.12"
version: "2.1.13"
watcher:
dependency: transitive
description:
Expand Down
4 changes: 2 additions & 2 deletions 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.1.0-beta02
version: 3.1.0-beta03
repository: https://github.com/WalletConnect/Web3ModalFlutter

environment:
Expand All @@ -22,7 +22,7 @@ dependencies:
qr_flutter_wc: ^0.0.3
shimmer: ^3.0.0
url_launcher: ^6.2.3
walletconnect_flutter_v2: ^2.1.12
walletconnect_flutter_v2: ^2.1.13

dev_dependencies:
build_runner: ^2.4.7
Expand Down

0 comments on commit 11d0a0e

Please sign in to comment.