Skip to content

Commit

Permalink
Improvements during chain switchng by properly catching errors and re…
Browse files Browse the repository at this point in the history
…jections and highlighting non-approved chains by the connected wallet.
  • Loading branch information
quetool committed Oct 26, 2023
1 parent bd1aa67 commit 607a7ed
Show file tree
Hide file tree
Showing 34 changed files with 670 additions and 378 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 3.0.0-beta11

- Improvements during chain switchng by properly catching errors and rejections and highlighting non-approved chains by the connected wallet.

## 3.0.0-beta10

- Fix a bug where QR Code wasn't readable anymore after user rejects connection from within the chosen wallet app
Expand Down
3 changes: 3 additions & 0 deletions assets/icons/extension.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions assets/icons/mobile.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ PODS:
- FMDB (2.7.5):
- FMDB/standard (= 2.7.5)
- FMDB/standard (2.7.5)
- package_info_plus (0.4.5):
- Flutter
- path_provider_foundation (0.0.1):
- Flutter
- FlutterMacOS
Expand All @@ -20,6 +22,7 @@ PODS:
DEPENDENCIES:
- appcheck (from `.symlinks/plugins/appcheck/ios`)
- Flutter (from `Flutter`)
- 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`)
- sqflite (from `.symlinks/plugins/sqflite/ios`)
Expand All @@ -34,6 +37,8 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/appcheck/ios"
Flutter:
:path: Flutter
package_info_plus:
:path: ".symlinks/plugins/package_info_plus/ios"
path_provider_foundation:
:path: ".symlinks/plugins/path_provider_foundation/darwin"
shared_preferences_foundation:
Expand All @@ -47,6 +52,7 @@ SPEC CHECKSUMS:
appcheck: e1ab9d4e03736f03e0401554a134d1ed502d7629
Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854
FMDB: 2ce00b547f966261cd18927a3ddb07cb6f3db82a
package_info_plus: 115f4ad11e0698c8c1c5d8a689390df880f47e85
path_provider_foundation: 29f094ae23ebbca9d3d0cec13889cd9060c0e943
shared_preferences_foundation: 5b919d13b803cadd15ed2dc053125c68730e5126
sqflite: 31f7eba61e3074736dff8807a9b41581e4f7f15a
Expand Down
27 changes: 6 additions & 21 deletions example/lib/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import 'package:walletconnect_flutter_dapp/utils/crypto/chain_data_wrapper.dart'
import 'package:walletconnect_flutter_dapp/utils/crypto/helpers.dart';
import 'package:walletconnect_flutter_dapp/utils/dart_defines.dart';
import 'package:walletconnect_flutter_dapp/utils/string_constants.dart';
import 'package:walletconnect_flutter_dapp/widgets/event_widget.dart';

class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.swapTheme});
Expand Down Expand Up @@ -101,27 +100,13 @@ class _MyHomePageState extends State<MyHomePage> {
);
}

void _onSessionPing(SessionPing? args) => showDialog(
context: context,
builder: (BuildContext context) {
return EventWidget(
title: StringConstants.receivedPing,
content: 'Topic: ${args!.topic}',
);
},
);
void _onSessionPing(SessionPing? args) {
debugPrint('[$runtimeType] ${StringConstants.receivedPing}: $args');
}

void _onSessionEvent(SessionEvent? args) => showDialog(
context: context,
builder: (BuildContext context) {
return EventWidget(
title: StringConstants.receivedEvent,
content: 'Topic: ${args!.topic}\n'
'Event Name: ${args.name}\n'
'Event Data: ${args.data}',
);
},
);
void _onSessionEvent(SessionEvent? args) {
debugPrint('[$runtimeType] ${StringConstants.receivedEvent}: $args');
}
}

class _W3MPage extends StatefulWidget {
Expand Down
2 changes: 2 additions & 0 deletions example/macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
import FlutterMacOS
import Foundation

import package_info_plus
import path_provider_foundation
import shared_preferences_foundation
import sqflite
import url_launcher_macos

func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
FPPPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FPPPackageInfoPlusPlugin"))
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
SqflitePlugin.register(with: registry.registrar(forPlugin: "SqflitePlugin"))
Expand Down
30 changes: 27 additions & 3 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.0.6"
custom_sliding_segmented_control:
dependency: transitive
description:
name: custom_sliding_segmented_control
sha256: "05b73fa48d57218bfdf806bad68a859812b216cd81fe81c6cbefde89f39eb257"
url: "https://pub.dev"
source: hosted
version: "1.8.1"
dart_style:
dependency: transitive
description:
Expand Down Expand Up @@ -600,6 +608,22 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.0"
package_info_plus:
dependency: transitive
description:
name: package_info_plus
sha256: "7e76fad405b3e4016cd39d08f455a4eb5199723cf594cd1b8916d47140d93017"
url: "https://pub.dev"
source: hosted
version: "4.2.0"
package_info_plus_platform_interface:
dependency: transitive
description:
name: package_info_plus_platform_interface
sha256: "9bc8ba46813a4cc42c66ab781470711781940780fd8beddd0c3da62506d3a6c6"
url: "https://pub.dev"
source: hosted
version: "2.0.1"
path:
dependency: transitive
description:
Expand Down Expand Up @@ -1089,10 +1113,10 @@ packages:
dependency: "direct main"
description:
name: walletconnect_flutter_v2
sha256: "7619022ecea01adc771aaaefb4cace48bc3e8645d5e5962d4859347c6a0ea777"
sha256: "55315779dd94b5b38754c8abcccba6e8f159083e799945dc49441a20dc73cffd"
url: "https://pub.dev"
source: hosted
version: "2.1.5"
version: "2.1.8"
watcher:
dependency: transitive
description:
Expand Down Expand Up @@ -1123,7 +1147,7 @@ packages:
path: ".."
relative: true
source: path
version: "3.0.0-beta10"
version: "3.0.0-beta11"
web_socket_channel:
dependency: transitive
description:
Expand Down
1 change: 0 additions & 1 deletion lib/constants/namespaces.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'package:walletconnect_flutter_v2/walletconnect_flutter_v2.dart';

// TODO this is not used on package side, check if it's needed.
class NamespaceConstants {
static const Map<String, RequiredNamespace> ethereum = {
'eip155': RequiredNamespace(
Expand Down
4 changes: 2 additions & 2 deletions lib/constants/string_constants.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
class StringConstants {
// Request Headers
static const X_SDK_TYPE = 'w3m';
static const X_SDK_VERSION = '3.0.0-beta10';
static const X_CORE_SDK_VERSION = 'flutter_v2.1.5';
static const X_SDK_VERSION = '3.0.0-beta11';
static const X_CORE_SDK_VERSION = 'flutter_v2.1.8';

// UI
static const String selectNetwork = 'Select Network';
Expand Down
5 changes: 4 additions & 1 deletion lib/models/grid_item.dart
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
// TODO this class shouldn't be needed
class GridItem<T> {
final String image;
final String id;
final String title;
final bool disabled;
final T data;

GridItem({
required this.image,
required this.id,
required this.title,
required this.data,
this.disabled = false,
});

GridItem<T> copyWith({
String? image,
String? id,
String? title,
bool? disabled,
T? data,
}) {
return GridItem<T>(
image: image ?? this.image,
id: id ?? this.id,
title: title ?? this.title,
disabled: disabled ?? this.disabled,
data: data ?? this.data,
);
}
Expand Down
55 changes: 44 additions & 11 deletions lib/pages/account_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:flutter/material.dart';

import 'package:web3modal_flutter/constants/key_constants.dart';
import 'package:web3modal_flutter/pages/select_network_page.dart';
import 'package:web3modal_flutter/services/w3m_service/i_w3m_service.dart';
import 'package:web3modal_flutter/theme/constants.dart';
import 'package:web3modal_flutter/widgets/widget_stack/widget_stack_singleton.dart';
import 'package:web3modal_flutter/web3modal_flutter.dart';
Expand All @@ -14,14 +15,47 @@ import 'package:web3modal_flutter/widgets/lists/list_items/account_list_item.dar
import 'package:web3modal_flutter/widgets/navigation/navbar_action_button.dart';
import 'package:web3modal_flutter/widgets/text/w3m_balance.dart';

class AccountPage extends StatelessWidget {
class AccountPage extends StatefulWidget {
const AccountPage() : super(key: Web3ModalKeyConstants.accountPage);

@override
State<AccountPage> createState() => _AccountPageState();
}

class _AccountPageState extends State<AccountPage> with WidgetsBindingObserver {
IW3MService? _service;

@override
void initState() {
super.initState();
WidgetsBinding.instance.addObserver(this);
WidgetsBinding.instance.addPostFrameCallback((_) {
_service = Web3ModalProvider.of(context).service;
_service?.addListener(_rebuild);
_rebuild();
});
}

void _rebuild() => setState(() {});

@override
void didChangeAppLifecycleState(AppLifecycleState state) {
if (state == AppLifecycleState.resumed) {
_rebuild();
}
}

@override
void dispose() {
_service?.removeListener(_rebuild);
WidgetsBinding.instance.removeObserver(this);
super.dispose();
}

@override
Widget build(BuildContext context) {
final themeData = Web3ModalTheme.getDataOf(context);
final themeColors = Web3ModalTheme.colorsOf(context);
final service = Web3ModalProvider.of(context).service;

return SafeArea(
child: Stack(
Expand All @@ -44,12 +78,12 @@ class AccountPage extends StatelessWidget {
const W3MAddressWithCopyButton(),
const W3MBalanceText(),
Visibility(
visible: service.selectedChain?.blockExplorer != null,
visible: _service?.selectedChain?.blockExplorer != null,
child: Column(
children: [
const SizedBox.square(dimension: 12.0),
SimpleIconButton(
onTap: () => service.launchBlockExplorer(),
onTap: () => _service?.launchBlockExplorer(),
leftIcon: 'assets/icons/compass.svg',
rightIcon: 'assets/icons/arrow_top_right.svg',
title: 'Block Explorer',
Expand All @@ -67,15 +101,14 @@ class AccountPage extends StatelessWidget {
const SizedBox.square(dimension: 20.0),
AccountListItem(
iconWidget: RoundedIcon(
imageUrl: service.tokenImageUrl,
imageUrl: _service?.tokenImageUrl,
assetColor: themeColors.background100,
),
title: service.selectedChain?.chainName ?? '',
title: _service?.selectedChain?.chainName ?? '',
onTap: () {
widgetStack.instance.push(SelectNetworkPage(
onTapNetwork: (W3MChainInfo chainInfo) {
// TODO check what happens when switch can not be done
service.selectChain(chainInfo, switchChain: true);
_service?.selectChain(chainInfo, switchChain: true);
widgetStack.instance.pop();
},
));
Expand All @@ -90,8 +123,8 @@ class AccountPage extends StatelessWidget {
color: themeColors.foreground200,
),
onTap: () async {
service.closeModal();
await service.disconnect();
_service?.closeModal();
await _service?.disconnect();
},
),
],
Expand All @@ -102,7 +135,7 @@ class AccountPage extends StatelessWidget {
right: 0,
child: NavbarActionButton(
asset: 'assets/icons/close.svg',
action: () => service.closeModal(),
action: () => _service?.closeModal(),
),
),
],
Expand Down
Loading

0 comments on commit 607a7ed

Please sign in to comment.