From 580d7a58af1ef1c1ece26148e7c8cb9432d8dedc Mon Sep 17 00:00:00 2001 From: Kris Urbas <605420+krzysu@users.noreply.github.com> Date: Fri, 15 Mar 2024 16:40:07 +0100 Subject: [PATCH] code review --- .changeset/eleven-frogs-battle.md | 2 +- .../web/src/profiles/UseCreateProfile.tsx | 4 ++-- ...GetProfilePrice.ts => GetProfilePrices.ts} | 10 ++++---- .../domain/src/use-cases/profile/index.ts | 2 +- ...riceGateway.ts => ProfilePricesGateway.ts} | 4 ++-- .../adapters/useProfilePriceController.ts | 23 ------------------- .../adapters/useProfilePricesController.ts | 21 +++++++++++++++++ packages/react/src/misc/index.ts | 2 +- ...useProfilePrice.ts => useProfilePrices.ts} | 16 +++++-------- 9 files changed, 39 insertions(+), 45 deletions(-) rename packages/domain/src/use-cases/profile/{GetProfilePrice.ts => GetProfilePrices.ts} (59%) rename packages/react/src/misc/adapters/{ProfilePriceGateway.ts => ProfilePricesGateway.ts} (84%) delete mode 100644 packages/react/src/misc/adapters/useProfilePriceController.ts create mode 100644 packages/react/src/misc/adapters/useProfilePricesController.ts rename packages/react/src/misc/{useProfilePrice.ts => useProfilePrices.ts} (68%) diff --git a/.changeset/eleven-frogs-battle.md b/.changeset/eleven-frogs-battle.md index 7b165c020..efb702d48 100644 --- a/.changeset/eleven-frogs-battle.md +++ b/.changeset/eleven-frogs-battle.md @@ -5,4 +5,4 @@ "@lens-protocol/react-web": minor --- -**feat:** added `useProfilePrice` hook to fetch profile minting price +**feat:** added `useProfilePrices` hook to fetch profile minting price diff --git a/examples/web/src/profiles/UseCreateProfile.tsx b/examples/web/src/profiles/UseCreateProfile.tsx index 20e9d0151..265a6d7c6 100644 --- a/examples/web/src/profiles/UseCreateProfile.tsx +++ b/examples/web/src/profiles/UseCreateProfile.tsx @@ -1,10 +1,10 @@ -import { useCreateProfile, useProfilePrice } from '@lens-protocol/react-web'; +import { useCreateProfile, useProfilePrices } from '@lens-protocol/react-web'; import toast from 'react-hot-toast'; import { RequireConnectedWallet } from '../components/auth'; function ProfilePrice() { - const { data: prices, loading, error } = useProfilePrice(); + const { data: prices, loading, error } = useProfilePrices(); if (loading) return 'Fetching price...'; if (error) return 'Error fetching price.'; diff --git a/packages/domain/src/use-cases/profile/GetProfilePrice.ts b/packages/domain/src/use-cases/profile/GetProfilePrices.ts similarity index 59% rename from packages/domain/src/use-cases/profile/GetProfilePrice.ts rename to packages/domain/src/use-cases/profile/GetProfilePrices.ts index e054da846..d320e09e3 100644 --- a/packages/domain/src/use-cases/profile/GetProfilePrice.ts +++ b/packages/domain/src/use-cases/profile/GetProfilePrices.ts @@ -6,16 +6,16 @@ export type ProfilePrices = { matic: Amount; }; -export interface IGetProfilePriceGateway { +export interface IGetProfilePricesGateway { getMaticPrice(): Promise>; } -export type IGetProfilePricePresenter = IGenericResultPresenter; +export type IGetProfilePricesPresenter = IGenericResultPresenter; -export class GetProfilePrice { +export class GetProfilePrices { constructor( - private readonly gateway: IGetProfilePriceGateway, - private readonly presenter: IGetProfilePricePresenter, + private readonly gateway: IGetProfilePricesGateway, + private readonly presenter: IGetProfilePricesPresenter, ) {} async execute() { diff --git a/packages/domain/src/use-cases/profile/index.ts b/packages/domain/src/use-cases/profile/index.ts index f92ca84b3..d175c3fe4 100644 --- a/packages/domain/src/use-cases/profile/index.ts +++ b/packages/domain/src/use-cases/profile/index.ts @@ -4,7 +4,7 @@ export * from './CreateProfile'; export * from './DismissRecommendedProfiles'; export * from './FollowPolicy'; export * from './FollowProfile'; -export * from './GetProfilePrice'; +export * from './GetProfilePrices'; export * from './LinkHandle'; export * from './ReportProfile'; export * from './SetProfileMetadata'; diff --git a/packages/react/src/misc/adapters/ProfilePriceGateway.ts b/packages/react/src/misc/adapters/ProfilePricesGateway.ts similarity index 84% rename from packages/react/src/misc/adapters/ProfilePriceGateway.ts rename to packages/react/src/misc/adapters/ProfilePricesGateway.ts index c26b0d4ba..74ece330b 100644 --- a/packages/react/src/misc/adapters/ProfilePriceGateway.ts +++ b/packages/react/src/misc/adapters/ProfilePricesGateway.ts @@ -1,11 +1,11 @@ import { permissionlessCreator } from '@lens-protocol/blockchain-bindings'; -import { IGetProfilePriceGateway } from '@lens-protocol/domain/use-cases/profile'; +import { IGetProfilePricesGateway } from '@lens-protocol/domain/use-cases/profile'; import { Amount, ChainType, Denomination, Matic } from '@lens-protocol/shared-kernel'; import { RequiredConfig } from '../../config'; import { IProviderFactory } from '../../wallet/adapters/IProviderFactory'; -export class ProfilePriceGateway implements IGetProfilePriceGateway { +export class ProfilePricesGateway implements IGetProfilePricesGateway { constructor( private readonly config: RequiredConfig, private readonly providerFactory: IProviderFactory, diff --git a/packages/react/src/misc/adapters/useProfilePriceController.ts b/packages/react/src/misc/adapters/useProfilePriceController.ts deleted file mode 100644 index e7bfc30b2..000000000 --- a/packages/react/src/misc/adapters/useProfilePriceController.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { UnspecifiedError } from '@lens-protocol/api-bindings'; -import { GetProfilePrice, ProfilePrices } from '@lens-protocol/domain/use-cases/profile'; -import { PromiseResult } from '@lens-protocol/shared-kernel'; - -import { useSharedDependencies } from '../../shared'; -import { PromiseResultPresenter } from '../../transactions/adapters/PromiseResultPresenter'; -import { ProfilePriceGateway } from './ProfilePriceGateway'; - -export type ProfilePriceResult = ProfilePrices; - -export function useProfilePriceController() { - const { config, providerFactory } = useSharedDependencies(); - - return async (): PromiseResult => { - const presenter = new PromiseResultPresenter(); - const gateway = new ProfilePriceGateway(config, providerFactory); - const profilePrice = new GetProfilePrice(gateway, presenter); - - void profilePrice.execute(); - - return presenter.asResult(); - }; -} diff --git a/packages/react/src/misc/adapters/useProfilePricesController.ts b/packages/react/src/misc/adapters/useProfilePricesController.ts new file mode 100644 index 000000000..660d8e875 --- /dev/null +++ b/packages/react/src/misc/adapters/useProfilePricesController.ts @@ -0,0 +1,21 @@ +import { UnspecifiedError } from '@lens-protocol/api-bindings'; +import { GetProfilePrices, ProfilePrices } from '@lens-protocol/domain/use-cases/profile'; +import { PromiseResult } from '@lens-protocol/shared-kernel'; + +import { useSharedDependencies } from '../../shared'; +import { PromiseResultPresenter } from '../../transactions/adapters/PromiseResultPresenter'; +import { ProfilePricesGateway } from './ProfilePricesGateway'; + +export function useProfilePricesController() { + const { config, providerFactory } = useSharedDependencies(); + + return async (): PromiseResult => { + const presenter = new PromiseResultPresenter(); + const gateway = new ProfilePricesGateway(config, providerFactory); + const profilePrices = new GetProfilePrices(gateway, presenter); + + void profilePrices.execute(); + + return presenter.asResult(); + }; +} diff --git a/packages/react/src/misc/index.ts b/packages/react/src/misc/index.ts index ad77da7f9..28efdbf20 100644 --- a/packages/react/src/misc/index.ts +++ b/packages/react/src/misc/index.ts @@ -2,7 +2,7 @@ export * from './useCurrencies'; export * from './useInvitedProfiles'; export * from './useInviteWallets'; export * from './useModuleMetadata'; -export * from './useProfilePrice'; +export * from './useProfilePrices'; export * from './useResolveAddress'; export * from './useValidateHandle'; export * from './useWasWalletInvited'; diff --git a/packages/react/src/misc/useProfilePrice.ts b/packages/react/src/misc/useProfilePrices.ts similarity index 68% rename from packages/react/src/misc/useProfilePrice.ts rename to packages/react/src/misc/useProfilePrices.ts index 93f4a5fe3..a201b7e34 100644 --- a/packages/react/src/misc/useProfilePrice.ts +++ b/packages/react/src/misc/useProfilePrices.ts @@ -1,30 +1,26 @@ import { QueryResult } from '@apollo/client'; import { UnspecifiedError } from '@lens-protocol/api-bindings'; +import { ProfilePrices } from '@lens-protocol/domain/use-cases/profile'; import { useEffect, useState } from 'react'; import { ReadResult, useReadResult } from '../helpers/reads'; -import { - ProfilePriceResult, - useProfilePriceController, -} from './adapters/useProfilePriceController'; - -export type { ProfilePriceResult }; +import { useProfilePricesController } from './adapters/useProfilePricesController'; /** * Retrieve the prices for minting a new Lens Profile, denominated in various currencies. * * @example * ```tsx - * const { data, error, loading } = useProfilePrice(); + * const { data, error, loading } = useProfilePrices(); * ``` * * @category Misc * @group Hooks */ -export function useProfilePrice(): ReadResult { - const [prices, setPrices] = useState(); +export function useProfilePrices(): ReadResult { + const [prices, setPrices] = useState(); const [error, setError] = useState(); - const fetchPrices = useProfilePriceController(); + const fetchPrices = useProfilePricesController(); useEffect(() => { const fetchData = async () => {