diff --git a/lib/pages/account_page.dart b/lib/pages/account_page.dart index d28adfbb..fe3b0e19 100644 --- a/lib/pages/account_page.dart +++ b/lib/pages/account_page.dart @@ -67,22 +67,22 @@ class _AccountPageState extends State with WidgetsBindingObserver { right: kPadding12, bottom: kPadding12, ), - child: Column( - mainAxisSize: MainAxisSize.min, - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Column( - children: [ - const W3MAccountOrb(size: 72.0), - const SizedBox.square(dimension: kPadding12), - const W3MAddressWithCopyButton(), - const W3MBalanceText(), - Visibility( - visible: _service?.selectedChain?.blockExplorer != null, - child: Column( - children: [ - const SizedBox.square(dimension: 12.0), - SimpleIconButton( + child: SingleChildScrollView( + child: Column( + mainAxisSize: MainAxisSize.min, + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Column( + children: [ + const W3MAccountOrb(size: 72.0), + const SizedBox.square(dimension: kPadding12), + const W3MAddressWithCopyButton(), + const W3MBalanceText(), + Visibility( + visible: _service?.selectedChain?.blockExplorer != null, + child: Padding( + padding: const EdgeInsets.only(top: kPadding12), + child: SimpleIconButton( onTap: () => _service?.launchBlockExplorer(), leftIcon: 'assets/icons/compass.svg', rightIcon: 'assets/icons/arrow_top_right.svg', @@ -93,41 +93,41 @@ class _AccountPageState extends State with WidgetsBindingObserver { themeColors.background200, ), ), - ], + ), ), + ], + ), + const SizedBox.square(dimension: 20.0), + AccountListItem( + iconWidget: RoundedIcon( + imageUrl: _service?.tokenImageUrl, + assetColor: themeColors.background100, ), - ], - ), - const SizedBox.square(dimension: 20.0), - AccountListItem( - iconWidget: RoundedIcon( - imageUrl: _service?.tokenImageUrl, - assetColor: themeColors.background100, + title: _service?.selectedChain?.chainName ?? '', + onTap: () { + widgetStack.instance.push(SelectNetworkPage( + onTapNetwork: (W3MChainInfo chainInfo) { + _service?.selectChain(chainInfo, switchChain: true); + widgetStack.instance.pop(); + }, + )); + }, ), - title: _service?.selectedChain?.chainName ?? '', - onTap: () { - widgetStack.instance.push(SelectNetworkPage( - onTapNetwork: (W3MChainInfo chainInfo) { - _service?.selectChain(chainInfo, switchChain: true); - widgetStack.instance.pop(); - }, - )); - }, - ), - const SizedBox.square(dimension: kPadding8), - AccountListItem( - iconPath: 'assets/icons/disconnect.svg', - trailing: const SizedBox.shrink(), - title: 'Disconnect', - titleStyle: themeData.textStyles.paragraph600.copyWith( - color: themeColors.foreground200, + const SizedBox.square(dimension: kPadding8), + AccountListItem( + iconPath: 'assets/icons/disconnect.svg', + trailing: const SizedBox.shrink(), + title: 'Disconnect', + titleStyle: themeData.textStyles.paragraph600.copyWith( + color: themeColors.foreground200, + ), + onTap: () async { + _service?.closeModal(); + await _service?.disconnect(); + }, ), - onTap: () async { - _service?.closeModal(); - await _service?.disconnect(); - }, - ), - ], + ], + ), ), ), Positioned( diff --git a/lib/services/explorer_service/explorer_service.dart b/lib/services/explorer_service/explorer_service.dart index 5aa2b8c9..e718d105 100644 --- a/lib/services/explorer_service/explorer_service.dart +++ b/lib/services/explorer_service/explorer_service.dart @@ -103,6 +103,7 @@ class ExplorerService implements IExplorerService { @override Future fetchInitialWallets() async { + totalListings.value = 0; final allListings = await Future.wait([ _fetchInstalledListings(), _fetchOtherListings(firstCall: true), diff --git a/lib/services/explorer_service/i_explorer_service.dart b/lib/services/explorer_service/i_explorer_service.dart index cc3999eb..b92bb8c4 100644 --- a/lib/services/explorer_service/i_explorer_service.dart +++ b/lib/services/explorer_service/i_explorer_service.dart @@ -37,7 +37,7 @@ abstract class IExplorerService { void search({String? query}); /// update the recently used position to the top list - Future updateRecentPosition(String recentId); + Future updateRecentPosition(String? recentId); String getWalletImageUrl(String imageId); diff --git a/lib/services/network_service/i_network_service.dart b/lib/services/network_service/i_network_service.dart index 72c1cc9e..40363ae5 100644 --- a/lib/services/network_service/i_network_service.dart +++ b/lib/services/network_service/i_network_service.dart @@ -10,6 +10,4 @@ abstract class INetworkService { Future init(); void filterList({String? query}); - - void updateSort(); } diff --git a/lib/services/network_service/network_service.dart b/lib/services/network_service/network_service.dart index 07204282..e2a18ec6 100644 --- a/lib/services/network_service/network_service.dart +++ b/lib/services/network_service/network_service.dart @@ -63,9 +63,4 @@ class NetworkService implements INetworkService { ) .toList(); } - - @override - void updateSort() { - // itemList.value = itemList.value; - } } diff --git a/lib/services/w3m_service/w3m_service.dart b/lib/services/w3m_service/w3m_service.dart index 948f3c7e..a1880aaa 100644 --- a/lib/services/w3m_service/w3m_service.dart +++ b/lib/services/w3m_service/w3m_service.dart @@ -201,8 +201,8 @@ class W3MService with ChangeNotifier implements IW3MService { // Set the optional namespaces to everything in our asset util. final List chainIds = []; - for (final String id in W3MChainPresets.chains.keys) { - chainIds.add('eip155:$id'); + for (final chain in W3MChainPresets.chains.values) { + chainIds.add(chain.namespace); } final Map optionalNamespaces = { 'eip155': RequiredNamespace( @@ -316,16 +316,19 @@ class W3MService with ChangeNotifier implements IW3MService { if (_currentSession == null) { return null; } - // Get all of the accounts - final List namespaceAccounts = []; - // Loop through the namespaces, and get the accounts - for (final Namespace namespace in _currentSession!.namespaces.values) { - namespaceAccounts.addAll(namespace.accounts); + + final sessionNamespaces = _currentSession!.namespaces; + final nsMethods = sessionNamespaces['eip155']?.methods ?? []; + final nsAccounts = sessionNamespaces['eip155']?.accounts ?? []; + + final supportsAllNetworks = nsMethods.contains(EthUtil.walletAddEthChain); + final approvedNetworks = NamespaceUtils.getChainsFromAccounts(nsAccounts); + + if (supportsAllNetworks) { + return null; } - return namespaceAccounts.map((e) { - final parts = e.split(':'); - return '${parts[0]}:${parts[1]}'; - }).toList(); + + return approvedNetworks; } void _setEthChain(W3MChainInfo chainInfo) async { @@ -515,10 +518,10 @@ class W3MService with ChangeNotifier implements IW3MService { try { _currentSession = await connectResponse!.session.future; _setSessionValues(_currentSession!); + await _selectChainFromStoredId(); await explorerService.instance!.updateRecentPosition( - _selectedWallet!.listing.id, + _selectedWallet?.listing.id, ); - await _selectChainFromStoredId(); } on TimeoutException { W3MLoggerUtil.logger .i('[$runtimeType] Rebuilding session, ending future'); diff --git a/lib/widgets/avatars/w3m_wallet_avatar.dart b/lib/widgets/avatars/w3m_wallet_avatar.dart index 991327a5..bfa8736e 100644 --- a/lib/widgets/avatars/w3m_wallet_avatar.dart +++ b/lib/widgets/avatars/w3m_wallet_avatar.dart @@ -11,11 +11,13 @@ class W3MListAvatar extends StatelessWidget { this.borderRadius, this.isNetwork = false, this.color, + this.disabled = false, }); final String? imageUrl; final double? borderRadius; final bool isNetwork; final Color? color; + final bool disabled; @override Widget build(BuildContext context) { @@ -49,14 +51,20 @@ class W3MListAvatar extends StatelessWidget { ), clipBehavior: Clip.antiAlias, child: (imageUrl ?? '').isNotEmpty - ? CachedNetworkImage( - imageUrl: imageUrl!, - httpHeaders: coreUtils.instance.getAPIHeaders(projectId), - fadeOutDuration: Duration.zero, - fadeInDuration: Duration.zero, - placeholderFadeInDuration: Duration.zero, - errorWidget: (context, url, error) => ColoredBox( - color: themeColors.grayGlass005, + ? ColorFiltered( + colorFilter: ColorFilter.mode( + disabled ? Colors.grey : Colors.transparent, + BlendMode.saturation, + ), + child: CachedNetworkImage( + imageUrl: imageUrl!, + httpHeaders: coreUtils.instance.getAPIHeaders(projectId), + fadeOutDuration: Duration.zero, + fadeInDuration: Duration.zero, + placeholderFadeInDuration: Duration.zero, + errorWidget: (context, url, error) => ColoredBox( + color: themeColors.grayGlass005, + ), ), ) : ColoredBox( diff --git a/lib/widgets/lists/grid_items/wallet_grid_item.dart b/lib/widgets/lists/grid_items/wallet_grid_item.dart index 1b4212a5..2a3367f2 100644 --- a/lib/widgets/lists/grid_items/wallet_grid_item.dart +++ b/lib/widgets/lists/grid_items/wallet_grid_item.dart @@ -36,21 +36,14 @@ class WalletGridItem extends StatelessWidget { Expanded( child: Align( alignment: Alignment.topCenter, - child: Container( - foregroundDecoration: onTap == null - ? BoxDecoration( - color: Colors.grey, - backgroundBlendMode: BlendMode.saturation, - ) - : null, - child: imageWidget ?? - W3MListAvatar( - borderRadius: radiuses.radiusXS, - imageUrl: imageUrl, - isNetwork: isNetwork, - color: isSelected ? themeColors.accent100 : null, - ), - ), + child: imageWidget ?? + W3MListAvatar( + borderRadius: radiuses.radiusXS, + imageUrl: imageUrl, + isNetwork: isNetwork, + color: isSelected ? themeColors.accent100 : null, + disabled: isNetwork && onTap == null, + ), ), ), Column( diff --git a/lib/widgets/value_listenable_builders/network_service_items_listener.dart b/lib/widgets/value_listenable_builders/network_service_items_listener.dart index 96019b2c..60763287 100644 --- a/lib/widgets/value_listenable_builders/network_service_items_listener.dart +++ b/lib/widgets/value_listenable_builders/network_service_items_listener.dart @@ -10,8 +10,11 @@ class NetworkServiceItemsListener extends StatelessWidget { super.key, required this.builder, }); - final Function(BuildContext context, bool initialised, - List> items) builder; + final Function( + BuildContext context, + bool initialised, + List> items, + ) builder; @override Widget build(BuildContext context) { @@ -23,17 +26,21 @@ class NetworkServiceItemsListener extends StatelessWidget { } return ValueListenableBuilder( valueListenable: networkService.instance.itemList, - builder: (context, List> items, _) { + builder: (context, items, _) { final service = Web3ModalProvider.of(context).service; final supportedChains = service.approvedChainsByConnectedWallet(); - final parsedItems = items.map((e) { - if (supportedChains == null) { - return e; - } - return e.copyWith( - disabled: !supportedChains.contains('eip155:${e.id}'), - ); - }).toList(); + final parsedItems = supportedChains == null + ? items + : items.map((e) { + return e.copyWith( + disabled: !supportedChains.contains(e.data.namespace), + ); + }).toList() + ..sort((a, b) { + final disabledA = a.disabled ? 0 : 1; + final disabledB = b.disabled ? 0 : 1; + return disabledB.compareTo(disabledA); + }); return builder(context, initialised, parsedItems); }, ); diff --git a/test/mock_classes.mocks.dart b/test/mock_classes.mocks.dart index 43365788..9d6daf00 100644 --- a/test/mock_classes.mocks.dart +++ b/test/mock_classes.mocks.dart @@ -2295,14 +2295,6 @@ class MockNetworkService extends _i1.Mock implements _i33.NetworkService { ), returnValueForMissingStub: null, ); - @override - void updateSort() => super.noSuchMethod( - Invocation.method( - #updateSort, - [], - ), - returnValueForMissingStub: null, - ); } /// A class which mocks [BlockchainApiUtils].