Skip to content

Commit

Permalink
Fix claiming logic
Browse files Browse the repository at this point in the history
  • Loading branch information
enjinabner committed Jul 3, 2023
1 parent 55262cb commit fd83912
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/Jobs/ClaimBeam.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Enjin\Platform\Beam\Jobs;

use Enjin\Platform\Beam\Enums\BeamType;
use Enjin\Platform\Beam\Models\Beam;
use Enjin\Platform\Beam\Models\BeamClaim;
use Enjin\Platform\Beam\Models\BeamScan;
use Enjin\Platform\Beam\Services\BatchService;
Expand Down Expand Up @@ -88,7 +89,7 @@ public function failed(Throwable $exception): void
*/
protected function computeClaim(Model $beam): ?Model
{
$tryLimit = BeamClaim::where('beam_id', $beam->id)->claimable()->count();
$tryLimit = BeamClaim::where('beam_id', $beam->id)->claimable()->count() + count($beam->chances);
$tries = 0;
$claim = null;
do {
Expand Down
19 changes: 14 additions & 5 deletions src/Models/Laravel/Beam.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Cache;
use Staudenmeir\EloquentEagerLimit\HasEagerLimit;

Expand Down Expand Up @@ -109,13 +110,21 @@ public function hasFlag(BeamFlag $flag): bool
*/
public function getChancesAttribute(): array
{
return collect($this->probabilities)->map(function ($key, $chance) {
if ($key === 'nft') {
return ['nft' => $chance];
$chances = [];
foreach ($this->probabilities as $key => $values) {
if ($key === 'nft' && $values > 0) {
$chances['nft'] = $values;
} else {
foreach (Arr::get($values, 'ft', []) as $value) {
if ($value['chance'] > 0) {
$chances[$value['tokenId']] = $value['chance'];
}
}
}
}
arsort($chances);

return collect($chance['ft'])->map(fn ($row) => [$row['tokenId'] => $row['chance']])->all();
})->all();
return $chances;
}

/**
Expand Down

0 comments on commit fd83912

Please sign in to comment.