Skip to content

Commit e8a5a9d

Browse files
authored
Merge pull request #246 from argentlabs/fix/bug-with-installed-wallet-not-opening
fix: set installed prop inside `getModalWallet` by window object
2 parents 3ab5926 + ca2d086 commit e8a5a9d

File tree

4 files changed

+20
-11
lines changed

4 files changed

+20
-11
lines changed

src/connectors/argent/argentMobile/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ export class ArgentMobileBaseConnector extends Connector {
232232
url,
233233
icons,
234234
rpcUrl: providerRpcUrl,
235-
modalWallet: getModalWallet(this, discoveryWallets),
235+
modalWallet: getModalWallet(this, { discoveryWallets }),
236236
}
237237

238238
if (projectId === DEFAULT_PROJECT_ID) {

src/helpers/mapModalWallets.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { WalletProvider } from "@starknet-io/get-starknet-core"
22
import { isString } from "lodash-es"
33
import type { StarknetWindowObject } from "@starknet-io/types-js"
4-
import {
4+
import type {
55
Connector,
66
StarknetkitCompoundConnector,
77
StarknetkitConnector,
@@ -30,10 +30,13 @@ export function getModalWallet(
3030
| Connector
3131
| StarknetkitConnector
3232
| StarknetkitCompoundConnector,
33-
discoveryWallets?: WalletProvider[],
34-
_storeVersion?: StoreVersion | null,
33+
options?: {
34+
installedWallets?: StarknetWindowObject[]
35+
discoveryWallets?: WalletProvider[]
36+
storeVersion?: StoreVersion | null
37+
},
3538
): ModalWallet {
36-
let storeVersion = _storeVersion
39+
let storeVersion = options?.storeVersion
3740
if (!storeVersion) {
3841
storeVersion = getStoreVersionFromBrowser()
3942
}
@@ -44,17 +47,21 @@ export function getModalWallet(
4447

4548
const isCompound = isCompoundConnector(connectorOrCompoundConnector)
4649

47-
const downloads = discoveryWallets?.find(
50+
const downloads = options?.discoveryWallets?.find(
4851
(d) =>
4952
d.id === (connector.id === "argentMobile" ? "argentX" : connector.id),
5053
)?.downloads
5154

55+
const installed =
56+
connector.id === "argentMobile" ||
57+
Boolean(options?.installedWallets?.find((w) => w.id === connector.id))
58+
5259
return {
60+
installed,
5361
name: isCompound ? connectorOrCompoundConnector.name : connector.name,
5462
id: connector.id,
5563
icon: isCompound ? connectorOrCompoundConnector.icon : connector.icon,
5664
connector: connectorOrCompoundConnector,
57-
installed: connector.id === "argentMobile",
5865
title:
5966
"title" in connector && isString(connector.title)
6067
? connector.title
@@ -105,7 +112,6 @@ export const mapModalWallets = ({
105112
if (installed) {
106113
let icon
107114
let name
108-
let download
109115

110116
if (isCompound) {
111117
icon = _c.icon
@@ -166,7 +172,7 @@ export const mapModalWallets = ({
166172
return null
167173
}
168174

169-
return getModalWallet(_c, discoveryWallets)
175+
return getModalWallet(_c, { discoveryWallets })
170176
})
171177
.filter((c): c is ModalWallet => c !== null)
172178

src/main.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ export const connect = async ({
245245
theme: modalTheme === "system" ? null : (modalTheme ?? null),
246246
modalWallets,
247247
discoveryWallets,
248+
installedWallets,
248249
},
249250
}) as unknown as ModalInstance // Prevents vite build errors
250251
})

src/modal/Modal.svelte

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<script lang="ts">
22
import { onMount } from "svelte"
33
import type { WalletProvider } from "@starknet-io/get-starknet-core"
4+
import type { StarknetWindowObject } from "@starknet-io/types-js"
45
56
import {
67
type Callback,
@@ -41,6 +42,7 @@
4142
}
4243
4344
export let discoveryWallets: WalletProvider[]
45+
export let installedWallets: StarknetWindowObject[]
4446
export let modalWallets: ModalWallet[] = []
4547
export let selectedWallet: ModalWallet | null = null
4648
$: selectedConnector =
@@ -75,7 +77,7 @@
7577
if (isInAppBrowser) {
7678
try {
7779
setTimeout(() => {
78-
void callback(getModalWallet(new ArgentX()))
80+
void callback(getModalWallet(new ArgentX(), { installedWallets }))
7981
})
8082
} catch (e) {
8183
console.error(e)
@@ -90,7 +92,7 @@
9092
if (isBraavosMobileApp) {
9193
try {
9294
setTimeout(() => {
93-
void callback(getModalWallet(new Braavos()))
95+
void callback(getModalWallet(new Braavos(), { installedWallets }))
9496
})
9597
} catch (e) {
9698
console.error(e)

0 commit comments

Comments
 (0)