feat: add platform risk summary to admin dashboard
- Introduced a new method to determine if platform risk should be included based on admin permissions and scope. - Enhanced the dashboard output to include platform risk details when applicable, consolidating risk data for better visibility. - Removed the deprecated platformRiskSummary method to streamline the codebase.
This commit is contained in:
@@ -110,6 +110,14 @@ final class AdminDashboardSnapshotBuilder
|
||||
$out['finance'] = $this->financeSummary($draw, $scope);
|
||||
$out['draw'] = $this->drawPanel($draw);
|
||||
$out['risk'] = $this->riskPanel($draw);
|
||||
|
||||
if ($this->includesPlatformRisk($admin, $scope)) {
|
||||
$out['platform_risk'] = [
|
||||
'locked_amount' => $out['risk']['locked_amount'],
|
||||
'cap_amount' => $out['risk']['cap_amount'],
|
||||
'usage_percent' => $out['risk']['usage_percent'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return $out;
|
||||
@@ -128,11 +136,17 @@ final class AdminDashboardSnapshotBuilder
|
||||
&& $scope->effectiveRequestedSiteCode() === null
|
||||
&& $scope->effectiveRequestedAgentNodeId() === null
|
||||
) {
|
||||
$out['platform_risk'] = $this->platformRiskSummary();
|
||||
$out['result_batch_queue'] = $this->resultBatchQueue();
|
||||
}
|
||||
}
|
||||
|
||||
private function includesPlatformRisk(AdminUser $admin, AdminScopeContext $scope): bool
|
||||
{
|
||||
return $admin->isSuperAdmin()
|
||||
&& $scope->effectiveRequestedSiteCode() === null
|
||||
&& $scope->effectiveRequestedAgentNodeId() === null;
|
||||
}
|
||||
|
||||
private function canDrawFinanceAndRisk(AdminUser $admin): bool
|
||||
{
|
||||
return $admin->hasPermissionCode('dashboard.view')
|
||||
@@ -295,23 +309,6 @@ final class AdminDashboardSnapshotBuilder
|
||||
];
|
||||
}
|
||||
|
||||
/** @return array{locked_amount: int, cap_amount: int, usage_percent: float} */
|
||||
private function platformRiskSummary(): array
|
||||
{
|
||||
$sums = RiskPool::query()
|
||||
->selectRaw('COALESCE(SUM(locked_amount), 0) as locked, COALESCE(SUM(total_cap_amount), 0) as cap')
|
||||
->first();
|
||||
|
||||
$locked = (int) (($sums?->locked) ?? 0);
|
||||
$cap = (int) (($sums?->cap) ?? 0);
|
||||
|
||||
return [
|
||||
'locked_amount' => $locked,
|
||||
'cap_amount' => $cap,
|
||||
'usage_percent' => $cap > 0 ? round(($locked / $cap) * 100, 4) : 0.0,
|
||||
];
|
||||
}
|
||||
|
||||
/** @return array<string, mixed> */
|
||||
private function drawPanel(Draw $draw): array
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user