add RBF wallet interface mixin

This commit is contained in:
julian 2024-06-15 11:36:53 -06:00
parent 425dc1ca5a
commit ac07aee9c3
4 changed files with 94 additions and 40 deletions

View file

@ -34,6 +34,7 @@ import '../../../../utilities/block_explorers.dart';
import '../../../../utilities/constants.dart';
import '../../../../utilities/format.dart';
import '../../../../utilities/logger.dart';
import '../../../../utilities/show_loading.dart';
import '../../../../utilities/text_styles.dart';
import '../../../../utilities/util.dart';
import '../../../../wallets/crypto_currency/crypto_currency.dart';
@ -41,6 +42,7 @@ import '../../../../wallets/crypto_currency/intermediate/nano_currency.dart';
import '../../../../wallets/isar/models/spark_coin.dart';
import '../../../../wallets/isar/providers/wallet_info_provider.dart';
import '../../../../wallets/wallet/impl/epiccash_wallet.dart';
import '../../../../wallets/wallet/wallet_mixin_interfaces/rbf_interface.dart';
import '../../../../wallets/wallet/wallet_mixin_interfaces/spark_interface.dart';
import '../../../../widgets/background.dart';
import '../../../../widgets/conditional_parent.dart';
@ -92,6 +94,7 @@ class _TransactionV2DetailsViewState
late final String unit;
late final int minConfirms;
late final EthContract? ethContract;
late final bool supportsRbf;
bool get isTokenTx => ethContract != null;
@ -103,44 +106,57 @@ class _TransactionV2DetailsViewState
bool _boostButtonLock = false;
Future<void> _boostPressed() async {
if (_boostButtonLock) {
final wallet = ref.read(pWallets).getWallet(walletId);
if (_boostButtonLock || wallet is! RbfInterface) {
return;
}
_boostButtonLock = true;
try {
if (Util.isDesktop) {
await showDialog<void>(
// TODO fetch size from _transaction after its added to db schema, if not there,
// then fetch using the function below
final size = await showLoading(
whileFuture: wallet.getVSize(_transaction.txid),
context: context,
builder: (context) => DesktopDialog(
maxHeight: null,
maxWidth: 580,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Padding(
padding: const EdgeInsets.only(left: 32),
child: Text(
"Boost transaction",
style: STextStyles.desktopH3(context),
message: "Fetching transaction vSize...",
);
// TODO pass the size in to the rbf screen
if (mounted) {
await showDialog<void>(
context: context,
builder: (context) => DesktopDialog(
maxHeight: null,
maxWidth: 580,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Padding(
padding: const EdgeInsets.only(left: 32),
child: Text(
"Boost transaction",
style: STextStyles.desktopH3(context),
),
),
const DesktopDialogCloseButton(),
],
),
Flexible(
child: SingleChildScrollView(
child: BoostTransactionView(
transaction: _transaction,
),
),
const DesktopDialogCloseButton(),
],
),
Flexible(
child: SingleChildScrollView(
child: BoostTransactionView(
transaction: _transaction,
),
),
),
],
],
),
),
),
);
);
}
} else {
unawaited(
Navigator.of(context).pushNamed(
@ -160,6 +176,13 @@ class _TransactionV2DetailsViewState
_transaction = widget.transaction;
walletId = widget.walletId;
if (_transaction.type
case TransactionType.sentToSelf || TransactionType.outgoing) {
supportsRbf = ref.read(pWallets).getWallet(walletId) is RbfInterface;
} else {
supportsRbf = false;
}
coin = widget.coin;
if (_transaction.subType == TransactionSubType.ethToken) {
@ -537,14 +560,12 @@ class _TransactionV2DetailsViewState
outputLabel = "Sent to";
}
// TODO [prio=high]: set to true for ui testing
final showBoost = true;
// final showBoost = coin is! NanoCurrency &&
// _transaction.type == TransactionType.outgoing &&
// !_transaction.isConfirmed(
// currentHeight,
// coin.minConfirms,
// );
// TODO: [prio=high]: revert the following when done testing
final confirmedTxn = false;
// final confirmedTxn = _transaction.isConfirmed(
// currentHeight,
// coin.minConfirms,
// );
return ConditionalParent(
condition: !isDesktop,
@ -1394,11 +1415,11 @@ class _TransactionV2DetailsViewState
context,
),
),
if (showBoost)
if (supportsRbf && !confirmedTxn)
const SizedBox(
height: 8,
),
if (showBoost)
if (supportsRbf && !confirmedTxn)
CustomTextButton(
text: "Boost transaction",
onTap: _boostPressed,

View file

@ -8,9 +8,14 @@ import '../intermediate/bip39_hd_wallet.dart';
import '../wallet_mixin_interfaces/coin_control_interface.dart';
import '../wallet_mixin_interfaces/electrumx_interface.dart';
import '../wallet_mixin_interfaces/paynym_interface.dart';
import '../wallet_mixin_interfaces/rbf_interface.dart';
class BitcoinWallet<T extends PaynymCurrencyInterface> extends Bip39HDWallet<T>
with ElectrumXInterface<T>, CoinControlInterface, PaynymInterface<T> {
with
ElectrumXInterface<T>,
CoinControlInterface,
PaynymInterface<T>,
RbfInterface<T> {
@override
int get isarTransactionVersion => 2;

View file

@ -14,10 +14,15 @@ import '../intermediate/bip39_hd_wallet.dart';
import '../wallet_mixin_interfaces/coin_control_interface.dart';
import '../wallet_mixin_interfaces/electrumx_interface.dart';
import '../wallet_mixin_interfaces/ordinals_interface.dart';
import '../wallet_mixin_interfaces/rbf_interface.dart';
class LitecoinWallet<T extends ElectrumXCurrencyInterface>
extends Bip39HDWallet<T>
with ElectrumXInterface<T>, CoinControlInterface<T>, OrdinalsInterface<T> {
with
ElectrumXInterface<T>,
CoinControlInterface<T>,
RbfInterface<T>,
OrdinalsInterface<T> {
@override
int get isarTransactionVersion => 2;

View file

@ -0,0 +1,23 @@
import '../../crypto_currency/interfaces/electrumx_currency_interface.dart';
import 'electrumx_interface.dart';
typedef TxSize = ({int real, int virtual});
mixin RbfInterface<T extends ElectrumXCurrencyInterface>
on ElectrumXInterface<T> {
// TODO actually save the size
Future<TxSize?> getVSize(String txid) async {
final tx = await electrumXCachedClient.getTransaction(
txHash: txid,
cryptoCurrency: cryptoCurrency,
);
try {
return (real: tx["size"] as int, virtual: tx["vsize"] as int);
} catch (_) {
return null;
}
}
// TODO more RBF specific logic
}