From 100c32481b7d616df82a02c14e4d47dd1422354e Mon Sep 17 00:00:00 2001 From: Siddharth Tiwari Date: Sun, 21 Jan 2024 14:42:44 +0530 Subject: [PATCH] fix: e2e test, using return --- src/app/file_manager.rs | 10 ++++------ src/app/operations/batch.rs | 3 ++- src/app/operations/wallet.rs | 3 ++- src/client/requests/auth.rs | 10 ++++------ src/client/requests/default_wallet.rs | 7 +++---- src/client/requests/intraledger.rs | 14 ++++++-------- src/client/requests/onchain.rs | 7 +++---- src/client/requests/set_username.rs | 7 +++---- 8 files changed, 27 insertions(+), 34 deletions(-) diff --git a/src/app/file_manager.rs b/src/app/file_manager.rs index c1372fa..d3358fb 100644 --- a/src/app/file_manager.rs +++ b/src/app/file_manager.rs @@ -22,10 +22,9 @@ pub fn get_data(file_type: &str) -> Result, AppError> { if file_path.exists() { let data = fs::read_to_string(&file_path) .map_err(|_| TokenError::FailedToReadToken(file_path.clone()))?; - Ok(Some(data)) - } else { - Ok(None) + return Ok(Some(data)); } + Ok(None) } pub fn save_data(file_type: &str, data: &str) -> Result<(), AppError> { @@ -48,8 +47,7 @@ pub fn remove_data(file_type: &str) -> Result<(), AppError> { if file_path.exists() { fs::remove_file(&file_path) .map_err(|_| TokenError::FailedToDeleteFile(file_path.clone()))?; - Ok(()) - } else { - Err(AppError::TokenError(TokenError::TokenFileNotFound)) + return Ok(()); } + Err(AppError::TokenError(TokenError::TokenFileNotFound)) } diff --git a/src/app/operations/batch.rs b/src/app/operations/batch.rs index 7250a22..0e23dfa 100644 --- a/src/app/operations/batch.rs +++ b/src/app/operations/batch.rs @@ -55,7 +55,8 @@ impl QueryMeMe { } pub fn get_default_wallet_currency(&self) -> Option<&WalletCurrency> { - let default_wallet_id = &self.default_account.id; + #[allow(deprecated)] + let default_wallet_id = &self.default_account.default_wallet_id; self.default_account .wallets .iter() diff --git a/src/app/operations/wallet.rs b/src/app/operations/wallet.rs index 491034b..04b0062 100644 --- a/src/app/operations/wallet.rs +++ b/src/app/operations/wallet.rs @@ -61,7 +61,8 @@ impl App { wallet_ids: Vec, ) -> anyhow::Result<()> { let me = self.client.me().await?; - let default_wallet_id = me.default_account.id; + #[allow(deprecated)] + let default_wallet_id = me.default_account.default_wallet_id; let wallets = &me.default_account.wallets; let wallet_ids_set: HashSet<_> = wallet_ids.into_iter().collect(); diff --git a/src/client/requests/auth.rs b/src/client/requests/auth.rs index fcfe969..1f885c2 100644 --- a/src/client/requests/auth.rs +++ b/src/client/requests/auth.rs @@ -140,7 +140,6 @@ impl GaloyClient { let response = Client::new().post(&url).json(&request_body).send().await; - // TODO status code coming from backend are not appropriate need, will update this when correct status codes are added. match response { Ok(resp) => match resp.status() { StatusCode::OK => Ok(true), @@ -151,12 +150,11 @@ impl GaloyClient { .await .unwrap_or_else(|_| "Unknown error".to_string()); if error_details.contains("Request failed with status code 400") { - Ok(false) - } else { - Err(ClientError::ApiError(ApiError::RequestFailedWithError( - error_details, - ))) + return Ok(false); } + Err(ClientError::ApiError(ApiError::RequestFailedWithError( + error_details, + ))) } _ => { let status = resp.status(); diff --git a/src/client/requests/default_wallet.rs b/src/client/requests/default_wallet.rs index a14563d..5aae45f 100644 --- a/src/client/requests/default_wallet.rs +++ b/src/client/requests/default_wallet.rs @@ -55,11 +55,10 @@ impl GaloyClient { .collect::>() .join(", "); - Err(ClientError::ApiError(ApiError::RequestFailedWithError( + return Err(ClientError::ApiError(ApiError::RequestFailedWithError( error_string, - ))) - } else { - Ok(()) + ))); } + Ok(()) } } diff --git a/src/client/requests/intraledger.rs b/src/client/requests/intraledger.rs index d083d5e..b570664 100644 --- a/src/client/requests/intraledger.rs +++ b/src/client/requests/intraledger.rs @@ -44,12 +44,11 @@ impl GaloyClient { .collect::>() .join(", "); - Err(ClientError::ApiError(ApiError::RequestFailedWithError( + return Err(ClientError::ApiError(ApiError::RequestFailedWithError( error_string, - ))) - } else { - Ok(()) + ))); } + Ok(()) } pub async fn intraleger_send_usd( @@ -91,11 +90,10 @@ impl GaloyClient { .collect::>() .join(", "); - Err(ClientError::ApiError(ApiError::RequestFailedWithError( + return Err(ClientError::ApiError(ApiError::RequestFailedWithError( error_string, - ))) - } else { - Ok(()) + ))); } + Ok(()) } } diff --git a/src/client/requests/onchain.rs b/src/client/requests/onchain.rs index b72ee61..78dc05d 100644 --- a/src/client/requests/onchain.rs +++ b/src/client/requests/onchain.rs @@ -66,11 +66,10 @@ impl GaloyClient { .collect::>() .join(", "); - Err(ClientError::ApiError(ApiError::RequestFailedWithError( + return Err(ClientError::ApiError(ApiError::RequestFailedWithError( error_string, - ))) - } else { - Ok(()) + ))); } + Ok(()) } } diff --git a/src/client/requests/set_username.rs b/src/client/requests/set_username.rs index 1e71114..95a0970 100644 --- a/src/client/requests/set_username.rs +++ b/src/client/requests/set_username.rs @@ -30,11 +30,10 @@ impl GaloyClient { .collect::>() .join(", "); - Err(ClientError::ApiError(ApiError::RequestFailedWithError( + return Err(ClientError::ApiError(ApiError::RequestFailedWithError( error_string, - ))) - } else { - Ok(()) + ))); } + Ok(()) } }