Skip to content

Commit

Permalink
Merge pull request #156 from argentlabs/feat/webwallet-sso
Browse files Browse the repository at this point in the history
feat: argent webwallet sso connect
  • Loading branch information
bluecco authored Nov 15, 2024
2 parents 1b067d9 + 2c764a6 commit 926b6b8
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
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 @@ -35,6 +35,8 @@ let _address: string | null = null

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

export class WebWalletConnector extends Connector {
Expand Down Expand Up @@ -109,9 +111,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

0 comments on commit 926b6b8

Please sign in to comment.