cake_wallet/cw_zano/lib/pending_zano_transaction.dart

88 lines
2.4 KiB
Dart
Raw Normal View History

import 'dart:convert';
import 'package:cw_zano/api/model/destination.dart';
import 'package:cw_zano/api/model/transfer_params.dart';
import 'package:cw_zano/api/model/transfer_result.dart';
2023-10-02 14:17:35 +00:00
import 'package:cw_core/crypto_currency.dart';
import 'package:cw_core/amount_converter.dart';
import 'package:cw_core/pending_transaction.dart';
import 'package:cw_zano/api/calls.dart' as calls;
import 'package:cw_zano/zano_wallet.dart';
2023-10-02 14:17:35 +00:00
class PendingZanoTransaction with PendingTransaction {
PendingZanoTransaction(
{required this.fee,
required this.intAmount,
//required this.stringAmount,
required this.hWallet,
required this.address,
required this.assetId,
required this.comment});
2023-10-02 14:17:35 +00:00
final int hWallet;
final int intAmount;
//final String stringAmount;
final int fee;
final String address;
final String assetId;
final String comment;
final CryptoCurrency cryptoCurrency = CryptoCurrency.zano;
2023-10-02 14:17:35 +00:00
@override
String get id => transferResult != null ? transferResult!.txHash : '';
2023-10-02 14:17:35 +00:00
@override
String get hex => '';
@override
2023-12-14 04:51:16 +00:00
String get amountFormatted {
return AmountConverter.amountIntToString(cryptoCurrency, intAmount);
2023-12-14 04:51:16 +00:00
}
2023-10-02 14:17:35 +00:00
@override
String get feeFormatted => AmountConverter.amountIntToString(cryptoCurrency, fee);
TransferResult? transferResult;
2023-10-02 14:17:35 +00:00
@override
Future<void> commit() async {
final result = await calls.transfer(
hWallet,
TransferParams(
destinations: [
Destination(
amount: intAmount.toString(), //stringAmount,
address: address,
assetId: assetId,
)
],
fee: fee,
mixin: zanoMixin,
paymentId: '',
comment: comment,
pushPayer: false,
hideReceiver: false,
));
print('transfer result $result');
final map = jsonDecode(result);
if (map["result"] != null && map["result"]["result"] != null ) {
transferResult = TransferResult.fromJson(
map["result"]["result"] as Map<String, dynamic>,
);
}
// try {
// zano_transaction_history.commitTransactionFromPointerAddress(
// address: pendingTransactionDescription.pointerAddress);
// } catch (e) {
// final message = e.toString();
2023-10-02 14:17:35 +00:00
// if (message.contains('Reason: double spend')) {
// throw DoubleSpendException();
// }
2023-10-02 14:17:35 +00:00
// rethrow;
// }
2023-10-02 14:17:35 +00:00
}
}