Skip to content

Refactor credit runout calculation and simplify related logic - #1351

Open
simbabimba-dev wants to merge 8 commits into
Ctrlpanel-gg:developmentfrom
simbabimba-dev:development
Open

Refactor credit runout calculation and simplify related logic#1351
simbabimba-dev wants to merge 8 commits into
Ctrlpanel-gg:developmentfrom
simbabimba-dev:development

Conversation

@simbabimba-dev

Copy link
Copy Markdown
Collaborator

Very self explanatory, simplifies the credit runout estimate timer as it was before

Copilot AI review requested due to automatic review settings May 20, 2026 16:13

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Comment thread app/Http/Controllers/HomeController.php Outdated
Comment thread app/Http/Controllers/HomeController.php Outdated

@MrWeez MrWeez left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And general thing: previously message contained ranout date, but you're including value now. Doesn't make sense to show duplicate information. It should be either date or just text

Comment thread app/Http/Controllers/HomeController.php Outdated
@simbabimba-dev

Copy link
Copy Markdown
Collaborator Author

And general thing: previously message contained ranout date, but you're including value now. Doesn't make sense to show duplicate information. It should be either date or just text

resolved, i added the date instead
image

@simbabimba-dev
simbabimba-dev requested a review from MrWeez May 24, 2026 03:20
@simbabimba-dev

Copy link
Copy Markdown
Collaborator Author

I have read and agree to the CLA.

@MrWeez

MrWeez commented May 26, 2026

Copy link
Copy Markdown
Collaborator

@simbabimba-dev have you checked all scenarios? Including when time left should display 1 day and x hours until ranout?

@MrWeez MrWeez left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one thing, otherwise LGTM

Comment thread app/Http/Controllers/HomeController.php Outdated
'unit' => 'minute',
'bg' => self::TIME_LEFT_BG_DANGER
];
return $hoursLeft < 1 ? __('You ran out of Credits') : strval($hoursLeft);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return $hoursLeft < 1 ? __('You ran out of Credits') : strval($hoursLeft);
return $hoursLeft < 1 ? __('You ran out of Credits') : strval(number_format($hoursLeft, 0));

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do

@simbabimba-dev

Copy link
Copy Markdown
Collaborator Author

@simbabimba-dev have you checked all scenarios? Including when time left should display 1 day and x hours until ranout?

right now, it just shows hours, but im editing it to show it in days too

@simbabimba-dev

Copy link
Copy Markdown
Collaborator Author
image

@MrWeez MrWeez left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment on lines +54 to +57
public function getTimeLeftBoxUnit(float $daysLeft, float $hoursLeft)
{
if (!$date) return null;

$now = now();
$daysLeft = $now->diffInDays($date, false);
$hoursLeft = $now->diffInHours($date, false);
$minutesLeft = $now->diffInMinutes($date, false);

if ($daysLeft > 1) {
return [
'value' => floor($daysLeft),
'unit' => 'days',
'bg' => $daysLeft >= 15 ? self::TIME_LEFT_BG_SUCCESS :
($daysLeft <= 7 ? self::TIME_LEFT_BG_DANGER : self::TIME_LEFT_BG_WARNING)
];
return null;
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dead function: always returns null (marked deprecated in the docblock), but it's still called in index() and the result is passed into the view. Either drop the call + method, or leave a comment explaining why it's kept

Comment on lines +12 to +15
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\URL;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused imports

return $this->calculateCreditRunout($user, $credits);
});
/** Build our Time-Left-Box */
if ($credits > 10 && $usage > 0) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why 10 credits and not 0 as it was?

'simulation_steps' => []
];
if ($daysLeft >= 15) {
return $this::TIME_LEFT_BG_SUCCESS;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works, but since these are class constants, self:: is more idiomatic than $this::

Comment on lines +88 to +89
$usage = Auth::user()->creditUsage();
$credits = Auth::user()->credits;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Auth::user() is called 4 times in index(). Previously it was cached in $user = Auth::user() once. Not a functional issue, but reintroducing the local variable would be more readable

@MrWeez

MrWeez commented Jul 27, 2026

Copy link
Copy Markdown
Collaborator

After resolving this can be merged

@MrWeez MrWeez added the Low Priority Can wait, not urgent. Handle when possible label Jul 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Low Priority Can wait, not urgent. Handle when possible

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect Server Rental Expiry Estimation – Stuck at “41 Days” Regardless of User Credit

3 participants