Skip to content

Commit

Permalink
minor changes and bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
quetool committed Jul 5, 2024
1 parent b667f90 commit 3ad159d
Show file tree
Hide file tree
Showing 14 changed files with 111 additions and 71 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## 3.3.0-beta02
## 3.3.0-beta03

- One-Click Auth + SIWE implementation
- Coinbase Wallet dependency update
Expand Down
Binary file modified assets/png/logo_wc.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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.3.0
versionCode=63
versionCode=64
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 = 63;
CURRENT_PROJECT_VERSION = 64;
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 = 63;
CURRENT_PROJECT_VERSION = 64;
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 = 63;
CURRENT_PROJECT_VERSION = 64;
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 = 63;
CURRENT_PROJECT_VERSION = 64;
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 = 63;
CURRENT_PROJECT_VERSION = 64;
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 = 63;
CURRENT_PROJECT_VERSION = 64;
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>63</string>
<string>64</string>
<key>ITSAppUsesNonExemptEncryption</key>
<false/>
<key>LSApplicationQueriesSchemes</key>
Expand Down
2 changes: 1 addition & 1 deletion example/lib/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ class _MyHomePageState extends State<MyHomePage> {
metadata: _pairingMetadata,
siweConfig: _siweConfig,
enableAnalytics: true, // OPTIONAL - null by default
enableEmail: true, // OPTIONAL - false by default
// enableEmail: true, // OPTIONAL - false by default
// requiredNamespaces: {},
// optionalNamespaces: {},
// includedWalletIds: {},
Expand Down
10 changes: 9 additions & 1 deletion example/lib/utils/crypto/siwe_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,15 @@ class SIWESampleWebService {
headers: _headers,
);
debugPrint('[SIWESERVICE] signOut() => ${response.body}');
return jsonDecode(response.body) as Map<String, dynamic>;
final result = jsonDecode(response.body) as Map<String, dynamic>;
_headers = {
...coreUtils.instance.getAPIHeaders(
DartDefines.appKitProjectId,
),
'Content-Type': 'application/json',
};
await _persistHeaders();
return result;
} catch (error) {
debugPrint('[SIWESERVICE] ⛔️ signOut() => ${error.toString()}');
rethrow;
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1131,7 +1131,7 @@ packages:
path: ".."
relative: true
source: path
version: "3.3.0-beta02"
version: "3.3.0-beta03"
web_socket_channel:
dependency: transitive
description:
Expand Down
2 changes: 1 addition & 1 deletion lib/constants/key_constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class KeyConstants {
static const Key qrCodePageKey = Key('qrCodePageKey');
static const Key walletListShortPageKey = Key('walletListShortPageKey');
static const Key walletListLongPageKey = Key('walletListLongPageKey');
static const Key connecWalletPageKey = Key('connecWalletPageKey');
static const Key connectWalletPageKey = Key('connectWalletPageKey');
static const Key connecNetworkPageKey = Key('connecNetworkPageKey');
static const Key qrCodeAndWalletListPageKey =
Key('qrCodeAndWalletListFullPageKey');
Expand Down
58 changes: 44 additions & 14 deletions lib/pages/approve_siwe.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import 'package:web3modal_flutter/web3modal_flutter.dart';
import 'package:web3modal_flutter/widgets/avatars/w3m_account_avatar.dart';
import 'package:web3modal_flutter/widgets/buttons/primary_button.dart';
import 'package:web3modal_flutter/widgets/buttons/secondary_button.dart';
import 'package:web3modal_flutter/widgets/icons/rounded_icon.dart';
import 'package:web3modal_flutter/widgets/miscellaneous/content_loading.dart';
import 'package:web3modal_flutter/widgets/web3modal_provider.dart';
import 'package:web3modal_flutter/widgets/avatars/w3m_wallet_avatar.dart';
Expand Down Expand Up @@ -127,6 +128,18 @@ class _ApproveSIWEPageState extends State<ApproveSIWEPage> {
final themeData = Web3ModalTheme.getDataOf(context);
final themeColors = Web3ModalTheme.colorsOf(context);
final radiuses = Web3ModalTheme.radiusesOf(context);
String peerIcon;
try {
peerIcon = _service?.session?.peer?.metadata.icons.first ?? '';
} catch (e) {
peerIcon = '';
}
String selfIcon;
try {
selfIcon = _service?.session?.self?.metadata.icons.first ?? '';
} catch (e) {
selfIcon = '';
}
return Web3ModalNavbar(
title: 'Sign In',
noClose: true,
Expand All @@ -153,7 +166,8 @@ class _ApproveSIWEPageState extends State<ApproveSIWEPage> {
child: Container(
padding: const EdgeInsets.all(8.0),
decoration: BoxDecoration(
borderRadius: _service!.session!.sessionService.isMagic
borderRadius: _service!.session!.sessionService.isMagic ||
peerIcon.isEmpty
? BorderRadius.circular(60.0)
: BorderRadius.circular(radiuses.radiusM),
color: themeColors.background150,
Expand All @@ -166,11 +180,22 @@ class _ApproveSIWEPageState extends State<ApproveSIWEPage> {
: SizedBox(
width: 60.0,
height: 60.0,
child: W3MListAvatar(
imageUrl:
_service?.session?.peer?.metadata.icons.first,
borderRadius: radiuses.radiusS,
),
child: peerIcon.isEmpty
? RoundedIcon(
borderRadius:
radiuses.isSquare() ? 0.0 : 60.0,
size: 60.0,
padding: 12.0,
assetPath:
'assets/icons/regular/wallet.svg',
assetColor: themeColors.accent100,
circleColor: themeColors.accenGlass010,
borderColor: themeColors.accenGlass010,
)
: W3MListAvatar(
imageUrl: peerIcon,
borderRadius: radiuses.radiusS,
),
),
),
),
Expand All @@ -185,14 +210,19 @@ class _ApproveSIWEPageState extends State<ApproveSIWEPage> {
borderRadius: BorderRadius.circular(36.0),
color: themeColors.background150,
),
child: SizedBox(
width: 60.0,
height: 60.0,
child: W3MListAvatar(
imageUrl: _service?.session?.self?.metadata.icons.first,
borderRadius: 30.0,
),
),
child: selfIcon.isEmpty
? W3MAccountAvatar(
service: _service!,
size: 60.0,
)
: SizedBox(
width: 60.0,
height: 60.0,
child: W3MListAvatar(
imageUrl: selfIcon,
borderRadius: 30.0,
),
),
),
),
],
Expand Down
10 changes: 7 additions & 3 deletions lib/pages/connect_wallet_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:flutter/services.dart';

import 'package:web3modal_flutter/constants/key_constants.dart';
import 'package:web3modal_flutter/services/explorer_service/explorer_service_singleton.dart';
import 'package:web3modal_flutter/services/siwe_service/siwe_service_singleton.dart';
import 'package:web3modal_flutter/services/w3m_service/i_w3m_service.dart';
import 'package:web3modal_flutter/theme/constants.dart';
import 'package:web3modal_flutter/utils/toast/toast_message.dart';
Expand All @@ -23,7 +24,7 @@ import 'package:web3modal_flutter/widgets/avatars/loading_border.dart';
import 'package:web3modal_flutter/widgets/navigation/navbar.dart';

class ConnectWalletPage extends StatefulWidget {
const ConnectWalletPage() : super(key: KeyConstants.connecWalletPageKey);
const ConnectWalletPage() : super(key: KeyConstants.connectWalletPageKey);

@override
State<ConnectWalletPage> createState() => _ConnectWalletPageState();
Expand Down Expand Up @@ -55,8 +56,11 @@ class _ConnectWalletPageState extends State<ConnectWalletPage>
if (state == AppLifecycleState.resumed) {
final isOpen = _service?.isOpen ?? false;
final isConnected = _service?.isConnected ?? false;
if (isOpen && isConnected) {
_service?.closeModal();
if (isOpen && isConnected && !siweService.instance!.enabled) {
Future.delayed(Duration(seconds: 1), () {
if (!mounted) return;
_service?.closeModal();
});
}
}
}
Expand Down
76 changes: 37 additions & 39 deletions lib/services/w3m_service/w3m_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1630,44 +1630,42 @@ extension _W3MServiceExtension on W3MService {
void _onSessionAuthResponse(SessionAuthResponse? args) async {
final debugString = jsonEncode(args?.toJson());
dev.log('[$runtimeType] _onSessionAuthResponse: $debugString');
if (args != null) {
if (args.session != null) {
// IF 1-CA SUPPORTED WE SHOULD CALL SIWECONGIF METHODS HERE
final session = await _settleSession(args.session!);
final namespace = args.session!.namespaces[StringConstants.namespace]!;
final chains = namespace.chains!.map((c) => c.split(':').last).toList()
..sort();
String chainId = _currentSelectedChain?.chainId ?? chains.first;
chainId = W3MChainPresets.chains[chainId]!.namespace;
//
try {
// Verify message with just the first cacao
final Cacao cacao = args.auths!.first;
final message = _web3App.formatAuthMessage(
iss: cacao.p.iss,
cacaoPayload: CacaoRequestPayload.fromCacaoPayload(cacao.p),
);
final clientId = await _web3App.core.crypto.getClientId();
await siweService.instance!.verifyMessage(
message: message,
signature: cacao.s.s,
clientId: clientId,
);
} catch (e) {
await disconnect();
return;
}
//
final siweSession = await siweService.instance!.getSession();
final newSession = session.copyWith(siweSession: siweSession);
//
onModalConnect.broadcast(ModalConnect(newSession));
await _storeSession(newSession);
_notify();
//
if (_isOpen) {
closeModal();
}
if (args?.session != null) {
// IF 1-CA SUPPORTED WE SHOULD CALL SIWECONGIF METHODS HERE
final session = await _settleSession(args!.session!);
final namespace = args.session!.namespaces[StringConstants.namespace]!;
final chains = namespace.chains!.map((c) => c.split(':').last).toList()
..sort();
String chainId = _currentSelectedChain?.chainId ?? chains.first;
chainId = W3MChainPresets.chains[chainId]!.namespace;
//
try {
// Verify message with just the first cacao
final Cacao cacao = args.auths!.first;
final message = _web3App.formatAuthMessage(
iss: cacao.p.iss,
cacaoPayload: CacaoRequestPayload.fromCacaoPayload(cacao.p),
);
final clientId = await _web3App.core.crypto.getClientId();
await siweService.instance!.verifyMessage(
message: message,
signature: cacao.s.s,
clientId: clientId,
);
} catch (e) {
loggerService.instance.e('[$runtimeType] _onSessionAuthResponse $e');
await disconnect();
return;
}
//
final siweSession = await siweService.instance!.getSession();
final newSession = session.copyWith(siweSession: siweSession);
//
await _storeSession(newSession);
onModalConnect.broadcast(ModalConnect(newSession));
//
if (_isOpen) {
closeModal();
}
}
}
Expand All @@ -1676,7 +1674,7 @@ extension _W3MServiceExtension on W3MService {
final siweEnabled = siweService.instance!.enabled;
if (_supportsOneClickAuth && siweEnabled) return;
final debugString = jsonEncode(args?.session.toJson());
_logger.i('[$runtimeType] _onSessionConnect: $debugString');
dev.log('[$runtimeType] _onSessionConnect: $debugString');
if (args != null) {
// IF SIWE CALLBACK (1-CA NOT SUPPORTED) SIWECONGIF METHODS ARE CALLED ON ApproveSIWEPage
final session = await _settleSession(args.session);
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.3.0-beta02
version: 3.3.0-beta03
repository: https://github.com/WalletConnect/Web3ModalFlutter

environment:
Expand Down

0 comments on commit 3ad159d

Please sign in to comment.