fetchTransfersAsync method

Future<Map> fetchTransfersAsync(
  1. String address,
  2. int page, {
  3. int size = tx_list_page_size,
  4. String network = 'kusama',
})

do the request in an isolate to avoid UI stall in IOS due to https issue: https://github.com/dart-lang/sdk/issues/41519

Implementation

Future<Map> fetchTransfersAsync(
  String address,
  int page, {
  int size = tx_list_page_size,
  String network = 'kusama',
}) async {
  Completer completer = new Completer<Map>();

  ReceivePort receivePort = ReceivePort();
  Isolate isolateIns = await Isolate.spawn(
      SubScanApi.fetchTransfers,
      SubScanRequestParams(
        sendPort: receivePort.sendPort,
        network: network,
        address: address,
        page: page,
        row: size,
      ));
  receivePort.listen((msg) {
    receivePort.close();
    isolateIns.kill(priority: Isolate.immediate);
    completer.complete(msg);
  });
  return completer.future as FutureOr<Map<dynamic, dynamic>>;
}