Skip to content

Commit

Permalink
PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
enjinabner committed Aug 20, 2024
1 parent 9a88a0f commit a1aac1c
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 12 deletions.
3 changes: 2 additions & 1 deletion lang/en/input_type.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
'claim_token.description' => 'The claimable tokens.',
'claim_token.field.tokenId' => 'The token chain IDs available to claim.',
'claim_token.field.tokenIdDataUpload' => 'You can use this to upload a txt file that contains a list of token ID ranges, one per line.',
'claim_token.field.claimQuantity' => 'The total amount of times each token ID can be claimed. This is mainly relevant for fungible tokens, where you can specify that there are a certain amount of claims for a token ID, e.g. 10 individual claims to receive 1 token with ID 123 per claim. This field will be ingored when creating beam packs.',
'claim_token.field.claimQuantity' => 'The total amount of times each token ID can be claimed. This is mainly relevant for fungible tokens, where you can specify that there are a certain amount of claims for a token ID, e.g. 10 individual claims to receive 1 token with ID 123 per claim.',
'claim_token.field.tokenQuantityPerClaim' => 'The quantity of token that can be received per claim.',
'beam_pack.description' => 'The beam pack.',
'beam_pack.field.id' => 'The beam pack database ID, which can be null when creating a new beam pack.',
'beam_pack.field.beam_pack' => 'The number of times this pack can be claimed.',
];
3 changes: 3 additions & 0 deletions lang/en/type.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,7 @@
'beam_scan.field.walletPublicKey' => 'The wallet public key.',
'integer_range.description' => "A string value that can be used to represent a range of integer numbers. Use a double full stop to supply a range between 2 integers. \n\nExample \[\"1\",\"2\",\"3..8\"\]",
'attribute.description' => 'An initial attribute to set for the token when minting on demand.',
'beam_pack.description' => 'The beam pack.',
'beam_pack.field.id' => 'The beam pack internal ID.',
'beam_pack.field.isClaimed' => 'The flag that determines if the beam pack is claimed.',
];
5 changes: 5 additions & 0 deletions lang/en/union.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

return [
'claim_union.description' => 'The beam claim can be of either type: BeamPack or BeamClaim',
];
9 changes: 9 additions & 0 deletions src/GraphQL/Traits/HasTokenInputRules.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,15 @@ public function packTokenRules(array $args, ?string $collectionId = null, bool $
'min:1',
new MaxTokenSupply($collectionId),
],
'packs.*.tokens.*.claimQuantity' => [
'prohibited',
],
'packs.claimQuantity' => [
'bail',
'integer',
'min:1',
'max:1000',
],
];
}
}
4 changes: 2 additions & 2 deletions src/GraphQL/Types/BeamPackType.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function fields(): array
return [
'id' => [
'type' => GraphQL::type('Int'),
'description' => __('enjin-platform-beam::type.beam_claim.field.id'),
'description' => __('enjin-platform-beam::type.beam_pack.field.id'),
],
'code' => [
'type' => GraphQL::type('String!'),
Expand All @@ -42,7 +42,7 @@ public function fields(): array
],
'isClaimed' => [
'type' => GraphQL::type('Boolean!'),
'description' => __('enjin-platform-beam::type.beam_claim.field.code'),
'description' => __('enjin-platform-beam::type.beam_pack.field.isClaimed'),
'alias' => 'is_claimed',
],
'beam' => [
Expand Down
5 changes: 5 additions & 0 deletions src/GraphQL/Types/Input/BeamPackInputType.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ public function fields(): array
'type' => GraphQL::type('[ClaimToken!]!'),
'description' => __('enjin-platform-beam::input_type.claim_token.description'),
],
'claimQuantity' => [
'type' => GraphQL::type('Int'),
'description' => __('enjin-platform-beam::input_type.beam_pack.field.beam_pack'),
'defaultValue' => 1,
],
];
}
}
1 change: 0 additions & 1 deletion src/GraphQL/Types/Input/ClaimTokenInputType.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public function fields(): array
'type' => GraphQL::type('Int'),
'description' => __('enjin-platform-beam::input_type.claim_token.field.claimQuantity'),
'rules' => ['integer'],
'defaultValue' => 1,
],
'type' => [
'type' => GraphQL::type('BeamType'),
Expand Down
2 changes: 1 addition & 1 deletion src/GraphQL/Unions/ClaimUnion.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function attributes(): array
{
return [
'name' => 'ClaimUnion',
'description' => __('enjin-platform-marketplace::union.listing_data.description'),
'description' => __('enjin-platform-beam::union.claim_union.description'),
];
}

Expand Down
6 changes: 4 additions & 2 deletions src/Rules/MaxTokenCount.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ public function validate(string $attribute, mixed $value, Closure $fail): void
return collect(Arr::get($token, 'tokenIds'))->reduce(function ($val, $tokenId) use ($token) {
$range = $this->integerRange($tokenId);

$claimQuantity = Arr::get($token, 'claimQuantity', 1);

return $val + (
$range === false
? $token['claimQuantity']
: (($range[1] - $range[0]) + 1) * $token['claimQuantity']
? $claimQuantity
: (($range[1] - $range[0]) + 1) * $claimQuantity
);
}, $carry);
}, 0)
Expand Down
18 changes: 13 additions & 5 deletions src/Services/BeamService.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use Illuminate\Contracts\Cache\LockTimeoutException;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\LazyCollection;
Expand Down Expand Up @@ -125,7 +126,10 @@ public function createPackClaims(Model $beam, array $packs, bool $isNew = false)
'nonce' => 1,
]);

$tokens = collect($pack['tokens']);
$tokens = Collection::times(
Arr::get($pack, 'claimQuantity', 1),
fn () => $pack['tokens']
)->flatMap(fn ($rows) => $rows);
$tokenIds = $tokens->whereNotNull('tokenIds');

if ($tokenIds->count()) {
Expand Down Expand Up @@ -537,10 +541,12 @@ protected function createClaims(Model $beam, array $tokens): int
return collect($token['tokenIds'])->reduce(function ($val, $tokenId) use ($token) {
$range = $this->integerRange($tokenId);

$claimQuantity = Arr::get($token, 'claimQuantity', 1);

return $val + (
$range === false
? $token['claimQuantity']
: (($range[1] - $range[0]) + 1) * $token['claimQuantity']
? $claimQuantity
: (($range[1] - $range[0]) + 1) * $claimQuantity
);
}, $carry);
}, $totalClaimCount);
Expand All @@ -567,10 +573,12 @@ protected function createClaims(Model $beam, array $tokens): int
$totalClaimCount = $tokenIds->reduce(function ($carry, $tokenId) use ($token) {
$range = $this->integerRange($tokenId);

$claimQuantity = Arr::get($token, 'claimQuantity', 1);

return $carry + (
$range === false
? $token['claimQuantity']
: (($range[1] - $range[0]) + 1) * $token['claimQuantity']
? $claimQuantity
: (($range[1] - $range[0]) + 1) * $claimQuantity
);
}, $totalClaimCount);
unset($token['tokenIdDataUpload']);
Expand Down

0 comments on commit a1aac1c

Please sign in to comment.