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: argent webwallet sso connect #156

Merged
merged 1 commit into from
Nov 15, 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
11 changes: 11 additions & 0 deletions src/connectors/webwallet/helpers/trpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,17 @@ const appRouter = t.router({
}),
)
.mutation(async () => ({})),
connectWebwalletSSO: t.procedure
.input(
z.object({ token: z.string(), authorizedPartyId: z.string().optional() }),
)
.output(
z.object({
account: z.string().array().optional(),
chainId: z.string().optional(),
}),
)
.mutation(async () => ({})),
enable: t.procedure.output(z.string()).mutation(async () => ""),
execute: t.procedure
.input(StarknetMethodArgumentsSchemas.execute)
Expand Down
23 changes: 20 additions & 3 deletions src/connectors/webwallet/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ let _address: string | null = null

interface WebWalletConnectorOptions {
url?: string
ssoToken?: string
authorizedPartyId?: string
}

export class WebWalletConnector extends Connector {
Expand Down Expand Up @@ -108,9 +110,24 @@ export class WebWalletConnector extends Connector {
}

try {
const { account, chainId } = await (
this._wallet as WebWalletStarknetWindowObject
).connectWebwallet()
let account, chainId

if (this._options.ssoToken) {
const ssoReponse = await (
this._wallet as WebWalletStarknetWindowObject
).connectWebwalletSSO(
this._options.ssoToken,
this._options.authorizedPartyId,
)
account = ssoReponse.account
chainId = ssoReponse.chainId
} else {
const connectResponse = await (
this._wallet as WebWalletStarknetWindowObject
).connectWebwallet()
account = connectResponse.account
chainId = connectResponse.chainId
}

if (!account || !chainId) {
return {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ export type WebWalletStarknetWindowObject = StarknetWindowObject & {
account?: string[]
chainId?: string
}>
connectWebwalletSSO(
token: string,
authorizedPartyId?: string,
): Promise<{
account?: string[]
chainId?: string
}>
}

export const getArgentStarknetWindowObject = (
Expand All @@ -53,6 +60,9 @@ export const getArgentStarknetWindowObject = (
connectWebwallet: () => {
return proxyLink.connectWebwallet.mutate()
},
connectWebwalletSSO: (token, authorizedPartyId) => {
return proxyLink.connectWebwalletSSO.mutate({ token, authorizedPartyId })
},
async request(call) {
switch (call.type) {
case "wallet_requestAccounts": {
Expand Down
1 change: 0 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import type {

let selectedConnector: StarknetkitConnector | null = null


/**
*
* @param [modalMode="canAsk"] - Choose connection behavior:
Expand Down