Skip to content

Commit

Permalink
Updated readme to include registering accounts and events for auto-na…
Browse files Browse the repository at this point in the history
…mespace generation
  • Loading branch information
Sterling Long committed Jul 25, 2023
1 parent dc56254 commit dbb2ea8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
25 changes: 21 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ wcClient.onSessionProposal.subscribe((SessionProposal? args) async {
});
// Also setup the methods and chains that your wallet supports
final kadenaSignV1RequestHandler = (String topic, dynamic parameters) async {
final signRequestHandler = (String topic, dynamic parameters) async {
// Handling Steps
// 1. Parse the request, if there are any errors thrown while trying to parse
// the client will automatically respond to the requester with a
Expand Down Expand Up @@ -166,10 +166,27 @@ final kadenaSignV1RequestHandler = (String topic, dynamic parameters) async {
}
}
wcClient.registerRequestHandler(
chainId: 'kadena:mainnet01',
method: 'kadena_sign_v1',
handler: kadenaSignV1RequestHandler,
chainId: 'eip155:1',
method: 'eth_sendTransaction',
handler: signRequestHandler,
);
// If you want to the library to handle Namespace validation automatically,
// you can register your events and accounts like so:
wcClient.registerEventEmitter(
chainId: 'eip155:1',
event: 'chainChanged',
);
wcClient.registerAccount(
chainId: 'eip155:1',
account: '0xabc',
);
// If your wallet receives a session proposal that it can't make the proper Namespaces for,
// it will broadcast an onSessionProposalError
wcClient.onSessionProposalError.subscribe((SessionProposalError? args) {
// Handle the error
});
// Setup the auth handling
clientB.onAuthRequest.subscribe((AuthRequest? args) async {
Expand Down
4 changes: 2 additions & 2 deletions example/dapp/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ class _MyHomePageState extends State<MyHomePage> {
),
);

// Register event handlers

// Loop through all the chain data
for (final ChainMetadata chain in ChainData.allChains) {
// Loop through the events for that chain
Expand All @@ -81,6 +79,7 @@ class _MyHomePageState extends State<MyHomePage> {
}
}

// Register event handlers
_web3App!.onSessionPing.subscribe(_onSessionPing);
_web3App!.onSessionEvent.subscribe(_onSessionEvent);

Expand Down Expand Up @@ -118,6 +117,7 @@ class _MyHomePageState extends State<MyHomePage> {
@override
void dispose() {
_web3App!.onSessionPing.unsubscribe(_onSessionPing);
_web3App!.onSessionEvent.unsubscribe(_onSessionEvent);
super.dispose();
}

Expand Down

0 comments on commit dbb2ea8

Please sign in to comment.