getAssets method

  1. @override
Future<List<Asset>> getAssets()
override

Get assets suported by TelePay.

Throw UnauthorizedException when the secret key is invalid, otherwise it throws exception TelePayException with any other error.

Implementation

@override
Future<List<Asset>> getAssets() async {
  try {
    final response = await _dio.get<Map<String, dynamic>>(
      'getAssets',
      options: Options(headers: _headers),
    );
    if (response.statusCode == 200 && response.data != null) {
      final data = response.data!['assets']! as List<dynamic>;
      final assets = data.cast<Map<String, dynamic>>();

      return assets.map(Asset.fromJson).toList();
    }
  } on DioError catch (e) {
    _handlerError(e, 'get assets');
  }
  throw const TelePayException('Failed to get assets info');
}