Should we use registerRequestHandler or handle everything in onSessionRequest stream? #253
Replies: 2 comments 2 replies
-
Hello @Rimantovas, thanks for reaching out!
Indeed
The proper way to respond with errors AS A WALLET, is to use Here there are error codes everyone should follow https://specs.walletconnect.com/2.0/specs/clients/sign/error-codes The proper way to capture request errors (such as user rejections) AS A DAPP is by listening to relay messages and parsing it content For instance: _web3App!.core.relayClient.onRelayClientMessage.subscribe(_onRelayMessage);
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());
}
} It's up to the wallets to send the proper message in the proper format and it's up to the dApps to capture them properly. |
Beta Was this translation helpful? Give feedback.
-
Hello @Rimantovas! Just looked deepest into Flutter's SDK and you don't have to use Future<dynamic> personalSignHandler(String topic, dynamic parameters) async {
// Show approval modal
if (approved) {
final signature = // => Sign message code
return signature;
} else {
return const JsonRpcError(code: 5001, message: 'User rejected method');
}
} |
Beta Was this translation helpful? Give feedback.
-
Currently I have walletconnect implementation done like in the repository example using registerRequestHandler, but when I checked react-wallet-v2 example, it implemented all request handlers in the onSessionRequest stream. Which is the preferred method or is there no difference?
One thing I found with using registerRequestHandler is that I can't seem to return a valid response back to the dApp. For example, when handling eth_sendTransaction, if the user doesn't approve the request, I can only send back a null transaction hash to produce some sort of error on the dApp's side. If I send anything else, it will handle it as a successful request.
Beta Was this translation helpful? Give feedback.
All reactions