Skip to content

Commit

Permalink
chore: fix discrepancies with docs (#798)
Browse files Browse the repository at this point in the history
* chore: removes SelfFundedProtocolTransactionRequest

* chore: exports AsyncTransactionResult

* Adds missing exports and fixes TSDoc

* Exports missing helpers

* fix: exports missing ProfileFields from react sdks

* Adds missing changesets
  • Loading branch information
cesarenaldi authored Jan 17, 2024
1 parent 0c69a5c commit c2b05bd
Show file tree
Hide file tree
Showing 23 changed files with 74 additions and 71 deletions.
8 changes: 8 additions & 0 deletions .changeset/hip-baboons-camp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@lens-protocol/api-bindings": patch
"@lens-protocol/react": patch
"@lens-protocol/react-native": patch
"@lens-protocol/react-web": patch
---

**Fixed**: missing export of `findCollectModuleSettings` and `isCollectModuleSettings` helpers
7 changes: 7 additions & 0 deletions .changeset/shaggy-colts-turn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@lens-protocol/react": patch
"@lens-protocol/react-native": patch
"@lens-protocol/react-web": patch
---

**fixed:** return type of `useLazyModuleMetadata`
7 changes: 7 additions & 0 deletions .changeset/silent-mangos-yawn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@lens-protocol/react": patch
"@lens-protocol/react-native": patch
"@lens-protocol/react-web": patch
---

**fix:** exports missing `AsyncTransactionResult`
7 changes: 7 additions & 0 deletions .changeset/witty-roses-burn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@lens-protocol/react": patch
"@lens-protocol/react-native": patch
"@lens-protocol/react-web": patch
---

**fix:** exports missing `ProfileFields` type
7 changes: 0 additions & 7 deletions examples/web/src/publications/UseOpenAction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,6 @@ function TestScenario({ id }: { id: PublicationId }) {
</button>
</RequireWalletSession>
</div>
<div className="notice">
<p>
At the time of this example writing there is a known API issue resulting in{' '}
<code>PublicationOperations.canCollect</code> (SDK alias of <code>canAct</code>) returning
always <code>'NO'</code>.
</p>
</div>
</div>
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as gql from '../graphql/generated';
import { OpenActionModuleSettings, PrimaryPublication } from '../publication';

export type KnownCollectModuleSettings =
export type CollectModuleSettings =
| gql.LegacyAaveFeeCollectModuleSettings
| gql.LegacyErc4626FeeCollectModuleSettings
| gql.LegacyFeeCollectModuleSettings
Expand Down Expand Up @@ -31,16 +31,26 @@ const ModulesWithKnownCollectCapability: Record<OpenActionModuleSettings['__type
UnknownOpenActionModuleSettings: false,
};

export function isKnownCollectModuleSettings(
/**
* Given an open action module settings, determine if it is a collect module
*
* @experimental This function is not yet stable and may be removed in a future release
*/
export function isCollectModuleSettings(
settings: OpenActionModuleSettings,
): settings is KnownCollectModuleSettings {
): settings is CollectModuleSettings {
return ModulesWithKnownCollectCapability[settings.__typename] ?? false;
}

export function findCollectActionModuleSettings(
/**
* Given a publication, find the collect module settings if any
*
* @experimental This function is not yet stable and may be removed in a future release
*/
export function findCollectModuleSettings(
collectable: PrimaryPublication,
): KnownCollectModuleSettings | null {
): CollectModuleSettings | null {
if (!collectable.openActionModules) return null;

return collectable.openActionModules.find(isKnownCollectModuleSettings) ?? null;
return collectable.openActionModules.find(isCollectModuleSettings) ?? null;
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
mockSimpleCollectOpenActionSettingsFragment,
} from '../../__helpers__';
import { AnyPublication } from '../../publication';
import { KnownCollectModuleSettings } from '../KnownCollectModuleSettings';
import { CollectModuleSettings } from '../CollectModuleSettings';
import { resolveTokenAllowanceRequest } from '../token-allowance';

const amount = mockDaiAmount(42);
Expand Down Expand Up @@ -61,7 +61,7 @@ describe(`Given the ${resolveTokenAllowanceRequest.name} helper`, () => {

describe.each<{
name: string;
mockPublicationWith: (settings: KnownCollectModuleSettings) => AnyPublication;
mockPublicationWith: (settings: CollectModuleSettings) => AnyPublication;
}>([
{
name: 'Post',
Expand Down
1 change: 1 addition & 0 deletions packages/api-bindings/src/lens/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './amount';
export * from './CollectModuleSettings';
export * from './isValidHandle';
export * from './omitTypename';
export * from './open-actions';
Expand Down
4 changes: 2 additions & 2 deletions packages/api-bindings/src/lens/utils/open-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Data, EvmAddress, invariant, never } from '@lens-protocol/shared-kernel

import * as gql from '../graphql/generated';
import { AnyPublication, OpenActionModuleSettings } from '../publication';
import { findCollectActionModuleSettings } from './KnownCollectModuleSettings';
import { findCollectModuleSettings } from './CollectModuleSettings';
import { erc20Amount } from './amount';

/**
Expand Down Expand Up @@ -76,7 +76,7 @@ function resolveCollectRequestFor(
context: OpenActionContext<CollectParams>,
): CollectRequest {
const collectable = publication.__typename === 'Mirror' ? publication.mirrorOn : publication;
const settings = findCollectActionModuleSettings(collectable);
const settings = findCollectModuleSettings(collectable);

invariant(settings, 'No open action module settings found for publication');

Expand Down
4 changes: 2 additions & 2 deletions packages/api-bindings/src/lens/utils/token-allowance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import { assertNever, invariant, never } from '@lens-protocol/shared-kernel';

import { Profile } from '../graphql/generated';
import { AnyPublication, PrimaryPublication } from '../publication';
import { findCollectActionModuleSettings } from './KnownCollectModuleSettings';
import { findCollectModuleSettings } from './CollectModuleSettings';
import { erc20Amount } from './amount';

export function resolveTokenAllowanceRequestForCollect(
publication: PrimaryPublication,
limit: TokenAllowanceLimit,
): TokenAllowanceRequest {
const module = findCollectActionModuleSettings(publication);
const module = findCollectModuleSettings(publication);

invariant(module, `Publication ${publication.id} has no collect module`);

Expand Down
1 change: 1 addition & 0 deletions packages/client/src/submodules/modules/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ export type {
GenerateModuleCurrencyApprovalResultFragment,
KnownSupportedModuleFragment,
ModuleInfoFragment,
ModuleMetadataResultFragment,
UnknownSupportedModuleFragment,
} from './graphql/modules.generated';
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export type RecipientWithSplit = {
/**
* The split of the collect fee.
*
* Number between 0-1 with up to 2 decimals of precision (e.g. 0.5 for 50%)
* Number between 1-100 with up to 2 decimals of precision (e.g. 10.5 for 10.5%)
*/
split: number;
};
Expand Down
4 changes: 3 additions & 1 deletion packages/react/src/misc/useModuleMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { useLensApolloClient } from '../helpers/arguments';
import { ReadResult, useReadResult } from '../helpers/reads';
import { useDeferredTask, UseDeferredTask } from '../helpers/tasks';

export type { ModuleMetadataResult };

/**
* {@link useModuleMetadata} hook arguments
*/
Expand Down Expand Up @@ -69,7 +71,7 @@ export type FetchModuleMetadataArgs = {
* @group Hooks
*/
export function useLazyModuleMetadata(): UseDeferredTask<
ModuleMetadataResult | null,
ModuleMetadataResult,
NotFoundError | UnspecifiedError,
UseModuleMetadataArgs
> {
Expand Down
1 change: 1 addition & 0 deletions packages/react/src/profile/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export type {
HandleInfo,
NftImage,
Profile,
ProfileFields,
ProfileActionHistory,
ProfileGuardianResult,
ProfileManager,
Expand Down
2 changes: 2 additions & 0 deletions packages/react/src/publication/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,6 @@ export {
isMirrorPublication,
isQuotePublication,
isPrimaryPublication,
findCollectModuleSettings,
isCollectModuleSettings,
} from '@lens-protocol/api-bindings';

This file was deleted.

13 changes: 1 addition & 12 deletions packages/react/src/transactions/adapters/__helpers__/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@ import {
mockProtocolTransactionRequestModel,
mockTransactionHash,
} from '@lens-protocol/domain/mocks';
import { ChainType, Data } from '@lens-protocol/shared-kernel';
import { ChainType } from '@lens-protocol/shared-kernel';
import { mockEvmAddress } from '@lens-protocol/shared-kernel/mocks';
import { MockProvider } from 'ethereum-waffle';
import { mock } from 'jest-mock-extended';

import { UnsignedProtocolCall } from '../../../wallet/adapters/ConcreteWallet';
import { ITransactionObserver, TransactionFactory } from '../../infrastructure/TransactionFactory';
import { MetaTransactionData, NativeTransactionData } from '../ITransactionFactory';
import { SelfFundedProtocolTransactionRequest } from '../SelfFundedProtocolTransactionRequest';

export function mockITransactionFactory(
transactionObserver: ITransactionObserver = mock<ITransactionObserver>(),
Expand Down Expand Up @@ -86,16 +85,6 @@ export function mockNativeTransactionDataWithRelayerTxId<
};
}

export function mockSelfFundedProtocolTransactionRequest<
TRequest extends ProtocolTransactionRequestModel,
>(): SelfFundedProtocolTransactionRequest<TRequest> {
return {
contractAddress: mockEvmAddress(),
encodedData: faker.datatype.hexadecimal({ length: 32 }) as Data,
...mockAnyTransactionRequestModel(),
} as SelfFundedProtocolTransactionRequest<TRequest>;
}

export function assertUnsignedProtocolCallCorrectness<T extends ProtocolTransactionRequestModel>(
unsignedProtocolCall: UnsignedProtocolCall<T>,
broadcastResult: {
Expand Down
2 changes: 2 additions & 0 deletions packages/react/src/transactions/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export type { AsyncTransactionResult } from './adapters/AsyncTransactionResult';

export * from './useApproveModule';
export * from './useClaimHandle';
export * from './useCreateComment';
Expand Down
4 changes: 2 additions & 2 deletions packages/react/src/transactions/useCreateComment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,11 @@ export type CreateCommentArgs = {
* recipients: [
* {
* recipient: '0x4f94FAFEE38F545920485fC747467EFc85C302E0',
* split: 0.3, // 30%
* split: 30, // 30%
* },
* {
* recipient: '0x097A4fE5cfFf0360438990b88549d4288748f6cB',
* split: 0.7, // 70%
* split: 70, // 70%
* },
* ],
* endsAt: new Date('2025-12-31T00:00:00.000Z'),
Expand Down
16 changes: 6 additions & 10 deletions packages/react/src/transactions/useCreatePost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,11 @@ export type CreatePostArgs = {
* recipients: [
* {
* recipient: '0x4f94FAFEE38F545920485fC747467EFc85C302E0',
* split: 0.3, // 30%
* split: 30, // 30%
* },
* {
* recipient: '0x097A4fE5cfFf0360438990b88549d4288748f6cB',
* split: 0.7, // 70%
* split: 70, // 70%
* },
* ],
* endsAt: new Date('2025-12-31T00:00:00.000Z'),
Expand Down Expand Up @@ -390,7 +390,7 @@ export type CreatePostArgs = {
* case 'BroadcastingError':
* if ([BroadcastingErrorReason.NOT_SPONSORED, BroadcastingErrorReason.RATE_LIMITED].includes(sponsoredResult.error.reason)) {
*
* const chargedResult = = await execute({
* const chargedResult = await execute({
* metadata: uri,
* sponsored: false,
* });
Expand Down Expand Up @@ -460,17 +460,13 @@ export function useCreatePost(): UseDeferredTask<

return useDeferredTask(async (args: CreatePostArgs) => {
invariant(
session?.authenticated,
'You must be authenticated to create a post. Use `useLogin` hook to authenticate.',
);
invariant(
session.type === SessionType.WithProfile,
'You must have a profile to create a post.',
session?.type === SessionType.WithProfile,
'You must be authenticated with a Profile to post. Use `useLogin` hook to authenticate.',
);

const request = createPostRequest({
signless: session.profile.signless,
sponsored: args.sponsored ?? true,
sponsored: args.sponsored ?? session.profile.sponsor,
...args,
});

Expand Down
4 changes: 2 additions & 2 deletions packages/react/src/transactions/useCreateQuote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,11 @@ export type CreateQuoteArgs = {
* recipients: [
* {
* recipient: '0x4f94FAFEE38F545920485fC747467EFc85C302E0',
* split: 0.3, // 30%
* split: 30, // 30%
* },
* {
* recipient: '0x097A4fE5cfFf0360438990b88549d4288748f6cB',
* split: 0.7, // 70%
* split: 70, // 70%
* },
* ],
* endsAt: new Date('2025-12-31T00:00:00.000Z'),
Expand Down
2 changes: 0 additions & 2 deletions packages/react/src/wallet/adapters/ConcreteWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import { z } from 'zod';
import { UnsignedVote } from '../../polls/adapters/SnapshotVoteFactory';
import { ISnapshotVote } from '../../polls/adapters/SnapshotVoteRelayer';
import { ITransactionFactory } from '../../transactions/adapters/ITransactionFactory';
import { SelfFundedProtocolTransactionRequest } from '../../transactions/adapters/SelfFundedProtocolTransactionRequest';
import { assertErrorObjectWithCode } from './errors';

export type RequiredSigner = Signer & TypedDataSigner;
Expand Down Expand Up @@ -72,7 +71,6 @@ export class UnsignedProtocolCall<T extends ProtocolTransactionRequestModel>
id: string;
request: T;
typedData: TypedData;
fallback?: SelfFundedProtocolTransactionRequest<T>; // TODO remove fallback
}): UnsignedProtocolCall<T> {
return new UnsignedProtocolCall(id, request, typedData);
}
Expand Down
6 changes: 1 addition & 5 deletions packages/react/src/wallet/adapters/__helpers__/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ import { mock } from 'jest-mock-extended';
import { when } from 'jest-when';

import { ITransactionFactory } from '../../../transactions/adapters/ITransactionFactory';
import {
mockSelfFundedProtocolTransactionRequest,
mockTypedData,
} from '../../../transactions/adapters/__helpers__/mocks';
import { mockTypedData } from '../../../transactions/adapters/__helpers__/mocks';
import {
ConcreteWallet,
ISignerFactory,
Expand Down Expand Up @@ -64,7 +61,6 @@ export function mockUnsignedProtocolCall<T extends ProtocolTransactionRequestMod
id: faker.datatype.uuid(),
request,
typedData,
fallback: mockSelfFundedProtocolTransactionRequest<T>(),
});
}

Expand Down

0 comments on commit c2b05bd

Please sign in to comment.