more minor fixes

This commit is contained in:
fossephate 2024-09-09 13:24:50 -07:00
parent 0f5ee476f1
commit 728a0bf4b2
4 changed files with 7 additions and 33 deletions

View file

@ -776,6 +776,7 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
script: outputs[0].toOutput.scriptPubKey, value: utxos.sumOfUtxosValue())
];
}
// https://github.com/ltcmweb/mwebd?tab=readme-ov-file#fee-estimation
final preOutputSum =
outputs.fold<BigInt>(BigInt.zero, (acc, output) => acc + output.toOutput.amount);
final fee = utxos.sumOfUtxosValue() - preOutputSum;
@ -891,19 +892,15 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
_utxoStream?.cancel();
}
void setMwebEnabled(bool enabled) {
Future<void> setMwebEnabled(bool enabled) async {
if (mwebEnabled == enabled) {
return;
}
mwebEnabled = enabled;
(walletAddresses as LitecoinWalletAddresses).mwebEnabled = enabled;
if (enabled) {
// generate inital mweb addresses:
(walletAddresses as LitecoinWalletAddresses).topUpMweb(0);
}
stopSync();
startSync();
await stopSync();
await startSync();
}
Future<RpcClient> getStub() async {

View file

@ -2,20 +2,14 @@ import 'dart:typed_data';
import 'package:bech32/bech32.dart';
import 'package:bitcoin_base/bitcoin_base.dart';
import 'package:blockchain_utils/bech32/bech32_base.dart';
import 'package:blockchain_utils/blockchain_utils.dart';
import 'package:cw_bitcoin/electrum_wallet.dart';
import 'package:cw_bitcoin/utils.dart';
import 'package:cw_bitcoin/electrum_wallet_addresses.dart';
import 'package:cw_core/wallet_info.dart';
import 'package:cw_mweb/cw_mweb.dart';
import 'package:cw_mweb/mwebd.pb.dart';
import 'package:mobx/mobx.dart';
// import 'dart:typed_data';
// import 'package:bech32/bech32.dart';
// import 'package:r_crypto/r_crypto.dart';
part 'litecoin_wallet_addresses.g.dart';
String encodeMwebAddress(List<int> scriptPubKey) {
@ -36,12 +30,7 @@ abstract class LitecoinWalletAddressesBase extends ElectrumWalletAddresses with
super.initialRegularAddressIndex,
super.initialChangeAddressIndex,
}) : super(walletInfo) {
if (mwebEnabled) {
// give the server a few seconds to start up before trying to get the addresses:
Future.delayed(const Duration(seconds: 5), () async {
await topUpMweb(0);
});
}
topUpMweb(0);
}
final Bip32Slip10Secp256k1 mwebHd;
@ -79,18 +68,6 @@ abstract class LitecoinWalletAddressesBase extends ElectrumWalletAddresses with
return generateP2WPKHAddress(hd: hd, index: index, network: network);
}
@override
Future<String> getAddressAsync({
required int index,
required Bip32Slip10Secp256k1 hd,
BitcoinAddressType? addressType,
}) async {
if (addressType == SegwitAddresType.mweb) {
await topUpMweb(index);
}
return getAddress(index: index, hd: hd, addressType: addressType);
}
@action
@override
Future<String> getChangeAddress({List<BitcoinOutput>? outputs, UtxoDetails? utxoDetails}) async {

View file

@ -557,7 +557,7 @@ class CWBitcoin extends Bitcoin {
}
@override
void setMwebEnabled(Object wallet, bool enabled) {
Future<void> setMwebEnabled(Object wallet, bool enabled) async {
final litecoinWallet = wallet as LitecoinWallet;
litecoinWallet.setMwebEnabled(enabled);
}

View file

@ -224,7 +224,7 @@ abstract class Bitcoin {
void setLedger(WalletBase wallet, Ledger ledger, LedgerDevice device);
Future<List<HardwareAccountData>> getHardwareWalletAccounts(LedgerViewModel ledgerVM, {int index = 0, int limit = 5});
void setMwebEnabled(Object wallet, bool enabled);
Future<void> setMwebEnabled(Object wallet, bool enabled);
bool getMwebEnabled(Object wallet);
}
""";