From 65e4d3714cf455700f5a5be5d41507c66e50025a Mon Sep 17 00:00:00 2001 From: Alfreedom <00tango.bromine@icloud.com> Date: Thu, 19 Dec 2024 15:52:00 +0100 Subject: [PATCH] Tron example on AppKit and some clean up on unused files --- .../reown_appkit/example/base/lib/main.dart | 174 +++++--- .../example/base/lib/pages/connect_page.dart | 269 +---------- .../example/base/lib/pages/sessions_page.dart | 126 ------ .../example/base/lib/utils/crypto/eip155.dart | 236 ---------- .../base/lib/utils/crypto/helpers.dart | 44 +- .../base/lib/utils/crypto/polkadot.dart | 65 --- .../example/base/lib/utils/crypto/solana.dart | 49 --- .../example/base/lib/utils/crypto/tron.dart | 105 +++++ .../base/lib/widgets/session_widget.dart | 416 ------------------ .../modal/widgets/buttons/network_button.dart | 8 +- .../lib/modal/widgets/icons/rounded_icon.dart | 4 +- .../public/appkit_modal_account_button.dart | 8 +- .../public/appkit_modal_address_button.dart | 16 +- .../public/appkit_modal_balance_button.dart | 8 +- .../test/tests/sign_client_helpers.dart | 1 + 15 files changed, 279 insertions(+), 1250 deletions(-) delete mode 100644 packages/reown_appkit/example/base/lib/pages/sessions_page.dart delete mode 100644 packages/reown_appkit/example/base/lib/utils/crypto/eip155.dart delete mode 100644 packages/reown_appkit/example/base/lib/utils/crypto/solana.dart create mode 100644 packages/reown_appkit/example/base/lib/utils/crypto/tron.dart delete mode 100644 packages/reown_appkit/example/base/lib/widgets/session_widget.dart diff --git a/packages/reown_appkit/example/base/lib/main.dart b/packages/reown_appkit/example/base/lib/main.dart index 550ca42..144a825 100644 --- a/packages/reown_appkit/example/base/lib/main.dart +++ b/packages/reown_appkit/example/base/lib/main.dart @@ -1,20 +1,24 @@ import 'dart:convert'; import 'dart:io'; +import 'dart:developer' as dev; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:reown_appkit/reown_appkit.dart'; +// ignore: depend_on_referenced_packages +import 'package:shared_preferences/shared_preferences.dart'; + import 'package:reown_appkit_dapp/models/page_data.dart'; import 'package:reown_appkit_dapp/pages/connect_page.dart'; import 'package:reown_appkit_dapp/pages/pairings_page.dart'; import 'package:reown_appkit_dapp/utils/constants.dart'; import 'package:reown_appkit_dapp/utils/crypto/helpers.dart'; +import 'package:reown_appkit_dapp/utils/crypto/polkadot.dart'; +import 'package:reown_appkit_dapp/utils/crypto/tron.dart'; import 'package:reown_appkit_dapp/utils/dart_defines.dart'; import 'package:reown_appkit_dapp/utils/deep_link_handler.dart'; import 'package:reown_appkit_dapp/utils/string_constants.dart'; import 'package:reown_appkit_dapp/widgets/event_widget.dart'; -// ignore: depend_on_referenced_packages -import 'package:shared_preferences/shared_preferences.dart'; void main() { WidgetsFlutterBinding.ensureInitialized(); @@ -92,7 +96,7 @@ class _MyHomePageState extends State { @override void initState() { super.initState(); - initializeService(); + _initializeService(); } String get _flavor { @@ -130,7 +134,7 @@ class _MyHomePageState extends State { ); } - Future initializeService() async { + Future _initializeService() async { _appKit = ReownAppKit( core: ReownCore( projectId: DartDefines.projectId, @@ -163,28 +167,8 @@ class _MyHomePageState extends State { final prefs = await SharedPreferences.getInstance(); final linkMode = prefs.getBool('appkit_sample_linkmode') ?? false; - if (!linkMode) { - ReownAppKitModalNetworks.addSupportedNetworks('polkadot', [ - ReownAppKitModalNetworkInfo( - name: 'Polkadot', - chainId: '91b171bb158e2d3848fa23a9f1c25182', - chainIcon: 'https://cryptologos.cc/logos/polkadot-new-dot-logo.png', - currency: 'DOT', - rpcUrl: 'https://rpc.polkadot.io', - explorerUrl: 'https://polkadot.subscan.io', - ), - ReownAppKitModalNetworkInfo( - name: 'Westend', - chainId: 'e143f23803ac50e8f6f8e62695d1ce9e', - currency: 'DOT', - rpcUrl: 'https://westend-rpc.polkadot.io', - explorerUrl: 'https://westend.subscan.io', - isTestNetwork: true, - ), - ]); - } else { - ReownAppKitModalNetworks.removeSupportedNetworks('solana'); - } + + _addOrRemoveNetworks(linkMode); _appKitModal = ReownAppKitModal( context: context, @@ -204,6 +188,11 @@ class _MyHomePageState extends State { // requiredNamespaces: {}, // optionalNamespaces: {}, // includedWalletIds: {}, + getBalanceFallback: () async { + // This method will be triggered if getting the balance from our blockchain API fails + // You could place here your own getBalance method + return 0.0; + }, featuredWalletIds: { 'fd20dc426fb37566d803205b19bbc1d4096b248ac04548e3cfb6b3a38bd033aa', // Coinbase '18450873727504ae9315a084fa7624b5297d2fe5880f0982979c17345a138277', // Kraken Wallet @@ -216,38 +205,7 @@ class _MyHomePageState extends State { // 'fd20dc426fb37566d803205b19bbc1d4096b248ac04548e3cfb6b3a38bd033aa', // Coinbase // }, // MORE WALLETS https://explorer.walletconnect.com/?type=wallet&chains=eip155%3A1 - optionalNamespaces: !linkMode - ? { - // This is needed if more chains besides EVM and Solana are supported - // mostly because we can not define internally every possible method for every possible chain - 'eip155': RequiredNamespace.fromJson({ - 'chains': ReownAppKitModalNetworks.getAllSupportedNetworks( - namespace: 'eip155', - ).map((chain) => 'eip155:${chain.chainId}').toList(), - 'methods': - NetworkUtils.defaultNetworkMethods['eip155']!.toList(), - 'events': NetworkUtils.defaultNetworkEvents['eip155']!.toList(), - }), - 'solana': RequiredNamespace.fromJson({ - 'chains': ReownAppKitModalNetworks.getAllSupportedNetworks( - namespace: 'solana', - ).map((chain) => 'solana:${chain.chainId}').toList(), - 'methods': - NetworkUtils.defaultNetworkMethods['solana']!.toList(), - 'events': [], - }), - 'polkadot': RequiredNamespace.fromJson({ - 'chains': ReownAppKitModalNetworks.getAllSupportedNetworks( - namespace: 'polkadot', - ).map((chain) => 'polkadot:${chain.chainId}').toList(), - 'methods': [ - 'polkadot_signMessage', - 'polkadot_signTransaction', - ], - 'events': [] - }), - } - : null, + optionalNamespaces: _updatedNamespaces(), ); _appKitModal!.onModalConnect.subscribe(_onModalConnect); @@ -325,6 +283,102 @@ class _MyHomePageState extends State { } } + // Adds or remove supported networks based on linkMode + void _addOrRemoveNetworks(bool linkMode) { + if (!linkMode) { + ReownAppKitModalNetworks.addSupportedNetworks('polkadot', [ + ReownAppKitModalNetworkInfo( + name: 'Polkadot', + chainId: '91b171bb158e2d3848fa23a9f1c25182', + chainIcon: 'https://cryptologos.cc/logos/polkadot-new-dot-logo.png', + currency: 'DOT', + rpcUrl: 'https://rpc.polkadot.io', + explorerUrl: 'https://polkadot.subscan.io', + ), + ReownAppKitModalNetworkInfo( + name: 'Westend', + chainId: 'e143f23803ac50e8f6f8e62695d1ce9e', + currency: 'DOT', + rpcUrl: 'https://westend-rpc.polkadot.io', + explorerUrl: 'https://westend.subscan.io', + isTestNetwork: true, + ), + ]); + ReownAppKitModalNetworks.addSupportedNetworks('tron', [ + ReownAppKitModalNetworkInfo( + name: 'Tron', + chainId: '0x2b6653dc', + chainIcon: 'https://cryptologos.cc/logos/tron-trx-logo.png', + currency: 'TRX', + rpcUrl: 'https://api.trongrid.io', + explorerUrl: 'https://tronscan.org', + ), + ReownAppKitModalNetworkInfo( + name: 'Tron testnet', + chainId: '0xcd8690dc', + chainIcon: 'https://cryptologos.cc/logos/tron-trx-logo.png', + currency: 'TRX', + rpcUrl: 'https://nile.trongrid.io', + explorerUrl: 'https://test.tronscan.org', + isTestNetwork: true, + ), + ]); + } else { + ReownAppKitModalNetworks.removeSupportedNetworks('solana'); + } + } + + // Updates namespaces based on supported networks list + Map? _updatedNamespaces() { + Map? namespaces = {}; + + final evmChains = ReownAppKitModalNetworks.getAllSupportedNetworks( + namespace: 'eip155', + ); + if (evmChains.isNotEmpty) { + namespaces['eip155'] = RequiredNamespace( + chains: evmChains.map((c) => 'eip155:${c.chainId}').toList(), + methods: NetworkUtils.defaultNetworkMethods['eip155']!.toList(), + events: NetworkUtils.defaultNetworkEvents['eip155']!.toList(), + ); + } + // + final solanaChains = ReownAppKitModalNetworks.getAllSupportedNetworks( + namespace: 'solana', + ); + if (solanaChains.isNotEmpty) { + namespaces['solana'] = RequiredNamespace( + chains: solanaChains.map((c) => 'solana:${c.chainId}').toList(), + methods: NetworkUtils.defaultNetworkMethods['solana']!.toList(), + events: NetworkUtils.defaultNetworkEvents['solana']!.toList(), + ); + } + // + final polkadotChains = ReownAppKitModalNetworks.getAllSupportedNetworks( + namespace: 'polkadot', + ); + if (polkadotChains.isNotEmpty) { + namespaces['polkadot'] = RequiredNamespace( + chains: polkadotChains.map((c) => 'polkadot:${c.chainId}').toList(), + methods: Polkadot.methods.values.toList(), + events: Polkadot.events.values.toList(), + ); + } + // + final tronChains = ReownAppKitModalNetworks.getAllSupportedNetworks( + namespace: 'tron', + ); + if (tronChains.isNotEmpty) { + namespaces['tron'] = RequiredNamespace( + chains: tronChains.map((c) => 'tron:${c.chainId}').toList(), + methods: Tron.methods.values.toList(), + events: Tron.events.values.toList(), + ); + } + + return namespaces; + } + Future _registerEventHandlers() async { final onLine = _appKit!.core.connectivity.isOnline.value; if (!onLine) { @@ -350,7 +404,9 @@ class _MyHomePageState extends State { } void _onSessionConnect(SessionConnect? event) { - log('[SampleDapp] _onSessionConnect ${jsonEncode(event?.session.toJson())}'); + dev.log( + '[SampleDapp] _onSessionConnect ${jsonEncode(event?.session.toJson())}', + ); } void _onSessionAuthResponse(SessionAuthResponse? response) { diff --git a/packages/reown_appkit/example/base/lib/pages/connect_page.dart b/packages/reown_appkit/example/base/lib/pages/connect_page.dart index 990a825..0279180 100644 --- a/packages/reown_appkit/example/base/lib/pages/connect_page.dart +++ b/packages/reown_appkit/example/base/lib/pages/connect_page.dart @@ -1,19 +1,11 @@ -import 'dart:async'; -import 'dart:convert'; - -import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:package_info_plus/package_info_plus.dart'; import 'package:qr_flutter/qr_flutter.dart'; import 'package:reown_appkit/reown_appkit.dart'; import 'package:reown_appkit_dapp/utils/constants.dart'; -import 'package:reown_appkit_dapp/utils/crypto/eip155.dart'; import 'package:reown_appkit_dapp/utils/crypto/helpers.dart'; -import 'package:reown_appkit_dapp/utils/crypto/polkadot.dart'; -import 'package:reown_appkit_dapp/utils/crypto/solana.dart'; import 'package:reown_appkit_dapp/utils/string_constants.dart'; -import 'package:reown_appkit_dapp/widgets/chain_button.dart'; import 'package:reown_appkit_dapp/widgets/method_dialog.dart'; import 'package:toastification/toastification.dart'; @@ -76,95 +68,9 @@ class ConnectPageState extends State { super.dispose(); } - void _selectChain(ReownAppKitModalNetworkInfo chain) { - setState(() { - if (_selectedChains.contains(chain)) { - _selectedChains.remove(chain); - } else { - _selectedChains.add(chain); - } - _updateNamespaces(); - }); - } - - Map requiredNamespaces = {}; - Map optionalNamespaces = {}; - - void _updateNamespaces() { - optionalNamespaces = {}; - - final evmChains = _selectedChains.where((c) { - final ns = ReownAppKitModalNetworks.getNamespaceForChainId(c.chainId); - return ns == 'eip155'; - }).toList(); - if (evmChains.isNotEmpty) { - optionalNamespaces['eip155'] = RequiredNamespace( - chains: evmChains.map((c) => 'eip155:${c.chainId}').toList(), - methods: EIP155.methods.values.toList(), - events: EIP155.events.values.toList(), - ); - } - - final solanaChains = _selectedChains.where((c) { - final ns = ReownAppKitModalNetworks.getNamespaceForChainId(c.chainId); - return ns == 'solana'; - }).toList(); - if (solanaChains.isNotEmpty) { - optionalNamespaces['solana'] = RequiredNamespace( - chains: solanaChains.map((c) => 'solana:${c.chainId}').toList(), - methods: Solana.methods.values.toList(), - events: Solana.events.values.toList(), - ); - } - - final polkadotChains = _selectedChains.where((c) { - final ns = ReownAppKitModalNetworks.getNamespaceForChainId(c.chainId); - return ns == 'polkadot'; - }).toList(); - if (polkadotChains.isNotEmpty) { - optionalNamespaces['polkadot'] = RequiredNamespace( - chains: polkadotChains.map((c) => 'polkadot:${c.chainId}').toList(), - methods: Polkadot.methods.values.toList(), - events: Polkadot.events.values.toList(), - ); - } - - debugPrint( - '[$runtimeType] optionalNamespaces ${jsonEncode(optionalNamespaces)}', - ); - } - @override Widget build(BuildContext context) { // Build the list of chain buttons, clear if the textnet changed - final allChains = ReownAppKitModalNetworks.getAllSupportedNetworks(); - final mainChains = allChains.where((e) => !e.isTestNetwork).toList(); - final testChains = allChains.where((e) => e.isTestNetwork).toList(); - - final List chainButtons = []; - final List testButtons = []; - - for (final chain in mainChains) { - // Build the button - chainButtons.add( - ChainButton( - chain: chain, - onPressed: () => _selectChain(chain), - selected: _selectedChains.contains(chain), - ), - ); - } - for (final chain in testChains) { - // Build the button - testButtons.add( - ChainButton( - chain: chain, - onPressed: () => _selectChain(chain), - selected: _selectedChains.contains(chain), - ), - ); - } - return ListView( padding: const EdgeInsets.symmetric( horizontal: StyleConstants.linear8, @@ -293,7 +199,11 @@ class ConnectPageState extends State { vertical: StyleConstants.linear8, ), child: FutureBuilder( - future: getParams(method, address, rpcUrl: chainInfo?.rpcUrl), + future: getParams( + method, + address, + chainInfo!, + ), builder: (_, snapshot) { final enabled = snapshot.data != null; return ElevatedButton( @@ -316,143 +226,6 @@ class ConnectPageState extends State { []; } - // ignore: unused_element - Future _onConnect({ - required String nativeLink, - VoidCallback? closeModal, - Function(String message)? showToast, - }) async { - debugPrint('[SampleDapp] Creating connection with $nativeLink'); - // It is currently safer to send chains approvals on optionalNamespaces - // but depending on Wallet implementation you may need to send some (for innstance eip155:1) as required - final connectResponse = await widget.appKitModal.appKit!.connect( - requiredNamespaces: requiredNamespaces, - optionalNamespaces: optionalNamespaces, - ); - - try { - final encodedUri = Uri.encodeComponent(connectResponse.uri.toString()); - final uri = '$nativeLink?uri=$encodedUri'; - await ReownCoreUtils.openURL(uri); - } catch (e) { - _showQrCode(connectResponse.uri.toString()); - } - - debugPrint('[SampleDapp] Awaiting session proposal settlement'); - try { - await connectResponse.session.future; - showToast?.call(StringConstants.connectionEstablished); - } on JsonRpcError catch (e) { - showToast?.call(e.message.toString()); - } - closeModal?.call(); - } - - // ignore: unused_element - void _sessionAuthenticate({ - required String nativeLink, - required String universalLink, - VoidCallback? closeModal, - Function(String message)? showToast, - }) async { - debugPrint( - '[SampleDapp] Creating authentication with $nativeLink, $universalLink', - ); - final methods1 = requiredNamespaces['eip155']?.methods ?? []; - final methods2 = optionalNamespaces['eip155']?.methods ?? []; - final authResponse = await widget.appKitModal.appKit!.authenticate( - params: SessionAuthRequestParams( - chains: _selectedChains.map((e) => 'eip155:${e.chainId}').toList(), - domain: Uri.parse(widget.appKitModal.appKit!.metadata.url).authority, - nonce: AuthUtils.generateNonce(), - uri: widget.appKitModal.appKit!.metadata.url, - statement: 'Welcome to example flutter app', - methods: {...methods1, ...methods2}.toList(), - ), - walletUniversalLink: universalLink, - ); - - debugPrint('[SampleDapp] authResponse.uri ${authResponse.uri}'); - try { - // If response uri is not universalLink show QR Code - if (authResponse.uri?.authority != Uri.parse(universalLink).authority) { - _showQrCode('${authResponse.uri}', walletScheme: nativeLink); - } else { - await ReownCoreUtils.openURL(authResponse.uri.toString()); - } - } catch (e) { - debugPrint('[SampleDapp] authResponse error $e'); - _showQrCode('${authResponse.uri}', walletScheme: nativeLink); - } - - try { - debugPrint('[SampleDapp] Awaiting 1-CA session'); - final response = await authResponse.completer.future; - - if (response.session != null) { - showToast?.call( - '${StringConstants.authSucceeded} and ${StringConstants.connectionEstablished}', - ); - } else { - final error = response.error ?? response.jsonRpcError; - showToast?.call(error.toString()); - } - } catch (e) { - debugPrint('[SampleDapp] 1-CA $e'); - showToast?.call(StringConstants.connectionFailed); - } - closeModal?.call(); - } - - Future _showQrCode(String uri, {String walletScheme = ''}) async { - // Show the QR code - debugPrint('[SampleDapp] Showing QR Code: $uri'); - _shouldDismissQrCode = true; - if (kIsWeb) { - await showDialog( - context: context, - barrierDismissible: false, - builder: (BuildContext context) { - return AlertDialog( - insetPadding: const EdgeInsets.all(0.0), - contentPadding: const EdgeInsets.all(0.0), - backgroundColor: Colors.white, - content: SizedBox( - width: 400.0, - child: AspectRatio( - aspectRatio: 0.8, - child: Padding( - padding: const EdgeInsets.all(20.0), - child: _QRCodeView( - uri: uri, - ), - ), - ), - ), - actions: [ - TextButton( - onPressed: () => Navigator.pop(context), - child: const Text('Cancel'), - ) - ], - ); - }, - ); - _shouldDismissQrCode = false; - return; - } - Navigator.push( - context, - MaterialPageRoute( - fullscreenDialog: true, - builder: (context) => QRCodeScreen( - uri: uri, - walletScheme: walletScheme, - ), - ), - ); - } - void _onSessionConnect(SessionConnect? event) async { if (event == null) return; @@ -489,38 +262,6 @@ class ConnectPageState extends State { void _onModalError(ModalError? event) { setState(() {}); } - - // ignore: unused_element - ButtonStyle get _buttonStyle => ButtonStyle( - backgroundColor: WidgetStateProperty.resolveWith( - (states) { - if (states.contains(WidgetState.disabled)) { - return StyleConstants.grayColor; - } - return Colors.blue; - }, - ), - textStyle: WidgetStateProperty.resolveWith( - (states) => TextStyle( - fontSize: 8.0, - fontWeight: FontWeight.w400, - ), - ), - padding: WidgetStateProperty.resolveWith( - (states) => EdgeInsets.all(0.0), - ), - minimumSize: WidgetStateProperty.all(const Size( - 1000.0, - StyleConstants.linear48, - )), - shape: WidgetStateProperty.all( - RoundedRectangleBorder( - borderRadius: BorderRadius.circular( - StyleConstants.linear8, - ), - ), - ), - ); } class _FooterWidget extends StatefulWidget { diff --git a/packages/reown_appkit/example/base/lib/pages/sessions_page.dart b/packages/reown_appkit/example/base/lib/pages/sessions_page.dart deleted file mode 100644 index 412e318..0000000 --- a/packages/reown_appkit/example/base/lib/pages/sessions_page.dart +++ /dev/null @@ -1,126 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:reown_appkit/reown_appkit.dart'; - -import 'package:reown_appkit_dapp/utils/constants.dart'; -import 'package:reown_appkit_dapp/utils/string_constants.dart'; -import 'package:reown_appkit_dapp/widgets/session_item.dart'; -import 'package:reown_appkit_dapp/widgets/session_widget.dart'; - -class SessionsPage extends StatefulWidget { - const SessionsPage({ - super.key, - required this.appKitModal, - }); - - final ReownAppKitModal appKitModal; - - @override - SessionsPageState createState() => SessionsPageState(); -} - -class SessionsPageState extends State { - late IReownAppKit _appKit; - Map _activeSessions = {}; - String _selectedTopic = ''; - - @override - void initState() { - _appKit = widget.appKitModal.appKit!; - _activeSessions = _appKit.getActiveSessions(); - _appKit.onSessionDelete.subscribe(_onSessionDelete); - _appKit.onSessionExpire.subscribe(_onSessionExpire); - super.initState(); - } - - @override - void dispose() { - _appKit.onSessionDelete.unsubscribe(_onSessionDelete); - _appKit.onSessionExpire.unsubscribe(_onSessionExpire); - super.dispose(); - } - - @override - Widget build(BuildContext context) { - final List sessions = _activeSessions.values.toList(); - if (sessions.isEmpty) { - return Center( - child: Text('No relay sessions'), - ); - } - return Center( - child: Container( - constraints: const BoxConstraints( - maxWidth: StyleConstants.maxWidth, - ), - child: Align( - alignment: Alignment.topCenter, - child: SingleChildScrollView( - child: ExpansionPanelList( - elevation: 0.0, - materialGapSize: 0.0, - expansionCallback: (int index, bool isExpanded) { - setState(() { - _selectedTopic = !isExpanded ? '' : sessions[index].topic; - }); - }, - children: sessions - .map( - (session) => ExpansionPanel( - canTapOnHeader: true, - isExpanded: _selectedTopic == session.topic, - backgroundColor: Colors.blue.withOpacity(0.2), - headerBuilder: (context, isExpanded) { - return SessionItem( - key: ValueKey(session.topic), - session: session, - ); - }, - body: Container( - height: MediaQuery.of(context).size.height - 300.0, - padding: const EdgeInsets.symmetric(horizontal: 12.0), - child: _buildSessionView(), - ), - ), - ) - .toList(), - ), - ), - ), - ), - ); - } - - Widget _buildSessionView() { - if (_selectedTopic == '') { - return const Center( - child: Text( - StringConstants.noSessionSelected, - style: StyleConstants.titleText, - ), - ); - } - - return SessionWidget( - appKitModal: widget.appKitModal, - sessionTopic: _selectedTopic, - ); - } - - void _onSessionDelete(SessionDelete? event) { - setState(() { - if (event!.topic == _selectedTopic) { - _selectedTopic = ''; - } - _activeSessions = _appKit.getActiveSessions(); - }); - } - - void _onSessionExpire(SessionExpire? event) { - setState(() { - if (event!.topic == _selectedTopic) { - _selectedTopic = ''; - } - _activeSessions = _appKit.getActiveSessions(); - }); - } -} diff --git a/packages/reown_appkit/example/base/lib/utils/crypto/eip155.dart b/packages/reown_appkit/example/base/lib/utils/crypto/eip155.dart deleted file mode 100644 index 594bb28..0000000 --- a/packages/reown_appkit/example/base/lib/utils/crypto/eip155.dart +++ /dev/null @@ -1,236 +0,0 @@ -import 'dart:convert'; - -import 'package:intl/intl.dart'; -import 'package:reown_appkit/reown_appkit.dart'; -import 'package:reown_appkit_dapp/utils/crypto/helpers.dart'; -import 'package:reown_appkit_dapp/utils/smart_contracts.dart'; - -enum EIP155Methods { - personalSign, - ethSign, - ethSignTransaction, - ethSignTypedData, - ethSendTransaction, -} - -enum EIP155Events { - chainChanged, - accountsChanged, -} - -class EIP155 { - static final Map methods = { - EIP155Methods.personalSign: 'personal_sign', - EIP155Methods.ethSign: 'eth_sign', - EIP155Methods.ethSignTransaction: 'eth_signTransaction', - EIP155Methods.ethSignTypedData: 'eth_signTypedData', - EIP155Methods.ethSendTransaction: 'eth_sendTransaction', - }; - - static final Map events = { - EIP155Events.chainChanged: 'chainChanged', - EIP155Events.accountsChanged: 'accountsChanged', - }; - - static Future callMethod({ - required IReownAppKit appKit, - required String topic, - required String method, - required ReownAppKitModalNetworkInfo chainData, - required String address, - }) { - switch (method) { - case 'personal_sign': - return personalSign( - appKit: appKit, - topic: topic, - chainId: chainData.chainId, - address: address, - ); - case 'eth_sign': - return ethSign( - appKit: appKit, - topic: topic, - chainId: chainData.chainId, - address: address, - ); - case 'eth_signTypedData': - return ethSignTypedData( - appKit: appKit, - topic: topic, - chainId: chainData.chainId, - address: address, - ); - case 'eth_signTransaction': - return ethSignTransaction( - appKit: appKit, - topic: topic, - chainId: chainData.chainId, - ); - case 'eth_sendTransaction': - return ethSendTransaction( - appKit: appKit, - topic: topic, - chainId: chainData.chainId, - ); - default: - throw 'Method unimplemented'; - } - } - - static Future callSmartContract({ - required IReownAppKit appKit, - required String topic, - required String address, - required String action, - }) { - // Create DeployedContract object using contract's ABI and address - final deployedContract = DeployedContract( - ContractAbi.fromJson( - jsonEncode(SepoliaTestContract.readContractAbi), - 'Alfreedoms', - ), - EthereumAddress.fromHex(SepoliaTestContract.contractAddress), - ); - - final sepolia = ReownAppKitModalNetworks.getNetworkById( - 'eip155', - '11155111', - )!; - - switch (action) { - case 'read': - return readSmartContract( - appKit: appKit, - rpcUrl: sepolia.rpcUrl, - contract: deployedContract, - address: address, - ); - case 'write': - return appKit.requestWriteContract( - topic: topic, - chainId: 'eip155:${sepolia.chainId}', - deployedContract: deployedContract, - functionName: 'transfer', - transaction: Transaction( - from: EthereumAddress.fromHex(address), - ), - parameters: [ - // Recipient - EthereumAddress.fromHex( - '0x59e2f66C0E96803206B6486cDb39029abAE834c0', - ), - // Amount to Transfer - EtherAmount.fromInt(EtherUnit.finney, 10).getInWei, // == 0.010 - ], - ); - default: - return Future.value(); - } - } - - static Future personalSign({ - required IReownAppKit appKit, - required String topic, - required String chainId, - required String address, - }) async { - return await appKit.request( - topic: topic, - chainId: 'eip155:$chainId', - request: (await getParams('personal_sign', address))!, - ); - } - - static Future ethSign({ - required IReownAppKit appKit, - required String topic, - required String chainId, - required String address, - }) async { - return await appKit.request( - topic: topic, - chainId: 'eip155:$chainId', - request: (await getParams('eth_sign', address))!, - ); - } - - static Future ethSignTypedData({ - required IReownAppKit appKit, - required String topic, - required String chainId, - required String address, - }) async { - return await appKit.request( - topic: topic, - chainId: 'eip155:$chainId', - request: (await getParams('eth_signTypedData', address))!, - ); - } - - static Future ethSignTransaction({ - required IReownAppKit appKit, - required String topic, - required String chainId, - }) async { - return await appKit.request( - topic: topic, - chainId: 'eip155:$chainId', - request: (await getParams('eth_signTransaction', ''))!, - ); - } - - static Future ethSendTransaction({ - required IReownAppKit appKit, - required String topic, - required String chainId, - }) async { - return await appKit.request( - topic: topic, - chainId: 'eip155:$chainId', - request: (await getParams('eth_sendTransaction', ''))!, - ); - } - - static Future readSmartContract({ - required IReownAppKit appKit, - required String rpcUrl, - required String address, - required DeployedContract contract, - }) async { - final results = await Future.wait([ - // results[0] - appKit.requestReadContract( - deployedContract: contract, - functionName: 'name', - rpcUrl: rpcUrl, - ), - // results[1] - appKit.requestReadContract( - deployedContract: contract, - functionName: 'totalSupply', - rpcUrl: rpcUrl, - ), - // results[2] - appKit.requestReadContract( - deployedContract: contract, - functionName: 'balanceOf', - rpcUrl: rpcUrl, - parameters: [ - EthereumAddress.fromHex(address), - ], - ), - ]); - - final oCcy = NumberFormat('#,##0.00', 'en_US'); - final name = results[0].first.toString(); - final total = results[1].first / BigInt.from(1000000000000000000); - final balance = results[2].first / BigInt.from(1000000000000000000); - - return { - 'name': name, - 'totalSupply': oCcy.format(total), - 'balance': oCcy.format(balance), - }; - } -} diff --git a/packages/reown_appkit/example/base/lib/utils/crypto/helpers.dart b/packages/reown_appkit/example/base/lib/utils/crypto/helpers.dart index 5caf4b9..7329b93 100644 --- a/packages/reown_appkit/example/base/lib/utils/crypto/helpers.dart +++ b/packages/reown_appkit/example/base/lib/utils/crypto/helpers.dart @@ -3,9 +3,8 @@ import 'dart:convert'; import 'package:bs58/bs58.dart'; import 'package:eth_sig_util/util/utils.dart'; import 'package:reown_appkit/reown_appkit.dart'; -import 'package:reown_appkit_dapp/utils/crypto/eip155.dart'; import 'package:reown_appkit_dapp/utils/crypto/polkadot.dart'; -import 'package:reown_appkit_dapp/utils/crypto/solana.dart'; +import 'package:reown_appkit_dapp/utils/crypto/tron.dart'; import 'package:reown_appkit_dapp/utils/test_data.dart'; import 'package:solana_web3/solana_web3.dart' as solana; @@ -13,11 +12,13 @@ import 'package:solana_web3/solana_web3.dart' as solana; List getChainMethods(String namespace) { switch (namespace) { case 'eip155': - return EIP155.methods.values.toList(); + return NetworkUtils.defaultNetworkMethods['eip155']!.toList(); case 'solana': - return Solana.methods.values.toList(); + return NetworkUtils.defaultNetworkMethods['solana']!.toList(); case 'polkadot': return Polkadot.methods.values.toList(); + case 'tron': + return Tron.methods.values.toList(); default: return []; } @@ -26,11 +27,13 @@ List getChainMethods(String namespace) { List getChainEvents(String namespace) { switch (namespace) { case 'eip155': - return EIP155.events.values.toList(); + return NetworkUtils.defaultNetworkEvents['eip155']!.toList(); case 'solana': - return Solana.events.values.toList(); + return NetworkUtils.defaultNetworkEvents['solana']!.toList(); case 'polkadot': return Polkadot.events.values.toList(); + case 'tron': + return Tron.events.values.toList(); default: return []; } @@ -38,9 +41,9 @@ List getChainEvents(String namespace) { Future getParams( String method, - String address, { - String? rpcUrl, -}) async { + String address, + ReownAppKitModalNetworkInfo chainData, +) async { switch (method) { case 'personal_sign': final bytes = utf8.encode(testSignData); @@ -95,7 +98,7 @@ Future getParams( case 'solana_signTransaction': // Create a connection to the devnet cluster. final cluster = solana.Cluster.https( - Uri.parse(rpcUrl!).authority, + Uri.parse(chainData.rpcUrl).authority, ); // final cluster = solana.Cluster.devnet; final connection = solana.Connection(cluster); @@ -149,6 +152,27 @@ Future getParams( // ...transactionv0.message.toJson(), }, ); + case 'tron_signMessage': + return SessionRequestParams( + method: method, + params: { + 'address': address, + 'message': testSignData, + }, + ); + case 'tron_signTransaction': + // + final transaction = await Tron.triggerSmartContract( + chainData: chainData, + walletAdress: address, + ); + return SessionRequestParams( + method: method, + params: { + 'address': address, + 'transaction': transaction, + }, + ); default: return null; } diff --git a/packages/reown_appkit/example/base/lib/utils/crypto/polkadot.dart b/packages/reown_appkit/example/base/lib/utils/crypto/polkadot.dart index 194aacb..3242905 100644 --- a/packages/reown_appkit/example/base/lib/utils/crypto/polkadot.dart +++ b/packages/reown_appkit/example/base/lib/utils/crypto/polkadot.dart @@ -1,5 +1,3 @@ -import 'package:reown_appkit/reown_appkit.dart'; - enum PolkadotMethods { polkadotSignTransaction, polkadotSignMessage, @@ -16,67 +14,4 @@ class Polkadot { }; static final Map events = {}; - - static Future callMethod({ - required IReownAppKit appKit, - required String topic, - required String method, - required ReownAppKitModalNetworkInfo chainData, - required String address, - }) { - switch (method) { - case 'polkadot_signMessage': - return appKit.request( - topic: topic, - chainId: chainData.chainId, - request: SessionRequestParams( - method: method, - params: { - 'address': address, - 'message': - 'This is an example message to be signed - ${DateTime.now()}', - }, - ), - ); - case 'polkadot_signTransaction': - return appKit.request( - topic: topic, - chainId: chainData.chainId, - request: SessionRequestParams( - method: method, - params: { - 'address': address, - 'transactionPayload': { - 'specVersion': '0x00002468', - 'transactionVersion': '0x0000000e', - 'address': address, - 'blockHash': - '0x554d682a74099d05e8b7852d19c93b527b5fae1e9e1969f6e1b82a2f09a14cc9', - 'blockNumber': '0x00cb539c', - 'era': '0xc501', - 'genesisHash': - '0xe143f23803ac50e8f6f8e62695d1ce9e4e1d68aa36c1cd2cfd15340213f3423e', - 'method': - '0x0001784920616d207369676e696e672074686973207472616e73616374696f6e21', - 'nonce': '0x00000000', - 'signedExtensions': [ - 'CheckNonZeroSender', - 'CheckSpecVersion', - 'CheckTxVersion', - 'CheckGenesis', - 'CheckMortality', - 'CheckNonce', - 'CheckWeight', - 'ChargeTransactionPayment', - ], - 'tip': '0x00000000000000000000000000000000', - 'version': 4, - }, - }, - ), - ); - default: - throw 'Method unimplemented'; - } - } } diff --git a/packages/reown_appkit/example/base/lib/utils/crypto/solana.dart b/packages/reown_appkit/example/base/lib/utils/crypto/solana.dart deleted file mode 100644 index 57266e1..0000000 --- a/packages/reown_appkit/example/base/lib/utils/crypto/solana.dart +++ /dev/null @@ -1,49 +0,0 @@ -import 'package:reown_appkit_dapp/utils/crypto/helpers.dart'; -import 'package:reown_appkit/reown_appkit.dart'; - -enum SolanaMethods { - solanaSignTransaction, - solanaSignMessage, -} - -enum SolanaEvents { - none, -} - -class Solana { - static final Map methods = { - SolanaMethods.solanaSignTransaction: 'solana_signTransaction', - SolanaMethods.solanaSignMessage: 'solana_signMessage' - }; - - static final Map events = {}; - - static Future callMethod({ - required IReownAppKit appKit, - required String topic, - required String method, - required ReownAppKitModalNetworkInfo chainData, - required String address, - }) async { - switch (method) { - case 'solana_signMessage': - return appKit.request( - topic: topic, - chainId: chainData.chainId, - request: (await getParams(method, address))!, - ); - case 'solana_signTransaction': - return appKit.request( - topic: topic, - chainId: chainData.chainId, - request: (await getParams( - method, - address, - rpcUrl: chainData.rpcUrl, - ))!, - ); - default: - throw 'Method unimplemented'; - } - } -} diff --git a/packages/reown_appkit/example/base/lib/utils/crypto/tron.dart b/packages/reown_appkit/example/base/lib/utils/crypto/tron.dart new file mode 100644 index 0000000..97fd2a3 --- /dev/null +++ b/packages/reown_appkit/example/base/lib/utils/crypto/tron.dart @@ -0,0 +1,105 @@ +import 'package:flutter/foundation.dart'; +import 'package:reown_appkit/reown_appkit.dart'; + +import 'dart:convert'; +// ignore: depend_on_referenced_packages +import 'package:http/http.dart' as http; +import 'package:solana_web3/solana_web3.dart' as solana; +import 'package:bs58/bs58.dart'; + +enum TronMethods { + tronSignTransaction, + tronSignMessage, +} + +enum TronEvents { + none, +} + +class Tron { + static final Map methods = { + TronMethods.tronSignTransaction: 'tron_signTransaction', + TronMethods.tronSignMessage: 'tron_signMessage' + }; + + static final Map events = {}; + + static Future> triggerSmartContract({ + required ReownAppKitModalNetworkInfo chainData, + required String walletAdress, + }) async { + /// Get the USDT contract address + final usdtContract = chainData.isTestNetwork + ? 'TXYZopYRdj2D9XRtbG411XZZ3kM5VkAeBf' + : 'TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t'; + + final parameter = [ + {'type': 'address', 'value': walletAdress}, + {'type': 'uint256', 'value': 1} + ]; + final params = _convertToFormat(parameter); + // + // https://developers.tron.network/reference/triggersmartcontract + final url = '${chainData.rpcUrl}/wallet/triggersmartcontract'; + final paradic = { + 'owner_address': walletAdress, + 'contract_address': usdtContract, + 'function_selector': 'approve(address,uint256)', + 'parameter': params, + 'fee_limit': 200000000, + 'call_value': 0, + 'visible': true + }; + final respom = await http.post( + Uri.parse(url), + body: jsonEncode(paradic), + headers: { + 'accept': 'application/json', + }, + ); + try { + return jsonDecode(respom.body) as Map; + } catch (e) { + debugPrint(e.toString()); + rethrow; + } + } + + static String _convertToFormat(List> data) { + String result = ''; + for (var item in data) { + if (item['type'] == 'address') { + String addressValue = item['value']; + result += _addressToFormat(addressValue); + } else if (item['type'] == 'uint256') { + int intValue = item['value']; + result += _uint256ToFormat(intValue); + } else if (item['type'] == 'bool') { + String value = + item['value'].toString().toLowerCase() == 'true' ? '1' : '0'; + result += _boolvalue(value); + } + } + return result; + } + + static String _addressToFormat(String addressValue) { + var addres = base58.decode(addressValue); + var hex1 = solana.hex.encode(addres); + var hex2 = hex1.substring(2); + var finalhex = hex2.substring(0, hex2.length - 8); + return finalhex.padLeft(64, '0'); + } + + static String _boolvalue(String value) { + return value.padLeft(64, '0'); + } + + static String _uint256ToFormat(int intValue) { + String hexValue = intValue.toRadixString(16).padLeft(64, '0'); + if (hexValue.length > 64) { + throw Exception('Integer value exceeds 64 bits'); + } + return hexValue; + } +} diff --git a/packages/reown_appkit/example/base/lib/widgets/session_widget.dart b/packages/reown_appkit/example/base/lib/widgets/session_widget.dart deleted file mode 100644 index 6af3a83..0000000 --- a/packages/reown_appkit/example/base/lib/widgets/session_widget.dart +++ /dev/null @@ -1,416 +0,0 @@ -import 'package:flutter/foundation.dart'; -import 'package:flutter/material.dart'; -import 'package:reown_appkit/reown_appkit.dart'; -import 'package:reown_appkit_dapp/utils/constants.dart'; -import 'package:reown_appkit_dapp/utils/crypto/eip155.dart'; -import 'package:reown_appkit_dapp/utils/crypto/helpers.dart'; -import 'package:reown_appkit_dapp/utils/crypto/polkadot.dart'; -import 'package:reown_appkit_dapp/utils/crypto/solana.dart'; -import 'package:reown_appkit_dapp/utils/string_constants.dart'; -import 'package:reown_appkit_dapp/widgets/method_dialog.dart'; - -class SessionWidget extends StatefulWidget { - const SessionWidget({ - super.key, - required this.sessionTopic, - required this.appKitModal, - }); - - final String sessionTopic; - final ReownAppKitModal appKitModal; - - @override - SessionWidgetState createState() => SessionWidgetState(); -} - -class SessionWidgetState extends State { - late IReownAppKit _appKit; - late SessionData _session; - - @override - void initState() { - super.initState(); - _appKit = widget.appKitModal.appKit!; - _session = _appKit.sessions.get(widget.sessionTopic)!; - } - - @override - Widget build(BuildContext context) { - final List children = [ - Text( - '${StringConstants.sessionTopic}${_session.topic}', - ), - ]; - - // Get all of the accounts - final List namespaceAccounts = []; - - // Loop through the namespaces, and get the accounts - for (final Namespace namespace in _session.namespaces.values) { - namespaceAccounts.addAll(namespace.accounts); - } - - // Loop through the namespace accounts and build the widgets - for (final String namespaceAccount in namespaceAccounts) { - children.add( - _buildAccountWidget( - namespaceAccount, - ), - ); - } - - // Add a delete button - children.add( - Container( - width: double.infinity, - height: StyleConstants.linear48, - margin: const EdgeInsets.symmetric( - vertical: StyleConstants.linear8, - ), - child: ElevatedButton( - onPressed: () async { - await _appKit.disconnectSession( - topic: _session.topic, - reason: Errors.getSdkError( - Errors.USER_DISCONNECTED, - ).toSignError(), - ); - }, - style: ButtonStyle( - backgroundColor: WidgetStateProperty.all( - Colors.red, - ), - ), - child: const Text( - StringConstants.delete, - style: StyleConstants.buttonText, - ), - ), - ), - ); - - children.add(const SizedBox(height: 20.0)); - return ListView( - children: children, - ); - } - - Widget _buildAccountWidget(String namespaceAccount) { - final chainId = NamespaceUtils.getChainFromAccount(namespaceAccount); - final account = NamespaceUtils.getAccount(namespaceAccount); - final namespace = NamespaceUtils.getNamespaceFromChain( - chainId, - ); - final chainData = ReownAppKitModalNetworks.getNetworkById( - namespace, - chainId.split(':').last, - ); - - final List children = [ - Text( - chainData!.name, - style: StyleConstants.subtitleText, - ), - const SizedBox( - height: StyleConstants.linear8, - ), - Text( - account, - textAlign: TextAlign.center, - ), - const SizedBox( - height: StyleConstants.linear8, - ), - const Text( - StringConstants.methods, - style: StyleConstants.subtitleText, - ), - ]; - - children.addAll(_buildChainMethodButtons(chainData, account)); - - children.add(const Divider()); - - if (chainId != 'eip155:11155111') { - children.add(const Text('Connect to Sepolia to Test')); - } - children.addAll(_buildSepoliaButtons(account, chainId)); - - children.addAll([ - const SizedBox( - height: StyleConstants.linear8, - ), - const Text( - StringConstants.events, - style: StyleConstants.subtitleText, - ), - ]); - children.addAll(_buildChainEventsTiles(chainData)); - - // final ChainMetadata - return Container( - width: double.infinity, - // height: StyleConstants.linear48, - padding: const EdgeInsets.all( - StyleConstants.linear8, - ), - margin: const EdgeInsets.symmetric( - vertical: StyleConstants.linear8, - ), - decoration: BoxDecoration( - border: Border.all( - color: Colors.blue, - ), - borderRadius: const BorderRadius.all( - Radius.circular( - StyleConstants.linear8, - ), - ), - ), - child: Column( - children: children, - ), - ); - } - - List _buildChainMethodButtons( - ReownAppKitModalNetworkInfo chainMetadata, - String address, - ) { - final List buttons = []; - // Add Methods - final namespace = ReownAppKitModalNetworks.getNamespaceForChainId( - chainMetadata.chainId, - ); - for (final String method in getChainMethods(namespace)) { - final namespaces = _session.namespaces[namespace]; - final supported = namespaces?.methods.contains(method) ?? false; - buttons.add( - Container( - width: double.infinity, - height: StyleConstants.linear48, - margin: const EdgeInsets.symmetric( - vertical: StyleConstants.linear8, - ), - child: ElevatedButton( - onPressed: supported - ? () async { - final future = callChainMethod( - method, - chainMetadata, - address, - ); - MethodDialog.show(context, method, future); - _launchWallet(); - } - : null, - style: ButtonStyle( - backgroundColor: WidgetStateProperty.resolveWith( - (states) => states.contains(WidgetState.disabled) - ? Colors.grey - : Colors.blue, - ), - shape: WidgetStateProperty.all( - RoundedRectangleBorder( - borderRadius: BorderRadius.circular( - StyleConstants.linear8, - ), - ), - ), - ), - child: Text( - method, - style: StyleConstants.buttonText, - textAlign: TextAlign.center, - ), - ), - ), - ); - } - - return buttons; - } - - Future callChainMethod( - String method, - ReownAppKitModalNetworkInfo chainMetadata, - String address, - ) { - final namespace = ReownAppKitModalNetworks.getNamespaceForChainId( - chainMetadata.chainId, - ); - switch (namespace) { - case 'eip155': - return EIP155.callMethod( - appKit: _appKit, - topic: _session.topic, - method: method, - chainData: chainMetadata, - address: address, - ); - case 'polkadot': - return Polkadot.callMethod( - appKit: _appKit, - topic: _session.topic, - method: method, - chainData: chainMetadata, - address: address, - ); - case 'solana': - return Solana.callMethod( - appKit: _appKit, - topic: _session.topic, - method: method, - chainData: chainMetadata, - address: address, - ); - // case ChainType.kadena: - // return Kadena.callMethod( - // appKit: _appKit, - // topic: _session.topic, - // method: method.toKadenaMethod()!, - // chainId: chainMetadata.chainId, - // address: address.toLowerCase(), - // ); - default: - throw 'Unimplemented'; - } - } - - void _launchWallet() { - if (kIsWeb) return; - _appKit.redirectToWallet( - topic: _session.topic, - redirect: _session.peer.metadata.redirect, - ); - } - - List _buildSepoliaButtons(String address, String chainId) { - final List buttons = []; - final enabled = chainId == 'eip155:11155111'; - buttons.add( - Container( - width: double.infinity, - height: StyleConstants.linear48, - margin: const EdgeInsets.symmetric( - vertical: StyleConstants.linear8, - ), - child: ElevatedButton( - onPressed: enabled - ? () async { - final future = EIP155.callSmartContract( - appKit: _appKit, - topic: _session.topic, - address: address, - action: 'read', - ); - MethodDialog.show(context, 'Test Contract (Read)', future); - } - : null, - style: ButtonStyle( - backgroundColor: WidgetStateProperty.resolveWith((states) { - if (states.contains(WidgetState.disabled)) { - return StyleConstants.grayColor; - } - return Colors.orange; - }), - shape: WidgetStateProperty.all( - RoundedRectangleBorder( - borderRadius: BorderRadius.circular( - StyleConstants.linear8, - ), - ), - ), - ), - child: const Text( - 'Test Contract (Read)', - style: StyleConstants.buttonText, - textAlign: TextAlign.center, - ), - ), - ), - ); - buttons.add( - Container( - width: double.infinity, - height: StyleConstants.linear48, - margin: const EdgeInsets.symmetric( - vertical: StyleConstants.linear8, - ), - child: ElevatedButton( - onPressed: enabled - ? () async { - final future = EIP155.callSmartContract( - appKit: _appKit, - topic: _session.topic, - address: address, - action: 'write', - ); - MethodDialog.show(context, 'Test Contract (Write)', future); - _launchWallet(); - } - : null, - style: ButtonStyle( - backgroundColor: WidgetStateProperty.resolveWith((states) { - if (states.contains(WidgetState.disabled)) { - return StyleConstants.grayColor; - } - return Colors.orange; - }), - shape: WidgetStateProperty.all( - RoundedRectangleBorder( - borderRadius: BorderRadius.circular( - StyleConstants.linear8, - ), - ), - ), - ), - child: const Text( - 'Test Contract (Write)', - style: StyleConstants.buttonText, - textAlign: TextAlign.center, - ), - ), - ), - ); - - return buttons; - } - - List _buildChainEventsTiles(ReownAppKitModalNetworkInfo chainData) { - final namespace = ReownAppKitModalNetworks.getNamespaceForChainId( - chainData.chainId, - ); - final List values = []; - for (final String event in getChainEvents(namespace)) { - values.add( - Container( - width: double.infinity, - height: StyleConstants.linear48, - margin: const EdgeInsets.symmetric( - vertical: StyleConstants.linear8, - ), - decoration: BoxDecoration( - border: Border.all( - color: Colors.blue, - ), - borderRadius: const BorderRadius.all( - Radius.circular( - StyleConstants.linear8, - ), - ), - ), - child: Center( - child: Text( - event, - style: StyleConstants.buttonText, - textAlign: TextAlign.center, - ), - ), - ), - ); - } - - return values; - } -} diff --git a/packages/reown_appkit/lib/modal/widgets/buttons/network_button.dart b/packages/reown_appkit/lib/modal/widgets/buttons/network_button.dart index d526de7..bae6aa8 100644 --- a/packages/reown_appkit/lib/modal/widgets/buttons/network_button.dart +++ b/packages/reown_appkit/lib/modal/widgets/buttons/network_button.dart @@ -50,9 +50,9 @@ class NetworkButton extends StatelessWidget { backgroundColor: WidgetStateProperty.resolveWith( (states) { if (states.contains(WidgetState.disabled)) { - return themeColors.grayGlass005; + return themeColors.grayGlass002; } - return themeColors.grayGlass010; + return themeColors.grayGlass005; }, ), foregroundColor: WidgetStateProperty.resolveWith( @@ -67,8 +67,8 @@ class NetworkButton extends StatelessWidget { (states) { return RoundedRectangleBorder( side: states.contains(WidgetState.disabled) - ? BorderSide(color: themeColors.grayGlass005, width: 1.0) - : BorderSide(color: themeColors.grayGlass010, width: 1.0), + ? BorderSide(color: themeColors.grayGlass002, width: 1.0) + : BorderSide(color: themeColors.grayGlass005, width: 1.0), borderRadius: BorderRadius.circular(borderRadius), ); }, diff --git a/packages/reown_appkit/lib/modal/widgets/icons/rounded_icon.dart b/packages/reown_appkit/lib/modal/widgets/icons/rounded_icon.dart index 1651b4d..05a4e8d 100644 --- a/packages/reown_appkit/lib/modal/widgets/icons/rounded_icon.dart +++ b/packages/reown_appkit/lib/modal/widgets/icons/rounded_icon.dart @@ -35,12 +35,12 @@ class RoundedIcon extends StatelessWidget { borderRadius: BorderRadius.all(Radius.circular(radius)), border: Border.fromBorderSide( BorderSide( - color: borderColor ?? themeColors.grayGlass005, + color: borderColor ?? themeColors.grayGlass002, width: 2, strokeAlign: BorderSide.strokeAlignOutside, ), ), - color: circleColor ?? themeColors.grayGlass010, + color: circleColor ?? themeColors.grayGlass005, ), clipBehavior: Clip.antiAlias, child: (imageUrl ?? '').isNotEmpty diff --git a/packages/reown_appkit/lib/modal/widgets/public/appkit_modal_account_button.dart b/packages/reown_appkit/lib/modal/widgets/public/appkit_modal_account_button.dart index 0dd421f..5c700b4 100644 --- a/packages/reown_appkit/lib/modal/widgets/public/appkit_modal_account_button.dart +++ b/packages/reown_appkit/lib/modal/widgets/public/appkit_modal_account_button.dart @@ -133,9 +133,9 @@ class _AppKitModalAccountButtonState extends State { backgroundColor: WidgetStateProperty.resolveWith( (states) { if (states.contains(WidgetState.disabled)) { - return themeColors.grayGlass005; + return themeColors.grayGlass002; } - return themeColors.grayGlass010; + return themeColors.grayGlass005; }, ), foregroundColor: WidgetStateProperty.resolveWith( @@ -150,8 +150,8 @@ class _AppKitModalAccountButtonState extends State { (states) { return RoundedRectangleBorder( side: states.contains(WidgetState.disabled) - ? BorderSide(color: themeColors.grayGlass005, width: 1.0) - : BorderSide(color: themeColors.grayGlass010, width: 1.0), + ? BorderSide(color: themeColors.grayGlass002, width: 1.0) + : BorderSide(color: themeColors.grayGlass005, width: 1.0), borderRadius: BorderRadius.circular(borderRadius), ); }, diff --git a/packages/reown_appkit/lib/modal/widgets/public/appkit_modal_address_button.dart b/packages/reown_appkit/lib/modal/widgets/public/appkit_modal_address_button.dart index 6c48739..acd4fb4 100644 --- a/packages/reown_appkit/lib/modal/widgets/public/appkit_modal_address_button.dart +++ b/packages/reown_appkit/lib/modal/widgets/public/appkit_modal_address_button.dart @@ -55,9 +55,9 @@ class AppKitModalAddressButton extends StatelessWidget { backgroundColor: WidgetStateProperty.resolveWith( (states) { if (states.contains(WidgetState.disabled)) { - return themeColors.grayGlass005; + return themeColors.grayGlass002; } - return themeColors.grayGlass010; + return themeColors.grayGlass005; }, ), foregroundColor: WidgetStateProperty.resolveWith( @@ -72,14 +72,8 @@ class AppKitModalAddressButton extends StatelessWidget { (states) { return RoundedRectangleBorder( side: states.contains(WidgetState.disabled) - ? BorderSide( - color: themeColors.grayGlass005, - width: 1.0, - ) - : BorderSide( - color: themeColors.grayGlass010, - width: 1.0, - ), + ? BorderSide(color: themeColors.grayGlass002, width: 1.0) + : BorderSide(color: themeColors.grayGlass005, width: 1.0), borderRadius: BorderRadius.circular(innerBorderRadius), ); }, @@ -92,7 +86,7 @@ class AppKitModalAddressButton extends StatelessWidget { decoration: BoxDecoration( borderRadius: BorderRadius.circular(size.iconSize), border: Border.all( - color: themeColors.grayGlass005, + color: themeColors.grayGlass002, width: 1.0, strokeAlign: BorderSide.strokeAlignInside, ), diff --git a/packages/reown_appkit/lib/modal/widgets/public/appkit_modal_balance_button.dart b/packages/reown_appkit/lib/modal/widgets/public/appkit_modal_balance_button.dart index fa8c322..f8ac8dd 100644 --- a/packages/reown_appkit/lib/modal/widgets/public/appkit_modal_balance_button.dart +++ b/packages/reown_appkit/lib/modal/widgets/public/appkit_modal_balance_button.dart @@ -64,9 +64,9 @@ class _AppKitModalBalanceButtonState extends State { backgroundColor: WidgetStateProperty.resolveWith( (states) { if (states.contains(WidgetState.disabled)) { - return themeColors.grayGlass005; + return themeColors.grayGlass002; } - return themeColors.grayGlass010; + return themeColors.grayGlass005; }, ), foregroundColor: WidgetStateProperty.resolveWith( @@ -81,8 +81,8 @@ class _AppKitModalBalanceButtonState extends State { (states) { return RoundedRectangleBorder( side: states.contains(WidgetState.disabled) - ? BorderSide(color: themeColors.grayGlass005, width: 1.0) - : BorderSide(color: themeColors.grayGlass010, width: 1.0), + ? BorderSide(color: themeColors.grayGlass002, width: 1.0) + : BorderSide(color: themeColors.grayGlass005, width: 1.0), borderRadius: BorderRadius.circular(widget.size.height / 2), ); }, diff --git a/packages/reown_sign/test/tests/sign_client_helpers.dart b/packages/reown_sign/test/tests/sign_client_helpers.dart index c238523..008b153 100644 --- a/packages/reown_sign/test/tests/sign_client_helpers.dart +++ b/packages/reown_sign/test/tests/sign_client_helpers.dart @@ -103,6 +103,7 @@ class SignClientHelpers { Completer completer = Completer(); b.onSessionConnect.subscribe((args) { + // ignore: unnecessary_null_comparison expect(args != null, true); completer.complete(); });