Merge pull request #601 from cypherstack/ui-fixes

fix: dogecoin custom fee slider and possible absurd fees error
This commit is contained in:
Diego Salazar 2023-07-05 11:53:20 -06:00 committed by GitHub
commit 9c23b8f836
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 55 additions and 29 deletions

View file

@ -66,7 +66,7 @@ class MainDB {
// contact entries
List<ContactEntry> getContactEntries() {
return isar.contactEntrys.where().findAllSync();
return isar.contactEntrys.where().sortByName().findAllSync();
}
Future<bool> deleteContactEntry({required String id}) {

View file

@ -146,7 +146,7 @@ class ElectrumX {
throw response.exception!;
}
if (response.data["error"] != null) {
if (response.data is Map && response.data["error"] != null) {
if (response.data["error"]
.toString()
.contains("No such mempool or blockchain transaction")) {

View file

@ -33,6 +33,22 @@ class ContactEntry {
@Index(unique: true, replace: true)
late final String customId;
@ignore
List<ContactAddressEntry> get addressesSorted {
final List<ContactAddressEntry> sorted = [];
for (final coin in Coin.values) {
final slice = addresses.where((e) => e.coin == coin).toList();
if (slice.isNotEmpty) {
slice.sort(
(a, b) => (a.other ?? a.label).compareTo(b.other ?? b.label),
);
sorted.addAll(slice);
}
}
return sorted;
}
ContactEntry copyWith({
bool shouldCopyEmojiWithNull = false,
String? emojiChar,

View file

@ -302,7 +302,7 @@ class _AddressBookViewState extends ConsumerState<AddressBookView> {
child: Column(
children: [
...contacts
.where((element) => element.addresses
.where((element) => element.addressesSorted
.where((e) => ref.watch(addressBookFilterProvider
.select((value) => value.coins.contains(e.coin))))
.isNotEmpty)
@ -350,7 +350,7 @@ class _AddressBookViewState extends ConsumerState<AddressBookView> {
child: Column(
children: [
...contacts
.where((element) => element.addresses
.where((element) => element.addressesSorted
.where((e) => ref.watch(
addressBookFilterProvider.select((value) =>
value.coins.contains(e.coin))))

View file

@ -211,7 +211,8 @@ class _AddNewContactAddressViewState
const Duration(milliseconds: 75),
);
}
List<ContactAddressEntry> entries = contact.addresses;
List<ContactAddressEntry> entries =
contact.addresses.toList();
entries.add(ref
.read(addressEntryDataProvider(0))

View file

@ -341,7 +341,7 @@ class _ContactDetailsViewState extends ConsumerState<ContactDetailsView> {
padding: const EdgeInsets.all(0),
child: Column(
children: [
..._contact.addresses.map(
..._contact.addressesSorted.map(
(e) => Padding(
padding: const EdgeInsets.all(12),
child: Row(

View file

@ -63,7 +63,7 @@ class ContactPopUp extends ConsumerWidget {
bool isExchangeFlow =
ref.watch(exchangeFlowIsActiveStateProvider.state).state;
final addresses = contact.addresses.where((e) {
final addresses = contact.addressesSorted.where((e) {
if (hasActiveWallet && !isExchangeFlow) {
return e.coin == active[0].coin;
} else {

View file

@ -2065,6 +2065,7 @@ class _SendViewState extends ConsumerState<SendView> {
top: 16,
),
child: FeeSlider(
coin: coin,
onSatVByteChanged: (rate) {
customFeeRate = rate;
},

View file

@ -53,15 +53,6 @@ class DesktopContactDetails extends ConsumerStatefulWidget {
class _DesktopContactDetailsState extends ConsumerState<DesktopContactDetails> {
List<Tuple2<String, Transaction>> _cachedTransactions = [];
bool _contactHasAddress(String address, ContactEntry contact) {
for (final entry in contact.addresses) {
if (entry.address == address) {
return true;
}
}
return false;
}
Future<List<Tuple2<String, Transaction>>> _filteredTransactionsByContact(
List<Manager> managers,
) async {
@ -259,7 +250,9 @@ class _DesktopContactDetailsState extends ConsumerState<DesktopContactDetails> {
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
for (int i = 0; i < contact.addresses.length; i++)
for (int i = 0;
i < contact.addressesSorted.length;
i++)
Column(
mainAxisSize: MainAxisSize.min,
children: [
@ -273,7 +266,7 @@ class _DesktopContactDetailsState extends ConsumerState<DesktopContactDetails> {
Padding(
padding: const EdgeInsets.all(18),
child: DesktopAddressCard(
entry: contact.addresses[i],
entry: contact.addressesSorted[i],
contactId: contact.customId,
),
),

View file

@ -69,8 +69,8 @@ class _AddressBookAddressChooserState extends State<AddressBookAddressChooser> {
List<ContactEntry> filter(List<ContactEntry> contacts, String searchTerm) {
if (widget.coin != null) {
contacts.removeWhere(
(e) => e.addresses.where((a) => a.coin == widget.coin!).isEmpty);
contacts.removeWhere((e) =>
e.addressesSorted.where((a) => a.coin == widget.coin!).isEmpty);
}
contacts.retainWhere((e) => _matches(searchTerm, e));

View file

@ -78,7 +78,7 @@ class _ContactListItemState extends ConsumerState<ContactListItem> {
mainAxisSize: MainAxisSize.min,
children: [
// filter addresses by coin is provided before building address list
...contact.addresses
...contact.addressesSorted
.where((e) =>
filterByCoin != null ? e.coin == filterByCoin! : true)
.map(

View file

@ -1564,6 +1564,7 @@ class _DesktopSendState extends ConsumerState<DesktopSend> {
top: 16,
),
child: FeeSlider(
coin: coin,
onSatVByteChanged: (rate) {
customFeeRate = rate;
},

View file

@ -2665,7 +2665,10 @@ class DogecoinWallet extends CoinServiceAPI
Logging.instance
.log("Starting buildTransaction ----------", level: LogLevel.Info);
final txb = TransactionBuilder(network: network);
final txb = TransactionBuilder(
network: network,
maximumFeeRate: 2500000, // 1000x default value in bitcoindart lib
);
txb.setVersion(1);
// Add transaction inputs

View file

@ -70,9 +70,10 @@ class _AddressBookCardState extends ConsumerState<AddressBookCard> {
final contact = _contact!;
final List<Coin> coins = [];
for (var element in contact.addresses) {
if (!coins.contains(element.coin)) {
coins.add(element.coin);
for (final coin in Coin.values) {
if (contact.addresses.where((e) => e.coin == coin).isNotEmpty) {
coins.add(coin);
}
}

View file

@ -1,14 +1,17 @@
import 'dart:math';
import 'package:flutter/material.dart';
import 'package:stackwallet/utilities/enums/coin_enum.dart';
import 'package:stackwallet/utilities/text_styles.dart';
class FeeSlider extends StatefulWidget {
const FeeSlider({
super.key,
required this.onSatVByteChanged,
required this.coin,
});
final Coin coin;
final void Function(int) onSatVByteChanged;
@override
@ -16,12 +19,12 @@ class FeeSlider extends StatefulWidget {
}
class _FeeSliderState extends State<FeeSlider> {
static const int min = 1;
static const int max = 4;
static const double min = 1;
static const double max = 4;
double sliderValue = 0;
int rate = min;
int rate = min.toInt();
@override
Widget build(BuildContext context) {
@ -45,7 +48,14 @@ class _FeeSliderState extends State<FeeSlider> {
onChanged: (value) {
setState(() {
sliderValue = value;
rate = pow(sliderValue * (max - min) + min, 4).toInt();
final number = pow(sliderValue * (max - min) + min, 4).toDouble();
switch (widget.coin) {
case Coin.dogecoin:
case Coin.dogecoinTestNet:
rate = (number * 1000).toInt();
default:
rate = number.toInt();
}
});
widget.onSatVByteChanged(rate);
},