fix: fiat amount when sending all (#1516)
* fix: fiat amount when sending all * possible fix for pending txs workaroudn update * also for wow
cyan committed
Jul 6, 2024 at 15:01 UTC
0335702aa925bd6477cea4db77fe954e835e84e0
6 files changed
+39
-14
cw_monero/lib/api/transaction_history.dart
+5
-5
@@ -18,7 +18,7 @@ String getTxKey(String txId) {
18
monero.TransactionHistory? txhistory;
19
20
void refreshTransactions() {
21
- txhistory = monero.Wallet_history(wptr!);
21
+ txhistory ??= monero.Wallet_history(wptr!);
22
monero.TransactionHistory_refresh(txhistory!);
23
}
24
@@ -27,17 +27,17 @@ int countOfTransactions() => monero.TransactionHistory_count(txhistory!);
27
List<Transaction> getAllTransactions() {
28
List<Transaction> dummyTxs = [];
29
30
- txhistory = monero.Wallet_history(wptr!);
30
+ txhistory ??= monero.Wallet_history(wptr!);
31
monero.TransactionHistory_refresh(txhistory!);
32
int size = countOfTransactions();
33
- final list = List.generate(size, (index) => Transaction(txInfo: monero.TransactionHistory_transaction(txhistory!, index: index)))..addAll(dummyTxs);
33
+ final list = List.generate(size, (index) => Transaction(txInfo: monero.TransactionHistory_transaction(txhistory!, index: index)));
34
35
final accts = monero.Wallet_numSubaddressAccounts(wptr!);
36
for (var i = 0; i < accts; i++) {
37
final fullBalance = monero.Wallet_balance(wptr!, accountIndex: i);
38
final availBalance = monero.Wallet_unlockedBalance(wptr!, accountIndex: i);
39
if (fullBalance > availBalance) {
40
- if (list.where((element) => element.accountIndex == i && element.isConfirmed == false).isNotEmpty) {
40
+ if (list.where((element) => element.accountIndex == i && element.isConfirmed == false).isEmpty) {
41
dummyTxs.add(
42
Transaction.dummy(
43
displayLabel: "",
@@ -50,7 +50,7 @@ List<Transaction> getAllTransactions() {
50
amount: fullBalance - availBalance,
51
isSpend: false,
52
hash: "pending",
53
- key: "pending",
53
+ key: "",
54
txInfo: Pointer.fromAddress(0),
55
)..timeStamp = DateTime.now()
56
);
cw_monero/lib/api/wallet_manager.dart
+9
-1
@@ -6,6 +6,7 @@ import 'package:cw_monero/api/exceptions/wallet_creation_exception.dart';
6
import 'package:cw_monero/api/exceptions/wallet_opening_exception.dart';
7
import 'package:cw_monero/api/exceptions/wallet_restore_from_keys_exception.dart';
8
import 'package:cw_monero/api/exceptions/wallet_restore_from_seed_exception.dart';
9
+import 'package:cw_monero/api/transaction_history.dart';
10
import 'package:cw_monero/api/wallet.dart';
11
import 'package:monero/monero.dart' as monero;
12
@@ -29,6 +30,7 @@ void createWalletSync(
30
required String password,
31
required String language,
32
int nettype = 0}) {
33
+ txhistory = null;
34
wptr = monero.WalletManager_createWallet(wmPtr,
35
path: path, password: password, language: language, networkType: 0);
36
@@ -53,6 +55,7 @@ void restoreWalletFromSeedSync(
55
required String seed,
56
int nettype = 0,
57
int restoreHeight = 0}) {
58
+ txhistory = null;
59
wptr = monero.WalletManager_recoveryWallet(
60
wmPtr,
61
path: path,
@@ -82,6 +85,7 @@ void restoreWalletFromKeysSync(
85
required String spendKey,
86
int nettype = 0,
87
int restoreHeight = 0}) {
88
+ txhistory = null;
89
wptr = monero.WalletManager_createWalletFromKeys(
90
wmPtr,
91
path: path,
@@ -110,6 +114,7 @@ void restoreWalletFromSpendKeySync(
114
required String spendKey,
115
int nettype = 0,
116
int restoreHeight = 0}) {
117
+ // txhistory = null;
118
// wptr = monero.WalletManager_createWalletFromKeys(
119
// wmPtr,
120
// path: path,
@@ -120,7 +125,8 @@ void restoreWalletFromSpendKeySync(
125
// viewKeyString: '',
126
// nettype: 0,
127
// );
123
-
128
+
129
+ txhistory = null;
130
wptr = monero.WalletManager_createDeterministicWalletFromSpendKey(
131
wmPtr,
132
path: path,
@@ -184,6 +190,7 @@ Map<String, monero.wallet> openedWalletsByPath = {};
190
void loadWallet(
191
{required String path, required String password, int nettype = 0}) {
192
if (openedWalletsByPath[path] != null) {
193
+ txhistory = null;
194
wptr = openedWalletsByPath[path]!;
195
return;
196
}
@@ -195,6 +202,7 @@ void loadWallet(
202
monero.Wallet_store(Pointer.fromAddress(addr));
203
});
204
}
205
+ txhistory = null;
206
wptr = monero.WalletManager_openWallet(wmPtr,
207
path: path, password: password);
208
openedWalletsByPath[path] = wptr!;
cw_wownero/lib/api/transaction_history.dart
+4
-4
@@ -17,7 +17,7 @@ String getTxKey(String txId) {
17
wownero.TransactionHistory? txhistory;
18
19
void refreshTransactions() {
20
- txhistory = wownero.Wallet_history(wptr!);
20
+ txhistory ??= wownero.Wallet_history(wptr!);
21
wownero.TransactionHistory_refresh(txhistory!);
22
}
23
@@ -26,17 +26,17 @@ int countOfTransactions() => wownero.TransactionHistory_count(txhistory!);
26
List<Transaction> getAllTransactions() {
27
List<Transaction> dummyTxs = [];
28
29
- txhistory = wownero.Wallet_history(wptr!);
29
+ txhistory ??= wownero.Wallet_history(wptr!);
30
wownero.TransactionHistory_refresh(txhistory!);
31
int size = countOfTransactions();
32
- final list = List.generate(size, (index) => Transaction(txInfo: wownero.TransactionHistory_transaction(txhistory!, index: index)))..addAll(dummyTxs);
32
+ final list = List.generate(size, (index) => Transaction(txInfo: wownero.TransactionHistory_transaction(txhistory!, index: index)));
33
34
final accts = wownero.Wallet_numSubaddressAccounts(wptr!);
35
for (var i = 0; i < accts; i++) {
36
final fullBalance = wownero.Wallet_balance(wptr!, accountIndex: i);
37
final availBalance = wownero.Wallet_unlockedBalance(wptr!, accountIndex: i);
38
if (fullBalance > availBalance) {
39
- if (list.where((element) => element.accountIndex == i && element.isConfirmed == false).isNotEmpty) {
39
+ if (list.where((element) => element.accountIndex == i && element.isConfirmed == false).isEmpty) {
40
dummyTxs.add(
41
Transaction.dummy(
42
displayLabel: "",
cw_wownero/lib/api/wallet_manager.dart
+9
@@ -6,6 +6,7 @@ import 'package:cw_wownero/api/exceptions/wallet_creation_exception.dart';
6
import 'package:cw_wownero/api/exceptions/wallet_opening_exception.dart';
7
import 'package:cw_wownero/api/exceptions/wallet_restore_from_keys_exception.dart';
8
import 'package:cw_wownero/api/exceptions/wallet_restore_from_seed_exception.dart';
9
+import 'package:cw_wownero/api/transaction_history.dart';
10
import 'package:cw_wownero/api/wallet.dart';
11
import 'package:monero/wownero.dart' as wownero;
12
@@ -29,6 +30,7 @@ void createWalletSync(
30
required String password,
31
required String language,
32
int nettype = 0}) {
33
+ txhistory = null;
34
wptr = wownero.WalletManager_createWallet(wmPtr,
35
path: path, password: password, language: language, networkType: 0);
36
@@ -54,6 +56,7 @@ void restoreWalletFromSeedSync(
56
int nettype = 0,
57
int restoreHeight = 0}) {
58
if (seed.split(" ").length == 14) {
59
+ txhistory = null;
60
wptr = wownero.WOWNERO_deprecated_restore14WordSeed(
61
path: path,
62
password: password,
@@ -65,6 +68,7 @@ void restoreWalletFromSeedSync(
68
height: wownero.WOWNERO_deprecated_14WordSeedHeight(seed: seed),
69
);
70
} else {
71
+ txhistory = null;
72
wptr = wownero.WalletManager_recoveryWallet(
73
wmPtr,
74
path: path,
@@ -95,6 +99,7 @@ void restoreWalletFromKeysSync(
99
required String spendKey,
100
int nettype = 0,
101
int restoreHeight = 0}) {
102
+ txhistory = null;
103
wptr = wownero.WalletManager_createWalletFromKeys(
104
wmPtr,
105
path: path,
@@ -123,6 +128,7 @@ void restoreWalletFromSpendKeySync(
128
required String spendKey,
129
int nettype = 0,
130
int restoreHeight = 0}) {
131
+ // txhistory = null;
132
// wptr = wownero.WalletManager_createWalletFromKeys(
133
// wmPtr,
134
// path: path,
@@ -134,6 +140,7 @@ void restoreWalletFromSpendKeySync(
140
// nettype: 0,
141
// );
142
143
+ txhistory = null;
144
wptr = wownero.WalletManager_createDeterministicWalletFromSpendKey(
145
wmPtr,
146
path: path,
@@ -197,6 +204,7 @@ Map<String, wownero.wallet> openedWalletsByPath = {};
204
void loadWallet(
205
{required String path, required String password, int nettype = 0}) {
206
if (openedWalletsByPath[path] != null) {
207
+ txhistory = null;
208
wptr = openedWalletsByPath[path]!;
209
return;
210
}
@@ -208,6 +216,7 @@ void loadWallet(
216
wownero.Wallet_store(Pointer.fromAddress(addr));
217
});
218
}
219
+ txhistory = null;
220
wptr = wownero.WalletManager_openWallet(wmPtr,
221
path: path, password: password);
222
openedWalletsByPath[path] = wptr!;
lib/src/screens/send/widgets/send_card.dart
+3
-1
@@ -332,7 +332,9 @@ class SendCardState extends State<SendCard> with AutomaticKeepAliveClientMixin<S
332
width: prefixIconWidth,
333
height: prefixIconHeight,
334
child: InkWell(
335
- onTap: () async => output.setSendAll(),
335
+ onTap: () async {
336
+ output.setSendAll(sendViewModel.balance);
337
+ },
338
child: Container(
339
decoration: BoxDecoration(
340
color: Theme.of(context)
lib/view_model/send/output.dart
+9
-3
@@ -38,6 +38,7 @@ abstract class OutputBase with Store {
38
key = UniqueKey(),
39
sendAll = false,
40
cryptoAmount = '',
41
+ cryptoFullBalance = '',
42
fiatAmount = '',
43
address = '',
44
note = '',
@@ -54,6 +55,9 @@ abstract class OutputBase with Store {
55
@observable
56
String cryptoAmount;
57
58
+ @observable
59
+ String cryptoFullBalance;
60
+
61
@observable
62
String address;
63
@@ -202,9 +206,11 @@ abstract class OutputBase with Store {
206
final SettingsStore _settingsStore;
207
final FiatConversionStore _fiatConversationStore;
208
final NumberFormat _cryptoNumberFormat;
205
-
209
@action
207
- void setSendAll() => sendAll = true;
210
+ void setSendAll(String fullBalance) {
211
+ cryptoFullBalance = fullBalance;
212
+ sendAll = true;
213
+ }
214
215
@action
216
void reset() {
@@ -243,7 +249,7 @@ abstract class OutputBase with Store {
249
try {
250
final fiat = calculateFiatAmount(
251
price: _fiatConversationStore.prices[cryptoCurrencyHandler()]!,
246
- cryptoAmount: cryptoAmount.replaceAll(',', '.'));
252
+ cryptoAmount: sendAll ? cryptoFullBalance.replaceAll(",", ".") : cryptoAmount.replaceAll(',', '.'));
253
if (fiatAmount != fiat) {
254
fiatAmount = fiat;
255
}