Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/packages/service/dfx/models/pdf/multi_receipt_dto.dart
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
import 'package:realunit_wallet/styles/currency.dart';
import 'package:realunit_wallet/styles/language.dart';

class MultiReceiptDto {
final List<String> txIds;
final Currency currency;
final Language? language;

const MultiReceiptDto({
required this.txIds,
this.currency = Currency.chf,
this.language,
});

Map<String, dynamic> toJson() {
return {
'txHashes': txIds,
'currency': currency.code,
if (language != null) 'language': language!.code.toUpperCase(),
};
}
}
4 changes: 4 additions & 0 deletions lib/packages/service/dfx/models/pdf/single_receipt_dto.dart
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
import 'package:realunit_wallet/styles/currency.dart';
import 'package:realunit_wallet/styles/language.dart';

class SingleReceiptDto {
final String txId;
final Currency currency;
final Language? language;

const SingleReceiptDto({
required this.txId,
this.currency = Currency.chf,
this.language,
});

Map<String, dynamic> toJson() {
return {
'txHash': txId,
'currency': currency.code,
if (language != null) 'language': language!.code.toUpperCase(),
};
}
}
7 changes: 4 additions & 3 deletions lib/packages/service/dfx/real_unit_pdf_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,15 @@ class RealUnitPdfService extends DFXAuthService {
Future<PdfDto> getTransactionsReceipt(
List<String> ids, {
Currency currency = Currency.chf,
Language? language,
}) async {
final uri = buildUri(host, _transactionsReceiptMultiPath);
final response = await authenticatedPost(
uri,
headers: {
'Content-Type': 'application/json',
},
body: jsonEncode(MultiReceiptDto(txIds: ids, currency: currency)),
body: jsonEncode(MultiReceiptDto(txIds: ids, currency: currency, language: language)),
);

if (response.statusCode != 200 && response.statusCode != 201) {
Expand All @@ -67,14 +68,14 @@ class RealUnitPdfService extends DFXAuthService {
return PdfDto.fromJson(jsonDecode(response.body));
}

Future<PdfDto> getTransactionReceipt(String id, {Currency currency = Currency.chf}) async {
Future<PdfDto> getTransactionReceipt(String id, {Currency currency = Currency.chf, Language? language}) async {
final uri = buildUri(host, _transactionsReceiptSinglePath);
final response = await authenticatedPost(
uri,
headers: {
'Content-Type': 'application/json',
},
body: jsonEncode(SingleReceiptDto(txId: id, currency: currency)),
body: jsonEncode(SingleReceiptDto(txId: id, currency: currency, language: language)),
);

if (response.statusCode != 200 && response.statusCode != 201) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:realunit_wallet/packages/io/documents_directory_port.dart';
import 'package:realunit_wallet/packages/io/path_provider_adapter.dart';
import 'package:realunit_wallet/packages/service/dfx/real_unit_pdf_service.dart';
import 'package:realunit_wallet/styles/currency.dart';
import 'package:realunit_wallet/styles/language.dart';

part 'transaction_history_multi_receipt_state.dart';

Expand All @@ -21,11 +22,11 @@ class TransactionHistoryMultiReceiptCubit extends Cubit<TransactionHistoryMultiR
_directory = directory ?? const PathProviderAdapter(),
super(const TransactionHistoryMultiReceiptInitial());

Future<void> generateReceipt(List<String> ids, {Currency currency = Currency.chf}) async {
Future<void> generateReceipt(List<String> ids, {Currency currency = Currency.chf, Language? language}) async {
try {
emit(const TransactionHistoryMultiReceiptLoading());

final response = await _pdfService.getTransactionsReceipt(ids, currency: currency);
final response = await _pdfService.getTransactionsReceipt(ids, currency: currency, language: language);
if (isClosed) return;
final file = await _createFileFromBytes(response.pdfData);
if (isClosed) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:realunit_wallet/packages/io/documents_directory_port.dart';
import 'package:realunit_wallet/packages/io/path_provider_adapter.dart';
import 'package:realunit_wallet/packages/service/dfx/real_unit_pdf_service.dart';
import 'package:realunit_wallet/styles/currency.dart';
import 'package:realunit_wallet/styles/language.dart';

part 'transaction_history_receipt_state.dart';

Expand All @@ -21,11 +22,11 @@ class TransactionHistoryReceiptCubit extends Cubit<TransactionHistoryReceiptStat
_directory = directory ?? const PathProviderAdapter(),
super(const TransactionHistoryReceiptInitial());

Future<void> generateReceipt(String txId, {Currency currency = Currency.chf}) async {
Future<void> generateReceipt(String txId, {Currency currency = Currency.chf, Language? language}) async {
try {
emit(const TransactionHistoryReceiptLoading());

final response = await _pdfService.getTransactionReceipt(txId, currency: currency);
final response = await _pdfService.getTransactionReceipt(txId, currency: currency, language: language);
if (isClosed) return;
final file = await _createFileFromBytes(response.pdfData, txId);
if (isClosed) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class TransactionHistoryDownloadButtonView extends StatelessWidget {
context.read<TransactionHistoryMultiReceiptCubit>().generateReceipt(
transactionsIds,
currency: context.read<SettingsBloc>().state.currency,
language: context.read<SettingsBloc>().state.language,
),
child: Container(
height: 44,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ class TransactionHistoryRowView extends StatelessWidget {
context.read<TransactionHistoryReceiptCubit>().generateReceipt(
transaction.txId,
currency: context.read<SettingsBloc>().state.currency,
language: context.read<SettingsBloc>().state.language,
);
},
child: const Icon(
Expand Down