Skip to content

Commit 43fed59

Browse files
author
Aleksandar Cakalic
committed
Merge branch 'refs/heads/feat/argent-one-button-connector' into beta
2 parents 1ca776b + e991c89 commit 43fed59

File tree

9 files changed

+43
-55
lines changed

9 files changed

+43
-55
lines changed

src/connectors/argent/argentMobile/index.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { removeStarknetLastConnectedWallet } from "../../../helpers/lastConnecte
2424
import { getRandomPublicRPCNode } from "../../../helpers/publicRcpNodes"
2525
import { resetWalletConnect } from "../../../helpers/resetWalletConnect"
2626
import {
27+
ConnectArgs,
2728
Connector,
2829
type ConnectorData,
2930
type ConnectorIcons,
@@ -97,22 +98,15 @@ export class ArgentMobileBaseConnector extends Connector {
9798
return this._wallet
9899
}
99100

100-
async connect(
101-
props:
102-
| {
103-
onlyQRCode?: boolean
104-
}
105-
| undefined,
106-
): Promise<ConnectorData> {
107-
await this.ensureWallet({ onlyQRCode: props?.onlyQRCode })
101+
async connect(_args: ConnectArgs = {}): Promise<ConnectorData> {
102+
await this.ensureWallet({ onlyQRCode: _args?.onlyQRCode })
108103

109104
if (!this._wallet) {
110105
throw new ConnectorNotFoundError()
111106
}
112107

113108
const accounts = await this._wallet.request({
114109
type: "wallet_requestAccounts",
115-
params: { silent_mode: false }, // explicit to show the modal
116110
})
117111

118112
const chainId = await this.chainId()

src/connectors/braavosMobile/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
} from "@starknet-io/types-js"
88
import { AccountInterface, ProviderInterface, ProviderOptions } from "starknet"
99
import {
10+
ConnectArgs,
1011
Connector,
1112
type ConnectorData,
1213
type ConnectorIcons,
@@ -52,7 +53,7 @@ export class BraavosMobileBaseConnector extends Connector {
5253
throw new Error("not implemented")
5354
}
5455

55-
async connect(): Promise<ConnectorData> {
56+
async connect(_args: ConnectArgs = {}): Promise<ConnectorData> {
5657
await this.ensureWallet()
5758

5859
// will return empty data, connect will only open braavos mobile app

src/connectors/connector.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ export interface ConnectorEvents {
2828
disconnect(): void
2929
}
3030

31-
export type ConnectOptions = {
32-
silent_mode: boolean
31+
export type ConnectArgs = {
32+
chainIdHint?: bigint
3333
onlyQRCode?: boolean
3434
}
3535

@@ -46,7 +46,7 @@ export abstract class Connector extends EventEmitter<ConnectorEvents> {
4646
/** Whether connector is already authorized */
4747
abstract ready(): Promise<boolean>
4848
/** Connect wallet. */
49-
abstract connect(params?: ConnectOptions): Promise<ConnectorData>
49+
abstract connect(params?: ConnectArgs): Promise<ConnectorData>
5050
/** Disconnect wallet. */
5151
abstract disconnect(): Promise<void>
5252
/** Get current account silently. Return null if the account is not authorized */

src/connectors/injected/index.ts

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
} from "../../errors"
1919
import { removeStarknetLastConnectedWallet } from "../../helpers/lastConnected"
2020
import {
21-
ConnectOptions,
21+
ConnectArgs,
2222
Connector,
2323
type ConnectorData,
2424
type ConnectorIcons,
@@ -141,7 +141,7 @@ export class InjectedConnector extends Connector {
141141
return new Account(provider, accounts[0], "")
142142
}
143143

144-
async connect(params: ConnectOptions): Promise<ConnectorData> {
144+
async connect(_args: ConnectArgs = {}): Promise<ConnectorData> {
145145
this.ensureWallet()
146146

147147
if (!this._wallet) {
@@ -150,16 +150,9 @@ export class InjectedConnector extends Connector {
150150

151151
let accounts: string[]
152152
try {
153-
accounts = await this.request(
154-
params
155-
? {
156-
type: "wallet_requestAccounts",
157-
params,
158-
}
159-
: {
160-
type: "wallet_requestAccounts",
161-
},
162-
)
153+
accounts = await this.request({
154+
type: "wallet_requestAccounts",
155+
})
163156
} catch {
164157
throw new UserRejectedRequestError()
165158
}

src/connectors/webwallet/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
import { getStarknetChainId } from "../../helpers/getStarknetChainId"
2121
import { removeStarknetLastConnectedWallet } from "../../helpers/lastConnected"
2222
import {
23+
ConnectArgs,
2324
Connector,
2425
type ConnectorData,
2526
type ConnectorIcons,
@@ -100,7 +101,7 @@ export class WebWalletConnector extends Connector {
100101
return "Powered by Argent"
101102
}
102103

103-
async connect(): Promise<ConnectorData> {
104+
async connect(_args: ConnectArgs = {}): Promise<ConnectorData> {
104105
await this.ensureWallet()
105106

106107
if (!this._wallet) {

src/helpers/defaultConnectors.ts

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,12 @@ import {
22
StarknetkitCompoundConnector,
33
StarknetkitConnector,
44
} from "../connectors"
5-
import {
6-
type ArgentMobileConnectorOptions,
7-
} from "../connectors/argent/argentMobile"
5+
import { type ArgentMobileConnectorOptions } from "../connectors/argent/argentMobile"
86
import { BraavosMobileBaseConnector } from "../connectors/braavosMobile"
97
import { WebWalletConnector } from "../connectors/webwallet"
108
import { Braavos } from "../connectors/injected/braavos"
119
import { Argent } from "../connectors/argent"
12-
13-
const isMobileDevice = () => {
14-
// Primary method: User Agent + Touch support check
15-
const userAgent = navigator.userAgent.toLowerCase()
16-
const isMobileUA =
17-
/android|webos|iphone|ipad|ipod|blackberry|windows phone/.test(userAgent)
18-
const hasTouchSupport =
19-
"ontouchstart" in window || navigator.maxTouchPoints > 0
20-
21-
// Backup method: Screen size
22-
const isSmallScreen = window.innerWidth <= 768
23-
24-
// Combine checks: Must match user agent AND (touch support OR small screen)
25-
return isMobileUA && (hasTouchSupport || isSmallScreen)
26-
}
10+
import { isMobileDevice, isSafari } from "./navigator"
2711

2812
export const defaultConnectors = ({
2913
argentMobileOptions,
@@ -32,19 +16,14 @@ export const defaultConnectors = ({
3216
argentMobileOptions: ArgentMobileConnectorOptions
3317
webWalletUrl?: string
3418
}): (StarknetkitConnector | StarknetkitCompoundConnector)[] => {
35-
const isSafari =
36-
typeof window !== "undefined"
37-
? /^((?!chrome|android).)*safari/i.test(navigator.userAgent)
38-
: false
39-
4019
const defaultConnectors: (
4120
| StarknetkitConnector
4221
| StarknetkitCompoundConnector
4322
)[] = []
4423

4524
defaultConnectors.push(new Argent({ mobile: argentMobileOptions }))
4625

47-
if (!isSafari) {
26+
if (!isSafari()) {
4827
defaultConnectors.push(new Braavos())
4928
}
5029

src/helpers/navigator.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
export const isMobileDevice = () => {
2+
// Primary method: User Agent + Touch support check
3+
const userAgent = navigator.userAgent.toLowerCase()
4+
const isMobileUA =
5+
/android|webos|iphone|ipad|ipod|blackberry|windows phone/.test(userAgent)
6+
const hasTouchSupport =
7+
"ontouchstart" in window || navigator.maxTouchPoints > 0
8+
9+
// Backup method: Screen size
10+
const isSmallScreen = window.innerWidth <= 768
11+
12+
// Combine checks: Must match user agent AND (touch support OR small screen)
13+
return isMobileUA && (hasTouchSupport || isSmallScreen)
14+
}
15+
16+
export const isSafari = () =>
17+
typeof window !== "undefined"
18+
? /^((?!chrome|android).)*safari/i.test(navigator.userAgent)
19+
: false

src/main.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ export const connect = async ({
9292

9393
if (connector && resultType === "wallet") {
9494
connectorData = await connector.connect({
95-
silent_mode: true,
9695
onlyQRCode: true,
9796
})
9897
}
@@ -129,7 +128,6 @@ export const connect = async ({
129128
connectorData =
130129
(await connector?.connect({
131130
onlyQRCode: true,
132-
silent_mode: false,
133131
})) ?? null
134132
}
135133

@@ -189,7 +187,6 @@ export const connect = async ({
189187
const connectorData =
190188
(await selectedConnector?.connect({
191189
onlyQRCode: true,
192-
silent_mode: false,
193190
})) ?? null
194191
if (selectedConnector !== null) {
195192
setStarknetLastConnectedWallet(selectedConnector.id)

src/modal/Modal.svelte

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@
5959
6060
if (isInAppBrowser) {
6161
try {
62-
void callback(getModalWallet(new ArgentX()))
62+
setTimeout(() => {
63+
void callback(getModalWallet(new ArgentX()))
64+
})
6365
} catch (e) {
6466
console.error(e)
6567
}
@@ -72,7 +74,9 @@
7274
7375
if (isBraavosMobileApp) {
7476
try {
75-
void callback(getModalWallet(new Braavos()))
77+
setTimeout(() => {
78+
void callback(getModalWallet(new Braavos()))
79+
})
7680
} catch (e) {
7781
console.error(e)
7882
}

0 commit comments

Comments
 (0)