Skip to content

Commit 5425fbd

Browse files
author
Aleksandar Cakalic
committed
Merge branch 'refs/heads/feat/argent-one-button-connector' into beta
2 parents 8d95e82 + 7eed317 commit 5425fbd

File tree

11 files changed

+117
-26
lines changed

11 files changed

+117
-26
lines changed

package.json

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,16 @@
5757
"import": "./dist/braavos.js",
5858
"require": "./dist/braavos.cjs"
5959
},
60+
"./metamask": {
61+
"types": "./dist/metamask.d.ts",
62+
"import": "./dist/metamask.js",
63+
"require": "./dist/metamask.cjs"
64+
},
65+
"./keplr": {
66+
"types": "./dist/keplr.d.ts",
67+
"import": "./dist/keplr.js",
68+
"require": "./dist/keplr.cjs"
69+
},
6070
"./braavosMobile": {
6171
"types": "./dist/braavosMobile.d.ts",
6272
"import": "./dist/braavosMobile.js",
@@ -81,8 +91,8 @@
8191
],
8292
"dependencies": {
8393
"@argent/x-ui": "^1.70.1",
84-
"@starknet-io/get-starknet": "^4.0.2",
85-
"@starknet-io/get-starknet-core": "^4.0.2",
94+
"@starknet-io/get-starknet": "^4.0.4",
95+
"@starknet-io/get-starknet-core": "^4.0.4",
8696
"@starknet-io/types-js": "^0.7.7",
8797
"@trpc/client": "^10.38.1",
8898
"@trpc/server": "^10.38.1",

pnpm-lock.yaml

Lines changed: 21 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/connectors/argent/argentMobile/modal/starknet/adapter.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,12 +188,12 @@ export class StarknetAdapter
188188
const response = await this.client.request({ topic, chainId, request })
189189
argentModal.closeModal(true)
190190
return response
191-
} catch (error) {
191+
} catch (error: any) {
192192
argentModal.closeModal()
193-
if (error instanceof Error) {
193+
if (error instanceof Error || (error && error.message !== undefined)) {
194194
throw new Error(error.message)
195195
}
196-
throw new Error("Unknow error on requestWallet")
196+
throw new Error("Unknown error on requestWallet")
197197
}
198198
}
199199

src/connectors/injected/index.ts

Lines changed: 4 additions & 0 deletions
Large diffs are not rendered by default.

src/connectors/injected/keplr.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { InjectedConnector, InjectedConnectorOptions } from "./index"
2+
3+
export class Keplr extends InjectedConnector {
4+
constructor(options?: Omit<InjectedConnectorOptions, "id">) {
5+
super({ options: { id: "keplr", ...options } })
6+
}
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { InjectedConnector, InjectedConnectorOptions } from "./index"
2+
3+
export class MetaMask extends InjectedConnector {
4+
constructor(options?: Omit<InjectedConnectorOptions, "id">) {
5+
super({ options: { id: "metamask", ...options } })
6+
}
7+
}

src/connectors/webwallet/helpers/trpc.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,22 @@ const appRouter = t.router({
6161
}),
6262
connect: t.procedure.mutation(async () => ""),
6363
connectWebwallet: t.procedure
64+
.input(
65+
z.object({
66+
theme: z.enum(["light", "dark", "auto"]).optional(),
67+
}),
68+
)
69+
.output(
70+
z.object({
71+
account: z.string().array().optional(),
72+
chainId: z.string().optional(),
73+
}),
74+
)
75+
.mutation(async () => ({})),
76+
connectWebwalletSSO: t.procedure
77+
.input(
78+
z.object({ token: z.string(), authorizedPartyId: z.string().optional() }),
79+
)
6480
.output(
6581
z.object({
6682
account: z.string().array().optional(),

src/connectors/webwallet/index.ts

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,19 @@ import {
2828
import { DEFAULT_WEBWALLET_ICON, DEFAULT_WEBWALLET_URL } from "./constants"
2929
import { openWebwallet } from "./helpers/openWebwallet"
3030
import { setPopupOptions } from "./helpers/trpc"
31-
import type { WebWalletStarknetWindowObject } from "./starknetWindowObject/argentStarknetWindowObject"
31+
import type {
32+
Theme,
33+
WebWalletStarknetWindowObject,
34+
} from "./starknetWindowObject/argentStarknetWindowObject"
3235

3336
let _wallet: StarknetWindowObject | null = null
3437
let _address: string | null = null
3538

3639
interface WebWalletConnectorOptions {
3740
url?: string
41+
theme?: Theme
42+
ssoToken?: string
43+
authorizedPartyId?: string
3844
}
3945

4046
export class WebWalletConnector extends Connector {
@@ -109,9 +115,24 @@ export class WebWalletConnector extends Connector {
109115
}
110116

111117
try {
112-
const { account, chainId } = await (
113-
this._wallet as WebWalletStarknetWindowObject
114-
).connectWebwallet()
118+
let account, chainId
119+
120+
if (this._options.ssoToken) {
121+
const ssoReponse = await (
122+
this._wallet as WebWalletStarknetWindowObject
123+
).connectWebwalletSSO(
124+
this._options.ssoToken,
125+
this._options.authorizedPartyId,
126+
)
127+
account = ssoReponse.account
128+
chainId = ssoReponse.chainId
129+
} else {
130+
const connectResponse = await (
131+
this._wallet as WebWalletStarknetWindowObject
132+
).connectWebwallet({ theme: this._options.theme })
133+
account = connectResponse.account
134+
chainId = connectResponse.chainId
135+
}
115136

116137
if (!account || !chainId) {
117138
return {}

src/connectors/webwallet/starknetWindowObject/argentStarknetWindowObject.ts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,22 @@ export type LoginStatus = {
3333
isPreauthorized?: boolean
3434
}
3535

36+
export type Theme = "light" | "dark"
37+
38+
type ConnectWebwalletProps = {
39+
theme?: Theme
40+
}
41+
3642
export type WebWalletStarknetWindowObject = StarknetWindowObject & {
3743
getLoginStatus(): Promise<LoginStatus>
38-
connectWebwallet(): Promise<{
44+
connectWebwallet(props?: ConnectWebwalletProps): Promise<{
45+
account?: string[]
46+
chainId?: string
47+
}>
48+
connectWebwalletSSO(
49+
token: string,
50+
authorizedPartyId?: string,
51+
): Promise<{
3952
account?: string[]
4053
chainId?: string
4154
}>
@@ -50,8 +63,12 @@ export const getArgentStarknetWindowObject = (
5063
getLoginStatus: () => {
5164
return proxyLink.getLoginStatus.mutate()
5265
},
53-
connectWebwallet: () => {
54-
return proxyLink.connectWebwallet.mutate()
66+
connectWebwallet: (props = {}) => {
67+
const { theme } = props
68+
return proxyLink.connectWebwallet.mutate({ theme })
69+
},
70+
connectWebwalletSSO: (token, authorizedPartyId) => {
71+
return proxyLink.connectWebwalletSSO.mutate({ token, authorizedPartyId })
5572
},
5673
async request(call) {
5774
switch (call.type) {

src/connectors/webwallet/starknetWindowObject/wormhole.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ const applyModalStyle = (iframe: HTMLIFrameElement) => {
2020
background.style.left = "0"
2121
background.style.right = "0"
2222
background.style.bottom = "0"
23-
background.style.backgroundColor = "rgba(0, 0, 0, 0.5)"
2423
background.style.zIndex = "99999"
2524
;(background.style as any).backdropFilter = "blur(4px)"
2625

0 commit comments

Comments
 (0)