polkawallet-io / sdk

polkawallet SDK for integrating substrate-based blockchain as a plugin.
Apache License 2.0
18 stars 24 forks source link

signAndSend doesn't wait for Finalized event #40

Open poka-IT opened 10 months ago

poka-IT commented 10 months ago

Your signAndSend method is commented with:

/// Send tx, [params] will be ignored if we have [rawParam]. /// [onStatusChange] is a callback when tx status change. /// @return txHash [string] if tx finalized success.

But that's wrong, the method return hash when transaction is validate by Babe, but still not Finalized by Granpa.

By reading your code in tx.dart, I realy don't understand why :

  Future<Map?> signAndSend(Map txInfo, String params, password,
      Function(String) onStatusChange) async {
    final msgId =
        "onStatusChange${serviceRoot.webView!.getEvalJavascriptUID()}";
    serviceRoot.webView!.addMsgHandler(msgId, onStatusChange);
    final code =
        'keyring.sendTx(api, ${jsonEncode(txInfo)}, $params, "$password", "$msgId")';
    // print(code);
    final dynamic res = await serviceRoot.webView!.evalJavascript(code);
    serviceRoot.webView!.removeMsgHandler(msgId);

    return res;
  }

Do you have an idea ?

RomeroYang commented 10 months ago

You're right, the comment is wrong, it doesn't wait for finalized event.