mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-11-17 09:47:37 +00:00
WIP token send logic
This commit is contained in:
parent
42d168dc57
commit
8d0dcafccf
1 changed files with 67 additions and 47 deletions
|
@ -66,27 +66,78 @@ class EthTokenWallet extends ChangeNotifier with EthTokenCache {
|
||||||
|
|
||||||
Coin get coin => Coin.ethereum;
|
Coin get coin => Coin.ethereum;
|
||||||
|
|
||||||
Future<String> confirmSend({required Map<String, dynamic> txData}) async {
|
Future<Map<String, dynamic>> prepareSend({
|
||||||
final amount = txData['recipientAmt'];
|
required String address,
|
||||||
|
required int satoshiAmount,
|
||||||
|
Map<String, dynamic>? args,
|
||||||
|
}) async {
|
||||||
|
final feeRateType = args?["feeRate"];
|
||||||
|
int fee = 0;
|
||||||
|
final feeObject = await fees;
|
||||||
|
switch (feeRateType) {
|
||||||
|
case FeeRateType.fast:
|
||||||
|
fee = feeObject.fast;
|
||||||
|
break;
|
||||||
|
case FeeRateType.average:
|
||||||
|
fee = feeObject.medium;
|
||||||
|
break;
|
||||||
|
case FeeRateType.slow:
|
||||||
|
fee = feeObject.slow;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
final feeEstimate = await estimateFeeFor(satoshiAmount, fee);
|
||||||
|
|
||||||
final decimalAmount =
|
final decimalAmount =
|
||||||
Format.satoshisToAmount(amount as int, coin: Coin.ethereum);
|
Format.satoshisToAmount(satoshiAmount, coin: Coin.ethereum);
|
||||||
final bigIntAmount =
|
final bigIntAmount =
|
||||||
amountToBigInt(decimalAmount.toDouble(), tokenContract.decimals);
|
amountToBigInt(decimalAmount.toDouble(), tokenContract.decimals);
|
||||||
|
|
||||||
final sentTx = await _client.sendTransaction(
|
final client = await getEthClient();
|
||||||
_credentials,
|
|
||||||
web3dart.Transaction.callContract(
|
|
||||||
contract: _deployedContract,
|
|
||||||
function: _sendFunction,
|
|
||||||
parameters: [
|
|
||||||
web3dart.EthereumAddress.fromHex(txData['address'] as String),
|
|
||||||
bigIntAmount
|
|
||||||
],
|
|
||||||
maxGas: _gasLimit,
|
|
||||||
gasPrice: web3dart.EtherAmount.fromUnitAndValue(
|
|
||||||
web3dart.EtherUnit.wei, txData['feeInWei'])));
|
|
||||||
|
|
||||||
return sentTx;
|
final est = await client.estimateGas(
|
||||||
|
sender: web3dart.EthereumAddress.fromHex(await currentReceivingAddress),
|
||||||
|
to: web3dart.EthereumAddress.fromHex(address),
|
||||||
|
data: _sendFunction.encodeCall(
|
||||||
|
[web3dart.EthereumAddress.fromHex(address), bigIntAmount]),
|
||||||
|
gasPrice: web3dart.EtherAmount.fromUnitAndValue(
|
||||||
|
web3dart.EtherUnit.wei,
|
||||||
|
fee,
|
||||||
|
),
|
||||||
|
amountOfGas: BigInt.from(_gasLimit),
|
||||||
|
value: web3dart.EtherAmount.inWei(BigInt.one),
|
||||||
|
);
|
||||||
|
|
||||||
|
final tx = web3dart.Transaction.callContract(
|
||||||
|
contract: _deployedContract,
|
||||||
|
function: _sendFunction,
|
||||||
|
parameters: [web3dart.EthereumAddress.fromHex(address), bigIntAmount],
|
||||||
|
maxGas: _gasLimit,
|
||||||
|
gasPrice: web3dart.EtherAmount.fromUnitAndValue(
|
||||||
|
web3dart.EtherUnit.wei,
|
||||||
|
fee,
|
||||||
|
),
|
||||||
|
nonce: args?["nonce"] as int?,
|
||||||
|
);
|
||||||
|
|
||||||
|
Map<String, dynamic> txData = {
|
||||||
|
"fee": feeEstimate,
|
||||||
|
"feeInWei": fee,
|
||||||
|
"address": address,
|
||||||
|
"recipientAmt": satoshiAmount,
|
||||||
|
"ethTx": tx,
|
||||||
|
};
|
||||||
|
|
||||||
|
return txData;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<String> confirmSend({required Map<String, dynamic> txData}) async {
|
||||||
|
final txid = await _client.sendTransaction(
|
||||||
|
_credentials,
|
||||||
|
txData["ethTx"] as web3dart.Transaction,
|
||||||
|
);
|
||||||
|
|
||||||
|
return txid;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<String> get currentReceivingAddress async {
|
Future<String> get currentReceivingAddress async {
|
||||||
|
@ -243,37 +294,6 @@ class EthTokenWallet extends ChangeNotifier with EthTokenCache {
|
||||||
|
|
||||||
bool get isRefreshing => _refreshLock;
|
bool get isRefreshing => _refreshLock;
|
||||||
|
|
||||||
Future<Map<String, dynamic>> prepareSend(
|
|
||||||
{required String address,
|
|
||||||
required int satoshiAmount,
|
|
||||||
Map<String, dynamic>? args}) async {
|
|
||||||
final feeRateType = args?["feeRate"];
|
|
||||||
int fee = 0;
|
|
||||||
final feeObject = await fees;
|
|
||||||
switch (feeRateType) {
|
|
||||||
case FeeRateType.fast:
|
|
||||||
fee = feeObject.fast;
|
|
||||||
break;
|
|
||||||
case FeeRateType.average:
|
|
||||||
fee = feeObject.medium;
|
|
||||||
break;
|
|
||||||
case FeeRateType.slow:
|
|
||||||
fee = feeObject.slow;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
final feeEstimate = await estimateFeeFor(satoshiAmount, fee);
|
|
||||||
|
|
||||||
Map<String, dynamic> txData = {
|
|
||||||
"fee": feeEstimate,
|
|
||||||
"feeInWei": fee,
|
|
||||||
"address": address,
|
|
||||||
"recipientAmt": satoshiAmount,
|
|
||||||
};
|
|
||||||
|
|
||||||
return txData;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool _refreshLock = false;
|
bool _refreshLock = false;
|
||||||
|
|
||||||
Future<void> refresh() async {
|
Future<void> refresh() async {
|
||||||
|
|
Loading…
Reference in a new issue