mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-03 09:29:48 +00:00
Enable Eth/Erc20 auto send in exchange (#1024)
* Generate missing secrets file for ethereum * Enable Sending ERC-20 and Ethereum automatically from an Exchange
This commit is contained in:
parent
d1684f5be8
commit
8185b88b4a
5 changed files with 24 additions and 12 deletions
1
.github/workflows/pr_test_build.yml
vendored
1
.github/workflows/pr_test_build.yml
vendored
|
@ -99,6 +99,7 @@ jobs:
|
||||||
run: |
|
run: |
|
||||||
cd /opt/android/cake_wallet
|
cd /opt/android/cake_wallet
|
||||||
touch lib/.secrets.g.dart
|
touch lib/.secrets.g.dart
|
||||||
|
touch cw_ethereum/lib/.secrets.g.dart
|
||||||
echo "const salt = '${{ secrets.SALT }}';" > lib/.secrets.g.dart
|
echo "const salt = '${{ secrets.SALT }}';" > lib/.secrets.g.dart
|
||||||
echo "const keychainSalt = '${{ secrets.KEY_CHAIN_SALT }}';" >> lib/.secrets.g.dart
|
echo "const keychainSalt = '${{ secrets.KEY_CHAIN_SALT }}';" >> lib/.secrets.g.dart
|
||||||
echo "const key = '${{ secrets.KEY }}';" >> lib/.secrets.g.dart
|
echo "const key = '${{ secrets.KEY }}';" >> lib/.secrets.g.dart
|
||||||
|
|
|
@ -57,7 +57,8 @@ class Erc20Token extends CryptoCurrency with HiveObjectMixin {
|
||||||
static const boxName = 'Erc20Tokens';
|
static const boxName = 'Erc20Tokens';
|
||||||
|
|
||||||
@override
|
@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
|
@override
|
||||||
int get hashCode => contractAddress.hashCode;
|
int get hashCode => contractAddress.hashCode;
|
||||||
|
|
|
@ -156,15 +156,19 @@ abstract class EthereumWalletBase
|
||||||
final _credentials = credentials as EthereumTransactionCredentials;
|
final _credentials = credentials as EthereumTransactionCredentials;
|
||||||
final outputs = _credentials.outputs;
|
final outputs = _credentials.outputs;
|
||||||
final hasMultiDestination = outputs.length > 1;
|
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;
|
BigInt totalAmount = BigInt.zero;
|
||||||
int exponent =
|
int exponent = transactionCurrency is Erc20Token ? transactionCurrency.decimal : 18;
|
||||||
_credentials.currency is Erc20Token ? (_credentials.currency as Erc20Token).decimal : 18;
|
|
||||||
num amountToEthereumMultiplier = pow(10, exponent);
|
num amountToEthereumMultiplier = pow(10, exponent);
|
||||||
|
|
||||||
|
// so far this can not be made with Ethereum as Ethereum does not support multiple recipients
|
||||||
if (hasMultiDestination) {
|
if (hasMultiDestination) {
|
||||||
if (outputs.any((item) => item.sendAll || (item.formattedCryptoAmount ?? 0) <= 0)) {
|
if (outputs.any((item) => item.sendAll || (item.formattedCryptoAmount ?? 0) <= 0)) {
|
||||||
throw EthereumTransactionCreationException(_credentials.currency);
|
throw EthereumTransactionCreationException(transactionCurrency);
|
||||||
}
|
}
|
||||||
|
|
||||||
final totalOriginalAmount = EthereumFormatter.parseEthereumAmountToDouble(
|
final totalOriginalAmount = EthereumFormatter.parseEthereumAmountToDouble(
|
||||||
|
@ -172,7 +176,7 @@ abstract class EthereumWalletBase
|
||||||
totalAmount = BigInt.from(totalOriginalAmount * amountToEthereumMultiplier);
|
totalAmount = BigInt.from(totalOriginalAmount * amountToEthereumMultiplier);
|
||||||
|
|
||||||
if (_erc20Balance.balance < totalAmount) {
|
if (_erc20Balance.balance < totalAmount) {
|
||||||
throw EthereumTransactionCreationException(_credentials.currency);
|
throw EthereumTransactionCreationException(transactionCurrency);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
final output = outputs.first;
|
final output = outputs.first;
|
||||||
|
@ -185,7 +189,7 @@ abstract class EthereumWalletBase
|
||||||
: BigInt.from(totalOriginalAmount * amountToEthereumMultiplier);
|
: BigInt.from(totalOriginalAmount * amountToEthereumMultiplier);
|
||||||
|
|
||||||
if (_erc20Balance.balance < totalAmount) {
|
if (_erc20Balance.balance < totalAmount) {
|
||||||
throw EthereumTransactionCreationException(_credentials.currency);
|
throw EthereumTransactionCreationException(transactionCurrency);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -195,11 +199,10 @@ abstract class EthereumWalletBase
|
||||||
amount: totalAmount.toString(),
|
amount: totalAmount.toString(),
|
||||||
gas: _estimatedGas!,
|
gas: _estimatedGas!,
|
||||||
priority: _credentials.priority!,
|
priority: _credentials.priority!,
|
||||||
currency: _credentials.currency,
|
currency: transactionCurrency,
|
||||||
exponent: exponent,
|
exponent: exponent,
|
||||||
contractAddress: _credentials.currency is Erc20Token
|
contractAddress:
|
||||||
? (_credentials.currency as Erc20Token).contractAddress
|
transactionCurrency is Erc20Token ? transactionCurrency.contractAddress : null,
|
||||||
: null,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
return pendingEthereumTransaction;
|
return pendingEthereumTransaction;
|
||||||
|
|
|
@ -29,7 +29,9 @@ abstract class ExchangeTradeViewModelBase with Store {
|
||||||
required this.sendViewModel})
|
required this.sendViewModel})
|
||||||
: trade = tradesStore.trade!,
|
: trade = tradesStore.trade!,
|
||||||
isSendable = tradesStore.trade!.from == wallet.currency ||
|
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>() {
|
items = ObservableList<ExchangeTradeItem>() {
|
||||||
switch (trade.provider) {
|
switch (trade.provider) {
|
||||||
case ExchangeProviderDescription.xmrto:
|
case ExchangeProviderDescription.xmrto:
|
||||||
|
@ -103,6 +105,7 @@ abstract class ExchangeTradeViewModelBase with Store {
|
||||||
final output = sendViewModel.outputs.first;
|
final output = sendViewModel.outputs.first;
|
||||||
output.address = trade.inputAddress ?? '';
|
output.address = trade.inputAddress ?? '';
|
||||||
output.setCryptoAmount(trade.amount);
|
output.setCryptoAmount(trade.amount);
|
||||||
|
sendViewModel.selectedCryptoCurrency = trade.from;
|
||||||
await sendViewModel.createTransaction();
|
await sendViewModel.createTransaction();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import 'package:cake_wallet/bitcoin/bitcoin.dart';
|
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_mode.dart';
|
||||||
import 'package:cake_wallet/view_model/restore/restore_wallet.dart';
|
import 'package:cake_wallet/view_model/restore/restore_wallet.dart';
|
||||||
import 'package:hive/hive.dart';
|
import 'package:hive/hive.dart';
|
||||||
|
@ -80,6 +81,9 @@ abstract class WalletRestorationFromQRVMBase extends WalletCreationVM with Store
|
||||||
case WalletType.litecoin:
|
case WalletType.litecoin:
|
||||||
return bitcoin!.createBitcoinRestoreWalletFromSeedCredentials(
|
return bitcoin!.createBitcoinRestoreWalletFromSeedCredentials(
|
||||||
name: name, mnemonic: restoreWallet.mnemonicSeed ?? '', password: password);
|
name: name, mnemonic: restoreWallet.mnemonicSeed ?? '', password: password);
|
||||||
|
case WalletType.ethereum:
|
||||||
|
return ethereum!.createEthereumRestoreWalletFromSeedCredentials(
|
||||||
|
name: name, mnemonic: restoreWallet.mnemonicSeed ?? '', password: password);
|
||||||
default:
|
default:
|
||||||
throw Exception('Unexpected type: ${type.toString()}');
|
throw Exception('Unexpected type: ${type.toString()}');
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue