WalletConnect / WalletConnectFlutterV2

WalletConnect v2 client made in Dart for Flutter.
https://pub.dev/packages/walletconnect_flutter_v2
Apache License 2.0
101 stars 52 forks source link

Wallet sample app does not know how to accept contract methods such as swap #283

Closed ivanborisof closed 2 months ago

ivanborisof commented 2 months ago

Description

Sample app wallet is not able to accept contract methods out of the box, for example it can be swap or approval methods. All this is due to incorrect parsing of the data parameter in the Transaction class.

The thing is that in the source code data tries to be parsed using the Uint8List.fromList method, but it does not take into account that data can start with "0x", because of this an error occurs.

Before:

data: (this['data'] != null && this['data'] != '0x')
          ? Uint8List.fromList(hex.decode(this['data']!))
          : null,

After:

data: (this['data'] != null && this['data'] != '0x')
          ? Uint8List.fromList(hex.decode(this['data']!.startsWith('0x')
              ? this['data']!.substring(2)
              : this['data']!))
          : null,

How Has This Been Tested?

This has been tested on several dapps, for example: 1inch, uniswap.

No swap or approval was possible before the code was modified.

Due Dilligence

quetool commented 2 months ago

Hello @ivanborisof! Thanks for this! Could you extract the whole code for parsing data into its own private function? Like Uint8List? _parseTransationData() {} For readability purposes. Thanks!

sonarcloud[bot] commented 2 months ago

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarCloud