Skip to content

Commit

Permalink
feat: tx cost estimation on mobile
Browse files Browse the repository at this point in the history
  • Loading branch information
mpoplavkov committed Dec 2, 2023
1 parent 9ea5b78 commit 08fc0fb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
8 changes: 2 additions & 6 deletions packages/flutter_fuels/lib/model/transaction_cost.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,25 @@ class TransactionCost {
final int gasPrice;
final int gasUsed;
final int minFee;
final int maxFee;

TransactionCost(
{required this.minGasPrice,
required this.gasPrice,
required this.gasUsed,
required this.minFee,
required this.maxFee});
required this.minFee});

factory TransactionCost.fromJson(Map<String, dynamic> data) {
return TransactionCost(
minGasPrice: data['minGasPrice'],
gasPrice: data['gasPrice'],
gasUsed: data['gasUsed'],
minFee: data['minFee'],
maxFee: data['maxFee']);
minFee: data['minFee']);
}

Map<String, dynamic> toJson() => {
'minGasPrice': minGasPrice,
'gasPrice': gasPrice,
'gasUsed': gasUsed,
'minFee': minFee,
'maxFee': maxFee,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,15 @@ class MobileWalletUnlocked extends DartWalletUnlocked {

@override
Future<transaction_cost.TransactionCost> getTransactionCost(
{required String transactionRequestHexOrJson}) {
throw UnimplementedError();
{required String transactionRequestHexOrJson}) async {
final bytes = hex.decode(transactionRequestHexOrJson);
final txCost = await _rustWalletUnlocked.estimateTransactionCost(
encodedTx: Uint8List.fromList(bytes));
return transaction_cost.TransactionCost(
minGasPrice: txCost.minGasPrice,
gasPrice: txCost.gasPrice,
gasUsed: txCost.gasUsed,
minFee: txCost.totalFee);
}

@override
Expand Down

0 comments on commit 08fc0fb

Please sign in to comment.