Skip to content

Commit

Permalink
wip: stored replayed in use config
Browse files Browse the repository at this point in the history
  • Loading branch information
shanimal08 committed Nov 20, 2024
1 parent 2442336 commit af120cc
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 83 deletions.
30 changes: 14 additions & 16 deletions src-tauri/src/app_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ pub struct AppConfigFromFile {
#[serde(default = "default_display_mode")]
display_mode: String,
#[serde(default = "default_true")]
auto_mining: bool,
#[serde(default = "default_true")]
mine_on_app_start: bool,
#[serde(default = "default_true")]
p2pool_enabled: bool,
Expand All @@ -47,8 +45,6 @@ pub struct AppConfigFromFile {
#[serde(default = "default_application_language")]
application_language: String,
#[serde(default = "default_true")]
airdrop_ui_enabled: bool,
#[serde(default = "default_true")]
use_tor: bool,
#[serde(default = "default_false")]
paper_wallet_enabled: bool,
Expand All @@ -75,6 +71,7 @@ pub struct AppConfigFromFile {
sharing_enabled: bool,
#[serde(default = "default_true")]
visual_mode: bool,
replayed_ids: Vec<String>,
}

impl Default for AppConfigFromFile {
Expand All @@ -83,7 +80,6 @@ impl Default for AppConfigFromFile {
version: default_version(),
mode: default_mode(),
display_mode: default_display_mode(),
auto_mining: true,
mine_on_app_start: true,
p2pool_enabled: true,
last_binaries_update_timestamp: default_system_time(),
Expand All @@ -98,7 +94,6 @@ impl Default for AppConfigFromFile {
application_language: default_application_language(),
custom_max_cpu_usage: None,
custom_max_gpu_usage: None,
airdrop_ui_enabled: true,
paper_wallet_enabled: false,
use_tor: true,
eco_mode_cpu_options: Vec::new(),
Expand All @@ -113,6 +108,7 @@ impl Default for AppConfigFromFile {
custom_power_levels_enabled: true,
sharing_enabled: true,
visual_mode: true,
replayed_ids: Vec::new(),
}
}
}
Expand Down Expand Up @@ -206,6 +202,7 @@ pub(crate) struct AppConfig {
custom_power_levels_enabled: bool,
sharing_enabled: bool,
visual_mode: bool,
replayed_ids: Vec<String>,
}

impl AppConfig {
Expand Down Expand Up @@ -245,6 +242,7 @@ impl AppConfig {
auto_update: true,
sharing_enabled: true,
visual_mode: true,
replayed_ids: Vec::new(),
}
}

Expand Down Expand Up @@ -275,7 +273,6 @@ impl AppConfig {
} else {
self.display_mode = DisplayMode::Light;
}
self.auto_mining = config.auto_mining;
self.mine_on_app_start = config.mine_on_app_start;
self.p2pool_enabled = config.p2pool_enabled;
self.last_binaries_update_timestamp = config.last_binaries_update_timestamp;
Expand All @@ -288,7 +285,6 @@ impl AppConfig {
self.should_always_use_system_language = config.should_always_use_system_language;
self.should_auto_launch = config.should_auto_launch;
self.application_language = config.application_language;
self.airdrop_ui_enabled = config.airdrop_ui_enabled;
self.use_tor = config.use_tor;
self.paper_wallet_enabled = config.paper_wallet_enabled;
self.eco_mode_cpu_options = config.eco_mode_cpu_options;
Expand Down Expand Up @@ -484,12 +480,6 @@ impl AppConfig {
self.auto_mining
}

// pub async fn set_airdrop_ui_enabled(&mut self, airdrop_ui_enabled: bool) -> Result<(), anyhow::Error> {
// self.airdrop_ui_enabled = airdrop_ui_enabled;
// self.update_config_file().await?;
// Ok(())
// }

pub fn should_auto_launch(&self) -> bool {
self.should_auto_launch
}
Expand All @@ -512,6 +502,15 @@ impl AppConfig {
Ok(())
}

pub async fn set_replayed_ids(
&mut self,
replayed_ids: Vec<String>,
) -> Result<(), anyhow::Error> {
self.replayed_ids = replayed_ids;
self.update_config_file().await?;
Ok(())
}

pub async fn set_allow_telemetry(
&mut self,
allow_telemetry: bool,
Expand Down Expand Up @@ -622,7 +621,6 @@ impl AppConfig {
version: self.config_version,
mode: MiningMode::to_str(self.mode),
display_mode: DisplayMode::to_str(self.display_mode),
auto_mining: self.auto_mining,
mine_on_app_start: self.mine_on_app_start,
p2pool_enabled: self.p2pool_enabled,
last_binaries_update_timestamp: self.last_binaries_update_timestamp,
Expand All @@ -635,7 +633,6 @@ impl AppConfig {
should_always_use_system_language: self.should_always_use_system_language,
should_auto_launch: self.should_auto_launch,
application_language: self.application_language.clone(),
airdrop_ui_enabled: self.airdrop_ui_enabled,
paper_wallet_enabled: self.paper_wallet_enabled,
custom_max_cpu_usage: self.custom_max_cpu_usage,
custom_max_gpu_usage: self.custom_max_gpu_usage,
Expand All @@ -652,6 +649,7 @@ impl AppConfig {
custom_power_levels_enabled: self.custom_power_levels_enabled,
sharing_enabled: self.sharing_enabled,
visual_mode: self.visual_mode,
replayed_ids: self.replayed_ids.clone(),
};
let config = serde_json::to_string(config)?;
debug!(target: LOG_TARGET, "Updating config file: {:?} {:?}", file, self.clone());
Expand Down
97 changes: 59 additions & 38 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1899,6 +1899,27 @@ async fn close_splashscreen(window: Window) {
.expect("could not show");
}

#[tauri::command]
async fn set_replayed_ids<'r>(
replayed_ids: Vec<String>,
state: tauri::State<'_, UniverseAppState>,
) -> Result<(), String> {
let timer = Instant::now();
let mut config = state.config.write().await;
config
.set_replayed_ids(replayed_ids)
.await
.inspect_err(|e| error!("error at set_replayed_ids {:?}", e))
.map_err(|e| e.to_string())?;
if timer.elapsed() > MAX_ACCEPTABLE_COMMAND_TIME {
warn!(target: LOG_TARGET,
"set_replayed_ids took too long: {:?}",
timer.elapsed()
);
}
Ok(())
}

#[derive(Debug, Serialize, Clone)]
pub struct CpuMinerMetrics {
// hardware: Vec<PublicDeviceProperties>,
Expand Down Expand Up @@ -2208,53 +2229,53 @@ fn main() {
})
.invoke_handler(tauri::generate_handler![
close_splashscreen,
setup_application,
start_mining,
stop_mining,
set_p2pool_enabled,
set_mode,
set_display_mode,
open_log_dir,
get_seed_words,
get_applications_versions,
send_feedback,
update_applications,
log_web_message,
set_allow_telemetry,
set_airdrop_access_token,
download_and_start_installer,
exit_application,
fetch_tor_bridges,
get_app_config,
get_app_id,
get_app_in_memory_config,
set_monero_address,
update_applications,
reset_settings,
set_gpu_mining_enabled,
set_cpu_mining_enabled,
restart_application,
resolve_application_language,
set_application_language,
set_mine_on_app_start,
get_applications_versions,
get_external_dependencies,
get_max_consumption_levels,
get_miner_metrics,
get_app_config,
get_p2pool_stats,
get_tari_wallet_details,
get_paper_wallet_details,
exit_application,
set_excluded_gpu_devices,
set_should_always_use_system_language,
set_should_auto_launch,
download_and_start_installer,
get_external_dependencies,
set_use_tor,
get_seed_words,
get_tari_wallet_details,
get_tor_config,
get_tor_entry_guards,
get_transaction_history,
import_seed_words,
log_web_message,
open_log_dir,
reset_settings,
resolve_application_language,
restart_application,
send_feedback,
set_airdrop_access_token,
set_allow_telemetry,
set_application_language,
set_auto_update,
get_tor_config,
get_max_consumption_levels,
set_tor_config,
fetch_tor_bridges,
set_cpu_mining_enabled,
set_display_mode,
set_excluded_gpu_devices,
set_gpu_mining_enabled,
set_mine_on_app_start,
set_mode,
set_monero_address,
set_monerod_config,
get_tor_entry_guards,
set_visual_mode
set_p2pool_enabled,
set_replayed_ids,
set_should_always_use_system_language,
set_should_auto_launch,
set_tor_config,
set_use_tor,
set_visual_mode,
setup_application,
start_mining,
stop_mining,
update_applications,
])
.build(tauri::generate_context!())
.inspect_err(
Expand Down
7 changes: 5 additions & 2 deletions src/containers/main/SideBar/components/Wallet/Wallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ export default function Wallet() {
const isTransactionLoading = useWalletStore((s) => s.isTransactionLoading);
const setShowPaperWalletModal = usePaperWalletStore((s) => s.setShowModal);
const paperWalletEnabled = useAppConfigStore((s) => s.paper_wallet_enabled);
const historyItemRecapData = useBlockchainVisualisationStore((s) => s.historyItemRecapData);
const replayedIds = useAppConfigStore((s) => s.replayed_ids);
const historyItemRecapData = transactions.filter((tx) => !replayedIds?.includes(tx.tx_id));

Check failure on line 37 in src/containers/main/SideBar/components/Wallet/Wallet.tsx

View workflow job for this annotation

GitHub Actions / tauri-build

Argument of type 'number' is not assignable to parameter of type 'string'.

const fetchTx = useFetchTx();
const formatted = useFormatBalance(balance || 0);
Expand Down Expand Up @@ -78,7 +79,9 @@ export default function Wallet() {
</WalletBalanceContainer>
);

const rewardCount = historyItemRecapData?.count || 0;
console.debug(historyItemRecapData);

const rewardCount = historyItemRecapData?.length || 0;
const showCount = rewardCount > 0 && !showHistory;

return (
Expand Down
1 change: 0 additions & 1 deletion src/hooks/mining/useEarningsRecap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export default function useEarningsRecap() {
const count = missedWins.length;
if (count > 0) {
const totalEarnings = missedWins.reduce((earnings, cur) => earnings + cur.amount, 0);

handleWinRecap({ count, totalEarnings });
}
}
Expand Down
12 changes: 10 additions & 2 deletions src/store/useAppConfigStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ interface Actions {
setMonerodConfig: (use_monero_fail: boolean, monero_nodes: string[]) => Promise<void>;
setTheme: (theme: displayMode) => Promise<void>;
setVisualMode: (enabled: boolean) => void;
setReplayedIds: (replayedIds: string[]) => void;
}

type AppConfigStoreState = State & Actions;
Expand All @@ -41,7 +42,7 @@ const initialState: State = {
config_version: 0,
config_file: undefined,
mode: 'Eco',
auto_mining: true,

mine_on_app_start: false,
p2pool_enabled: false,
last_binaries_update_timestamp: '0',
Expand All @@ -51,7 +52,7 @@ const initialState: State = {
gpu_mining_enabled: true,
cpu_mining_enabled: true,
sharing_enabled: true,
airdrop_ui_enabled: false,

paper_wallet_enabled: false,
custom_power_levels_enabled: true,
use_tor: true,
Expand Down Expand Up @@ -293,4 +294,11 @@ export const useAppConfigStore = create<AppConfigStoreState>()((set, getState) =
set({ visual_mode: !enabled });
});
},
setReplayedIds: (replayedIds) => {
invoke('set_replayed_ids', { replayedIds })
.then(() => {
set((state) => ({ ...state, replayed_ids: replayedIds }));
})
.catch((e) => console.error('Could not set replayed_ids', e));
},
}));
6 changes: 4 additions & 2 deletions src/store/useBlockchainVisualisationStore.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Transaction } from '@app/types/wallet';
import { create } from './create';
import { useMiningStore } from './useMiningStore.ts';

Expand All @@ -17,7 +18,7 @@ interface State {
displayBlockHeight?: number;
earnings?: number;
recapData?: Recap;
historyItemRecapData?: Recap;
historyItemRecapData?: Transaction[];
recapIds: TransactionInfo['tx_id'][];
}

Expand All @@ -29,6 +30,7 @@ interface Actions {
setDisplayBlockHeight: (displayBlockHeight: number) => void;
setDisplayBlockTime: (displayBlockTime: BlockTimeData) => void;
setDebugBlockTime: (displayBlockTime: BlockTimeData) => void;
setHistoryItemRecapData: (historyItemRecap: Transaction[]) => void;
}

type BlockchainVisualisationStoreState = State & Actions;
Expand Down Expand Up @@ -65,7 +67,6 @@ export const useBlockchainVisualisationStore = create<BlockchainVisualisationSto
setAnimationState(successTier);

set({ recapData });
set({ historyItemRecapData: recapData });

setTimeout(() => {
useMiningStore.getState().setMiningControlsEnabled(true);
Expand Down Expand Up @@ -120,4 +121,5 @@ export const useBlockchainVisualisationStore = create<BlockchainVisualisationSto
setDisplayBlockHeight: (displayBlockHeight) => set({ displayBlockHeight }),
setDisplayBlockTime: (displayBlockTime) => set({ displayBlockTime }),
setDebugBlockTime: (debugBlockTime) => set({ debugBlockTime }),
setHistoryItemRecapData: (historyItemRecapData) => set({ historyItemRecapData }),
}));
Loading

0 comments on commit af120cc

Please sign in to comment.