1
+import 'package:cake_wallet/anonpay/anonpay_donation_link_info.dart';
2
+import 'package:cake_wallet/entities/preferences_key.dart';
3
+import 'package:cake_wallet/entities/receive_page_option.dart';
4
import 'package:cake_wallet/src/screens/base_page.dart';
5
+import 'package:cake_wallet/src/screens/dashboard/widgets/present_receive_option_picker.dart';
6
import 'package:cake_wallet/src/widgets/alert_with_two_actions.dart';
7
import 'package:cake_wallet/src/widgets/keyboard_done_button.dart';
8
import 'package:cake_wallet/themes/theme_base.dart';
9
import 'package:cake_wallet/utils/share_util.dart';
10
import 'package:cake_wallet/utils/show_pop_up.dart';
11
+import 'package:cake_wallet/view_model/dashboard/receive_option_view_model.dart';
12
import 'package:cake_wallet/view_model/dashboard/dashboard_view_model.dart';
13
import 'package:flutter/material.dart';
14
import 'package:cake_wallet/view_model/wallet_address_list/wallet_address_list_view_model.dart';
18
import 'package:flutter_mobx/flutter_mobx.dart';
19
import 'package:keyboard_actions/keyboard_actions.dart';
20
import 'package:mobx/mobx.dart';
21
+import 'package:shared_preferences/shared_preferences.dart';
22
+import 'package:cake_wallet/di.dart';
23
24
class AddressPage extends BasePage {
25
AddressPage({
26
required this.addressListViewModel,
20
- required this.walletViewModel})
21
- : _cryptoAmountFocus = FocusNode();
27
+ required this.walletViewModel,
28
+ required this.receiveOptionViewModel,
29
+ }) : _cryptoAmountFocus = FocusNode();
30
31
final WalletAddressListViewModel addressListViewModel;
32
final DashboardViewModel walletViewModel;
33
+ final ReceiveOptionViewModel receiveOptionViewModel;
34
35
final FocusNode _cryptoAmountFocus;
36
37
@override
29
- String get title => S.current.receive;
30
-
31
- @override
32
- Color get backgroundLightColor => currentTheme.type == ThemeType.bright
33
- ? Colors.transparent : Colors.white;
38
+ Color get backgroundLightColor =>
39
+ currentTheme.type == ThemeType.bright ? Colors.transparent : Colors.white;
40
41
@override
42
Color get backgroundDarkColor => Colors.transparent;
44
@override
45
bool get resizeToAvoidBottomInset => false;
46
47
+ bool effectsInstalled = false;
48
+
49
@override
50
Widget leading(BuildContext context) {
43
- final _backButton = Icon(Icons.arrow_back_ios,
44
- color: Theme.of(context).accentTextTheme!.headline2!.backgroundColor!,
45
- size: 16,);
51
+ final _backButton = Icon(
52
+ Icons.arrow_back_ios,
53
+ color: Theme.of(context).accentTextTheme.headline2!.backgroundColor!,
54
+ size: 16,
55
+ );
56
57
return SizedBox(
58
height: 37,
71
}
72
73
@override
64
- Widget middle(BuildContext context) {
65
- return Text(
66
- title,
67
- style: TextStyle(
68
- fontSize: 18.0,
69
- fontWeight: FontWeight.bold,
70
- fontFamily: 'Lato',
71
- color: Theme.of(context).accentTextTheme!.headline2!.backgroundColor!),
72
- );
73
- }
74
+ Widget middle(BuildContext context) =>
75
+ PresentReceiveOptionPicker(receiveOptionViewModel: receiveOptionViewModel);
76
77
@override
78
Widget Function(BuildContext, Widget) get rootWrapper =>
87
88
@override
89
Widget? trailing(BuildContext context) {
88
- final shareImage =
89
- Image.asset('assets/images/share.png',
90
+ final shareImage = Image.asset('assets/images/share.png',
91
color: Theme.of(context).accentTextTheme!.headline2!.backgroundColor!);
92
92
- return !addressListViewModel.hasAddressList ? Material(
93
- color: Colors.transparent,
94
- child: IconButton(
95
- padding: EdgeInsets.zero,
96
- constraints: BoxConstraints(),
97
- highlightColor: Colors.transparent,
98
- splashColor: Colors.transparent,
99
- iconSize: 25,
100
- onPressed: () {
101
- ShareUtil.share(
102
- text: addressListViewModel.address.address,
103
- context: context,
104
- );
105
- },
106
- icon: shareImage,
107
- ),
108
- ) : null;
93
+ return !addressListViewModel.hasAddressList
94
+ ? Material(
95
+ color: Colors.transparent,
96
+ child: IconButton(
97
+ padding: EdgeInsets.zero,
98
+ constraints: BoxConstraints(),
99
+ highlightColor: Colors.transparent,
100
+ splashColor: Colors.transparent,
101
+ iconSize: 25,
102
+ onPressed: () {
103
+ ShareUtil.share(
104
+ text: addressListViewModel.address.address,
105
+ context: context,
106
+ );
107
+ },
108
+ icon: shareImage,
109
+ ),
110
+ )
111
+ : null;
112
}
113
114
@override
115
Widget body(BuildContext context) {
116
+ _setEffects(context);
117
+
118
autorun((_) async {
114
- if (!walletViewModel.isOutdatedElectrumWallet
115
- || !walletViewModel.settingsStore.shouldShowReceiveWarning) {
119
+ if (!walletViewModel.isOutdatedElectrumWallet ||
120
+ !walletViewModel.settingsStore.shouldShowReceiveWarning) {
121
return;
122
}
123
124
await Future<void>.delayed(Duration(seconds: 1));
125
if (context.mounted) {
126
await showPopUp<void>(
122
- context: context,
123
- builder: (BuildContext context) {
124
- return AlertWithTwoActions(
125
- alertTitle: S.of(context).pre_seed_title,
126
- alertContent: S.of(context).outdated_electrum_wallet_receive_warning,
127
- leftButtonText: S.of(context).understand,
128
- actionLeftButton: () => Navigator.of(context).pop(),
129
- rightButtonText: S.of(context).do_not_show_me,
130
- actionRightButton: () {
131
- walletViewModel.settingsStore.setShouldShowReceiveWarning(false);
132
- Navigator.of(context).pop();
133
- });
134
- });
127
+ context: context,
128
+ builder: (BuildContext context) {
129
+ return AlertWithTwoActions(
130
+ alertTitle: S.of(context).pre_seed_title,
131
+ alertContent: S.of(context).outdated_electrum_wallet_receive_warning,
132
+ leftButtonText: S.of(context).understand,
133
+ actionLeftButton: () => Navigator.of(context).pop(),
134
+ rightButtonText: S.of(context).do_not_show_me,
135
+ actionRightButton: () {
136
+ walletViewModel.settingsStore.setShouldShowReceiveWarning(false);
137
+ Navigator.of(context).pop();
138
+ });
139
+ });
140
}
141
});
142
146
tapOutsideToDismiss: true,
147
config: KeyboardActionsConfig(
148
keyboardActionsPlatform: KeyboardActionsPlatform.IOS,
144
- keyboardBarColor:
145
- Theme.of(context).accentTextTheme!.bodyText1!.backgroundColor!,
149
+ keyboardBarColor: Theme.of(context).accentTextTheme.bodyText1!.backgroundColor!,
150
nextFocus: false,
151
actions: [
152
KeyboardActionsItem(
158
padding: EdgeInsets.fromLTRB(24, 24, 24, 32),
159
child: Column(
160
children: <Widget>[
157
- Expanded(
158
- child: Observer(builder: (_) => QRWidget(
159
- addressListViewModel: addressListViewModel,
160
- amountTextFieldFocusNode: _cryptoAmountFocus,
161
- isAmountFieldShow: !addressListViewModel.hasAccounts,
162
- isLight: walletViewModel.settingsStore.currentTheme.type == ThemeType.light))
161
+ Expanded(
162
+ child: Observer(builder: (_) => QRWidget(
163
+ addressListViewModel: addressListViewModel,
164
+ amountTextFieldFocusNode: _cryptoAmountFocus,
165
+ isAmountFieldShow: !addressListViewModel.hasAccounts,
166
+ isLight: walletViewModel.settingsStore.currentTheme.type == ThemeType.light))
167
),
168
Observer(builder: (_) {
169
return addressListViewModel.hasAddressList
170
? GestureDetector(
167
- onTap: () =>
168
- Navigator.of(context).pushNamed(Routes.receive),
171
+ onTap: () => Navigator.of(context).pushNamed(Routes.receive),
172
child: Container(
173
height: 50,
174
padding: EdgeInsets.only(left: 24, right: 12),
175
alignment: Alignment.center,
176
decoration: BoxDecoration(
174
- borderRadius:
175
- BorderRadius.all(Radius.circular(25)),
177
+ borderRadius: BorderRadius.all(Radius.circular(25)),
178
border: Border.all(
177
- color:
178
- Theme.of(context).textTheme!.subtitle1!.color!,
179
- width: 1),
179
+ color: Theme.of(context).textTheme.subtitle1!.color!, width: 1),
180
color: Theme.of(context).buttonColor),
181
child: Row(
182
mainAxisSize: MainAxisSize.max,
185
Observer(
186
builder: (_) => Text(
187
addressListViewModel.hasAccounts
188
- ? S
189
- .of(context)
190
- .accounts_subaddresses
188
+ ? S.of(context).accounts_subaddresses
189
: S.of(context).addresses,
190
style: TextStyle(
191
fontSize: 14,
192
fontWeight: FontWeight.w500,
193
color: Theme.of(context)
196
- .accentTextTheme!
194
+ .accentTextTheme
195
.headline2!
196
.backgroundColor!),
197
)),
198
Icon(
199
Icons.arrow_forward_ios,
200
size: 14,
203
- color: Theme.of(context)
204
- .accentTextTheme!
205
- .headline2!
206
- .backgroundColor!,
201
+ color:
202
+ Theme.of(context).accentTextTheme.headline2!.backgroundColor!,
203
)
204
],
205
),
206
),
207
)
212
- : Text(
213
- S.of(context).electrum_address_disclaimer,
208
+ : Text(S.of(context).electrum_address_disclaimer,
209
textAlign: TextAlign.center,
210
style: TextStyle(
211
fontSize: 15,
217
- color: Theme.of(context)
218
- .accentTextTheme!
219
- .headline3!
220
- .backgroundColor!));
212
+ color: Theme.of(context).accentTextTheme.headline3!.backgroundColor!));
213
})
214
],
215
),
216
));
217
}
218
+
219
+ void _setEffects(BuildContext context) {
220
+ if (effectsInstalled) {
221
+ return;
222
+ }
223
+
224
+ reaction((_) => receiveOptionViewModel.selectedReceiveOption, (ReceivePageOption option) {
225
+ Navigator.pop(context);
226
+ switch (option) {
227
+ case ReceivePageOption.anonPayInvoice:
228
+ Navigator.pushReplacementNamed(
229
+ context,
230
+ Routes.anonPayInvoicePage,
231
+ arguments: [addressListViewModel.address.address, option],
232
+ );
233
+ break;
234
+ case ReceivePageOption.anonPayDonationLink:
235
+ final sharedPreferences = getIt.get<SharedPreferences>();
236
+ final clearnetUrl = sharedPreferences.getString(PreferencesKey.clearnetDonationLink);
237
+ final onionUrl = sharedPreferences.getString(PreferencesKey.onionDonationLink);
238
+
239
+ if (clearnetUrl != null && onionUrl != null) {
240
+ Navigator.pushReplacementNamed(
241
+ context,
242
+ Routes.anonPayReceivePage,
243
+ arguments: AnonpayDonationLinkInfo(
244
+ clearnetUrl: clearnetUrl,
245
+ onionUrl: onionUrl,
246
+ address: addressListViewModel.address.address,
247
+ ),
248
+ );
249
+ } else {
250
+ Navigator.pushReplacementNamed(
251
+ context,
252
+ Routes.anonPayInvoicePage,
253
+ arguments: [addressListViewModel.address.address, option],
254
+ );
255
+ }
256
+ break;
257
+ default:
258
+ }
259
+ });
260
+
261
+ effectsInstalled = true;
262
+ }
263
}