Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use 30-day volume for previous "cotm" winners #629

Merged
merged 4 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions app/Data/Collections/CollectionOfTheMonthData.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions app/Models/CollectionWinner.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion app/Models/Traits/HasVolume.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export const WinnerCollectionMainInfo = ({

<p
className={cn(
"line-clamp-2 w-full text-sm font-medium text-theme-secondary-900 group-hover:text-theme-primary-700 dark:text-theme-dark-50 dark:text-theme-dark-50 dark:group-hover:text-theme-primary-400",
"line-clamp-2 w-full text-sm font-medium text-theme-secondary-900 group-hover:text-theme-primary-700 dark:text-theme-dark-50 dark:group-hover:text-theme-primary-400",
)}
>
{collection.name}
Expand All @@ -79,8 +79,12 @@ export const WinnerCollectionMainInfo = ({
<div className="mt-4 flex w-full flex-col items-center space-y-4 sm:flex-row sm:justify-between sm:space-y-0 lg:hidden">
<WinnerCollectionLabel label={t("common.volume")}>
<FormatCrypto
value={collection.volume ?? "0"}
token={token}
value={collection.volume.value ?? "0"}
token={{
symbol: collection.volume.currency,
name: collection.volume.currency,
decimals: collection.volume.decimals,
}}
/>
</WinnerCollectionLabel>

Expand Down Expand Up @@ -248,8 +252,12 @@ export const WinnerCollectionTableRow = ({
>
<WinnerCollectionLabel label={t("common.volume")}>
<FormatCrypto
value={collection.volume ?? "0"}
token={token}
value={collection.volume.value ?? "0"}
token={{
symbol: collection.volume.currency,
name: collection.volume.currency,
decimals: collection.volume.decimals,
}}
/>
</WinnerCollectionLabel>
</TableCell>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { faker } from "@faker-js/faker";
import ModelFactory from "@/Tests/Factories/ModelFactory";
import VolumeFactory from "@/Tests/Factories/VolumeFactory";

export default class CollectionOfTheMonthFactory extends ModelFactory<App.Data.Collections.CollectionOfTheMonthData> {
protected factory(): App.Data.Collections.CollectionOfTheMonthData {
return {
image: this.optional(faker.image.avatar(), 0.9),
votes: faker.datatype.number({ min: 1, max: 100000 }),
volume: "1",
volume: new VolumeFactory().create(),
floorPrice: "1",
floorPriceCurrency: "ETH",
floorPriceDecimals: 18,
Expand Down
2 changes: 1 addition & 1 deletion resources/types/generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ declare namespace App.Data.Collections {
export type CollectionOfTheMonthData = {
image: string | null;
votes: number;
volume: string | null;
volume: App.Data.VolumeData;
floorPrice: string | null;
floorPriceCurrency: string | null;
floorPriceDecimals: number | null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Loading