mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-11-12 08:53:57 +01:00
Cleanup and Bug fixes
This commit is contained in:
@@ -629,7 +629,7 @@ class ExchangePage extends BasePage {
|
||||
|
||||
void _onCurrencyChange(CryptoCurrency currency, ExchangeViewModel exchangeViewModel,
|
||||
GlobalKey<ExchangeCardState> key) {
|
||||
final isCurrentTypeWallet = currency == exchangeViewModel.wallet.currency;
|
||||
final isCurrentTypeWallet = exchangeViewModel.isDepositSameCurrency;
|
||||
|
||||
key.currentState!.changeSelectedCurrency(currency);
|
||||
key.currentState!.changeWalletName(isCurrentTypeWallet ? exchangeViewModel.wallet.name : '');
|
||||
@@ -708,22 +708,6 @@ class ExchangePage extends BasePage {
|
||||
isMoneroWallet: exchangeViewModel.isMoneroWallet,
|
||||
currencies: exchangeViewModel.depositCurrencies,
|
||||
onCurrencySelected: (currency) {
|
||||
// FIXME: need to move it into view model
|
||||
if (currency == CryptoCurrency.xmr &&
|
||||
exchangeViewModel.wallet.type != WalletType.monero) {
|
||||
showPopUp<void>(
|
||||
context: context,
|
||||
builder: (dialogContext) {
|
||||
return AlertWithOneAction(
|
||||
alertTitle: S.of(context).error,
|
||||
alertContent: S.of(context).exchange_incorrect_current_wallet_for_xmr,
|
||||
buttonText: S.of(context).ok,
|
||||
buttonAction: () => Navigator.of(dialogContext).pop(),
|
||||
);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
exchangeViewModel.changeDepositCurrency(currency: currency);
|
||||
},
|
||||
currencyButtonColor: Colors.transparent,
|
||||
|
||||
@@ -243,7 +243,9 @@ class SendCardState extends State<SendCard> with AutomaticKeepAliveClientMixin<S
|
||||
PaymentRequest paymentRequest,
|
||||
PaymentFlowResult result,
|
||||
) async {
|
||||
Navigator.of(context).pop();
|
||||
if (context.mounted && Navigator.of(context).canPop()) {
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
|
||||
if (result.wallet != null) {
|
||||
walletSwitcherViewModel.selectWallet(result.wallet!);
|
||||
|
||||
@@ -150,12 +150,11 @@ abstract class ExchangeViewModelBase extends WalletChangeListenerViewModel with
|
||||
}
|
||||
});
|
||||
|
||||
isDepositAddressEnabled = !(depositCurrency == wallet.currency);
|
||||
isDepositAddressEnabled = !(isDepositSameCurrency);
|
||||
depositAmount = '';
|
||||
receiveAmount = '';
|
||||
receiveAddress = '';
|
||||
depositAddress =
|
||||
depositCurrency == wallet.currency ? wallet.walletAddresses.addressForExchange : '';
|
||||
depositAddress = isDepositSameCurrency ? wallet.walletAddresses.addressForExchange : '';
|
||||
|
||||
provider = providerList.firstOrNull;
|
||||
final initialProvider = provider;
|
||||
@@ -190,6 +189,11 @@ abstract class ExchangeViewModelBase extends WalletChangeListenerViewModel with
|
||||
}
|
||||
}
|
||||
|
||||
bool get isDepositSameCurrency =>
|
||||
depositCurrency == wallet.currency ||
|
||||
depositCurrency.tag == wallet.currency.tag ||
|
||||
depositCurrency.tag == wallet.currency.title;
|
||||
|
||||
bool get isElectrumWallet => [
|
||||
WalletType.bitcoin,
|
||||
WalletType.litecoin,
|
||||
@@ -412,10 +416,16 @@ abstract class ExchangeViewModelBase extends WalletChangeListenerViewModel with
|
||||
|
||||
@action
|
||||
void changeDepositCurrency({required CryptoCurrency currency}) {
|
||||
print("@@@@@@@@");
|
||||
print(currency);
|
||||
print(currency.tag);
|
||||
print(currency.title);
|
||||
print(wallet.currency.tag);
|
||||
print(wallet.currency.title);
|
||||
depositCurrency = currency;
|
||||
isFixedRateMode = false;
|
||||
_onPairChange();
|
||||
isDepositAddressEnabled = !(depositCurrency == wallet.currency);
|
||||
isDepositAddressEnabled = !(isDepositSameCurrency);
|
||||
}
|
||||
|
||||
@action
|
||||
@@ -423,7 +433,7 @@ abstract class ExchangeViewModelBase extends WalletChangeListenerViewModel with
|
||||
receiveCurrency = currency;
|
||||
isFixedRateMode = false;
|
||||
_onPairChange();
|
||||
isDepositAddressEnabled = !(depositCurrency == wallet.currency);
|
||||
isDepositAddressEnabled = !(isDepositSameCurrency);
|
||||
}
|
||||
|
||||
@action
|
||||
@@ -534,12 +544,11 @@ abstract class ExchangeViewModelBase extends WalletChangeListenerViewModel with
|
||||
_providers.map(
|
||||
(element) => element
|
||||
.fetchRate(
|
||||
from: depositCurrency,
|
||||
to: receiveCurrency,
|
||||
amount: amount,
|
||||
isFixedRateMode: isFixedRateMode,
|
||||
isReceiveAmount: isFixedRateMode
|
||||
)
|
||||
from: depositCurrency,
|
||||
to: receiveCurrency,
|
||||
amount: amount,
|
||||
isFixedRateMode: isFixedRateMode,
|
||||
isReceiveAmount: isFixedRateMode)
|
||||
.timeout(
|
||||
Duration(seconds: 7),
|
||||
onTimeout: () => 0.0,
|
||||
|
||||
@@ -730,46 +730,85 @@ abstract class SendViewModelBase extends WalletChangeListenerViewModel with Stor
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _handleOcpRequest() async {
|
||||
if (OpenCryptoPayService.requiresClientCommit(selectedCryptoCurrency)) {
|
||||
await pendingTransaction!.commit();
|
||||
}
|
||||
|
||||
await _ocpService.commitOpenCryptoPayRequest(
|
||||
pendingTransaction!.hex,
|
||||
txId: pendingTransaction!.id,
|
||||
request: ocpRequest!,
|
||||
asset: selectedCryptoCurrency,
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _commitApprovalTransaction() async {
|
||||
if (_pendingApprovalTx != null) {
|
||||
await _pendingApprovalTx!.commit();
|
||||
_pendingApprovalTx = null;
|
||||
// Small pause to ensure allowance is indexed
|
||||
await Future.delayed(const Duration(milliseconds: 300));
|
||||
}
|
||||
|
||||
await pendingTransaction!.commit();
|
||||
_isSwapsXYZCallDataTx = false;
|
||||
}
|
||||
|
||||
Future<void> _commitUR(BuildContext context) async {
|
||||
final urstr = await pendingTransaction!.commitUR();
|
||||
final result = await Navigator.of(context).pushNamed(Routes.urqrAnimatedPage, arguments: urstr);
|
||||
if (result == null) {
|
||||
throw "Canceled by user";
|
||||
}
|
||||
}
|
||||
|
||||
@action
|
||||
Future<void> commitTransaction(BuildContext context) async {
|
||||
if (pendingTransaction == null) {
|
||||
throw Exception("Pending transaction doesn't exist. It should not be happened.");
|
||||
}
|
||||
|
||||
if (ocpRequest != null) {
|
||||
try {
|
||||
state = TransactionCommitting();
|
||||
if (OpenCryptoPayService.requiresClientCommit(selectedCryptoCurrency)) {
|
||||
|
||||
if (ocpRequest != null) {
|
||||
await _handleOcpRequest();
|
||||
} else if (_isSwapsXYZCallDataTx) {
|
||||
// Swaps.xyz approval (if any), then commit the prebuilt router tx
|
||||
await _commitApprovalTransaction();
|
||||
} else if (pendingTransaction!.shouldCommitUR()) {
|
||||
await _commitUR(context);
|
||||
} else {
|
||||
await pendingTransaction!.commit();
|
||||
}
|
||||
|
||||
await _ocpService.commitOpenCryptoPayRequest(
|
||||
pendingTransaction!.hex,
|
||||
txId: pendingTransaction!.id,
|
||||
request: ocpRequest!,
|
||||
asset: selectedCryptoCurrency,
|
||||
);
|
||||
|
||||
state = TransactionCommitted();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Swaps.xyz approval (if any), then commit the prebuilt router tx
|
||||
if (_isSwapsXYZCallDataTx) {
|
||||
if (_pendingApprovalTx != null) {
|
||||
await _pendingApprovalTx!.commit();
|
||||
_pendingApprovalTx = null;
|
||||
// Small pause to ensure allowance is indexed
|
||||
await Future.delayed(const Duration(milliseconds: 300));
|
||||
// Immediate transaction update for EVM chains, Solana, Tron, and Nano
|
||||
if (isEVMWallet ||
|
||||
[WalletType.solana, WalletType.tron, WalletType.nano].contains(walletType)) {
|
||||
Future.delayed(Duration(seconds: 4), () async {
|
||||
try {
|
||||
await wallet.updateTransactionsHistory();
|
||||
} catch (e) {
|
||||
printV('Failed to update transactions after send: $e');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
await pendingTransaction!.commit();
|
||||
_isSwapsXYZCallDataTx = false;
|
||||
|
||||
state = TransactionCommitted();
|
||||
return; // skip the regular flow below
|
||||
if (pendingTransaction!.id.isNotEmpty) {
|
||||
_addTransactionDescription();
|
||||
}
|
||||
final sharedPreferences = await SharedPreferences.getInstance();
|
||||
await sharedPreferences.setString(PreferencesKey.backgroundSyncLastTrigger(wallet.name),
|
||||
DateTime.now().add(Duration(minutes: 1)).toIso8601String());
|
||||
} catch (e) {
|
||||
state = FailureState(translateErrorMessage(e, wallet.type, wallet.currency));
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _addTransactionDescription() async {
|
||||
String address = outputs.fold('', (acc, value) {
|
||||
return value.isParsedAddress
|
||||
? '$acc${value.address}\n${value.extractedAddress}\n\n'
|
||||
@@ -782,65 +821,26 @@ abstract class SendViewModelBase extends WalletChangeListenerViewModel with Stor
|
||||
|
||||
note = note.trim();
|
||||
|
||||
try {
|
||||
state = TransactionCommitting();
|
||||
|
||||
if (pendingTransaction!.shouldCommitUR()) {
|
||||
final urstr = await pendingTransaction!.commitUR();
|
||||
final result =
|
||||
await Navigator.of(context).pushNamed(Routes.urqrAnimatedPage, arguments: urstr);
|
||||
if (result == null) {
|
||||
state = FailureState("Canceled by user");
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
await pendingTransaction!.commit();
|
||||
}
|
||||
|
||||
if (walletType == WalletType.nano) {
|
||||
nano!.updateTransactions(wallet);
|
||||
}
|
||||
|
||||
// Immediate transaction update for EVM chains, Solana, and Tron
|
||||
if (isEVMWallet || walletType == WalletType.solana || walletType == WalletType.tron) {
|
||||
Future.delayed(Duration(seconds: 4), () async {
|
||||
try {
|
||||
await wallet.updateTransactionsHistory();
|
||||
} catch (e) {
|
||||
printV('Failed to update transactions after send: $e');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (pendingTransaction!.id.isNotEmpty) {
|
||||
TransactionInfo? tx;
|
||||
if (walletType == WalletType.monero) {
|
||||
await Future.delayed(Duration(milliseconds: 450));
|
||||
await wallet.fetchTransactions();
|
||||
final txhistory = monero!.getTransactionHistory(wallet);
|
||||
tx = txhistory.transactions.values.last;
|
||||
}
|
||||
final descriptionKey = '${pendingTransaction!.id}_${wallet.walletAddresses.primaryAddress}';
|
||||
_settingsStore.shouldSaveRecipientAddress
|
||||
? await transactionDescriptionBox.add(TransactionDescription(
|
||||
id: descriptionKey,
|
||||
recipientAddress: address,
|
||||
transactionNote: note,
|
||||
transactionKey: tx?.additionalInfo["key"] as String?,
|
||||
))
|
||||
: await transactionDescriptionBox.add(TransactionDescription(
|
||||
id: descriptionKey,
|
||||
transactionNote: note,
|
||||
transactionKey: tx?.additionalInfo["key"] as String?,
|
||||
));
|
||||
}
|
||||
final sharedPreferences = await SharedPreferences.getInstance();
|
||||
await sharedPreferences.setString(PreferencesKey.backgroundSyncLastTrigger(wallet.name),
|
||||
DateTime.now().add(Duration(minutes: 1)).toIso8601String());
|
||||
state = TransactionCommitted();
|
||||
} catch (e) {
|
||||
state = FailureState(translateErrorMessage(e, wallet.type, wallet.currency));
|
||||
TransactionInfo? tx;
|
||||
if (walletType == WalletType.monero) {
|
||||
await Future.delayed(Duration(milliseconds: 450));
|
||||
await wallet.fetchTransactions();
|
||||
final txhistory = monero!.getTransactionHistory(wallet);
|
||||
tx = txhistory.transactions.values.last;
|
||||
}
|
||||
final descriptionKey = '${pendingTransaction!.id}_${wallet.walletAddresses.primaryAddress}';
|
||||
_settingsStore.shouldSaveRecipientAddress
|
||||
? await transactionDescriptionBox.add(TransactionDescription(
|
||||
id: descriptionKey,
|
||||
recipientAddress: address,
|
||||
transactionNote: note,
|
||||
transactionKey: tx?.additionalInfo["key"] as String?,
|
||||
))
|
||||
: await transactionDescriptionBox.add(TransactionDescription(
|
||||
id: descriptionKey,
|
||||
transactionNote: note,
|
||||
transactionKey: tx?.additionalInfo["key"] as String?,
|
||||
));
|
||||
}
|
||||
|
||||
Object _credentials([ExchangeProvider? provider]) {
|
||||
|
||||
Reference in New Issue
Block a user