From ce8b90f4eefecfe3442ab8bf4d4e67eb40582a01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josip=20Crnkovi=C4=87?= <6536260+crnkovic@users.noreply.github.com> Date: Wed, 24 Jan 2024 14:38:05 +0100 Subject: [PATCH 1/4] wip --- .../Collections/CollectionOfTheMonthData.php | 6 ++++-- app/Models/CollectionWinner.php | 2 +- app/Models/Traits/HasVolume.php | 2 +- .../WinnerCollections.blocks.tsx | 18 +++++++++++++----- .../Collections/CollectionOfTheMonthFactory.ts | 3 ++- resources/types/generated.d.ts | 2 +- 6 files changed, 22 insertions(+), 11 deletions(-) diff --git a/app/Data/Collections/CollectionOfTheMonthData.php b/app/Data/Collections/CollectionOfTheMonthData.php index fc97f75b9..9bddae120 100644 --- a/app/Data/Collections/CollectionOfTheMonthData.php +++ b/app/Data/Collections/CollectionOfTheMonthData.php @@ -4,6 +4,8 @@ namespace App\Data\Collections; +use App\Data\VolumeData; +use App\Enums\Period; use App\Models\CollectionWinner; use App\Transformers\IpfsGatewayUrlTransformer; use Spatie\LaravelData\Attributes\WithTransformer; @@ -17,7 +19,7 @@ public function __construct( #[WithTransformer(IpfsGatewayUrlTransformer::class)] public ?string $image, public int $votes, - public ?string $volume, + public VolumeData $volume, public ?string $floorPrice, public ?string $floorPriceCurrency, public ?int $floorPriceDecimals, @@ -31,7 +33,7 @@ public static function fromModel(CollectionWinner $winner): self return new self( image: $winner->collection->extra_attributes->get('image'), votes: $winner->votes, - volume: $winner->collection->volume, + volume: $winner->collection->createVolumeData(Period::MONTH), floorPrice: $winner->collection->floor_price, floorPriceCurrency: $winner->collection->floorPriceToken?->symbol, floorPriceDecimals: $winner->collection->floorPriceToken?->decimals, diff --git a/app/Models/CollectionWinner.php b/app/Models/CollectionWinner.php index eb3e78bf9..adaf3d2e6 100644 --- a/app/Models/CollectionWinner.php +++ b/app/Models/CollectionWinner.php @@ -52,7 +52,7 @@ public static function ineligibleCollectionIds(): LaravelCollection public static function getByMonth(): LaravelCollection { $winners = static::query() - ->with('collection', 'collection.floorPriceToken') + ->with('collection', 'collection.floorPriceToken', 'collection.network.nativeToken') ->orderBy('year', 'desc') ->orderBy('month', 'desc') ->get() diff --git a/app/Models/Traits/HasVolume.php b/app/Models/Traits/HasVolume.php index 00fca3d9b..c2eba658b 100644 --- a/app/Models/Traits/HasVolume.php +++ b/app/Models/Traits/HasVolume.php @@ -51,7 +51,7 @@ public function getVolume(?Period $period = null): ?string /** * Create a volume DTO based on the volume in the given period. */ - public function createVolumeData(Period $period, CurrencyCode $currency): VolumeData + public function createVolumeData(Period $period, ?CurrencyCode $currency = CurrencyCode::USD): VolumeData { $volume = $this->getVolume($period); $token = $this->nativeToken(); diff --git a/resources/js/Pages/Collections/Components/WinnerCollections/WinnerCollections.blocks.tsx b/resources/js/Pages/Collections/Components/WinnerCollections/WinnerCollections.blocks.tsx index 83b47d20c..ce94f7028 100644 --- a/resources/js/Pages/Collections/Components/WinnerCollections/WinnerCollections.blocks.tsx +++ b/resources/js/Pages/Collections/Components/WinnerCollections/WinnerCollections.blocks.tsx @@ -69,7 +69,7 @@ export const WinnerCollectionMainInfo = ({

{collection.name} @@ -79,8 +79,12 @@ export const WinnerCollectionMainInfo = ({

@@ -248,8 +252,12 @@ export const WinnerCollectionTableRow = ({ > diff --git a/resources/js/Tests/Factories/Collections/CollectionOfTheMonthFactory.ts b/resources/js/Tests/Factories/Collections/CollectionOfTheMonthFactory.ts index dc5c5302b..49bf02011 100644 --- a/resources/js/Tests/Factories/Collections/CollectionOfTheMonthFactory.ts +++ b/resources/js/Tests/Factories/Collections/CollectionOfTheMonthFactory.ts @@ -1,4 +1,5 @@ import { faker } from "@faker-js/faker"; +import VolumeFactory from "@/Tests/Factories/VolumeFactory"; import ModelFactory from "@/Tests/Factories/ModelFactory"; export default class CollectionOfTheMonthFactory extends ModelFactory { @@ -6,7 +7,7 @@ export default class CollectionOfTheMonthFactory extends ModelFactory Date: Wed, 24 Jan 2024 14:39:24 +0100 Subject: [PATCH 2/4] Update CollectionWinner.php --- app/Models/CollectionWinner.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Models/CollectionWinner.php b/app/Models/CollectionWinner.php index adaf3d2e6..390358864 100644 --- a/app/Models/CollectionWinner.php +++ b/app/Models/CollectionWinner.php @@ -81,7 +81,7 @@ public static function current(): LaravelCollection return static::query() ->where('year', $previousMonth->year) ->where('month', $previousMonth->month) - ->with('collection', 'collection.floorPriceToken') + ->with('collection', 'collection.floorPriceToken', 'collection.network.nativeToken') ->orderBy('rank', 'asc') ->limit(3) ->get(); From f92ff729065834e3335a13ff60de687231a474c9 Mon Sep 17 00:00:00 2001 From: crnkovic Date: Wed, 24 Jan 2024 13:41:12 +0000 Subject: [PATCH 3/4] style: resolve linting violations --- .../Tests/Factories/Collections/CollectionOfTheMonthFactory.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/js/Tests/Factories/Collections/CollectionOfTheMonthFactory.ts b/resources/js/Tests/Factories/Collections/CollectionOfTheMonthFactory.ts index 49bf02011..f4e533dad 100644 --- a/resources/js/Tests/Factories/Collections/CollectionOfTheMonthFactory.ts +++ b/resources/js/Tests/Factories/Collections/CollectionOfTheMonthFactory.ts @@ -1,6 +1,6 @@ import { faker } from "@faker-js/faker"; -import VolumeFactory from "@/Tests/Factories/VolumeFactory"; import ModelFactory from "@/Tests/Factories/ModelFactory"; +import VolumeFactory from "@/Tests/Factories/VolumeFactory"; export default class CollectionOfTheMonthFactory extends ModelFactory { protected factory(): App.Data.Collections.CollectionOfTheMonthData { From 7a904579b0f554fbc33245147dd58de658c19656 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josip=20Crnkovi=C4=87?= <6536260+crnkovic@users.noreply.github.com> Date: Wed, 24 Jan 2024 15:21:14 +0100 Subject: [PATCH 4/4] Update CollectionOfTheMonthControllerTest.php --- .../Controllers/CollectionOfTheMonthControllerTest.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/App/Http/Controllers/CollectionOfTheMonthControllerTest.php b/tests/App/Http/Controllers/CollectionOfTheMonthControllerTest.php index 4bd1f4a1f..ad5dcc142 100644 --- a/tests/App/Http/Controllers/CollectionOfTheMonthControllerTest.php +++ b/tests/App/Http/Controllers/CollectionOfTheMonthControllerTest.php @@ -4,9 +4,17 @@ use App\Models\Collection; use App\Models\CollectionWinner; +use App\Models\Network; +use App\Models\Token; it('opens the collection of the month page', function () { - $collection = Collection::factory()->create(); + Token::factory()->matic()->create([ + 'is_native_token' => true, + ]); + + $network = Network::polygon(); + + $collection = Collection::factory()->for($network)->create(); CollectionWinner::factory()->for($collection)->create();