From 44befdd69c144a305e824d9ae7700e44867b142f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josip=20Crnkovi=C4=87?= <6536260+crnkovic@users.noreply.github.com> Date: Thu, 26 Oct 2023 16:03:47 +0200 Subject: [PATCH 1/4] create simple wallet data object --- app/Data/SimpleWalletData.php | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 app/Data/SimpleWalletData.php diff --git a/app/Data/SimpleWalletData.php b/app/Data/SimpleWalletData.php new file mode 100644 index 000000000..e80c67931 --- /dev/null +++ b/app/Data/SimpleWalletData.php @@ -0,0 +1,30 @@ +address, + domain: $wallet->details?->domain, + avatar: WalletAvatarData::fromModel($wallet), + ); + } +} From 54367f3c0b7b24880f410ba22c6b6e08c06aa3d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josip=20Crnkovi=C4=87?= <6536260+crnkovic@users.noreply.github.com> Date: Thu, 26 Oct 2023 16:04:20 +0200 Subject: [PATCH 2/4] use simple wallet data in backend --- app/Data/Gallery/GalleryData.php | 5 +++-- app/Data/Nfts/NftData.php | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/Data/Gallery/GalleryData.php b/app/Data/Gallery/GalleryData.php index 9df52763a..d1d275e97 100644 --- a/app/Data/Gallery/GalleryData.php +++ b/app/Data/Gallery/GalleryData.php @@ -4,6 +4,7 @@ namespace App\Data\Gallery; +use App\Data\SimpleWalletData; use App\Enums\CurrencyCode; use App\Models\Gallery; use App\Models\User; @@ -28,7 +29,7 @@ public function __construct( public int $collectionsCount, public ?float $value, public ?string $coverImage, - public GalleryWalletData $wallet, + public SimpleWalletData $wallet, public GalleryNftsData $nfts, public bool $isOwner = false, public bool $hasLiked = false, @@ -62,8 +63,8 @@ public static function fromModel(Gallery $gallery, ?int $limit = 6): self collectionsCount: $galleryCache->collectionsCount(), value: $gallery->value($currency), coverImage: $gallery->cover_image, - wallet: GalleryWalletData::fromModel($gallery->user->wallet), nfts: new GalleryNftsData(GalleryNftData::collection($gallery->nfts()->orderByPivot('order_index', 'asc')->paginate($limit, ['*'], 'page', 1))), + wallet: SimpleWalletData::fromModel($gallery->user->wallet), isOwner: $isOwner, hasLiked: $hasLiked, ); diff --git a/app/Data/Nfts/NftData.php b/app/Data/Nfts/NftData.php index 79292bd7d..3479af7e3 100644 --- a/app/Data/Nfts/NftData.php +++ b/app/Data/Nfts/NftData.php @@ -4,6 +4,7 @@ namespace App\Data\Nfts; +use App\Data\SimpleWalletData; use App\Models\Nft; use DateTime; use Spatie\LaravelData\Attributes\MapInputName; @@ -22,7 +23,7 @@ public function __construct( public string $tokenNumber, public NftCollectionData $collection, public NftImagesData $images, - public ?NftWalletData $wallet, + public ?SimpleWalletData $wallet, public ?DateTime $lastViewedAt, public ?DateTime $lastActivityFetchedAt ) { @@ -37,7 +38,7 @@ public static function fromModel(Nft $nft): self tokenNumber: $nft->token_number, collection: NftCollectionData::fromModel($nft->collection), images: NftImagesData::from($nft->images()), - wallet: $nft->wallet_id ? NftWalletData::fromModel($nft->wallet) : null, + wallet: $nft->wallet_id ? SimpleWalletData::fromModel($nft->wallet) : null, lastViewedAt: $nft->last_viewed_at, lastActivityFetchedAt: $nft->collection->activity_updated_at, ); From 906df0ba9de91d65c2dfb5397e706e073ce2ee11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josip=20Crnkovi=C4=87?= <6536260+crnkovic@users.noreply.github.com> Date: Thu, 26 Oct 2023 16:04:35 +0200 Subject: [PATCH 3/4] remove unused data objects --- app/Data/Gallery/GalleryWalletData.php | 33 -------------------------- app/Data/Nfts/NftWalletData.php | 25 ------------------- 2 files changed, 58 deletions(-) delete mode 100644 app/Data/Gallery/GalleryWalletData.php delete mode 100644 app/Data/Nfts/NftWalletData.php diff --git a/app/Data/Gallery/GalleryWalletData.php b/app/Data/Gallery/GalleryWalletData.php deleted file mode 100644 index 6a182c4f9..000000000 --- a/app/Data/Gallery/GalleryWalletData.php +++ /dev/null @@ -1,33 +0,0 @@ -details?->domain; - $avatarData = WalletAvatarData::fromModel($wallet); - - return new self( - $wallet['address'], - $domain, - $avatarData, - ); - } -} diff --git a/app/Data/Nfts/NftWalletData.php b/app/Data/Nfts/NftWalletData.php deleted file mode 100644 index 48e87a085..000000000 --- a/app/Data/Nfts/NftWalletData.php +++ /dev/null @@ -1,25 +0,0 @@ -address, - ); - } -} From d4bde3c935b0283856e3d61ff6c6f552c3462c1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josip=20Crnkovi=C4=87?= <6536260+crnkovic@users.noreply.github.com> Date: Thu, 26 Oct 2023 16:05:01 +0200 Subject: [PATCH 4/4] handle frontend --- .../Nfts/NftHeader/NftOwner.test.tsx | 6 +++--- .../Galleries/GalleryPage/GalleryControls.tsx | 2 +- .../Galleries/GalleryPage/GalleryCurator.tsx | 2 +- .../Galleries/NftGalleryCard.blocks.tsx | 8 +------- .../Factories/Gallery/GalleryDataFactory.ts | 4 ++-- resources/js/Tests/Factories/Nfts/NftFactory.ts | 6 +++--- .../js/Tests/Factories/Nfts/NftWalletFactory.ts | 9 --------- ...ataFactory.ts => SimpleWalletDataFactory.ts} | 6 +++--- resources/types/generated.d.ts | 17 +++++++---------- 9 files changed, 21 insertions(+), 39 deletions(-) delete mode 100644 resources/js/Tests/Factories/Nfts/NftWalletFactory.ts rename resources/js/Tests/Factories/{Gallery/GalleryWalletDataFactory.ts => SimpleWalletDataFactory.ts} (54%) diff --git a/resources/js/Components/Collections/Nfts/NftHeader/NftOwner.test.tsx b/resources/js/Components/Collections/Nfts/NftHeader/NftOwner.test.tsx index 6a3d1a0bd..b2431762c 100644 --- a/resources/js/Components/Collections/Nfts/NftHeader/NftOwner.test.tsx +++ b/resources/js/Components/Collections/Nfts/NftHeader/NftOwner.test.tsx @@ -1,7 +1,7 @@ import { NftOwner } from "./NftOwner"; import NFTCollectionFactory from "@/Tests/Factories/Nfts/NFTCollectionFactory"; import NftFactory from "@/Tests/Factories/Nfts/NftFactory"; -import NftWalletFactory from "@/Tests/Factories/Nfts/NftWalletFactory"; +import SimpleWalletDataFactory from "@/Tests/Factories/SimpleWalletDataFactory"; import { render, screen } from "@/Tests/testing-library"; import { ExplorerChains } from "@/Utils/Explorer"; @@ -34,7 +34,7 @@ describe("NftOwner", () => { const collection = new NFTCollectionFactory().create({ chainId: ExplorerChains.PolygonMainnet, }); - const wallet = new NftWalletFactory().create(); + const wallet = new SimpleWalletDataFactory().create(); const nft = new NftFactory().withWallet().create({ collection, wallet, @@ -54,7 +54,7 @@ describe("NftOwner", () => { const collection = new NFTCollectionFactory().create({ chainId: ExplorerChains.EthereumMainnet, }); - const wallet = new NftWalletFactory().create(); + const wallet = new SimpleWalletDataFactory().create(); const nft = new NftFactory().withWallet().create({ collection, wallet, diff --git a/resources/js/Components/Galleries/GalleryPage/GalleryControls.tsx b/resources/js/Components/Galleries/GalleryPage/GalleryControls.tsx index c3225c4ab..5123c20d7 100644 --- a/resources/js/Components/Galleries/GalleryPage/GalleryControls.tsx +++ b/resources/js/Components/Galleries/GalleryPage/GalleryControls.tsx @@ -22,7 +22,7 @@ export const GalleryControls = ({ }: { likesCount?: number; gallery?: App.Data.Gallery.GalleryData; - wallet: App.Data.Gallery.GalleryWalletData; + wallet: App.Data.SimpleWalletData; isDisabled?: boolean; showEditAction?: boolean; alreadyReported?: boolean; diff --git a/resources/js/Components/Galleries/GalleryPage/GalleryCurator.tsx b/resources/js/Components/Galleries/GalleryPage/GalleryCurator.tsx index 5ea492e66..c197b0cdc 100644 --- a/resources/js/Components/Galleries/GalleryPage/GalleryCurator.tsx +++ b/resources/js/Components/Galleries/GalleryPage/GalleryCurator.tsx @@ -12,7 +12,7 @@ export const GalleryCurator = ({ className, truncate = 10, }: { - wallet: App.Data.Gallery.GalleryWalletData; + wallet: App.Data.SimpleWalletData; className?: string; truncate?: number | false; }): JSX.Element => { diff --git a/resources/js/Components/Galleries/NftGalleryCard.blocks.tsx b/resources/js/Components/Galleries/NftGalleryCard.blocks.tsx index 38b48bd7a..0ac290c83 100644 --- a/resources/js/Components/Galleries/NftGalleryCard.blocks.tsx +++ b/resources/js/Components/Galleries/NftGalleryCard.blocks.tsx @@ -208,13 +208,7 @@ export const NftImageGrid = ({ ); }; -export const GalleryHeading = ({ - name, - wallet, -}: { - name: string; - wallet: App.Data.Gallery.GalleryWalletData; -}): JSX.Element => { +export const GalleryHeading = ({ name, wallet }: { name: string; wallet: App.Data.SimpleWalletData }): JSX.Element => { const truncateReference = useRef(null); const isTruncated = useIsTruncated({ reference: truncateReference }); diff --git a/resources/js/Tests/Factories/Gallery/GalleryDataFactory.ts b/resources/js/Tests/Factories/Gallery/GalleryDataFactory.ts index 8a662d03b..94bb3126e 100644 --- a/resources/js/Tests/Factories/Gallery/GalleryDataFactory.ts +++ b/resources/js/Tests/Factories/Gallery/GalleryDataFactory.ts @@ -1,7 +1,7 @@ import { faker } from "@faker-js/faker"; import GalleryNftDataFactory from "./GalleryNftDataFactory"; -import GalleryWalletDataFactory from "./GalleryWalletDataFactory"; import ModelFactory from "@/Tests/Factories/ModelFactory"; +import SimpleWalletDataFactory from "@/Tests/Factories/SimpleWalletDataFactory"; const url = "http://test.test"; @@ -17,7 +17,7 @@ export default class GalleryDataFactory extends ModelFactory { protected factory(): App.Data.Nfts.NftData { @@ -13,7 +13,7 @@ export default class NftFactory extends ModelFactory { tokenNumber: faker.datatype.number({ min: 1, max: 100000 }).toString(), collection: new NFTCollectionFactory().withImage().create(), images: new NftImagesDataFactory().create(), - wallet: this.optional(new NftWalletFactory().create()), + wallet: this.optional(new SimpleWalletDataFactory().create()), lastViewedAt: null, lastActivityFetchedAt: null, }; @@ -21,7 +21,7 @@ export default class NftFactory extends ModelFactory { public withWallet(): this { return this.state(() => ({ - wallet: new NftWalletFactory().create(), + wallet: new SimpleWalletDataFactory().create(), })); } diff --git a/resources/js/Tests/Factories/Nfts/NftWalletFactory.ts b/resources/js/Tests/Factories/Nfts/NftWalletFactory.ts deleted file mode 100644 index ab99a7549..000000000 --- a/resources/js/Tests/Factories/Nfts/NftWalletFactory.ts +++ /dev/null @@ -1,9 +0,0 @@ -import ModelFactory from "@/Tests/Factories/ModelFactory"; - -export default class NftWalletFactory extends ModelFactory { - protected factory(): App.Data.Nfts.NftWalletData { - return { - address: this.generateAddress(), - }; - } -} diff --git a/resources/js/Tests/Factories/Gallery/GalleryWalletDataFactory.ts b/resources/js/Tests/Factories/SimpleWalletDataFactory.ts similarity index 54% rename from resources/js/Tests/Factories/Gallery/GalleryWalletDataFactory.ts rename to resources/js/Tests/Factories/SimpleWalletDataFactory.ts index 3872ed5e5..a11b57746 100644 --- a/resources/js/Tests/Factories/Gallery/GalleryWalletDataFactory.ts +++ b/resources/js/Tests/Factories/SimpleWalletDataFactory.ts @@ -1,9 +1,9 @@ import { faker } from "@faker-js/faker"; +import WalletAvatarDataFactory from "./Wallet/WalletAvatarDataFactory"; import ModelFactory from "@/Tests/Factories/ModelFactory"; -import WalletAvatarDataFactory from "@/Tests/Factories/Wallet/WalletAvatarDataFactory"; -export default class GalleryWalletDataFactory extends ModelFactory { - protected factory(): App.Data.Gallery.GalleryWalletData { +export default class SimpleWalletDataFactory extends ModelFactory { + protected factory(): App.Data.SimpleWalletData { return { address: this.generateAddress(), domain: this.optional(faker.internet.domainName()), diff --git a/resources/types/generated.d.ts b/resources/types/generated.d.ts index 43a3a0a3f..25400c350 100644 --- a/resources/types/generated.d.ts +++ b/resources/types/generated.d.ts @@ -31,6 +31,11 @@ declare namespace App.Data { timestamp: number; price: number; }; + export type SimpleWalletData = { + address: string; + domain: string | null; + avatar: App.Data.Wallet.WalletAvatarData; + }; export type TokenListItemData = { guid: number | null; name: string; @@ -232,7 +237,7 @@ declare namespace App.Data.Gallery { collectionsCount: number; value: number | null; coverImage: string | null; - wallet: App.Data.Gallery.GalleryWalletData; + wallet: App.Data.SimpleWalletData; nfts: App.Data.Gallery.GalleryNftsData; isOwner: boolean; hasLiked: boolean; @@ -284,11 +289,6 @@ declare namespace App.Data.Gallery { nfts: number; likes: number; }; - export type GalleryWalletData = { - address: string; - domain: string | null; - avatar: App.Data.Wallet.WalletAvatarData; - }; } declare namespace App.Data.Network { export type NetworkWithCollectionsData = { @@ -349,7 +349,7 @@ declare namespace App.Data.Nfts { tokenNumber: string; collection: App.Data.Nfts.NftCollectionData; images: App.Data.Nfts.NftImagesData; - wallet: App.Data.Nfts.NftWalletData | null; + wallet: App.Data.SimpleWalletData | null; lastViewedAt: string | null; lastActivityFetchedAt: string | null; }; @@ -360,9 +360,6 @@ declare namespace App.Data.Nfts { original: string | null; originalRaw: string | null; }; - export type NftWalletData = { - address: string; - }; } declare namespace App.Data.Token { export type TokenData = {