-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Extract non-order related functions into
users
module
These functions didn't really fit into `order` module.
- Loading branch information
1 parent
fff8b28
commit 4f4f527
Showing
4 changed files
with
64 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
pub mod order; | ||
pub mod position; | ||
pub mod users; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -165,4 +165,3 @@ impl From<OrderType> for orderbook_commons::OrderType { | |
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
use crate::commons::reqwest_client; | ||
use crate::config; | ||
use crate::ln_dlc; | ||
use anyhow::anyhow; | ||
use anyhow::Context; | ||
use anyhow::Result; | ||
use coordinator_commons::RegisterParams; | ||
use coordinator_commons::TokenUpdateParams; | ||
|
||
pub async fn update_fcm_token(fcm_token: String) -> Result<()> { | ||
let token_update = TokenUpdateParams { | ||
pubkey: ln_dlc::get_node_info()?.pubkey.to_string(), | ||
fcm_token, | ||
}; | ||
|
||
reqwest_client() | ||
.post(format!( | ||
"http://{}/api/fcm_token", | ||
config::get_http_endpoint() | ||
)) | ||
.json(&token_update) | ||
.send() | ||
.await | ||
.context("Failed to update FCM token with coordinator")? | ||
.error_for_status()?; | ||
Ok(()) | ||
} | ||
|
||
/// Enroll the user in the beta program | ||
pub async fn register_beta(email: String) -> Result<()> { | ||
let register = RegisterParams { | ||
pubkey: ln_dlc::get_node_info()?.pubkey, | ||
email: Some(email), | ||
nostr: None, | ||
}; | ||
|
||
let client = reqwest_client(); | ||
let response = client | ||
.post(format!( | ||
"http://{}/api/register", | ||
config::get_http_endpoint() | ||
)) | ||
.json(®ister) | ||
.send() | ||
.await | ||
.context("Failed to register beta program with coordinator")?; | ||
|
||
if !response.status().is_success() { | ||
let response_text = match response.text().await { | ||
Ok(text) => text, | ||
Err(err) => { | ||
format!("could not decode response {err:#}") | ||
} | ||
}; | ||
return Err(anyhow!( | ||
"Could not register email with coordinator: {response_text}" | ||
)); | ||
} | ||
tracing::info!("Registered into beta program successfully"); | ||
Ok(()) | ||
} |