Skip to content

Commit

Permalink
Merge pull request #124 from WalletConnect/chores/email_login_bug_fixes
Browse files Browse the repository at this point in the history
[Email Wallets] minor bug fixes
  • Loading branch information
quetool authored May 6, 2024
2 parents d1e3ffc + 6ae48eb commit bebd72c
Show file tree
Hide file tree
Showing 13 changed files with 36 additions and 46 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## 3.2.0-beta06
## 3.2.0-beta07

- Email Login support
- Analytics API support
Expand Down
2 changes: 1 addition & 1 deletion example/android/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true
android.enableJetifier=true
versionName=3.2.0
versionCode=55
versionCode=56
12 changes: 6 additions & 6 deletions example/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 55;
CURRENT_PROJECT_VERSION = 56;
DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = W5R8AG9K22;
ENABLE_BITCODE = NO;
Expand All @@ -496,7 +496,7 @@
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 55;
CURRENT_PROJECT_VERSION = 56;
GENERATE_INFOPLIST_FILE = YES;
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = com.web3modal.flutterExample.RunnerTests;
Expand All @@ -514,7 +514,7 @@
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 55;
CURRENT_PROJECT_VERSION = 56;
GENERATE_INFOPLIST_FILE = YES;
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = com.web3modal.flutterExample.RunnerTests;
Expand All @@ -530,7 +530,7 @@
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 55;
CURRENT_PROJECT_VERSION = 56;
GENERATE_INFOPLIST_FILE = YES;
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = com.web3modal.flutterExample.RunnerTests;
Expand Down Expand Up @@ -655,7 +655,7 @@
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 55;
CURRENT_PROJECT_VERSION = 56;
DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = W5R8AG9K22;
ENABLE_BITCODE = NO;
Expand Down Expand Up @@ -686,7 +686,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 55;
CURRENT_PROJECT_VERSION = 56;
DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = W5R8AG9K22;
ENABLE_BITCODE = NO;
Expand Down
2 changes: 1 addition & 1 deletion example/ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
</dict>
</array>
<key>CFBundleVersion</key>
<string>55</string>
<string>56</string>
<key>ITSAppUsesNonExemptEncryption</key>
<false/>
<key>LSApplicationQueriesSchemes</key>
Expand Down
2 changes: 2 additions & 0 deletions example/lib/utils/crypto/eip155.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'dart:convert';
import 'dart:math';
import 'package:intl/intl.dart';
import 'package:web3modal_flutter/web3modal_flutter.dart';

Expand Down Expand Up @@ -127,6 +128,7 @@ class EIP155 {
'0x59e2f66C0E96803206B6486cDb39029abAE834c0',
),
value: EtherAmount.fromInt(EtherUnit.finney, 11), // == 0.011
nonce: Random().nextInt(10000),
),
);
case EIP155UIMethods.walletWatchAsset:
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1139,7 +1139,7 @@ packages:
path: ".."
relative: true
source: path
version: "3.2.0-beta06"
version: "3.2.0-beta07"
web_socket_channel:
dependency: transitive
description:
Expand Down
4 changes: 1 addition & 3 deletions lib/pages/approve_magic_request_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ class _ApproveTransactionPageState extends State<ApproveTransactionPage> {
noClose: true,
safeAreaLeft: true,
safeAreaRight: true,
body: SafeArea(
child: magicService.instance.webview,
),
body: magicService.instance.webview,
);
}
}
10 changes: 3 additions & 7 deletions lib/pages/confirm_email_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class _ConfirmEmailPageState extends State<ConfirmEmailPage> {
@override
void dispose() {
magicService.instance.onMagicError.unsubscribe(_onMagicErrorEvent);
_dispose();
magicService.instance.step.value = EmailLoginStep.idle;
super.dispose();
}

Expand All @@ -47,13 +47,9 @@ class _ConfirmEmailPageState extends State<ConfirmEmailPage> {
}
}

void _dispose() {
magicService.instance.setEmail('');
magicService.instance.step.value = EmailLoginStep.idle;
}

void _goBack() {
_dispose();
magicService.instance.step.value = EmailLoginStep.idle;
magicService.instance.setEmail('');
FocusManager.instance.primaryFocus?.unfocus();
widgetStack.instance.pop();
}
Expand Down
2 changes: 1 addition & 1 deletion lib/services/magic_service/i_magic_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ abstract class IMagicService {
String? chainId,
required SessionRequestParams request,
});
Future<dynamic> disconnect();
Future<bool> disconnect();

abstract final Event<MagicSessionEvent> onMagicLoginRequest;
abstract final Event<MagicLoginEvent> onMagicLoginSuccess;
Expand Down
27 changes: 10 additions & 17 deletions lib/services/magic_service/magic_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ class MagicService implements IMagicService {
'wallet_addEthereumChain',
];
//
// late final Key _key;
final IWeb3App _web3app;
Web3ModalTheme? _currentTheme;
Timer? _timeOutTimer;
Expand All @@ -55,7 +54,7 @@ class MagicService implements IMagicService {
late Completer<bool> _initialized;
late Completer<bool> _connected;
late Completer<dynamic> _response;
late Completer<dynamic> _disconnect;
late Completer<bool> _disconnect;

@override
Event<MagicSessionEvent> onMagicLoginRequest = Event<MagicSessionEvent>();
Expand Down Expand Up @@ -84,17 +83,11 @@ class MagicService implements IMagicService {
final newEmail = ValueNotifier<String>('');
final step = ValueNotifier<EmailLoginStep>(EmailLoginStep.idle);

MagicService({
required IWeb3App web3app,
bool enabled = false,
// Key? key,
}) : _web3app = web3app //,
// _key = key ?? Key('magic_service')
{
MagicService({required IWeb3App web3app, bool enabled = false})
: _web3app = web3app {
isEnabled.value = enabled;
if (isEnabled.value) {
_webViewController = WebViewController();
// key: Key('${_key.hashCode}'),
_webview = WebViewWidget(controller: _webViewController);
isReady.addListener(_readyListener);
}
Expand Down Expand Up @@ -291,17 +284,17 @@ class MagicService implements IMagicService {
}

@override
Future<dynamic> disconnect() async {
if (!isEnabled.value || !isReady.value) return;
_disconnect = Completer<dynamic>();
Future<bool> disconnect() async {
if (!isEnabled.value || !isReady.value) return false;
_disconnect = Completer<bool>();
if (!isConnected.value) {
_resetTimeOut();
_disconnect.complete(true);
return await _disconnect.future;
return (await _disconnect.future);
}
final message = SignOut().toString();
await _webViewController.runJavaScript('sendW3Message($message)');
return await _disconnect.future;
return (await _disconnect.future);
}

// ****** Private Methods ******* //
Expand Down Expand Up @@ -546,12 +539,12 @@ class MagicService implements IMagicService {
const iframeFL = document.getElementById('frame-mobile-sdk')
window.addEventListener('message', ({ data, origin }) => {
// console.log('w3mMessage received <=== ' + JSON.stringify({data,origin}))
console.log('w3mMessage received <=== ' + JSON.stringify({data,origin}))
window.w3mWebview.postMessage(JSON.stringify({data,origin}))
})
const sendW3Message = async (message) => {
// console.log('w3mMessage posted =====> ' + JSON.stringify(message))
console.log('w3mMessage posted =====> ' + JSON.stringify(message))
iframeFL.contentWindow.postMessage(message, '*')
}
Expand Down
13 changes: 7 additions & 6 deletions lib/services/w3m_service/w3m_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,12 @@ class W3MService with ChangeNotifier, CoinbaseService implements IW3MService {
_currentSelectedChain = W3MChainPresets.chains[chainId];
await _setSesionAndChainData(_currentSession!);
}
if (_currentSession!.sessionService.isMagic) {
await magicService.instance.init();
}
} else {
magicService.instance.init();
}
await magicService.instance.init();

await expirePreviousInactivePairings();

Expand All @@ -243,24 +247,20 @@ class W3MService with ChangeNotifier, CoinbaseService implements IW3MService {
}
} else {
// Check for other type of sessions stored
// final storedSession = await _getStoredSession();
if (_currentSession != null) {
if (_currentSession!.sessionService.isCoinbase) {
final isCbConnected = await cbIsConnected();
if (!isCbConnected) {
await _cleanSession();
}
} else if (_currentSession!.sessionService.isMagic) {
// Every time the app gets killed MAgic service will treat the user as disconnected
// Every time the app gets killed Magic service will treat the user as disconnected
// So we will need to treat magic session differently
// await _storeSession(storedSession);
final email = _currentSession!.email;
magicService.instance.setEmail(email);
} else {
await _cleanSession();
}
} else {
magicService.instance.disconnect();
}
}

Expand Down Expand Up @@ -764,6 +764,7 @@ class W3MService with ChangeNotifier, CoinbaseService implements IW3MService {

_status = W3MServiceStatus.initializing;
_notify();

if (_currentSession?.sessionService.isCoinbase == true) {
try {
await cbResetSession();
Expand Down
2 changes: 1 addition & 1 deletion 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 pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: web3modal_flutter
description: "WalletConnect Web3Modal: Simple, intuitive wallet login. With this drop-in UI SDK, enable any wallet's users to seamlessly log in to your app and enjoy a unified experience"
version: 3.2.0-beta06
version: 3.2.0-beta07
repository: https://github.com/WalletConnect/Web3ModalFlutter

environment:
Expand Down

0 comments on commit bebd72c

Please sign in to comment.