From 8fd2eb4a80a8dd3f2d6f73d0ed7792e2a064f00d Mon Sep 17 00:00:00 2001 From: Zane Schepke Date: Thu, 9 Jan 2025 09:15:17 -0500 Subject: [PATCH] refactor --- .../src/commands/mod.rs | 3 ++ .../src/controller.rs | 30 +++++++++---------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/nym-vpn-core/crates/nym-vpn-account-controller/src/commands/mod.rs b/nym-vpn-core/crates/nym-vpn-account-controller/src/commands/mod.rs index 9696de26b5..88cfc9b693 100644 --- a/nym-vpn-core/crates/nym-vpn-account-controller/src/commands/mod.rs +++ b/nym-vpn-core/crates/nym-vpn-account-controller/src/commands/mod.rs @@ -76,6 +76,9 @@ pub enum AccountCommandError { #[error("no device stored")] NoDeviceStored, + #[error("device registration is in progress")] + RegistrationInProgress, + #[error("failed to remove account: {0}")] RemoveAccount(String), diff --git a/nym-vpn-core/crates/nym-vpn-account-controller/src/controller.rs b/nym-vpn-core/crates/nym-vpn-account-controller/src/controller.rs index acaead94ab..10efdc2c1f 100644 --- a/nym-vpn-core/crates/nym-vpn-account-controller/src/controller.rs +++ b/nym-vpn-core/crates/nym-vpn-account-controller/src/controller.rs @@ -3,6 +3,19 @@ use std::{path::PathBuf, sync::Arc, time::Duration}; +use nym_http_api_client::UserAgent; +use nym_vpn_api_client::{ + response::{NymVpnDevice, NymVpnUsage}, + types::{DeviceStatus, VpnApiAccount}, +}; +use nym_vpn_network_config::Network; +use nym_vpn_store::{mnemonic::Mnemonic, VpnStorage}; +use tokio::{ + sync::mpsc::{UnboundedReceiver, UnboundedSender}, + task::{JoinError, JoinSet}, +}; +use tokio_util::sync::CancellationToken; + use crate::{ commands::{ register_device::RegisterDeviceCommandHandler, @@ -16,19 +29,6 @@ use crate::{ storage::{AccountStorage, VpnCredentialStorage}, AccountControllerCommander, AvailableTicketbooks, }; -use nym_http_api_client::UserAgent; -use nym_vpn_api_client::types::DeviceStatus; -use nym_vpn_api_client::{ - response::{NymVpnDevice, NymVpnUsage}, - types::VpnApiAccount, -}; -use nym_vpn_network_config::Network; -use nym_vpn_store::{mnemonic::Mnemonic, VpnStorage}; -use tokio::{ - sync::mpsc::{UnboundedReceiver, UnboundedSender}, - task::{JoinError, JoinSet}, -}; -use tokio_util::sync::CancellationToken; // The interval at which we automatically request zk-nyms const ZK_NYM_AUTOMATIC_REQUEST_INTERVAL: Duration = Duration::from_secs(6 * 60); @@ -355,9 +355,7 @@ where if self.shared_state().is_ready_to_register_device().await == ReadyToRegisterDevice::InProgress { - return Err(AccountCommandError::Internal( - "Device registration in progress".to_owned(), - )); + return Err(AccountCommandError::RegistrationInProgress); } let device = self