fix: fiat amount when sending all (#1516)
Some checks failed
Cache Dependencies / test (push) Has been cancelled

* fix: fiat amount when sending all

* possible fix for pending txs
workaroudn update

* also for wow
This commit is contained in:
cyan 2024-07-06 15:01:42 +02:00 committed by GitHub
parent c5d3cbf66c
commit 0335702aa9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 39 additions and 14 deletions

View file

@ -18,7 +18,7 @@ String getTxKey(String txId) {
monero.TransactionHistory? txhistory;
void refreshTransactions() {
txhistory = monero.Wallet_history(wptr!);
txhistory ??= monero.Wallet_history(wptr!);
monero.TransactionHistory_refresh(txhistory!);
}
@ -27,17 +27,17 @@ int countOfTransactions() => monero.TransactionHistory_count(txhistory!);
List<Transaction> getAllTransactions() {
List<Transaction> dummyTxs = [];
txhistory = monero.Wallet_history(wptr!);
txhistory ??= monero.Wallet_history(wptr!);
monero.TransactionHistory_refresh(txhistory!);
int size = countOfTransactions();
final list = List.generate(size, (index) => Transaction(txInfo: monero.TransactionHistory_transaction(txhistory!, index: index)))..addAll(dummyTxs);
final list = List.generate(size, (index) => Transaction(txInfo: monero.TransactionHistory_transaction(txhistory!, index: index)));
final accts = monero.Wallet_numSubaddressAccounts(wptr!);
for (var i = 0; i < accts; i++) {
final fullBalance = monero.Wallet_balance(wptr!, accountIndex: i);
final availBalance = monero.Wallet_unlockedBalance(wptr!, accountIndex: i);
if (fullBalance > availBalance) {
if (list.where((element) => element.accountIndex == i && element.isConfirmed == false).isNotEmpty) {
if (list.where((element) => element.accountIndex == i && element.isConfirmed == false).isEmpty) {
dummyTxs.add(
Transaction.dummy(
displayLabel: "",
@ -50,7 +50,7 @@ List<Transaction> getAllTransactions() {
amount: fullBalance - availBalance,
isSpend: false,
hash: "pending",
key: "pending",
key: "",
txInfo: Pointer.fromAddress(0),
)..timeStamp = DateTime.now()
);

View file

@ -6,6 +6,7 @@ import 'package:cw_monero/api/exceptions/wallet_creation_exception.dart';
import 'package:cw_monero/api/exceptions/wallet_opening_exception.dart';
import 'package:cw_monero/api/exceptions/wallet_restore_from_keys_exception.dart';
import 'package:cw_monero/api/exceptions/wallet_restore_from_seed_exception.dart';
import 'package:cw_monero/api/transaction_history.dart';
import 'package:cw_monero/api/wallet.dart';
import 'package:monero/monero.dart' as monero;
@ -29,6 +30,7 @@ void createWalletSync(
required String password,
required String language,
int nettype = 0}) {
txhistory = null;
wptr = monero.WalletManager_createWallet(wmPtr,
path: path, password: password, language: language, networkType: 0);
@ -53,6 +55,7 @@ void restoreWalletFromSeedSync(
required String seed,
int nettype = 0,
int restoreHeight = 0}) {
txhistory = null;
wptr = monero.WalletManager_recoveryWallet(
wmPtr,
path: path,
@ -82,6 +85,7 @@ void restoreWalletFromKeysSync(
required String spendKey,
int nettype = 0,
int restoreHeight = 0}) {
txhistory = null;
wptr = monero.WalletManager_createWalletFromKeys(
wmPtr,
path: path,
@ -110,6 +114,7 @@ void restoreWalletFromSpendKeySync(
required String spendKey,
int nettype = 0,
int restoreHeight = 0}) {
// txhistory = null;
// wptr = monero.WalletManager_createWalletFromKeys(
// wmPtr,
// path: path,
@ -120,7 +125,8 @@ void restoreWalletFromSpendKeySync(
// viewKeyString: '',
// nettype: 0,
// );
txhistory = null;
wptr = monero.WalletManager_createDeterministicWalletFromSpendKey(
wmPtr,
path: path,
@ -184,6 +190,7 @@ Map<String, monero.wallet> openedWalletsByPath = {};
void loadWallet(
{required String path, required String password, int nettype = 0}) {
if (openedWalletsByPath[path] != null) {
txhistory = null;
wptr = openedWalletsByPath[path]!;
return;
}
@ -195,6 +202,7 @@ void loadWallet(
monero.Wallet_store(Pointer.fromAddress(addr));
});
}
txhistory = null;
wptr = monero.WalletManager_openWallet(wmPtr,
path: path, password: password);
openedWalletsByPath[path] = wptr!;

View file

@ -17,7 +17,7 @@ String getTxKey(String txId) {
wownero.TransactionHistory? txhistory;
void refreshTransactions() {
txhistory = wownero.Wallet_history(wptr!);
txhistory ??= wownero.Wallet_history(wptr!);
wownero.TransactionHistory_refresh(txhistory!);
}
@ -26,17 +26,17 @@ int countOfTransactions() => wownero.TransactionHistory_count(txhistory!);
List<Transaction> getAllTransactions() {
List<Transaction> dummyTxs = [];
txhistory = wownero.Wallet_history(wptr!);
txhistory ??= wownero.Wallet_history(wptr!);
wownero.TransactionHistory_refresh(txhistory!);
int size = countOfTransactions();
final list = List.generate(size, (index) => Transaction(txInfo: wownero.TransactionHistory_transaction(txhistory!, index: index)))..addAll(dummyTxs);
final list = List.generate(size, (index) => Transaction(txInfo: wownero.TransactionHistory_transaction(txhistory!, index: index)));
final accts = wownero.Wallet_numSubaddressAccounts(wptr!);
for (var i = 0; i < accts; i++) {
final fullBalance = wownero.Wallet_balance(wptr!, accountIndex: i);
final availBalance = wownero.Wallet_unlockedBalance(wptr!, accountIndex: i);
if (fullBalance > availBalance) {
if (list.where((element) => element.accountIndex == i && element.isConfirmed == false).isNotEmpty) {
if (list.where((element) => element.accountIndex == i && element.isConfirmed == false).isEmpty) {
dummyTxs.add(
Transaction.dummy(
displayLabel: "",

View file

@ -6,6 +6,7 @@ import 'package:cw_wownero/api/exceptions/wallet_creation_exception.dart';
import 'package:cw_wownero/api/exceptions/wallet_opening_exception.dart';
import 'package:cw_wownero/api/exceptions/wallet_restore_from_keys_exception.dart';
import 'package:cw_wownero/api/exceptions/wallet_restore_from_seed_exception.dart';
import 'package:cw_wownero/api/transaction_history.dart';
import 'package:cw_wownero/api/wallet.dart';
import 'package:monero/wownero.dart' as wownero;
@ -29,6 +30,7 @@ void createWalletSync(
required String password,
required String language,
int nettype = 0}) {
txhistory = null;
wptr = wownero.WalletManager_createWallet(wmPtr,
path: path, password: password, language: language, networkType: 0);
@ -54,6 +56,7 @@ void restoreWalletFromSeedSync(
int nettype = 0,
int restoreHeight = 0}) {
if (seed.split(" ").length == 14) {
txhistory = null;
wptr = wownero.WOWNERO_deprecated_restore14WordSeed(
path: path,
password: password,
@ -65,6 +68,7 @@ void restoreWalletFromSeedSync(
height: wownero.WOWNERO_deprecated_14WordSeedHeight(seed: seed),
);
} else {
txhistory = null;
wptr = wownero.WalletManager_recoveryWallet(
wmPtr,
path: path,
@ -95,6 +99,7 @@ void restoreWalletFromKeysSync(
required String spendKey,
int nettype = 0,
int restoreHeight = 0}) {
txhistory = null;
wptr = wownero.WalletManager_createWalletFromKeys(
wmPtr,
path: path,
@ -123,6 +128,7 @@ void restoreWalletFromSpendKeySync(
required String spendKey,
int nettype = 0,
int restoreHeight = 0}) {
// txhistory = null;
// wptr = wownero.WalletManager_createWalletFromKeys(
// wmPtr,
// path: path,
@ -134,6 +140,7 @@ void restoreWalletFromSpendKeySync(
// nettype: 0,
// );
txhistory = null;
wptr = wownero.WalletManager_createDeterministicWalletFromSpendKey(
wmPtr,
path: path,
@ -197,6 +204,7 @@ Map<String, wownero.wallet> openedWalletsByPath = {};
void loadWallet(
{required String path, required String password, int nettype = 0}) {
if (openedWalletsByPath[path] != null) {
txhistory = null;
wptr = openedWalletsByPath[path]!;
return;
}
@ -208,6 +216,7 @@ void loadWallet(
wownero.Wallet_store(Pointer.fromAddress(addr));
});
}
txhistory = null;
wptr = wownero.WalletManager_openWallet(wmPtr,
path: path, password: password);
openedWalletsByPath[path] = wptr!;

View file

@ -332,7 +332,9 @@ class SendCardState extends State<SendCard> with AutomaticKeepAliveClientMixin<S
width: prefixIconWidth,
height: prefixIconHeight,
child: InkWell(
onTap: () async => output.setSendAll(),
onTap: () async {
output.setSendAll(sendViewModel.balance);
},
child: Container(
decoration: BoxDecoration(
color: Theme.of(context)

View file

@ -38,6 +38,7 @@ abstract class OutputBase with Store {
key = UniqueKey(),
sendAll = false,
cryptoAmount = '',
cryptoFullBalance = '',
fiatAmount = '',
address = '',
note = '',
@ -54,6 +55,9 @@ abstract class OutputBase with Store {
@observable
String cryptoAmount;
@observable
String cryptoFullBalance;
@observable
String address;
@ -202,9 +206,11 @@ abstract class OutputBase with Store {
final SettingsStore _settingsStore;
final FiatConversionStore _fiatConversationStore;
final NumberFormat _cryptoNumberFormat;
@action
void setSendAll() => sendAll = true;
void setSendAll(String fullBalance) {
cryptoFullBalance = fullBalance;
sendAll = true;
}
@action
void reset() {
@ -243,7 +249,7 @@ abstract class OutputBase with Store {
try {
final fiat = calculateFiatAmount(
price: _fiatConversationStore.prices[cryptoCurrencyHandler()]!,
cryptoAmount: cryptoAmount.replaceAll(',', '.'));
cryptoAmount: sendAll ? cryptoFullBalance.replaceAll(",", ".") : cryptoAmount.replaceAll(',', '.'));
if (fiatAmount != fiat) {
fiatAmount = fiat;
}