Clean up and refactor

This commit is contained in:
likho 2023-08-15 15:28:53 +02:00
parent 373637701c
commit 520ceabf79

View file

@ -185,14 +185,16 @@ class TezosWallet extends CoinServiceAPI with WalletCache, WalletDB {
@override @override
Future<String> confirmSend({required Map<String, dynamic> txData}) async { Future<String> confirmSend({required Map<String, dynamic> txData}) async {
try { try {
final amount = txData["recipientAmt"] as Amount; final amount = txData["recipientAmt"] as Amount;
final amountInMicroTez = amount.decimal * Decimal.fromInt(1000000); final amountInMicroTez =
amount.decimal * Decimal.fromInt(1000000);
final microtezToInt = int.parse(amountInMicroTez.toString()); final microtezToInt = int.parse(amountInMicroTez.toString());
final int feeInMicroTez = int.parse(txData["fee"].toString()); final int feeInMicroTez = int.parse(txData["fee"].toString());
final String destinationAddress = txData["address"] as String; final String destinationAddress = txData["address"] as String;
final secretKey = final secretKey = Keystore.fromMnemonic((await mnemonicString)!)
Keystore.fromMnemonic((await mnemonicString)!).secretKey; .secretKey;
Logging.instance.log(secretKey, level: LogLevel.Info); Logging.instance.log(secretKey, level: LogLevel.Info);
final sourceKeyStore = Keystore.fromSecretKey(secretKey); final sourceKeyStore = Keystore.fromSecretKey(secretKey);
final client = TezartClient(getCurrentNode().host); final client = TezartClient(getCurrentNode().host);
@ -202,7 +204,9 @@ class TezosWallet extends CoinServiceAPI with WalletCache, WalletDB {
destination: destinationAddress, destination: destinationAddress,
amount: microtezToInt, amount: microtezToInt,
customFee: feeInMicroTez, customFee: feeInMicroTez,
customGasLimit: 400); customGasLimit: feeInMicroTez
);
await operation.executeAndMonitor(); // This line gives an error await operation.executeAndMonitor(); // This line gives an error
return Future.value(""); return Future.value("");
} catch (e) { } catch (e) {
@ -403,18 +407,12 @@ class TezosWallet extends CoinServiceAPI with WalletCache, WalletDB {
Future<void> updateBalance() async { Future<void> updateBalance() async {
try { try {
var api = final client = TezartClient(getCurrentNode().host);
"${getCurrentNode().host}/chains/main/blocks/head/context/contracts/${await currentReceivingAddress}/balance"; final thisBalance = await client.getBalance(
var theBalance = (await get(Uri.parse(api)).then((value) => value.body)) address: await currentReceivingAddress
.substring( );
1, Amount balanceInAmount = Amount(
(await get(Uri.parse(api)).then((value) => value.body)).length - rawValue: BigInt.parse(thisBalance.toString()),
2);
Logging.instance.log(
"Balance for ${await currentReceivingAddress}: $theBalance",
level: LogLevel.Info);
var balanceInAmount = Amount(
rawValue: BigInt.parse(theBalance.toString()),
fractionDigits: coin.decimals); fractionDigits: coin.decimals);
_balance = Balance( _balance = Balance(
total: balanceInAmount, total: balanceInAmount,
@ -507,6 +505,7 @@ class TezosWallet extends CoinServiceAPI with WalletCache, WalletDB {
Future<void> updateChainHeight() async { Future<void> updateChainHeight() async {
try { try {
final client = TezartClient(getCurrentNode().host);
var api = "${getCurrentNode().host}/chains/main/blocks/head/header/shell"; var api = "${getCurrentNode().host}/chains/main/blocks/head/header/shell";
var jsonParsedResponse = var jsonParsedResponse =
jsonDecode(await get(Uri.parse(api)).then((value) => value.body)); jsonDecode(await get(Uri.parse(api)).then((value) => value.body));