connectSelectedWallet method
Connects the selectedWallet previously selected
Implementation
@override
Future<void> connectSelectedWallet({bool inBrowser = false}) async {
_checkInitialized();
final walletRedirect = explorerService.instance.getWalletRedirect(
selectedWallet,
);
if (walletRedirect == null) {
throw ReownAppKitModalException(
'You didn\'t select a wallet or walletInfo argument is null',
);
}
_trackSelectedWallet(walletRedirect, inBrowser: inBrowser);
var pType = PlatformUtils.getPlatformType();
if (inBrowser) {
pType = PlatformType.web;
}
try {
if (_selectedWallet!.isCoinbase) {
await coinbaseService.instance.getAccount();
await explorerService.instance.storeConnectedWallet(_selectedWallet);
} else {
await buildConnectionUri();
await uriService.instance.openRedirect(
walletRedirect,
wcURI: wcUri!,
pType: pType,
);
}
} on LaunchUrlException catch (e) {
if (e is CanNotLaunchUrl) {
onModalError.broadcast(WalletNotInstalled());
} else {
onModalError.broadcast(ErrorOpeningWallet());
}
} catch (e, s) {
if (e is PlatformException) {
final installed = _selectedWallet?.installed ?? false;
if (!installed) {
onModalError.broadcast(WalletNotInstalled());
} else {
onModalError.broadcast(ErrorOpeningWallet());
}
} else if (e is CoinbaseServiceException) {
if (e is CoinbaseWalletNotInstalledException) {
onModalError.broadcast(WalletNotInstalled());
} else {
if (_isUserRejectedError(e)) {
_logger.i('[$runtimeType] User declined connection');
onModalError.broadcast(UserRejectedConnection());
analyticsService.instance.sendEvent(ConnectErrorEvent(
message: 'User declined connection',
));
} else {
onModalError.broadcast(ErrorOpeningWallet());
analyticsService.instance.sendEvent(ConnectErrorEvent(
message: e.message,
));
}
}
} else if (_isUserRejectedError(e)) {
_logger.i('[$runtimeType] User declined connection');
onModalError.broadcast(UserRejectedConnection());
analyticsService.instance.sendEvent(ConnectErrorEvent(
message: 'User declined connection',
));
} else {
_logger.e(
'[$runtimeType] Error connecting wallet',
error: e,
stackTrace: s,
);
onModalError.broadcast(ErrorOpeningWallet());
}
}
}