Merge pull request #441 from cypherstack/bug_fixes

Bug fixes
This commit is contained in:
Diego Salazar 2023-03-28 17:39:10 -06:00 committed by GitHub
commit 85456e0df5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 378 additions and 413 deletions

View file

@ -57,7 +57,10 @@ class AddressEntryData extends ChangeNotifier {
} }
bool get isValidAddress { bool get isValidAddress {
if (_address == null || coin == null) { if ( coin == null) {
return true;
}
if (_address == null) {
return false; return false;
} }
return AddressUtils.validateAddress(_address!, _coin!); return AddressUtils.validateAddress(_address!, _coin!);

View file

@ -138,270 +138,228 @@ class _UtxoDetailsViewState extends ConsumerState<UtxoDetailsView> {
), ),
), ),
child: StreamBuilder<UTXO?>( child: StreamBuilder<UTXO?>(
stream: streamUTXO, stream: streamUTXO,
builder: (context, snapshot) { builder: (context, snapshot) {
if (snapshot.hasData) { if (snapshot.hasData) {
utxo = snapshot.data!; utxo = snapshot.data!;
} }
return ConditionalParent( return ConditionalParent(
condition: isDesktop, condition: isDesktop,
builder: (child) { builder: (child) {
return DesktopDialog( return DesktopDialog(
maxHeight: double.infinity, maxHeight: double.infinity,
child: Column( child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Padding(
padding: const EdgeInsets.only(left: 32),
child: Text(
"Output details",
style: STextStyles.desktopH3(context),
),
),
DesktopDialogCloseButton(
onPressedOverride: () {
Navigator.of(context)
.pop(_popWithRefresh ? "refresh" : null);
},
),
],
),
IntrinsicHeight(
child: Padding(
padding: const EdgeInsets.only(
left: 32,
right: 32,
bottom: 32,
top: 10,
),
child: Column(
children: [
IntrinsicHeight(
child: RoundedContainer(
padding: EdgeInsets.zero,
color: Colors.transparent,
borderColor: Theme.of(context)
.extension<StackColors>()!
.textFieldDefaultBG,
child: child,
),
),
const SizedBox(
height: 20,
),
SecondaryButton(
buttonHeight: ButtonHeight.l,
label: utxo!.isBlocked ? "Unfreeze" : "Freeze",
onPressed: _toggleFreeze,
),
],
),
),
),
],
),
);
},
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
if (!isDesktop)
const SizedBox(
height: 10,
),
RoundedContainer(
padding: const EdgeInsets.all(12),
color: isDesktop
? Colors.transparent
: Theme.of(context).extension<StackColors>()!.popupBG,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
Row( Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
Padding( if (isDesktop)
padding: const EdgeInsets.only(left: 32), UTXOStatusIcon(
child: Text( blocked: utxo!.isBlocked,
"Output details", status: confirmed
style: STextStyles.desktopH3(context), ? UTXOStatusIconStatus.confirmed
: UTXOStatusIconStatus.unconfirmed,
background: Theme.of(context)
.extension<StackColors>()!
.popupBG,
selected: false,
width: 32,
height: 32,
), ),
), if (isDesktop)
DesktopDialogCloseButton( const SizedBox(
onPressedOverride: () { width: 16,
Navigator.of(context) ),
.pop(_popWithRefresh ? "refresh" : null); Text(
}, "${Format.satoshisToAmount(
utxo!.value,
coin: coin,
).toStringAsFixed(
coin.decimals,
)} ${coin.ticker}",
style: STextStyles.pageTitleH2(context),
), ),
], ],
), ),
IntrinsicHeight( Text(
child: Padding( utxo!.isBlocked
padding: const EdgeInsets.only( ? "Frozen"
left: 32, : confirmed
right: 32, ? "Available"
bottom: 32, : "Unconfirmed",
top: 10, style: STextStyles.w500_14(context).copyWith(
), color: utxo!.isBlocked
child: Column( ? const Color(0xFF7FA2D4) // todo theme
children: [ : confirmed
IntrinsicHeight( ? Theme.of(context)
child: RoundedContainer(
padding: EdgeInsets.zero,
color: Colors.transparent,
borderColor: Theme.of(context)
.extension<StackColors>()! .extension<StackColors>()!
.textFieldDefaultBG, .accentColorGreen
child: child, : Theme.of(context)
), .extension<StackColors>()!
), .accentColorYellow,
const SizedBox(
height: 20,
),
SecondaryButton(
buttonHeight: ButtonHeight.l,
label: utxo!.isBlocked ? "Unfreeze" : "Freeze",
onPressed: _toggleFreeze,
),
],
),
), ),
), ),
], ],
), ),
); ),
}, const _Div(),
child: Column( RoundedContainer(
crossAxisAlignment: CrossAxisAlignment.stretch, padding: isDesktop
children: [ ? const EdgeInsets.all(16)
if (!isDesktop) : const EdgeInsets.all(12),
const SizedBox( color: isDesktop
height: 10, ? Colors.transparent
), : Theme.of(context).extension<StackColors>()!.popupBG,
RoundedContainer( child: Column(
padding: const EdgeInsets.all(12), mainAxisSize: MainAxisSize.min,
color: isDesktop crossAxisAlignment: CrossAxisAlignment.start,
? Colors.transparent children: [
: Theme.of(context).extension<StackColors>()!.popupBG, Row(
child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
children: [
if (isDesktop)
UTXOStatusIcon(
blocked: utxo!.isBlocked,
status: confirmed
? UTXOStatusIconStatus.confirmed
: UTXOStatusIconStatus.unconfirmed,
background: Theme.of(context)
.extension<StackColors>()!
.popupBG,
selected: false,
width: 32,
height: 32,
),
if (isDesktop)
const SizedBox(
width: 16,
),
Text(
"${Format.satoshisToAmount(
utxo!.value,
coin: coin,
).toStringAsFixed(
coin.decimals,
)} ${coin.ticker}",
style: STextStyles.pageTitleH2(context),
),
],
),
Text(
utxo!.isBlocked
? "Frozen"
: confirmed
? "Available"
: "Unconfirmed",
style: STextStyles.w500_14(context).copyWith(
color: utxo!.isBlocked
? const Color(0xFF7FA2D4) // todo theme
: confirmed
? Theme.of(context)
.extension<StackColors>()!
.accentColorGreen
: Theme.of(context)
.extension<StackColors>()!
.accentColorYellow,
),
),
],
),
),
const _Div(),
RoundedContainer(
padding: isDesktop
? const EdgeInsets.all(16)
: const EdgeInsets.all(12),
color: isDesktop
? Colors.transparent
: Theme.of(context).extension<StackColors>()!.popupBG,
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
"Label",
style: STextStyles.w500_14(context).copyWith(
color: Theme.of(context)
.extension<StackColors>()!
.textSubtitle1,
),
),
SimpleEditButton(
editValue: utxo!.name,
editLabel: "label",
onValueChanged: (newName) {
MainDB.instance.putUTXO(
utxo!.copyWith(
name: newName,
),
);
},
),
],
),
const SizedBox(
height: 4,
),
Text(
utxo!.name,
style: STextStyles.w500_14(context),
),
],
),
),
const _Div(),
RoundedContainer(
padding: isDesktop
? const EdgeInsets.all(16)
: const EdgeInsets.all(12),
color: isDesktop
? Colors.transparent
: Theme.of(context).extension<StackColors>()!.popupBG,
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
"Address",
style: STextStyles.w500_14(context).copyWith(
color: Theme.of(context)
.extension<StackColors>()!
.textSubtitle1,
),
),
isDesktop
? IconCopyButton(
data: utxo!.address!,
)
: SimpleCopyButton(
data: utxo!.address!,
),
],
),
const SizedBox(
height: 4,
),
Text(
utxo!.address!,
style: STextStyles.w500_14(context),
),
],
),
),
if (label != null && label!.value.isNotEmpty) const _Div(),
if (label != null && label!.value.isNotEmpty)
RoundedContainer(
padding: isDesktop
? const EdgeInsets.all(16)
: const EdgeInsets.all(12),
color: isDesktop
? Colors.transparent
: Theme.of(context).extension<StackColors>()!.popupBG,
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
"Address label",
style: STextStyles.w500_14(context).copyWith(
color: Theme.of(context)
.extension<StackColors>()!
.textSubtitle1,
),
),
isDesktop
? IconCopyButton(
data: utxo!.address!,
)
: SimpleCopyButton(
data: label!.value,
),
],
),
const SizedBox(
height: 4,
),
Text( Text(
label!.value, "Label",
style: STextStyles.w500_14(context), style: STextStyles.w500_14(context).copyWith(
color: Theme.of(context)
.extension<StackColors>()!
.textSubtitle1,
),
),
SimpleEditButton(
editValue: utxo!.name,
editLabel: "label",
onValueChanged: (newName) {
MainDB.instance.putUTXO(
utxo!.copyWith(
name: newName,
),
);
},
), ),
], ],
), ),
), const SizedBox(
const _Div(), height: 4,
),
Text(
utxo!.name,
style: STextStyles.w500_14(context),
),
],
),
),
const _Div(),
RoundedContainer(
padding: isDesktop
? const EdgeInsets.all(16)
: const EdgeInsets.all(12),
color: isDesktop
? Colors.transparent
: Theme.of(context).extension<StackColors>()!.popupBG,
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
"Address",
style: STextStyles.w500_14(context).copyWith(
color: Theme.of(context)
.extension<StackColors>()!
.textSubtitle1,
),
),
isDesktop
? IconCopyButton(
data: utxo!.address!,
)
: SimpleCopyButton(
data: utxo!.address!,
),
],
),
const SizedBox(
height: 4,
),
Text(
utxo!.address!,
style: STextStyles.w500_14(context),
),
],
),
),
if (label != null && label!.value.isNotEmpty) const _Div(),
if (label != null && label!.value.isNotEmpty)
RoundedContainer( RoundedContainer(
padding: isDesktop padding: isDesktop
? const EdgeInsets.all(16) ? const EdgeInsets.all(16)
@ -417,7 +375,7 @@ class _UtxoDetailsViewState extends ConsumerState<UtxoDetailsView> {
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
Text( Text(
"Transaction ID", "Address label",
style: STextStyles.w500_14(context).copyWith( style: STextStyles.w500_14(context).copyWith(
color: Theme.of(context) color: Theme.of(context)
.extension<StackColors>()! .extension<StackColors>()!
@ -426,10 +384,10 @@ class _UtxoDetailsViewState extends ConsumerState<UtxoDetailsView> {
), ),
isDesktop isDesktop
? IconCopyButton( ? IconCopyButton(
data: utxo!.address!, data: label!.value,
) )
: SimpleCopyButton( : SimpleCopyButton(
data: utxo!.txid, data: label!.value,
), ),
], ],
), ),
@ -437,114 +395,155 @@ class _UtxoDetailsViewState extends ConsumerState<UtxoDetailsView> {
height: 4, height: 4,
), ),
Text( Text(
utxo!.txid, label!.value,
style: STextStyles.w500_14(context), style: STextStyles.w500_14(context),
), ),
], ],
), ),
), ),
const _Div(), const _Div(),
RoundedContainer( RoundedContainer(
padding: isDesktop padding: isDesktop
? const EdgeInsets.all(16) ? const EdgeInsets.all(16)
: const EdgeInsets.all(12), : const EdgeInsets.all(12),
color: isDesktop color: isDesktop
? Colors.transparent ? Colors.transparent
: Theme.of(context).extension<StackColors>()!.popupBG, : Theme.of(context).extension<StackColors>()!.popupBG,
child: Column( child: Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Text( Row(
"Confirmations", mainAxisAlignment: MainAxisAlignment.spaceBetween,
style: STextStyles.w500_14(context).copyWith( children: [
color: Theme.of(context) Text(
.extension<StackColors>()! "Transaction ID",
.textSubtitle1, style: STextStyles.w500_14(context).copyWith(
), color: Theme.of(context)
),
const SizedBox(
height: 4,
),
Text(
"${utxo!.getConfirmations(currentHeight)}",
style: STextStyles.w500_14(context),
),
],
),
),
if (utxo!.isBlocked) const _Div(),
if (utxo!.isBlocked)
Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
RoundedContainer(
padding: isDesktop
? const EdgeInsets.all(16)
: const EdgeInsets.all(12),
color: isDesktop
? Colors.transparent
: Theme.of(context)
.extension<StackColors>()! .extension<StackColors>()!
.popupBG, .textSubtitle1,
child: Column( ),
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Text(
"Freeze reason",
style:
STextStyles.w500_14(context).copyWith(
color: Theme.of(context)
.extension<StackColors>()!
.textSubtitle1,
),
),
SimpleEditButton(
editValue: utxo!.blockedReason ?? "",
editLabel: "freeze reason",
onValueChanged: (newReason) {
MainDB.instance.putUTXO(
utxo!.copyWith(
blockedReason: newReason,
),
);
},
),
],
),
const SizedBox(
height: 4,
),
Text(
utxo!.blockedReason ?? "",
style: STextStyles.w500_14(context),
),
],
), ),
isDesktop
? IconCopyButton(
data: utxo!.txid,
)
: SimpleCopyButton(
data: utxo!.txid,
),
],
),
const SizedBox(
height: 4,
),
Text(
utxo!.txid,
style: STextStyles.w500_14(context),
),
],
),
),
const _Div(),
RoundedContainer(
padding: isDesktop
? const EdgeInsets.all(16)
: const EdgeInsets.all(12),
color: isDesktop
? Colors.transparent
: Theme.of(context).extension<StackColors>()!.popupBG,
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"Confirmations",
style: STextStyles.w500_14(context).copyWith(
color: Theme.of(context)
.extension<StackColors>()!
.textSubtitle1,
), ),
if (!isDesktop) const _Div(), ),
], const SizedBox(
), height: 4,
if (!isDesktop) const Spacer(), ),
if (!isDesktop) Text(
SecondaryButton( "${utxo!.getConfirmations(currentHeight)}",
label: utxo!.isBlocked ? "Unfreeze" : "Freeze", style: STextStyles.w500_14(context),
onPressed: _toggleFreeze, ),
), ],
if (!isDesktop) ),
const SizedBox( ),
height: 16, if (utxo!.isBlocked) const _Div(),
), if (utxo!.isBlocked)
], Column(
), mainAxisSize: MainAxisSize.min,
); crossAxisAlignment: CrossAxisAlignment.stretch,
}), children: [
RoundedContainer(
padding: isDesktop
? const EdgeInsets.all(16)
: const EdgeInsets.all(12),
color: isDesktop
? Colors.transparent
: Theme.of(context)
.extension<StackColors>()!
.popupBG,
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
"Freeze reason",
style: STextStyles.w500_14(context).copyWith(
color: Theme.of(context)
.extension<StackColors>()!
.textSubtitle1,
),
),
SimpleEditButton(
editValue: utxo!.blockedReason ?? "",
editLabel: "freeze reason",
onValueChanged: (newReason) {
MainDB.instance.putUTXO(
utxo!.copyWith(
blockedReason: newReason,
),
);
},
),
],
),
const SizedBox(
height: 4,
),
Text(
utxo!.blockedReason ?? "",
style: STextStyles.w500_14(context),
),
],
),
),
if (!isDesktop) const _Div(),
],
),
if (!isDesktop) const Spacer(),
if (!isDesktop)
SecondaryButton(
label: utxo!.isBlocked ? "Unfreeze" : "Freeze",
onPressed: _toggleFreeze,
),
if (!isDesktop)
const SizedBox(
height: 16,
),
],
),
);
},
),
); );
} }
} }

View file

@ -282,6 +282,7 @@ abstract class SWB {
backupWallet['id'] = manager.walletId; backupWallet['id'] = manager.walletId;
backupWallet['isFavorite'] = manager.isFavorite; backupWallet['isFavorite'] = manager.isFavorite;
backupWallet['mnemonic'] = await manager.mnemonic; backupWallet['mnemonic'] = await manager.mnemonic;
backupWallet['mnemonicPassphrase'] = await manager.mnemonicPassphrase;
backupWallet['coinName'] = manager.coin.name; backupWallet['coinName'] = manager.coin.name;
backupWallet['storedChainHeight'] = DB.instance backupWallet['storedChainHeight'] = DB.instance
.get<dynamic>(boxName: manager.walletId, key: 'storedChainHeight'); .get<dynamic>(boxName: manager.walletId, key: 'storedChainHeight');
@ -363,6 +364,7 @@ abstract class SWB {
walletId: manager.walletId, walletId: manager.walletId,
restoringStatus: StackRestoringStatus.restoring, restoringStatus: StackRestoringStatus.restoring,
mnemonic: mnemonic, mnemonic: mnemonic,
mnemonicPassphrase: mnemonicPassphrase,
); );
if (_shouldCancelRestore) { if (_shouldCancelRestore) {
@ -432,6 +434,7 @@ abstract class SWB {
address: currentAddress, address: currentAddress,
height: restoreHeight, height: restoreHeight,
mnemonic: mnemonic, mnemonic: mnemonic,
mnemonicPassphrase: mnemonicPassphrase,
); );
} catch (e, s) { } catch (e, s) {
Logging.instance.log("$e $s", level: LogLevel.Warning); Logging.instance.log("$e $s", level: LogLevel.Warning);
@ -440,6 +443,7 @@ abstract class SWB {
restoringStatus: StackRestoringStatus.failed, restoringStatus: StackRestoringStatus.failed,
manager: manager, manager: manager,
mnemonic: mnemonic, mnemonic: mnemonic,
mnemonicPassphrase: mnemonicPassphrase,
); );
return false; return false;
} }

View file

@ -2490,60 +2490,17 @@ class FiroWallet extends CoinServiceAPI with WalletCache, WalletDB, FiroHive {
}); });
} }
// final int utxosIntValue = utxos.satoshiBalance; _balancePrivate = Balance(
// final Decimal utxosValue = coin: coin,
// Format.satoshisToAmount(utxosIntValue, coin: coin); total: intLelantusBalance + unconfirmedLelantusBalance,
spendable: intLelantusBalance,
// List<Decimal> balances = List.empty(growable: true); blockedTotal: 0,
// pendingSpendable: unconfirmedLelantusBalance,
// Decimal lelantusBalance = );
// Format.satoshisToAmount(intLelantusBalance, coin: coin); await updateCachedBalanceSecondary(_balancePrivate!);
// balances.add(lelantusBalance); 0
//
// balances.add(lelantusBalance * price); 1
// Decimal _unconfirmedLelantusBalance =
// Format.satoshisToAmount(unconfirmedLelantusBalance, coin: coin);
// balances.add(lelantusBalance + utxosValue + _unconfirmedLelantusBalance); 2
//
// balances.add(
// (lelantusBalance + utxosValue + _unconfirmedLelantusBalance) * price); 3
// int availableSats =
// utxos.satoshiBalance - utxos.satoshiBalanceUnconfirmed;
// if (availableSats < 0) {
// availableSats = 0;
// }
// balances.add(Format.satoshisToAmount(availableSats, coin: coin)); 4
// wait for updated uxtos to get updated public balance // wait for updated uxtos to get updated public balance
await utxosUpdateFuture; await utxosUpdateFuture;
// todo: shared total between private and public balances?
_balancePrivate = Balance(
coin: coin,
total: intLelantusBalance + unconfirmedLelantusBalance + balance.total,
spendable: intLelantusBalance,
blockedTotal: 0,
pendingSpendable: unconfirmedLelantusBalance + balance.total,
);
await updateCachedBalanceSecondary(_balancePrivate!);
// _balance = Balance(
// coin: coin,
// total: utxos.satoshiBalance,
// spendable: availableSats,
// blockedTotal: 0,
// pendingSpendable: utxos.satoshiBalanceUnconfirmed,
// );
// Logging.instance.log("balances $balances", level: LogLevel.Info);
// await DB.instance.put<dynamic>(
// boxName: walletId,
// key: 'totalBalance',
// value: balances[2].toString());
// return balances;
} catch (e, s) { } catch (e, s) {
Logging.instance.log("Exception rethrown in getFullBalance(): $e\n$s", Logging.instance.log("Exception rethrown in getFullBalance(): $e\n$s",
level: LogLevel.Error); level: LogLevel.Error);

View file

@ -33,22 +33,24 @@ class WalletSheetCard extends ConsumerWidget {
), ),
), ),
onPressed: () async { onPressed: () async {
final manager = ref final manager =
.read(walletsChangeNotifierProvider) ref.read(walletsChangeNotifierProvider).getManager(walletId);
.getManager(walletId); if (manager.coin == Coin.monero || manager.coin == Coin.wownero) {
if (manager.coin == Coin.monero ||
manager.coin == Coin.wownero) {
await manager.initializeExisting(); await manager.initializeExisting();
} }
if (popPrevious) Navigator.of(context).pop(); if (context.mounted) {
Navigator.of(context).pushNamed( if (popPrevious && context.mounted) Navigator.of(context).pop();
WalletView.routeName,
arguments: Tuple2( await Navigator.of(context).pushNamed(
WalletView.routeName,
arguments: Tuple2(
walletId, walletId,
ref ref
.read(walletsChangeNotifierProvider) .read(walletsChangeNotifierProvider)
.getManagerProvider(walletId)), .getManagerProvider(walletId),
); ),
);
}
}, },
child: WalletInfoRow( child: WalletInfoRow(
walletId: walletId, walletId: walletId,