mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-06-28 12:29:51 +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
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue