mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-01-22 10:34:32 +00:00
refactor updateVSize function
This commit is contained in:
parent
1426495474
commit
741c0be88b
2 changed files with 14 additions and 11 deletions
|
@ -9,7 +9,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'dart:convert';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
@ -105,14 +104,6 @@ class _TransactionV2DetailsViewState
|
||||||
|
|
||||||
String? _sparkMemo;
|
String? _sparkMemo;
|
||||||
|
|
||||||
Future<TransactionV2> _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;
|
bool _boostButtonLock = false;
|
||||||
Future<void> _boostPressed() async {
|
Future<void> _boostPressed() async {
|
||||||
final wallet = ref.read(pWallets).getWallet(walletId);
|
final wallet = ref.read(pWallets).getWallet(walletId);
|
||||||
|
@ -124,7 +115,7 @@ class _TransactionV2DetailsViewState
|
||||||
if (Util.isDesktop) {
|
if (Util.isDesktop) {
|
||||||
if (_transaction.vSize == null) {
|
if (_transaction.vSize == null) {
|
||||||
final updatedTx = await showLoading(
|
final updatedTx = await showLoading(
|
||||||
whileFuture: _updateVSize(wallet),
|
whileFuture: wallet.updateVSize(_transaction),
|
||||||
context: context,
|
context: context,
|
||||||
message: "Fetching transaction vSize...",
|
message: "Fetching transaction vSize...",
|
||||||
);
|
);
|
||||||
|
|
|
@ -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 '../../crypto_currency/interfaces/electrumx_currency_interface.dart';
|
||||||
import 'electrumx_interface.dart';
|
import 'electrumx_interface.dart';
|
||||||
|
|
||||||
|
@ -5,7 +8,6 @@ typedef TxSize = ({int real, int virtual});
|
||||||
|
|
||||||
mixin RbfInterface<T extends ElectrumXCurrencyInterface>
|
mixin RbfInterface<T extends ElectrumXCurrencyInterface>
|
||||||
on ElectrumXInterface<T> {
|
on ElectrumXInterface<T> {
|
||||||
// TODO actually save the size
|
|
||||||
Future<TxSize?> getVSize(String txid) async {
|
Future<TxSize?> getVSize(String txid) async {
|
||||||
final tx = await electrumXCachedClient.getTransaction(
|
final tx = await electrumXCachedClient.getTransaction(
|
||||||
txHash: txid,
|
txHash: txid,
|
||||||
|
@ -19,5 +21,15 @@ mixin RbfInterface<T extends ElectrumXCurrencyInterface>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<TransactionV2> 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
|
// TODO more RBF specific logic
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue