Skip to content

Commit

Permalink
Merge pull request #16 from wakumo/feature/optional-namespaces
Browse files Browse the repository at this point in the history
feat: upgrade latest sdks, support optional namespaces in session pro…
  • Loading branch information
ludowkm authored Jul 14, 2023
2 parents b3e35fa + b860255 commit 5852c86
Show file tree
Hide file tree
Showing 17 changed files with 261 additions and 170 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,8 @@
## 1.0.5

* Upgrade to the latest SDKs Android Bom 1.10.0

## 1.0.6

* Upgrade to the latest SDKs Android Bom 1.13.1, iOS 1.6.12
* Support optional namespaces
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ android {

dependencies {
implementation 'com.google.code.gson:gson:2.10'
implementation(platform("com.walletconnect:android-bom:1.10.0"))
implementation(platform("com.walletconnect:android-bom:1.13.1"))
implementation("com.walletconnect:android-core")
implementation("com.walletconnect:sign")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,19 @@ class WalletConnectV2Plugin : FlutterPlugin, MethodCallHandler, ActivityAware,
}

val walletDelegate = object : SignClient.WalletDelegate {
override fun onSessionProposal(sessionProposal: Sign.Model.SessionProposal) {
override fun onSessionProposal(
sessionProposal: Sign.Model.SessionProposal,
verifyContext: Sign.Model.VerifyContext
) {
onEvent(
name = "proposal", data = sessionProposal.toFlutterValue()
)
}

override fun onSessionRequest(sessionRequest: Sign.Model.SessionRequest) {
override fun onSessionRequest(
sessionRequest: Sign.Model.SessionRequest,
verifyContext: Sign.Model.VerifyContext
) {
onEvent(
name = "session_request", data = sessionRequest.toFlutterValue()
)
Expand Down Expand Up @@ -410,6 +416,13 @@ fun Sign.Model.SessionProposal.toFlutterValue(): Map<String, Any> {
"methods" to value.methods,
"events" to value.events
)
}.toMap(),
"optionalNamespaces" to this.optionalNamespaces.map { (key, value) ->
key to mapOf(
"chains" to value.chains,
"methods" to value.methods,
"events" to value.events
)
}.toMap()
)
}
Expand Down
12 changes: 11 additions & 1 deletion example/android/app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
-keep class com.walletconnect.android.** { *; }
-keep interface com.walletconnect.** { *; }
-keep class kotlinx.coroutines.** { *; }
-keepnames class com.walletconnect.** { *; }
-keepnames interface com.walletconnect.** { *; }

-dontwarn kotlinx.coroutines.**
-dontwarn org.conscrypt.**
-dontwarn org.bouncycastle.**
-dontwarn org.openjsse.**
-dontwarn okhttp3.internal.platform.**

-repackageclasses 'com.walletconnect'
-allowaccessmodification
-keeppackagenames doNotKeepAThing
-keeppackagenames doNotKeepAThing
50 changes: 36 additions & 14 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,46 @@ PODS:
- wallet_connect_v2 (0.0.1):
- Flutter
- Starscream (= 3.1.1)
- WalletConnectSwiftV2 (= 1.3.0)
- WalletConnectSwiftV2 (1.3.0):
- WalletConnectSwiftV2/WalletConnect (= 1.3.0)
- WalletConnectSwiftV2/Commons (1.3.0)
- WalletConnectSwiftV2/JSONRPC (1.3.0):
- WalletConnectSwiftV2 (= 1.6.12)
- WalletConnectSwiftV2 (1.6.12):
- WalletConnectSwiftV2/WalletConnect (= 1.6.12)
- WalletConnectSwiftV2/Commons (1.6.12)
- WalletConnectSwiftV2/HTTPClient (1.6.12)
- WalletConnectSwiftV2/JSONRPC (1.6.12):
- WalletConnectSwiftV2/Commons
- WalletConnectSwiftV2/WalletConnect (1.3.0):
- WalletConnectSwiftV2/WalletConnect (1.6.12):
- WalletConnectSwiftV2/WalletConnectAuth
- WalletConnectSwiftV2/WalletConnectEcho
- WalletConnectSwiftV2/WalletConnectSign
- WalletConnectSwiftV2/WalletConnectVerify
- WalletConnectSwiftV2/WalletConnectAuth (1.6.12):
- WalletConnectSwiftV2/WalletConnectPairing
- WalletConnectSwiftV2/WalletConnectKMS (1.3.0):
- WalletConnectSwiftV2/WalletConnectSigner
- WalletConnectSwiftV2/WalletConnectVerify
- WalletConnectSwiftV2/WalletConnectEcho (1.6.12):
- WalletConnectSwiftV2/WalletConnectJWT
- WalletConnectSwiftV2/WalletConnectNetworking
- WalletConnectSwiftV2/WalletConnectJWT (1.6.12):
- WalletConnectSwiftV2/WalletConnectKMS
- WalletConnectSwiftV2/WalletConnectKMS (1.6.12):
- WalletConnectSwiftV2/WalletConnectUtils
- WalletConnectSwiftV2/WalletConnectNetworking (1.3.0):
- WalletConnectSwiftV2/WalletConnectNetworking (1.6.12):
- WalletConnectSwiftV2/HTTPClient
- WalletConnectSwiftV2/WalletConnectRelay
- WalletConnectSwiftV2/WalletConnectPairing (1.3.0):
- WalletConnectSwiftV2/WalletConnectPairing (1.6.12):
- WalletConnectSwiftV2/WalletConnectNetworking
- WalletConnectSwiftV2/WalletConnectRelay (1.3.0):
- WalletConnectSwiftV2/WalletConnectKMS
- WalletConnectSwiftV2/WalletConnectUtils (1.3.0):
- WalletConnectSwiftV2/WalletConnectRelay (1.6.12):
- WalletConnectSwiftV2/WalletConnectJWT
- WalletConnectSwiftV2/WalletConnectSign (1.6.12):
- WalletConnectSwiftV2/WalletConnectPairing
- WalletConnectSwiftV2/WalletConnectVerify
- WalletConnectSwiftV2/WalletConnectSigner (1.6.12):
- WalletConnectSwiftV2/WalletConnectNetworking
- WalletConnectSwiftV2/WalletConnectUtils (1.6.12):
- WalletConnectSwiftV2/JSONRPC
- WalletConnectSwiftV2/WalletConnectVerify (1.6.12):
- WalletConnectSwiftV2/WalletConnectNetworking
- WalletConnectSwiftV2/WalletConnectUtils

DEPENDENCIES:
- Flutter (from `Flutter`)
Expand Down Expand Up @@ -53,8 +75,8 @@ SPEC CHECKSUMS:
shared_preferences_ios: 548a61f8053b9b8a49ac19c1ffbc8b92c50d68ad
Starscream: 4bb2f9942274833f7b4d296a55504dcfc7edb7b0
url_launcher_ios: 08a3dfac5fb39e8759aeb0abbd5d9480f30fc8b4
wallet_connect_v2: 6dbafd13b16a32d40a68d223001d527441992baf
WalletConnectSwiftV2: 4b90e4115ad47e8b8ce749be6de0d8b13a33225a
wallet_connect_v2: ad634eb6588ce21fc2b51edb052bcd46dcd45601
WalletConnectSwiftV2: 6b96868cd4b46bfb2660b523e8a1441c0d9f3a5b

PODFILE CHECKSUM: cc1f88378b4bfcf93a6ce00d2c587857c6008d3b

Expand Down
178 changes: 98 additions & 80 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:hex/hex.dart';
import 'package:http/http.dart' hide Request;
import 'package:qr_flutter/qr_flutter.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:wallet_connect_v2/wallet_connect_v2.dart';
Expand Down Expand Up @@ -92,11 +93,10 @@ class _HomeViewState extends State<HomeView> with WidgetsBindingObserver {
});
if (proposal.namespaces.length != 1 ||
!proposal.namespaces.containsKey('eip155') ||
int.parse(
proposal.namespaces['eip155']!.chains.first.split(':')[1]) !=
5) {
proposal.namespaces['eip155']?.chains == null) {
_showDialog(
child: const Text('Please choose GOERLI testnet only to do test!'));
child:
const Text('Please choose Ethereum networks only to do test!'));
_walletConnectV2Plugin.rejectSession(proposalId: proposal.id);
return;
}
Expand Down Expand Up @@ -127,17 +127,37 @@ class _HomeViewState extends State<HomeView> with WidgetsBindingObserver {
));
if (isApprove == true) {
try {
_walletConnectV2Plugin.approveSession(
approval: SessionApproval(
id: proposal.id,
namespaces: proposal.namespaces.map((key, value) => MapEntry(
key,
SessionNamespace(
accounts:
value.chains.map((e) => '$e:$_address').toList(),
methods: value.methods,
events: value.events,
extensions: value.extensions)))));
final requiredMethods = proposal.namespaces['eip155']!.methods;
final requiredEvents = proposal.namespaces['eip155']!.events;

final optionalMethods =
proposal.optionalNamespaces?['eip155']?.methods;
final optionalEvents = proposal.optionalNamespaces?['eip155']?.events;

final methods = optionalMethods != null &&
optionalMethods.length > requiredMethods.length
? optionalMethods
: requiredMethods;
final events = optionalEvents != null &&
optionalEvents.length > requiredEvents.length
? optionalEvents
: requiredEvents;

final List<String> chainList = [];
chainList.addAll(proposal.namespaces['eip155']!.chains!);
chainList.addAll(proposal.optionalNamespaces!['eip155']!.chains!);
final chainIDs = chainList.toSet().toList();

final approval = SessionApproval(id: proposal.id, namespaces: {
'eip155': SessionNamespace(
accounts: chainIDs.map((e) => '$e:$_address').toList(),
methods: methods,
events: events)
});

print(approval.toJson());

_walletConnectV2Plugin.approveSession(approval: approval);
} catch (e) {
_showDialog(child: Text('Approve session error: ${e.toString()}'));
}
Expand Down Expand Up @@ -321,6 +341,15 @@ class _HomeViewState extends State<HomeView> with WidgetsBindingObserver {
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
QrImage(
padding: const EdgeInsets.all(16),
backgroundColor: Colors.white,
foregroundColor: Colors.black,
data: _uriDisplay!,
version: QrVersions.auto,
size: MediaQuery.of(context).size.height / 3,
),
const SizedBox(height: 16),
Text('URI: $_uriDisplay'),
const SizedBox(height: 16),
TextButton(
Expand All @@ -340,7 +369,8 @@ class _HomeViewState extends State<HomeView> with WidgetsBindingObserver {
),
)
: Padding(
padding: const EdgeInsets.all(16),
padding: const EdgeInsets.only(
left: 16, right: 16, top: 16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expand Down Expand Up @@ -379,11 +409,6 @@ class _HomeViewState extends State<HomeView> with WidgetsBindingObserver {
const Text('personal_sign'),
onPressed: () =>
onSendPersonalMessageTest()),
TextButton(
child: const Text(
'eth_signTransaction'),
onPressed: () =>
onSendTransactionTest()),
TextButton(
child: const Text('Disconnect'),
onPressed: () async {
Expand All @@ -402,69 +427,15 @@ class _HomeViewState extends State<HomeView> with WidgetsBindingObserver {
color: Colors.grey,
margin:
const EdgeInsets.symmetric(vertical: 16)),
const Text('Sessions:'),
Expanded(
child: _sessions.isEmpty
? const Center(
child: Text(
'No sessions\n\nPair wallet connect uri and approve to have session',
textAlign: TextAlign.center))
: ListView.separated(
padding: const EdgeInsets.symmetric(
vertical: 16),
itemBuilder: (_, index) {
final session = _sessions[index];
return Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
borderRadius:
BorderRadius.circular(12),
border: Border.all(
width: 1,
color: Colors.grey)),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(session
.toJson()
.toString()),
TextButton(
onPressed: () async {
await _walletConnectV2Plugin
.disconnectSession(
topic: session
.topic);
_refreshSessions();
},
child: const Text(
'Disconnect'))
],
),
);
},
separatorBuilder: (_, __) =>
const SizedBox(height: 16),
itemCount: _sessions.length)),
Container(
width: double.infinity,
height: 1,
color: Colors.grey,
margin:
const EdgeInsets.symmetric(vertical: 16)),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text('Account:'),
const SizedBox(height: 8),
Text('Private Key: $_privateKey'),
const SizedBox(height: 8),
// const Text('Account:'),
// const SizedBox(height: 8),
// Text('Private Key: $_privateKey'),
// const SizedBox(height: 8),
Text('Address: $_address'),
const SizedBox(height: 8),
const Text(
'PLEASE CHOOSE GOERLI NETWORK ONLY TO PAIR!',
style:
TextStyle(color: Colors.redAccent)),
const SizedBox(height: 8),
Container(
padding: const EdgeInsets.symmetric(
horizontal: 16),
Expand All @@ -486,7 +457,6 @@ class _HomeViewState extends State<HomeView> with WidgetsBindingObserver {
"Enter wallet connect URI",
counterText: '')),
),
const SizedBox(height: 8),
Row(
mainAxisAlignment:
MainAxisAlignment.spaceEvenly,
Expand Down Expand Up @@ -531,6 +501,54 @@ class _HomeViewState extends State<HomeView> with WidgetsBindingObserver {
)
],
),
Container(
width: double.infinity,
height: 1,
color: Colors.grey,
margin: const EdgeInsets.only(bottom: 16)),
const Text('Sessions:'),
Expanded(
child: _sessions.isEmpty
? const Center(
child: Text(
'No sessions\n\nPair wallet connect uri and approve to have session',
textAlign: TextAlign.center))
: ListView.separated(
padding: const EdgeInsets.symmetric(
vertical: 16),
itemBuilder: (_, index) {
final session = _sessions[index];
return Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
borderRadius:
BorderRadius.circular(12),
border: Border.all(
width: 1,
color: Colors.grey)),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(session
.toJson()
.toString()),
TextButton(
onPressed: () async {
await _walletConnectV2Plugin
.disconnectSession(
topic: session
.topic);
_refreshSessions();
},
child: const Text(
'Disconnect'))
],
),
);
},
separatorBuilder: (_, __) =>
const SizedBox(height: 16),
itemCount: _sessions.length))
],
),
)
Expand Down
Loading

0 comments on commit 5852c86

Please sign in to comment.