Skip to content

Commit

Permalink
Merge pull request #9 from wakumo/fix/request-params
Browse files Browse the repository at this point in the history
fix(request-params): allow params as dynamic for serializable in native
  • Loading branch information
ludowkm authored Apr 14, 2023
2 parents 4c20d0b + f7fa5ca commit 826fbd2
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 14 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@
## 1.0.2

* Add `redirect` field into AppMetadata

## 1.0.3

* Update session request params, add example for sending request
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class WalletConnectV2Plugin : FlutterPlugin, MethodCallHandler, ActivityAware,
// TODO: it should be have redirect here!
// https://github.com/WalletConnect/WalletConnectKotlinV2/issues/792
onEvent(
name = "proposal", data = sessionProposal.toFlutterValue(null)
name = "proposal", data = sessionProposal.toFlutterValue()
)
}

Expand Down
37 changes: 32 additions & 5 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ class _HomeViewState extends State<HomeView> with WidgetsBindingObserver {
'eip155': ProposalNamespace(chains: [
'eip155:1'
], methods: [
"eth_signTransaction",
"eth_sendTransaction",
"personal_sign",
"eth_signTypedData"
Expand All @@ -372,15 +373,18 @@ class _HomeViewState extends State<HomeView> with WidgetsBindingObserver {
CrossAxisAlignment.start,
children: [
Text('Topic: $_dappTopic'),
Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
Wrap(
children: [
TextButton(
child: const Text(
'Send personal_sign Request'),
child:
const Text('personal_sign'),
onPressed: () =>
onSendPersonalMessageTest()),
TextButton(
child: const Text(
'eth_signTransaction'),
onPressed: () =>
onSendTransactionTest()),
TextButton(
child: const Text('Disconnect'),
onPressed: () async {
Expand Down Expand Up @@ -564,6 +568,29 @@ class _HomeViewState extends State<HomeView> with WidgetsBindingObserver {
session.peer.redirect?.launch();
}

void onSendTransactionTest() async {
final session =
_sessions.firstWhere((element) => element.topic == _dappTopic!);
await _walletConnectV2Plugin.sendRequest(
request: Request(
method: 'eth_signTransaction',
chainId: 'eip155:1',
topic: _dappTopic!,
params: [
{
"from": "0xb60e8dd61c5d32be8058bb8eb970870f07233155",
"to": "0xd46e8dd67c5d32be8058bb8eb970870f07244567",
"gas": "0x76c0", // 30400
"gasPrice": "0x9184e72a000", // 10000000000000
"value": "0x9184e72a", // 2441406250
"data":
"0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675"
}
]));
// TODO: don't forget to check if where is the source come from to determine launch or not
session.peer.redirect?.launch();
}

Future _refreshSessions() async {
try {
final sessions = await _walletConnectV2Plugin.getActivatedSessions();
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ packages:
path: ".."
relative: true
source: path
version: "1.0.2"
version: "1.0.3"
watcher:
dependency: transitive
description:
Expand Down
2 changes: 1 addition & 1 deletion ios/Classes/SwiftWalletConnectV2Plugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ public class SwiftWalletConnectV2Plugin: NSObject, FlutterPlugin, FlutterStreamH
let topic = arguments["topic"] as! String
let method = arguments["method"] as! String
let chainId = Blockchain(arguments["chainId"] as! String)!
let requestParams = AnyCodable(arguments["params"] as! [String])
let requestParams: AnyCodable = try! JSONDecoder().decode(AnyCodable.self, from: JSONSerialization.data(withJSONObject: arguments["params"]!))
let request = Request(topic: topic, method: method, params: requestParams, chainId: chainId)
try await Sign.instance.request(params: request)
} catch let error {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/model/request.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Request {
final String method;
final String chainId;
final String topic;
final List<String> params;
final dynamic params;

Request(
{required this.method,
Expand Down
3 changes: 1 addition & 2 deletions lib/src/model/request.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/src/model/session_update.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ class SessionUpdate {
_$SessionUpdateFromJson(json);

Map<String, dynamic> toJson() => _$SessionUpdateToJson(this);
}
}
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: wallet_connect_v2
description: Wallet Connect V2 for Flutter, available for both Wallet and DApp to interact with Blockchain easier
version: 1.0.2
description: Wallet Connect V2 for Flutter, available for both Wallet and DApp to interact easier
version: 1.0.3
homepage: https://avacus.cc
repository: https://github.com/wakumo/flutter-wallet-connect-v2

Expand Down

0 comments on commit 826fbd2

Please sign in to comment.