Merge branch 'main' of https://github.com/cake-tech/cake_wallet into CW-434-Prompt-to-update-app

This commit is contained in:
Blazebrain 2023-08-08 11:23:51 +01:00
commit beaac86eb2
4 changed files with 23 additions and 12 deletions

View file

@ -57,7 +57,8 @@ class Erc20Token extends CryptoCurrency with HiveObjectMixin {
static const boxName = 'Erc20Tokens';
@override
bool operator ==(other) => other is Erc20Token && other.contractAddress == contractAddress;
bool operator ==(other) => (other is Erc20Token && other.contractAddress == contractAddress) ||
(other is CryptoCurrency && other.title == title);
@override
int get hashCode => contractAddress.hashCode;

View file

@ -156,15 +156,19 @@ abstract class EthereumWalletBase
final _credentials = credentials as EthereumTransactionCredentials;
final outputs = _credentials.outputs;
final hasMultiDestination = outputs.length > 1;
final _erc20Balance = balance[_credentials.currency]!;
final CryptoCurrency transactionCurrency =
balance.keys.firstWhere((element) => element.title == _credentials.currency.title);
final _erc20Balance = balance[transactionCurrency]!;
BigInt totalAmount = BigInt.zero;
int exponent =
_credentials.currency is Erc20Token ? (_credentials.currency as Erc20Token).decimal : 18;
int exponent = transactionCurrency is Erc20Token ? transactionCurrency.decimal : 18;
num amountToEthereumMultiplier = pow(10, exponent);
// so far this can not be made with Ethereum as Ethereum does not support multiple recipients
if (hasMultiDestination) {
if (outputs.any((item) => item.sendAll || (item.formattedCryptoAmount ?? 0) <= 0)) {
throw EthereumTransactionCreationException(_credentials.currency);
throw EthereumTransactionCreationException(transactionCurrency);
}
final totalOriginalAmount = EthereumFormatter.parseEthereumAmountToDouble(
@ -172,7 +176,7 @@ abstract class EthereumWalletBase
totalAmount = BigInt.from(totalOriginalAmount * amountToEthereumMultiplier);
if (_erc20Balance.balance < totalAmount) {
throw EthereumTransactionCreationException(_credentials.currency);
throw EthereumTransactionCreationException(transactionCurrency);
}
} else {
final output = outputs.first;
@ -185,7 +189,7 @@ abstract class EthereumWalletBase
: BigInt.from(totalOriginalAmount * amountToEthereumMultiplier);
if (_erc20Balance.balance < totalAmount) {
throw EthereumTransactionCreationException(_credentials.currency);
throw EthereumTransactionCreationException(transactionCurrency);
}
}
@ -195,11 +199,10 @@ abstract class EthereumWalletBase
amount: totalAmount.toString(),
gas: _estimatedGas!,
priority: _credentials.priority!,
currency: _credentials.currency,
currency: transactionCurrency,
exponent: exponent,
contractAddress: _credentials.currency is Erc20Token
? (_credentials.currency as Erc20Token).contractAddress
: null,
contractAddress:
transactionCurrency is Erc20Token ? transactionCurrency.contractAddress : null,
);
return pendingEthereumTransaction;

View file

@ -29,7 +29,9 @@ abstract class ExchangeTradeViewModelBase with Store {
required this.sendViewModel})
: trade = tradesStore.trade!,
isSendable = tradesStore.trade!.from == wallet.currency ||
tradesStore.trade!.provider == ExchangeProviderDescription.xmrto,
tradesStore.trade!.provider == ExchangeProviderDescription.xmrto ||
(wallet.currency == CryptoCurrency.eth &&
tradesStore.trade!.from.tag == CryptoCurrency.eth.title),
items = ObservableList<ExchangeTradeItem>() {
switch (trade.provider) {
case ExchangeProviderDescription.xmrto:
@ -103,6 +105,7 @@ abstract class ExchangeTradeViewModelBase with Store {
final output = sendViewModel.outputs.first;
output.address = trade.inputAddress ?? '';
output.setCryptoAmount(trade.amount);
sendViewModel.selectedCryptoCurrency = trade.from;
await sendViewModel.createTransaction();
}

View file

@ -1,4 +1,5 @@
import 'package:cake_wallet/bitcoin/bitcoin.dart';
import 'package:cake_wallet/ethereum/ethereum.dart';
import 'package:cake_wallet/view_model/restore/restore_mode.dart';
import 'package:cake_wallet/view_model/restore/restore_wallet.dart';
import 'package:hive/hive.dart';
@ -80,6 +81,9 @@ abstract class WalletRestorationFromQRVMBase extends WalletCreationVM with Store
case WalletType.litecoin:
return bitcoin!.createBitcoinRestoreWalletFromSeedCredentials(
name: name, mnemonic: restoreWallet.mnemonicSeed ?? '', password: password);
case WalletType.ethereum:
return ethereum!.createEthereumRestoreWalletFromSeedCredentials(
name: name, mnemonic: restoreWallet.mnemonicSeed ?? '', password: password);
default:
throw Exception('Unexpected type: ${type.toString()}');
}