mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-12-23 11:59:30 +00:00
fix monero and wownero fee estimates for sending. fix some ui bugs
This commit is contained in:
parent
da941376be
commit
deec0cdddb
3 changed files with 67 additions and 11 deletions
|
@ -410,8 +410,8 @@ class _TransactionFeeSelectionSheetState
|
||||||
FutureBuilder(
|
FutureBuilder(
|
||||||
future: feeFor(
|
future: feeFor(
|
||||||
coin: manager.coin,
|
coin: manager.coin,
|
||||||
feeRateType: FeeRateType.fast,
|
feeRateType: FeeRateType.average,
|
||||||
feeRate: feeObject!.fast,
|
feeRate: feeObject!.medium,
|
||||||
amount: Format
|
amount: Format
|
||||||
.decimalAmountToSatoshis(
|
.decimalAmountToSatoshis(
|
||||||
amount)),
|
amount)),
|
||||||
|
|
|
@ -1451,7 +1451,7 @@ class MoneroWallet extends CoinServiceAPI {
|
||||||
bool isSendAll = false;
|
bool isSendAll = false;
|
||||||
final balance = await availableBalance;
|
final balance = await availableBalance;
|
||||||
final satInDecimal = ((Decimal.fromInt(satoshiAmount) /
|
final satInDecimal = ((Decimal.fromInt(satoshiAmount) /
|
||||||
Decimal.fromInt(Constants.satsPerCoinWownero))
|
Decimal.fromInt(Constants.satsPerCoinMonero))
|
||||||
.toDecimal() *
|
.toDecimal() *
|
||||||
Decimal.fromInt(10000));
|
Decimal.fromInt(10000));
|
||||||
if (satInDecimal == balance) {
|
if (satInDecimal == balance) {
|
||||||
|
@ -1471,7 +1471,9 @@ class MoneroWallet extends CoinServiceAPI {
|
||||||
Object tmp = monero.createMoneroTransactionCreationCredentials(
|
Object tmp = monero.createMoneroTransactionCreationCredentials(
|
||||||
outputs: outputs, priority: feePriority);
|
outputs: outputs, priority: feePriority);
|
||||||
|
|
||||||
awaitPendingTransaction = walletBase!.createTransaction(tmp);
|
await prepareSendMutex.protect(() async {
|
||||||
|
awaitPendingTransaction = walletBase!.createTransaction(tmp);
|
||||||
|
});
|
||||||
} catch (e, s) {
|
} catch (e, s) {
|
||||||
Logging.instance.log("Exception rethrown from prepareSend(): $e\n$s",
|
Logging.instance.log("Exception rethrown from prepareSend(): $e\n$s",
|
||||||
level: LogLevel.Warning);
|
level: LogLevel.Warning);
|
||||||
|
@ -1510,30 +1512,57 @@ class MoneroWallet extends CoinServiceAPI {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Mutex prepareSendMutex = Mutex();
|
||||||
|
Mutex estimateFeeMutex = Mutex();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<int> estimateFeeFor(int satoshiAmount, int feeRate) async {
|
Future<int> estimateFeeFor(int satoshiAmount, int feeRate) async {
|
||||||
MoneroTransactionPriority? priority;
|
MoneroTransactionPriority? priority;
|
||||||
|
FeeRateType feeRateType = FeeRateType.slow;
|
||||||
switch (feeRate) {
|
switch (feeRate) {
|
||||||
case 1:
|
case 1:
|
||||||
priority = MoneroTransactionPriority.regular;
|
priority = MoneroTransactionPriority.regular;
|
||||||
|
feeRateType = FeeRateType.slow;
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
priority = MoneroTransactionPriority.medium;
|
priority = MoneroTransactionPriority.medium;
|
||||||
|
feeRateType = FeeRateType.average;
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
priority = MoneroTransactionPriority.fast;
|
priority = MoneroTransactionPriority.fast;
|
||||||
|
feeRateType = FeeRateType.average;
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
priority = MoneroTransactionPriority.fastest;
|
priority = MoneroTransactionPriority.fastest;
|
||||||
|
feeRateType = FeeRateType.fast;
|
||||||
break;
|
break;
|
||||||
case 0:
|
case 0:
|
||||||
default:
|
default:
|
||||||
priority = MoneroTransactionPriority.slow;
|
priority = MoneroTransactionPriority.slow;
|
||||||
|
feeRateType = FeeRateType.slow;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
final fee =
|
var aprox;
|
||||||
(walletBase?.calculateEstimatedFee(priority, satoshiAmount) ?? 0) ~/
|
|
||||||
10000;
|
await estimateFeeMutex.protect(() async {
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
aprox = (await prepareSend(
|
||||||
|
// This address is only used for getting an approximate fee, never for sending
|
||||||
|
address:
|
||||||
|
"8347huhmj6Ggzr1BpZPJAD5oa96ob5Fe8GtQdGZDYVVYVsCgtUNH3pEEzExDuaAVZdC16D4FkAb24J6wUfsKkcZtC8EPXB7",
|
||||||
|
satoshiAmount: satoshiAmount,
|
||||||
|
args: {"feeRate": feeRateType}))['fee'];
|
||||||
|
await Future.delayed(const Duration(milliseconds: 1000));
|
||||||
|
} catch (e, s) {
|
||||||
|
Logging.instance.log("$feeRateType $e $s", level: LogLevel.Error);
|
||||||
|
aprox = -9999999999999999;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
print("this is the aprox fee $aprox for $satoshiAmount");
|
||||||
|
final fee = (aprox as int);
|
||||||
return fee;
|
return fee;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1477,7 +1477,9 @@ class WowneroWallet extends CoinServiceAPI {
|
||||||
Object tmp = wownero.createWowneroTransactionCreationCredentials(
|
Object tmp = wownero.createWowneroTransactionCreationCredentials(
|
||||||
outputs: outputs, priority: feePriority);
|
outputs: outputs, priority: feePriority);
|
||||||
|
|
||||||
awaitPendingTransaction = walletBase!.createTransaction(tmp);
|
await prepareSendMutex.protect(() async {
|
||||||
|
awaitPendingTransaction = walletBase!.createTransaction(tmp);
|
||||||
|
});
|
||||||
} catch (e, s) {
|
} catch (e, s) {
|
||||||
Logging.instance.log("Exception rethrown from prepareSend(): $e\n$s",
|
Logging.instance.log("Exception rethrown from prepareSend(): $e\n$s",
|
||||||
level: LogLevel.Warning);
|
level: LogLevel.Warning);
|
||||||
|
@ -1516,30 +1518,55 @@ class WowneroWallet extends CoinServiceAPI {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Mutex prepareSendMutex = Mutex();
|
||||||
|
Mutex estimateFeeMutex = Mutex();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<int> estimateFeeFor(int satoshiAmount, int feeRate) async {
|
Future<int> estimateFeeFor(int satoshiAmount, int feeRate) async {
|
||||||
MoneroTransactionPriority? priority;
|
MoneroTransactionPriority? priority;
|
||||||
|
FeeRateType feeRateType = FeeRateType.slow;
|
||||||
switch (feeRate) {
|
switch (feeRate) {
|
||||||
case 1:
|
case 1:
|
||||||
priority = MoneroTransactionPriority.regular;
|
priority = MoneroTransactionPriority.regular;
|
||||||
|
feeRateType = FeeRateType.slow;
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
priority = MoneroTransactionPriority.medium;
|
priority = MoneroTransactionPriority.medium;
|
||||||
|
feeRateType = FeeRateType.average;
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
priority = MoneroTransactionPriority.fast;
|
priority = MoneroTransactionPriority.fast;
|
||||||
|
feeRateType = FeeRateType.average;
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
priority = MoneroTransactionPriority.fastest;
|
priority = MoneroTransactionPriority.fastest;
|
||||||
|
feeRateType = FeeRateType.fast;
|
||||||
break;
|
break;
|
||||||
case 0:
|
case 0:
|
||||||
default:
|
default:
|
||||||
priority = MoneroTransactionPriority.slow;
|
priority = MoneroTransactionPriority.slow;
|
||||||
|
feeRateType = FeeRateType.slow;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
final fee =
|
var aprox;
|
||||||
(walletBase?.calculateEstimatedFee(priority, satoshiAmount) ?? 0) ~/
|
await estimateFeeMutex.protect(() async {
|
||||||
10000;
|
{
|
||||||
|
try {
|
||||||
|
aprox = (await prepareSend(
|
||||||
|
// This address is only used for getting an approximate fee, never for sending
|
||||||
|
address:
|
||||||
|
"WW3iVcnoAY6K9zNdU4qmdvZELefx6xZz4PMpTwUifRkvMQckyadhSPYMVPJhBdYE8P9c27fg9RPmVaWNFx1cDaj61HnetqBiy",
|
||||||
|
satoshiAmount: satoshiAmount,
|
||||||
|
args: {"feeRate": feeRateType}))['fee'];
|
||||||
|
await Future.delayed(const Duration(milliseconds: 100));
|
||||||
|
} catch (e, s) {
|
||||||
|
aprox = -9999999999999999;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
print("this is the aprox fee $aprox for $satoshiAmount");
|
||||||
|
final fee = (aprox as int);
|
||||||
return fee;
|
return fee;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue