mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-01-09 20:29:57 +00:00
Merge pull request #554 from cypherstack/ui-fixes
fix: Handle sent to self transactions when sent to a change address
This commit is contained in:
commit
990cc7cfa5
5 changed files with 116 additions and 62 deletions
|
@ -6,7 +6,7 @@ import 'package:flutter_svg/flutter_svg.dart';
|
||||||
import 'package:stackwallet/pages/wallet_view/wallet_view.dart';
|
import 'package:stackwallet/pages/wallet_view/wallet_view.dart';
|
||||||
import 'package:stackwallet/pages_desktop_specific/my_stack_view/wallet_view/desktop_wallet_view.dart';
|
import 'package:stackwallet/pages_desktop_specific/my_stack_view/wallet_view/desktop_wallet_view.dart';
|
||||||
import 'package:stackwallet/providers/providers.dart';
|
import 'package:stackwallet/providers/providers.dart';
|
||||||
import 'package:stackwallet/services/coins/manager.dart';
|
import 'package:stackwallet/services/coins/firo/firo_wallet.dart';
|
||||||
import 'package:stackwallet/themes/coin_icon_provider.dart';
|
import 'package:stackwallet/themes/coin_icon_provider.dart';
|
||||||
import 'package:stackwallet/themes/stack_colors.dart';
|
import 'package:stackwallet/themes/stack_colors.dart';
|
||||||
import 'package:stackwallet/utilities/amount/amount.dart';
|
import 'package:stackwallet/utilities/amount/amount.dart';
|
||||||
|
@ -24,13 +24,11 @@ class FavoriteCard extends ConsumerStatefulWidget {
|
||||||
required this.walletId,
|
required this.walletId,
|
||||||
required this.width,
|
required this.width,
|
||||||
required this.height,
|
required this.height,
|
||||||
required this.managerProvider,
|
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
final String walletId;
|
final String walletId;
|
||||||
final double width;
|
final double width;
|
||||||
final double height;
|
final double height;
|
||||||
final ChangeNotifierProvider<Manager> managerProvider;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
ConsumerState<FavoriteCard> createState() => _FavoriteCardState();
|
ConsumerState<FavoriteCard> createState() => _FavoriteCardState();
|
||||||
|
@ -38,15 +36,10 @@ class FavoriteCard extends ConsumerStatefulWidget {
|
||||||
|
|
||||||
class _FavoriteCardState extends ConsumerState<FavoriteCard> {
|
class _FavoriteCardState extends ConsumerState<FavoriteCard> {
|
||||||
late final String walletId;
|
late final String walletId;
|
||||||
late final ChangeNotifierProvider<Manager> managerProvider;
|
|
||||||
|
|
||||||
Amount _cachedBalance = Amount.zero;
|
|
||||||
Amount _cachedFiatValue = Amount.zero;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
walletId = widget.walletId;
|
walletId = widget.walletId;
|
||||||
managerProvider = widget.managerProvider;
|
|
||||||
|
|
||||||
super.initState();
|
super.initState();
|
||||||
}
|
}
|
||||||
|
@ -55,9 +48,13 @@ class _FavoriteCardState extends ConsumerState<FavoriteCard> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final coin = ref.watch(managerProvider.select((value) => value.coin));
|
final coin = ref.watch(
|
||||||
|
walletsChangeNotifierProvider
|
||||||
|
.select((value) => value.getManager(walletId).coin),
|
||||||
|
);
|
||||||
final externalCalls = ref.watch(
|
final externalCalls = ref.watch(
|
||||||
prefsChangeNotifierProvider.select((value) => value.externalCalls));
|
prefsChangeNotifierProvider.select((value) => value.externalCalls),
|
||||||
|
);
|
||||||
|
|
||||||
return ConditionalParent(
|
return ConditionalParent(
|
||||||
condition: Util.isDesktop,
|
condition: Util.isDesktop,
|
||||||
|
@ -109,7 +106,10 @@ class _FavoriteCardState extends ConsumerState<FavoriteCard> {
|
||||||
child: GestureDetector(
|
child: GestureDetector(
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
if (coin == Coin.monero || coin == Coin.wownero) {
|
if (coin == Coin.monero || coin == Coin.wownero) {
|
||||||
await ref.read(managerProvider).initializeExisting();
|
await ref
|
||||||
|
.read(walletsChangeNotifierProvider)
|
||||||
|
.getManager(walletId)
|
||||||
|
.initializeExisting();
|
||||||
}
|
}
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
if (Util.isDesktop) {
|
if (Util.isDesktop) {
|
||||||
|
@ -122,7 +122,9 @@ class _FavoriteCardState extends ConsumerState<FavoriteCard> {
|
||||||
WalletView.routeName,
|
WalletView.routeName,
|
||||||
arguments: Tuple2(
|
arguments: Tuple2(
|
||||||
walletId,
|
walletId,
|
||||||
managerProvider,
|
ref
|
||||||
|
.read(walletsChangeNotifierProvider)
|
||||||
|
.getManagerProvider(walletId),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -205,8 +207,12 @@ class _FavoriteCardState extends ConsumerState<FavoriteCard> {
|
||||||
children: [
|
children: [
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Text(
|
child: Text(
|
||||||
ref.watch(managerProvider
|
ref.watch(
|
||||||
.select((value) => value.walletName)),
|
walletsChangeNotifierProvider.select(
|
||||||
|
(value) =>
|
||||||
|
value.getManager(walletId).walletName,
|
||||||
|
),
|
||||||
|
),
|
||||||
style: STextStyles.itemSubtitle12(context).copyWith(
|
style: STextStyles.itemSubtitle12(context).copyWith(
|
||||||
color: Theme.of(context)
|
color: Theme.of(context)
|
||||||
.extension<StackColors>()!
|
.extension<StackColors>()!
|
||||||
|
@ -225,41 +231,54 @@ class _FavoriteCardState extends ConsumerState<FavoriteCard> {
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
FutureBuilder(
|
Builder(
|
||||||
future: Future(() => ref.watch(managerProvider
|
builder: (context) {
|
||||||
.select((value) => value.balance.total))),
|
final balance = ref.watch(
|
||||||
builder: (builderContext, AsyncSnapshot<Amount> snapshot) {
|
walletsChangeNotifierProvider.select(
|
||||||
if (snapshot.connectionState == ConnectionState.done &&
|
(value) => value.getManager(walletId).balance,
|
||||||
snapshot.hasData) {
|
),
|
||||||
if (snapshot.data != null) {
|
);
|
||||||
_cachedBalance = snapshot.data!;
|
|
||||||
if (externalCalls && _cachedBalance > Amount.zero) {
|
Amount total = balance.total;
|
||||||
_cachedFiatValue = (_cachedBalance.decimal *
|
if (coin == Coin.firo || coin == Coin.firoTestNet) {
|
||||||
|
final balancePrivate = ref.watch(
|
||||||
|
walletsChangeNotifierProvider.select(
|
||||||
|
(value) => (value.getManager(walletId).wallet
|
||||||
|
as FiroWallet)
|
||||||
|
.balancePrivate,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
total += balancePrivate.total;
|
||||||
|
}
|
||||||
|
|
||||||
|
Amount fiatTotal = Amount.zero;
|
||||||
|
|
||||||
|
if (externalCalls && total > Amount.zero) {
|
||||||
|
fiatTotal = (total.decimal *
|
||||||
ref
|
ref
|
||||||
.watch(
|
.watch(
|
||||||
priceAnd24hChangeNotifierProvider
|
priceAnd24hChangeNotifierProvider.select(
|
||||||
.select(
|
|
||||||
(value) => value.getPrice(coin),
|
(value) => value.getPrice(coin),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.item1)
|
.item1)
|
||||||
.toAmount(fractionDigits: 2);
|
.toAmount(fractionDigits: 2);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
return Column(
|
return Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
FittedBox(
|
FittedBox(
|
||||||
fit: BoxFit.scaleDown,
|
fit: BoxFit.scaleDown,
|
||||||
child: Text(
|
child: Text(
|
||||||
"${_cachedBalance.localizedStringAsFixed(
|
"${total.localizedStringAsFixed(
|
||||||
locale: ref.watch(
|
locale: ref.watch(
|
||||||
localeServiceChangeNotifierProvider
|
localeServiceChangeNotifierProvider.select(
|
||||||
.select((value) => value.locale),
|
(value) => value.locale,
|
||||||
),
|
),
|
||||||
decimalPlaces: ref.watch(managerProvider
|
),
|
||||||
.select((value) => value.coin.decimals)),
|
decimalPlaces: coin.decimals,
|
||||||
)} ${coin.ticker}",
|
)} ${coin.ticker}",
|
||||||
style: STextStyles.titleBold12(context).copyWith(
|
style: STextStyles.titleBold12(context).copyWith(
|
||||||
fontSize: 16,
|
fontSize: 16,
|
||||||
|
@ -275,15 +294,17 @@ class _FavoriteCardState extends ConsumerState<FavoriteCard> {
|
||||||
),
|
),
|
||||||
if (externalCalls)
|
if (externalCalls)
|
||||||
Text(
|
Text(
|
||||||
"${_cachedFiatValue.localizedStringAsFixed(
|
"${fiatTotal.localizedStringAsFixed(
|
||||||
locale: ref.watch(
|
locale: ref.watch(
|
||||||
localeServiceChangeNotifierProvider
|
localeServiceChangeNotifierProvider.select(
|
||||||
.select((value) => value.locale),
|
(value) => value.locale,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
decimalPlaces: 2,
|
decimalPlaces: 2,
|
||||||
)} ${ref.watch(
|
)} ${ref.watch(
|
||||||
prefsChangeNotifierProvider
|
prefsChangeNotifierProvider.select(
|
||||||
.select((value) => value.currency),
|
(value) => value.currency,
|
||||||
|
),
|
||||||
)}",
|
)}",
|
||||||
style:
|
style:
|
||||||
STextStyles.itemSubtitle12(context).copyWith(
|
STextStyles.itemSubtitle12(context).copyWith(
|
||||||
|
|
|
@ -211,7 +211,6 @@ class _FavoriteWalletsState extends ConsumerState<FavoriteWallets> {
|
||||||
child: FavoriteCard(
|
child: FavoriteCard(
|
||||||
key: Key("favCard_$walletId"),
|
key: Key("favCard_$walletId"),
|
||||||
walletId: walletId!,
|
walletId: walletId!,
|
||||||
managerProvider: managerProvider!,
|
|
||||||
width: cardWidth,
|
width: cardWidth,
|
||||||
height: cardHeight,
|
height: cardHeight,
|
||||||
),
|
),
|
||||||
|
@ -219,7 +218,6 @@ class _FavoriteWalletsState extends ConsumerState<FavoriteWallets> {
|
||||||
: FavoriteCard(
|
: FavoriteCard(
|
||||||
key: Key("favCard_$walletId"),
|
key: Key("favCard_$walletId"),
|
||||||
walletId: walletId!,
|
walletId: walletId!,
|
||||||
managerProvider: managerProvider!,
|
|
||||||
width: cardWidth,
|
width: cardWidth,
|
||||||
height: cardHeight,
|
height: cardHeight,
|
||||||
)
|
)
|
||||||
|
|
|
@ -74,7 +74,6 @@ class DesktopFavoriteWallets extends ConsumerWidget {
|
||||||
key: Key(walletName),
|
key: Key(walletName),
|
||||||
width: cardWidth,
|
width: cardWidth,
|
||||||
height: cardHeight,
|
height: cardHeight,
|
||||||
managerProvider: managerProvider,
|
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
],
|
],
|
||||||
|
|
|
@ -148,8 +148,13 @@ mixin ElectrumXParsing {
|
||||||
type = TransactionType.outgoing;
|
type = TransactionType.outgoing;
|
||||||
amount = amountSentFromWallet - changeAmount - fee;
|
amount = amountSentFromWallet - changeAmount - fee;
|
||||||
|
|
||||||
final possible =
|
// non wallet addresses found in tx outputs
|
||||||
outputAddresses.difference(myChangeReceivedOnAddresses).first;
|
final nonWalletOutAddresses = outputAddresses.difference(
|
||||||
|
myChangeReceivedOnAddresses,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (nonWalletOutAddresses.isNotEmpty) {
|
||||||
|
final possible = nonWalletOutAddresses.first;
|
||||||
|
|
||||||
if (transactionAddress.value != possible) {
|
if (transactionAddress.value != possible) {
|
||||||
transactionAddress = Address(
|
transactionAddress = Address(
|
||||||
|
@ -162,6 +167,13 @@ mixin ElectrumXParsing {
|
||||||
publicKey: [],
|
publicKey: [],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// some other type of tx where the receiving address is
|
||||||
|
// one of my change addresses
|
||||||
|
|
||||||
|
type = TransactionType.sentToSelf;
|
||||||
|
amount = changeAmount;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// incoming tx
|
// incoming tx
|
||||||
type = TransactionType.incoming;
|
type = TransactionType.incoming;
|
||||||
|
|
|
@ -4,8 +4,10 @@ import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
import 'package:flutter_svg/svg.dart';
|
import 'package:flutter_svg/svg.dart';
|
||||||
import 'package:stackwallet/providers/providers.dart';
|
import 'package:stackwallet/providers/providers.dart';
|
||||||
|
import 'package:stackwallet/services/coins/firo/firo_wallet.dart';
|
||||||
import 'package:stackwallet/themes/coin_icon_provider.dart';
|
import 'package:stackwallet/themes/coin_icon_provider.dart';
|
||||||
import 'package:stackwallet/themes/stack_colors.dart';
|
import 'package:stackwallet/themes/stack_colors.dart';
|
||||||
|
import 'package:stackwallet/utilities/amount/amount.dart';
|
||||||
import 'package:stackwallet/utilities/constants.dart';
|
import 'package:stackwallet/utilities/constants.dart';
|
||||||
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
||||||
import 'package:stackwallet/utilities/text_styles.dart';
|
import 'package:stackwallet/utilities/text_styles.dart';
|
||||||
|
@ -34,6 +36,28 @@ class _ManagedFavoriteCardState extends ConsumerState<ManagedFavorite> {
|
||||||
|
|
||||||
final isDesktop = Util.isDesktop;
|
final isDesktop = Util.isDesktop;
|
||||||
|
|
||||||
|
final balance = ref.watch(
|
||||||
|
walletsChangeNotifierProvider.select(
|
||||||
|
(value) => value.getManager(widget.walletId).balance,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
Amount total = balance.total;
|
||||||
|
if (manager.coin == Coin.firo || manager.coin == Coin.firoTestNet) {
|
||||||
|
final balancePrivate = ref.watch(
|
||||||
|
walletsChangeNotifierProvider.select(
|
||||||
|
(value) => (value
|
||||||
|
.getManager(
|
||||||
|
widget.walletId,
|
||||||
|
)
|
||||||
|
.wallet as FiroWallet)
|
||||||
|
.balancePrivate,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
total += balancePrivate.total;
|
||||||
|
}
|
||||||
|
|
||||||
return RoundedWhiteContainer(
|
return RoundedWhiteContainer(
|
||||||
padding: EdgeInsets.all(isDesktop ? 0 : 4.0),
|
padding: EdgeInsets.all(isDesktop ? 0 : 4.0),
|
||||||
child: RawMaterialButton(
|
child: RawMaterialButton(
|
||||||
|
@ -107,7 +131,7 @@ class _ManagedFavoriteCardState extends ConsumerState<ManagedFavorite> {
|
||||||
),
|
),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Text(
|
child: Text(
|
||||||
"${manager.balance.total.localizedStringAsFixed(
|
"${total.localizedStringAsFixed(
|
||||||
locale: ref.watch(
|
locale: ref.watch(
|
||||||
localeServiceChangeNotifierProvider.select(
|
localeServiceChangeNotifierProvider.select(
|
||||||
(value) => value.locale,
|
(value) => value.locale,
|
||||||
|
@ -150,7 +174,7 @@ class _ManagedFavoriteCardState extends ConsumerState<ManagedFavorite> {
|
||||||
height: 2,
|
height: 2,
|
||||||
),
|
),
|
||||||
Text(
|
Text(
|
||||||
"${manager.balance.total.localizedStringAsFixed(
|
"${total.localizedStringAsFixed(
|
||||||
locale: ref.watch(
|
locale: ref.watch(
|
||||||
localeServiceChangeNotifierProvider.select(
|
localeServiceChangeNotifierProvider.select(
|
||||||
(value) => value.locale,
|
(value) => value.locale,
|
||||||
|
|
Loading…
Reference in a new issue