Skip to content

Commit

Permalink
chain switching enhancement
Browse files Browse the repository at this point in the history
  • Loading branch information
quetool committed Oct 27, 2023
1 parent 607a7ed commit a6842e6
Show file tree
Hide file tree
Showing 10 changed files with 107 additions and 110 deletions.
94 changes: 47 additions & 47 deletions lib/pages/account_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,22 @@ class _AccountPageState extends State<AccountPage> 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',
Expand All @@ -93,41 +93,41 @@ class _AccountPageState extends State<AccountPage> 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(
Expand Down
1 change: 1 addition & 0 deletions lib/services/explorer_service/explorer_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ class ExplorerService implements IExplorerService {

@override
Future<void> fetchInitialWallets() async {
totalListings.value = 0;
final allListings = await Future.wait([
_fetchInstalledListings(),
_fetchOtherListings(firstCall: true),
Expand Down
2 changes: 1 addition & 1 deletion lib/services/explorer_service/i_explorer_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ abstract class IExplorerService {
void search({String? query});

/// update the recently used position to the top list
Future<void> updateRecentPosition(String recentId);
Future<void> updateRecentPosition(String? recentId);

String getWalletImageUrl(String imageId);

Expand Down
2 changes: 0 additions & 2 deletions lib/services/network_service/i_network_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,4 @@ abstract class INetworkService {
Future<void> init();

void filterList({String? query});

void updateSort();
}
5 changes: 0 additions & 5 deletions lib/services/network_service/network_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,4 @@ class NetworkService implements INetworkService {
)
.toList();
}

@override
void updateSort() {
// itemList.value = itemList.value;
}
}
29 changes: 16 additions & 13 deletions lib/services/w3m_service/w3m_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,8 @@ class W3MService with ChangeNotifier implements IW3MService {

// Set the optional namespaces to everything in our asset util.
final List<String> 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<String, RequiredNamespace> optionalNamespaces = {
'eip155': RequiredNamespace(
Expand Down Expand Up @@ -316,16 +316,19 @@ class W3MService with ChangeNotifier implements IW3MService {
if (_currentSession == null) {
return null;
}
// Get all of the accounts
final List<String> 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 {
Expand Down Expand Up @@ -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');
Expand Down
24 changes: 16 additions & 8 deletions lib/widgets/avatars/w3m_wallet_avatar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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(
Expand Down
23 changes: 8 additions & 15 deletions lib/widgets/lists/grid_items/wallet_grid_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ class NetworkServiceItemsListener extends StatelessWidget {
super.key,
required this.builder,
});
final Function(BuildContext context, bool initialised,
List<GridItem<W3MChainInfo>> items) builder;
final Function(
BuildContext context,
bool initialised,
List<GridItem<W3MChainInfo>> items,
) builder;

@override
Widget build(BuildContext context) {
Expand All @@ -23,17 +26,21 @@ class NetworkServiceItemsListener extends StatelessWidget {
}
return ValueListenableBuilder(
valueListenable: networkService.instance.itemList,
builder: (context, List<GridItem<W3MChainInfo>> 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);
},
);
Expand Down
8 changes: 0 additions & 8 deletions test/mock_classes.mocks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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].
Expand Down

0 comments on commit a6842e6

Please sign in to comment.