From ca75ad76773c7e3585514e6489cd144802a65fe0 Mon Sep 17 00:00:00 2001 From: Alfreedom <00tango.bromine@icloud.com> Date: Thu, 4 Apr 2024 20:18:10 +0200 Subject: [PATCH] Email login bug fixes and performance improvements --- .github/workflows/build-ios-debug.yml | 2 +- .github/workflows/build-ios-internal.yml | 2 +- .github/workflows/build-ios.yml | 2 +- CHANGELOG.md | 2 +- android/app/src/main/AndroidManifest.xml | 2 +- .../android/app/src/main/AndroidManifest.xml | 3 +- example/android/gradle.properties | 2 +- example/ios/Runner.xcodeproj/project.pbxproj | 24 ++-- example/ios/Runner/Info.plist | 2 +- example/lib/home_page.dart | 30 ++--- example/lib/utils/crypto/eip155.dart | 8 +- example/lib/utils/crypto/helpers.dart | 2 +- example/lib/widgets/logger_widget.dart | 4 +- example/lib/widgets/method_dialog.dart | 1 - example/lib/widgets/session_widget.dart | 2 +- example/pubspec.lock | 2 +- .../coinbase_service/coinbase_service.dart | 8 +- .../logger_service/logger_service.dart | 2 +- .../magic_service/i_magic_service.dart | 3 +- lib/services/magic_service/magic_service.dart | 8 +- .../magic_service/models/magic_events.dart | 9 +- lib/services/w3m_service/i_w3m_service.dart | 5 - lib/services/w3m_service/w3m_service.dart | 119 ++++++++++-------- lib/utils/w3m_logger.dart | 2 +- lib/version.dart | 2 +- pubspec.yaml | 9 +- test/mock_classes.mocks.dart | 57 +++------ 27 files changed, 158 insertions(+), 156 deletions(-) diff --git a/.github/workflows/build-ios-debug.yml b/.github/workflows/build-ios-debug.yml index a776e522..e24b476f 100644 --- a/.github/workflows/build-ios-debug.yml +++ b/.github/workflows/build-ios-debug.yml @@ -11,7 +11,7 @@ on: jobs: build_with_signing: name: Build iOS App Debug (alpha) - runs-on: macos-latest + runs-on: macos-latest-xlarge steps: # Checkout the repo diff --git a/.github/workflows/build-ios-internal.yml b/.github/workflows/build-ios-internal.yml index fd3b4c58..f8deba00 100644 --- a/.github/workflows/build-ios-internal.yml +++ b/.github/workflows/build-ios-internal.yml @@ -10,7 +10,7 @@ on: jobs: build_with_signing: - runs-on: macos-latest + runs-on: macos-latest-xlarge steps: # Checkout the repo diff --git a/.github/workflows/build-ios.yml b/.github/workflows/build-ios.yml index c1eaba5b..7e684005 100644 --- a/.github/workflows/build-ios.yml +++ b/.github/workflows/build-ios.yml @@ -10,7 +10,7 @@ on: jobs: build_with_signing: - runs-on: macos-latest + runs-on: macos-latest-xlarge steps: # Checkout the repo diff --git a/CHANGELOG.md b/CHANGELOG.md index 662e8f00..699a558e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -## 3.2.0-beta02 +## 3.2.0-beta03 - Email Login support - Analytics API support diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 1c2ed327..c73a0aae 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -6,7 +6,7 @@ CFBundleVersion - 44 + 46 ITSAppUsesNonExemptEncryption LSApplicationQueriesSchemes diff --git a/example/lib/home_page.dart b/example/lib/home_page.dart index ba09f490..f9f96a3a 100644 --- a/example/lib/home_page.dart +++ b/example/lib/home_page.dart @@ -80,8 +80,6 @@ class _MyHomePageState extends State { // If you want to support just one chain uncomment this line and avoid using W3MNetworkSelectButton() // _w3mService.selectChain(W3MChainPresets.chains['137']); - - _w3mService.addListener(_serviceListener); // _w3mService.onModalConnect.subscribe(_onModalConnect); _w3mService.onModalDisconnect.subscribe(_onModalDisconnect); @@ -91,14 +89,12 @@ class _MyHomePageState extends State { _w3mService.onSessionUpdateEvent.subscribe(_onSessionUpdate); _w3mService.onSessionEventEvent.subscribe(_onSessionEvent); // - // await _w3mService.init(); + setState(() {}); } @override void dispose() { - _w3mService.removeListener(_serviceListener); - // _w3mService.onModalConnect.unsubscribe(_onModalConnect); _w3mService.onModalDisconnect.unsubscribe(_onModalDisconnect); _w3mService.onModalError.unsubscribe(_onModalError); @@ -110,40 +106,40 @@ class _MyHomePageState extends State { super.dispose(); } - void _serviceListener() { - setState(() {}); - } - void _onModalConnect(ModalConnect? event) { - debugPrint('[HomePage] 1 _onModalConnect ${event?.toString()}'); - debugPrint('[HomePage] 2 _onModalConnect ${event?.session.address}'); - debugPrint('[HomePage] 3 _onModalConnect ${_w3mService.session?.address}'); + debugPrint('[ExampleApp] _onModalConnect ${event?.toString()}'); + setState(() {}); } void _onModalDisconnect(ModalDisconnect? event) { - debugPrint('[HomePage] 1 _onModalDisconnect ${event?.toString()}'); + debugPrint('[ExampleApp] _onModalDisconnect ${event?.toString()}'); + setState(() {}); } void _onModalError(ModalError? event) { - debugPrint('[HomePage] modal error ${event?.toString()}'); + debugPrint('[ExampleApp] _onModalError ${event?.toString()}'); // When user connected to Coinbase Wallet but Coinbase Wallet does not have a session anymore // (for instance if user disconnected the dapp directly within Coinbase Wallet) // Then Coinbase Wallet won't emit any event if ((event?.message ?? '').contains('Coinbase Wallet Error')) { _w3mService.disconnect(); } + setState(() {}); } void _onSessionExpired(SessionExpire? event) { - debugPrint('[HomePage] _onSessionExpired ${event?.toString()}'); + debugPrint('[ExampleApp] _onSessionExpired ${event?.toString()}'); + setState(() {}); } void _onSessionUpdate(SessionUpdate? event) { - debugPrint('[HomePage] _onSessionUpdate ${event?.toString()}'); + debugPrint('[ExampleApp] _onSessionUpdate ${event?.toString()}'); + setState(() {}); } void _onSessionEvent(SessionEvent? event) { - debugPrint('[HomePage] _onSessionEvent ${event?.toString()}'); + debugPrint('[ExampleApp] _onSessionEvent ${event?.toString()}'); + setState(() {}); } @override diff --git a/example/lib/utils/crypto/eip155.dart b/example/lib/utils/crypto/eip155.dart index 412d5333..3c983e2c 100644 --- a/example/lib/utils/crypto/eip155.dart +++ b/example/lib/utils/crypto/eip155.dart @@ -1,7 +1,4 @@ import 'dart:convert'; -// ignore: depend_on_referenced_packages -import 'package:convert/convert.dart'; -import 'package:flutter/foundation.dart'; import 'package:intl/intl.dart'; import 'package:web3modal_flutter/web3modal_flutter.dart'; @@ -146,9 +143,8 @@ class EIP155 { required String address, required String message, }) async { - final bytes = utf8.encode(message); - final encoded = hex.encode(bytes); - debugPrint('personalSign 0x$encoded'); + // final bytes = utf8.encode(message); + // final encoded = hex.encode(bytes); return await w3mService.request( topic: topic, diff --git a/example/lib/utils/crypto/helpers.dart b/example/lib/utils/crypto/helpers.dart index e1c9a0a5..064c0fb8 100644 --- a/example/lib/utils/crypto/helpers.dart +++ b/example/lib/utils/crypto/helpers.dart @@ -11,7 +11,7 @@ String getChainName(String chain) { .w3mChainInfo .chainName; } catch (e) { - debugPrint('getChainName, Invalid chain: $chain'); + debugPrint('[ExampleApp] getChainName, Invalid chain: $chain'); } return 'Unknown'; } diff --git a/example/lib/widgets/logger_widget.dart b/example/lib/widgets/logger_widget.dart index 0104aee1..736757c7 100644 --- a/example/lib/widgets/logger_widget.dart +++ b/example/lib/widgets/logger_widget.dart @@ -116,8 +116,8 @@ class _DraggableCardState extends State { class OverlayController extends AnimatedOverlay { OverlayController(super.duration); OverlayEntry? _entry; - final _defaultAlign = const Alignment(0.0, -1.8); - Alignment align = const Alignment(0.0, -1.8); + final _defaultAlign = const Alignment(0.0, -2.0); + Alignment align = const Alignment(0.0, -2.0); Animation? alignAnimation; OverlayEntry createAlignOverlay(Widget child) { diff --git a/example/lib/widgets/method_dialog.dart b/example/lib/widgets/method_dialog.dart index ae74aed9..07f5781b 100644 --- a/example/lib/widgets/method_dialog.dart +++ b/example/lib/widgets/method_dialog.dart @@ -44,7 +44,6 @@ class MethodDialogState extends State { content: FutureBuilder( future: widget.response, builder: (BuildContext context, AsyncSnapshot snapshot) { - debugPrint('snapshot: $snapshot'); if (snapshot.hasData) { final String t = jsonEncode(snapshot.data); return InkWell( diff --git a/example/lib/widgets/session_widget.dart b/example/lib/widgets/session_widget.dart index 6560847a..6eea6666 100644 --- a/example/lib/widgets/session_widget.dart +++ b/example/lib/widgets/session_widget.dart @@ -118,7 +118,7 @@ class SessionWidgetState extends State { children.add(_buildAccountWidget(account)); } } catch (e) { - debugPrint('[$runtimeType] ${e.toString()}'); + debugPrint('[ExampleApp] ${e.toString()}'); } return Padding( diff --git a/example/pubspec.lock b/example/pubspec.lock index 57ae75c0..35e6008f 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -1147,7 +1147,7 @@ packages: path: ".." relative: true source: path - version: "3.2.0-beta02" + version: "3.2.0-beta03" web_socket_channel: dependency: transitive description: diff --git a/lib/services/coinbase_service/coinbase_service.dart b/lib/services/coinbase_service/coinbase_service.dart index 40eeefee..2d1a2253 100644 --- a/lib/services/coinbase_service/coinbase_service.dart +++ b/lib/services/coinbase_service/coinbase_service.dart @@ -217,16 +217,18 @@ extension on SessionRequestParams { toAddress: jsonData['to'], chainId: chainId!, weiValue: BigInt.from(value), - data: jsonData['data'], + data: jsonData['data'] ?? '', ); case MethodsConstants.ethSendTransaction: final jsonData = _getTransactionFromParams(params); + final hexValue = jsonData['value'].toString().replaceFirst('0x', ''); + final value = int.parse(hexValue, radix: 16); return SendTransaction( fromAddress: jsonData['from'], toAddress: jsonData['to'], chainId: chainId!, - weiValue: jsonData['value'], - data: jsonData['data'], + weiValue: BigInt.from(value).toString(), + data: jsonData['data'] ?? '', ); case MethodsConstants.walletSwitchEthChain: case MethodsConstants.walletAddEthChain: diff --git a/lib/services/logger_service/logger_service.dart b/lib/services/logger_service/logger_service.dart index 44ce0a47..4d8869dc 100644 --- a/lib/services/logger_service/logger_service.dart +++ b/lib/services/logger_service/logger_service.dart @@ -11,7 +11,7 @@ class LoggerService implements ILoggerService { level: level.toLevel(), printer: PrettyPrinter(methodCount: null), ); - if (kDebugMode && debugMode) { + if (kDebugMode && debugMode && level == LogLevel.error) { Logger.addLogListener(_logListener); } } diff --git a/lib/services/magic_service/i_magic_service.dart b/lib/services/magic_service/i_magic_service.dart index 1b93d55e..5b17b084 100644 --- a/lib/services/magic_service/i_magic_service.dart +++ b/lib/services/magic_service/i_magic_service.dart @@ -28,7 +28,8 @@ abstract class IMagicService { Future disconnect(); abstract final Event onMagicLoginRequest; - abstract final Event onMagicLoginSuccess; + abstract final Event onMagicLoginSuccess; + abstract final Event onMagicConnect; abstract final Event onMagicUpdate; abstract final Event onMagicError; abstract final Event onMagicRpcRequest; diff --git a/lib/services/magic_service/magic_service.dart b/lib/services/magic_service/magic_service.dart index 7e29e1b8..27923380 100644 --- a/lib/services/magic_service/magic_service.dart +++ b/lib/services/magic_service/magic_service.dart @@ -56,7 +56,10 @@ class MagicService implements IMagicService { Event onMagicLoginRequest = Event(); @override - Event onMagicLoginSuccess = Event(); + Event onMagicLoginSuccess = Event(); + + @override + Event onMagicConnect = Event(); @override Event onMagicError = Event(); @@ -327,6 +330,7 @@ class MagicService implements IMagicService { if (!_connected.isCompleted) { _connected.complete(isConnected.value); } + onMagicConnect.broadcast(MagicConnectEvent(isConnected.value)); if (isConnected.value) { await _getUser(_connectionChainId); } @@ -405,7 +409,7 @@ class MagicService implements IMagicService { onMagicUpdate.broadcast(event); _connected.complete(isConnected.value); } else { - onMagicLoginSuccess.broadcast(MagicConnectEvent(data)); + onMagicLoginSuccess.broadcast(MagicLoginEvent(data)); } } // ****** SIGN_OUT diff --git a/lib/services/magic_service/models/magic_events.dart b/lib/services/magic_service/models/magic_events.dart index 4475fcfa..19e7fed7 100644 --- a/lib/services/magic_service/models/magic_events.dart +++ b/lib/services/magic_service/models/magic_events.dart @@ -1,9 +1,9 @@ import 'package:web3modal_flutter/services/magic_service/models/magic_data.dart'; import 'package:web3modal_flutter/web3modal_flutter.dart'; -class MagicConnectEvent implements EventArgs { +class MagicLoginEvent implements EventArgs { final MagicData? data; - MagicConnectEvent(this.data); + MagicLoginEvent(this.data); @override String toString() => data?.toString() ?? ''; @@ -54,6 +54,11 @@ class MagicRequestEvent implements EventArgs { String toString() => 'request: $request, success: $success, result: $result'; } +class MagicConnectEvent implements EventArgs { + final bool connected; + MagicConnectEvent(this.connected); +} + class MagicErrorEvent implements EventArgs { final String? error; MagicErrorEvent(this.error); diff --git a/lib/services/w3m_service/i_w3m_service.dart b/lib/services/w3m_service/i_w3m_service.dart index 70f7f230..335acdaf 100644 --- a/lib/services/w3m_service/i_w3m_service.dart +++ b/lib/services/w3m_service/i_w3m_service.dart @@ -140,12 +140,7 @@ abstract class IW3MService with ChangeNotifier { abstract final Event onModalConnect; abstract final Event onModalDisconnect; abstract final Event onModalError; - // - @Deprecated('Use onModalConnect') - abstract final Event onSessionConnectEvent; - @Deprecated('Use onModalDisconnect') - abstract final Event onSessionDeleteEvent; abstract final Event onSessionExpireEvent; abstract final Event onSessionUpdateEvent; abstract final Event onSessionEventEvent; diff --git a/lib/services/w3m_service/w3m_service.dart b/lib/services/w3m_service/w3m_service.dart index 43daa271..48fd31e9 100644 --- a/lib/services/w3m_service/w3m_service.dart +++ b/lib/services/w3m_service/w3m_service.dart @@ -189,14 +189,14 @@ class W3MService with ChangeNotifier, CoinbaseService implements IW3MService { final cbWallet = await explorerService.instance.getCoinbaseWalletObject(); await cbInit(metadata: _web3App.metadata, cbWallet: cbWallet); } + await _web3App.init(); + _currentSession = await _getStoredSession(); - if (_currentSession?.sessionService.isMagic == true) { - await magicService.instance.init(); - // await magicService.instance.getUser(chainId: _currentSession?.chainId); - } else { - magicService.instance.init(); + if (_currentSession?.sessionService.isMagic == true || + _currentSession?.sessionService.isCoinbase == true) { + await _setSesionAndChainData(_currentSession!); } - await _web3App.init(); + magicService.instance.init(); await expirePreviousInactivePairings(); @@ -251,6 +251,15 @@ class W3MService with ChangeNotifier, CoinbaseService implements IW3MService { _notify(); } + Future _setSesionAndChainData(W3MSession w3mSession) async { + await _storeSession(w3mSession); + final chainId = w3mSession.chainId.toString(); + final chainInfo = + W3MChainPresets.chains[chainId] ?? W3MChainPresets.chains['1']!; + _setEthChain(chainInfo, logEvent: false); + // await selectChain(chainInfo); + } + Future _getStoredSession() async { try { final sessionString = storageService.instance.getString( @@ -726,7 +735,11 @@ class W3MService with ChangeNotifier, CoinbaseService implements IW3MService { } analyticsService.instance.sendEvent(DisconnectSuccessEvent()); - return await _cleanSession(); + if (!(_currentSession?.sessionService.isWC == true)) { + // if sessionService.isWC then _cleanSession() is being called on sessionDelete event + return await _cleanSession(); + } + return; } catch (e) { analyticsService.instance.sendEvent(DisconnectErrorEvent()); } @@ -903,22 +916,14 @@ class W3MService with ChangeNotifier, CoinbaseService implements IW3MService { @override final Event onModalError = Event(); - @Deprecated('Use onModalConnect') - @override - Event get onSessionConnectEvent => _web3App.onSessionConnect; - - @Deprecated('Use onModalDisconnect') @override - Event get onSessionDeleteEvent => _web3App.onSessionDelete; + final Event onSessionExpireEvent = Event(); @override - Event get onSessionExpireEvent => _web3App.onSessionExpire; + final Event onSessionUpdateEvent = Event(); @override - Event get onSessionUpdateEvent => _web3App.onSessionUpdate; - - @override - Event get onSessionEventEvent => _web3App.onSessionEvent; + final Event onSessionEventEvent = Event(); ////////* PRIVATE METHODS *///////// @@ -1095,7 +1100,7 @@ class W3MService with ChangeNotifier, CoinbaseService implements IW3MService { } } - Future _cleanSession() async { + Future _cleanSession({SessionDelete? args}) async { if (_currentSession?.sessionService.isCoinbase == true) { await cbResetSession(); } @@ -1107,6 +1112,12 @@ class W3MService with ChangeNotifier, CoinbaseService implements IW3MService { ); await storageService.instance.clearAll(); await explorerService.instance.storeRecentWalletId(walletId); + if (_currentSession != null) { + onModalDisconnect.broadcast(ModalDisconnect( + topic: args?.topic, + id: args?.id, + )); + } _currentSelectedChain = null; _isConnected = false; _currentSession = null; @@ -1124,6 +1135,7 @@ class W3MService with ChangeNotifier, CoinbaseService implements IW3MService { void _registerListeners() { // Magic + magicService.instance.onMagicConnect.subscribe(_onMagicConnectEvent); magicService.instance.onMagicLoginSuccess.subscribe(_onMagicLoginEvent); magicService.instance.onMagicError.subscribe(_onMagicErrorEvent); magicService.instance.onMagicUpdate.subscribe(_onMagicUpdateEvent); @@ -1136,8 +1148,9 @@ class W3MService with ChangeNotifier, CoinbaseService implements IW3MService { // _web3App.onSessionConnect.subscribe(_onSessionConnect); _web3App.onSessionDelete.subscribe(_onSessionDelete); - _web3App.onSessionEvent.subscribe(_onSessionEvent); + _web3App.onSessionExpire.subscribe(_onSessionExpire); _web3App.onSessionUpdate.subscribe(_onSessionUpdate); + _web3App.onSessionEvent.subscribe(_onSessionEvent); // Core _web3App.core.relayClient.onRelayClientConnect.subscribe( _onRelayClientConnect, @@ -1174,11 +1187,19 @@ class W3MService with ChangeNotifier, CoinbaseService implements IW3MService { } extension _W3MMagicExtension on W3MService { - Future _onMagicLoginEvent(MagicConnectEvent? args) async { + Future _onMagicConnectEvent(MagicConnectEvent? event) async { + if (event?.connected == false) { + if (_currentSession != null) { + onModalConnect.broadcast(ModalConnect(_currentSession!)); + } + } + } + + Future _onMagicLoginEvent(MagicLoginEvent? args) async { loggerService.instance.i('[$runtimeType] onMagicLoginSuccess $args'); if (args != null) { final session = W3MSession(magicData: args.data); - await _storeSession(session); + await _setSesionAndChainData(session); onModalConnect.broadcast(ModalConnect(session)); if (_selectedWallet == null) { await storageService.instance.clearKey(StringConstants.recentWalletId); @@ -1186,9 +1207,6 @@ extension _W3MMagicExtension on W3MService { StringConstants.connectedWalletData, ); } - final chainId = session.chainId.toString(); - final chainInfo = W3MChainPresets.chains[chainId]!; - _setEthChain(chainInfo, logEvent: false); if (_isOpen) { closeModal(); } @@ -1208,10 +1226,7 @@ extension _W3MMagicExtension on W3MService { address: newAddress, ), ); - await _storeSession(newSession); - final chainId = newSession.chainId.toString(); - final chainInfo = W3MChainPresets.chains[chainId]!; - _setEthChain(chainInfo, logEvent: true); + await _setSesionAndChainData(newSession); } } @@ -1235,26 +1250,14 @@ extension _W3MCoinbaseExtension on W3MService { loggerService.instance.i('[$runtimeType] onCoinbaseConnect: $args'); if (args != null) { final session = W3MSession(coinbaseData: args.data); - await _storeSession(session); + await _setSesionAndChainData(session); onModalConnect.broadcast(ModalConnect(session)); - final eChainId = session.chainId.toString(); - final chainInfo = - W3MChainPresets.chains[eChainId] ?? W3MChainPresets.chains['1']!; - await selectChain(chainInfo); if (_isOpen) { closeModal(); } } } - void _onCoinbaseErrorEvent(CoinbaseErrorEvent? args) async { - loggerService.instance.i('[$runtimeType] onCoinbaseError: ${args?.error}'); - final errorMessage = args?.error ?? 'Something went wrong'; - if (!errorMessage.toLowerCase().contains('user denied')) { - onModalError.broadcast(ModalError(errorMessage)); - } - } - void _onCoinbaseSessionUpdateEvent(CoinbaseSessionEvent? args) async { loggerService.instance.i('[$runtimeType] onCoinbaseSessionUpdate: $args'); if (args != null) { @@ -1268,7 +1271,9 @@ extension _W3MCoinbaseExtension on W3MService { chainName: chainInfo.chainName, chainId: int.parse(chainInfo.chainId), ); - await _storeSession(W3MSession(coinbaseData: newData)); + final session = W3MSession(coinbaseData: newData); + await _setSesionAndChainData(session); + // TODO onModalConnect.broadcast(ModalConnect(session)); } catch (e, s) { loggerService.instance.e( '[$runtimeType] onCoinbaseSessionUpdate: $e', @@ -1277,6 +1282,14 @@ extension _W3MCoinbaseExtension on W3MService { } } } + + void _onCoinbaseErrorEvent(CoinbaseErrorEvent? args) async { + loggerService.instance.i('[$runtimeType] onCoinbaseError: ${args?.error}'); + final errorMessage = args?.error ?? 'Something went wrong'; + if (!errorMessage.toLowerCase().contains('user denied')) { + onModalError.broadcast(ModalError(errorMessage)); + } + } } extension _W3MServiceExtension on W3MService { @@ -1284,7 +1297,7 @@ extension _W3MServiceExtension on W3MService { loggerService.instance.i('[$runtimeType] onSessionConnect: $args'); if (args != null) { final session = W3MSession(sessionData: args.session); - await _storeSession(session); + await _setSesionAndChainData(session); onModalConnect.broadcast(ModalConnect(session)); if (_selectedWallet == null) { // final walletName = args.session.peer.metadata.name; @@ -1306,8 +1319,6 @@ extension _W3MServiceExtension on W3MService { method: AnalyticsPlatform.mobile, )); } - await _selectChainFromStoredId(); - loadAccountData(); if (_isOpen) { closeModal(); } @@ -1316,6 +1327,7 @@ extension _W3MServiceExtension on W3MService { void _onSessionEvent(SessionEvent? args) async { loggerService.instance.i('[$runtimeType] onSessionEvent $args'); + onSessionEventEvent.broadcast(args); if (args?.name == EventsConstants.chainChanged) { final chainId = args?.data.toString() ?? ''; if (W3MChainPresets.chains.containsKey(chainId)) { @@ -1327,18 +1339,19 @@ extension _W3MServiceExtension on W3MService { void _onSessionUpdate(SessionUpdate? args) async { loggerService.instance.i('[$runtimeType] onSessionUpdate $args'); + onSessionUpdateEvent.broadcast(args); final wcSessions = _web3App.sessions.getAll(); - await _storeSession(W3MSession(sessionData: wcSessions.first)); - loadAccountData(); + final session = W3MSession(sessionData: wcSessions.first); + await _setSesionAndChainData(session); + } + + void _onSessionExpire(SessionExpire? args) { + onSessionExpireEvent.broadcast(args); } void _onSessionDelete(SessionDelete? args) { loggerService.instance.i('[$runtimeType] onSessionDelete: $args'); - onModalDisconnect.broadcast(ModalDisconnect( - topic: args?.topic, - id: args?.id, - )); - _cleanSession(); + _cleanSession(args: args); } void _onRelayClientConnect(EventArgs? args) async { diff --git a/lib/utils/w3m_logger.dart b/lib/utils/w3m_logger.dart index f7f0aee3..d8dbf7e1 100644 --- a/lib/utils/w3m_logger.dart +++ b/lib/utils/w3m_logger.dart @@ -9,7 +9,7 @@ class W3MLoggerUtil { ); static void setLogLevel(LogLevel level, {bool debugMode = false}) { - if (kDebugMode && debugMode) { + if (kDebugMode && debugMode && level == LogLevel.error) { Logger.addLogListener((LogEvent event) => debugPrint('${event.message}')); } logger = Logger( diff --git a/lib/version.dart b/lib/version.dart index c78f0113..f4cc0945 100644 --- a/lib/version.dart +++ b/lib/version.dart @@ -1,2 +1,2 @@ // Generated code. Do not modify. -const packageVersion = '3.2.0-beta02'; +const packageVersion = '3.2.0-beta03'; diff --git a/pubspec.yaml b/pubspec.yaml index 8009a914..45e7e96e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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.2.0-beta02 +version: 3.2.0-beta03 repository: https://github.com/WalletConnect/Web3ModalFlutter environment: @@ -55,3 +55,10 @@ flutter: - assets/png/2.0x/ - assets/png/3.0x/ +platforms: + android: + ios: + # web: + # linux: + # macos: + # windows: \ No newline at end of file diff --git a/test/mock_classes.mocks.dart b/test/mock_classes.mocks.dart index 93aebdaf..eed8c230 100644 --- a/test/mock_classes.mocks.dart +++ b/test/mock_classes.mocks.dart @@ -512,43 +512,6 @@ class MockW3MService extends _i1.Mock implements _i3.W3MService { ), ) as _i3.Event<_i3.ModalError>); @override - _i15.W3MServiceStatus get status => (super.noSuchMethod( - Invocation.getter(#status), - returnValue: _i15.W3MServiceStatus.idle, - ) as _i15.W3MServiceStatus); - @override - bool get hasNamespaces => (super.noSuchMethod( - Invocation.getter(#hasNamespaces), - returnValue: false, - ) as bool); - @override - bool get isOpen => (super.noSuchMethod( - Invocation.getter(#isOpen), - returnValue: false, - ) as bool); - @override - bool get isConnected => (super.noSuchMethod( - Invocation.getter(#isConnected), - returnValue: false, - ) as bool); - @override - _i3.Event<_i3.SessionConnect> get onSessionConnectEvent => - (super.noSuchMethod( - Invocation.getter(#onSessionConnectEvent), - returnValue: _FakeEvent_1<_i3.SessionConnect>( - this, - Invocation.getter(#onSessionConnectEvent), - ), - ) as _i3.Event<_i3.SessionConnect>); - @override - _i3.Event<_i3.SessionDelete> get onSessionDeleteEvent => (super.noSuchMethod( - Invocation.getter(#onSessionDeleteEvent), - returnValue: _FakeEvent_1<_i3.SessionDelete>( - this, - Invocation.getter(#onSessionDeleteEvent), - ), - ) as _i3.Event<_i3.SessionDelete>); - @override _i3.Event<_i3.SessionExpire> get onSessionExpireEvent => (super.noSuchMethod( Invocation.getter(#onSessionExpireEvent), returnValue: _FakeEvent_1<_i3.SessionExpire>( @@ -573,6 +536,26 @@ class MockW3MService extends _i1.Mock implements _i3.W3MService { ), ) as _i3.Event<_i3.SessionEvent>); @override + _i15.W3MServiceStatus get status => (super.noSuchMethod( + Invocation.getter(#status), + returnValue: _i15.W3MServiceStatus.idle, + ) as _i15.W3MServiceStatus); + @override + bool get hasNamespaces => (super.noSuchMethod( + Invocation.getter(#hasNamespaces), + returnValue: false, + ) as bool); + @override + bool get isOpen => (super.noSuchMethod( + Invocation.getter(#isOpen), + returnValue: false, + ) as bool); + @override + bool get isConnected => (super.noSuchMethod( + Invocation.getter(#isConnected), + returnValue: false, + ) as bool); + @override bool get hasListeners => (super.noSuchMethod( Invocation.getter(#hasListeners), returnValue: false,