Skip to content

Commit

Permalink
fix: connect params
Browse files Browse the repository at this point in the history
  • Loading branch information
bluecco committed Aug 14, 2024
1 parent 1082d37 commit de49db5
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/connectors/webwallet/helpers/trpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
RpcCallsArraySchema,
StarknetMethodArgumentsSchemas,
deployAccountContractSchema,
} from "../../../window/window"
} from "@argent/x-window"
import { DEFAULT_WEBWALLET_URL } from "../constants"
import { Permission } from "@starknet-io/types-js"

Expand Down
2 changes: 1 addition & 1 deletion src/helpers/getStoreVersionFromBrowser.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Bowser from "bowser"
import type { StoreVersion } from "../window/modal"
import type { StoreVersion } from "../types/modal"

export const globalWindow = typeof window !== "undefined" ? window : null

Expand Down
2 changes: 1 addition & 1 deletion src/helpers/mapModalWallets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { isString } from "lodash-es"
import type { StarknetWindowObject } from "@starknet-io/types-js"
import { StarknetkitConnector } from "../connectors/connector"
import { ARGENT_X_ICON } from "../connectors/injected/constants"
import type { ModalWallet, StoreVersion } from "../window/modal"
import type { ModalWallet, StoreVersion } from "../types/modal"

interface SetConnectorsExpandedParams {
availableConnectors: StarknetkitConnector[]
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useStarknetkitConnectModal.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { connect } from "../main"
import { ConnectOptions, ModalResult } from "../window/modal"
import { ConnectOptions, ModalResult } from "../types/modal"

type UseStarknetkitConnectors = {
starknetkitConnectModal: () => Promise<ModalResult>
Expand Down
30 changes: 19 additions & 11 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ import {
import { mapModalWallets } from "./helpers/mapModalWallets"
import Modal from "./modal/Modal.svelte"
import css from "./theme.css?inline"
import type { ConnectOptions, ModalResult, ModalWallet } from "./window/modal"
import type {
ConnectOptions,
ConnectOptionsWithConnectors,
ModalResult,
ModalWallet,
} from "./types/modal"

let selectedConnector: StarknetkitConnector | null = null

Expand All @@ -21,12 +26,14 @@ export const connect = async ({
storeVersion = getStoreVersionFromBrowser(),
modalTheme,
dappName,
webWalletUrl = DEFAULT_WEBWALLET_URL,
argentMobileOptions,
connectors = [],
resultType = "wallet",
...restOptions
}: ConnectOptions): Promise<ModalResult> => {
}: ConnectOptionsWithConnectors | ConnectOptions): Promise<ModalResult> => {
const { webWalletUrl = DEFAULT_WEBWALLET_URL, argentMobileOptions } =
restOptions as ConnectOptions

const { connectors } = restOptions as ConnectOptionsWithConnectors

// force null in case it was disconnected from mobile app
selectedConnector = null
const availableConnectors =
Expand Down Expand Up @@ -66,8 +73,8 @@ export const connect = async ({
const authorizedWallets = await sn.getAuthorizedWallets(restOptions)

const wallet =
authorizedWallets.find((w) => w.id === lastWalletId) ??
installedWallets.length === 1
(authorizedWallets.find((w) => w.id === lastWalletId) ??
installedWallets.length === 1)
? installedWallets[0]
: undefined

Expand Down Expand Up @@ -97,7 +104,7 @@ export const connect = async ({
installedWallets,
discoveryWallets: await sn.getDiscoveryWallets(restOptions),
storeVersion,
customOrder: connectors?.length > 0,
customOrder: connectors ? connectors?.length > 0 : false,
})

const getTarget = (): ShadowRoot => {
Expand Down Expand Up @@ -157,7 +164,7 @@ export const connect = async ({
setTimeout(() => modal.$destroy())
}
},
theme: modalTheme === "system" ? null : modalTheme ?? null,
theme: modalTheme === "system" ? null : (modalTheme ?? null),
modalWallets,
},
})
Expand Down Expand Up @@ -185,9 +192,10 @@ export type {
StarknetWindowObject,
StarknetkitConnector,
defaultConnectors as starknetkitDefaultConnectors,
ConnectOptions,
ConnectOptionsWithConnectors,
}

export * from "./window"
export type * from "./window/modal"
export type * from "./types/modal"

export { useStarknetkitConnectModal } from "./hooks/useStarknetkitConnectModal"
41 changes: 41 additions & 0 deletions src/types/modal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import type { GetWalletOptions } from "@starknet-io/get-starknet-core"
import { StarknetWindowObject } from "@starknet-io/types-js"
import type { ArgentMobileConnectorOptions } from "../connectors/argentMobile"
import type {
ConnectorData,
ConnectorIcons,
StarknetkitConnector,
} from "../connectors/connector"

export type StoreVersion = "chrome" | "firefox" | "edge"

export interface ConnectOptions extends GetWalletOptions {
dappName?: string
modalMode?: "alwaysAsk" | "canAsk" | "neverAsk"
modalTheme?: "light" | "dark" | "system"
storeVersion?: StoreVersion | null
resultType?: "connector" | "wallet"
webWalletUrl?: string
argentMobileOptions: ArgentMobileConnectorOptions
}

export interface ConnectOptionsWithConnectors
extends Omit<ConnectOptions, "webWalletUrl" | "argentMobileOptions"> {
connectors?: StarknetkitConnector[]
}

export type ModalWallet = {
name: string
id: string
icon: ConnectorIcons
download?: string
subtitle?: string
title?: string
connector: StarknetkitConnector
}

export type ModalResult = {
connector: StarknetkitConnector | null
connectorData: ConnectorData | null
wallet?: StarknetWindowObject | null
}

0 comments on commit de49db5

Please sign in to comment.