From 47548d7a711a0f14ba3a3c74703f85adaa87fa05 Mon Sep 17 00:00:00 2001 From: Alfreedom <00tango.bromine@icloud.com> Date: Thu, 4 Jul 2024 17:38:51 +0200 Subject: [PATCH] Added context param on W3MService as non-breaking required change and bug fixes --- .github/workflows/build-android-debug.yml | 5 +- .github/workflows/build-android-internal.yml | 5 +- .github/workflows/build-android.yml | 5 +- .github/workflows/build-ios-debug.yml | 5 +- .github/workflows/build-ios-internal.yml | 5 +- .github/workflows/build-ios.yml | 6 +- CHANGELOG.md | 2 +- example/android/gradle.properties | 2 +- example/ios/Podfile.lock | 6 - example/ios/Runner.xcodeproj/project.pbxproj | 12 +- example/ios/Runner/Info.plist | 2 +- example/lib/home_page.dart | 107 +- example/lib/utils/crypto/siwe_service.dart | 85 +- .../Flutter/GeneratedPluginRegistrant.swift | 2 - example/pubspec.lock | 10 +- ios/Podfile.lock | 6 - lib/pages/approve_siwe.dart | 7 + .../models/analytics_event.dart | 92 ++ .../blockchain_identity.freezed.dart | 169 --- .../blockchain_identity.g.dart | 23 - .../magic_service/models/frame_message.dart | 1 - .../network_service/network_service.dart | 1 - .../siwe_service/models/w3m_siwe.dart | 8 - .../siwe_service/models/w3m_siwe.freezed.dart | 6 +- .../siwe_service/models/w3m_siwe.g.dart | 60 +- lib/services/w3m_service/i_w3m_service.dart | 12 +- .../w3m_service/models/w3m_siwe.freezed.dart | 1077 ----------------- .../w3m_service/models/w3m_siwe.g.dart | 126 -- lib/services/w3m_service/w3m_service.dart | 108 +- lib/version.dart | 2 +- lib/web3modal_flutter.dart | 1 + lib/widgets/avatars/w3m_account_avatar.dart | 1 - lib/widgets/buttons/address_button.dart | 1 - lib/widgets/text/w3m_address.dart | 1 - lib/widgets/w3m_account_button.dart | 33 +- lib/widgets/w3m_connect_wallet_button.dart | 8 +- lib/widgets/w3m_network_select_button.dart | 31 +- macos/Flutter/GeneratedPluginRegistrant.swift | 2 - pubspec.lock | 8 - pubspec.yaml | 3 +- test/mock_classes.mocks.dart | 19 + .../w3m_account_page_ui_test.dart | 1 - test/w3m_connect/w3m_connect_ui_test.dart | 1 - 43 files changed, 431 insertions(+), 1636 deletions(-) delete mode 100644 lib/services/blockchain_service/blockchain_identity.freezed.dart delete mode 100644 lib/services/blockchain_service/blockchain_identity.g.dart delete mode 100644 lib/services/w3m_service/models/w3m_siwe.freezed.dart delete mode 100644 lib/services/w3m_service/models/w3m_siwe.g.dart diff --git a/.github/workflows/build-android-debug.yml b/.github/workflows/build-android-debug.yml index 851929c7..cc54ecfe 100644 --- a/.github/workflows/build-android-debug.yml +++ b/.github/workflows/build-android-debug.yml @@ -65,6 +65,9 @@ jobs: working-directory: example env: PROJECT_ID: ${{ secrets.PROJECT_ID }} + APPKIT_AUTH: ${{ secrets.APPKIT_AUTH }} + APPKIT_PROJECT_ID: ${{ secrets.APPKIT_PROJECT_ID }} + AUTH_SERVICE_URL: ${{ secrets.AUTH_SERVICE_URL }} run: | # Get app version from file GRADLE_FILE=android/gradle.properties @@ -86,7 +89,7 @@ jobs: NEXT_BUILD=$(grep 'versionCode' $GRADLE_FILE | cut -d'=' -f2) # Build Android app with flutter - flutter build apk --build-name $VERSION --build-number $NEXT_BUILD --dart-define="PROJECT_ID=$PROJECT_ID" --flavor alpha --release + flutter build apk --build-name $VERSION --build-number $NEXT_BUILD --dart-define="PROJECT_ID=$PROJECT_ID" --dart-define="APPKIT_AUTH=$APPKIT_AUTH" --dart-define="APPKIT_PROJECT_ID=$APPKIT_PROJECT_ID" --dart-define="AUTH_SERVICE_URL=$AUTH_SERVICE_URL" --flavor alpha --release # Setup Node - name: Setup Node diff --git a/.github/workflows/build-android-internal.yml b/.github/workflows/build-android-internal.yml index 6b31a7c6..c73ba585 100644 --- a/.github/workflows/build-android-internal.yml +++ b/.github/workflows/build-android-internal.yml @@ -65,6 +65,9 @@ jobs: working-directory: example env: PROJECT_ID: ${{ secrets.PROJECT_ID }} + APPKIT_AUTH: ${{ secrets.APPKIT_AUTH }} + APPKIT_PROJECT_ID: ${{ secrets.APPKIT_PROJECT_ID }} + AUTH_SERVICE_URL: ${{ secrets.AUTH_SERVICE_URL }} run: | # Get app version from file GRADLE_FILE=android/gradle.properties @@ -82,7 +85,7 @@ jobs: NEXT_BUILD=$(grep 'versionCode' $GRADLE_FILE | cut -d'=' -f2) # Build Android app with flutter - flutter build apk --build-name $VERSION --build-number $NEXT_BUILD --dart-define="PROJECT_ID=$PROJECT_ID" --release --flavor beta + flutter build apk --build-name $VERSION --build-number $NEXT_BUILD --dart-define="PROJECT_ID=$PROJECT_ID" --dart-define="APPKIT_AUTH=$APPKIT_AUTH" --dart-define="APPKIT_PROJECT_ID=$APPKIT_PROJECT_ID" --dart-define="AUTH_SERVICE_URL=$AUTH_SERVICE_URL" --release --flavor beta # Setup Node - name: Setup Node diff --git a/.github/workflows/build-android.yml b/.github/workflows/build-android.yml index 9ba90695..f1b17ad8 100644 --- a/.github/workflows/build-android.yml +++ b/.github/workflows/build-android.yml @@ -65,6 +65,9 @@ jobs: working-directory: example env: PROJECT_ID: ${{ secrets.PROJECT_ID }} + APPKIT_AUTH: ${{ secrets.APPKIT_AUTH }} + APPKIT_PROJECT_ID: ${{ secrets.APPKIT_PROJECT_ID }} + AUTH_SERVICE_URL: ${{ secrets.AUTH_SERVICE_URL }} run: | # Get app version from file GRADLE_FILE=android/gradle.properties @@ -82,7 +85,7 @@ jobs: NEXT_BUILD=$(grep 'versionCode' $GRADLE_FILE | cut -d'=' -f2) # Build Android app with flutter - flutter build apk --build-name $VERSION --build-number $NEXT_BUILD --dart-define="PROJECT_ID=$PROJECT_ID" --release --flavor stable + flutter build apk --build-name $VERSION --build-number $NEXT_BUILD --dart-define="PROJECT_ID=$PROJECT_ID" --dart-define="APPKIT_AUTH=$APPKIT_AUTH" --dart-define="APPKIT_PROJECT_ID=$APPKIT_PROJECT_ID" --dart-define="AUTH_SERVICE_URL=$AUTH_SERVICE_URL" --release --flavor stable # Setup Node - name: Setup Node diff --git a/.github/workflows/build-ios-debug.yml b/.github/workflows/build-ios-debug.yml index 116c49a5..a7895e10 100644 --- a/.github/workflows/build-ios-debug.yml +++ b/.github/workflows/build-ios-debug.yml @@ -83,6 +83,9 @@ jobs: PROJECT_ID: ${{ secrets.PROJECT_ID }} APP_STORE_KEY_ID: ${{ secrets.APP_STORE_KEY_ID }} APPLE_ISSUER_ID: ${{ secrets.APPLE_ISSUER_ID }} + APPKIT_AUTH: ${{ secrets.APPKIT_AUTH }} + APPKIT_PROJECT_ID: ${{ secrets.APPKIT_PROJECT_ID }} + AUTH_SERVICE_URL: ${{ secrets.AUTH_SERVICE_URL }} run: | # Get app version from file FILE_VALUE=$(echo | grep "^version: " pubspec.yaml) @@ -98,7 +101,7 @@ jobs: sed -i '' 's/FlutterAppStoreProfileWithPush/FlutterAppStoreProfileDebug/g' ios/Runner.xcodeproj/project.pbxproj # Build ios app with flutter - flutter build ios --build-name $VERSION_NUMBER --dart-define="PROJECT_ID=$PROJECT_ID" --config-only --release + flutter build ios --build-name $VERSION_NUMBER --dart-define="PROJECT_ID=$PROJECT_ID" --dart-define="APPKIT_AUTH=$APPKIT_AUTH" --dart-define="APPKIT_PROJECT_ID=$APPKIT_PROJECT_ID" --dart-define="AUTH_SERVICE_URL=$AUTH_SERVICE_URL" --config-only --release cd ios agvtool new-marketing-version $VERSION_NUMBER diff --git a/.github/workflows/build-ios-internal.yml b/.github/workflows/build-ios-internal.yml index f4348421..292a5ebf 100644 --- a/.github/workflows/build-ios-internal.yml +++ b/.github/workflows/build-ios-internal.yml @@ -82,6 +82,9 @@ jobs: PROJECT_ID: ${{ secrets.PROJECT_ID }} APP_STORE_KEY_ID: ${{ secrets.APP_STORE_KEY_ID }} APPLE_ISSUER_ID: ${{ secrets.APPLE_ISSUER_ID }} + APPKIT_AUTH: ${{ secrets.APPKIT_AUTH }} + APPKIT_PROJECT_ID: ${{ secrets.APPKIT_PROJECT_ID }} + AUTH_SERVICE_URL: ${{ secrets.AUTH_SERVICE_URL }} run: | # Get app version from file FILE_VALUE=$(echo | grep "^version: " pubspec.yaml) @@ -97,7 +100,7 @@ jobs: sed -i '' 's/FlutterAppStoreProfileWithPush/FlutterAppStoreProfileInternal/g' ios/Runner.xcodeproj/project.pbxproj # Build ios app with flutter - flutter build ios --build-name $VERSION_NUMBER --dart-define="PROJECT_ID=$PROJECT_ID" --config-only --release + flutter build ios --build-name $VERSION_NUMBER --dart-define="PROJECT_ID=$PROJECT_ID" --dart-define="APPKIT_AUTH=$APPKIT_AUTH" --dart-define="APPKIT_PROJECT_ID=$APPKIT_PROJECT_ID" --dart-define="AUTH_SERVICE_URL=$AUTH_SERVICE_URL" --config-only --release cd ios agvtool new-marketing-version $VERSION_NUMBER diff --git a/.github/workflows/build-ios.yml b/.github/workflows/build-ios.yml index a1dc4d4b..0f8d2cfa 100644 --- a/.github/workflows/build-ios.yml +++ b/.github/workflows/build-ios.yml @@ -82,6 +82,9 @@ jobs: PROJECT_ID: ${{ secrets.PROJECT_ID }} APP_STORE_KEY_ID: ${{ secrets.APP_STORE_KEY_ID }} APPLE_ISSUER_ID: ${{ secrets.APPLE_ISSUER_ID }} + APPKIT_AUTH: ${{ secrets.APPKIT_AUTH }} + APPKIT_PROJECT_ID: ${{ secrets.APPKIT_PROJECT_ID }} + AUTH_SERVICE_URL: ${{ secrets.AUTH_SERVICE_URL }} run: | # Get app version from file FILE_VALUE=$(echo | grep "^version: " pubspec.yaml) @@ -90,8 +93,7 @@ jobs: VERSION_NUMBER=(${FULL_VERSION//-/ }) # Build ios app with flutter - # echo "flutter build ios --build-name $VERSION_NUMBER --dart-define=\"PROJECT_ID=$PROJECT_ID\" --config-only --release" - flutter build ios --build-name $VERSION_NUMBER --dart-define="PROJECT_ID=$PROJECT_ID" --config-only --release + flutter build ios --build-name $VERSION_NUMBER --dart-define="PROJECT_ID=$PROJECT_ID" --dart-define="APPKIT_AUTH=$APPKIT_AUTH" --dart-define="APPKIT_PROJECT_ID=$APPKIT_PROJECT_ID" --dart-define="AUTH_SERVICE_URL=$AUTH_SERVICE_URL" --config-only --release cd ios agvtool new-marketing-version $VERSION_NUMBER diff --git a/CHANGELOG.md b/CHANGELOG.md index 93fd1c9c..6c80ddcd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -## 3.3.0-beta01 +## 3.3.0-beta02 - One-Click Auth + SIWE implementation - Coinbase Wallet dependency update diff --git a/example/android/gradle.properties b/example/android/gradle.properties index 65662b88..07ceccf9 100644 --- a/example/android/gradle.properties +++ b/example/android/gradle.properties @@ -2,4 +2,4 @@ org.gradle.jvmargs=-Xmx1536M android.useAndroidX=true android.enableJetifier=true versionName=3.3.0 -versionCode=62 +versionCode=63 diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index 10a787fe..e75e6ff7 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -8,8 +8,6 @@ PODS: - CoinbaseWalletSDK/CrossPlatform (1.0.4): - CoinbaseWalletSDK/Client - Flutter (1.0.0) - - flutter_timezone (0.0.1): - - Flutter - FMDB (2.7.5): - FMDB/standard (= 2.7.5) - FMDB/standard (2.7.5) @@ -33,7 +31,6 @@ DEPENDENCIES: - appcheck (from `.symlinks/plugins/appcheck/ios`) - coinbase_wallet_sdk (from `.symlinks/plugins/coinbase_wallet_sdk/ios`) - Flutter (from `Flutter`) - - flutter_timezone (from `.symlinks/plugins/flutter_timezone/ios`) - package_info_plus (from `.symlinks/plugins/package_info_plus/ios`) - path_provider_foundation (from `.symlinks/plugins/path_provider_foundation/darwin`) - shared_preferences_foundation (from `.symlinks/plugins/shared_preferences_foundation/darwin`) @@ -53,8 +50,6 @@ EXTERNAL SOURCES: :path: ".symlinks/plugins/coinbase_wallet_sdk/ios" Flutter: :path: Flutter - flutter_timezone: - :path: ".symlinks/plugins/flutter_timezone/ios" package_info_plus: :path: ".symlinks/plugins/package_info_plus/ios" path_provider_foundation: @@ -73,7 +68,6 @@ SPEC CHECKSUMS: coinbase_wallet_sdk: 7ccd4e1a7940deba6ba9bd81beece999a2268c15 CoinbaseWalletSDK: ea1f37512bbc69ebe07416e3b29bf840f5cc3152 Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7 - flutter_timezone: ffb07bdad3c6276af8dada0f11978d8a1f8a20bb FMDB: 2ce00b547f966261cd18927a3ddb07cb6f3db82a package_info_plus: 58f0028419748fad15bf008b270aaa8e54380b1c path_provider_foundation: 29f094ae23ebbca9d3d0cec13889cd9060c0e943 diff --git a/example/ios/Runner.xcodeproj/project.pbxproj b/example/ios/Runner.xcodeproj/project.pbxproj index e8822df8..0761fd26 100644 --- a/example/ios/Runner.xcodeproj/project.pbxproj +++ b/example/ios/Runner.xcodeproj/project.pbxproj @@ -470,7 +470,7 @@ CLANG_ENABLE_MODULES = YES; CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements; CODE_SIGN_STYLE = Manual; - CURRENT_PROJECT_VERSION = 62; + CURRENT_PROJECT_VERSION = 63; DEVELOPMENT_TEAM = ""; "DEVELOPMENT_TEAM[sdk=iphoneos*]" = W5R8AG9K22; ENABLE_BITCODE = NO; @@ -496,7 +496,7 @@ buildSettings = { BUNDLE_LOADER = "$(TEST_HOST)"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 62; + CURRENT_PROJECT_VERSION = 63; GENERATE_INFOPLIST_FILE = YES; MARKETING_VERSION = 1.0; PRODUCT_BUNDLE_IDENTIFIER = com.web3modal.flutterExample.RunnerTests; @@ -514,7 +514,7 @@ buildSettings = { BUNDLE_LOADER = "$(TEST_HOST)"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 62; + CURRENT_PROJECT_VERSION = 63; GENERATE_INFOPLIST_FILE = YES; MARKETING_VERSION = 1.0; PRODUCT_BUNDLE_IDENTIFIER = com.web3modal.flutterExample.RunnerTests; @@ -530,7 +530,7 @@ buildSettings = { BUNDLE_LOADER = "$(TEST_HOST)"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 62; + CURRENT_PROJECT_VERSION = 63; GENERATE_INFOPLIST_FILE = YES; MARKETING_VERSION = 1.0; PRODUCT_BUNDLE_IDENTIFIER = com.web3modal.flutterExample.RunnerTests; @@ -655,7 +655,7 @@ CLANG_ENABLE_MODULES = YES; CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements; CODE_SIGN_STYLE = Manual; - CURRENT_PROJECT_VERSION = 62; + CURRENT_PROJECT_VERSION = 63; DEVELOPMENT_TEAM = ""; "DEVELOPMENT_TEAM[sdk=iphoneos*]" = W5R8AG9K22; ENABLE_BITCODE = NO; @@ -686,7 +686,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution"; CODE_SIGN_STYLE = Manual; - CURRENT_PROJECT_VERSION = 62; + CURRENT_PROJECT_VERSION = 63; DEVELOPMENT_TEAM = ""; "DEVELOPMENT_TEAM[sdk=iphoneos*]" = W5R8AG9K22; ENABLE_BITCODE = NO; diff --git a/example/ios/Runner/Info.plist b/example/ios/Runner/Info.plist index 58fd63ff..dd9cbf7a 100644 --- a/example/ios/Runner/Info.plist +++ b/example/ios/Runner/Info.plist @@ -36,7 +36,7 @@ CFBundleVersion - 62 + 63 ITSAppUsesNonExemptEncryption LSApplicationQueriesSchemes diff --git a/example/lib/home_page.dart b/example/lib/home_page.dart index 191d288d..be625cc5 100644 --- a/example/lib/home_page.dart +++ b/example/lib/home_page.dart @@ -26,6 +26,7 @@ class _MyHomePageState extends State { final overlay = OverlayController(const Duration(milliseconds: 200)); late W3MService _w3mService; late SIWESampleWebService _siweTestService; + bool _initialized = false; @override void initState() { @@ -55,7 +56,6 @@ class _MyHomePageState extends State { ); SIWEConfig get _siweConfig => SIWEConfig( - context: context, getNonce: () async { // this has to be called at the very moment of creating the pairing uri try { @@ -75,7 +75,7 @@ class _MyHomePageState extends State { return SIWEMessageArgs( domain: uri.authority, uri: 'https://walletconnect.com/login', - statement: 'Welcome to AppKit for Flutter.', + statement: 'Welcome to AppKit $packageVersion for Flutter.', methods: MethodsConstants.allMethods, ); }, @@ -91,7 +91,7 @@ class _MyHomePageState extends State { debugPrint('[SIWEConfig] verifyMessage()'); final payload = args.toJson(); final uri = Uri.parse(_pairingMetadata.redirect!.universal!); - final result = await _siweTestService.authenticate( + final result = await _siweTestService.verifyMessage( payload, domain: uri.authority, ); @@ -120,7 +120,7 @@ class _MyHomePageState extends State { // Return proper session from your Web Service try { debugPrint('[SIWEConfig] getSession()'); - final session = await _siweTestService.getAppKitAuthSession(); + final session = await _siweTestService.getSession(); final address = session['address']!.toString(); final chainId = session['chainId']!.toString(); return SIWESession(address: address, chains: [chainId]); @@ -140,7 +140,7 @@ class _MyHomePageState extends State { // Called when user taps on disconnect button try { debugPrint('[SIWEConfig] signOut()'); - final _ = await _siweTestService.appKitAuthSignOut(); + final _ = await _siweTestService.signOut(); return true; } catch (error) { debugPrint('[SIWEConfig] signOut error: $error'); @@ -165,29 +165,36 @@ class _MyHomePageState extends State { W3MChainPresets.chains.addAll(W3MChainPresets.extraChains); W3MChainPresets.chains.addAll(W3MChainPresets.testChains); - _w3mService = W3MService( - projectId: DartDefines.projectId, - logLevel: LogLevel.error, - metadata: _pairingMetadata, - siweConfig: _siweConfig, - enableAnalytics: true, // OPTIONAL - null by default - enableEmail: true, // OPTIONAL - false by default - // requiredNamespaces: {}, - // optionalNamespaces: {}, - // includedWalletIds: {}, - featuredWalletIds: { - 'fd20dc426fb37566d803205b19bbc1d4096b248ac04548e3cfb6b3a38bd033aa', // Coinbase - '18450873727504ae9315a084fa7624b5297d2fe5880f0982979c17345a138277', // Kraken Wallet - 'c57ca95b47569778a828d19178114f4db188b89b763c899ba0be274e97267d96', // Metamask - '1ae92b26df02f0abca6304df07debccd18262fdf5fe82daa81593582dac9a369', // Rainbow - 'c03dfee351b6fcc421b4494ea33b9d4b92a984f87aa76d1663bb28705e95034a', // Uniswap - '38f5d18bd8522c244bdd70cb4a68e0e718865155811c043f052fb9f1c51de662', // Bitget - }, - // excludedWalletIds: { - // 'fd20dc426fb37566d803205b19bbc1d4096b248ac04548e3cfb6b3a38bd033aa', // Coinbase - // }, - // MORE WALLETS https://explorer.walletconnect.com/?type=wallet&chains=eip155%3A1 - ); + try { + _w3mService = W3MService( + context: context, + projectId: DartDefines.projectId, + logLevel: LogLevel.error, + metadata: _pairingMetadata, + siweConfig: _siweConfig, + enableAnalytics: true, // OPTIONAL - null by default + enableEmail: true, // OPTIONAL - false by default + // requiredNamespaces: {}, + // optionalNamespaces: {}, + // includedWalletIds: {}, + featuredWalletIds: { + 'fd20dc426fb37566d803205b19bbc1d4096b248ac04548e3cfb6b3a38bd033aa', // Coinbase + '18450873727504ae9315a084fa7624b5297d2fe5880f0982979c17345a138277', // Kraken Wallet + 'c57ca95b47569778a828d19178114f4db188b89b763c899ba0be274e97267d96', // Metamask + '1ae92b26df02f0abca6304df07debccd18262fdf5fe82daa81593582dac9a369', // Rainbow + 'c03dfee351b6fcc421b4494ea33b9d4b92a984f87aa76d1663bb28705e95034a', // Uniswap + '38f5d18bd8522c244bdd70cb4a68e0e718865155811c043f052fb9f1c51de662', // Bitget + }, + // excludedWalletIds: { + // 'fd20dc426fb37566d803205b19bbc1d4096b248ac04548e3cfb6b3a38bd033aa', // Coinbase + // }, + // MORE WALLETS https://explorer.walletconnect.com/?type=wallet&chains=eip155%3A1 + ); + setState(() => _initialized = true); + } on W3MServiceException catch (e) { + debugPrint('⛔️ ${e.message}'); + return; + } // modal specific subscriptions _w3mService.onModalConnect.subscribe(_onModalConnect); _w3mService.onModalUpdate.subscribe(_onModalUpdate); @@ -380,26 +387,28 @@ class _MyHomePageState extends State { ), ], ), - body: RefreshIndicator( - onRefresh: () => _refreshData(), - child: SingleChildScrollView( - child: Column( - mainAxisAlignment: MainAxisAlignment.start, - children: [ - const SizedBox.square(dimension: 4.0), - Text( - 'Custom theme is: ${isCustom ? 'ON' : 'OFF'}', - style: TextStyle( - color: Web3ModalTheme.colorsOf(context).foreground100, + body: !_initialized + ? const SizedBox.shrink() + : RefreshIndicator( + onRefresh: () => _refreshData(), + child: SingleChildScrollView( + child: Column( + mainAxisAlignment: MainAxisAlignment.start, + children: [ + const SizedBox.square(dimension: 4.0), + Text( + 'v$packageVersion', + style: TextStyle( + color: Web3ModalTheme.colorsOf(context).foreground100, + ), + ), + _ButtonsView(w3mService: _w3mService), + const Divider(height: 0.0, color: Colors.transparent), + _ConnectedView(w3mService: _w3mService) + ], ), ), - _ButtonsView(w3mService: _w3mService), - const Divider(height: 0.0, color: Colors.transparent), - _ConnectedView(w3mService: _w3mService) - ], - ), - ), - ), + ), ); } @@ -428,7 +437,7 @@ class _ButtonsView extends StatelessWidget { // custom: ElevatedButton( // style: buttonStyle(context), // onPressed: () { - // w3mService.openNetworks(context); + // w3mService.openNetworksView(); // }, // child: const Text('OPEN CHAINS'), // ), @@ -442,7 +451,7 @@ class _ButtonsView extends StatelessWidget { // custom: ElevatedButton( // style: buttonStyle(context), // onPressed: () { - // w3mService.openModal(context); + // w3mService.openModalView(); // }, // child: w3mService.isConnected // ? Text(Util.truncate(w3mService.session!.address!)) @@ -477,7 +486,7 @@ class _ConnectedView extends StatelessWidget { // custom: ElevatedButton( // style: buttonStyle(context), // onPressed: () { - // w3mService.openModal(context); + // w3mService.openModalView(); // }, // child: Text(balance), // ), diff --git a/example/lib/utils/crypto/siwe_service.dart b/example/lib/utils/crypto/siwe_service.dart index 38354606..f17164cf 100644 --- a/example/lib/utils/crypto/siwe_service.dart +++ b/example/lib/utils/crypto/siwe_service.dart @@ -5,25 +5,47 @@ import 'dart:convert'; import 'package:walletconnect_flutter_dapp/utils/dart_defines.dart'; import 'package:web3modal_flutter/utils/core/core_utils_singleton.dart'; +import 'package:web3modal_flutter/web3modal_flutter.dart'; class SIWESampleWebService { - late Map _headers; + Map? _headers; SIWESampleWebService() { - _headers = coreUtils.instance.getAPIHeaders( - DartDefines.appKitProjectId, - ); + _headers = { + ...coreUtils.instance.getAPIHeaders( + DartDefines.appKitProjectId, + ), + 'Content-Type': 'application/json', + }; + } + + Future _checkHeaders() async { + final instance = await SharedPreferences.getInstance(); + final headers = instance.getString('w3m_siwe_headers'); + if (headers != null) { + _headers = { + ...(jsonDecode(headers) as Map), + 'Content-Type': 'application/json', + }; + } + } + + Future _persistHeaders() async { + final instance = await SharedPreferences.getInstance(); + await instance.setString('w3m_siwe_headers', jsonEncode(_headers)); } Future> getNonce() async { try { - final res = await http.get( + final response = await http.get( Uri.parse('${DartDefines.authApiUrl}/auth/v1/nonce'), headers: _headers, ); - final nonceRes = json.decode(res.body) as Map; + debugPrint('[SIWESERVICE] getNonce() => ${response.body}'); + final nonceRes = jsonDecode(response.body) as Map; final newToken = nonceRes['token'] as String; - _headers['Authorization'] = 'Bearer $newToken'; + _headers!['Authorization'] = 'Bearer $newToken'; + await _persistHeaders(); // Persist the newToken so it can be used again with getSession() even if the user terminated the app return nonceRes; } catch (error) { @@ -32,77 +54,70 @@ class SIWESampleWebService { } } - Future> getAppKitAuthSession() async { + Future> getSession() async { try { + await _checkHeaders(); final response = await http.get( Uri.parse('${DartDefines.authApiUrl}/auth/v1/me'), headers: _headers, ); - if (response.statusCode == 200) { - return json.decode(response.body); - } - throw Exception(response.statusCode.toString()); + debugPrint('[SIWESERVICE] getSession() => ${response.body}'); + return jsonDecode(response.body) as Map; } catch (error) { - debugPrint( - '[SIWESERVICE] ⛔️ getAppKitAuthSession() => ${error.toString()}'); + debugPrint('[SIWESERVICE] ⛔️ getSession() => ${error.toString()}'); rethrow; } } - Future> authenticate( + Future> verifyMessage( Map payload, { required String domain, }) async { try { final uri = Uri.parse('${DartDefines.authApiUrl}/auth/v1/authenticate'); - final res = await http.post( + final response = await http.post( uri.replace(queryParameters: {'domain': domain}), - headers: { - ..._headers, - 'Content-Type': 'application/json', - }, + headers: _headers, body: jsonEncode(payload), ); - debugPrint(jsonEncode(payload)); - debugPrint(res.request?.url.toString()); - debugPrint(jsonEncode(res.request?.headers)); - debugPrint(res.body); - final authenticateRes = jsonDecode(res.body); + debugPrint('[SIWESERVICE] verifyMessage() => ${response.body}'); + final authenticateRes = jsonDecode(response.body) as Map; final newToken = authenticateRes['token'] as String; - _headers['Authorization'] = 'Bearer $newToken'; + _headers!['Authorization'] = 'Bearer $newToken'; + await _persistHeaders(); // Persist the newToken so it can be used again with getSession() even if the user terminated the app return authenticateRes; } catch (error) { - debugPrint('[SIWESERVICE] ⛔️ authenticate() => ${error.toString()}'); + debugPrint('[SIWESERVICE] ⛔️ verifyMessage() => ${error.toString()}'); rethrow; } } Future> updateUser(Map data) async { try { - final res = await http.post( + final response = await http.post( Uri.parse('${DartDefines.authApiUrl}/auth/v1/update-user'), headers: _headers, body: json.encode({'metadata': data}), ); - final updateUserRes = json.decode(res.body); - return updateUserRes; + debugPrint('[SIWESERVICE] updateUser() => ${response.body}'); + return jsonDecode(response.body) as Map; } catch (error) { debugPrint('[SIWESERVICE] ⛔️ updateUser() => ${error.toString()}'); rethrow; } } - Future> appKitAuthSignOut() async { + Future> signOut() async { try { - final res = await http.post( + final response = await http.post( Uri.parse('${DartDefines.authApiUrl}/auth/v1/sign-out'), headers: _headers, ); - final signOutRes = json.decode(res.body) as Map; - return signOutRes; + debugPrint('[SIWESERVICE] signOut() => ${response.body}'); + return jsonDecode(response.body) as Map; } catch (error) { - debugPrint('[SIWESERVICE] ⛔️ appKitAuthSignOut() => ${error.toString()}'); + debugPrint('[SIWESERVICE] ⛔️ signOut() => ${error.toString()}'); rethrow; } } diff --git a/example/macos/Flutter/GeneratedPluginRegistrant.swift b/example/macos/Flutter/GeneratedPluginRegistrant.swift index 03439581..3ebb6b9e 100644 --- a/example/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/example/macos/Flutter/GeneratedPluginRegistrant.swift @@ -5,7 +5,6 @@ import FlutterMacOS import Foundation -import flutter_timezone import package_info_plus import path_provider_foundation import shared_preferences_foundation @@ -13,7 +12,6 @@ import sqflite import url_launcher_macos func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { - FlutterTimezonePlugin.register(with: registry.registrar(forPlugin: "FlutterTimezonePlugin")) FPPPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FPPPackageInfoPlusPlugin")) PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin")) SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin")) diff --git a/example/pubspec.lock b/example/pubspec.lock index 55d82b23..10af5ecb 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -387,14 +387,6 @@ packages: description: flutter source: sdk version: "0.0.0" - flutter_timezone: - dependency: transitive - description: - name: flutter_timezone - sha256: "06b35132c98fa188db3c4b654b7e1af7ccd01dfe12a004d58be423357605fb24" - url: "https://pub.dev" - source: hosted - version: "1.0.8" flutter_web_plugins: dependency: transitive description: flutter @@ -1139,7 +1131,7 @@ packages: path: ".." relative: true source: path - version: "3.3.0-beta01" + version: "3.3.0-beta02" web_socket_channel: dependency: transitive description: diff --git a/ios/Podfile.lock b/ios/Podfile.lock index 10a787fe..e75e6ff7 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -8,8 +8,6 @@ PODS: - CoinbaseWalletSDK/CrossPlatform (1.0.4): - CoinbaseWalletSDK/Client - Flutter (1.0.0) - - flutter_timezone (0.0.1): - - Flutter - FMDB (2.7.5): - FMDB/standard (= 2.7.5) - FMDB/standard (2.7.5) @@ -33,7 +31,6 @@ DEPENDENCIES: - appcheck (from `.symlinks/plugins/appcheck/ios`) - coinbase_wallet_sdk (from `.symlinks/plugins/coinbase_wallet_sdk/ios`) - Flutter (from `Flutter`) - - flutter_timezone (from `.symlinks/plugins/flutter_timezone/ios`) - package_info_plus (from `.symlinks/plugins/package_info_plus/ios`) - path_provider_foundation (from `.symlinks/plugins/path_provider_foundation/darwin`) - shared_preferences_foundation (from `.symlinks/plugins/shared_preferences_foundation/darwin`) @@ -53,8 +50,6 @@ EXTERNAL SOURCES: :path: ".symlinks/plugins/coinbase_wallet_sdk/ios" Flutter: :path: Flutter - flutter_timezone: - :path: ".symlinks/plugins/flutter_timezone/ios" package_info_plus: :path: ".symlinks/plugins/package_info_plus/ios" path_provider_foundation: @@ -73,7 +68,6 @@ SPEC CHECKSUMS: coinbase_wallet_sdk: 7ccd4e1a7940deba6ba9bd81beece999a2268c15 CoinbaseWalletSDK: ea1f37512bbc69ebe07416e3b29bf840f5cc3152 Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7 - flutter_timezone: ffb07bdad3c6276af8dada0f11978d8a1f8a20bb FMDB: 2ce00b547f966261cd18927a3ddb07cb6f3db82a package_info_plus: 58f0028419748fad15bf008b270aaa8e54380b1c path_provider_foundation: 29f094ae23ebbca9d3d0cec13889cd9060c0e943 diff --git a/lib/pages/approve_siwe.dart b/lib/pages/approve_siwe.dart index 08a67533..5124426b 100644 --- a/lib/pages/approve_siwe.dart +++ b/lib/pages/approve_siwe.dart @@ -5,6 +5,8 @@ import 'package:flutter/material.dart'; import 'package:flutter/widgets.dart'; import 'package:web3modal_flutter/constants/key_constants.dart'; +import 'package:web3modal_flutter/services/analytics_service/analytics_service_singleton.dart'; +import 'package:web3modal_flutter/services/analytics_service/models/analytics_event.dart'; import 'package:web3modal_flutter/services/siwe_service/siwe_service_singleton.dart'; import 'package:web3modal_flutter/services/w3m_service/i_w3m_service.dart'; import 'package:web3modal_flutter/theme/constants.dart'; @@ -66,6 +68,9 @@ class _ApproveSIWEPageState extends State { try { final address = _service!.session!.address!; String chainId = _service!.selectedChain?.chainId ?? '1'; + analyticsService.instance.sendEvent(ClickSignSiweMessage( + network: chainId, + )); chainId = W3MChainPresets.chains[chainId]!.namespace; // final message = await siweService.instance!.createMessage( @@ -102,6 +107,8 @@ class _ApproveSIWEPageState extends State { void _handleError(String? error) { debugPrint('[$runtimeType] _handleError $error'); + String chainId = _service!.selectedChain?.chainId ?? '1'; + analyticsService.instance.sendEvent(SiweAuthError(network: chainId)); setState(() => _waitingSign = false); toastUtils.instance.show(ToastMessage( type: ToastType.error, diff --git a/lib/services/analytics_service/models/analytics_event.dart b/lib/services/analytics_service/models/analytics_event.dart index e54ff670..2af5a772 100644 --- a/lib/services/analytics_service/models/analytics_event.dart +++ b/lib/services/analytics_service/models/analytics_event.dart @@ -495,3 +495,95 @@ class EmailUpgradeFromModal implements AnalyticsEvent { if (properties != null) 'properties': properties, }; } + +class ClickSignSiweMessage implements AnalyticsEvent { + final String _network; + ClickSignSiweMessage({required String network}) : _network = network; + + @override + String get type => 'track'; + + @override + String get event => 'CLICK_SIGN_SIWE_MESSAGE'; + + @override + Map? get properties => { + 'network': _network, + }; + + @override + Map toMap() => { + 'type': type, + 'event': event, + if (properties != null) 'properties': properties, + }; +} + +class ClickCancelSiwe implements AnalyticsEvent { + final String _network; + ClickCancelSiwe({required String network}) : _network = network; + + @override + String get type => 'track'; + + @override + String get event => 'CLICK_CANCEL_SIWE'; + + @override + Map? get properties => { + 'network': _network, + }; + + @override + Map toMap() => { + 'type': type, + 'event': event, + if (properties != null) 'properties': properties, + }; +} + +class SiweAuthSuccess implements AnalyticsEvent { + final String _network; + SiweAuthSuccess({required String network}) : _network = network; + + @override + String get type => 'track'; + + @override + String get event => 'SIWE_AUTH_SUCCESS'; + + @override + Map? get properties => { + 'network': _network, + }; + + @override + Map toMap() => { + 'type': type, + 'event': event, + if (properties != null) 'properties': properties, + }; +} + +class SiweAuthError implements AnalyticsEvent { + final String _network; + SiweAuthError({required String network}) : _network = network; + + @override + String get type => 'track'; + + @override + String get event => 'SIWE_AUTH_ERROR'; + + @override + Map? get properties => { + 'network': _network, + }; + + @override + Map toMap() => { + 'type': type, + 'event': event, + if (properties != null) 'properties': properties, + }; +} diff --git a/lib/services/blockchain_service/blockchain_identity.freezed.dart b/lib/services/blockchain_service/blockchain_identity.freezed.dart deleted file mode 100644 index 1c372f97..00000000 --- a/lib/services/blockchain_service/blockchain_identity.freezed.dart +++ /dev/null @@ -1,169 +0,0 @@ -// coverage:ignore-file -// GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: type=lint -// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark - -part of 'blockchain_identity.dart'; - -// ************************************************************************** -// FreezedGenerator -// ************************************************************************** - -T _$identity(T value) => value; - -final _privateConstructorUsedError = UnsupportedError( - 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models'); - -BlockchainIdentity _$BlockchainIdentityFromJson(Map json) { - return _BlockchainIdentity.fromJson(json); -} - -/// @nodoc -mixin _$BlockchainIdentity { - String? get name => throw _privateConstructorUsedError; - String? get avatar => throw _privateConstructorUsedError; - - Map toJson() => throw _privateConstructorUsedError; - @JsonKey(ignore: true) - $BlockchainIdentityCopyWith get copyWith => - throw _privateConstructorUsedError; -} - -/// @nodoc -abstract class $BlockchainIdentityCopyWith<$Res> { - factory $BlockchainIdentityCopyWith( - BlockchainIdentity value, $Res Function(BlockchainIdentity) then) = - _$BlockchainIdentityCopyWithImpl<$Res, BlockchainIdentity>; - @useResult - $Res call({String? name, String? avatar}); -} - -/// @nodoc -class _$BlockchainIdentityCopyWithImpl<$Res, $Val extends BlockchainIdentity> - implements $BlockchainIdentityCopyWith<$Res> { - _$BlockchainIdentityCopyWithImpl(this._value, this._then); - - // ignore: unused_field - final $Val _value; - // ignore: unused_field - final $Res Function($Val) _then; - - @pragma('vm:prefer-inline') - @override - $Res call({ - Object? name = freezed, - Object? avatar = freezed, - }) { - return _then(_value.copyWith( - name: freezed == name - ? _value.name - : name // ignore: cast_nullable_to_non_nullable - as String?, - avatar: freezed == avatar - ? _value.avatar - : avatar // ignore: cast_nullable_to_non_nullable - as String?, - ) as $Val); - } -} - -/// @nodoc -abstract class _$$BlockchainIdentityImplCopyWith<$Res> - implements $BlockchainIdentityCopyWith<$Res> { - factory _$$BlockchainIdentityImplCopyWith(_$BlockchainIdentityImpl value, - $Res Function(_$BlockchainIdentityImpl) then) = - __$$BlockchainIdentityImplCopyWithImpl<$Res>; - @override - @useResult - $Res call({String? name, String? avatar}); -} - -/// @nodoc -class __$$BlockchainIdentityImplCopyWithImpl<$Res> - extends _$BlockchainIdentityCopyWithImpl<$Res, _$BlockchainIdentityImpl> - implements _$$BlockchainIdentityImplCopyWith<$Res> { - __$$BlockchainIdentityImplCopyWithImpl(_$BlockchainIdentityImpl _value, - $Res Function(_$BlockchainIdentityImpl) _then) - : super(_value, _then); - - @pragma('vm:prefer-inline') - @override - $Res call({ - Object? name = freezed, - Object? avatar = freezed, - }) { - return _then(_$BlockchainIdentityImpl( - name: freezed == name - ? _value.name - : name // ignore: cast_nullable_to_non_nullable - as String?, - avatar: freezed == avatar - ? _value.avatar - : avatar // ignore: cast_nullable_to_non_nullable - as String?, - )); - } -} - -/// @nodoc -@JsonSerializable() -class _$BlockchainIdentityImpl implements _BlockchainIdentity { - const _$BlockchainIdentityImpl({this.name, this.avatar}); - - factory _$BlockchainIdentityImpl.fromJson(Map json) => - _$$BlockchainIdentityImplFromJson(json); - - @override - final String? name; - @override - final String? avatar; - - @override - String toString() { - return 'BlockchainIdentity(name: $name, avatar: $avatar)'; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - (other.runtimeType == runtimeType && - other is _$BlockchainIdentityImpl && - (identical(other.name, name) || other.name == name) && - (identical(other.avatar, avatar) || other.avatar == avatar)); - } - - @JsonKey(ignore: true) - @override - int get hashCode => Object.hash(runtimeType, name, avatar); - - @JsonKey(ignore: true) - @override - @pragma('vm:prefer-inline') - _$$BlockchainIdentityImplCopyWith<_$BlockchainIdentityImpl> get copyWith => - __$$BlockchainIdentityImplCopyWithImpl<_$BlockchainIdentityImpl>( - this, _$identity); - - @override - Map toJson() { - return _$$BlockchainIdentityImplToJson( - this, - ); - } -} - -abstract class _BlockchainIdentity implements BlockchainIdentity { - const factory _BlockchainIdentity( - {final String? name, final String? avatar}) = _$BlockchainIdentityImpl; - - factory _BlockchainIdentity.fromJson(Map json) = - _$BlockchainIdentityImpl.fromJson; - - @override - String? get name; - @override - String? get avatar; - @override - @JsonKey(ignore: true) - _$$BlockchainIdentityImplCopyWith<_$BlockchainIdentityImpl> get copyWith => - throw _privateConstructorUsedError; -} diff --git a/lib/services/blockchain_service/blockchain_identity.g.dart b/lib/services/blockchain_service/blockchain_identity.g.dart deleted file mode 100644 index b3504975..00000000 --- a/lib/services/blockchain_service/blockchain_identity.g.dart +++ /dev/null @@ -1,23 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -// ignore_for_file: non_constant_identifier_names - -part of 'blockchain_identity.dart'; - -// ************************************************************************** -// JsonSerializableGenerator -// ************************************************************************** - -_$BlockchainIdentityImpl _$$BlockchainIdentityImplFromJson( - Map json) => - _$BlockchainIdentityImpl( - name: json['name'] as String?, - avatar: json['avatar'] as String?, - ); - -Map _$$BlockchainIdentityImplToJson( - _$BlockchainIdentityImpl instance) => - { - 'name': instance.name, - 'avatar': instance.avatar, - }; diff --git a/lib/services/magic_service/models/frame_message.dart b/lib/services/magic_service/models/frame_message.dart index 19cb8f12..d0384faa 100644 --- a/lib/services/magic_service/models/frame_message.dart +++ b/lib/services/magic_service/models/frame_message.dart @@ -3,7 +3,6 @@ import 'dart:convert'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:web3modal_flutter/constants/url_constants.dart'; -import 'package:web3modal_flutter/utils/util.dart'; import 'package:web3modal_flutter/web3modal_flutter.dart'; class FrameMessage { diff --git a/lib/services/network_service/network_service.dart b/lib/services/network_service/network_service.dart index bf2b4df2..b5652aff 100644 --- a/lib/services/network_service/network_service.dart +++ b/lib/services/network_service/network_service.dart @@ -4,7 +4,6 @@ import 'package:web3modal_flutter/models/grid_item.dart'; import 'package:web3modal_flutter/services/explorer_service/explorer_service_singleton.dart'; import 'package:web3modal_flutter/services/network_service/i_network_service.dart'; import 'package:web3modal_flutter/utils/asset_util.dart'; -import 'package:web3modal_flutter/utils/util.dart'; import 'package:web3modal_flutter/web3modal_flutter.dart'; class NetworkService implements INetworkService { diff --git a/lib/services/siwe_service/models/w3m_siwe.dart b/lib/services/siwe_service/models/w3m_siwe.dart index 11f0e270..2cf381b9 100644 --- a/lib/services/siwe_service/models/w3m_siwe.dart +++ b/lib/services/siwe_service/models/w3m_siwe.dart @@ -6,10 +6,6 @@ import 'package:walletconnect_flutter_v2/walletconnect_flutter_v2.dart'; part 'w3m_siwe.g.dart'; part 'w3m_siwe.freezed.dart'; -// TODO work to do -// context parameter -// disconnect when closing modal -// siwe with email class SIWEConfig { final Future Function() getNonce; final Future Function() getMessageParams; @@ -34,10 +30,8 @@ class SIWEConfig { // Defaults to true final bool signOutOnNetworkChange; // - final BuildContext context; SIWEConfig({ - required this.context, required this.getNonce, required this.getMessageParams, required this.createMessage, @@ -115,7 +109,6 @@ class SIWECreateMessageArgs with _$SIWECreateMessageArgs { @freezed class SIWEMessageArgs with _$SIWEMessageArgs { - @JsonSerializable(includeIfNull: false) const factory SIWEMessageArgs({ required String domain, required String uri, @@ -136,7 +129,6 @@ class SIWEMessageArgs with _$SIWEMessageArgs { @freezed class SIWEVerifyMessageArgs with _$SIWEVerifyMessageArgs { - @JsonSerializable(includeIfNull: false) const factory SIWEVerifyMessageArgs({ required String message, required String signature, diff --git a/lib/services/siwe_service/models/w3m_siwe.freezed.dart b/lib/services/siwe_service/models/w3m_siwe.freezed.dart index 5243cb04..5b92dc0a 100644 --- a/lib/services/siwe_service/models/w3m_siwe.freezed.dart +++ b/lib/services/siwe_service/models/w3m_siwe.freezed.dart @@ -695,8 +695,7 @@ class __$$SIWEMessageArgsImplCopyWithImpl<$Res> } /// @nodoc - -@JsonSerializable(includeIfNull: false) +@JsonSerializable() class _$SIWEMessageArgsImpl implements _SIWEMessageArgs { const _$SIWEMessageArgsImpl( {required this.domain, @@ -992,8 +991,7 @@ class __$$SIWEVerifyMessageArgsImplCopyWithImpl<$Res> } /// @nodoc - -@JsonSerializable(includeIfNull: false) +@JsonSerializable() class _$SIWEVerifyMessageArgsImpl implements _SIWEVerifyMessageArgs { const _$SIWEVerifyMessageArgsImpl( {required this.message, diff --git a/lib/services/siwe_service/models/w3m_siwe.g.dart b/lib/services/siwe_service/models/w3m_siwe.g.dart index af8b323e..a3b33b11 100644 --- a/lib/services/siwe_service/models/w3m_siwe.g.dart +++ b/lib/services/siwe_service/models/w3m_siwe.g.dart @@ -72,29 +72,20 @@ _$SIWEMessageArgsImpl _$$SIWEMessageArgsImplFromJson( ); Map _$$SIWEMessageArgsImplToJson( - _$SIWEMessageArgsImpl instance) { - final val = { - 'domain': instance.domain, - 'uri': instance.uri, - }; - - void writeNotNull(String key, dynamic value) { - if (value != null) { - val[key] = value; - } - } - - writeNotNull('type', instance.type?.toJson()); - writeNotNull('nbf', instance.nbf); - writeNotNull('exp', instance.exp); - writeNotNull('statement', instance.statement); - writeNotNull('requestId', instance.requestId); - writeNotNull('resources', instance.resources); - writeNotNull('expiry', instance.expiry); - writeNotNull('iat', instance.iat); - writeNotNull('methods', instance.methods); - return val; -} + _$SIWEMessageArgsImpl instance) => + { + 'domain': instance.domain, + 'uri': instance.uri, + 'type': instance.type?.toJson(), + 'nbf': instance.nbf, + 'exp': instance.exp, + 'statement': instance.statement, + 'requestId': instance.requestId, + 'resources': instance.resources, + 'expiry': instance.expiry, + 'iat': instance.iat, + 'methods': instance.methods, + }; _$SIWEVerifyMessageArgsImpl _$$SIWEVerifyMessageArgsImplFromJson( Map json) => @@ -108,22 +99,13 @@ _$SIWEVerifyMessageArgsImpl _$$SIWEVerifyMessageArgsImplFromJson( ); Map _$$SIWEVerifyMessageArgsImplToJson( - _$SIWEVerifyMessageArgsImpl instance) { - final val = { - 'message': instance.message, - 'signature': instance.signature, - }; - - void writeNotNull(String key, dynamic value) { - if (value != null) { - val[key] = value; - } - } - - writeNotNull('cacao', instance.cacao?.toJson()); - writeNotNull('clientId', instance.clientId); - return val; -} + _$SIWEVerifyMessageArgsImpl instance) => + { + 'message': instance.message, + 'signature': instance.signature, + 'cacao': instance.cacao?.toJson(), + 'clientId': instance.clientId, + }; _$SIWESessionImpl _$$SIWESessionImplFromJson(Map json) => _$SIWESessionImpl( diff --git a/lib/services/w3m_service/i_w3m_service.dart b/lib/services/w3m_service/i_w3m_service.dart index 3e01ea82..352076f8 100644 --- a/lib/services/w3m_service/i_w3m_service.dart +++ b/lib/services/w3m_service/i_w3m_service.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:flutter/widgets.dart'; import 'package:web3modal_flutter/web3modal_flutter.dart'; @@ -15,6 +16,8 @@ enum W3MServiceStatus { /// Either a [projectId] and [metadata] must be provided or an already created [web3App]. /// optionalNamespaces is mostly not needed, if you use it, the values set here will override every optionalNamespaces set in evey chain abstract class IW3MService with ChangeNotifier { + BuildContext? get modalContext; + /// Whether or not this object has been initialized. W3MServiceStatus get status; @@ -30,7 +33,7 @@ abstract class IW3MService with ChangeNotifier { bool get isConnected; /// The URI that can be used to connect to this dApp. - /// This is only available after the [openModal] function is called. + /// This is only available after the [openModalView] function is called. String? get wcUri; /// The current session's data. @@ -54,12 +57,19 @@ abstract class IW3MService with ChangeNotifier { /// Sets up the explorer and the web3App if they already been initialized. Future init(); + @Deprecated( + 'Add context param to W3MService and use openNetworksView() instead') Future openNetworks(BuildContext context); + Future openNetworksView(); + /// Opens the modal with the provided [startWidget] (if any). /// If none is provided, the default state will be used based on platform. + @Deprecated('Add context param to W3MService and use openModalView() instead') Future openModal(BuildContext context, [Widget? startWidget]); + Future openModalView([Widget? startWidget]); + /// Connects to the relay if not already connected. /// If the relay is already connected, this does nothing. Future reconnectRelay(); diff --git a/lib/services/w3m_service/models/w3m_siwe.freezed.dart b/lib/services/w3m_service/models/w3m_siwe.freezed.dart deleted file mode 100644 index 971115af..00000000 --- a/lib/services/w3m_service/models/w3m_siwe.freezed.dart +++ /dev/null @@ -1,1077 +0,0 @@ -// coverage:ignore-file -// GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: type=lint -// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark - -part of 'w3m_siwe.dart'; - -// ************************************************************************** -// FreezedGenerator -// ************************************************************************** - -T _$identity(T value) => value; - -final _privateConstructorUsedError = UnsupportedError( - 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models'); - -SIWECreateMessageArgs _$SIWECreateMessageArgsFromJson( - Map json) { - return _SIWECreateMessageArgs.fromJson(json); -} - -/// @nodoc -mixin _$SIWECreateMessageArgs { - String get chainId => throw _privateConstructorUsedError; - String get domain => throw _privateConstructorUsedError; - String get nonce => throw _privateConstructorUsedError; - String get uri => throw _privateConstructorUsedError; - String get address => throw _privateConstructorUsedError; - String get version => throw _privateConstructorUsedError; - CacaoHeader? get type => throw _privateConstructorUsedError; - String? get nbf => throw _privateConstructorUsedError; - String? get exp => throw _privateConstructorUsedError; - String? get statement => throw _privateConstructorUsedError; - String? get requestId => throw _privateConstructorUsedError; - List? get resources => throw _privateConstructorUsedError; - int? get expiry => throw _privateConstructorUsedError; - String? get iat => throw _privateConstructorUsedError; - - Map toJson() => throw _privateConstructorUsedError; - @JsonKey(ignore: true) - $SIWECreateMessageArgsCopyWith get copyWith => - throw _privateConstructorUsedError; -} - -/// @nodoc -abstract class $SIWECreateMessageArgsCopyWith<$Res> { - factory $SIWECreateMessageArgsCopyWith(SIWECreateMessageArgs value, - $Res Function(SIWECreateMessageArgs) then) = - _$SIWECreateMessageArgsCopyWithImpl<$Res, SIWECreateMessageArgs>; - @useResult - $Res call( - {String chainId, - String domain, - String nonce, - String uri, - String address, - String version, - CacaoHeader? type, - String? nbf, - String? exp, - String? statement, - String? requestId, - List? resources, - int? expiry, - String? iat}); - - $CacaoHeaderCopyWith<$Res>? get type; -} - -/// @nodoc -class _$SIWECreateMessageArgsCopyWithImpl<$Res, - $Val extends SIWECreateMessageArgs> - implements $SIWECreateMessageArgsCopyWith<$Res> { - _$SIWECreateMessageArgsCopyWithImpl(this._value, this._then); - - // ignore: unused_field - final $Val _value; - // ignore: unused_field - final $Res Function($Val) _then; - - @pragma('vm:prefer-inline') - @override - $Res call({ - Object? chainId = null, - Object? domain = null, - Object? nonce = null, - Object? uri = null, - Object? address = null, - Object? version = null, - Object? type = freezed, - Object? nbf = freezed, - Object? exp = freezed, - Object? statement = freezed, - Object? requestId = freezed, - Object? resources = freezed, - Object? expiry = freezed, - Object? iat = freezed, - }) { - return _then(_value.copyWith( - chainId: null == chainId - ? _value.chainId - : chainId // ignore: cast_nullable_to_non_nullable - as String, - domain: null == domain - ? _value.domain - : domain // ignore: cast_nullable_to_non_nullable - as String, - nonce: null == nonce - ? _value.nonce - : nonce // ignore: cast_nullable_to_non_nullable - as String, - uri: null == uri - ? _value.uri - : uri // ignore: cast_nullable_to_non_nullable - as String, - address: null == address - ? _value.address - : address // ignore: cast_nullable_to_non_nullable - as String, - version: null == version - ? _value.version - : version // ignore: cast_nullable_to_non_nullable - as String, - type: freezed == type - ? _value.type - : type // ignore: cast_nullable_to_non_nullable - as CacaoHeader?, - nbf: freezed == nbf - ? _value.nbf - : nbf // ignore: cast_nullable_to_non_nullable - as String?, - exp: freezed == exp - ? _value.exp - : exp // ignore: cast_nullable_to_non_nullable - as String?, - statement: freezed == statement - ? _value.statement - : statement // ignore: cast_nullable_to_non_nullable - as String?, - requestId: freezed == requestId - ? _value.requestId - : requestId // ignore: cast_nullable_to_non_nullable - as String?, - resources: freezed == resources - ? _value.resources - : resources // ignore: cast_nullable_to_non_nullable - as List?, - expiry: freezed == expiry - ? _value.expiry - : expiry // ignore: cast_nullable_to_non_nullable - as int?, - iat: freezed == iat - ? _value.iat - : iat // ignore: cast_nullable_to_non_nullable - as String?, - ) as $Val); - } - - @override - @pragma('vm:prefer-inline') - $CacaoHeaderCopyWith<$Res>? get type { - if (_value.type == null) { - return null; - } - - return $CacaoHeaderCopyWith<$Res>(_value.type!, (value) { - return _then(_value.copyWith(type: value) as $Val); - }); - } -} - -/// @nodoc -abstract class _$$SIWECreateMessageArgsImplCopyWith<$Res> - implements $SIWECreateMessageArgsCopyWith<$Res> { - factory _$$SIWECreateMessageArgsImplCopyWith( - _$SIWECreateMessageArgsImpl value, - $Res Function(_$SIWECreateMessageArgsImpl) then) = - __$$SIWECreateMessageArgsImplCopyWithImpl<$Res>; - @override - @useResult - $Res call( - {String chainId, - String domain, - String nonce, - String uri, - String address, - String version, - CacaoHeader? type, - String? nbf, - String? exp, - String? statement, - String? requestId, - List? resources, - int? expiry, - String? iat}); - - @override - $CacaoHeaderCopyWith<$Res>? get type; -} - -/// @nodoc -class __$$SIWECreateMessageArgsImplCopyWithImpl<$Res> - extends _$SIWECreateMessageArgsCopyWithImpl<$Res, - _$SIWECreateMessageArgsImpl> - implements _$$SIWECreateMessageArgsImplCopyWith<$Res> { - __$$SIWECreateMessageArgsImplCopyWithImpl(_$SIWECreateMessageArgsImpl _value, - $Res Function(_$SIWECreateMessageArgsImpl) _then) - : super(_value, _then); - - @pragma('vm:prefer-inline') - @override - $Res call({ - Object? chainId = null, - Object? domain = null, - Object? nonce = null, - Object? uri = null, - Object? address = null, - Object? version = null, - Object? type = freezed, - Object? nbf = freezed, - Object? exp = freezed, - Object? statement = freezed, - Object? requestId = freezed, - Object? resources = freezed, - Object? expiry = freezed, - Object? iat = freezed, - }) { - return _then(_$SIWECreateMessageArgsImpl( - chainId: null == chainId - ? _value.chainId - : chainId // ignore: cast_nullable_to_non_nullable - as String, - domain: null == domain - ? _value.domain - : domain // ignore: cast_nullable_to_non_nullable - as String, - nonce: null == nonce - ? _value.nonce - : nonce // ignore: cast_nullable_to_non_nullable - as String, - uri: null == uri - ? _value.uri - : uri // ignore: cast_nullable_to_non_nullable - as String, - address: null == address - ? _value.address - : address // ignore: cast_nullable_to_non_nullable - as String, - version: null == version - ? _value.version - : version // ignore: cast_nullable_to_non_nullable - as String, - type: freezed == type - ? _value.type - : type // ignore: cast_nullable_to_non_nullable - as CacaoHeader?, - nbf: freezed == nbf - ? _value.nbf - : nbf // ignore: cast_nullable_to_non_nullable - as String?, - exp: freezed == exp - ? _value.exp - : exp // ignore: cast_nullable_to_non_nullable - as String?, - statement: freezed == statement - ? _value.statement - : statement // ignore: cast_nullable_to_non_nullable - as String?, - requestId: freezed == requestId - ? _value.requestId - : requestId // ignore: cast_nullable_to_non_nullable - as String?, - resources: freezed == resources - ? _value._resources - : resources // ignore: cast_nullable_to_non_nullable - as List?, - expiry: freezed == expiry - ? _value.expiry - : expiry // ignore: cast_nullable_to_non_nullable - as int?, - iat: freezed == iat - ? _value.iat - : iat // ignore: cast_nullable_to_non_nullable - as String?, - )); - } -} - -/// @nodoc -@JsonSerializable() -class _$SIWECreateMessageArgsImpl implements _SIWECreateMessageArgs { - const _$SIWECreateMessageArgsImpl( - {required this.chainId, - required this.domain, - required this.nonce, - required this.uri, - required this.address, - this.version = '1', - this.type = const CacaoHeader(t: 'eip4361'), - this.nbf, - this.exp, - this.statement, - this.requestId, - final List? resources, - this.expiry, - this.iat}) - : _resources = resources; - - factory _$SIWECreateMessageArgsImpl.fromJson(Map json) => - _$$SIWECreateMessageArgsImplFromJson(json); - - @override - final String chainId; - @override - final String domain; - @override - final String nonce; - @override - final String uri; - @override - final String address; - @override - @JsonKey() - final String version; - @override - @JsonKey() - final CacaoHeader? type; - @override - final String? nbf; - @override - final String? exp; - @override - final String? statement; - @override - final String? requestId; - final List? _resources; - @override - List? get resources { - final value = _resources; - if (value == null) return null; - if (_resources is EqualUnmodifiableListView) return _resources; - // ignore: implicit_dynamic_type - return EqualUnmodifiableListView(value); - } - - @override - final int? expiry; - @override - final String? iat; - - @override - String toString() { - return 'SIWECreateMessageArgs(chainId: $chainId, domain: $domain, nonce: $nonce, uri: $uri, address: $address, version: $version, type: $type, nbf: $nbf, exp: $exp, statement: $statement, requestId: $requestId, resources: $resources, expiry: $expiry, iat: $iat)'; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - (other.runtimeType == runtimeType && - other is _$SIWECreateMessageArgsImpl && - (identical(other.chainId, chainId) || other.chainId == chainId) && - (identical(other.domain, domain) || other.domain == domain) && - (identical(other.nonce, nonce) || other.nonce == nonce) && - (identical(other.uri, uri) || other.uri == uri) && - (identical(other.address, address) || other.address == address) && - (identical(other.version, version) || other.version == version) && - (identical(other.type, type) || other.type == type) && - (identical(other.nbf, nbf) || other.nbf == nbf) && - (identical(other.exp, exp) || other.exp == exp) && - (identical(other.statement, statement) || - other.statement == statement) && - (identical(other.requestId, requestId) || - other.requestId == requestId) && - const DeepCollectionEquality() - .equals(other._resources, _resources) && - (identical(other.expiry, expiry) || other.expiry == expiry) && - (identical(other.iat, iat) || other.iat == iat)); - } - - @JsonKey(ignore: true) - @override - int get hashCode => Object.hash( - runtimeType, - chainId, - domain, - nonce, - uri, - address, - version, - type, - nbf, - exp, - statement, - requestId, - const DeepCollectionEquality().hash(_resources), - expiry, - iat); - - @JsonKey(ignore: true) - @override - @pragma('vm:prefer-inline') - _$$SIWECreateMessageArgsImplCopyWith<_$SIWECreateMessageArgsImpl> - get copyWith => __$$SIWECreateMessageArgsImplCopyWithImpl< - _$SIWECreateMessageArgsImpl>(this, _$identity); - - @override - Map toJson() { - return _$$SIWECreateMessageArgsImplToJson( - this, - ); - } -} - -abstract class _SIWECreateMessageArgs implements SIWECreateMessageArgs { - const factory _SIWECreateMessageArgs( - {required final String chainId, - required final String domain, - required final String nonce, - required final String uri, - required final String address, - final String version, - final CacaoHeader? type, - final String? nbf, - final String? exp, - final String? statement, - final String? requestId, - final List? resources, - final int? expiry, - final String? iat}) = _$SIWECreateMessageArgsImpl; - - factory _SIWECreateMessageArgs.fromJson(Map json) = - _$SIWECreateMessageArgsImpl.fromJson; - - @override - String get chainId; - @override - String get domain; - @override - String get nonce; - @override - String get uri; - @override - String get address; - @override - String get version; - @override - CacaoHeader? get type; - @override - String? get nbf; - @override - String? get exp; - @override - String? get statement; - @override - String? get requestId; - @override - List? get resources; - @override - int? get expiry; - @override - String? get iat; - @override - @JsonKey(ignore: true) - _$$SIWECreateMessageArgsImplCopyWith<_$SIWECreateMessageArgsImpl> - get copyWith => throw _privateConstructorUsedError; -} - -SIWEMessageArgs _$SIWEMessageArgsFromJson(Map json) { - return _SIWEMessageArgs.fromJson(json); -} - -/// @nodoc -mixin _$SIWEMessageArgs { - String get domain => throw _privateConstructorUsedError; - String get uri => throw _privateConstructorUsedError; - CacaoHeader? get type => throw _privateConstructorUsedError; - String? get nbf => throw _privateConstructorUsedError; - String? get exp => throw _privateConstructorUsedError; - String? get statement => throw _privateConstructorUsedError; - String? get requestId => throw _privateConstructorUsedError; - List? get resources => throw _privateConstructorUsedError; - int? get expiry => throw _privateConstructorUsedError; - String? get iat => throw _privateConstructorUsedError; - List? get methods => throw _privateConstructorUsedError; - - Map toJson() => throw _privateConstructorUsedError; - @JsonKey(ignore: true) - $SIWEMessageArgsCopyWith get copyWith => - throw _privateConstructorUsedError; -} - -/// @nodoc -abstract class $SIWEMessageArgsCopyWith<$Res> { - factory $SIWEMessageArgsCopyWith( - SIWEMessageArgs value, $Res Function(SIWEMessageArgs) then) = - _$SIWEMessageArgsCopyWithImpl<$Res, SIWEMessageArgs>; - @useResult - $Res call( - {String domain, - String uri, - CacaoHeader? type, - String? nbf, - String? exp, - String? statement, - String? requestId, - List? resources, - int? expiry, - String? iat, - List? methods}); - - $CacaoHeaderCopyWith<$Res>? get type; -} - -/// @nodoc -class _$SIWEMessageArgsCopyWithImpl<$Res, $Val extends SIWEMessageArgs> - implements $SIWEMessageArgsCopyWith<$Res> { - _$SIWEMessageArgsCopyWithImpl(this._value, this._then); - - // ignore: unused_field - final $Val _value; - // ignore: unused_field - final $Res Function($Val) _then; - - @pragma('vm:prefer-inline') - @override - $Res call({ - Object? domain = null, - Object? uri = null, - Object? type = freezed, - Object? nbf = freezed, - Object? exp = freezed, - Object? statement = freezed, - Object? requestId = freezed, - Object? resources = freezed, - Object? expiry = freezed, - Object? iat = freezed, - Object? methods = freezed, - }) { - return _then(_value.copyWith( - domain: null == domain - ? _value.domain - : domain // ignore: cast_nullable_to_non_nullable - as String, - uri: null == uri - ? _value.uri - : uri // ignore: cast_nullable_to_non_nullable - as String, - type: freezed == type - ? _value.type - : type // ignore: cast_nullable_to_non_nullable - as CacaoHeader?, - nbf: freezed == nbf - ? _value.nbf - : nbf // ignore: cast_nullable_to_non_nullable - as String?, - exp: freezed == exp - ? _value.exp - : exp // ignore: cast_nullable_to_non_nullable - as String?, - statement: freezed == statement - ? _value.statement - : statement // ignore: cast_nullable_to_non_nullable - as String?, - requestId: freezed == requestId - ? _value.requestId - : requestId // ignore: cast_nullable_to_non_nullable - as String?, - resources: freezed == resources - ? _value.resources - : resources // ignore: cast_nullable_to_non_nullable - as List?, - expiry: freezed == expiry - ? _value.expiry - : expiry // ignore: cast_nullable_to_non_nullable - as int?, - iat: freezed == iat - ? _value.iat - : iat // ignore: cast_nullable_to_non_nullable - as String?, - methods: freezed == methods - ? _value.methods - : methods // ignore: cast_nullable_to_non_nullable - as List?, - ) as $Val); - } - - @override - @pragma('vm:prefer-inline') - $CacaoHeaderCopyWith<$Res>? get type { - if (_value.type == null) { - return null; - } - - return $CacaoHeaderCopyWith<$Res>(_value.type!, (value) { - return _then(_value.copyWith(type: value) as $Val); - }); - } -} - -/// @nodoc -abstract class _$$SIWEMessageArgsImplCopyWith<$Res> - implements $SIWEMessageArgsCopyWith<$Res> { - factory _$$SIWEMessageArgsImplCopyWith(_$SIWEMessageArgsImpl value, - $Res Function(_$SIWEMessageArgsImpl) then) = - __$$SIWEMessageArgsImplCopyWithImpl<$Res>; - @override - @useResult - $Res call( - {String domain, - String uri, - CacaoHeader? type, - String? nbf, - String? exp, - String? statement, - String? requestId, - List? resources, - int? expiry, - String? iat, - List? methods}); - - @override - $CacaoHeaderCopyWith<$Res>? get type; -} - -/// @nodoc -class __$$SIWEMessageArgsImplCopyWithImpl<$Res> - extends _$SIWEMessageArgsCopyWithImpl<$Res, _$SIWEMessageArgsImpl> - implements _$$SIWEMessageArgsImplCopyWith<$Res> { - __$$SIWEMessageArgsImplCopyWithImpl( - _$SIWEMessageArgsImpl _value, $Res Function(_$SIWEMessageArgsImpl) _then) - : super(_value, _then); - - @pragma('vm:prefer-inline') - @override - $Res call({ - Object? domain = null, - Object? uri = null, - Object? type = freezed, - Object? nbf = freezed, - Object? exp = freezed, - Object? statement = freezed, - Object? requestId = freezed, - Object? resources = freezed, - Object? expiry = freezed, - Object? iat = freezed, - Object? methods = freezed, - }) { - return _then(_$SIWEMessageArgsImpl( - domain: null == domain - ? _value.domain - : domain // ignore: cast_nullable_to_non_nullable - as String, - uri: null == uri - ? _value.uri - : uri // ignore: cast_nullable_to_non_nullable - as String, - type: freezed == type - ? _value.type - : type // ignore: cast_nullable_to_non_nullable - as CacaoHeader?, - nbf: freezed == nbf - ? _value.nbf - : nbf // ignore: cast_nullable_to_non_nullable - as String?, - exp: freezed == exp - ? _value.exp - : exp // ignore: cast_nullable_to_non_nullable - as String?, - statement: freezed == statement - ? _value.statement - : statement // ignore: cast_nullable_to_non_nullable - as String?, - requestId: freezed == requestId - ? _value.requestId - : requestId // ignore: cast_nullable_to_non_nullable - as String?, - resources: freezed == resources - ? _value._resources - : resources // ignore: cast_nullable_to_non_nullable - as List?, - expiry: freezed == expiry - ? _value.expiry - : expiry // ignore: cast_nullable_to_non_nullable - as int?, - iat: freezed == iat - ? _value.iat - : iat // ignore: cast_nullable_to_non_nullable - as String?, - methods: freezed == methods - ? _value._methods - : methods // ignore: cast_nullable_to_non_nullable - as List?, - )); - } -} - -/// @nodoc - -@JsonSerializable(includeIfNull: false) -class _$SIWEMessageArgsImpl implements _SIWEMessageArgs { - const _$SIWEMessageArgsImpl( - {required this.domain, - required this.uri, - this.type = const CacaoHeader(t: 'eip4361'), - this.nbf, - this.exp, - this.statement, - this.requestId, - final List? resources, - this.expiry, - this.iat, - final List? methods}) - : _resources = resources, - _methods = methods; - - factory _$SIWEMessageArgsImpl.fromJson(Map json) => - _$$SIWEMessageArgsImplFromJson(json); - - @override - final String domain; - @override - final String uri; - @override - @JsonKey() - final CacaoHeader? type; - @override - final String? nbf; - @override - final String? exp; - @override - final String? statement; - @override - final String? requestId; - final List? _resources; - @override - List? get resources { - final value = _resources; - if (value == null) return null; - if (_resources is EqualUnmodifiableListView) return _resources; - // ignore: implicit_dynamic_type - return EqualUnmodifiableListView(value); - } - - @override - final int? expiry; - @override - final String? iat; - final List? _methods; - @override - List? get methods { - final value = _methods; - if (value == null) return null; - if (_methods is EqualUnmodifiableListView) return _methods; - // ignore: implicit_dynamic_type - return EqualUnmodifiableListView(value); - } - - @override - String toString() { - return 'SIWEMessageArgs(domain: $domain, uri: $uri, type: $type, nbf: $nbf, exp: $exp, statement: $statement, requestId: $requestId, resources: $resources, expiry: $expiry, iat: $iat, methods: $methods)'; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - (other.runtimeType == runtimeType && - other is _$SIWEMessageArgsImpl && - (identical(other.domain, domain) || other.domain == domain) && - (identical(other.uri, uri) || other.uri == uri) && - (identical(other.type, type) || other.type == type) && - (identical(other.nbf, nbf) || other.nbf == nbf) && - (identical(other.exp, exp) || other.exp == exp) && - (identical(other.statement, statement) || - other.statement == statement) && - (identical(other.requestId, requestId) || - other.requestId == requestId) && - const DeepCollectionEquality() - .equals(other._resources, _resources) && - (identical(other.expiry, expiry) || other.expiry == expiry) && - (identical(other.iat, iat) || other.iat == iat) && - const DeepCollectionEquality().equals(other._methods, _methods)); - } - - @JsonKey(ignore: true) - @override - int get hashCode => Object.hash( - runtimeType, - domain, - uri, - type, - nbf, - exp, - statement, - requestId, - const DeepCollectionEquality().hash(_resources), - expiry, - iat, - const DeepCollectionEquality().hash(_methods)); - - @JsonKey(ignore: true) - @override - @pragma('vm:prefer-inline') - _$$SIWEMessageArgsImplCopyWith<_$SIWEMessageArgsImpl> get copyWith => - __$$SIWEMessageArgsImplCopyWithImpl<_$SIWEMessageArgsImpl>( - this, _$identity); - - @override - Map toJson() { - return _$$SIWEMessageArgsImplToJson( - this, - ); - } -} - -abstract class _SIWEMessageArgs implements SIWEMessageArgs { - const factory _SIWEMessageArgs( - {required final String domain, - required final String uri, - final CacaoHeader? type, - final String? nbf, - final String? exp, - final String? statement, - final String? requestId, - final List? resources, - final int? expiry, - final String? iat, - final List? methods}) = _$SIWEMessageArgsImpl; - - factory _SIWEMessageArgs.fromJson(Map json) = - _$SIWEMessageArgsImpl.fromJson; - - @override - String get domain; - @override - String get uri; - @override - CacaoHeader? get type; - @override - String? get nbf; - @override - String? get exp; - @override - String? get statement; - @override - String? get requestId; - @override - List? get resources; - @override - int? get expiry; - @override - String? get iat; - @override - List? get methods; - @override - @JsonKey(ignore: true) - _$$SIWEMessageArgsImplCopyWith<_$SIWEMessageArgsImpl> get copyWith => - throw _privateConstructorUsedError; -} - -SIWEVerifyMessageArgs _$SIWEVerifyMessageArgsFromJson( - Map json) { - return _SIWEVerifyMessageArgs.fromJson(json); -} - -/// @nodoc -mixin _$SIWEVerifyMessageArgs { - String get message => throw _privateConstructorUsedError; - String get signature => throw _privateConstructorUsedError; - Cacao? get cacao => throw _privateConstructorUsedError; // for One-Click Auth - String? get clientId => throw _privateConstructorUsedError; - - Map toJson() => throw _privateConstructorUsedError; - @JsonKey(ignore: true) - $SIWEVerifyMessageArgsCopyWith get copyWith => - throw _privateConstructorUsedError; -} - -/// @nodoc -abstract class $SIWEVerifyMessageArgsCopyWith<$Res> { - factory $SIWEVerifyMessageArgsCopyWith(SIWEVerifyMessageArgs value, - $Res Function(SIWEVerifyMessageArgs) then) = - _$SIWEVerifyMessageArgsCopyWithImpl<$Res, SIWEVerifyMessageArgs>; - @useResult - $Res call({String message, String signature, Cacao? cacao, String? clientId}); - - $CacaoCopyWith<$Res>? get cacao; -} - -/// @nodoc -class _$SIWEVerifyMessageArgsCopyWithImpl<$Res, - $Val extends SIWEVerifyMessageArgs> - implements $SIWEVerifyMessageArgsCopyWith<$Res> { - _$SIWEVerifyMessageArgsCopyWithImpl(this._value, this._then); - - // ignore: unused_field - final $Val _value; - // ignore: unused_field - final $Res Function($Val) _then; - - @pragma('vm:prefer-inline') - @override - $Res call({ - Object? message = null, - Object? signature = null, - Object? cacao = freezed, - Object? clientId = freezed, - }) { - return _then(_value.copyWith( - message: null == message - ? _value.message - : message // ignore: cast_nullable_to_non_nullable - as String, - signature: null == signature - ? _value.signature - : signature // ignore: cast_nullable_to_non_nullable - as String, - cacao: freezed == cacao - ? _value.cacao - : cacao // ignore: cast_nullable_to_non_nullable - as Cacao?, - clientId: freezed == clientId - ? _value.clientId - : clientId // ignore: cast_nullable_to_non_nullable - as String?, - ) as $Val); - } - - @override - @pragma('vm:prefer-inline') - $CacaoCopyWith<$Res>? get cacao { - if (_value.cacao == null) { - return null; - } - - return $CacaoCopyWith<$Res>(_value.cacao!, (value) { - return _then(_value.copyWith(cacao: value) as $Val); - }); - } -} - -/// @nodoc -abstract class _$$SIWEVerifyMessageArgsImplCopyWith<$Res> - implements $SIWEVerifyMessageArgsCopyWith<$Res> { - factory _$$SIWEVerifyMessageArgsImplCopyWith( - _$SIWEVerifyMessageArgsImpl value, - $Res Function(_$SIWEVerifyMessageArgsImpl) then) = - __$$SIWEVerifyMessageArgsImplCopyWithImpl<$Res>; - @override - @useResult - $Res call({String message, String signature, Cacao? cacao, String? clientId}); - - @override - $CacaoCopyWith<$Res>? get cacao; -} - -/// @nodoc -class __$$SIWEVerifyMessageArgsImplCopyWithImpl<$Res> - extends _$SIWEVerifyMessageArgsCopyWithImpl<$Res, - _$SIWEVerifyMessageArgsImpl> - implements _$$SIWEVerifyMessageArgsImplCopyWith<$Res> { - __$$SIWEVerifyMessageArgsImplCopyWithImpl(_$SIWEVerifyMessageArgsImpl _value, - $Res Function(_$SIWEVerifyMessageArgsImpl) _then) - : super(_value, _then); - - @pragma('vm:prefer-inline') - @override - $Res call({ - Object? message = null, - Object? signature = null, - Object? cacao = freezed, - Object? clientId = freezed, - }) { - return _then(_$SIWEVerifyMessageArgsImpl( - message: null == message - ? _value.message - : message // ignore: cast_nullable_to_non_nullable - as String, - signature: null == signature - ? _value.signature - : signature // ignore: cast_nullable_to_non_nullable - as String, - cacao: freezed == cacao - ? _value.cacao - : cacao // ignore: cast_nullable_to_non_nullable - as Cacao?, - clientId: freezed == clientId - ? _value.clientId - : clientId // ignore: cast_nullable_to_non_nullable - as String?, - )); - } -} - -/// @nodoc - -@JsonSerializable(includeIfNull: false) -class _$SIWEVerifyMessageArgsImpl implements _SIWEVerifyMessageArgs { - const _$SIWEVerifyMessageArgsImpl( - {required this.message, - required this.signature, - this.cacao, - this.clientId}); - - factory _$SIWEVerifyMessageArgsImpl.fromJson(Map json) => - _$$SIWEVerifyMessageArgsImplFromJson(json); - - @override - final String message; - @override - final String signature; - @override - final Cacao? cacao; -// for One-Click Auth - @override - final String? clientId; - - @override - String toString() { - return 'SIWEVerifyMessageArgs(message: $message, signature: $signature, cacao: $cacao, clientId: $clientId)'; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - (other.runtimeType == runtimeType && - other is _$SIWEVerifyMessageArgsImpl && - (identical(other.message, message) || other.message == message) && - (identical(other.signature, signature) || - other.signature == signature) && - (identical(other.cacao, cacao) || other.cacao == cacao) && - (identical(other.clientId, clientId) || - other.clientId == clientId)); - } - - @JsonKey(ignore: true) - @override - int get hashCode => - Object.hash(runtimeType, message, signature, cacao, clientId); - - @JsonKey(ignore: true) - @override - @pragma('vm:prefer-inline') - _$$SIWEVerifyMessageArgsImplCopyWith<_$SIWEVerifyMessageArgsImpl> - get copyWith => __$$SIWEVerifyMessageArgsImplCopyWithImpl< - _$SIWEVerifyMessageArgsImpl>(this, _$identity); - - @override - Map toJson() { - return _$$SIWEVerifyMessageArgsImplToJson( - this, - ); - } -} - -abstract class _SIWEVerifyMessageArgs implements SIWEVerifyMessageArgs { - const factory _SIWEVerifyMessageArgs( - {required final String message, - required final String signature, - final Cacao? cacao, - final String? clientId}) = _$SIWEVerifyMessageArgsImpl; - - factory _SIWEVerifyMessageArgs.fromJson(Map json) = - _$SIWEVerifyMessageArgsImpl.fromJson; - - @override - String get message; - @override - String get signature; - @override - Cacao? get cacao; - @override // for One-Click Auth - String? get clientId; - @override - @JsonKey(ignore: true) - _$$SIWEVerifyMessageArgsImplCopyWith<_$SIWEVerifyMessageArgsImpl> - get copyWith => throw _privateConstructorUsedError; -} diff --git a/lib/services/w3m_service/models/w3m_siwe.g.dart b/lib/services/w3m_service/models/w3m_siwe.g.dart deleted file mode 100644 index 84bc26c3..00000000 --- a/lib/services/w3m_service/models/w3m_siwe.g.dart +++ /dev/null @@ -1,126 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -// ignore_for_file: non_constant_identifier_names - -part of 'w3m_siwe.dart'; - -// ************************************************************************** -// JsonSerializableGenerator -// ************************************************************************** - -_$SIWECreateMessageArgsImpl _$$SIWECreateMessageArgsImplFromJson( - Map json) => - _$SIWECreateMessageArgsImpl( - chainId: json['chainId'] as String, - domain: json['domain'] as String, - nonce: json['nonce'] as String, - uri: json['uri'] as String, - address: json['address'] as String, - version: json['version'] as String? ?? '1', - type: json['type'] == null - ? const CacaoHeader(t: 'eip4361') - : CacaoHeader.fromJson(json['type'] as Map), - nbf: json['nbf'] as String?, - exp: json['exp'] as String?, - statement: json['statement'] as String?, - requestId: json['requestId'] as String?, - resources: (json['resources'] as List?) - ?.map((e) => e as String) - .toList(), - expiry: json['expiry'] as int?, - iat: json['iat'] as String?, - ); - -Map _$$SIWECreateMessageArgsImplToJson( - _$SIWECreateMessageArgsImpl instance) => - { - 'chainId': instance.chainId, - 'domain': instance.domain, - 'nonce': instance.nonce, - 'uri': instance.uri, - 'address': instance.address, - 'version': instance.version, - 'type': instance.type?.toJson(), - 'nbf': instance.nbf, - 'exp': instance.exp, - 'statement': instance.statement, - 'requestId': instance.requestId, - 'resources': instance.resources, - 'expiry': instance.expiry, - 'iat': instance.iat, - }; - -_$SIWEMessageArgsImpl _$$SIWEMessageArgsImplFromJson( - Map json) => - _$SIWEMessageArgsImpl( - domain: json['domain'] as String, - uri: json['uri'] as String, - type: json['type'] == null - ? const CacaoHeader(t: 'eip4361') - : CacaoHeader.fromJson(json['type'] as Map), - nbf: json['nbf'] as String?, - exp: json['exp'] as String?, - statement: json['statement'] as String?, - requestId: json['requestId'] as String?, - resources: (json['resources'] as List?) - ?.map((e) => e as String) - .toList(), - expiry: json['expiry'] as int?, - iat: json['iat'] as String?, - methods: - (json['methods'] as List?)?.map((e) => e as String).toList(), - ); - -Map _$$SIWEMessageArgsImplToJson( - _$SIWEMessageArgsImpl instance) { - final val = { - 'domain': instance.domain, - 'uri': instance.uri, - }; - - void writeNotNull(String key, dynamic value) { - if (value != null) { - val[key] = value; - } - } - - writeNotNull('type', instance.type?.toJson()); - writeNotNull('nbf', instance.nbf); - writeNotNull('exp', instance.exp); - writeNotNull('statement', instance.statement); - writeNotNull('requestId', instance.requestId); - writeNotNull('resources', instance.resources); - writeNotNull('expiry', instance.expiry); - writeNotNull('iat', instance.iat); - writeNotNull('methods', instance.methods); - return val; -} - -_$SIWEVerifyMessageArgsImpl _$$SIWEVerifyMessageArgsImplFromJson( - Map json) => - _$SIWEVerifyMessageArgsImpl( - message: json['message'] as String, - signature: json['signature'] as String, - cacao: json['cacao'] == null - ? null - : Cacao.fromJson(json['cacao'] as Map), - clientId: json['clientId'] as String?, - ); - -Map _$$SIWEVerifyMessageArgsImplToJson( - _$SIWEVerifyMessageArgsImpl instance) { - final val = { - 'message': instance.message, - 'signature': instance.signature, - }; - - void writeNotNull(String key, dynamic value) { - if (value != null) { - val[key] = value; - } - } - - writeNotNull('cacao', instance.cacao?.toJson()); - writeNotNull('clientId', instance.clientId); - return val; -} diff --git a/lib/services/w3m_service/w3m_service.dart b/lib/services/w3m_service/w3m_service.dart index 094591d2..0769fd8b 100644 --- a/lib/services/w3m_service/w3m_service.dart +++ b/lib/services/w3m_service/w3m_service.dart @@ -7,6 +7,7 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:url_launcher/url_launcher.dart'; +import 'package:web3modal_flutter/constants/key_constants.dart'; import 'package:web3modal_flutter/constants/string_constants.dart'; import 'package:web3modal_flutter/constants/url_constants.dart'; @@ -55,7 +56,7 @@ import 'package:web3modal_flutter/utils/url/url_utils_singleton.dart'; /// optionalNamespaces is mostly not needed, if you use it, the values set here will override every optionalNamespaces set in evey chain class W3MService with ChangeNotifier implements IW3MService { String _projectId = ''; - BuildContext? _context; + Map _requiredNamespaces = {}; Map _optionalNamespaces = {}; String? _lastChainEmitted; @@ -112,7 +113,15 @@ class W3MService with ChangeNotifier implements IW3MService { ILoggerService get _logger => loggerService.instance; + bool _disconnectOnClose = false; + + BuildContext? _context; + @override + BuildContext? get modalContext => _context; + + /// `context` is required if SIWEConfig is passed. W3MService({ + BuildContext? context, IWeb3App? web3App, String? projectId, PairingMetadata? metadata, @@ -128,16 +137,23 @@ class W3MService with ChangeNotifier implements IW3MService { }) { if (web3App == null) { if (projectId == null) { - throw ArgumentError( - 'Either a projectId and metadata must be provided or an already created web3App.', + throw W3MServiceException( + 'Either a `projectId` and `metadata` must be provided or an already created `web3App`', ); } if (metadata == null) { - throw ArgumentError( - 'Metada is required when using projectId.', + throw W3MServiceException( + '`metadata:` parameter is required when using `projectId:`', ); } } + if (siweConfig?.enabled == true && context == null) { + throw W3MServiceException( + '`context:` parameter is required if using `siweConfig:`. Also, `context:` parameter will be enforced in future versions.', + ); + } + + _context = context; _web3App = web3App ?? Web3App( @@ -299,10 +315,9 @@ class W3MService with ChangeNotifier implements IW3MService { await _setSesionAndChainData(session); _notify(); } catch (_) { - final context = siweService.instance!.config!.context; + _disconnectOnClose = true; _showModalView( - context, - ApproveSIWEPage(onSiweFinish: _oneSIWEFinish), + startWidget: ApproveSIWEPage(onSiweFinish: _oneSIWEFinish), ); } } @@ -468,11 +483,25 @@ class W3MService with ChangeNotifier implements IW3MService { } // This method would be used from a custom button alone + @Deprecated( + 'Add context param to W3MService and use openNetworksView() instead') @override Future openNetworks(BuildContext context) async { return _showModalView( - context, - SelectNetworkPage( + context: context, + startWidget: SelectNetworkPage( + onTapNetwork: (info) { + selectChain(info); + widgetStack.instance.addDefault(); + }, + ), + ); + } + + @override + Future openNetworksView() { + return _showModalView( + startWidget: SelectNetworkPage( onTapNetwork: (info) { selectChain(info); widgetStack.instance.addDefault(); @@ -482,15 +511,21 @@ class W3MService with ChangeNotifier implements IW3MService { } // TODO [W3MService] startWidget parameter should be removed + @Deprecated('Add context param to W3MService and use openModalView() instead') @override Future openModal(BuildContext context, [Widget? startWidget]) async { - return _showModalView(context, startWidget); + return _showModalView(context: context, startWidget: startWidget); } - Future _showModalView( - BuildContext context, [ + @override + Future openModalView([Widget? startWidget]) { + return _showModalView(startWidget: startWidget); + } + + Future _showModalView({ + BuildContext? context, Widget? startWidget, - ]) async { + }) async { _checkInitialized(); if (_isOpen) { @@ -498,7 +533,13 @@ class W3MService with ChangeNotifier implements IW3MService { return; } _isOpen = true; - _context = context; + _context = context ?? modalContext; + + if (_context == null) { + loggerService.instance.e( + 'No context was found. Try adding `context:` parameter in W3MService class'); + return; + } analyticsService.instance.sendEvent(ModalOpenEvent( connected: _isConnected, @@ -899,35 +940,37 @@ class W3MService with ChangeNotifier implements IW3MService { @override void closeModal({bool disconnectSession = false}) async { - if (disconnectSession) { - await disconnect(); - selectWallet(null); - } + _disconnectOnClose = disconnectSession; // If we aren't open, then we can't and shouldn't close - _close(event: false); + _close(); if (_context != null) { final canPop = Navigator.of(_context!, rootNavigator: true).canPop(); if (canPop) { Navigator.of(_context!, rootNavigator: true).pop(); - analyticsService.instance.sendEvent(ModalCloseEvent( - connected: _isConnected, - )); } } _notify(); } - void _close({bool event = true}) { + void _close() async { if (!_isOpen) { return; } _isOpen = false; - toastUtils.instance.clear(); - if (event) { - analyticsService.instance.sendEvent(ModalCloseEvent( - connected: _isConnected, - )); + if (_disconnectOnClose) { + _disconnectOnClose = false; + final currentKey = widgetStack.instance.getCurrent().key; + if (currentKey == KeyConstants.approveSiwePageKey) { + final chainId = _currentSelectedChain?.chainId ?? '1'; + analyticsService.instance.sendEvent(ClickCancelSiwe(network: chainId)); + } + await disconnect(); + selectWallet(null); } + toastUtils.instance.clear(); + analyticsService.instance.sendEvent(ModalCloseEvent( + connected: _isConnected, + )); } @override @@ -1373,6 +1416,7 @@ class W3MService with ChangeNotifier implements IW3MService { try { if (siweService.instance!.signOutOnNetworkChange) { await siweService.instance!.signOut(); + _disconnectOnClose = true; widgetStack.instance.push(ApproveSIWEPage( onSiweFinish: _oneSIWEFinish, )); @@ -1446,6 +1490,7 @@ extension _W3MMagicExtension on W3MService { await _checkSIWEStatus(); onModalUpdate.broadcast(ModalConnect(_currentSession!)); } else { + _disconnectOnClose = true; widgetStack.instance.push(ApproveSIWEPage( onSiweFinish: _oneSIWEFinish, )); @@ -1529,6 +1574,7 @@ extension _W3MCoinbaseExtension on W3MService { onModalConnect.broadcast(ModalConnect(session)); // if (siweService.instance!.enabled) { + _disconnectOnClose = true; widgetStack.instance.push(ApproveSIWEPage( onSiweFinish: _oneSIWEFinish, )); @@ -1637,6 +1683,7 @@ extension _W3MServiceExtension on W3MService { onModalConnect.broadcast(ModalConnect(session)); // if (siweService.instance!.enabled) { + _disconnectOnClose = true; widgetStack.instance.push(ApproveSIWEPage( onSiweFinish: _oneSIWEFinish, )); @@ -1681,6 +1728,9 @@ extension _W3MServiceExtension on W3MService { await _storeSession(updatedSession); onModalUpdate.broadcast(ModalConnect(updatedSession)); closeModal(); + analyticsService.instance.sendEvent(SiweAuthSuccess( + network: updatedSession.chainId, + )); } void _onSessionEvent(SessionEvent? args) async { diff --git a/lib/version.dart b/lib/version.dart index ec97fd58..608c2157 100644 --- a/lib/version.dart +++ b/lib/version.dart @@ -1,2 +1,2 @@ // Generated code. Do not modify. -const packageVersion = '3.3.0-beta01'; +const packageVersion = '3.3.0-beta02'; diff --git a/lib/web3modal_flutter.dart b/lib/web3modal_flutter.dart index 67e37ba2..02f49cfb 100644 --- a/lib/web3modal_flutter.dart +++ b/lib/web3modal_flutter.dart @@ -11,6 +11,7 @@ export 'services/siwe_service/models/w3m_siwe.dart'; /// Utils export 'utils/w3m_chains_presets.dart'; +export 'utils/util.dart'; /// Theme export 'theme/w3m_theme.dart'; diff --git a/lib/widgets/avatars/w3m_account_avatar.dart b/lib/widgets/avatars/w3m_account_avatar.dart index a6b1d222..445138b3 100644 --- a/lib/widgets/avatars/w3m_account_avatar.dart +++ b/lib/widgets/avatars/w3m_account_avatar.dart @@ -2,7 +2,6 @@ import 'package:cached_network_image/cached_network_image.dart'; import 'package:flutter/material.dart'; import 'package:web3modal_flutter/services/w3m_service/i_w3m_service.dart'; import 'package:web3modal_flutter/utils/core/core_utils_singleton.dart'; -import 'package:web3modal_flutter/utils/util.dart'; import 'package:web3modal_flutter/web3modal_flutter.dart'; class W3MAccountAvatar extends StatefulWidget { diff --git a/lib/widgets/buttons/address_button.dart b/lib/widgets/buttons/address_button.dart index e5f58c5d..773f3e3a 100644 --- a/lib/widgets/buttons/address_button.dart +++ b/lib/widgets/buttons/address_button.dart @@ -1,6 +1,5 @@ import 'package:flutter/material.dart'; import 'package:web3modal_flutter/services/w3m_service/i_w3m_service.dart'; -import 'package:web3modal_flutter/utils/util.dart'; import 'package:web3modal_flutter/web3modal_flutter.dart'; import 'package:web3modal_flutter/widgets/buttons/base_button.dart'; import 'package:web3modal_flutter/widgets/avatars/w3m_account_avatar.dart'; diff --git a/lib/widgets/text/w3m_address.dart b/lib/widgets/text/w3m_address.dart index 87c9dd47..27ec8243 100644 --- a/lib/widgets/text/w3m_address.dart +++ b/lib/widgets/text/w3m_address.dart @@ -1,6 +1,5 @@ import 'package:flutter/material.dart'; import 'package:web3modal_flutter/services/w3m_service/i_w3m_service.dart'; -import 'package:web3modal_flutter/utils/util.dart'; import 'package:web3modal_flutter/web3modal_flutter.dart'; class W3MAddress extends StatefulWidget { diff --git a/lib/widgets/w3m_account_button.dart b/lib/widgets/w3m_account_button.dart index c7878278..7006b74c 100644 --- a/lib/widgets/w3m_account_button.dart +++ b/lib/widgets/w3m_account_button.dart @@ -7,7 +7,6 @@ import 'package:web3modal_flutter/services/magic_service/models/magic_events.dar import 'package:web3modal_flutter/services/w3m_service/i_w3m_service.dart'; import 'package:web3modal_flutter/theme/constants.dart'; import 'package:web3modal_flutter/utils/asset_util.dart'; -import 'package:web3modal_flutter/utils/util.dart'; import 'package:web3modal_flutter/web3modal_flutter.dart'; import 'package:web3modal_flutter/widgets/buttons/balance_button.dart'; import 'package:web3modal_flutter/widgets/buttons/base_button.dart'; @@ -71,17 +70,31 @@ class _W3MAccountButtonState extends State { }); } - void _onTap() => widget.service.openModal(widget.context ?? context); + void _onTap() { + if (widget.service.modalContext != null) { + widget.service.openModalView(); + } else { + // TODO remove this once context parameter is enforced + // ignore: deprecated_member_use_from_same_package + widget.service.openModal(widget.context ?? context); + } + } void _approveSign(MagicRequestEvent? args) async { if (args?.request != null) { if (widget.service.isOpen) { widgetStack.instance.popAllAndPush(ApproveTransactionPage()); } else { - widget.service.openModal( - widget.context ?? context, - ApproveTransactionPage(), - ); + if (widget.service.modalContext != null) { + widget.service.openModalView(ApproveTransactionPage()); + } else { + // TODO remove this once context parameter is enforced + // ignore: deprecated_member_use_from_same_package + widget.service.openModal( + widget.context ?? context, + ApproveTransactionPage(), + ); + } } } } @@ -90,7 +103,13 @@ class _W3MAccountButtonState extends State { if (widget.service.isOpen) { widgetStack.instance.popAllAndPush(ConfirmEmailPage()); } else { - widget.service.openModal(widget.context ?? context, ConfirmEmailPage()); + if (widget.service.modalContext != null) { + widget.service.openModalView(ConfirmEmailPage()); + } else { + // TODO remove this once context parameter is enforced + // ignore: deprecated_member_use_from_same_package + widget.service.openModal(widget.context ?? context, ConfirmEmailPage()); + } } } diff --git a/lib/widgets/w3m_connect_wallet_button.dart b/lib/widgets/w3m_connect_wallet_button.dart index ca3041d2..be30abbc 100644 --- a/lib/widgets/w3m_connect_wallet_button.dart +++ b/lib/widgets/w3m_connect_wallet_button.dart @@ -70,7 +70,13 @@ class _W3MConnectWalletButtonState extends State { if (widget.service.isConnected) { widget.service.disconnect(); } else { - widget.service.openModal(widget.context ?? context); + if (widget.service.modalContext != null) { + widget.service.openModalView(); + } else { + // TODO remove this once context parameter is enforced + // ignore: deprecated_member_use_from_same_package + widget.service.openModal(widget.context ?? context); + } _updateState(); } } diff --git a/lib/widgets/w3m_network_select_button.dart b/lib/widgets/w3m_network_select_button.dart index 10e5fc84..898539f5 100644 --- a/lib/widgets/w3m_network_select_button.dart +++ b/lib/widgets/w3m_network_select_button.dart @@ -56,15 +56,28 @@ class _W3MNetworkSelectButtonState extends State { void _onConnectPressed() { analyticsService.instance.sendEvent(ClickNetworksEvent()); - widget.service.openModal( - widget.context ?? context, - SelectNetworkPage( - onTapNetwork: (info) { - widget.service.selectChain(info); - widgetStack.instance.addDefault(); - }, - ), - ); + if (widget.service.modalContext != null) { + widget.service.openModalView( + SelectNetworkPage( + onTapNetwork: (info) { + widget.service.selectChain(info); + widgetStack.instance.addDefault(); + }, + ), + ); + } else { + // TODO remove this once context parameter is enforced + // ignore: deprecated_member_use_from_same_package + widget.service.openModal( + widget.context ?? context, + SelectNetworkPage( + onTapNetwork: (info) { + widget.service.selectChain(info); + widgetStack.instance.addDefault(); + }, + ), + ); + } } void _onServiceUpdate() { diff --git a/macos/Flutter/GeneratedPluginRegistrant.swift b/macos/Flutter/GeneratedPluginRegistrant.swift index 03439581..3ebb6b9e 100644 --- a/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/macos/Flutter/GeneratedPluginRegistrant.swift @@ -5,7 +5,6 @@ import FlutterMacOS import Foundation -import flutter_timezone import package_info_plus import path_provider_foundation import shared_preferences_foundation @@ -13,7 +12,6 @@ import sqflite import url_launcher_macos func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { - FlutterTimezonePlugin.register(with: registry.registrar(forPlugin: "FlutterTimezonePlugin")) FPPPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FPPPackageInfoPlusPlugin")) PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin")) SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin")) diff --git a/pubspec.lock b/pubspec.lock index fdd12fb2..e08d1a4c 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -355,14 +355,6 @@ packages: description: flutter source: sdk version: "0.0.0" - flutter_timezone: - dependency: "direct main" - description: - name: flutter_timezone - sha256: "06b35132c98fa188db3c4b654b7e1af7ccd01dfe12a004d58be423357605fb24" - url: "https://pub.dev" - source: hosted - version: "1.0.8" flutter_web_plugins: dependency: transitive description: flutter diff --git a/pubspec.yaml b/pubspec.yaml index 1b543d31..ff8bd773 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.3.0-beta01 +version: 3.3.0-beta02 repository: https://github.com/WalletConnect/Web3ModalFlutter environment: @@ -17,7 +17,6 @@ dependencies: flutter: sdk: flutter flutter_svg: ^2.0.10+1 - flutter_timezone: ^1.0.8 freezed_annotation: ^2.4.1 http: ^1.1.2 json_annotation: ^4.8.1 diff --git a/test/mock_classes.mocks.dart b/test/mock_classes.mocks.dart index 0e7db331..8a780536 100644 --- a/test/mock_classes.mocks.dart +++ b/test/mock_classes.mocks.dart @@ -640,6 +640,15 @@ class MockW3MService extends _i1.Mock implements _i3.W3MService { returnValueForMissingStub: _i14.Future.value(), ) as _i14.Future); @override + _i14.Future openNetworksView() => (super.noSuchMethod( + Invocation.method( + #openNetworksView, + [], + ), + returnValue: _i14.Future.value(), + returnValueForMissingStub: _i14.Future.value(), + ) as _i14.Future); + @override _i14.Future openModal( _i11.BuildContext? context, [ _i11.Widget? startWidget, @@ -656,6 +665,16 @@ class MockW3MService extends _i1.Mock implements _i3.W3MService { returnValueForMissingStub: _i14.Future.value(), ) as _i14.Future); @override + _i14.Future openModalView([_i11.Widget? startWidget]) => + (super.noSuchMethod( + Invocation.method( + #openModalView, + [startWidget], + ), + returnValue: _i14.Future.value(), + returnValueForMissingStub: _i14.Future.value(), + ) as _i14.Future); + @override _i14.Future expirePreviousInactivePairings() => (super.noSuchMethod( Invocation.method( #expirePreviousInactivePairings, diff --git a/test/w3m_account_page/w3m_account_page_ui_test.dart b/test/w3m_account_page/w3m_account_page_ui_test.dart index c7be6178..d56a1c8a 100644 --- a/test/w3m_account_page/w3m_account_page_ui_test.dart +++ b/test/w3m_account_page/w3m_account_page_ui_test.dart @@ -8,7 +8,6 @@ import 'package:web3modal_flutter/constants/string_constants.dart'; import 'package:web3modal_flutter/pages/account_page.dart'; import 'package:web3modal_flutter/services/explorer_service/explorer_service_singleton.dart'; import 'package:web3modal_flutter/services/w3m_service/i_w3m_service.dart'; -import 'package:web3modal_flutter/utils/util.dart'; import 'package:web3modal_flutter/web3modal_flutter.dart'; import 'package:web3modal_flutter/widgets/web3modal_provider.dart'; import 'package:web3modal_flutter/widgets/buttons/balance_button.dart'; diff --git a/test/w3m_connect/w3m_connect_ui_test.dart b/test/w3m_connect/w3m_connect_ui_test.dart index 5a26b5f2..9072f3dc 100644 --- a/test/w3m_connect/w3m_connect_ui_test.dart +++ b/test/w3m_connect/w3m_connect_ui_test.dart @@ -3,7 +3,6 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:mockito/mockito.dart'; import 'package:web3modal_flutter/constants/key_constants.dart'; import 'package:web3modal_flutter/constants/string_constants.dart'; -import 'package:web3modal_flutter/utils/util.dart'; import 'package:web3modal_flutter/web3modal_flutter.dart'; import 'package:web3modal_flutter/widgets/buttons/balance_button.dart';