Skip to content

Commit

Permalink
fix coinbase
Browse files Browse the repository at this point in the history
  • Loading branch information
quetool committed Nov 1, 2024
1 parent 0fb963d commit d932641
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 19 deletions.
18 changes: 18 additions & 0 deletions packages/reown_appkit/example/base/ios/Runner/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import UIKit
import Flutter
import CoinbaseWalletSDK

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
Expand Down Expand Up @@ -48,14 +49,31 @@ import Flutter
}

override func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
if #available(iOS 13.0, *) {
if (CoinbaseWalletSDK.isConfigured == true) {
if (try? CoinbaseWalletSDK.shared.handleResponse(url)) == true {
return true
}
}
}

return linkStreamHandler.handleLink(url.absoluteString)
}

override func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
if #available(iOS 13.0, *) {
if (CoinbaseWalletSDK.isConfigured == true) {
if let url = userActivity.webpageURL, (try? CoinbaseWalletSDK.shared.handleResponse(url)) == true {
return true
}
}
}

if userActivity.activityType == NSUserActivityTypeBrowsingWeb {
handleIncomingUniversalLink(userActivity: userActivity)
return true
}

return false
}

Expand Down
8 changes: 4 additions & 4 deletions packages/reown_appkit/example/base/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ class _MyHomePageState extends State<MyHomePage> {
_appKitModal = ReownAppKitModal(
context: context,
appKit: _appKit,
siweConfig: linkMode ? _siweConfig() : null,
siweConfig: _siweConfig(linkMode),
enableAnalytics: true,
featuresConfig: FeaturesConfig(
email: true,
Expand Down Expand Up @@ -307,7 +307,7 @@ class _MyHomePageState extends State<MyHomePage> {
await _appKitModal!.init();
await _registerEventHandlers();

DeepLinkHandler.init(_appKit!);
DeepLinkHandler.init(_appKitModal!);
DeepLinkHandler.checkInitialLink();

final allChains = ReownAppKitModalNetworks.getAllSupportedNetworks();
Expand Down Expand Up @@ -522,7 +522,7 @@ class _MyHomePageState extends State<MyHomePage> {
}
}

SIWEConfig _siweConfig() => SIWEConfig(
SIWEConfig _siweConfig(bool enabled) => SIWEConfig(
getNonce: () async {
// this has to be called at the very moment of creating the pairing uri
return SIWEUtils.generateNonce();
Expand Down Expand Up @@ -585,7 +585,7 @@ class _MyHomePageState extends State<MyHomePage> {
// Called when disconnecting WalletConnect session was successfull
debugPrint('[SIWEConfig] onSignOut()');
},
enabled: true,
enabled: enabled,
signOutOnDisconnect: true,
signOutOnAccountChange: true,
signOutOnNetworkChange: false,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:reown_appkit/reown_appkit.dart';
import 'package:reown_appkit/modal/i_appkit_modal_impl.dart';

class DeepLinkHandler {
static const _methodChannel = MethodChannel(
Expand All @@ -10,7 +10,7 @@ class DeepLinkHandler {
'com.walletconnect.flutterdapp/events',
);
static final waiting = ValueNotifier<bool>(false);
static late IReownAppKit _appKit;
static late IReownAppKitModal _appKitModal;

static void initListener() {
if (kIsWeb) return;
Expand All @@ -24,9 +24,9 @@ class DeepLinkHandler {
}
}

static void init(IReownAppKit appKit) {
static void init(IReownAppKitModal appKitModal) {
if (kIsWeb) return;
_appKit = appKit;
_appKitModal = appKitModal;
}

static void checkInitialLink() async {
Expand All @@ -39,18 +39,17 @@ class DeepLinkHandler {
}

static Uri get nativeUri =>
Uri.parse(_appKit.metadata.redirect?.native ?? '');
Uri.parse(_appKitModal.appKit!.metadata.redirect?.native ?? '');
static Uri get universalUri =>
Uri.parse(_appKit.metadata.redirect?.universal ?? '');
Uri.parse(_appKitModal.appKit!.metadata.redirect?.universal ?? '');
static String get host => universalUri.host;

static void _onLink(dynamic link) async {
debugPrint('[SampleDapp] _onLink $link');
if (link == null) return;
try {
return await _appKit.dispatchEnvelope(link);
} catch (e) {
debugPrint('[SampleDapp] _onLink error $e');
final handled = await _appKitModal.dispatchEnvelope(link);
if (!handled) {
debugPrint('[SampleDapp] _onLink not handled by AppKit');
}
}

Expand Down
5 changes: 4 additions & 1 deletion packages/reown_appkit/lib/modal/appkit_modal_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ class ReownAppKitModal with ChangeNotifier implements IReownAppKitModal {
@override
Future<bool> dispatchEnvelope(String url) async {
_appKit.core.logger.d('[$runtimeType] dispatchEnvelope $url');
final envelope = ReownCoreUtils.getSearchParamFromURL(url, 'wc_ev');
if (envelope.isNotEmpty) {
await _appKit.dispatchEnvelope(url);
Expand Down Expand Up @@ -2042,7 +2043,9 @@ extension _AppKitModalExtension on ReownAppKitModal {
}

void _oneSIWEFinish(ReownAppKitModalSession updatedSession) async {
_appKit.core.logger.d('[$runtimeType] _oneSIWEFinish $updatedSession');
_appKit.core.logger.d(
'[$runtimeType] _oneSIWEFinish ${updatedSession.toJson()}',
);
await _storeSession(updatedSession);
try {
await _storage.set(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class CoinbaseService implements ICoinbaseService {
final redirect = _metadata.redirect;
final callback = redirect?.universal ?? redirect?.native ?? '';
_core.logger.i(
'[$runtimeType] init with $walletLink, $redirect, $callback',
'[$runtimeType] init with host: ${Uri.parse(walletLink)}, callback: ${Uri.parse(callback)}',
);
if (callback.isNotEmpty || walletLink.isNotEmpty) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,14 @@ class _AppKitModalAccountButtonState extends State<AppKitModalAccountButton> {
}

void _modalNotifyListener() {
setState(() {
final chainId = widget.appKitModal.selectedChain?.chainId ?? '';
final chainId = widget.appKitModal.selectedChain?.chainId ?? '';
if (chainId.isNotEmpty) {
final namespace = ReownAppKitModalNetworks.getNamespaceForChainId(
chainId,
);
_address = widget.appKitModal.session?.getAddress(namespace) ?? '';
});
}
setState(() {});
}

void _onTap() {
Expand Down

0 comments on commit d932641

Please sign in to comment.