Skip to content

Commit ba10bff

Browse files
Merge pull request #1255 from cypherstack/julian/firo-masternodes
firo masternode serialization fix and firo wizardswap interaction improvements
2 parents 02fdfc0 + 6e981ef commit ba10bff

14 files changed

Lines changed: 1104 additions & 761 deletions

File tree

lib/pages/buy_view/buy_form.dart

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ import '../../widgets/stack_dialog.dart';
5757
import '../../widgets/stack_text_field.dart';
5858
import '../../widgets/textfield_icon_button.dart';
5959
import '../address_book_views/address_book_view.dart';
60-
import '../exchange_view/choose_from_stack_view.dart';
60+
import '../exchange_view/choose_address_from_stack_view.dart';
6161
import 'buy_quote_preview.dart';
6262
import 'sub_widgets/crypto_selection_view.dart';
6363
import 'sub_widgets/fiat_selection_view.dart';
@@ -1172,14 +1172,19 @@ class _BuyFormState extends ConsumerState<BuyForm> {
11721172
);
11731173
Navigator.of(context)
11741174
.pushNamed(
1175-
ChooseFromStackView.routeName,
1175+
ChooseAddressFromStackView.routeName,
11761176
arguments: coin,
11771177
)
11781178
.then((value) async {
1179-
if (value is String) {
1179+
if (value
1180+
is ({
1181+
String walletId,
1182+
String address,
1183+
String walletName,
1184+
})) {
11801185
final wallet = ref
11811186
.read(pWallets)
1182-
.getWallet(value);
1187+
.getWallet(value.walletId);
11831188

11841189
// _toController.text = manager.walletName;
11851190
// model.recipientAddress =
Lines changed: 344 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,344 @@
1+
/*
2+
* This file is part of Stack Wallet.
3+
*
4+
* Copyright (c) 2023 Cypher Stack
5+
* All Rights Reserved.
6+
* The code is distributed under GPLv3 license, see LICENSE file for details.
7+
* Generated by Cypher Stack on 2023-05-26
8+
*
9+
*/
10+
11+
import 'package:flutter/material.dart';
12+
import 'package:flutter_riverpod/flutter_riverpod.dart';
13+
import 'package:flutter_svg/flutter_svg.dart';
14+
15+
import '../../providers/providers.dart';
16+
import '../../themes/stack_colors.dart';
17+
import '../../utilities/assets.dart';
18+
import '../../utilities/constants.dart';
19+
import '../../utilities/show_loading.dart';
20+
import '../../utilities/text_styles.dart';
21+
import '../../utilities/util.dart';
22+
import '../../wallets/crypto_currency/crypto_currency.dart';
23+
import '../../wallets/isar/providers/wallet_info_provider.dart';
24+
import '../../wallets/wallet/wallet_mixin_interfaces/spark_interface.dart';
25+
import '../../widgets/background.dart';
26+
import '../../widgets/custom_buttons/app_bar_icon_button.dart';
27+
import '../../widgets/rounded_white_container.dart';
28+
import '../../widgets/stack_dialog.dart';
29+
import '../../widgets/wallet_info_row/sub_widgets/wallet_info_row_balance.dart';
30+
import '../../widgets/wallet_info_row/sub_widgets/wallet_info_row_coin_icon.dart';
31+
32+
class ChooseAddressFromStackView extends ConsumerStatefulWidget {
33+
const ChooseAddressFromStackView({super.key, required this.coin});
34+
35+
final CryptoCurrency coin;
36+
37+
static const String routeName = "/chooseFromStack";
38+
39+
@override
40+
ConsumerState<ChooseAddressFromStackView> createState() =>
41+
_ChooseFromStackViewState();
42+
}
43+
44+
class _ChooseFromStackViewState
45+
extends ConsumerState<ChooseAddressFromStackView> {
46+
late final CryptoCurrency coin;
47+
48+
@override
49+
void initState() {
50+
coin = widget.coin;
51+
super.initState();
52+
}
53+
54+
@override
55+
Widget build(BuildContext context) {
56+
final walletIds = ref
57+
.watch(pWallets)
58+
.wallets
59+
.where((e) => e.info.coin == coin)
60+
.map((e) => e.walletId)
61+
.toList();
62+
63+
return Background(
64+
child: Scaffold(
65+
backgroundColor: Theme.of(context).extension<StackColors>()!.background,
66+
appBar: AppBar(
67+
leading: const AppBarBackButton(),
68+
title: Text(
69+
"Choose your ${coin.ticker.toUpperCase()} wallet",
70+
style: STextStyles.navBarTitle(context),
71+
),
72+
),
73+
body: SafeArea(
74+
child: Padding(
75+
padding: const EdgeInsets.all(16),
76+
child: walletIds.isEmpty
77+
? Column(
78+
children: [
79+
RoundedWhiteContainer(
80+
child: Center(
81+
child: Text(
82+
"No ${coin.ticker.toUpperCase()} wallets",
83+
style: STextStyles.itemSubtitle(context),
84+
),
85+
),
86+
),
87+
],
88+
)
89+
: ListView.builder(
90+
itemCount: walletIds.length,
91+
itemBuilder: (context, index) => Padding(
92+
padding: const EdgeInsets.symmetric(vertical: 5.0),
93+
child: _WalletAddressSelectCard(
94+
walletId: walletIds[index],
95+
),
96+
),
97+
),
98+
),
99+
),
100+
),
101+
);
102+
}
103+
}
104+
105+
class _WalletAddressSelectCard extends ConsumerStatefulWidget {
106+
const _WalletAddressSelectCard({required this.walletId});
107+
108+
final String walletId;
109+
110+
@override
111+
ConsumerState<_WalletAddressSelectCard> createState() =>
112+
_WalletAddressSelectCardState();
113+
}
114+
115+
class _WalletAddressSelectCardState
116+
extends ConsumerState<_WalletAddressSelectCard> {
117+
@override
118+
Widget build(BuildContext context) {
119+
final coin = ref.watch(pWalletCoin(widget.walletId));
120+
121+
if (coin is! Firo) {
122+
return RawMaterialButton(
123+
splashColor: Theme.of(context).extension<StackColors>()!.highlight,
124+
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
125+
shape: RoundedRectangleBorder(
126+
borderRadius: BorderRadius.circular(
127+
Constants.size.circularBorderRadius,
128+
),
129+
),
130+
padding: const EdgeInsets.all(0),
131+
elevation: 0,
132+
onPressed: () async {
133+
final wallet = ref.read(pWallets).getWallet(widget.walletId);
134+
135+
final data = (
136+
walletId: widget.walletId,
137+
address:
138+
(await wallet.getCurrentReceivingAddress())?.value ??
139+
wallet.info.cachedReceivingAddress,
140+
walletName: wallet.info.name,
141+
);
142+
143+
if (context.mounted) {
144+
Navigator.of(context).pop(data);
145+
}
146+
},
147+
child: RoundedWhiteContainer(
148+
child: Row(
149+
children: [
150+
WalletInfoCoinIcon(coin: coin),
151+
const SizedBox(width: 12),
152+
Expanded(
153+
child: Column(
154+
mainAxisSize: MainAxisSize.min,
155+
crossAxisAlignment: CrossAxisAlignment.start,
156+
children: [
157+
Text(
158+
ref.watch(pWalletName(widget.walletId)),
159+
style: STextStyles.titleBold12(context),
160+
overflow: TextOverflow.ellipsis,
161+
),
162+
const SizedBox(height: 2),
163+
WalletInfoRowBalance(walletId: widget.walletId),
164+
],
165+
),
166+
),
167+
],
168+
),
169+
),
170+
);
171+
}
172+
173+
return RoundedWhiteContainer(
174+
child: Column(
175+
mainAxisSize: .min,
176+
crossAxisAlignment: .start,
177+
children: [
178+
Row(
179+
children: [
180+
WalletInfoCoinIcon(coin: coin),
181+
const SizedBox(width: 12),
182+
Expanded(
183+
child: Text(
184+
ref.watch(pWalletName(widget.walletId)),
185+
style: STextStyles.titleBold12(context),
186+
overflow: TextOverflow.ellipsis,
187+
),
188+
),
189+
],
190+
),
191+
const SizedBox(height: 10),
192+
RawMaterialButton(
193+
splashColor: Theme.of(context).extension<StackColors>()!.highlight,
194+
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
195+
shape: RoundedRectangleBorder(
196+
borderRadius: BorderRadius.circular(
197+
Constants.size.circularBorderRadius,
198+
),
199+
),
200+
padding: const EdgeInsets.all(0),
201+
elevation: 0,
202+
onPressed: () async {
203+
Future<String?> _future() async {
204+
final wallet =
205+
ref.read(pWallets).getWallet(widget.walletId)
206+
as SparkInterface;
207+
final sparkAddress = await wallet
208+
.getCurrentReceivingSparkAddress();
209+
if (sparkAddress != null) {
210+
return sparkAddress.value;
211+
}
212+
213+
return (await wallet.generateNextSparkAddress(
214+
saveToDB: true,
215+
)).value;
216+
}
217+
218+
Exception? ex;
219+
final sparkAddress = await showLoading(
220+
context: context,
221+
message: "Fetching Spark address",
222+
rootNavigator: Util.isDesktop,
223+
delay: const Duration(milliseconds: 1200),
224+
whileFutureAlt: _future,
225+
onException: (e) => ex = e,
226+
);
227+
228+
if (context.mounted) {
229+
if (ex != null) {
230+
await showDialog<void>(
231+
context: context,
232+
builder: (context) => StackOkDialog(
233+
title: "Error",
234+
message: ex
235+
.toString()
236+
.replaceFirst("Exception:", "")
237+
.trim(),
238+
),
239+
);
240+
} else {
241+
Navigator.of(context).pop((
242+
walletId: widget.walletId,
243+
address: sparkAddress,
244+
walletName:
245+
"${ref.read(pWalletName(widget.walletId))} (Spark)",
246+
));
247+
}
248+
}
249+
},
250+
child: Row(
251+
crossAxisAlignment: .center,
252+
mainAxisAlignment: .spaceBetween,
253+
children: [
254+
Column(
255+
mainAxisSize: .min,
256+
crossAxisAlignment: .start,
257+
children: [
258+
Text("Spark address", style: STextStyles.w500_12(context)),
259+
const SizedBox(height: 2),
260+
WalletInfoRowBalance(
261+
walletId: widget.walletId,
262+
balanceType: .private,
263+
),
264+
],
265+
),
266+
SizedBox(
267+
width: 25,
268+
height: 25,
269+
child: SvgPicture.asset(
270+
Assets.svg.chevronRight,
271+
colorFilter: ColorFilter.mode(
272+
Theme.of(context).extension<StackColors>()!.textDark,
273+
BlendMode.srcIn,
274+
),
275+
),
276+
),
277+
],
278+
),
279+
),
280+
const SizedBox(height: 8),
281+
RawMaterialButton(
282+
splashColor: Theme.of(context).extension<StackColors>()!.highlight,
283+
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
284+
shape: RoundedRectangleBorder(
285+
borderRadius: BorderRadius.circular(
286+
Constants.size.circularBorderRadius,
287+
),
288+
),
289+
padding: const EdgeInsets.all(0),
290+
elevation: 0,
291+
onPressed: () async {
292+
final wallet = ref.read(pWallets).getWallet(widget.walletId);
293+
294+
final data = (
295+
walletId: widget.walletId,
296+
address:
297+
(await wallet.getCurrentReceivingAddress())?.value ??
298+
wallet.info.cachedReceivingAddress,
299+
walletName: "${wallet.info.name} (Transparent)",
300+
);
301+
302+
if (context.mounted) {
303+
Navigator.of(context).pop(data);
304+
}
305+
},
306+
307+
child: Row(
308+
crossAxisAlignment: .center,
309+
mainAxisAlignment: .spaceBetween,
310+
children: [
311+
Column(
312+
mainAxisSize: .min,
313+
crossAxisAlignment: .start,
314+
children: [
315+
Text(
316+
"Transparent address",
317+
style: STextStyles.w500_12(context),
318+
),
319+
const SizedBox(height: 2),
320+
WalletInfoRowBalance(
321+
walletId: widget.walletId,
322+
balanceType: .public,
323+
),
324+
],
325+
),
326+
SizedBox(
327+
width: 25,
328+
height: 25,
329+
child: SvgPicture.asset(
330+
Assets.svg.chevronRight,
331+
colorFilter: ColorFilter.mode(
332+
Theme.of(context).extension<StackColors>()!.textDark,
333+
BlendMode.srcIn,
334+
),
335+
),
336+
),
337+
],
338+
),
339+
),
340+
],
341+
),
342+
);
343+
}
344+
}

0 commit comments

Comments
 (0)