Skip to content

Commit

Permalink
first approach: added custom credentials as extension and enhanced ex…
Browse files Browse the repository at this point in the history
…amples
  • Loading branch information
quetool committed Jan 31, 2024
1 parent e3fdfd0 commit b60f048
Show file tree
Hide file tree
Showing 36 changed files with 4,354 additions and 243 deletions.
4 changes: 2 additions & 2 deletions example/dapp/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ android {

defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.dapp"
applicationId "com.walletconnect.flutterdapp"
// You can update the following values to match your application needs.
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration.
minSdkVersion flutter.minSdkVersion
Expand All @@ -60,7 +60,7 @@ android {
signingConfig signingConfigs.debug
}
}
namespace 'com.example.dapp'
namespace 'com.walletconnect.flutterdapp'
}

flutter {
Expand Down
9 changes: 6 additions & 3 deletions example/dapp/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -361,11 +361,12 @@
DEVELOPMENT_TEAM = W5R8AG9K22;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = "Flutter Dapp";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = com.example.dapp;
PRODUCT_BUNDLE_IDENTIFIER = com.walletconnect.flutterdapp;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
SWIFT_VERSION = 5.0;
Expand Down Expand Up @@ -490,11 +491,12 @@
DEVELOPMENT_TEAM = W5R8AG9K22;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = "Flutter Dapp";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = com.example.dapp;
PRODUCT_BUNDLE_IDENTIFIER = com.walletconnect.flutterdapp;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
Expand All @@ -513,11 +515,12 @@
DEVELOPMENT_TEAM = W5R8AG9K22;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = "Flutter Dapp";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = com.example.dapp;
PRODUCT_BUNDLE_IDENTIFIER = com.walletconnect.flutterdapp;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
SWIFT_VERSION = 5.0;
Expand Down
50 changes: 25 additions & 25 deletions example/dapp/ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,51 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CADisableMinimumFrameDurationOnPhone</key>
<true/>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleDisplayName</key>
<string>Dapp</string>
<string>Flutter Dapp</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>dapp</string>
<string>Flutter Dapp</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>$(FLUTTER_BUILD_NAME)</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLName</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleURLSchemes</key>
<array>
<string>wcflutterdapp</string>
</array>
</dict>
</array>
<key>CFBundleVersion</key>
<string>$(FLUTTER_BUILD_NUMBER)</string>
<key>LSApplicationCategoryType</key>
<string></string>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>wcflutterwallet</string>
</array>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
Expand All @@ -43,28 +66,5 @@
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
<key>CADisableMinimumFrameDurationOnPhone</key>
<true/>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>
<key>LSApplicationCategoryType</key>
<string></string>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLName</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleURLSchemes</key>
<array>
<string>wcflutterdapp</string>
</array>
</dict>
</array>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>wcflutterwallet</string>
</array>
</dict>
</plist>
31 changes: 27 additions & 4 deletions example/dapp/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class _MyHomePageState extends State<MyHomePage> {
projectId: DartDefines.projectId,
logLevel: LogLevel.info,
metadata: const PairingMetadata(
name: 'Sample dApp Fllutter',
name: 'Sample dApp Flutter',
description: 'WalletConnect\'s sample dapp with Flutter',
url: 'https://walletconnect.com/',
icons: [
Expand All @@ -86,12 +86,17 @@ class _MyHomePageState extends State<MyHomePage> {
}

// Register event handlers
_web3App!.onSessionConnect.subscribe(_onSessionConnect);
_web3App!.onSessionPing.subscribe(_onSessionPing);
_web3App!.onSessionEvent.subscribe(_onSessionEvent);
_web3App!.onSessionUpdate.subscribe(_onSessionUpdate);

_web3App!.core.relayClient.onRelayClientConnect.subscribe(_setState);
_web3App!.core.relayClient.onRelayClientDisconnect.subscribe(_setState);
_web3App!.onSessionConnect.subscribe(_onSessionConnect);
_web3App!.core.relayClient.onRelayClientMessage.subscribe(_onRelayMessage);

_web3App!.signEngine.onSessionEvent.subscribe(_onSessionEvent);
_web3App!.signEngine.onSessionUpdate.subscribe(_onSessionUpdate);

setState(() {
_pageDatas = [
Expand Down Expand Up @@ -128,12 +133,19 @@ class _MyHomePageState extends State<MyHomePage> {

@override
void dispose() {
// Unregister event handlers
_web3App!.onSessionConnect.unsubscribe(_onSessionConnect);
_web3App!.core.relayClient.onRelayClientConnect.unsubscribe(_setState);
_web3App!.core.relayClient.onRelayClientDisconnect.unsubscribe(_setState);
_web3App!.onSessionPing.unsubscribe(_onSessionPing);
_web3App!.onSessionEvent.unsubscribe(_onSessionEvent);
_web3App!.onSessionUpdate.unsubscribe(_onSessionUpdate);

_web3App!.core.relayClient.onRelayClientConnect.unsubscribe(_setState);
_web3App!.core.relayClient.onRelayClientDisconnect.unsubscribe(_setState);
_web3App!.core.relayClient.onRelayClientMessage
.unsubscribe(_onRelayMessage);

_web3App!.signEngine.onSessionEvent.unsubscribe(_onSessionEvent);
_web3App!.signEngine.onSessionUpdate.unsubscribe(_onSessionUpdate);
super.dispose();
}

Expand Down Expand Up @@ -249,4 +261,15 @@ class _MyHomePageState extends State<MyHomePage> {
void _onSessionUpdate(SessionUpdate? args) {
debugPrint('[$runtimeType] _onSessionUpdate $args');
}

void _onRelayMessage(MessageEvent? args) async {
if (args != null) {
final payloadString = await _web3App!.core.crypto.decode(
args.topic,
args.message,
);
final data = jsonDecode(payloadString ?? '{}') as Map<String, dynamic>;
debugPrint(data.toString());
}
}
}
41 changes: 32 additions & 9 deletions example/dapp/lib/pages/connect_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,15 @@ class ConnectPageState extends State<ConnectPage> {
children: <Widget>[
const Text(
StringConstants.appTitle,
style: StyleConstants.titleText,
style: StyleConstants.subtitleText,
textAlign: TextAlign.center,
),
const SizedBox(
height: StyleConstants.linear16,
),
const Text(
StringConstants.selectChains,
style: StyleConstants.subtitleText,
style: StyleConstants.paragraph,
textAlign: TextAlign.center,
),
const SizedBox(
Expand Down Expand Up @@ -169,8 +169,32 @@ class ConnectPageState extends State<ConnectPage> {

final encodedUri = Uri.encodeComponent(res.uri.toString());
final uri = 'wcflutterwallet://wc?uri=$encodedUri';
// final uri = 'metamask://wc?uri=$encodedUri';
if (await canLaunchUrlString(uri)) {
launchUrlString(uri, mode: LaunchMode.externalApplication);
// ignore: use_build_context_synchronously
final openApp = await showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
content: const Text('Do you want to open with Web3Wallet Flutter'),
actions: [
TextButton(
onPressed: () => Navigator.of(context).pop(false),
child: const Text('Show QR'),
),
TextButton(
onPressed: () => Navigator.of(context).pop(true),
child: const Text('Open'),
),
],
);
},
);
if (openApp) {
launchUrlString(uri, mode: LaunchMode.externalApplication);
} else {
_showQrCode(res);
}
} else {
_showQrCode(res);
}
Expand Down Expand Up @@ -203,23 +227,22 @@ class ConnectPageState extends State<ConnectPage> {
showToast?.call(StringConstants.authSucceeded);
}

if (_shouldDismissQrCode) {
// ignore: use_build_context_synchronously
if (_shouldDismissQrCode && Navigator.canPop(context)) {
// ignore: use_build_context_synchronously
Navigator.pop(context);
}
} catch (e) {
// debugPrint(e.toString());
if (_shouldDismissQrCode) {
// ignore: use_build_context_synchronously
if (_shouldDismissQrCode && Navigator.canPop(context)) {
// ignore: use_build_context_synchronously
Navigator.pop(context);
}
showToast?.call(StringConstants.connectionFailed);
}
}

Future<void> _showQrCode(
ConnectResponse response,
) async {
Future<void> _showQrCode(ConnectResponse response) async {
// Show the QR code
debugPrint('Showing QR Code: ${response.uri}');

Expand Down
Loading

0 comments on commit b60f048

Please sign in to comment.