Return just one value for fees since endpoint returns only one value for fees

This commit is contained in:
likho 2023-08-16 15:17:58 +02:00
parent e8d5c3ad8b
commit 444860da53

View file

@ -239,29 +239,17 @@ class TezosWallet extends CoinServiceAPI with WalletCache, WalletDB {
@override @override
Future<Amount> estimateFeeFor(Amount amount, int feeRate) async { Future<Amount> estimateFeeFor(Amount amount, int feeRate) async {
// TODO: Check if this is correct
var api = "https://api.tzstats.com/series/op?start_date=today&collapse=10d"; var api = "https://api.tzstats.com/series/op?start_date=today&collapse=1d";
var response = jsonDecode((await get(Uri.parse(api))).body)[0]; var response = jsonDecode((await get(Uri.parse(api))).body)[0];
double totalFees = response[4] as double; double totalFees = response[4] as double;
int totalTxs = response[8] as int; int totalTxs = response[8] as int;
int feePerTx = (totalFees / totalTxs * 1000000).floor(); int feePerTx = (totalFees / totalTxs * 1000000).floor();
int estimatedFee = 0;
Logging.instance.log("feePerTx:$feePerTx", level: LogLevel.Info);
Logging.instance.log("feeRate:$feeRate", level: LogLevel.Info);
switch (feeRate) {
case 0:
estimatedFee = feePerTx * 2;
case 1:
estimatedFee = feePerTx;
case 2:
case 3:
estimatedFee = (feePerTx / 2).floor();
default:
estimatedFee = feeRate;
}
Logging.instance.log("estimatedFee:$estimatedFee", level: LogLevel.Info);
return Amount( return Amount(
rawValue: BigInt.from(estimatedFee), fractionDigits: coin.decimals); rawValue: BigInt.from(feePerTx),
fractionDigits: coin.decimals,
);
} }
@override @override
@ -272,21 +260,20 @@ class TezosWallet extends CoinServiceAPI with WalletCache, WalletDB {
@override @override
Future<FeeObject> get fees async { Future<FeeObject> get fees async {
// TODO: Check if this is correct
var api = "https://api.tzstats.com/series/op?start_date=today&collapse=10d"; var api = "https://api.tzstats.com/series/op?start_date=today&collapse=10d";
var response = jsonDecode((await get(Uri.parse(api))).body); var response = jsonDecode((await get(Uri.parse(api))).body);
double totalFees = response[0][4] as double; double totalFees = response[0][4] as double;
int totalTxs = response[0][8] as int; int totalTxs = response[0][8] as int;
int feePerTx = (totalFees / totalTxs * 1000000).floor(); int feePerTx = (totalFees / totalTxs * 1000000).floor();
Logging.instance.log("feePerTx:$feePerTx", level: LogLevel.Info); Logging.instance.log("feePerTx:$feePerTx", level: LogLevel.Info);
// TODO: fix numberOfBlocks // TODO: fix numberOfBlocks - Since there is only one fee no need to set blocks
return FeeObject( return FeeObject(
numberOfBlocksFast: 3, numberOfBlocksFast: 10,
numberOfBlocksAverage: 10, numberOfBlocksAverage: 10,
numberOfBlocksSlow: 30, numberOfBlocksSlow: 10,
fast: (feePerTx * 2), fast: feePerTx,
medium: feePerTx, medium: feePerTx,
slow: (feePerTx / 2).floor(), slow: feePerTx,
); );
} }