Skip to content

Commit 1d9fb4c

Browse files
authored
Merge pull request #709 from cypherstack/ui-fixes
various small fixes
2 parents 2319c0e + 50a3e8e commit 1d9fb4c

File tree

27 files changed

+939
-416
lines changed

27 files changed

+939
-416
lines changed

lib/electrumx_rpc/cached_electrumx.dart

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*/
1010

1111
import 'dart:convert';
12+
import 'dart:math';
1213

1314
import 'package:stackwallet/db/hive/db.dart';
1415
import 'package:stackwallet/electrumx_rpc/electrumx.dart';
@@ -167,8 +168,10 @@ class CachedElectrumX {
167168
Set<String> cachedSerials =
168169
_list == null ? {} : List<String>.from(_list).toSet();
169170

170-
final startNumber =
171-
cachedSerials.length - 10; // 10 being some arbitrary buffer
171+
startNumber = max(
172+
max(0, startNumber),
173+
cachedSerials.length - 100, // 100 being some arbitrary buffer
174+
);
172175

173176
final serials = await electrumXClient.getUsedCoinSerials(
174177
startNumber: startNumber,

lib/models/isar/models/blockchain_data/v2/transaction_v2.dart

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,14 @@ class TransactionV2 {
8484
.where((e) => e.walletOwns)
8585
.fold(BigInt.zero, (p, e) => p + e.value);
8686

87-
return Amount(rawValue: inSum, fractionDigits: coin.decimals);
87+
return Amount(
88+
rawValue: inSum,
89+
fractionDigits: coin.decimals,
90+
) -
91+
getAmountReceivedThisWallet(
92+
coin: coin,
93+
) -
94+
getFee(coin: coin);
8895
}
8996

9097
Set<String> associatedAddresses() => {

lib/pages/cashfusion/cashfusion_view.dart

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,11 @@ class _CashFusionViewState extends ConsumerState<CashFusionView> {
6161
FusionOption _option = FusionOption.continuous;
6262

6363
Future<void> _startFusion() async {
64-
final fusionWallet = ref
64+
final wallet = ref
6565
.read(walletsChangeNotifierProvider)
6666
.getManager(widget.walletId)
67-
.wallet as FusionWalletInterface;
67+
.wallet;
68+
final fusionWallet = wallet as FusionWalletInterface;
6869

6970
try {
7071
fusionWallet.uiState = ref.read(
@@ -89,7 +90,9 @@ class _CashFusionViewState extends ConsumerState<CashFusionView> {
8990
);
9091

9192
// update user prefs (persistent)
92-
ref.read(prefsChangeNotifierProvider).fusionServerInfo = newInfo;
93+
ref
94+
.read(prefsChangeNotifierProvider)
95+
.setFusionServerInfo(wallet.coin, newInfo);
9396

9497
unawaited(
9598
fusionWallet.fuse(
@@ -113,7 +116,11 @@ class _CashFusionViewState extends ConsumerState<CashFusionView> {
113116
portFocusNode = FocusNode();
114117
fusionRoundFocusNode = FocusNode();
115118

116-
final info = ref.read(prefsChangeNotifierProvider).fusionServerInfo;
119+
final info = ref.read(prefsChangeNotifierProvider).getFusionServerInfo(ref
120+
.read(walletsChangeNotifierProvider)
121+
.getManager(widget.walletId)
122+
.wallet
123+
.coin);
117124
serverController.text = info.host;
118125
portController.text = info.port.toString();
119126
_enableSSLCheckbox = info.ssl;
@@ -150,7 +157,7 @@ class _CashFusionViewState extends ConsumerState<CashFusionView> {
150157
automaticallyImplyLeading: false,
151158
leading: const AppBarBackButton(),
152159
title: Text(
153-
"CashFusion",
160+
"Fusion",
154161
style: STextStyles.navBarTitle(context),
155162
),
156163
titleSpacing: 0,
@@ -189,7 +196,7 @@ class _CashFusionViewState extends ConsumerState<CashFusionView> {
189196
children: [
190197
RoundedWhiteContainer(
191198
child: Text(
192-
"CashFusion allows you to anonymize your BCH coins.",
199+
"Fusion helps anonymize your coins by mixing them.",
193200
style: STextStyles.w500_12(context).copyWith(
194201
color: Theme.of(context)
195202
.extension<StackColors>()!
@@ -214,7 +221,11 @@ class _CashFusionViewState extends ConsumerState<CashFusionView> {
214221
CustomTextButton(
215222
text: "Default",
216223
onTap: () {
217-
const def = FusionInfo.DEFAULTS;
224+
final def = kFusionServerInfoDefaults[ref
225+
.read(walletsChangeNotifierProvider)
226+
.getManager(widget.walletId)
227+
.wallet
228+
.coin]!;
218229
serverController.text = def.host;
219230
portController.text = def.port.toString();
220231
fusionRoundController.text =

lib/pages/cashfusion/fusion_progress_view.dart

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import 'package:stackwallet/providers/global/prefs_provider.dart';
1818
import 'package:stackwallet/providers/global/wallets_provider.dart';
1919
import 'package:stackwallet/services/mixins/fusion_wallet_interface.dart';
2020
import 'package:stackwallet/themes/stack_colors.dart';
21+
import 'package:stackwallet/utilities/enums/coin_enum.dart';
2122
import 'package:stackwallet/utilities/show_loading.dart';
2223
import 'package:stackwallet/utilities/text_styles.dart';
2324
import 'package:stackwallet/utilities/util.dart';
@@ -43,6 +44,8 @@ class FusionProgressView extends ConsumerStatefulWidget {
4344
}
4445

4546
class _FusionProgressViewState extends ConsumerState<FusionProgressView> {
47+
late final Coin coin;
48+
4649
Future<bool> _requestAndProcessCancel() async {
4750
final shouldCancel = await showDialog<bool?>(
4851
context: context,
@@ -88,6 +91,16 @@ class _FusionProgressViewState extends ConsumerState<FusionProgressView> {
8891
}
8992
}
9093

94+
@override
95+
void initState() {
96+
coin = ref
97+
.read(walletsChangeNotifierProvider)
98+
.getManager(widget.walletId)
99+
.wallet
100+
.coin;
101+
super.initState();
102+
}
103+
91104
@override
92105
Widget build(BuildContext context) {
93106
final bool _succeeded =
@@ -230,7 +243,8 @@ class _FusionProgressViewState extends ConsumerState<FusionProgressView> {
230243
.getManager(widget.walletId)
231244
.wallet as FusionWalletInterface;
232245

233-
final fusionInfo = ref.read(prefsChangeNotifierProvider).fusionServerInfo;
246+
final fusionInfo =
247+
ref.read(prefsChangeNotifierProvider).getFusionServerInfo(coin);
234248

235249
try {
236250
fusionWallet.uiState = ref.read(

lib/pages/exchange_view/exchange_coin_selection/exchange_currency_selection_view.dart

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import 'package:stackwallet/services/exchange/change_now/change_now_exchange.dar
2121
import 'package:stackwallet/services/exchange/exchange.dart';
2222
import 'package:stackwallet/services/exchange/exchange_data_loading_service.dart';
2323
import 'package:stackwallet/services/exchange/majestic_bank/majestic_bank_exchange.dart';
24+
import 'package:stackwallet/services/exchange/trocador/trocador_exchange.dart';
2425
import 'package:stackwallet/themes/stack_colors.dart';
2526
import 'package:stackwallet/utilities/assets.dart';
2627
import 'package:stackwallet/utilities/constants.dart';
@@ -107,10 +108,14 @@ class _ExchangeCurrencySelectionViewState
107108
if (widget.pairedTicker == null) {
108109
return await _getCurrencies();
109110
}
111+
await ExchangeDataLoadingService.instance.initDB();
110112
List<Currency> currencies = await ExchangeDataLoadingService
111113
.instance.isar.currencies
112114
.where()
115+
.filter()
113116
.exchangeNameEqualTo(MajesticBankExchange.exchangeName)
117+
.or()
118+
.exchangeNameStartsWith(TrocadorExchange.exchangeName)
114119
.findAll();
115120

116121
final cn = await ChangeNowExchange.instance.getPairedCurrencies(
@@ -120,7 +125,7 @@ class _ExchangeCurrencySelectionViewState
120125

121126
if (cn.value == null) {
122127
if (cn.exception is UnsupportedCurrencyException) {
123-
return currencies;
128+
return _getDistinctCurrenciesFrom(currencies);
124129
}
125130

126131
if (mounted) {
@@ -153,6 +158,7 @@ class _ExchangeCurrencySelectionViewState
153158
}
154159

155160
Future<List<Currency>> _getCurrencies() async {
161+
await ExchangeDataLoadingService.instance.initDB();
156162
final currencies = await ExchangeDataLoadingService.instance.isar.currencies
157163
.where()
158164
.filter()
@@ -186,7 +192,8 @@ class _ExchangeCurrencySelectionViewState
186192
List<Currency> _getDistinctCurrenciesFrom(List<Currency> currencies) {
187193
final List<Currency> distinctCurrencies = [];
188194
for (final currency in currencies) {
189-
if (!distinctCurrencies.any((e) => e.ticker == currency.ticker)) {
195+
if (!distinctCurrencies.any(
196+
(e) => e.ticker.toLowerCase() == currency.ticker.toLowerCase())) {
190197
distinctCurrencies.add(currency);
191198
}
192199
}

lib/pages/exchange_view/trade_details_view.dart

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,10 @@ class _TradeDetailsViewState extends ConsumerState<TradeDetailsView> {
8888

8989
bool isStackCoin(String ticker) {
9090
try {
91-
coinFromTickerCaseInsensitive(ticker);
91+
try {
92+
coinFromTickerCaseInsensitive(ticker);
93+
} catch (_) {}
94+
coinFromPrettyName(ticker);
9295
return true;
9396
} on ArgumentError catch (_) {
9497
return false;
@@ -272,10 +275,17 @@ class _TradeDetailsViewState extends ConsumerState<TradeDetailsView> {
272275
label: "Send from Stack",
273276
buttonHeight: ButtonHeight.l,
274277
onPressed: () {
275-
final coin =
276-
coinFromTickerCaseInsensitive(trade.payInCurrency);
277-
final amount =
278-
sendAmount.toAmount(fractionDigits: coin.decimals);
278+
Coin coin;
279+
try {
280+
coin = coinFromTickerCaseInsensitive(
281+
trade.payInCurrency);
282+
} catch (_) {
283+
coin = coinFromPrettyName(trade.payInCurrency);
284+
}
285+
final amount = Amount.fromDecimal(
286+
sendAmount,
287+
fractionDigits: coin.decimals,
288+
);
279289
final address = trade.payInAddress;
280290

281291
Navigator.of(context).pushNamed(
@@ -1347,12 +1357,18 @@ class _TradeDetailsViewState extends ConsumerState<TradeDetailsView> {
13471357
SecondaryButton(
13481358
label: "Send from Stack",
13491359
onPressed: () {
1350-
final amount = sendAmount;
1360+
Coin coin;
1361+
try {
1362+
coin = coinFromTickerCaseInsensitive(trade.payInCurrency);
1363+
} catch (_) {
1364+
coin = coinFromPrettyName(trade.payInCurrency);
1365+
}
1366+
final amount = Amount.fromDecimal(
1367+
sendAmount,
1368+
fractionDigits: coin.decimals,
1369+
);
13511370
final address = trade.payInAddress;
13521371

1353-
final coin =
1354-
coinFromTickerCaseInsensitive(trade.payInCurrency);
1355-
13561372
Navigator.of(context).pushNamed(
13571373
SendFromView.routeName,
13581374
arguments: Tuple4(

lib/pages/send_view/send_view.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2007,6 +2007,7 @@ class _SendViewState extends ConsumerState<SendView> {
20072007
),
20082008
if (coin != Coin.epicCash &&
20092009
coin != Coin.nano &&
2010+
coin != Coin.tezos &&
20102011
coin != Coin.banano)
20112012
Text(
20122013
"Transaction fee (estimated)",
@@ -2015,12 +2016,14 @@ class _SendViewState extends ConsumerState<SendView> {
20152016
),
20162017
if (coin != Coin.epicCash &&
20172018
coin != Coin.nano &&
2019+
coin != Coin.tezos &&
20182020
coin != Coin.banano)
20192021
const SizedBox(
20202022
height: 8,
20212023
),
20222024
if (coin != Coin.epicCash &&
20232025
coin != Coin.nano &&
2026+
coin != Coin.tezos &&
20242027
coin != Coin.banano)
20252028
Stack(
20262029
children: [

lib/pages/wallet_view/wallet_view.dart

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,8 @@ class _WalletViewState extends ConsumerState<WalletView> {
845845
onTap: () {
846846
Navigator.of(context).pushNamed(
847847
coin == Coin.bitcoincash ||
848-
coin == Coin.bitcoincashTestnet
848+
coin == Coin.bitcoincashTestnet ||
849+
coin == Coin.eCash
849850
? AllTransactionsV2View.routeName
850851
: AllTransactionsView.routeName,
851852
arguments: walletId,
@@ -902,7 +903,9 @@ class _WalletViewState extends ConsumerState<WalletView> {
902903
children: [
903904
Expanded(
904905
child: coin == Coin.bitcoincash ||
905-
coin == Coin.bitcoincashTestnet
906+
coin ==
907+
Coin.bitcoincashTestnet ||
908+
coin == Coin.eCash
906909
? TransactionsV2List(
907910
walletId: widget.walletId,
908911
)

lib/pages_desktop_specific/cashfusion/desktop_cashfusion_view.dart

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import 'package:stackwallet/services/mixins/fusion_wallet_interface.dart';
2626
import 'package:stackwallet/themes/stack_colors.dart';
2727
import 'package:stackwallet/utilities/assets.dart';
2828
import 'package:stackwallet/utilities/constants.dart';
29+
import 'package:stackwallet/utilities/enums/coin_enum.dart';
2930
import 'package:stackwallet/utilities/text_styles.dart';
3031
import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart';
3132
import 'package:stackwallet/widgets/custom_buttons/blue_text_button.dart';
@@ -58,6 +59,7 @@ class _DesktopCashFusion extends ConsumerState<DesktopCashFusionView> {
5859
late final FocusNode portFocusNode;
5960
late final TextEditingController fusionRoundController;
6061
late final FocusNode fusionRoundFocusNode;
62+
late final Coin coin;
6163

6264
bool _enableStartButton = false;
6365
bool _enableSSLCheckbox = false;
@@ -93,7 +95,7 @@ class _DesktopCashFusion extends ConsumerState<DesktopCashFusionView> {
9395
);
9496

9597
// update user prefs (persistent)
96-
ref.read(prefsChangeNotifierProvider).fusionServerInfo = newInfo;
98+
ref.read(prefsChangeNotifierProvider).setFusionServerInfo(coin, newInfo);
9799

98100
unawaited(
99101
fusionWallet.fuse(
@@ -121,8 +123,14 @@ class _DesktopCashFusion extends ConsumerState<DesktopCashFusionView> {
121123
serverFocusNode = FocusNode();
122124
portFocusNode = FocusNode();
123125
fusionRoundFocusNode = FocusNode();
126+
coin = ref
127+
.read(walletsChangeNotifierProvider)
128+
.getManager(widget.walletId)
129+
.wallet
130+
.coin;
124131

125-
final info = ref.read(prefsChangeNotifierProvider).fusionServerInfo;
132+
final info =
133+
ref.read(prefsChangeNotifierProvider).getFusionServerInfo(coin);
126134
serverController.text = info.host;
127135
portController.text = info.port.toString();
128136
_enableSSLCheckbox = info.ssl;
@@ -197,7 +205,7 @@ class _DesktopCashFusion extends ConsumerState<DesktopCashFusionView> {
197205
width: 12,
198206
),
199207
Text(
200-
"CashFusion",
208+
"Fusion",
201209
style: STextStyles.desktopH3(context),
202210
),
203211
],
@@ -219,7 +227,7 @@ class _DesktopCashFusion extends ConsumerState<DesktopCashFusionView> {
219227
),
220228
RichText(
221229
text: TextSpan(
222-
text: "What is CashFusion?",
230+
text: "What is Fusion?",
223231
style: STextStyles.richLink(context).copyWith(
224232
fontSize: 16,
225233
),
@@ -248,7 +256,7 @@ class _DesktopCashFusion extends ConsumerState<DesktopCashFusionView> {
248256
.spaceBetween,
249257
children: [
250258
Text(
251-
"What is CashFusion?",
259+
"What is Fusion?",
252260
style: STextStyles.desktopH2(
253261
context),
254262
),
@@ -308,7 +316,7 @@ class _DesktopCashFusion extends ConsumerState<DesktopCashFusionView> {
308316
child: Row(
309317
children: [
310318
Text(
311-
"CashFusion allows you to anonymize your BCH coins.",
319+
"Fusion helps anonymize your coins by mixing them.",
312320
style:
313321
STextStyles.desktopTextExtraExtraSmall(context),
314322
),
@@ -336,7 +344,11 @@ class _DesktopCashFusion extends ConsumerState<DesktopCashFusionView> {
336344
CustomTextButton(
337345
text: "Default",
338346
onTap: () {
339-
const def = FusionInfo.DEFAULTS;
347+
final def = kFusionServerInfoDefaults[ref
348+
.read(walletsChangeNotifierProvider)
349+
.getManager(widget.walletId)
350+
.wallet
351+
.coin]!;
340352
serverController.text = def.host;
341353
portController.text = def.port.toString();
342354
fusionRoundController.text =

0 commit comments

Comments
 (0)