signTransactions method

  1. @override
Future<List<Map<String, dynamic>>> signTransactions({
  1. required List transactions,
})

Send transaction objects to MyAlgo for approval. If approved, the response is an array of signed transaction objects, with the binary blob field base64 encoded to prevent transmission issues.

Implementation

@override
Future<List<Map<String, dynamic>>> signTransactions({
  required List transactions,
}) async {
  final txs = transactions.map((tx) {
    if (tx is Map<String, dynamic>) {
      return mapToJSObj(tx);
    }

    return tx;
  }).toList();

  var c = Completer<List<Map<String, dynamic>>>();
  promiseToFuture(myAlgo.signTransaction(txs)).then((value) {
    if (value is! List) {
      return c.complete([]);
    }

    final transactions = value.map((tx) {
      final txId = getProperty(tx, 'txID') ?? '';
      final blob = getProperty(tx, 'blob') ?? [];
      return <String, dynamic>{
        'txId': txId,
        'blob': base64Encode(blob),
      };
    }).toList();

    return c.complete(transactions);
  }).onError((error, stackTrace) => c.completeError(_handleError(error)));

  return c.future;
}