Skip to content

Commit

Permalink
Merge branch 'develop' into feat/articles
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsANameToo committed Sep 26, 2023
2 parents b105767 + 4fe2274 commit d723bea
Show file tree
Hide file tree
Showing 81 changed files with 1,426 additions and 669 deletions.
6 changes: 5 additions & 1 deletion .husky/pre-push
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#!/bin/bash
. "$(dirname -- "$0")/_/husky.sh"

npx eslint --no-error-on-unmatched-pattern $(git diff --name-only --diff-filter=ACMRTUXB origin/$(git rev-parse --abbrev-ref HEAD) $(git rev-parse --abbrev-ref HEAD) | grep -E "resources/**/*.(tsx|ts|jsx|js)")
if [ "$DASHBRD_ENABLE_PREPUSH_LINTER" = "true" ]; then
npx eslint --no-error-on-unmatched-pattern $(git diff --name-only --diff-filter=ACMRTUXB origin/$(git rev-parse --abbrev-ref HEAD) $(git rev-parse --abbrev-ref HEAD) | grep -E "resources/**/*.(tsx|ts|jsx|js)")
else
echo "DASHBRD_ENABLE_PREPUSH_LINTER is not enabled. Skipping linting."
fi
4 changes: 2 additions & 2 deletions app/Console/Commands/FetchCollectionBanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace App\Console\Commands;

use App\Jobs\FetchCollectionBanner as Job;
use App\Jobs\FetchCollectionBanner as FetchCollectionBannerJob;
use Illuminate\Console\Command;

class FetchCollectionBanner extends Command
Expand Down Expand Up @@ -37,7 +37,7 @@ public function handle(): int
}

$this->forEachCollection(function ($collection) {
Job::dispatch($collection);
FetchCollectionBannerJob::dispatch($collection);
});

return Command::SUCCESS;
Expand Down
7 changes: 5 additions & 2 deletions app/Console/Commands/FetchCollectionBannerBatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,15 @@ public function handle(): int

$networks->map(function ($network) {
Collection::query()
->select(['id', 'address'])
->where('network_id', '=', $network->id)
->select(['collections.id', 'collections.address'])
->where('collections.network_id', '=', $network->id)
->withoutSpamContracts()
->when($this->option('missing-only'), function (Builder $query) {
$query->whereNull('extra_attributes->banner');
})
->chunkById(100, function (IlluminateCollection $collections) use ($network) {
$collections = $collections->filter(fn ($collection) => ! $collection->isBlacklisted());

$addresses = $collections->pluck('address')->toArray();

Log::info('Dispatching FetchCollectionBannerBatchJob', [
Expand Down
4 changes: 2 additions & 2 deletions app/Console/Commands/FetchCollectionFloorPrice.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace App\Console\Commands;

use App\Jobs\FetchCollectionFloorPrice as Job;
use App\Jobs\FetchCollectionFloorPrice as FetchCollectionFloorPriceJob;
use Illuminate\Console\Command;

class FetchCollectionFloorPrice extends Command
Expand All @@ -31,7 +31,7 @@ class FetchCollectionFloorPrice extends Command
public function handle(): int
{
$this->forEachCollection(function ($collection) {
Job::dispatch($collection->network->chain_id, $collection->address);
FetchCollectionFloorPriceJob::dispatch($collection->network->chain_id, $collection->address);
});

return Command::SUCCESS;
Expand Down
18 changes: 15 additions & 3 deletions app/Console/Commands/FetchCollectionNfts.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

namespace App\Console\Commands;

use App\Jobs\FetchCollectionNfts as Job;
use App\Jobs\FetchCollectionNfts as FetchCollectionNftsJob;
use Illuminate\Console\Command;
use Illuminate\Database\Eloquent\Builder;

class FetchCollectionNfts extends Command
{
Expand All @@ -16,7 +17,7 @@ class FetchCollectionNfts extends Command
*
* @var string
*/
protected $signature = 'collections:fetch-nfts {--collection-id=} {--start-token=}';
protected $signature = 'collections:fetch-nfts {--collection-id=} {--start-token=} {--only-signed}';

/**
* The console command description.
Expand All @@ -30,8 +31,19 @@ class FetchCollectionNfts extends Command
*/
public function handle(): int
{
$onlySigned = (bool) $this->option('only-signed');

$this->forEachCollection(function ($collection) {
Job::dispatch($collection, $this->option('start-token') ?? $collection->last_indexed_token_number);
if (! $collection->isBlacklisted()) {
FetchCollectionNftsJob::dispatch(
$collection,
$this->option('start-token') ?? $collection->last_indexed_token_number
);
}
}, queryCallback: function (Builder $query) use ($onlySigned) {
return $query
->when($onlySigned, fn ($q) => $q->withSignedWallets())
->withAcceptableSupply();
});

return Command::SUCCESS;
Expand Down
4 changes: 2 additions & 2 deletions app/Console/Commands/FetchCollectionOwners.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace App\Console\Commands;

use App\Jobs\FetchCollectionOwners as Job;
use App\Jobs\FetchCollectionOwners as FetchCollectionOwnersJob;
use Illuminate\Console\Command;

class FetchCollectionOwners extends Command
Expand All @@ -31,7 +31,7 @@ class FetchCollectionOwners extends Command
public function handle(): int
{
$this->forEachCollection(function ($collection) {
Job::dispatch($collection);
FetchCollectionOwnersJob::dispatch($collection);
});

return Command::SUCCESS;
Expand Down
4 changes: 2 additions & 2 deletions app/Console/Commands/FetchCollectionTraits.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace App\Console\Commands;

use App\Jobs\FetchCollectionTraits as Job;
use App\Jobs\FetchCollectionTraits as FetchCollectionTraitsJob;
use Illuminate\Console\Command;

class FetchCollectionTraits extends Command
Expand All @@ -31,7 +31,7 @@ class FetchCollectionTraits extends Command
public function handle(): int
{
$this->forEachCollection(function ($collection) {
Job::dispatch($collection);
FetchCollectionTraitsJob::dispatch($collection);
});

return Command::SUCCESS;
Expand Down
4 changes: 2 additions & 2 deletions app/Console/Commands/FetchCollectionVolume.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace App\Console\Commands;

use App\Jobs\FetchCollectionVolume as Job;
use App\Jobs\FetchCollectionVolume as FetchCollectionVolumeJob;
use Illuminate\Console\Command;

class FetchCollectionVolume extends Command
Expand All @@ -31,7 +31,7 @@ class FetchCollectionVolume extends Command
public function handle(): int
{
$this->forEachCollection(function ($collection) {
Job::dispatch($collection);
FetchCollectionVolumeJob::dispatch($collection);
});

return Command::SUCCESS;
Expand Down
20 changes: 9 additions & 11 deletions app/Console/Commands/InteractsWithCollections.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace App\Console\Commands;

use App\Models\Collection;
use App\Models\SpamContract;
use Closure;
use Illuminate\Database\Eloquent\Builder;

Expand All @@ -20,13 +19,13 @@ public function forEachCollection(Closure $callback, Closure $queryCallback = nu
// Apply `$queryCallback` to modify the query before fetching collections...

if ($this->option('collection-id')) {
$collection = Collection::find($this->option('collection-id'));
$collection = Collection::query()
->select('collections.*')
->where('collections.id', '=', $this->option('collection-id'))
->withoutSpamContracts()
->first();

if (SpamContract::isSpam($collection->address, $collection->network)) {
return;
}

$callback($collection);
$collection && $callback($collection);

return;
}
Expand All @@ -35,9 +34,8 @@ public function forEachCollection(Closure $callback, Closure $queryCallback = nu
->when($queryCallback !== null, $queryCallback)
->select('collections.*')
->withoutSpamContracts()
->chunkById(
100,
static fn ($collections) => $collections->each($callback),
'collections.id', 'id');
->chunkById(100, function ($collections) use ($callback) {
$collections->each($callback);
}, 'collections.id', 'id');
}
}
4 changes: 3 additions & 1 deletion app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ private function scheduleJobsForCollections(Schedule $schedule): void
->dailyAt('5:30');

$schedule
->command(FetchCollectionNfts::class)
->command(FetchCollectionNfts::class, [
'--only-signed',
])
->withoutOverlapping()
->dailyAt('11:00');

Expand Down
50 changes: 43 additions & 7 deletions app/Http/Controllers/Auth/AuthenticatedSessionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,33 @@

namespace App\Http\Controllers\Auth;

use App\Data\AuthData;
use App\Data\UserData;
use App\Data\Wallet\WalletData;
use App\Http\Controllers\Controller;
use App\Http\Requests\Auth\LoginRequest;
use App\Http\Requests\Auth\SignMessageRequest;
use App\Http\Requests\Auth\SignRequest;
use App\Providers\RouteServiceProvider;
use App\Models\User;
use App\Support\Facades\Signature;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Route;

class AuthenticatedSessionController extends Controller
{
/**
* Handle an incoming authentication request.
*/
public function store(LoginRequest $request): RedirectResponse
public function store(LoginRequest $request): JsonResponse
{
$request->authenticate();

$request->session()->regenerate();

return redirect()->intended($request->get('intendedUrl', RouteServiceProvider::HOME));
return response()->json($this->getAuthData($request));
}

/**
Expand All @@ -36,24 +41,55 @@ public function signMessage(SignMessageRequest $request): JsonResponse
return response()->json(['message' => $request->getMessage()]);
}

public function sign(SignRequest $request): RedirectResponse
public function sign(SignRequest $request): JsonResponse
{
$request->sign();

return redirect()->back();
return response()->json($this->getAuthData($request));
}

/**
* Destroy an authenticated session.
*/
public function destroy(Request $request): RedirectResponse
public function destroy(Request $request): RedirectResponse|JsonResponse
{
Auth::guard('web')->logout();

$request->session()->invalidate();

$request->session()->regenerateToken();

return redirect()->route('galleries');
$previousRoute = Route::getRoutes()->match(request()->create(url()->previousPath()))->getName();

$requiresRedirect = in_array($previousRoute, ['dashboard', 'collections']);

if ($request->wantsJson()) {
return response()->json([
'redirectTo' => $requiresRedirect ? 'galleries' : null,
]);
}

return $requiresRedirect ? redirect()->route('galleries') : redirect()->back();
}

private function getAuthData(Request $request): AuthData
{
/** @var User $user */
$user = $request->user();

$wallet = $user->wallet;

/** @var UserData $userData */
$userData = $user->getData();

/** @var WalletData $walletData */
$walletData = $wallet->getData();

return new AuthData(
$userData,
$walletData,
$user !== null,
Signature::walletIsSigned($wallet->id)
);
}
}
7 changes: 6 additions & 1 deletion app/Http/Controllers/CollectionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,17 @@ public function index(Request $request): Response|JsonResponse|RedirectResponse
'reportByCollectionAvailableIn' => $reportByCollectionAvailableIn,
'alreadyReportedByCollection' => $alreadyReportedByCollection,
'hiddenCollectionAddresses' => $hiddenCollections,
'stats' => new CollectionStatsData(
nfts: $showHidden ? $cache->hiddenNftsCount() : $cache->shownNftsCount(),
collections: $showHidden ? $cache->hiddenCollectionsCount() : $cache->shownCollectionsCount(),
value: $user->collectionsValue($user->currency(), readFromDatabase: false, onlyHidden: $showHidden),
),
]);
}

return Inertia::render('Collections/Index', [
'title' => trans('metatags.collections.title'),
'stats' => new CollectionStatsData(
'initialStats' => new CollectionStatsData(
nfts: $showHidden ? $cache->hiddenNftsCount() : $cache->shownNftsCount(),
collections: $showHidden ? $cache->hiddenCollectionsCount() : $cache->shownCollectionsCount(),
value: $user->collectionsValue($user->currency(), readFromDatabase: false, onlyHidden: $showHidden),
Expand Down
3 changes: 2 additions & 1 deletion app/Http/Controllers/GeneralSettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@

class GeneralSettingsController extends Controller
{
public function edit(): Response
public function edit(Request $request): Response
{
return Inertia::render('Settings/General', [
'title' => trans('metatags.settings.title'),
'currencies' => Currency::all(),
'dateFormats' => DateFormat::all(),
'timezones' => Timezone::formatted(),
'reset' => $request->boolean('reset'),
]);
}

Expand Down
3 changes: 0 additions & 3 deletions app/Http/Requests/Auth/LoginRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,6 @@ private function getAuthParams(): array
// Passing the `userId` in case is logged so we can associate the wallet
// to a existing user on the web3 auth provider
'userId' => $this->user()?->id,
// Passing the user locale information from frontend...
'timezone' => $this->input('tz', 'UTC'),
'locale' => $this->input('locale', 'en-US'),
];
}
}
Loading

0 comments on commit d723bea

Please sign in to comment.