fix(settings): push trading-hours changes to live user prices immediately

Recompute home price display on save, broadcast settings over SSE, and keep last-price status in sync without a user refresh.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-08-25 02:29:00 +03:30
co-authored by Cursor
parent 4562d00bd3
commit 8984899042
10 changed files with 300 additions and 44 deletions
+87 -3
View File
@@ -88,7 +88,7 @@ class ConfigServiceTradingHoursTest extends TestCase
$this->assertTrue($cfg->isOutsideTradingHours($fridayNoon));
}
public function test_apply_global_trading_hours_zeros_payload_when_closed(): void
public function test_apply_global_trading_hours_marks_closed_without_hiding_status_when_home_price_off(): void
{
$weekly = json_encode([
'mode' => 'per_day',
@@ -100,6 +100,7 @@ class ConfigServiceTradingHoursTest extends TestCase
$cfg = $this->cfg([
'close_price' => 'true',
'show_home_price_when_closed' => 'false',
'show_last_price' => 'false',
'startDay' => '08:30',
'endDay' => '21:30',
'trading_hours_by_day' => $weekly,
@@ -108,7 +109,7 @@ class ConfigServiceTradingHoursTest extends TestCase
$now = Carbon::create(2026, 8, 24, 21, 15, 0);
Carbon::setTestNow($now);
$result = $cfg->applyGlobalTradingHoursToPayload([
$result = $cfg->applyHomePriceDisplayState([
'sell' => 100,
'buy' => 110,
'price' => 105,
@@ -118,8 +119,91 @@ class ConfigServiceTradingHoursTest extends TestCase
$this->assertTrue($result['closed']);
$this->assertSame('closed', $result['status']);
$this->assertSame(0, $result['price']);
Carbon::setTestNow();
}
public function test_outside_hours_shows_last_price_when_home_price_when_closed_is_on(): void
{
$cfg = $this->cfg([
'close_price' => 'true',
'show_home_price_when_closed' => 'true',
'show_last_price' => 'false',
'startDay' => '11:00',
'endDay' => '20:30',
]);
$now = Carbon::create(2026, 8, 25, 2, 3, 0);
Carbon::setTestNow($now);
$result = $cfg->applyHomePriceDisplayState([
'sell' => 168000000,
'buy' => 168798112,
'price' => 168798112,
'closed' => false,
'status' => 'open',
]);
$this->assertTrue($result['closed']);
$this->assertSame('open', $result['status']);
$this->assertSame(168798112, $result['buy']);
Carbon::setTestNow();
}
public function test_close_price_off_with_no_quote_is_no_quote(): void
{
$cfg = $this->cfg([
'close_price' => 'false',
'show_last_price' => 'false',
'show_home_price_when_closed' => 'false',
'startDay' => '11:00',
'endDay' => '20:30',
]);
$result = $cfg->applyHomePriceDisplayState([
'sell' => 0,
'buy' => 0,
'price' => 0,
'closed' => false,
]);
$this->assertFalse($result['closed']);
$this->assertSame('no_quote', $result['status']);
}
public function test_inside_hours_with_quote_is_open(): void
{
$cfg = $this->cfg([
'close_price' => 'true',
'show_last_price' => 'false',
'show_home_price_when_closed' => 'false',
'startDay' => '11:00',
'endDay' => '20:30',
]);
$now = Carbon::create(2026, 8, 25, 12, 0, 0);
Carbon::setTestNow($now);
$result = $cfg->applyHomePriceDisplayState([
'sell' => 100,
'buy' => 110,
'price' => 105,
]);
$this->assertFalse($result['closed']);
$this->assertSame('open', $result['status']);
Carbon::setTestNow();
}
public function test_trading_hours_setting_keys(): void
{
$cfg = new ConfigService();
$this->assertTrue($cfg->isTradingHoursSettingKey('close_price'));
$this->assertTrue($cfg->isTradingHoursSettingKey('trading_hours_by_day'));
$this->assertTrue($cfg->isTradingHoursSettingKey('show_home_price_when_closed'));
$this->assertFalse($cfg->isTradingHoursSettingKey('name_fa'));
}
}