Skip to content

Commit

Permalink
code review
Browse files Browse the repository at this point in the history
  • Loading branch information
krzysu committed Mar 15, 2024
1 parent bd76b98 commit 580d7a5
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 45 deletions.
2 changes: 1 addition & 1 deletion .changeset/eleven-frogs-battle.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions examples/web/src/profiles/UseCreateProfile.tsx
Original file line number Diff line number Diff line change
@@ -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.';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ export type ProfilePrices = {
matic: Amount<Matic>;
};

export interface IGetProfilePriceGateway {
export interface IGetProfilePricesGateway {
getMaticPrice(): Promise<Amount<Matic>>;
}

export type IGetProfilePricePresenter = IGenericResultPresenter<ProfilePrices, never>;
export type IGetProfilePricesPresenter = IGenericResultPresenter<ProfilePrices, never>;

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() {
Expand Down
2 changes: 1 addition & 1 deletion packages/domain/src/use-cases/profile/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
23 changes: 0 additions & 23 deletions packages/react/src/misc/adapters/useProfilePriceController.ts

This file was deleted.

21 changes: 21 additions & 0 deletions packages/react/src/misc/adapters/useProfilePricesController.ts
Original file line number Diff line number Diff line change
@@ -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<ProfilePrices, UnspecifiedError> => {
const presenter = new PromiseResultPresenter<ProfilePrices, never>();
const gateway = new ProfilePricesGateway(config, providerFactory);
const profilePrices = new GetProfilePrices(gateway, presenter);

void profilePrices.execute();

return presenter.asResult();
};
}
2 changes: 1 addition & 1 deletion packages/react/src/misc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
@@ -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<ProfilePriceResult> {
const [prices, setPrices] = useState<ProfilePriceResult>();
export function useProfilePrices(): ReadResult<ProfilePrices> {
const [prices, setPrices] = useState<ProfilePrices>();
const [error, setError] = useState<UnspecifiedError>();
const fetchPrices = useProfilePriceController();
const fetchPrices = useProfilePricesController();

useEffect(() => {
const fetchData = async () => {
Expand Down

0 comments on commit 580d7a5

Please sign in to comment.