Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Smart Contracts (read and write) Interaction #256

Merged
merged 5 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.2.0-beta01

- Added Smart Contract interactions to SignEngine

## 2.1.14

- Minor improvements
Expand Down
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
2 changes: 1 addition & 1 deletion example/dapp/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="myflutterdapp" />
<data android:scheme="wcflutterdapp" />
</intent-filter>
</activity>
<!-- Don't delete the meta-data below.
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>myflutterdapp</string>
</array>
</dict>
</array>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>wcflutterwallet</string>
</array>
</dict>
</plist>
67 changes: 30 additions & 37 deletions example/dapp/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,6 @@ class _MyHomePageState extends State<MyHomePage> {
List<PageData> _pageDatas = [];
int _selectedIndex = 0;

// SessionData? _selectedSession;
// List<SessionData> _allSessions = [];
// List<PairingInfo> _allPairings = [];

@override
void initState() {
initialize();
Expand All @@ -67,14 +63,14 @@ class _MyHomePageState extends State<MyHomePage> {
projectId: DartDefines.projectId,
logLevel: LogLevel.info,
metadata: const PairingMetadata(
name: 'Example dApp',
description: 'Example dApp',
name: 'Sample dApp Flutter',
description: 'WalletConnect\'s sample dapp with Flutter',
url: 'https://walletconnect.com/',
icons: [
'https://images.prismic.io/wallet-connect/65785a56531ac2845a260732_WalletConnect-App-Logo-1024X1024.png'
],
redirect: Redirect(
native: 'myflutterdapp://',
native: 'wcflutterdapp://',
universal: 'https://walletconnect.com',
),
),
Expand All @@ -90,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 @@ -132,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 All @@ -157,33 +165,7 @@ class _MyHomePageState extends State<MyHomePage> {
}
navRail.add(
Expanded(
child: Stack(
children: [
_pageDatas[_selectedIndex].page,
Positioned(
bottom: StyleConstants.magic20,
right: StyleConstants.magic20,
child: Row(
children: [
Text(_web3App!.core.relayClient.isConnected
? 'Relay Connected'
: 'Relay Disconnected'),
Switch(
value: _web3App!.core.relayClient.isConnected,
onChanged: (value) {
if (!value) {
_web3App!.core.relayClient.disconnect();
} else {
_web3App!.core.relayClient.connect();
}
setState(() {});
},
),
],
),
),
],
),
child: _pageDatas[_selectedIndex].page,
),
);

Expand Down Expand Up @@ -279,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());
}
}
}
40 changes: 0 additions & 40 deletions example/dapp/lib/models/eth/ethereum_transaction.dart

This file was deleted.

44 changes: 0 additions & 44 deletions example/dapp/lib/models/eth/ethereum_transaction.g.dart

This file was deleted.

Loading
Loading