Skip to content

Commit

Permalink
Merge pull request #2362 from get10101/fix/order-max-quantity-validation
Browse files Browse the repository at this point in the history
fix: Subscribe to the websocket after the node has started
  • Loading branch information
holzeis authored Apr 5, 2024
2 parents b7abc7f + 7ffce2d commit ead19b7
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
5 changes: 4 additions & 1 deletion mobile/lib/features/trade/domain/trade_values.dart
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ class TradeValues {
}

_recalculateMaxQuantity() {
maxQuantity = tradeValuesService.calculateMaxQuantity(price: price, leverage: leverage);
final quantity = tradeValuesService.calculateMaxQuantity(price: price, leverage: leverage);
if (quantity != null) {
maxQuantity = quantity;
}
}
}
11 changes: 1 addition & 10 deletions mobile/native/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use crate::ln_dlc;
use crate::ln_dlc::get_storage;
use crate::logger;
use crate::max_quantity::max_quantity;
use crate::orderbook;
use crate::polls;
use crate::trade::order;
use crate::trade::order::api::NewOrder;
Expand Down Expand Up @@ -522,15 +521,7 @@ fn run_internal(

let (_health, tx) = health::Health::new(runtime);

orderbook::subscribe(
ln_dlc::get_node_key(),
runtime,
tx.orderbook,
fcm_token,
tx_websocket,
)?;

ln_dlc::run(runtime)
ln_dlc::run(runtime, tx, fcm_token, tx_websocket)
}

pub fn get_new_address() -> Result<String> {
Expand Down
19 changes: 18 additions & 1 deletion mobile/native/src/ln_dlc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ use crate::dlc::dlc_handler;
use crate::dlc::dlc_handler::DlcHandler;
use crate::event;
use crate::event::EventInternal;
use crate::health::Tx;
use crate::ln_dlc::node::Node;
use crate::ln_dlc::node::NodeStorage;
use crate::ln_dlc::node::WalletHistory;
use crate::orderbook;
use crate::position::ForceCloseDlcChannelSubscriber;
use crate::state;
use crate::storage::TenTenOneNodeStorage;
Expand Down Expand Up @@ -42,6 +44,7 @@ use bitcoin::Address;
use bitcoin::Amount;
use bitcoin::Txid;
use commons::CollaborativeRevertTraderResponse;
use commons::OrderbookRequest;
use dlc::PartyParams;
use dlc_manager::channel::Channel as DlcChannel;
use itertools::chain;
Expand Down Expand Up @@ -86,6 +89,7 @@ use std::time::SystemTime;
use time::OffsetDateTime;
use tokio::runtime;
use tokio::runtime::Runtime;
use tokio::sync::broadcast;
use tokio::sync::watch;
use tokio::task::spawn_blocking;
use uuid::Uuid;
Expand Down Expand Up @@ -262,7 +266,12 @@ pub fn get_storage() -> TenTenOneNodeStorage {
/// Start the node
///
/// Assumes that the seed has already been initialized
pub fn run(runtime: &Runtime) -> Result<()> {
pub fn run(
runtime: &Runtime,
tx: Tx,
fcm_token: String,
tx_websocket: broadcast::Sender<OrderbookRequest>,
) -> Result<()> {
runtime.block_on(async move {
event::publish(&EventInternal::Init("Starting full ldk node".to_string()));

Expand Down Expand Up @@ -318,6 +327,14 @@ pub fn run(runtime: &Runtime) -> Result<()> {
let node = Arc::new(Node::new(node, _running));
state::set_node(node.clone());

orderbook::subscribe(
node.inner.node_key(),
runtime,
tx.orderbook,
fcm_token,
tx_websocket,
)?;

if let Err(e) = spawn_blocking({
let node = node.clone();
move || keep_wallet_balance_and_history_up_to_date(&node)
Expand Down

0 comments on commit ead19b7

Please sign in to comment.