lvaccaro / lwk-rn

MIT License
4 stars 2 forks source link

Methods on Android are failing #10

Open BlakeKaufman opened 1 month ago

BlakeKaufman commented 1 month ago

I have installed the LWK into a bare react-native test environment You can reproduce the issue here: https://github.com/BlakeKaufman/lwkTest

{
  "name": "test",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "lint": "eslint .",
    "start": "react-native start",
    "test": "jest"
  },
  "dependencies": {
    "@breeztech/react-native-breez-sdk": "^0.5.2",
    "@craftzdog/react-native-buffer": "^6.0.5",
    "@dreson4/react-native-quick-bip39": "^0.0.6",
    "expo": "^51.0.0",
    "lwk-rn": "^0.1.0",
    "react": "18.3.1",
    "react-native": "0.75.2",
    "react-native-quick-base64": "^2.1.2",
    "react-native-quick-crypto": "^0.7.4",
    "stream-browserify": "^3.0.0"
  },
  "devDependencies": {
    "@babel/core": "^7.20.0",
    "@babel/preset-env": "^7.20.0",
    "@babel/runtime": "^7.20.0",
    "@react-native/babel-preset": "0.75.2",
    "@react-native/eslint-config": "0.75.2",
    "@react-native/metro-config": "0.75.2",
    "@react-native/typescript-config": "0.75.2",
    "@types/react": "^18.2.6",
    "@types/react-test-renderer": "^18.0.0",
    "babel-jest": "^29.6.3",
    "babel-plugin-module-resolver": "^5.0.2",
    "eslint": "^8.19.0",
    "jest": "^29.6.3",
    "metro-react-native-babel-preset": "^0.77.0",
    "prettier": "2.8.8",
    "react-native-dotenv": "^3.4.11",
    "react-test-renderer": "18.3.1",
    "typescript": "5.0.4"
  },
  "engines": {
    "node": ">=18"
  },
  "packageManager": "yarn@3.6.4"
}

Everything seems to be working fine on IOS, however, Android is returning errors when calling methods.

When calling wollet.getAddress(); I am getting an error saying: LwkRnModule.getAddress got 4 arguments, expected 3. This error is crashing the app.

When calling wollet.getTransactions() I am getting a warning saying: java.lang.illegalArgumentException: Could not convert class lwk.Txid. Although it is just a warning nothing is returned.

when calling wollet.getBalance() I am getting a warning saying: java.lang.RuntimeException: Cannot convert argument of type class koltin.collections.builders.MapBuilder. Although this is just a warning, nothing is returned.

The code I am running is

import {Wollet, Client, Signer, Network, TxBuilder} from 'lwk-rn';

async function connectToLWK() {
  const mnemonic =
    'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about';
  console.log(mnemonic);
  const network = Network.Testnet;
  const signer = await new Signer().create(mnemonic, network);
  const descriptor = await signer.wpkhSlip77Descriptor();
  console.log(await descriptor.asString());

  const wollet = await new Wollet().create(network, descriptor, null);
  const client = await new Client().defaultElectrumClient(network);
  const update = await client.fullScan(wollet);
  await wollet.applyUpdate(update);

  // const txs = await wollet.getTransactions();
  // // console.log('Get transactions');
  // console.log(txs);

  // const address = await wollet.getAddress();
  // console.log('Get address');
  // console.log(address);

  const balance = await wollet.getBalance();
  // console.log('Get balance');
  console.log(balance[liquidTestnet]);

  return;
  const out_address =
    'tlq1qqfkh3gtdtfw0uqcx8d0r7w3zh65tenu63qg394hwyed0lpey4hp5e0gztg6ay3nvz2k6d44quhz634s8weg6jt3xsz0h3jems';
  const satoshis = 1000;
  const fee_rate = 100; // this seems like absolute fees
  const builder = await new TxBuilder().create(network);
  await builder.addLbtcRecipient(out_address, satoshis);
  await builder.feeRate(fee_rate);
  let pset = await builder.finish(wollet);
  let signed_pset = await signer.sign(pset);
  let finalized_pset = await wollet.finalize(signed_pset);
  const tx = await finalized_pset.extractTx();
  await client.broadcast(tx);
  console.log('BROADCASTED TX!\nTXID: {:?}', (await tx.txId()).toString());
}
lvaccaro commented 1 month ago

Hi @BlakeKaufman , there was some incompatibility in kotlin types with react native. Fix android bindings and more related stuff in https://github.com/lvaccaro/lwk-rn/pull/11 . Could you check again your code?

I could make a new tag and publish a npm release, if it makes your tests easier. thanks

BlakeKaufman commented 1 month ago

Ya, could you make another tag on npm? It will ensure I don't add any user error when copying changes.

lvaccaro commented 1 month ago

Merged #11 and tag new release 0.1.1 available at https://www.npmjs.com/package/lwk-rn