Skip to content

Commit

Permalink
minor improvements on initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
quetool committed Oct 16, 2024
1 parent 1e36de5 commit e88a99e
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 16 deletions.
12 changes: 11 additions & 1 deletion .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,44 @@ assignees: ''
---

**Describe the bug**

A clear and concise description of what the bug is.

**To Reproduce**

Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error

**Expected behavior**

A clear and concise description of what you expected to happen.

**Reproducible code**
If applicable, add a minimum reproducible code snippet.

If applicable, add a minimum reproducible code snippet.
A minimum reproducible code should have only Reown's SDK as dependency (besides flutter sdk of course)
There is no point you copy/paste your code if we can't run it as it is on our side.

**Screenshots**

If applicable, add screenshots to help explain your problem.

**Desktop (please complete the following information):**

- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
- Version [e.g. 22]

**Smartphone (please complete the following information):**

- Device: [e.g. iPhone6]
- OS: [e.g. iOS8.1]
- Browser [e.g. stock browser, safari]
- Version [e.g. 22]

**Additional context**

Add any other context about the problem here.
2 changes: 1 addition & 1 deletion packages/reown_appkit/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## 1.1.0-beta01
## 1.1.0-beta02

- Social Logins

Expand Down
36 changes: 24 additions & 12 deletions packages/reown_appkit/lib/modal/appkit_modal_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class ReownAppKitModal with ChangeNotifier implements IReownAppKitModal {
Map<String, RequiredNamespace> _optionalNamespaces = {};
String? _lastChainEmitted;
bool _supportsOneClickAuth = false;
bool _serviceInitialized = false;
bool _relayConnected = false;

ReownAppKitModalStatus _status = ReownAppKitModalStatus.idle;
@override
Expand Down Expand Up @@ -194,8 +194,8 @@ class ReownAppKitModal with ChangeNotifier implements IReownAppKitModal {
core: _appKit.core,
);

GetIt.I.registerSingleton<IMagicService>(
MagicService(
GetIt.I.registerSingletonIfAbsent<IMagicService>(
() => MagicService(
core: _appKit.core,
metadata: _appKit.metadata,
featuresConfig: this.featuresConfig,
Expand Down Expand Up @@ -235,9 +235,13 @@ class ReownAppKitModal with ChangeNotifier implements IReownAppKitModal {
return false;
}

Completer<bool> _awaitRelayOnce = Completer<bool>();

@override
Future<void> init() async {
_serviceInitialized = false;
_relayConnected = false;
_awaitRelayOnce = Completer<bool>();

if (!CoreUtils.isValidProjectID(_projectId)) {
_appKit.core.logger.e(
'[$runtimeType] projectId $_projectId is invalid. '
Expand Down Expand Up @@ -332,12 +336,18 @@ class ReownAppKitModal with ChangeNotifier implements IReownAppKitModal {

onModalNetworkChange.subscribe(_onNetworkChainRequireSIWE);

final connected = _appKit.core.relayClient.isConnected;
_serviceInitialized = connected;
_status = connected
_relayConnected = _appKit.core.relayClient.isConnected;
if (!_relayConnected) {
_relayConnected = await _awaitRelayOnce.future;
} else {
if (!_awaitRelayOnce.isCompleted) {
_awaitRelayOnce.complete(_relayConnected);
}
}
_status = _relayConnected
? ReownAppKitModalStatus.initialized
: ReownAppKitModalStatus.error;
_appKit.core.logger.i('[$runtimeType] initialized');
: ReownAppKitModalStatus.initializing;
_appKit.core.logger.i('[$runtimeType] status $_status');
_notify();
}

Expand Down Expand Up @@ -595,7 +605,6 @@ class ReownAppKitModal with ChangeNotifier implements IReownAppKitModal {
Widget? startWidget,
}) async {
_checkInitialized();
ApproveTransactionPage();

if (_isOpen) {
closeModal();
Expand Down Expand Up @@ -1966,17 +1975,20 @@ extension _AppKitModalExtension on ReownAppKitModal {
_appKit.core.logger.i('[$runtimeType] relay client connected');
final service =
_currentSession?.sessionService ?? ReownAppKitModalConnector.wc;
if (service.isWC && _serviceInitialized) {
if (service.isWC && _relayConnected) {
_status = ReownAppKitModalStatus.initialized;
_notify();
}
if (!_awaitRelayOnce.isCompleted) {
_awaitRelayOnce.complete(true);
}
}

void _onRelayClientDisconnect(EventArgs? args) {
_appKit.core.logger.i('[$runtimeType] relay client disconnected');
final service =
_currentSession?.sessionService ?? ReownAppKitModalConnector.wc;
if (service.isWC && _serviceInitialized) {
if (service.isWC && _relayConnected) {
_status = ReownAppKitModalStatus.idle;
_notify();
}
Expand Down
2 changes: 1 addition & 1 deletion packages/reown_appkit/lib/version.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/reown_appkit/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: reown_appkit
description: "Reown is the onchain UX platform that provides toolkits built on top of the WalletConnect Network"
version: 1.1.0-beta01
version: 1.1.0-beta02
homepage: https://github.com/reown-com/reown_flutter
repository: https://github.com/reown-com/reown_flutter/tree/master/packages/reown_appkit
documentation: https://docs.reown.com/appkit/flutter/core/installation
Expand Down

0 comments on commit e88a99e

Please sign in to comment.