Skip to content

Commit 72ca7ce

Browse files
author
Aleksandar Cakalic
authored
Merge pull request #201 from argentlabs/fix/use-modal-hook
Fix/use modal hook
2 parents 541dca0 + 3cc918e commit 72ca7ce

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

src/hooks/useStarknetkitConnectModal.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ const useStarknetkitConnectModal = (
2626
const starknetkitConnectModal = async (): Promise<ModalResult> => {
2727
return await connect({
2828
...options,
29-
resultType: options?.resultType ?? "connector",
29+
skipEmit: true,
30+
resultType: undefined,
3031
})
3132
}
3233

src/main.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ import {
99
type ModalResult,
1010
type ModalWallet,
1111
} from "./types/modal"
12-
import {
12+
import type {
1313
Connector,
1414
StarknetkitConnector,
1515
StarknetkitCompoundConnector,
16-
type ConnectorData,
16+
ConnectorData,
1717
} from "./connectors"
1818
import { DEFAULT_WEBWALLET_URL } from "./connectors/webwallet/constants"
1919

@@ -25,7 +25,11 @@ import {
2525
setStarknetLastConnectedWallet,
2626
} from "./helpers/lastConnected"
2727
import { mapModalWallets } from "./helpers/mapModalWallets"
28-
import { extractConnector, findConnectorById } from "./helpers/connector"
28+
import {
29+
extractConnector,
30+
findConnectorById,
31+
isCompoundConnector,
32+
} from "./helpers/connector"
2933
import { getModalTarget } from "./helpers/modal"
3034

3135
import Modal from "./modal/Modal.svelte"
@@ -44,6 +48,7 @@ let selectedConnector: StarknetkitConnector | null = null
4448
* @param [dappName] - Name of your dapp, displayed in the modal
4549
* @param [resultType="wallet"] - It will by default return selected wallet's connector by default, otherwise null
4650
* @param [connectors] - Array of wallet connectors to show in the modal
51+
* @param [skipEmit] - Needed for internal handling of useStarknetkitConnectModal hook
4752
* @param [webWalletUrl="https://web.argent.xyz"] - Link to Argent's web wallet - Mainnet env by default, if as a dApp for integration and testing purposes, you need access to an internal testnet environment, please contact Argent
4853
* @param [argentMobileOptions] - Argent Mobile connector options - used only when `connectors` is not explicitly passed
4954
* @param [argentMobileOptions.dappName] - Name of the dapp
@@ -66,6 +71,7 @@ export const connect = async ({
6671
modalTheme,
6772
dappName,
6873
resultType = "wallet",
74+
skipEmit = false,
6975
...restOptions
7076
}: ConnectOptionsWithConnectors | ConnectOptions): Promise<ModalResult> => {
7177
const { webWalletUrl = DEFAULT_WEBWALLET_URL, argentMobileOptions } =
@@ -83,6 +89,19 @@ export const connect = async ({
8389
})
8490
: connectors
8591

92+
if (skipEmit) {
93+
// This is ugly but needed fix for useStarknetkitConnectModal
94+
availableConnectors?.map((connector) => {
95+
if (isCompoundConnector(connector)) {
96+
if ("connector" in connector && "_options" in connector.connector) {
97+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
98+
// @ts-expect-error
99+
connector.connector._options.shouldEmit = false
100+
}
101+
}
102+
})
103+
}
104+
86105
const lastWalletId = localStorage.getItem("starknetLastConnectedWallet")
87106
if (modalMode === "neverAsk") {
88107
try {

src/types/modal.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export interface ConnectOptions extends GetWalletOptions {
3232
resultType?: "connector" | "wallet"
3333
webWalletUrl?: string
3434
argentMobileOptions: ArgentMobileConnectorOptions
35+
skipEmit?: boolean
3536
}
3637

3738
export interface ConnectOptionsWithConnectors

0 commit comments

Comments
 (0)