refactor import

This commit is contained in:
julian 2023-02-24 08:45:34 -06:00
parent 5aed55235c
commit 58280010f8

View file

@ -16,8 +16,7 @@ import 'package:stackwallet/utilities/enums/fee_rate_type_enum.dart';
import 'package:stackwallet/utilities/eth_commons.dart'; import 'package:stackwallet/utilities/eth_commons.dart';
import 'package:stackwallet/utilities/flutter_secure_storage_interface.dart'; import 'package:stackwallet/utilities/flutter_secure_storage_interface.dart';
import 'package:stackwallet/utilities/format.dart'; import 'package:stackwallet/utilities/format.dart';
import 'package:web3dart/web3dart.dart'; import 'package:web3dart/web3dart.dart' as web3dart;
import 'package:web3dart/web3dart.dart' as transaction;
const int MINIMUM_CONFIRMATIONS = 3; const int MINIMUM_CONFIRMATIONS = 3;
@ -25,15 +24,15 @@ class EthereumTokenService {
final EthToken token; final EthToken token;
late bool shouldAutoSync; late bool shouldAutoSync;
late EthereumAddress _contractAddress; late web3dart.EthereumAddress _contractAddress;
late EthPrivateKey _credentials; late web3dart.EthPrivateKey _credentials;
late DeployedContract _contract; late web3dart.DeployedContract _contract;
late ContractFunction _balanceFunction; late web3dart.ContractFunction _balanceFunction;
late ContractFunction _sendFunction; late web3dart.ContractFunction _sendFunction;
late Future<List<String>> _walletMnemonic; late Future<List<String>> _walletMnemonic;
late SecureStorageInterface _secureStore; late SecureStorageInterface _secureStore;
late String _tokenAbi; late String _tokenAbi;
late Web3Client _client; late web3dart.Web3Client _client;
late final TransactionNotificationTracker txTracker; late final TransactionNotificationTracker txTracker;
TransactionData? cachedTxData; TransactionData? cachedTxData;
@ -44,7 +43,7 @@ class EthereumTokenService {
required Future<List<String>> walletMnemonic, required Future<List<String>> walletMnemonic,
required SecureStorageInterface secureStore, required SecureStorageInterface secureStore,
}) { }) {
_contractAddress = EthereumAddress.fromHex(token.contractAddress); _contractAddress = web3dart.EthereumAddress.fromHex(token.contractAddress);
_walletMnemonic = walletMnemonic; _walletMnemonic = walletMnemonic;
_secureStore = secureStore; _secureStore = secureStore;
} }
@ -75,16 +74,16 @@ class EthereumTokenService {
final sentTx = await _client.sendTransaction( final sentTx = await _client.sendTransaction(
_credentials, _credentials,
transaction.Transaction.callContract( web3dart.Transaction.callContract(
contract: _contract, contract: _contract,
function: _sendFunction, function: _sendFunction,
parameters: [ parameters: [
EthereumAddress.fromHex(txData['address'] as String), web3dart.EthereumAddress.fromHex(txData['address'] as String),
bigIntAmount bigIntAmount
], ],
maxGas: _gasLimit, maxGas: _gasLimit,
gasPrice: EtherAmount.fromUnitAndValue( gasPrice: web3dart.EtherAmount.fromUnitAndValue(
EtherUnit.wei, txData['feeInWei']))); web3dart.EtherUnit.wei, txData['feeInWei'])));
return sentTx; return sentTx;
} }
@ -118,10 +117,10 @@ class EthereumTokenService {
//Get private key for given mnemonic //Get private key for given mnemonic
// TODO: replace empty string with actual passphrase // TODO: replace empty string with actual passphrase
String privateKey = getPrivateKey(mnemonicString, ""); String privateKey = getPrivateKey(mnemonicString, "");
_credentials = EthPrivateKey.fromHex(privateKey); _credentials = web3dart.EthPrivateKey.fromHex(privateKey);
_contract = DeployedContract( _contract = web3dart.DeployedContract(
ContractAbi.fromJson(_tokenAbi, token.name), _contractAddress); web3dart.ContractAbi.fromJson(_tokenAbi, token.name), _contractAddress);
_balanceFunction = _contract.function('balanceOf'); _balanceFunction = _contract.function('balanceOf');
_sendFunction = _contract.function('transfer'); _sendFunction = _contract.function('transfer');
_client = await getEthClient(); _client = await getEthClient();
@ -148,10 +147,10 @@ class EthereumTokenService {
//Get private key for given mnemonic //Get private key for given mnemonic
// TODO: replace empty string with actual passphrase // TODO: replace empty string with actual passphrase
String privateKey = getPrivateKey(mnemonicString, ""); String privateKey = getPrivateKey(mnemonicString, "");
_credentials = EthPrivateKey.fromHex(privateKey); _credentials = web3dart.EthPrivateKey.fromHex(privateKey);
_contract = DeployedContract( _contract = web3dart.DeployedContract(
ContractAbi.fromJson(_tokenAbi, token.name), _contractAddress); web3dart.ContractAbi.fromJson(_tokenAbi, token.name), _contractAddress);
_balanceFunction = _contract.function('balanceOf'); _balanceFunction = _contract.function('balanceOf');
_sendFunction = _contract.function('transfer'); _sendFunction = _contract.function('transfer');
_client = await getEthClient(); _client = await getEthClient();
@ -342,8 +341,8 @@ class EthereumTokenService {
DefaultNodes.getNodeFor(coin); DefaultNodes.getNodeFor(coin);
} }
Future<Web3Client> getEthClient() async { Future<web3dart.Web3Client> getEthClient() async {
final node = await getCurrentNode(); final node = await getCurrentNode();
return Web3Client(node.host, Client()); return web3dart.Web3Client(node.host, Client());
} }
} }