Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/backend_task/platform_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,16 @@ impl AppContext {
PlatformInfoTaskRequestType::CurrentEpochInfo => {
match ExtendedEpochInfo::fetch_current(&sdk).await {
Ok(epoch_info) => {
let formatted = format_extended_epoch_info(epoch_info, self.network, true);
// Cache the fee multiplier for UI fee estimation
let fee_multiplier = epoch_info.fee_multiplier_permille();
self.set_fee_multiplier_permille(fee_multiplier);

let mut formatted =
format_extended_epoch_info(epoch_info, self.network, true);
formatted.push_str(&format!(
"\n\n(Fee multiplier cache updated: {}x)",
fee_multiplier as f64 / 1000.0
));
Ok(BackendTaskSuccessResult::PlatformInfo(
PlatformInfoTaskResult::TextResult(formatted),
))
Expand Down
27 changes: 26 additions & 1 deletion src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::context_provider::Provider as RpcProvider;
use crate::context_provider_spv::SpvProvider;
use crate::database::Database;
use crate::model::contested_name::ContestedName;
use crate::model::fee_estimation::PlatformFeeEstimator;
use crate::model::password_info::PasswordInfo;
use crate::model::qualified_contract::QualifiedContract;
use crate::model::qualified_identity::{DPNSNameInfo, QualifiedIdentity};
Expand Down Expand Up @@ -49,7 +50,7 @@ use dash_sdk::query_types::IndexMap;
use egui::Context;
use rusqlite::Result;
use std::collections::{BTreeMap, HashMap};
use std::sync::atomic::{AtomicBool, AtomicU8, Ordering};
use std::sync::atomic::{AtomicBool, AtomicU8, AtomicU64, Ordering};
use std::sync::{Arc, Mutex, RwLock, RwLockWriteGuard};

const ANIMATION_REFRESH_TIME: std::time::Duration = std::time::Duration::from_millis(100);
Expand Down Expand Up @@ -106,6 +107,9 @@ pub struct AppContext {
pub(crate) selected_wallet_hash: Mutex<Option<WalletSeedHash>>,
/// Currently selected single key wallet (persisted across screen navigation)
pub(crate) selected_single_key_hash: Mutex<Option<SingleKeyHash>>,
/// Cached fee multiplier permille from current epoch (1000 = 1x, 2000 = 2x)
/// Updated when epoch info is fetched from Platform
fee_multiplier_permille: AtomicU64,
}

impl AppContext {
Expand Down Expand Up @@ -275,6 +279,9 @@ impl AppContext {
pending_wallet_selection: Mutex::new(None),
selected_wallet_hash: Mutex::new(selected_wallet_hash),
selected_single_key_hash: Mutex::new(selected_single_key_hash),
fee_multiplier_permille: AtomicU64::new(
PlatformFeeEstimator::DEFAULT_FEE_MULTIPLIER_PERMILLE,
),
};

let app_context = Arc::new(app_context);
Expand Down Expand Up @@ -395,6 +402,24 @@ impl AppContext {
}
}

/// Get the cached fee multiplier permille (1000 = 1x, 2000 = 2x)
pub fn fee_multiplier_permille(&self) -> u64 {
self.fee_multiplier_permille.load(Ordering::Relaxed)
}

/// Update the cached fee multiplier from epoch info
pub fn set_fee_multiplier_permille(&self, multiplier: u64) {
self.fee_multiplier_permille
.store(multiplier, Ordering::Relaxed);
}

/// Get a fee estimator configured with the cached fee multiplier.
/// Use this instead of `PlatformFeeEstimator::new()` to get accurate fee estimates
/// that reflect the current network fee multiplier.
pub fn fee_estimator(&self) -> PlatformFeeEstimator {
PlatformFeeEstimator::with_fee_multiplier(self.fee_multiplier_permille())
}

pub fn spv_manager(&self) -> &Arc<SpvManager> {
&self.spv_manager
}
Expand Down
Loading
Loading