Merge branch 'main' into generic-fixes-ledger-payjoin

This commit is contained in:
Konstantin Ullrich 2025-06-27 14:42:25 +02:00 committed by GitHub
commit 1914ab7f7d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 44 additions and 45 deletions

View file

@ -1,19 +1,16 @@
import 'dart:convert';
import 'dart:typed_data';
import 'package:crypto/crypto.dart';
import 'package:cw_core/crypto_currency.dart';
import 'package:cw_ethereum/deuro/deuro_savings_contract.dart';
import 'package:cw_ethereum/ethereum_wallet.dart';
import 'package:cw_evm/contract/erc20.dart';
import 'package:cw_evm/evm_chain_transaction_priority.dart';
import 'package:cw_evm/pending_evm_chain_transaction.dart';
import 'package:web3dart/crypto.dart';
import 'package:web3dart/web3dart.dart';
const String savingsGatewayAddress =
"0x073493d73258C4BEb6542e8dd3e1b2891C972303";
const String savingsGatewayAddress = "0x073493d73258C4BEb6542e8dd3e1b2891C972303";
const String dEuroAddress = "0xbA3f535bbCcCcA2A154b573Ca6c5A49BAAE0a3ea";
const String frontendCode = "0x00000000000000000000000000000000000000000043616b652057616c6c6574";
class DEuro {
final SavingsGateway _savingsGateway;
@ -35,27 +32,21 @@ class DEuro {
client: client,
);
final frontendCode =
Uint8List.fromList(sha256.convert(utf8.encode("wallet")).bytes);
EthereumAddress get _address =>
EthereumAddress.fromHex(_wallet.walletAddresses.primaryAddress);
EthereumAddress get _address => EthereumAddress.fromHex(_wallet.walletAddresses.primaryAddress);
Future<BigInt> get savingsBalance async =>
(await _savingsGateway.savings(accountOwner: _address)).saved;
Future<BigInt> get accruedInterest =>
_savingsGateway.accruedInterest(accountOwner: _address);
Future<BigInt> get accruedInterest => _savingsGateway.accruedInterest(accountOwner: _address);
Future<BigInt> get interestRate => _savingsGateway.currentRatePPM();
Future<BigInt> get approvedBalance =>
_dEuro.allowance(_address, _savingsGateway.self.address);
Future<BigInt> get approvedBalance => _dEuro.allowance(_address, _savingsGateway.self.address);
Future<PendingEVMChainTransaction> depositSavings(
BigInt amount, EVMChainTransactionPriority priority) async {
final signedTransaction = await _savingsGateway.save(
(amount: amount, frontendCode: frontendCode),
(amount: amount, frontendCode: hexToBytes(frontendCode)),
credentials: _wallet.evmChainPrivateKey,
);
@ -64,12 +55,10 @@ class DEuro {
contractAddress: _savingsGateway.self.address.hexEip55,
receivingAddressHex: _savingsGateway.self.address.hexEip55,
priority: priority,
data: _savingsGateway.self.abi.functions[17]
.encodeCall([amount, frontendCode]),
data: _savingsGateway.self.abi.functions[17].encodeCall([amount, hexToBytes(frontendCode)]),
);
final sendTransaction =
() => _wallet.getWeb3Client()!.sendRawTransaction(signedTransaction);
final sendTransaction = () => _wallet.getWeb3Client()!.sendRawTransaction(signedTransaction);
return PendingEVMChainTransaction(
sendTransaction: sendTransaction,
@ -82,7 +71,7 @@ class DEuro {
Future<PendingEVMChainTransaction> withdrawSavings(
BigInt amount, EVMChainTransactionPriority priority) async {
final signedTransaction = await _savingsGateway.withdraw(
(target: _address, amount: amount, frontendCode: frontendCode),
(target: _address, amount: amount, frontendCode: hexToBytes(frontendCode)),
credentials: _wallet.evmChainPrivateKey,
);
@ -91,12 +80,10 @@ class DEuro {
contractAddress: _savingsGateway.self.address.hexEip55,
receivingAddressHex: _savingsGateway.self.address.hexEip55,
priority: priority,
data: _savingsGateway.self.abi.functions[17]
.encodeCall([amount, frontendCode]),
data: _savingsGateway.self.abi.functions[17].encodeCall([amount, hexToBytes(frontendCode)]),
);
final sendTransaction =
() => _wallet.getWeb3Client()!.sendRawTransaction(signedTransaction);
final sendTransaction = () => _wallet.getWeb3Client()!.sendRawTransaction(signedTransaction);
return PendingEVMChainTransaction(
sendTransaction: sendTransaction,
@ -107,8 +94,7 @@ class DEuro {
}
// Set an infinite approval to save gas in the future
Future<PendingEVMChainTransaction> enableSavings(
EVMChainTransactionPriority priority) async =>
Future<PendingEVMChainTransaction> enableSavings(EVMChainTransactionPriority priority) async =>
(await _wallet.createApprovalTransaction(
BigInt.parse(
'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',

View file

@ -116,12 +116,17 @@ String getSeedLegacy(String? language) {
}
String getPassphrase() {
return currentWallet!.getCacheAttribute(key: "cakewallet.passphrase");
return currentWallet?.getCacheAttribute(key: "cakewallet.passphrase") ?? "";
}
Map<int, Map<int, Map<int, String>>> addressCache = {};
String getAddress({int accountIndex = 0, int addressIndex = 0}) {
// this is a workaround for when we switch the wallet pointer,
// it should never reach UI but should be good enough to prevent gray screen
// or other errors because of forced null check.
if (currentWallet == null) return "<wallet not ready ($accountIndex:$addressIndex)>";
// printV("getaddress: ${accountIndex}/${addressIndex}: ${monero.Wallet_numSubaddresses(wptr!, accountIndex: accountIndex)}: ${monero.Wallet_address(wptr!, accountIndex: accountIndex, addressIndex: addressIndex)}");
// this could be a while loop, but I'm in favor of making it if to not cause freezes
if (currentWallet!.numSubaddresses(accountIndex: accountIndex)-1 < addressIndex) {
@ -272,13 +277,13 @@ void closeCurrentWallet() {
currentWallet!.stop();
}
String getSecretViewKey() => currentWallet!.secretViewKey();
String getSecretViewKey() => currentWallet?.secretViewKey() ?? "";
String getPublicViewKey() => currentWallet!.publicViewKey();
String getPublicViewKey() => currentWallet?.publicViewKey() ?? "";
String getSecretSpendKey() => currentWallet!.secretSpendKey();
String getSecretSpendKey() => currentWallet?.secretSpendKey() ?? "";
String getPublicSpendKey() => currentWallet!.publicSpendKey();
String getPublicSpendKey() => currentWallet?.publicSpendKey() ?? "";
class SyncListener {
SyncListener(this.onNewBlock, this.onNewTransaction)

View file

@ -5,8 +5,7 @@ import 'dart:convert';
import 'package:cake_wallet/.secrets.g.dart' as secrets;
const _fiatApiClearNetAuthority = 'fiat-api.cakewallet.com';
// const _fiatApiOnionAuthority = 'n4z7bdcmwk2oyddxvzaap3x2peqcplh3pzdy7tpkk5ejz5n4mhfvoxqd.onion';
const _fiatApiOnionAuthority = _fiatApiClearNetAuthority;
const _fiatApiOnionAuthority = 'kfkyguqtz5vcnbvar5pjgddkaeawbo4j3r4fj3e22k3tzqageplosiid.onion';
const _fiatApiPath = '/v2/rates';
Future<double> _fetchPrice(String crypto, String fiat, bool torOnly) async {

View file

@ -41,14 +41,18 @@ class UnspentCoinsListPage extends BasePage {
final UnspentCoinsListViewModel unspentCoinsListViewModel;
Future<void> handleOnPopInvoked(BuildContext context) async {
final navigator = Navigator.of(context);
final hasChanged = unspentCoinsListViewModel.hasAdjustableFieldChanged;
if (unspentCoinsListViewModel.items.isEmpty || !hasChanged) {
Navigator.of(context).pop();
} else {
unspentCoinsListViewModel.setIsDisposing(true);
await unspentCoinsListViewModel.dispose();
Navigator.of(context).pop();
if (navigator.canPop()) navigator.pop();
return;
}
unspentCoinsListViewModel.setIsDisposing(true);
await unspentCoinsListViewModel.dispose();
if (navigator.canPop()) navigator.pop();
if (navigator.canPop()) navigator.pop();
}
@override

View file

@ -1123,13 +1123,18 @@ abstract class DashboardViewModelBase with Store {
Future<ServicesResponse> _getServicesStatus() async {
try {
if (isEnabledBulletinAction) {
final uri = Uri.https(
"service-api.cakewallet.com",
"/v1/active-notices",
{'key': secrets.fiatApiKey},
final res = await ProxyWrapper().get(
clearnetUri: Uri.https(
"service-api.cakewallet.com",
"/v1/active-notices",
{'key': secrets.fiatApiKey},
),
onionUri: Uri.http(
"jpirgl4lrwzjgdqj2nsv3g7twhp2efzty5d3cnypktyczzqfc5qcwwyd.onion",
"/v1/active-notices",
{'key': secrets.fiatApiKey},
),
);
final res = await ProxyWrapper().get(clearnetUri: uri);
if (res.statusCode < 200 || res.statusCode >= 300) {
throw res.body;
}