Skip to content

Commit 6e4af03

Browse files
Merge pull request #1166 from cypherstack/bug-fixes
Bug fixes
2 parents ed9aae2 + aea8847 commit 6e4af03

File tree

9 files changed

+80
-38
lines changed

9 files changed

+80
-38
lines changed

lib/pages/send_view/send_view.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1087,7 +1087,10 @@ class _SendViewState extends ConsumerState<SendView> {
10871087
ref.refresh(pIsExchangeAddress);
10881088
});
10891089
isCustomFee.addListener(() {
1090-
if (!isCustomFee.value) ethFee = null;
1090+
if (!isCustomFee.value) {
1091+
customFeeRate = 1;
1092+
ethFee = null;
1093+
}
10911094
});
10921095
hasFees = coin is! Epiccash && coin is! NanoCurrency && coin is! Tezos;
10931096
_currentFee = 0.toAmountAsRaw(fractionDigits: coin.fractionDigits);

lib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_send.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1666,6 +1666,7 @@ class _DesktopSendState extends ConsumerState<DesktopSend> {
16661666
onCustomFeeSliderChanged: (value) => customFeeRate = value,
16671667
onCustomFeeOptionChanged: (value) {
16681668
isCustomFee = value;
1669+
customFeeRate = 1;
16691670
ethFee = null;
16701671
},
16711672
onCustomEip1559FeeOptionChanged: (value) => ethFee = value,

lib/wallets/crypto_currency/coins/bitcoincash.dart

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import 'dart:typed_data';
2-
31
import 'package:bech32/bech32.dart';
42
import 'package:bitbox/bitbox.dart' as bitbox;
53
import 'package:bs58check/bs58check.dart' as bs58check;
64
import 'package:coinlib_flutter/coinlib_flutter.dart' as coinlib;
5+
import 'package:flutter/foundation.dart';
76

87
import '../../../models/isar/models/blockchain_data/address.dart';
98
import '../../../models/node_model.dart';
@@ -231,6 +230,17 @@ class Bitcoincash extends Bip39HDCurrency with ElectrumXCurrencyInterface {
231230
// Do not validate "p" (P2SH) addresses.
232231
}
233232

233+
@override
234+
AddressType? getAddressType(String address) {
235+
final format = bitbox.Address.detectFormat(address);
236+
237+
return super.getAddressType(
238+
format == bitbox.Address.formatCashAddr
239+
? bitbox.Address.toLegacyAddress(address)
240+
: address,
241+
);
242+
}
243+
234244
@override
235245
DerivePathType addressType({required String address}) {
236246
Uint8List? decodeBase58;

lib/wallets/crypto_currency/coins/ecash.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,17 @@ class Ecash extends Bip39HDCurrency with ElectrumXCurrencyInterface {
222222
// Do not validate "p" (P2SH) addresses.
223223
}
224224

225+
@override
226+
AddressType? getAddressType(String address) {
227+
final format = bitbox.Address.detectFormat(address);
228+
229+
return super.getAddressType(
230+
format == bitbox.Address.formatCashAddr
231+
? bitbox.Address.toLegacyAddress(address)
232+
: address,
233+
);
234+
}
235+
225236
@override
226237
DerivePathType addressType({required String address}) {
227238
Uint8List? decodeBase58;

lib/wallets/crypto_currency/interfaces/electrumx_currency_interface.dart

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import 'package:coinlib_flutter/coinlib_flutter.dart' as cl;
2+
import 'package:flutter/foundation.dart';
23

34
import '../../../models/isar/models/blockchain_data/address.dart';
5+
import '../../../utilities/logger.dart';
46
import '../intermediate/bip39_hd_currency.dart';
57

68
mixin ElectrumXCurrencyInterface on Bip39HDCurrency {
@@ -14,15 +16,29 @@ mixin ElectrumXCurrencyInterface on Bip39HDCurrency {
1416
try {
1517
final clAddress = cl.Address.fromString(address, networkParams);
1618

19+
Logging.instance.t(
20+
"getAddressType($address) type is ${clAddress.runtimeType}",
21+
);
22+
1723
return switch (clAddress) {
1824
cl.P2PKHAddress() => AddressType.p2pkh,
19-
cl.P2WSHAddress() => AddressType.p2sh,
25+
cl.P2SHAddress() => AddressType.p2sh,
2026
cl.P2WPKHAddress() => AddressType.p2wpkh,
2127
cl.P2TRAddress() => AddressType.p2tr,
2228
cl.MwebAddress() => AddressType.mweb,
2329
_ => null,
2430
};
25-
} catch (_) {
31+
} catch (e, s) {
32+
if (kDebugMode) {
33+
Logging.instance.e(
34+
"getAddressType($address) failed",
35+
error: e,
36+
stackTrace: s,
37+
);
38+
} else {
39+
Logging.instance.t("getAddressType($address) failed");
40+
}
41+
2642
return null;
2743
}
2844
}

lib/wallets/wallet/impl/particl_wallet.dart

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -352,8 +352,10 @@ class ParticlWallet<T extends ElectrumXCurrencyInterface>
352352
@override
353353
Future<TxData> buildTransaction({
354354
required TxData txData,
355-
required covariant List<StandardInput> inputsWithKeys,
355+
required List<BaseInput> inputsWithKeys,
356356
}) async {
357+
final insAndKeys = inputsWithKeys.cast<StandardInput>();
358+
357359
Logging.instance.d("Starting Particl buildTransaction ----------");
358360

359361
// TODO: use coinlib (For this we need coinlib to support particl)
@@ -371,8 +373,8 @@ class ParticlWallet<T extends ElectrumXCurrencyInterface>
371373
);
372374

373375
final List<({Uint8List? output, Uint8List? redeem})> extraData = [];
374-
for (int i = 0; i < inputsWithKeys.length; i++) {
375-
final sd = inputsWithKeys[i];
376+
for (int i = 0; i < insAndKeys.length; i++) {
377+
final sd = insAndKeys[i];
376378

377379
final pubKey = sd.key!.publicKey.data;
378380
final bitcoindart.PaymentData? data;
@@ -448,11 +450,11 @@ class ParticlWallet<T extends ElectrumXCurrencyInterface>
448450
final List<OutputV2> tempOutputs = [];
449451

450452
// Add inputs.
451-
for (var i = 0; i < inputsWithKeys.length; i++) {
452-
final txid = inputsWithKeys[i].utxo.txid;
453+
for (var i = 0; i < insAndKeys.length; i++) {
454+
final txid = insAndKeys[i].utxo.txid;
453455
txb.addInput(
454456
txid,
455-
inputsWithKeys[i].utxo.vout,
457+
insAndKeys[i].utxo.vout,
456458
null,
457459
extraData[i].output!,
458460
cryptoCurrency.networkParams.bech32Hrp,
@@ -464,14 +466,14 @@ class ParticlWallet<T extends ElectrumXCurrencyInterface>
464466
scriptSigAsm: null,
465467
sequence: 0xffffffff - 1,
466468
outpoint: OutpointV2.isarCantDoRequiredInDefaultConstructor(
467-
txid: inputsWithKeys[i].utxo.txid,
468-
vout: inputsWithKeys[i].utxo.vout,
469+
txid: insAndKeys[i].utxo.txid,
470+
vout: insAndKeys[i].utxo.vout,
469471
),
470472
addresses:
471-
inputsWithKeys[i].utxo.address == null
473+
insAndKeys[i].utxo.address == null
472474
? []
473-
: [inputsWithKeys[i].utxo.address!],
474-
valueStringSats: inputsWithKeys[i].utxo.value.toString(),
475+
: [insAndKeys[i].utxo.address!],
476+
valueStringSats: insAndKeys[i].utxo.value.toString(),
475477
witness: null,
476478
innerRedeemScriptAsm: null,
477479
coinbase: null,
@@ -508,15 +510,15 @@ class ParticlWallet<T extends ElectrumXCurrencyInterface>
508510

509511
// Sign.
510512
try {
511-
for (var i = 0; i < inputsWithKeys.length; i++) {
513+
for (var i = 0; i < insAndKeys.length; i++) {
512514
txb.sign(
513515
vin: i,
514516
keyPair: bitcoindart.ECPair.fromPrivateKey(
515-
inputsWithKeys[i].key!.privateKey!.data,
517+
insAndKeys[i].key!.privateKey!.data,
516518
network: convertedNetwork,
517-
compressed: inputsWithKeys[i].key!.privateKey!.compressed,
519+
compressed: insAndKeys[i].key!.privateKey!.compressed,
518520
),
519-
witnessValue: inputsWithKeys[i].utxo.value,
521+
witnessValue: insAndKeys[i].utxo.value,
520522
redeemScript: extraData[i].redeem,
521523
overridePrefix: cryptoCurrency.networkParams.bech32Hrp,
522524
);

lib/wallets/wallet/wallet_mixin_interfaces/bcash_interface.dart

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ mixin BCashInterface<T extends ElectrumXCurrencyInterface>
1818
@override
1919
Future<TxData> buildTransaction({
2020
required TxData txData,
21-
required covariant List<StandardInput> inputsWithKeys,
21+
required List<BaseInput> inputsWithKeys,
2222
}) async {
23+
final insAndKeys = inputsWithKeys.cast<StandardInput>();
24+
2325
Logging.instance.d("Starting buildTransaction ----------");
2426

2527
// TODO: use coinlib
@@ -35,26 +37,23 @@ mixin BCashInterface<T extends ElectrumXCurrencyInterface>
3537
final List<OutputV2> tempOutputs = [];
3638

3739
// Add transaction inputs
38-
for (int i = 0; i < inputsWithKeys.length; i++) {
39-
builder.addInput(
40-
inputsWithKeys[i].utxo.txid,
41-
inputsWithKeys[i].utxo.vout,
42-
);
40+
for (int i = 0; i < insAndKeys.length; i++) {
41+
builder.addInput(insAndKeys[i].utxo.txid, insAndKeys[i].utxo.vout);
4342

4443
tempInputs.add(
4544
InputV2.isarCantDoRequiredInDefaultConstructor(
4645
scriptSigHex: "000000",
4746
scriptSigAsm: null,
4847
sequence: 0xffffffff - 1,
4948
outpoint: OutpointV2.isarCantDoRequiredInDefaultConstructor(
50-
txid: inputsWithKeys[i].utxo.txid,
51-
vout: inputsWithKeys[i].utxo.vout,
49+
txid: insAndKeys[i].utxo.txid,
50+
vout: insAndKeys[i].utxo.vout,
5251
),
5352
addresses:
54-
inputsWithKeys[i].utxo.address == null
53+
insAndKeys[i].utxo.address == null
5554
? []
56-
: [inputsWithKeys[i].utxo.address!],
57-
valueStringSats: inputsWithKeys[i].utxo.value.toString(),
55+
: [insAndKeys[i].utxo.address!],
56+
valueStringSats: insAndKeys[i].utxo.value.toString(),
5857
witness: null,
5958
innerRedeemScriptAsm: null,
6059
coinbase: null,
@@ -92,9 +91,9 @@ mixin BCashInterface<T extends ElectrumXCurrencyInterface>
9291

9392
try {
9493
// Sign the transaction accordingly
95-
for (int i = 0; i < inputsWithKeys.length; i++) {
94+
for (int i = 0; i < insAndKeys.length; i++) {
9695
final bitboxEC = bitbox.ECPair.fromPrivateKey(
97-
inputsWithKeys[i].key!.privateKey!.data,
96+
insAndKeys[i].key!.privateKey!.data,
9897
network: bitbox_utils.Network(
9998
cryptoCurrency.networkParams.privHDPrefix,
10099
cryptoCurrency.networkParams.pubHDPrefix,
@@ -103,10 +102,10 @@ mixin BCashInterface<T extends ElectrumXCurrencyInterface>
103102
cryptoCurrency.networkParams.wifPrefix,
104103
cryptoCurrency.networkParams.p2pkhPrefix,
105104
),
106-
compressed: inputsWithKeys[i].key!.privateKey!.compressed,
105+
compressed: insAndKeys[i].key!.privateKey!.compressed,
107106
);
108107

109-
builder.sign(i, bitboxEC, inputsWithKeys[i].utxo.value);
108+
builder.sign(i, bitboxEC, insAndKeys[i].utxo.value);
110109
}
111110
} catch (e, s) {
112111
Logging.instance.e(

pubspec.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -985,10 +985,10 @@ packages:
985985
dependency: "direct main"
986986
description:
987987
name: flutter_mwebd
988-
sha256: f6daecf6a4e10dde0a2fbfe026d801cd41864c6464923d9a26a92c613c893173
988+
sha256: "73b35b6eaccb6e1be7eb37e04bcc94f091244fa31b8aedc17e4119c580a7a747"
989989
url: "https://pub.dev"
990990
source: hosted
991-
version: "0.0.1-pre.6"
991+
version: "0.0.1-pre.7"
992992
flutter_native_splash:
993993
dependency: "direct main"
994994
description:

scripts/app_config/templates/pubspec.template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ dependencies:
224224
path: ^1.9.1
225225
cs_salvium: ^1.2.1
226226
cs_salvium_flutter_libs: ^1.0.4
227-
flutter_mwebd: ^0.0.1-pre.6
227+
flutter_mwebd: ^0.0.1-pre.7
228228
mweb_client: ^0.2.0
229229
fixnum: ^1.1.1
230230

0 commit comments

Comments
 (0)