From bfa09e0056395983030314e1fdfe954b1e00c4ab Mon Sep 17 00:00:00 2001 From: Vaibhav Date: Fri, 19 Jan 2024 19:03:54 +0530 Subject: [PATCH 1/6] chore: check-code should fail on clippy warnings --- Cargo.toml | 4 ++++ src/lib.rs | 3 +++ 2 files changed, 7 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 3eed7cc..895f3b4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,6 +6,10 @@ version = "0.1.7-dev" edition = "2021" license = "MIT" +[features] + +fail-on-warnings = [] + # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] diff --git a/src/lib.rs b/src/lib.rs index 6126235..f8f56ec 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,6 @@ +#![cfg_attr(feature = "fail-on-warnings", deny(warnings))] +#![cfg_attr(feature = "fail-on-warnings", deny(clippy::all))] + mod app; mod client; From 50fc65be48743c64d0ec84d2bdc3e4087d0b43cb Mon Sep 17 00:00:00 2001 From: Siddharth Tiwari Date: Fri, 19 Jan 2024 20:33:48 +0530 Subject: [PATCH 2/6] refactor: removing warnings --- src/app/errors/payment_error.rs | 3 - src/app/operations/batch.rs | 20 ++--- src/app/operations/request_code.rs | 2 +- src/app/operations/wallet.rs | 2 +- src/app/server/mod.rs | 122 +++++++++++++++++++++++++- src/app/server/server.rs | 122 -------------------------- src/client/queries.rs | 2 +- src/client/requests/default_wallet.rs | 4 +- src/client/requests/intraledger.rs | 8 +- src/client/requests/onchain.rs | 4 +- src/client/requests/set_username.rs | 4 +- src/client/types.rs | 4 +- 12 files changed, 146 insertions(+), 151 deletions(-) delete mode 100644 src/app/server/server.rs diff --git a/src/app/errors/payment_error.rs b/src/app/errors/payment_error.rs index 298618f..bf2748a 100644 --- a/src/app/errors/payment_error.rs +++ b/src/app/errors/payment_error.rs @@ -1,4 +1,3 @@ -use csv::StringRecord; use thiserror::Error; #[derive(Error, Debug)] @@ -16,8 +15,6 @@ pub enum PaymentError { #[error("Failed to collect records from CSV file.")] FailedToGetRecords, #[error("No username found for the record {:?}", 0)] - NoUsernameFound(StringRecord), - #[error("Username {0} does not exist")] UsernameDoesNotExist(String), #[error("Insufficient balance in the sender's wallet")] InsufficientBalance, diff --git a/src/app/operations/batch.rs b/src/app/operations/batch.rs index c5fb155..7250a22 100644 --- a/src/app/operations/batch.rs +++ b/src/app/operations/batch.rs @@ -55,7 +55,7 @@ impl QueryMeMe { } pub fn get_default_wallet_currency(&self) -> Option<&WalletCurrency> { - let default_wallet_id = &self.default_account.default_wallet_id; + let default_wallet_id = &self.default_account.id; self.default_account .wallets .iter() @@ -173,8 +173,8 @@ pub fn validate_csv( } let currency = match currency { - "SATS" => AmountCurrency::SATS, - "USD" => AmountCurrency::USD, + "SATS" => AmountCurrency::Sats, + "USD" => AmountCurrency::Usd, _ => return Err(PaymentError::IncorrectCSVFormat), }; @@ -186,14 +186,14 @@ pub fn validate_csv( //amount for SATS will be whole number and for USD max 2 decimals let formatted_amount = match currency { - AmountCurrency::SATS => amount.round_dp(0), - AmountCurrency::USD => { + AmountCurrency::Sats => amount.round_dp(0), + AmountCurrency::Usd => { amount.round_dp_with_strategy(2, RoundingStrategy::MidpointAwayFromZero) } }; //if currency is SATS then wallet should be BTC - if currency == AmountCurrency::SATS && wallet_currency != WalletCurrency::BTC { + if currency == AmountCurrency::Sats && wallet_currency != WalletCurrency::BTC { return Err(PaymentError::IncorrectCSVFormat); } @@ -339,11 +339,11 @@ impl App { let currency = &record.currency; let wallet_type = &record.wallet_currency; - if currency == &AmountCurrency::SATS && wallet_type == &WalletCurrency::BTC { + if currency == &AmountCurrency::Sats && wallet_type == &WalletCurrency::BTC { total_amount_payable.btc_wallet.sats += amount; - } else if currency == &AmountCurrency::USD && wallet_type == &WalletCurrency::BTC { + } else if currency == &AmountCurrency::Usd && wallet_type == &WalletCurrency::BTC { total_amount_payable.btc_wallet.usd += amount; - } else if currency == &AmountCurrency::USD && wallet_type == &WalletCurrency::USD { + } else if currency == &AmountCurrency::Usd && wallet_type == &WalletCurrency::USD { total_amount_payable.usd_wallet.usd += amount; } @@ -423,7 +423,7 @@ impl App { } WalletCurrency::BTC => { let mut final_amount = amount; - if currency == AmountCurrency::USD { + if currency == AmountCurrency::Usd { final_amount = convert_usd_to_btc_sats(amount, &btc_sat_price); } self.client diff --git a/src/app/operations/request_code.rs b/src/app/operations/request_code.rs index d8697f8..00d02b3 100644 --- a/src/app/operations/request_code.rs +++ b/src/app/operations/request_code.rs @@ -2,7 +2,7 @@ use anyhow::Context; use std::net::TcpListener; use webbrowser; -use crate::app::{file_manager, server::server::run, App}; +use crate::app::{file_manager, server::run, App}; const PORT: u16 = 42909; diff --git a/src/app/operations/wallet.rs b/src/app/operations/wallet.rs index 51ab865..491034b 100644 --- a/src/app/operations/wallet.rs +++ b/src/app/operations/wallet.rs @@ -61,7 +61,7 @@ impl App { wallet_ids: Vec, ) -> anyhow::Result<()> { let me = self.client.me().await?; - let default_wallet_id = me.default_account.default_wallet_id; + let default_wallet_id = me.default_account.id; let wallets = &me.default_account.wallets; let wallet_ids_set: HashSet<_> = wallet_ids.into_iter().collect(); diff --git a/src/app/server/mod.rs b/src/app/server/mod.rs index 74f47ad..adc97af 100644 --- a/src/app/server/mod.rs +++ b/src/app/server/mod.rs @@ -1 +1,121 @@ -pub mod server; +use actix_web::{web, App, HttpResponse, HttpServer, Responder}; +use mime_guess::from_path; +use rust_embed::RustEmbed; +use serde::{Deserialize, Serialize}; +use tera::{Context, Tera}; + +use graphql_client::reqwest::post_graphql; +use reqwest::Client; + +use std::net::TcpListener; + +use crate::client::queries::{captcha_request_auth_code, CaptchaChallenge, CaptchaRequestAuthCode}; + +struct AppData { + tera: Tera, + phone: String, + api: String, + captcha_challenge_result: CaptchaChallenge, +} + +#[actix_web::get("/login")] +async fn login(appdata: web::Data) -> impl Responder { + let mut ctx = Context::new(); + + ctx.insert("id", &appdata.captcha_challenge_result.id); + ctx.insert("new_captcha", &appdata.captcha_challenge_result.new_captcha); + ctx.insert( + "failback_mode", + &appdata.captcha_challenge_result.failback_mode, + ); + ctx.insert( + "challenge_code", + &appdata.captcha_challenge_result.challenge_code, + ); + + let rendered = appdata.tera.render("login.tera.html", &ctx).unwrap(); + HttpResponse::Ok().body(rendered) +} + +#[derive(Debug, Serialize, Deserialize)] +struct GeetestResponse { + geetest_challenge: String, + geetest_seccode: String, + geetest_validate: String, +} + +#[actix_web::post("/solve")] +async fn solve(r: web::Json, appdata: web::Data) -> impl Responder { + println!("Captcha Solved, you may close the browser and return to the CLI."); + + let client = Client::builder().build().expect("Can't build client"); + + let input = captcha_request_auth_code::CaptchaRequestAuthCodeInput { + challenge_code: r.geetest_challenge.clone(), + phone: appdata.phone.clone(), + sec_code: r.geetest_seccode.clone(), + validation_code: r.geetest_validate.clone(), + channel: None, + }; + let variables = captcha_request_auth_code::Variables { input }; + + let response_body = + post_graphql::(&client, appdata.api.clone(), variables).await; + + match response_body { + Ok(_) => println!("Phone Code sent successfully to {}", appdata.phone), + Err(_) => { + println!("Phone Code couldn't be send.") + } + }; + + tokio::spawn(async { + std::process::exit(0); + }); + + HttpResponse::Ok() +} + +#[derive(RustEmbed)] +#[folder = "src/app/server/public/"] +struct Asset; + +#[actix_web::get("/static/{_:.*}")] +async fn static_dir(path: web::Path) -> impl Responder { + match Asset::get(&path) { + Some(content) => HttpResponse::Ok() + .content_type(from_path(path.as_str()).first_or_octet_stream().as_ref()) + .body(content.data.into_owned()), + None => HttpResponse::NotFound().body("404 Not Found"), + } +} + +pub async fn run( + listener: TcpListener, + phone: String, + api: String, + captcha_challenge_result: CaptchaChallenge, +) -> anyhow::Result<()> { + let mut tera = Tera::default(); + tera.add_raw_template("login.tera.html", include_str!("./public/login.tera.html"))?; + + let appdata = web::Data::new(AppData { + tera, + phone, + api, + captcha_challenge_result, + }); + + let server = HttpServer::new(move || { + App::new() + .service(static_dir) + .service(login) + .service(solve) + .app_data(appdata.clone()) + }) + .listen(listener)? + .run(); + + server.await?; + Ok(()) +} diff --git a/src/app/server/server.rs b/src/app/server/server.rs deleted file mode 100644 index 78d11ff..0000000 --- a/src/app/server/server.rs +++ /dev/null @@ -1,122 +0,0 @@ -use actix_web::{web, App, HttpResponse, HttpServer, Responder}; -use anyhow; -use mime_guess::from_path; -use rust_embed::RustEmbed; -use serde::{Deserialize, Serialize}; -use tera::{Context, Tera}; - -use graphql_client::reqwest::post_graphql; -use reqwest::Client; - -use std::net::TcpListener; - -use crate::client::queries::{captcha_request_auth_code, CaptchaChallenge, CaptchaRequestAuthCode}; - -struct AppData { - tera: Tera, - phone: String, - api: String, - captcha_challenge_result: CaptchaChallenge, -} - -#[actix_web::get("/login")] -async fn login(appdata: web::Data) -> impl Responder { - let mut ctx = Context::new(); - - ctx.insert("id", &appdata.captcha_challenge_result.id); - ctx.insert("new_captcha", &appdata.captcha_challenge_result.new_captcha); - ctx.insert( - "failback_mode", - &appdata.captcha_challenge_result.failback_mode, - ); - ctx.insert( - "challenge_code", - &appdata.captcha_challenge_result.challenge_code, - ); - - let rendered = appdata.tera.render("login.tera.html", &ctx).unwrap(); - HttpResponse::Ok().body(rendered) -} - -#[derive(Debug, Serialize, Deserialize)] -struct GeetestResponse { - geetest_challenge: String, - geetest_seccode: String, - geetest_validate: String, -} - -#[actix_web::post("/solve")] -async fn solve(r: web::Json, appdata: web::Data) -> impl Responder { - println!("Captcha Solved, you may close the browser and return to the CLI."); - - let client = Client::builder().build().expect("Can't build client"); - - let input = captcha_request_auth_code::CaptchaRequestAuthCodeInput { - challenge_code: r.geetest_challenge.clone(), - phone: appdata.phone.clone(), - sec_code: r.geetest_seccode.clone(), - validation_code: r.geetest_validate.clone(), - channel: None, - }; - let variables = captcha_request_auth_code::Variables { input }; - - let response_body = - post_graphql::(&client, appdata.api.clone(), variables).await; - - match response_body { - Ok(_) => println!("Phone Code sent successfully to {}", appdata.phone), - Err(_) => { - println!("Phone Code couldn't be send.") - } - }; - - tokio::spawn(async { - std::process::exit(0); - }); - - HttpResponse::Ok() -} - -#[derive(RustEmbed)] -#[folder = "src/app/server/public/"] -struct Asset; - -#[actix_web::get("/static/{_:.*}")] -async fn static_dir(path: web::Path) -> impl Responder { - match Asset::get(&path) { - Some(content) => HttpResponse::Ok() - .content_type(from_path(path.as_str()).first_or_octet_stream().as_ref()) - .body(content.data.into_owned()), - None => HttpResponse::NotFound().body("404 Not Found"), - } -} - -pub async fn run( - listener: TcpListener, - phone: String, - api: String, - captcha_challenge_result: CaptchaChallenge, -) -> anyhow::Result<()> { - let mut tera = Tera::default(); - tera.add_raw_template("login.tera.html", include_str!("./public/login.tera.html"))?; - - let appdata = web::Data::new(AppData { - tera, - phone, - api, - captcha_challenge_result, - }); - - let server = HttpServer::new(move || { - App::new() - .service(static_dir) - .service(login) - .service(solve) - .app_data(appdata.clone()) - }) - .listen(listener)? - .run(); - - server.await?; - Ok(()) -} diff --git a/src/client/queries.rs b/src/client/queries.rs index 245fd3f..1dd6aa0 100644 --- a/src/client/queries.rs +++ b/src/client/queries.rs @@ -66,7 +66,7 @@ impl TryFrom for CaptchaChallenge { fn try_from(response: ResponseData) -> Result { let result = response.captcha_create_challenge.result; - let challenge = result.ok_or_else(|| CaptchaError::EmptyCaptcha)?; + let challenge = result.ok_or(CaptchaError::EmptyCaptcha)?; let (id, challenge_code, new_captcha, failback_mode) = ( challenge.id, diff --git a/src/client/requests/default_wallet.rs b/src/client/requests/default_wallet.rs index 7610db0..a14563d 100644 --- a/src/client/requests/default_wallet.rs +++ b/src/client/requests/default_wallet.rs @@ -55,9 +55,9 @@ impl GaloyClient { .collect::>() .join(", "); - return Err(ClientError::ApiError(ApiError::RequestFailedWithError( + Err(ClientError::ApiError(ApiError::RequestFailedWithError( error_string, - ))); + ))) } else { Ok(()) } diff --git a/src/client/requests/intraledger.rs b/src/client/requests/intraledger.rs index b14ac52..d083d5e 100644 --- a/src/client/requests/intraledger.rs +++ b/src/client/requests/intraledger.rs @@ -44,9 +44,9 @@ impl GaloyClient { .collect::>() .join(", "); - return Err(ClientError::ApiError(ApiError::RequestFailedWithError( + Err(ClientError::ApiError(ApiError::RequestFailedWithError( error_string, - ))); + ))) } else { Ok(()) } @@ -91,9 +91,9 @@ impl GaloyClient { .collect::>() .join(", "); - return Err(ClientError::ApiError(ApiError::RequestFailedWithError( + Err(ClientError::ApiError(ApiError::RequestFailedWithError( error_string, - ))); + ))) } else { Ok(()) } diff --git a/src/client/requests/onchain.rs b/src/client/requests/onchain.rs index 75518a8..b72ee61 100644 --- a/src/client/requests/onchain.rs +++ b/src/client/requests/onchain.rs @@ -66,9 +66,9 @@ impl GaloyClient { .collect::>() .join(", "); - return Err(ClientError::ApiError(ApiError::RequestFailedWithError( + Err(ClientError::ApiError(ApiError::RequestFailedWithError( error_string, - ))); + ))) } else { Ok(()) } diff --git a/src/client/requests/set_username.rs b/src/client/requests/set_username.rs index 873f8e1..e6d582a 100644 --- a/src/client/requests/set_username.rs +++ b/src/client/requests/set_username.rs @@ -28,9 +28,9 @@ impl GaloyClient { .collect::>() .join(", "); - return Err(ClientError::ApiError(ApiError::RequestFailedWithError( + Err(ClientError::ApiError(ApiError::RequestFailedWithError( error_string, - ))); + ))) } else { Ok(()) } diff --git a/src/client/types.rs b/src/client/types.rs index 92f6088..5f43796 100644 --- a/src/client/types.rs +++ b/src/client/types.rs @@ -9,8 +9,8 @@ pub enum Wallet { #[derive(Debug, Clone, clap::ValueEnum, PartialEq, Eq)] pub enum AmountCurrency { - SATS, - USD, + Sats, + Usd, } #[derive(Debug, Serialize)] From 0da708a092d98103ee31462622f38cb003cd2ad3 Mon Sep 17 00:00:00 2001 From: Siddharth Tiwari Date: Fri, 19 Jan 2024 20:39:16 +0530 Subject: [PATCH 3/6] refactor: fix warning for deprecated queries --- src/client/requests/set_username.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/client/requests/set_username.rs b/src/client/requests/set_username.rs index e6d582a..1e71114 100644 --- a/src/client/requests/set_username.rs +++ b/src/client/requests/set_username.rs @@ -7,6 +7,8 @@ use crate::client::{ }; impl GaloyClient { + #[allow(deprecated)] + // TODO remove this after updating user_update_username pub async fn set_username(&self, username: String) -> Result<(), ClientError> { let input = UserUpdateUsernameInput { username }; From 2dae9e2f7b5670c32a14610e07a6a8ebfa227c01 Mon Sep 17 00:00:00 2001 From: Siddharth Tiwari Date: Fri, 19 Jan 2024 20:49:02 +0530 Subject: [PATCH 4/6] chore: remove unused imports --- src/client/queries.rs | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/src/client/queries.rs b/src/client/queries.rs index 1dd6aa0..be8362c 100644 --- a/src/client/queries.rs +++ b/src/client/queries.rs @@ -34,7 +34,6 @@ pub use self::query_globals::QueryGlobalsGlobals; )] pub(super) struct UserLogin; pub use self::user_login::UserLoginInput; -pub use self::user_login::UserLoginUserLogin; #[derive(GraphQLQuery)] #[graphql( @@ -43,7 +42,6 @@ pub use self::user_login::UserLoginUserLogin; response_derives = "Debug, Serialize" )] pub(super) struct UserLogout; -pub use self::user_logout::UserLogoutInput; #[derive(GraphQLQuery)] #[graphql( @@ -52,7 +50,6 @@ pub use self::user_logout::UserLogoutInput; response_derives = "Debug, Serialize" )] pub struct CaptchaCreateChallenge; -pub use self::captcha_create_challenge::*; pub struct CaptchaChallenge { pub id: String, @@ -90,8 +87,6 @@ impl TryFrom for CaptchaChallenge { response_derives = "Debug, Serialize" )] pub struct CaptchaRequestAuthCode; -pub use self::captcha_request_auth_code::CaptchaRequestAuthCodeCaptchaRequestAuthCode; -pub use self::captcha_request_auth_code::CaptchaRequestAuthCodeInput; #[derive(GraphQLQuery)] #[graphql( @@ -127,7 +122,6 @@ pub use self::account_update_default_wallet_id::AccountUpdateDefaultWalletIdInpu response_derives = "Debug, Serialize" )] pub(super) struct QueryDefaultWallet; -pub use self::query_default_wallet::QueryDefaultWalletAccountDefaultWallet; #[derive(GraphQLQuery)] #[graphql( @@ -136,7 +130,6 @@ pub use self::query_default_wallet::QueryDefaultWalletAccountDefaultWallet; response_derives = "Debug, Serialize" )] pub(super) struct IntraLedgerPaymentSend; -pub use self::intra_ledger_payment_send::IntraLedgerPaymentSendInput; #[derive(GraphQLQuery)] #[graphql( @@ -156,8 +149,6 @@ use super::errors::captcha_error::CaptchaError; response_derives = "Debug, Serialize" )] pub(super) struct OnChainAddressCurrent; -pub use self::on_chain_address_current::OnChainAddressCurrentInput; -pub use self::on_chain_address_current::OnChainAddressCurrentOnChainAddressCurrent; #[derive(GraphQLQuery)] #[graphql( @@ -167,7 +158,6 @@ pub use self::on_chain_address_current::OnChainAddressCurrentOnChainAddressCurre )] pub(super) struct OnChainPaymentSend; pub use self::on_chain_payment_send::OnChainPaymentSendInput; -pub use self::on_chain_payment_send::OnChainPaymentSendOnChainPaymentSend; pub use self::on_chain_payment_send::PayoutSpeed; #[derive(GraphQLQuery)] @@ -178,5 +168,4 @@ pub use self::on_chain_payment_send::PayoutSpeed; )] pub(super) struct RealtimePrice; pub use self::realtime_price::RealtimePriceRealtimePrice; -pub use self::realtime_price::RealtimePriceRealtimePriceBtcSatPrice; -pub use self::realtime_price::RealtimePriceRealtimePriceUsdCentPrice; +pub use self::realtime_price::RealtimePriceRealtimePriceBtcSatPrice; \ No newline at end of file From 9a9ef5a39ea10ecfee44ba0581f621dd57422345 Mon Sep 17 00:00:00 2001 From: Siddharth Tiwari Date: Fri, 19 Jan 2024 20:52:46 +0530 Subject: [PATCH 5/6] fix: formatting --- src/client/queries.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/queries.rs b/src/client/queries.rs index be8362c..2fd3215 100644 --- a/src/client/queries.rs +++ b/src/client/queries.rs @@ -168,4 +168,4 @@ pub use self::on_chain_payment_send::PayoutSpeed; )] pub(super) struct RealtimePrice; pub use self::realtime_price::RealtimePriceRealtimePrice; -pub use self::realtime_price::RealtimePriceRealtimePriceBtcSatPrice; \ No newline at end of file +pub use self::realtime_price::RealtimePriceRealtimePriceBtcSatPrice; From 1f355cd696feaf0de900eea699e9bb94ffe68867 Mon Sep 17 00:00:00 2001 From: Siddharth Tiwari Date: Sun, 21 Jan 2024 14:42:44 +0530 Subject: [PATCH 6/6] fix: e2e --- 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(()) } }