-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
144 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
"@lens-protocol/domain": minor | ||
"@lens-protocol/react": minor | ||
"@lens-protocol/react-native": minor | ||
"@lens-protocol/react-web": minor | ||
--- | ||
|
||
**feat:** added `useProfilePrice` hook to fetch profile minting price |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { Amount, Matic, success } from '@lens-protocol/shared-kernel'; | ||
|
||
import { IGenericResultPresenter } from '../transactions/IGenericResultPresenter'; | ||
|
||
export type ProfilePrices = { | ||
matic: Amount<Matic>; | ||
}; | ||
|
||
export interface IGetProfilePriceGateway { | ||
getMaticPrice(): Promise<Amount<Matic>>; | ||
} | ||
|
||
export type IGetProfilePricePresenter = IGenericResultPresenter<ProfilePrices, never>; | ||
|
||
export class GetProfilePrice { | ||
constructor( | ||
private readonly gateway: IGetProfilePriceGateway, | ||
private readonly presenter: IGetProfilePricePresenter, | ||
) {} | ||
|
||
async execute() { | ||
const matic = await this.gateway.getMaticPrice(); | ||
|
||
this.presenter.present(success({ matic })); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -116,12 +116,5 @@ | |
"web/index.ts" | ||
], | ||
"exports": true | ||
}, | ||
"pnpm": { | ||
"peerDependencyRules": { | ||
"ignoreMissing": [ | ||
"react" | ||
] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { permissionlessCreator } from '@lens-protocol/blockchain-bindings'; | ||
import { IGetProfilePriceGateway } 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 { | ||
constructor( | ||
private readonly config: RequiredConfig, | ||
private readonly providerFactory: IProviderFactory, | ||
) {} | ||
|
||
async getMaticPrice(): Promise<Amount<Matic>> { | ||
const provider = await this.providerFactory.createProvider({ chainType: ChainType.POLYGON }); | ||
|
||
const contract = permissionlessCreator( | ||
this.config.environment.contracts.permissionlessCreator, | ||
provider, | ||
); | ||
|
||
const priceBN = await contract.getProfileWithHandleCreationPrice(); | ||
|
||
return Amount.matic(Denomination.wei(priceBN.toString())); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
packages/react/src/misc/adapters/useProfilePriceController.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
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<ProfilePriceResult, UnspecifiedError> => { | ||
const presenter = new PromiseResultPresenter<ProfilePriceResult, never>(); | ||
const gateway = new ProfilePriceGateway(config, providerFactory); | ||
const profilePrice = new GetProfilePrice(gateway, presenter); | ||
|
||
void profilePrice.execute(); | ||
|
||
return presenter.asResult(); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { QueryResult } from '@apollo/client'; | ||
import { UnspecifiedError } from '@lens-protocol/api-bindings'; | ||
import { useEffect, useState } from 'react'; | ||
|
||
import { ReadResult, useReadResult } from '../helpers/reads'; | ||
import { | ||
ProfilePriceResult, | ||
useProfilePriceController, | ||
} from './adapters/useProfilePriceController'; | ||
|
||
export type { ProfilePriceResult }; | ||
|
||
/** | ||
* Retrieve the prices for minting a new Lens Profile, denominated in various currencies. | ||
* | ||
* @example | ||
* ```tsx | ||
* const { data, error, loading } = useProfilePrice(); | ||
* ``` | ||
* | ||
* @category Misc | ||
* @group Hooks | ||
*/ | ||
export function useProfilePrice(): ReadResult<ProfilePriceResult> { | ||
const [prices, setPrices] = useState<ProfilePriceResult>(); | ||
const [error, setError] = useState<UnspecifiedError>(); | ||
const fetchPrices = useProfilePriceController(); | ||
|
||
useEffect(() => { | ||
const fetchData = async () => { | ||
const result = await fetchPrices(); | ||
|
||
if (result.isFailure()) { | ||
setError(result.error); | ||
return; | ||
} | ||
|
||
setPrices(result.value); | ||
}; | ||
|
||
void fetchData(); | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, []); | ||
|
||
return useReadResult({ error, data: { result: prices } } as QueryResult); | ||
} |