Skip to content

Commit

Permalink
Release 0.0.11 (#50)
Browse files Browse the repository at this point in the history
* fix txn query param

* update deprecated syntaxes

* bump version, update changelog and readme

* Add pagination (#49)

* add pagination

* fix

* fix

* update code

* bump version
  • Loading branch information
anakin001 authored Oct 30, 2023
1 parent d666918 commit 6bc33db
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.0.11
### Updates
[ADD] Add pagination property for transaction

## 0.0.10
### Bug fix
[ADD] Fix transaction type in transaction query parameter
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Add this to your package's pubspec.yaml file:

```dart
dependencies:
xpx_chain_sdk: 0.0.10
xpx_chain_sdk: 0.0.11
```

**2. Install it**
Expand Down
6 changes: 3 additions & 3 deletions lib/src/api/api_account_routes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class AccountRoutesApi {
/// param: pageSize The number of transactions to return for each request.
/// param: id The transaction id up to which transactions are returned.
/// param: ordering The ordering criteria: * -id - Descending order by id. * id - Ascending order by id.
Future<List<Transaction>> transactions(PublicAccount account,
Future<TransactionWithPagination> transactions(PublicAccount account,
[TransactionQueryParams? txnQueryParams]) async {
// query params
final List<QueryParam> queryParams = [];
Expand All @@ -137,8 +137,8 @@ class AccountRoutesApi {
if (txnQueryParams != null && !txnQueryParams.firstLevel) {
firstLevel = false;
}
return internalGetTransactions(
_apiClient, _transactionsRoute, queryParams, null,
return internalGetTransactionsWithPagination(
_apiClient, _transactionsRoute, queryParams,
firstLevel: firstLevel);
}

Expand Down
1 change: 1 addition & 0 deletions lib/src/model/transaction.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import '../api/dto.dart';
import 'transaction/buffer/buffer.dart' as $buffer;
import 'transaction/buffer/transactions_buffer.dart' as $txn_buffer;

part 'transaction/transaction_with_pagination.dart';
part 'transaction/fee_calculation_strategy.dart';
part 'transaction/abstract_transaction.dart';
part 'transaction/asset_id.dart';
Expand Down
23 changes: 23 additions & 0 deletions lib/src/model/transaction/transaction_internal.dart
Original file line number Diff line number Diff line change
Expand Up @@ -519,3 +519,26 @@ Future<List<Transaction>> internalGetTransactions(ApiClient client, String path,
return [];
}
}

Future<TransactionWithPagination> internalGetTransactionsWithPagination(
ApiClient client, String path, List<QueryParam> queryParams,
{bool firstLevel = true}) async {
final response = await client.get(path, null, queryParams);

if (response.statusCode! >= 299) {
throw ApiException(response.statusCode!, response.data);
} else if (response.data != null) {
final List resp = client.deserialize(response.data, 'List<Transaction>');
final allTransaction =
resp.map(deserializeDTO).toList().cast<Transaction>();

if (firstLevel) {
return TransactionWithPagination.fromDto(
allTransaction, response.data['pagination']);
} else
return TransactionWithPagination.fromDto(
fixAggregate(allTransaction), response.data['pagination']);
} else {
return TransactionWithPagination([], null);
}
}
31 changes: 31 additions & 0 deletions lib/src/model/transaction/transaction_with_pagination.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
part of xpx_chain_sdk.model.transaction;

class TransactionWithPagination {
final List<Transaction> transactions;
final Pagination? pagination;

TransactionWithPagination(this.transactions, this.pagination);

factory TransactionWithPagination.fromDto(
List<Transaction> transactions, Map<String, dynamic>? json) =>
TransactionWithPagination(
transactions,
json == null ? null : Pagination.fromJson(json),
);
}

class Pagination {
final int totalEntries;
final int pageNumber;
final int pageSize;
final int totalPages;

Pagination(
this.totalEntries, this.pageNumber, this.pageSize, this.totalPages);

factory Pagination.fromJson(Map<String, dynamic> json) => Pagination(
json['totalEntries'],
json['pageNumber'],
json['pageSize'],
json['totalPages']);
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: xpx_chain_sdk
version: 0.0.10
version: 0.0.11
#author: 'Eleazar Garrido <[email protected]>, ProximaX Devops <[email protected]>'
description: 'The ProximaX Sirius Chain Dart SDK works as a async lightweight Dart library for interacting with the Sirius Blockchain.'
homepage: https://github.com/proximax-storage
Expand Down

0 comments on commit 6bc33db

Please sign in to comment.