Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(headless): connect with delegated client shard #73

Merged
merged 1 commit into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions packages/waypoint/headless/client/headless-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ export type CreateHeadlessClientOpts = {
export type BaseParams = {
waypointToken: string
}
export type ConnectParam = BaseParams & {
export type ConnectParams = BaseParams & {
recoveryPassword: string
}
export type ConnectWithShardParams = BaseParams & {
clientShard: string
}
export type ReconnectParams = BaseParams
export type ValidateSponsorTxParams = BaseParams & {
txRequest: TransactionParams
Expand Down Expand Up @@ -52,7 +55,7 @@ export class HeadlessClient {
return this.baseClient.getProvider()
}

connect = async (params: ConnectParam) => {
connect = async (params: ConnectParams) => {
const { recoveryPassword, waypointToken } = params
const { baseClient, storage } = this

Expand All @@ -71,6 +74,24 @@ export class HeadlessClient {
}
}

connectWithShard = async (params: ConnectWithShardParams) => {
const { clientShard, waypointToken } = params
const { baseClient, storage } = this

baseClient.setWaypointToken(waypointToken)
baseClient.setClientShard(clientShard)

const address = await baseClient.getAddressFromClientShard()
const provider = await baseClient.getProvider()

storage.set(clientShard)

return {
address,
provider,
}
}

reconnect = async (params: ReconnectParams) => {
const { waypointToken } = params
const { baseClient, storage } = this
Expand Down
3 changes: 2 additions & 1 deletion packages/waypoint/headless/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
// simple client
export {
HeadlessClient,
type ConnectParam,
type ConnectParams,
type ConnectWithShardParams,
type CreateHeadlessClientOpts,
type ReconnectParams,
type ValidateSponsorTxParams,
Expand Down
Loading