From 741c0be88bc51ec30ab3a08157cde4d519ccf223 Mon Sep 17 00:00:00 2001 From: julian Date: Sun, 16 Jun 2024 10:33:54 -0600 Subject: [PATCH] refactor updateVSize function --- .../tx_v2/transaction_v2_details_view.dart | 11 +---------- .../wallet_mixin_interfaces/rbf_interface.dart | 14 +++++++++++++- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/lib/pages/wallet_view/transaction_views/tx_v2/transaction_v2_details_view.dart b/lib/pages/wallet_view/transaction_views/tx_v2/transaction_v2_details_view.dart index c971142d1..17479eaa6 100644 --- a/lib/pages/wallet_view/transaction_views/tx_v2/transaction_v2_details_view.dart +++ b/lib/pages/wallet_view/transaction_views/tx_v2/transaction_v2_details_view.dart @@ -9,7 +9,6 @@ */ import 'dart:async'; -import 'dart:convert'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; @@ -105,14 +104,6 @@ class _TransactionV2DetailsViewState String? _sparkMemo; - Future _updateVSize(RbfInterface rbfWallet) async { - final size = await rbfWallet.getVSize(_transaction.txid); - final otherData = jsonDecode(_transaction.otherData ?? "{}"); - otherData[TxV2OdKeys.vSize] = size!.virtual; - otherData[TxV2OdKeys.size] = size.real; - return _transaction.copyWith(otherData: jsonEncode(otherData)); - } - bool _boostButtonLock = false; Future _boostPressed() async { final wallet = ref.read(pWallets).getWallet(walletId); @@ -124,7 +115,7 @@ class _TransactionV2DetailsViewState if (Util.isDesktop) { if (_transaction.vSize == null) { final updatedTx = await showLoading( - whileFuture: _updateVSize(wallet), + whileFuture: wallet.updateVSize(_transaction), context: context, message: "Fetching transaction vSize...", ); diff --git a/lib/wallets/wallet/wallet_mixin_interfaces/rbf_interface.dart b/lib/wallets/wallet/wallet_mixin_interfaces/rbf_interface.dart index a44ea2443..22c011699 100644 --- a/lib/wallets/wallet/wallet_mixin_interfaces/rbf_interface.dart +++ b/lib/wallets/wallet/wallet_mixin_interfaces/rbf_interface.dart @@ -1,3 +1,6 @@ +import 'dart:convert'; + +import '../../../models/isar/models/blockchain_data/v2/transaction_v2.dart'; import '../../crypto_currency/interfaces/electrumx_currency_interface.dart'; import 'electrumx_interface.dart'; @@ -5,7 +8,6 @@ typedef TxSize = ({int real, int virtual}); mixin RbfInterface on ElectrumXInterface { - // TODO actually save the size Future getVSize(String txid) async { final tx = await electrumXCachedClient.getTransaction( txHash: txid, @@ -19,5 +21,15 @@ mixin RbfInterface } } + Future updateVSize(TransactionV2 transactionV2) async { + final size = await getVSize(transactionV2.txid); + final otherData = jsonDecode(transactionV2.otherData ?? "{}"); + otherData[TxV2OdKeys.vSize] = size!.virtual; + otherData[TxV2OdKeys.size] = size.real; + final updatedTx = transactionV2.copyWith(otherData: jsonEncode(otherData)); + await mainDB.updateOrPutTransactionV2s([updatedTx]); + return updatedTx; + } + // TODO more RBF specific logic }