-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #988 from lens-protocol/T-23102/wait-for-tx
feat: SessionClient#waitForTransaction
- Loading branch information
Showing
8 changed files
with
193 additions
and
15 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
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,37 @@ | ||
import type { EnvironmentConfig } from '@lens-protocol/env'; | ||
import type { IStorageProvider } from '@lens-protocol/storage'; | ||
|
||
/** | ||
* The client | ||
*/ | ||
export type ClientConfig = { | ||
/** | ||
* The environment configuration to use (e.g. `mainnet`, `testnet`). | ||
*/ | ||
environment: EnvironmentConfig; | ||
/** | ||
* Whether to enable caching. | ||
* | ||
* @defaultValue `false` | ||
*/ | ||
cache?: boolean; | ||
/** | ||
* Whether to enable debug mode. | ||
* | ||
* @defaultValue `false` | ||
*/ | ||
debug?: boolean; | ||
/** | ||
* The URL origin of the client. | ||
* | ||
* Use this to set the `Origin` header for requests from non-browser environments. | ||
*/ | ||
origin?: string; | ||
|
||
/** | ||
* The storage provider to use. | ||
* | ||
* @defaultValue {@link InMemoryStorageProvider} | ||
*/ | ||
storage?: IStorageProvider; | ||
}; |
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,27 @@ | ||
import type { EnvironmentConfig } from '@lens-protocol/env'; | ||
import { type IStorageProvider, InMemoryStorageProvider } from '@lens-protocol/storage'; | ||
import type { ClientConfig } from './config'; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export type Context = { | ||
environment: EnvironmentConfig; | ||
cache: boolean; | ||
debug: boolean; | ||
origin?: string; | ||
storage: IStorageProvider; | ||
}; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export function configureContext(from: ClientConfig): Context { | ||
return { | ||
environment: from.environment, | ||
cache: from.cache ?? false, | ||
debug: from.debug ?? false, | ||
origin: from.origin, | ||
storage: from.storage ?? new InMemoryStorageProvider(), | ||
}; | ||
} |
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
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,6 @@ | ||
/** | ||
* @internal | ||
*/ | ||
export function delay(ms: number): Promise<void> { | ||
return new Promise((resolve) => setTimeout(resolve, ms)); | ||
} |
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,45 @@ | ||
import { testnet } from '@lens-protocol/env'; | ||
import { describe, expect, it } from 'vitest'; | ||
|
||
import { chains } from '@lens-network/sdk/viem'; | ||
import { evmAddress, uri } from '@lens-protocol/types'; | ||
import { http, createWalletClient } from 'viem'; | ||
import { privateKeyToAccount } from 'viem/accounts'; | ||
import { handleWith } from '.'; | ||
import { post } from '../actions/post'; | ||
import { PublicClient } from '../clients'; | ||
|
||
const walletClient = createWalletClient({ | ||
account: privateKeyToAccount(import.meta.env.PRIVATE_KEY), | ||
chain: chains.testnet, | ||
transport: http(), | ||
}); | ||
|
||
const owner = evmAddress(walletClient.account.address); | ||
const app = evmAddress(import.meta.env.TEST_APP); | ||
const account = evmAddress(import.meta.env.TEST_ACCOUNT); | ||
|
||
const publicClient = PublicClient.create({ | ||
environment: testnet, | ||
origin: 'http://example.com', | ||
}); | ||
|
||
describe('Given an integration with viem', () => { | ||
describe('When handling transaction actions', () => { | ||
it('Then it should be possible to chain them with other helpers', async () => { | ||
const authenticated = await publicClient.login({ | ||
accountOwner: { account, app, owner }, | ||
signMessage: (message: string) => walletClient.signMessage({ message }), | ||
}); | ||
const sessionClient = authenticated._unsafeUnwrap(); | ||
|
||
const result = await post(sessionClient, { | ||
contentUri: uri('https://devnet.irys.xyz/3n3Ujg3jPBHX58MPPqYXBSQtPhTgrcTk4RedJgV1Ejhb'), | ||
}) | ||
.andThen(handleWith(walletClient)) | ||
.andThen(sessionClient.waitForTransaction); | ||
|
||
expect(result.isOk(), result.isErr() ? result.error.message : undefined).toBe(true); | ||
}); | ||
}); | ||
}); |
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