Skip to content

Commit

Permalink
chore: merge develop into main
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsANameToo authored Sep 8, 2023
2 parents 67536e8 + 0b72ec5 commit ed9c606
Show file tree
Hide file tree
Showing 177 changed files with 3,009 additions and 1,398 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
/public/hot
/public/storage
/storage/*.key
/storage/**/*.log
/vendor
.env
.env.backup
Expand Down
32 changes: 16 additions & 16 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,24 @@ diverse, inclusive, and healthy community.
Examples of behavior that contributes to a positive environment for our
community include:

* Demonstrating empathy and kindness toward other people
* Being respectful of differing opinions, viewpoints, and experiences
* Giving and gracefully accepting constructive feedback
* Accepting responsibility and apologizing to those affected by our mistakes,
and learning from the experience
* Focusing on what is best not just for us as individuals, but for the
overall community
- Demonstrating empathy and kindness toward other people
- Being respectful of differing opinions, viewpoints, and experiences
- Giving and gracefully accepting constructive feedback
- Accepting responsibility and apologizing to those affected by our mistakes,
and learning from the experience
- Focusing on what is best not just for us as individuals, but for the
overall community

Examples of unacceptable behavior include:

* The use of sexualized language or imagery, and sexual attention or
advances of any kind
* Trolling, insulting or derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or email
address, without their explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting
- The use of sexualized language or imagery, and sexual attention or
advances of any kind
- Trolling, insulting or derogatory comments, and personal or political attacks
- Public or private harassment
- Publishing others' private information, such as a physical or email
address, without their explicit permission
- Other conduct which could reasonably be considered inappropriate in a
professional setting

## Enforcement Responsibilities

Expand Down Expand Up @@ -106,7 +106,7 @@ Violating these terms may lead to a permanent ban.
### 4. Permanent Ban

**Community Impact**: Demonstrating a pattern of violation of community
standards, including sustained inappropriate behavior, harassment of an
standards, including sustained inappropriate behavior, harassment of an
individual, or aggression toward or disparagement of classes of individuals.

**Consequence**: A permanent ban from any sort of public interaction within
Expand Down
4 changes: 2 additions & 2 deletions app/Console/Commands/InteractsWithCollections.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function forEachCollection(Closure $callback, Closure $queryCallback = nu
->withoutSpamContracts()
->chunkById(
100,
static fn ($collections) => $collections->each($callback)
);
static fn ($collections) => $collections->each($callback),
'collections.id', 'id');
}
}
33 changes: 4 additions & 29 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
use App\Console\Commands\FetchCollectionBanner;
use App\Console\Commands\FetchCollectionFloorPrice;
use App\Console\Commands\FetchCollectionNfts;
use App\Console\Commands\FetchCollectionOwners;
use App\Console\Commands\FetchCollectionTraits;
use App\Console\Commands\FetchCollectionVolume;
use App\Console\Commands\FetchEnsDetails;
use App\Console\Commands\FetchNativeBalances;
use App\Console\Commands\FetchTokens;
Expand Down Expand Up @@ -134,12 +131,6 @@ private function scheduleJobsForCollections(Schedule $schedule): void
->withoutOverlapping()
->everyThirtyMinutes();

// Fetch traits for all collections in case some have changed
$schedule
->command(FetchCollectionTraits::class)
->withoutOverlapping()
->dailyAt('5:00');

// Fetch banners for collections that don't have one yet
// (More often according to config)
$schedule
Expand All @@ -149,22 +140,6 @@ private function scheduleJobsForCollections(Schedule $schedule): void
->withoutOverlapping()
->dailyAt('5:30');

// Fetch banners for all collections in case some have changed
$schedule
->command(FetchCollectionBanner::class)
->withoutOverlapping()
->weeklyOn(Schedule::TUESDAY, '10:00');

$schedule
->command(FetchCollectionOwners::class)
->withoutOverlapping()
->dailyAt('6:00');

$schedule
->command(FetchCollectionVolume::class)
->withoutOverlapping()
->dailyAt('6:30');

$schedule
->command(FetchCollectionNfts::class)
->withoutOverlapping()
Expand All @@ -188,26 +163,26 @@ private function scheduleJobsForPortfolio(Schedule $schedule): void
$schedule
->command(FetchTokens::class)
->withoutOverlapping()
->hourlyAt(15); // offset by 15 mins from FetchEnsDetails so they dont run at the same time...
->dailyAt('14:15'); // offset by 15 mins from FetchEnsDetails so they dont run at the same time...

$schedule
->command(FetchNativeBalances::class)
->withoutOverlapping()
->hourlyAt(45); // offset by 30 mins from FetchTokens so they dont run at the same time...
->dailyAt('14:45'); // offset by 30 mins from FetchTokens so they dont run at the same time...

$schedule
->command(FetchNativeBalances::class, [
'--only-online',
])
->withoutOverlapping()
->everyMinute();
->everyFiveMinutes();

$schedule
->command(FetchTokens::class, [
'--only-online',
])
->withoutOverlapping()
->everyMinute();
->everyFiveMinutes();
}

private function maxCoingeckoJobsInInterval(): int
Expand Down
2 changes: 1 addition & 1 deletion app/Data/Collections/CollectionDetailData.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static function fromModel(Collection $collection, CurrencyCode $currencyC
floorPriceFiat: $currencyCode !== null ? $collection->fiatValue($currencyCode) : null,
image: $collection->extra_attributes->get('image'),
banner: $collection->extra_attributes->get('banner'),
website: $collection->website(),
website: $collection->website(defaultToExplorer: false),
twitter: $collection->twitter(),
discord: $collection->discord(),
supply: $collection->supply,
Expand Down
14 changes: 11 additions & 3 deletions app/Data/Gallery/GalleryData.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use App\Enums\CurrencyCode;
use App\Models\Gallery;
use App\Models\User;
use App\Support\Cache\GalleryCache;
use Illuminate\Support\Facades\Auth;
use Spatie\LaravelData\Attributes\MapInputName;
Expand Down Expand Up @@ -39,7 +40,14 @@ public static function fromModel(Gallery $gallery, ?int $limit = 6): self
$currency = CurrencyCode::USD;

if (Auth::hasUser()) {
$currency = Auth::user()->currency();
/** @var User $user */
$user = Auth::user();
$currency = $user->currency();
$isOwner = $user->id === $gallery->user->id;
$hasLiked = $gallery->isLikedBy($user);
} else {
$isOwner = false;
$hasLiked = false;
}

$galleryCache = new GalleryCache($gallery);
Expand All @@ -56,8 +64,8 @@ public static function fromModel(Gallery $gallery, ?int $limit = 6): self
coverImage: $gallery->cover_image,
wallet: GalleryWalletData::fromModel($gallery->user->wallet),
nfts: new GalleryNftsData(GalleryNftData::collection($gallery->nfts()->orderByPivot('order_index', 'asc')->paginate($limit))),
isOwner: Auth::user()->id === $gallery->user->id,
hasLiked: $gallery->isLikedBy(Auth::user()),
isOwner: $isOwner,
hasLiked: $hasLiked,
);
}
}
96 changes: 96 additions & 0 deletions app/Filament/Resources/GalleryResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?php

declare(strict_types=1);

namespace App\Filament\Resources;

use App\Filament\Resources\GalleryResource\Pages\ListGalleries;
use App\Models\Gallery;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables\Actions\Action;
use Filament\Tables\Actions\ActionGroup;
use Filament\Tables\Actions\DeleteAction;
use Filament\Tables\Columns\ImageColumn;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;

class GalleryResource extends Resource
{
protected static ?string $model = Gallery::class;

protected static ?string $navigationIcon = 'heroicon-o-photo';

public static function form(Form $form): Form
{
return $form
->schema([
//
]);
}

public static function table(Table $table): Table
{
return $table
->columns([
ImageColumn::make('cover_image')
->getStateUsing(fn (Gallery $gallery) => $gallery->cover_image ? str_replace('/storage', '', $gallery->cover_image) : null)
->disk('public')
->size(40)
->url(fn (Gallery $gallery) => $gallery->cover_image)
->openUrlInNewTab(),

TextColumn::make('name')
->weight('medium')
->color('primary')
->label('Name')
->default('Unknown')
->url(fn (Gallery $gallery) => route('galleries.view', $gallery))
->icon(fn ($state) => $state ? 'heroicon-o-arrow-top-right-on-square' : null)
->iconPosition('after')
->openUrlInNewTab()
->sortable(),

TextColumn::make('created_at')
->label('Date Created')
->dateTime()
->icon('heroicon-m-calendar')
->sortable(),
])
->filters([
//
])
->actions([
ActionGroup::make([
Action::make('unresolve')
->label('Remove cover image')
->requiresConfirmation()
->action(fn (Gallery $gallery) => $gallery->update([
'cover_image' => null,
]))
->icon('heroicon-o-photo')
->modalHeading('Remove cover image')
->modalDescription('Are you sure you want to remove the cover image for this gallery?')
->modalSubmitActionLabel('Yes, do it')
->modalIcon('heroicon-o-photo')
->modalWidth('sm'),

DeleteAction::make(),
]),
]);
}

public static function getRelations(): array
{
return [
//
];
}

public static function getPages(): array
{
return [
'index' => ListGalleries::route('/'),
];
}
}
20 changes: 20 additions & 0 deletions app/Filament/Resources/GalleryResource/Pages/ListGalleries.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

namespace App\Filament\Resources\GalleryResource\Pages;

use App\Filament\Resources\GalleryResource;
use Filament\Resources\Pages\ListRecords;

class ListGalleries extends ListRecords
{
protected static string $resource = GalleryResource::class;

protected function getHeaderActions(): array
{
return [
//
];
}
}
85 changes: 85 additions & 0 deletions app/Filament/Widgets/OverviewStats.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php

declare(strict_types=1);

namespace App\Filament\Widgets;

use App\Models\Collection;
use App\Models\Nft;
use App\Models\Wallet;
use Filament\Widgets\StatsOverviewWidget;
use Filament\Widgets\StatsOverviewWidget\Stat;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;

class OverviewStats extends StatsOverviewWidget
{
protected function getCards(): array
{
$ttl = now()->addHours(1);

return [
Stat::make('Number of Wallets', static fn () => Cache::remember('filament:widgets:wallets', $ttl, static fn () => number_format(Wallet::count()))),

Stat::make('Number of NFTs', static fn () => Cache::remember('filament:widgets:nfts', $ttl, static fn () => number_format(Nft::count()))),

Stat::make('Number of wallet-owned NFTs', static fn () => Cache::remember('filament:widgets:owned-nfts', $ttl, static fn () => number_format(Nft::whereNotNull('wallet_id')->count()))),

Stat::make('Number of collections', static fn () => Cache::remember('filament:widgets:collections', $ttl,
static function () {
return Collection::count();
}
)),

Stat::make('Number of collections for wallet-owned NFTs', static fn () => Cache::remember('filament:widgets:collections-owned-nfts', $ttl,
static function () {
return Nft::whereNotNull('wallet_id')->distinct('collection_id')->count();
}
)),

Stat::make('Average NFTs per wallet', static fn () => Cache::remember('filament:widgets:nfts-per-wallet', $ttl,
static function () {
$wallets = Wallet::count();

if ($wallets === 0) {
return 0;
}

return round(Nft::whereNotNull('wallet_id')->count() / $wallets, 2);
}
)),

Stat::make('Average collections per wallet', static fn () => Cache::remember('filament:widgets:collections-per-wallet', $ttl,
static function () {
$wallets = Wallet::count();

if ($wallets === 0) {
return 0;
}

return round(Collection::count() / $wallets, 2);
}
)),

Stat::make('Most NFTs in a wallet', static fn () => Cache::remember('filament:widgets:most-nfts', $ttl,
static function () {
return Wallet::withCount('nfts')->latest('nfts_count')->first()->nfts_count;
}
))->description('Number of NFTs for a wallet that owns the most NFTs'),

Stat::make('Most unique collections owned by wallet', static fn () => Cache::remember('filament:widgets:most-collections', $ttl,
static function () {

/** @var object{wallet_id: int, count: int} $result */
$result = DB::table('nfts')
->select(DB::raw('nfts.wallet_id, count(distinct(collection_id))'))
->groupBy('wallet_id')
->limit(1)
->first();

return $result->count;
}
))->description('Number of collections for a wallet that owns NFTs in the most collections'),
];
}
}
Loading

0 comments on commit ed9c606

Please sign in to comment.