Skip to content

Commit

Permalink
chore: merge develop into main (#706)
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsANameToo authored Apr 18, 2024
2 parents 30e8dad + a296cb9 commit 4682772
Show file tree
Hide file tree
Showing 29 changed files with 495 additions and 234 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
.env.production
.env.test
.phpunit.result.cache
.phpunit.cache
Homestead.json
Homestead.yaml
auth.json
Expand Down
2 changes: 1 addition & 1 deletion app/Console/Commands/LiveDumpWallets.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function handle(): int

$providers = [new AlchemyWeb3DataProvider(), new MoralisWeb3DataProvider()];

$chains = [Chain::ETH, Chain::Polygon];
$chains = [Chain::ETH];

/** @var string[] */
$addresses = config('dashbrd.live_dump_wallets');
Expand Down
5 changes: 5 additions & 0 deletions app/Enums/Chain.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ enum Chain: int
case Polygon = 137;
case Mumbai = 80001;

public function isPolygon(): bool
{
return $this === self::Polygon || $this === self::Mumbai;
}

public function nativeCurrency(): string
{
return match ($this) {
Expand Down
6 changes: 4 additions & 2 deletions app/Enums/MnemonicChain.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace App\Enums;

use InvalidArgumentException;

enum MnemonicChain: string
{
case Ethereum = 'ethereum';
Expand All @@ -13,8 +15,8 @@ public static function fromChain(Chain $chain): self
{
return match ($chain) {
Chain::ETH => self::Ethereum,
Chain::Polygon => self::Polygon,
default => throw new \InvalidArgumentException(sprintf('Chain ID %d is not supported', $chain->name)),
Chain::Polygon => throw new InvalidArgumentException('Mnemonic does not support Polygon networks.'),
default => throw new InvalidArgumentException(sprintf('Chain ID %d is not supported', $chain->name)),
};
}
}
26 changes: 0 additions & 26 deletions app/Http/Client/Mnemonic/MnemonicPendingRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use App\Exceptions\ConnectionException;
use App\Exceptions\RateLimitException;
use App\Models\Token;
use App\Models\TokenPriceHistory;
use App\Support\CryptoUtils;
use App\Support\NftImageUrl;
use Carbon\Carbon;
Expand Down Expand Up @@ -399,37 +398,12 @@ private function extractActivityPrices(Chain $chain, array $transfer, CurrencyCo
$nativeTotalString = Arr::get($transfer, 'recipientPaid.totalNative');
$nativePrice = $nativeTotalString ? (float) $nativeTotalString : null;

if ($chain !== Chain::ETH && $usdPrice !== null) {
// On non-ETH chains we get native in e.g. MATIC so normalize it to ETH using our historical price data.
$nativePrice = $this->getActivityNativePrice($ethToken, $currency, $blockchainTimestamp, $usdPrice);
}

return [
'usd' => $usdPrice,
'native' => $nativePrice,
];
}

/**
* Finds a historical price record and converts USD amount to native
*/
private function getActivityNativePrice(
Token $token,
CurrencyCode $code,
Carbon $timestamp,
float $usdPrice
): ?float {
/** @var TokenPriceHistory|null $historicalPrice */
$historicalPrice = TokenPriceHistory::getHistory($token, $code, $timestamp);

// no historical price record found
if ($historicalPrice === null || $historicalPrice->price == 0) {
return null;
}

return $usdPrice / $historicalPrice->price;
}

/**
* @param string[] $labels
*
Expand Down
4 changes: 4 additions & 0 deletions app/Jobs/FetchBurnActivity.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ public function handle(MnemonicWeb3DataProvider $provider): void
return;
}

if ($this->collection->network->chain()->isPolygon()) {
return;
}

// This collection never had its activity retrieved, so we don't want to fetch only burn activity...
if ($this->collection->activity_updated_at === null) {
return;
Expand Down
4 changes: 4 additions & 0 deletions app/Jobs/FetchCollectionActivity.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ public function handle(MnemonicWeb3DataProvider $provider): void
return;
}

if ($this->collection->network->chain()->isPolygon()) {
return;
}

if ($this->collection->is_fetching_activity && ! $this->forced) {
return;
}
Expand Down
4 changes: 4 additions & 0 deletions app/Jobs/FetchCollectionBanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ public function handle(): void
'collection' => $this->collection->address,
]);

if ($this->collection->network->chain()->isPolygon()) {
return;
}

$banner = Mnemonic::getCollectionBanner(
chain: $this->collection->network->chain(),
contractAddress: $this->collection->address
Expand Down
4 changes: 4 additions & 0 deletions app/Jobs/FetchCollectionVolume.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ public function __construct(
*/
public function handle(): void
{
if ($this->collection->network->chain()->isPolygon()) {
return;
}

$volume = Mnemonic::getLatestCollectionVolume(
chain: $this->collection->network->chain(),
contractAddress: $this->collection->address
Expand Down
4 changes: 4 additions & 0 deletions app/Jobs/FetchCollectionVolumeHistory.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ public function __construct(
*/
public function handle(): void
{
if ($this->collection->network->chain()->isPolygon()) {
return;
}

$volumes = Mnemonic::getCollectionVolumeHistory(
chain: $this->collection->network->chain(),
address: $this->collection->address,
Expand Down
7 changes: 5 additions & 2 deletions app/Listeners/DispatchJobsForNewCollections.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\Listeners;

use App\Enums\Chain;
use App\Events\CollectionSaved;
use App\Jobs\DetermineCollectionMintingDate;
use App\Jobs\FetchCollectionActivity;
Expand All @@ -25,7 +26,9 @@ public function handle(CollectionSaved $event): void
DetermineCollectionMintingDate::dispatch($collection);
}

if (! $collection->is_fetching_activity && $collection->activity_updated_at === null) {
$isPolygon = Chain::from($event->chainId)->isPolygon();

if (! $isPolygon && ! $collection->is_fetching_activity && $collection->activity_updated_at === null) {
FetchCollectionActivity::dispatch($collection)->onQueue(Queues::NFTS);
}

Expand All @@ -34,7 +37,7 @@ public function handle(CollectionSaved $event): void
}

// If the collection has just been created, pre-fetch the 30-day volume history...
if ($event->collection->volumes()->count() === 0) {
if (! $isPolygon && $event->collection->volumes()->count() === 0) {
FetchCollectionVolumeHistory::dispatch($collection);
}

Expand Down
20 changes: 0 additions & 20 deletions app/Models/TokenPriceHistory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

namespace App\Models;

use App\Enums\CurrencyCode;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

Expand All @@ -28,22 +26,4 @@ class TokenPriceHistory extends Model
protected $casts = [
'timestamp' => 'datetime',
];

public static function getHistory(
Token $token,
CurrencyCode $currency,
Carbon $timestamp
): ?TokenPriceHistory {
// find the price history rows for dates between [date - 1 day, date + 1 day]
$priceHistory = TokenPriceHistory::query()->where([
['token_guid', $token->tokenGuid?->guid],
['currency', $currency],
])->whereBetween('timestamp', [
$timestamp->copy()->subDays(1)->startOfDay(),
$timestamp->copy()->addDays(1)->endOfDay(),
])->get();

// find the nearest date to the given timestamp and return
return $priceHistory->sortBy(fn ($history) => abs($history->timestamp->diffInSeconds($timestamp)))->first();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,27 @@ import React from "react";
import { CollectionPortfolioValue } from "./CollectionPortfolioValue";
import TokenDataFactory from "@/Tests/Factories/Token/TokenDataFactory";
import { render, screen } from "@/Tests/testing-library";
import { allBreakpoints, Breakpoint } from "@/Tests/utils";

describe("CollectionName", () => {
it.each(allBreakpoints)("should render on %s", (breakpoint) => {
render(
<CollectionPortfolioValue
value="1001000000000000000"
token={new TokenDataFactory().create({
symbol: "ETH",
name: "ETH",
decimals: 18,
})}
convertedValue="3508.09"
/>,
{ breakpoint },
);

expect(screen.getByTestId("CollectionPortfolioValue")).toBeInTheDocument();
expect(screen.getByTestId("CollectionPortfolioValue__crypto").textContent).toEqual("1.001 ETH");
});

it("should render", () => {
render(
<CollectionPortfolioValue
Expand All @@ -15,10 +34,30 @@ describe("CollectionName", () => {
})}
convertedValue="3508.09"
/>,
{ breakpoint: Breakpoint.sm },
);

expect(screen.getByTestId("CollectionPortfolioValue")).toBeInTheDocument();
expect(screen.getByTestId("CollectionPortfolioValue__crypto").textContent).toEqual("1.001 ETH");
expect(screen.getByTestId("CollectionPortfolioValue__fiat").textContent).toEqual("$3,508.09");
});

it("should render on a small screen", () => {
render(
<CollectionPortfolioValue
value="1001000000000000000"
token={new TokenDataFactory().create({
symbol: "ETH",
name: "ETH",
decimals: 18,
})}
convertedValue="3508.09"
/>,
{ breakpoint: Breakpoint.xs },
);

expect(screen.getByTestId("CollectionPortfolioValue")).toBeInTheDocument();
expect(screen.getByTestId("CollectionPortfolioValue__crypto").textContent).toEqual("1.001 ETH");
expect(screen.getByTestId("CollectionPortfolioValue__fiat").textContent).toEqual("$3.5K");
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,21 @@ describe("CollectionsTable", () => {
expect(getByTestId("CollectionsTable")).toBeInTheDocument();
});

it("should render when floor price fiat is not null, but the user does not exist", () => {
const { getByTestId } = render(
<CollectionsTable
hiddenCollectionAddresses={[]}
collections={collections}
user={null}
alreadyReportedByCollection={{}}
reportByCollectionAvailableIn={{}}
onChanged={vi.fn()}
/>,
);

expect(getByTestId("CollectionsTable")).toBeInTheDocument();
});

it("defaults fiat value to 0", () => {
const { getByTestId, queryByTestId } = render(
<CollectionsTable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,14 @@ describe("PopularCollectionsTable", () => {
});

it.each(allBreakpoints)("can render the skeleton for the table item", (breakpoint) => {
const { getByTestId } = render(<PopularCollectionsTableItemSkeleton index={1} />, { breakpoint });
const { getByTestId } = render(
<table>
<tbody>
<PopularCollectionsTableItemSkeleton index={1} />
</tbody>
</table>,
{ breakpoint },
);

expect(getByTestId("PopularCollectionsTableItemSkeleton")).toBeInTheDocument();
});
Expand Down
Loading

0 comments on commit 4682772

Please sign in to comment.