CW-319-Wallet-Seed-keys-URI-QR-code (#831)
* wallet QR code on Wallet/Seed screen * fix restore height for new wallet * fix height parameter * fix currenHeight and HeightByDate for haven * update configure.dart * fix coments * minor fix
Serhii committed
Mar 15, 2023 at 17:30 UTC
fc2627df38178fcb7d4ac769e859b6227cb63868
5 files changed
+410
-255
cw_core/lib/get_height_by_date.dart
+86
-1
@@ -1,4 +1,6 @@
1
import 'package:intl/intl.dart';
2
+import 'dart:convert';
3
+import 'package:http/http.dart' as http;
4
5
// FIXME: Hardcoded values; Works only for monero
6
@@ -93,7 +95,7 @@ int getMoneroHeigthByDate({required DateTime date}) {
95
int height = 0;
96
97
try {
96
- if ((dates[raw] == null)||(dates[raw] == lastHeight)) {
98
+ if ((dates[raw] == null) || (dates[raw] == lastHeight)) {
99
startHeight = dates.values.toList()[dates.length - 2];
100
endHeight = dates.values.toList()[dates.length - 1];
101
final heightPerDay = (endHeight - startHeight) / 31;
@@ -118,3 +120,86 @@ int getMoneroHeigthByDate({required DateTime date}) {
120
121
return height;
122
}
123
+
124
+const havenDates = {
125
+ "2023-03": 1309180,
126
+ "2023-01": 1266810,
127
+ "2022-12": 1244510,
128
+ "2022-11": 1222970,
129
+ "2022-10": 1200700,
130
+ "2022-09": 1179140,
131
+ "2022-08": 1156870,
132
+ "2022-07": 1134600,
133
+ "2022-06": 1113030,
134
+ "2022-05": 1090800,
135
+ "2022-04": 1069250,
136
+ "2022-03": 1047000,
137
+ "2022-02": 1026960,
138
+ "2022-01": 1004700,
139
+ "2021-12": 982400,
140
+ "2021-11": 961000,
141
+ "2021-10": 938600,
142
+ "2021-09": 917000,
143
+ "2021-08": 894800,
144
+ "2021-07": 886000,
145
+ "2021-06": 867300,
146
+ "2021-05": 845000,
147
+ "2021-04": 823500,
148
+ "2021-03": 801500,
149
+ "2021-02": 781000,
150
+ "2021-01": 759000,
151
+ "2020-12": 736500,
152
+ "2020-11": 715000,
153
+ "2020-10": 693000,
154
+ "2020-09": 671000,
155
+ "2020-08": 649000,
156
+ "2020-07": 626600,
157
+ "2020-06": 605000,
158
+ "2020-05": 582700,
159
+ "2020-04": 561100,
160
+ "2020-03": 539000,
161
+ "2020-02": 518000,
162
+ "2020-01": 496000,
163
+ "2019-12": 473400,
164
+ "2019-11": 451900,
165
+ "2019-10": 429600,
166
+ "2019-09": 408000,
167
+ "2019-08": 385700,
168
+ "2019-07": 363800,
169
+ "2019-06": 342200,
170
+ "2019-05": 320000,
171
+ "2019-04": 298400,
172
+ "2019-03": 276000,
173
+ "2019-02": 256000,
174
+ "2019-01": 233700,
175
+ "2018-12": 211400,
176
+ "2018-11": 189800,
177
+ "2018-10": 167500,
178
+ "2018-09": 145900,
179
+ "2018-08": 123700,
180
+ "2018-07": 101400,
181
+ "2018-06": 80000,
182
+ "2018-05": 57550,
183
+ "2018-04": 32000,
184
+ "2018-03": 8500
185
+};
186
+
187
+DateTime formatMapKey(String key) => dateFormat.parse(key);
188
+
189
+int getHavenHeightByDate({required DateTime date}) {
190
+ String closestKey =
191
+ havenDates.keys.firstWhere((key) => formatMapKey(key).isBefore(date), orElse: () => '');
192
+
193
+ return havenDates[closestKey] ?? 0;
194
+}
195
+
196
+Future<int> getHavenCurrentHeight() async {
197
+ final response = await http.get(Uri.parse('https://explorer.havenprotocol.org/api/networkinfo'));
198
+
199
+ if (response.statusCode == 200) {
200
+ final info = jsonDecode(response.body);
201
+ return info['data']['height'] as int;
202
+ } else {
203
+ throw Exception('Failed to load current blockchain height');
204
+ }
205
+}
lib/haven/cw_haven.dart
+236
-251
@@ -1,346 +1,331 @@
1
part of 'haven.dart';
2
3
class CWHavenAccountList extends HavenAccountList {
4
- CWHavenAccountList(this._wallet);
5
- final Object _wallet;
4
+ CWHavenAccountList(this._wallet);
5
7
- @override
8
- @computed
6
+ final Object _wallet;
7
+
8
+ @override
9
+ @computed
10
ObservableList<Account> get accounts {
10
- final havenWallet = _wallet as HavenWallet;
11
- final accounts = havenWallet.walletAddresses.accountList
12
- .accounts
13
- .map((acc) => Account(id: acc.id, label: acc.label))
14
- .toList();
15
- return ObservableList<Account>.of(accounts);
11
+ final havenWallet = _wallet as HavenWallet;
12
+ final accounts = havenWallet.walletAddresses.accountList.accounts
13
+ .map((acc) => Account(id: acc.id, label: acc.label))
14
+ .toList();
15
+ return ObservableList<Account>.of(accounts);
16
}
17
18
@override
19
void update(Object wallet) {
20
- final havenWallet = wallet as HavenWallet;
21
- havenWallet.walletAddresses.accountList.update();
20
+ final havenWallet = wallet as HavenWallet;
21
+ havenWallet.walletAddresses.accountList.update();
22
}
23
24
@override
25
- void refresh(Object wallet) {
26
- final havenWallet = wallet as HavenWallet;
27
- havenWallet.walletAddresses.accountList.refresh();
28
- }
25
+ void refresh(Object wallet) {
26
+ final havenWallet = wallet as HavenWallet;
27
+ havenWallet.walletAddresses.accountList.refresh();
28
+ }
29
30
- @override
30
+ @override
31
List<Account> getAll(Object wallet) {
32
- final havenWallet = wallet as HavenWallet;
33
- return havenWallet.walletAddresses.accountList
34
- .getAll()
35
- .map((acc) => Account(id: acc.id, label: acc.label))
36
- .toList();
32
+ final havenWallet = wallet as HavenWallet;
33
+ return havenWallet.walletAddresses.accountList
34
+ .getAll()
35
+ .map((acc) => Account(id: acc.id, label: acc.label))
36
+ .toList();
37
}
38
39
@override
40
Future<void> addAccount(Object wallet, {required String label}) async {
41
- final havenWallet = wallet as HavenWallet;
42
- await havenWallet.walletAddresses.accountList.addAccount(label: label);
41
+ final havenWallet = wallet as HavenWallet;
42
+ await havenWallet.walletAddresses.accountList.addAccount(label: label);
43
}
44
45
@override
46
- Future<void> setLabelAccount(Object wallet, {required int accountIndex, required String label}) async {
47
- final havenWallet = wallet as HavenWallet;
48
- await havenWallet.walletAddresses.accountList
49
- .setLabelAccount(
50
- accountIndex: accountIndex,
51
- label: label);
46
+ Future<void> setLabelAccount(Object wallet,
47
+ {required int accountIndex, required String label}) async {
48
+ final havenWallet = wallet as HavenWallet;
49
+ await havenWallet.walletAddresses.accountList
50
+ .setLabelAccount(accountIndex: accountIndex, label: label);
51
}
52
}
53
54
class CWHavenSubaddressList extends MoneroSubaddressList {
56
- CWHavenSubaddressList(this._wallet);
57
- final Object _wallet;
55
+ CWHavenSubaddressList(this._wallet);
56
+
57
+ final Object _wallet;
58
59
- @override
60
- @computed
59
+ @override
60
+ @computed
61
ObservableList<Subaddress> get subaddresses {
62
- final havenWallet = _wallet as HavenWallet;
63
- final subAddresses = havenWallet.walletAddresses.subaddressList
64
- .subaddresses
65
- .map((sub) => Subaddress(
66
- id: sub.id,
67
- address: sub.address,
68
- label: sub.label))
69
- .toList();
70
- return ObservableList<Subaddress>.of(subAddresses);
62
+ final havenWallet = _wallet as HavenWallet;
63
+ final subAddresses = havenWallet.walletAddresses.subaddressList.subaddresses
64
+ .map((sub) => Subaddress(id: sub.id, address: sub.address, label: sub.label))
65
+ .toList();
66
+ return ObservableList<Subaddress>.of(subAddresses);
67
}
68
69
@override
70
void update(Object wallet, {required int accountIndex}) {
75
- final havenWallet = wallet as HavenWallet;
76
- havenWallet.walletAddresses.subaddressList.update(accountIndex: accountIndex);
71
+ final havenWallet = wallet as HavenWallet;
72
+ havenWallet.walletAddresses.subaddressList.update(accountIndex: accountIndex);
73
}
74
75
@override
76
void refresh(Object wallet, {required int accountIndex}) {
81
- final havenWallet = wallet as HavenWallet;
82
- havenWallet.walletAddresses.subaddressList.refresh(accountIndex: accountIndex);
77
+ final havenWallet = wallet as HavenWallet;
78
+ havenWallet.walletAddresses.subaddressList.refresh(accountIndex: accountIndex);
79
}
80
81
@override
82
List<Subaddress> getAll(Object wallet) {
87
- final havenWallet = wallet as HavenWallet;
88
- return havenWallet.walletAddresses
89
- .subaddressList
90
- .getAll()
91
- .map((sub) => Subaddress(id: sub.id, label: sub.label, address: sub.address))
92
- .toList();
83
+ final havenWallet = wallet as HavenWallet;
84
+ return havenWallet.walletAddresses.subaddressList
85
+ .getAll()
86
+ .map((sub) => Subaddress(id: sub.id, label: sub.label, address: sub.address))
87
+ .toList();
88
}
89
90
@override
96
- Future<void> addSubaddress(Object wallet, {required int accountIndex, required String label}) async {
97
- final havenWallet = wallet as HavenWallet;
98
- await havenWallet.walletAddresses.subaddressList
99
- .addSubaddress(
100
- accountIndex: accountIndex,
101
- label: label);
91
+ Future<void> addSubaddress(Object wallet,
92
+ {required int accountIndex, required String label}) async {
93
+ final havenWallet = wallet as HavenWallet;
94
+ await havenWallet.walletAddresses.subaddressList
95
+ .addSubaddress(accountIndex: accountIndex, label: label);
96
}
97
98
@override
99
Future<void> setLabelSubaddress(Object wallet,
100
{required int accountIndex, required int addressIndex, required String label}) async {
107
- final havenWallet = wallet as HavenWallet;
108
- await havenWallet.walletAddresses.subaddressList
109
- .setLabelSubaddress(
110
- accountIndex: accountIndex,
111
- addressIndex: addressIndex,
112
- label: label);
101
+ final havenWallet = wallet as HavenWallet;
102
+ await havenWallet.walletAddresses.subaddressList
103
+ .setLabelSubaddress(accountIndex: accountIndex, addressIndex: addressIndex, label: label);
104
}
105
}
106
107
class CWHavenWalletDetails extends HavenWalletDetails {
117
- CWHavenWalletDetails(this._wallet);
118
- final Object _wallet;
108
+ CWHavenWalletDetails(this._wallet);
109
120
- @computed
110
+ final Object _wallet;
111
+
112
+ @computed
113
@override
114
Account get account {
123
- final havenWallet = _wallet as HavenWallet;
124
- final acc = havenWallet.walletAddresses.account as monero_account.Account;
125
- return Account(id: acc.id, label: acc.label);
115
+ final havenWallet = _wallet as HavenWallet;
116
+ final acc = havenWallet.walletAddresses.account as monero_account.Account;
117
+ return Account(id: acc.id, label: acc.label);
118
}
119
120
@computed
121
@override
130
- HavenBalance get balance {
131
- final havenWallet = _wallet as HavenWallet;
132
- final balance = havenWallet.balance;
133
- throw Exception('Unimplemented');
134
- //return HavenBalance(
135
- // fullBalance: balance.fullBalance,
136
- // unlockedBalance: balance.unlockedBalance);
137
- }
122
+ HavenBalance get balance {
123
+ final havenWallet = _wallet as HavenWallet;
124
+ final balance = havenWallet.balance;
125
+ throw Exception('Unimplemented');
126
+ //return HavenBalance(
127
+ // fullBalance: balance.fullBalance,
128
+ // unlockedBalance: balance.unlockedBalance);
129
+ }
130
}
131
132
class CWHaven extends Haven {
133
@override
134
HavenAccountList getAccountList(Object wallet) {
143
- return CWHavenAccountList(wallet);
144
- }
145
-
146
- @override
147
- MoneroSubaddressList getSubaddressList(Object wallet) {
148
- return CWHavenSubaddressList(wallet);
149
- }
150
-
151
- @override
152
- TransactionHistoryBase getTransactionHistory(Object wallet) {
153
- final havenWallet = wallet as HavenWallet;
154
- return havenWallet.transactionHistory;
155
- }
156
-
157
- @override
158
- HavenWalletDetails getMoneroWalletDetails(Object wallet) {
159
- return CWHavenWalletDetails(wallet);
160
- }
161
-
162
- @override
163
- int getHeigthByDate({required DateTime date}) {
164
- return getMoneroHeigthByDate(date: date);
165
- }
166
-
167
- @override
168
- TransactionPriority getDefaultTransactionPriority() {
169
- return MoneroTransactionPriority.automatic;
170
- }
171
-
172
- @override
173
- TransactionPriority deserializeMoneroTransactionPriority({required int raw}) {
174
- return MoneroTransactionPriority.deserialize(raw: raw);
175
- }
176
-
177
- @override
178
- List<TransactionPriority> getTransactionPriorities() {
179
- return MoneroTransactionPriority.all;
180
- }
181
-
182
- @override
183
- List<String> getMoneroWordList(String language) {
184
- switch (language.toLowerCase()) {
185
- case 'english':
186
- return EnglishMnemonics.words;
187
- case 'chinese (simplified)':
188
- return ChineseSimplifiedMnemonics.words;
189
- case 'dutch':
190
- return DutchMnemonics.words;
191
- case 'german':
192
- return GermanMnemonics.words;
193
- case 'japanese':
194
- return JapaneseMnemonics.words;
195
- case 'portuguese':
196
- return PortugueseMnemonics.words;
197
- case 'russian':
198
- return RussianMnemonics.words;
199
- case 'spanish':
200
- return SpanishMnemonics.words;
201
- case 'french':
202
- return FrenchMnemonics.words;
203
- case 'italian':
204
- return ItalianMnemonics.words;
205
- default:
206
- return EnglishMnemonics.words;
207
- }
208
- }
209
-
210
- @override
211
- WalletCredentials createHavenRestoreWalletFromKeysCredentials({
212
- required String name,
135
+ return CWHavenAccountList(wallet);
136
+ }
137
+
138
+ @override
139
+ MoneroSubaddressList getSubaddressList(Object wallet) {
140
+ return CWHavenSubaddressList(wallet);
141
+ }
142
+
143
+ @override
144
+ TransactionHistoryBase getTransactionHistory(Object wallet) {
145
+ final havenWallet = wallet as HavenWallet;
146
+ return havenWallet.transactionHistory;
147
+ }
148
+
149
+ @override
150
+ HavenWalletDetails getMoneroWalletDetails(Object wallet) {
151
+ return CWHavenWalletDetails(wallet);
152
+ }
153
+
154
+ @override
155
+ int getHeightByDate({required DateTime date}) => getHavenHeightByDate(date: date);
156
+
157
+ @override
158
+ Future<int> getCurrentHeight() => getHavenCurrentHeight();
159
+
160
+ @override
161
+ TransactionPriority getDefaultTransactionPriority() {
162
+ return MoneroTransactionPriority.automatic;
163
+ }
164
+
165
+ @override
166
+ TransactionPriority deserializeMoneroTransactionPriority({required int raw}) {
167
+ return MoneroTransactionPriority.deserialize(raw: raw);
168
+ }
169
+
170
+ @override
171
+ List<TransactionPriority> getTransactionPriorities() {
172
+ return MoneroTransactionPriority.all;
173
+ }
174
+
175
+ @override
176
+ List<String> getMoneroWordList(String language) {
177
+ switch (language.toLowerCase()) {
178
+ case 'english':
179
+ return EnglishMnemonics.words;
180
+ case 'chinese (simplified)':
181
+ return ChineseSimplifiedMnemonics.words;
182
+ case 'dutch':
183
+ return DutchMnemonics.words;
184
+ case 'german':
185
+ return GermanMnemonics.words;
186
+ case 'japanese':
187
+ return JapaneseMnemonics.words;
188
+ case 'portuguese':
189
+ return PortugueseMnemonics.words;
190
+ case 'russian':
191
+ return RussianMnemonics.words;
192
+ case 'spanish':
193
+ return SpanishMnemonics.words;
194
+ case 'french':
195
+ return FrenchMnemonics.words;
196
+ case 'italian':
197
+ return ItalianMnemonics.words;
198
+ default:
199
+ return EnglishMnemonics.words;
200
+ }
201
+ }
202
+
203
+ @override
204
+ WalletCredentials createHavenRestoreWalletFromKeysCredentials(
205
+ {required String name,
206
required String spendKey,
207
required String viewKey,
208
required String address,
209
required String password,
210
required String language,
211
required int height}) {
219
- return HavenRestoreWalletFromKeysCredentials(
220
- name: name,
221
- spendKey: spendKey,
222
- viewKey: viewKey,
223
- address: address,
224
- password: password,
225
- language: language,
226
- height: height);
227
- }
228
-
229
- @override
230
- WalletCredentials createHavenRestoreWalletFromSeedCredentials({
231
- required String name,
232
- required String password,
233
- required int height,
234
- required String mnemonic}) {
235
- return HavenRestoreWalletFromSeedCredentials(
236
- name: name,
237
- password: password,
238
- height: height,
239
- mnemonic: mnemonic);
240
- }
241
-
242
- @override
243
- WalletCredentials createHavenNewWalletCredentials({
244
- required String name,
245
- required String language,
246
- String? password}) {
247
- return HavenNewWalletCredentials(
248
- name: name,
249
- password: password,
250
- language: language);
251
- }
252
-
253
- @override
254
- Map<String, String> getKeys(Object wallet) {
255
- final havenWallet = wallet as HavenWallet;
256
- final keys = havenWallet.keys;
257
- return <String, String>{
258
- 'privateSpendKey': keys.privateSpendKey,
212
+ return HavenRestoreWalletFromKeysCredentials(
213
+ name: name,
214
+ spendKey: spendKey,
215
+ viewKey: viewKey,
216
+ address: address,
217
+ password: password,
218
+ language: language,
219
+ height: height);
220
+ }
221
+
222
+ @override
223
+ WalletCredentials createHavenRestoreWalletFromSeedCredentials(
224
+ {required String name,
225
+ required String password,
226
+ required int height,
227
+ required String mnemonic}) {
228
+ return HavenRestoreWalletFromSeedCredentials(
229
+ name: name, password: password, height: height, mnemonic: mnemonic);
230
+ }
231
+
232
+ @override
233
+ WalletCredentials createHavenNewWalletCredentials(
234
+ {required String name, required String language, String? password}) {
235
+ return HavenNewWalletCredentials(name: name, password: password, language: language);
236
+ }
237
+
238
+ @override
239
+ Map<String, String> getKeys(Object wallet) {
240
+ final havenWallet = wallet as HavenWallet;
241
+ final keys = havenWallet.keys;
242
+ return <String, String>{
243
+ 'privateSpendKey': keys.privateSpendKey,
244
'privateViewKey': keys.privateViewKey,
245
'publicSpendKey': keys.publicSpendKey,
261
- 'publicViewKey': keys.publicViewKey};
262
- }
246
+ 'publicViewKey': keys.publicViewKey
247
+ };
248
+ }
249
250
@override
265
- Object createHavenTransactionCreationCredentials({
266
- required List<Output> outputs,
267
- required TransactionPriority priority,
268
- required String assetType}) {
269
- return HavenTransactionCreationCredentials(
270
- outputs: outputs.map((out) => OutputInfo(
271
- fiatAmount: out.fiatAmount,
272
- cryptoAmount: out.cryptoAmount,
273
- address: out.address,
274
- note: out.note,
275
- sendAll: out.sendAll,
276
- extractedAddress: out.extractedAddress,
277
- isParsedAddress: out.isParsedAddress,
278
- formattedCryptoAmount: out.formattedCryptoAmount))
279
- .toList(),
280
- priority: priority as MoneroTransactionPriority,
281
- assetType: assetType);
282
- }
251
+ Object createHavenTransactionCreationCredentials(
252
+ {required List<Output> outputs,
253
+ required TransactionPriority priority,
254
+ required String assetType}) {
255
+ return HavenTransactionCreationCredentials(
256
+ outputs: outputs
257
+ .map((out) => OutputInfo(
258
+ fiatAmount: out.fiatAmount,
259
+ cryptoAmount: out.cryptoAmount,
260
+ address: out.address,
261
+ note: out.note,
262
+ sendAll: out.sendAll,
263
+ extractedAddress: out.extractedAddress,
264
+ isParsedAddress: out.isParsedAddress,
265
+ formattedCryptoAmount: out.formattedCryptoAmount))
266
+ .toList(),
267
+ priority: priority as MoneroTransactionPriority,
268
+ assetType: assetType);
269
+ }
270
271
@override
285
- String formatterMoneroAmountToString({required int amount}) {
286
- return moneroAmountToString(amount: amount);
287
- }
288
-
272
+ String formatterMoneroAmountToString({required int amount}) {
273
+ return moneroAmountToString(amount: amount);
274
+ }
275
+
276
@override
290
- double formatterMoneroAmountToDouble({required int amount}) {
291
- return moneroAmountToDouble(amount: amount);
292
- }
277
+ double formatterMoneroAmountToDouble({required int amount}) {
278
+ return moneroAmountToDouble(amount: amount);
279
+ }
280
281
@override
295
- int formatterMoneroParseAmount({required String amount}) {
296
- return moneroParseAmount(amount: amount);
297
- }
282
+ int formatterMoneroParseAmount({required String amount}) {
283
+ return moneroParseAmount(amount: amount);
284
+ }
285
286
@override
300
- Account getCurrentAccount(Object wallet) {
301
- final havenWallet = wallet as HavenWallet;
302
- final acc = havenWallet.walletAddresses.account as monero_account.Account;
303
- return Account(id: acc.id, label: acc.label);
304
- }
287
+ Account getCurrentAccount(Object wallet) {
288
+ final havenWallet = wallet as HavenWallet;
289
+ final acc = havenWallet.walletAddresses.account as monero_account.Account;
290
+ return Account(id: acc.id, label: acc.label);
291
+ }
292
293
@override
307
- void setCurrentAccount(Object wallet, int id, String label) {
308
- final havenWallet = wallet as HavenWallet;
309
- havenWallet.walletAddresses.account = monero_account.Account(id: id, label: label);
310
- }
294
+ void setCurrentAccount(Object wallet, int id, String label) {
295
+ final havenWallet = wallet as HavenWallet;
296
+ havenWallet.walletAddresses.account = monero_account.Account(id: id, label: label);
297
+ }
298
299
@override
313
- void onStartup() {
314
- monero_wallet_api.onStartup();
315
- }
300
+ void onStartup() {
301
+ monero_wallet_api.onStartup();
302
+ }
303
304
@override
318
- int getTransactionInfoAccountId(TransactionInfo tx) {
319
- final havenTransactionInfo = tx as HavenTransactionInfo;
320
- return havenTransactionInfo.accountIndex;
321
- }
305
+ int getTransactionInfoAccountId(TransactionInfo tx) {
306
+ final havenTransactionInfo = tx as HavenTransactionInfo;
307
+ return havenTransactionInfo.accountIndex;
308
+ }
309
310
@override
324
- WalletService createHavenWalletService(Box<WalletInfo> walletInfoSource) {
325
- return HavenWalletService(walletInfoSource);
326
- }
311
+ WalletService createHavenWalletService(Box<WalletInfo> walletInfoSource) {
312
+ return HavenWalletService(walletInfoSource);
313
+ }
314
315
@override
329
- String getTransactionAddress(Object wallet, int accountIndex, int addressIndex) {
330
- final havenWallet = wallet as HavenWallet;
331
- return havenWallet.getTransactionAddress(accountIndex, addressIndex);
332
- }
316
+ String getTransactionAddress(Object wallet, int accountIndex, int addressIndex) {
317
+ final havenWallet = wallet as HavenWallet;
318
+ return havenWallet.getTransactionAddress(accountIndex, addressIndex);
319
+ }
320
321
@override
335
- CryptoCurrency assetOfTransaction(TransactionInfo tx) {
336
- final transaction = tx as HavenTransactionInfo;
337
- final asset = CryptoCurrency.fromString(transaction.assetType);
338
- return asset;
339
- }
322
+ CryptoCurrency assetOfTransaction(TransactionInfo tx) {
323
+ final transaction = tx as HavenTransactionInfo;
324
+ final asset = CryptoCurrency.fromString(transaction.assetType);
325
+ return asset;
326
+ }
327
328
@override
342
- List<AssetRate> getAssetRate()
343
- => getRate()
344
- .map((rate) => AssetRate(rate.getAssetType(), rate.getRate()))
345
- .toList();
329
+ List<AssetRate> getAssetRate() =>
330
+ getRate().map((rate) => AssetRate(rate.getAssetType(), rate.getRate())).toList();
331
}
lib/src/screens/wallet_keys/wallet_keys_page.dart
+28
@@ -1,6 +1,7 @@
1
import 'package:auto_size_text/auto_size_text.dart';
2
import 'package:cake_wallet/src/widgets/section_divider.dart';
3
import 'package:cake_wallet/utils/show_bar.dart';
4
+import 'package:device_display_brightness/device_display_brightness.dart';
5
import 'package:flutter/material.dart';
6
import 'package:flutter/cupertino.dart';
7
import 'package:flutter/services.dart';
@@ -9,6 +10,7 @@ import 'package:cake_wallet/generated/i18n.dart';
10
import 'package:cake_wallet/src/screens/base_page.dart';
11
import 'package:cake_wallet/src/widgets/list_row.dart';
12
import 'package:cake_wallet/view_model/wallet_keys_view_model.dart';
13
+import 'package:cake_wallet/routes.dart';
14
15
class WalletKeysPage extends BasePage {
16
WalletKeysPage(this.walletKeysViewModel);
@@ -18,6 +20,32 @@ class WalletKeysPage extends BasePage {
20
21
final WalletKeysViewModel walletKeysViewModel;
22
23
+ @override
24
+ Widget trailing(BuildContext context) => IconButton(
25
+ onPressed: () async {
26
+ // Get the current brightness:
27
+ final double brightness = await DeviceDisplayBrightness.getBrightness();
28
+
29
+ // ignore: unawaited_futures
30
+ DeviceDisplayBrightness.setBrightness(1.0);
31
+ await Navigator.pushNamed(
32
+ context,
33
+ Routes.fullscreenQR,
34
+ arguments: {
35
+ 'qrData': (await walletKeysViewModel.url).toString(),
36
+ 'isLight': true,
37
+ },
38
+ );
39
+ // ignore: unawaited_futures
40
+ DeviceDisplayBrightness.setBrightness(brightness);
41
+ },
42
+ splashColor: Colors.transparent,
43
+ highlightColor: Colors.transparent,
44
+ hoverColor: Colors.transparent,
45
+ icon: Image.asset(
46
+ 'assets/images/qr_code_icon.png',
47
+ ));
48
+
49
@override
50
Widget body(BuildContext context) {
51
return Column(
lib/view_model/wallet_keys_view_model.dart
+58
-2
@@ -5,6 +5,7 @@ import 'package:cw_core/wallet_base.dart';
5
import 'package:cake_wallet/src/screens/transaction_details/standart_list_item.dart';
6
import 'package:cake_wallet/monero/monero.dart';
7
import 'package:cake_wallet/haven/haven.dart';
8
+import 'package:cw_monero/api/wallet.dart' as monero_wallet;
9
10
part 'wallet_keys_view_model.g.dart';
11
@@ -15,10 +16,11 @@ abstract class WalletKeysViewModelBase with Store {
16
: title = wallet.type == WalletType.bitcoin || wallet.type == WalletType.litecoin
17
? S.current.wallet_seed
18
: S.current.wallet_keys,
19
+ _wallet = wallet,
20
+ _restoreHeight = wallet.walletInfo.restoreHeight,
21
items = ObservableList<StandartListItem>() {
22
if (wallet.type == WalletType.monero) {
23
final keys = monero!.getKeys(wallet);
21
-
24
items.addAll([
25
if (keys['publicSpendKey'] != null)
26
StandartListItem(title: S.current.spend_key_public, value: keys['publicSpendKey']!),
@@ -34,7 +36,6 @@ abstract class WalletKeysViewModelBase with Store {
36
37
if (wallet.type == WalletType.haven) {
38
final keys = haven!.getKeys(wallet);
37
-
39
items.addAll([
40
if (keys['publicSpendKey'] != null)
41
StandartListItem(title: S.current.spend_key_public, value: keys['publicSpendKey']!),
@@ -58,4 +59,59 @@ abstract class WalletKeysViewModelBase with Store {
59
final ObservableList<StandartListItem> items;
60
61
final String title;
62
+
63
+ final WalletBase _wallet;
64
+
65
+ final int _restoreHeight;
66
+
67
+ Future<int?> currentHeight() async {
68
+ if (_wallet.type == WalletType.haven) {
69
+ return await haven!.getCurrentHeight();
70
+ }
71
+ if (_wallet.type == WalletType.monero) {
72
+ return monero_wallet.getCurrentHeight();
73
+ }
74
+ return null;
75
+ }
76
+
77
+ String get _path {
78
+ switch (_wallet.type) {
79
+ case WalletType.monero:
80
+ return 'monero_wallet:';
81
+ case WalletType.bitcoin:
82
+ return 'bitcoin_wallet:';
83
+ case WalletType.litecoin:
84
+ return 'litecoin_wallet:';
85
+ case WalletType.haven:
86
+ return 'haven_wallet:';
87
+ default:
88
+ throw Exception('Unexpected wallet type: ${_wallet.toString()}');
89
+ }
90
+ }
91
+
92
+ Future<String?> get restoreHeight async {
93
+ if (_restoreHeight != 0) {
94
+ return _restoreHeight.toString();
95
+ }
96
+ final _currentHeight = await currentHeight();
97
+ if (_currentHeight == null) {
98
+ return null;
99
+ }
100
+ return ((_currentHeight / 1000).floor() * 1000).toString();
101
+ }
102
+
103
+ Future<Map<String, String>> get _queryParams async {
104
+ final restoreHeightResult = await restoreHeight;
105
+ return {
106
+ 'seed': _wallet.seed,
107
+ if (restoreHeightResult != null) ...{'height': restoreHeightResult}
108
+ };
109
+ }
110
+
111
+ Future<Uri> get url async {
112
+ return Uri(
113
+ path: _path,
114
+ queryParameters: await _queryParams,
115
+ );
116
+ }
117
}
tool/configure.dart
+2
-1
@@ -402,7 +402,8 @@ abstract class Haven {
402
403
String getTransactionAddress(Object wallet, int accountIndex, int addressIndex);
404
405
- int getHeigthByDate({required DateTime date});
405
+ int getHeightByDate({required DateTime date});
406
+ Future<int> getCurrentHeight();
407
TransactionPriority getDefaultTransactionPriority();
408
TransactionPriority deserializeMoneroTransactionPriority({required int raw});
409
List<TransactionPriority> getTransactionPriorities();