From de49db5be9332289160915a6acc327086c8e0089 Mon Sep 17 00:00:00 2001 From: bluecco Date: Wed, 14 Aug 2024 08:46:00 +0200 Subject: [PATCH] fix: connect params --- src/connectors/webwallet/helpers/trpc.ts | 2 +- src/helpers/getStoreVersionFromBrowser.ts | 2 +- src/helpers/mapModalWallets.ts | 2 +- src/hooks/useStarknetkitConnectModal.ts | 2 +- src/main.ts | 30 +++++++++++------ src/types/modal.ts | 41 +++++++++++++++++++++++ 6 files changed, 64 insertions(+), 15 deletions(-) create mode 100644 src/types/modal.ts diff --git a/src/connectors/webwallet/helpers/trpc.ts b/src/connectors/webwallet/helpers/trpc.ts index 7f32ec3..2ebf698 100644 --- a/src/connectors/webwallet/helpers/trpc.ts +++ b/src/connectors/webwallet/helpers/trpc.ts @@ -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" diff --git a/src/helpers/getStoreVersionFromBrowser.ts b/src/helpers/getStoreVersionFromBrowser.ts index 4605ddb..ef53158 100644 --- a/src/helpers/getStoreVersionFromBrowser.ts +++ b/src/helpers/getStoreVersionFromBrowser.ts @@ -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 diff --git a/src/helpers/mapModalWallets.ts b/src/helpers/mapModalWallets.ts index 2e68a7d..73e4636 100644 --- a/src/helpers/mapModalWallets.ts +++ b/src/helpers/mapModalWallets.ts @@ -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[] diff --git a/src/hooks/useStarknetkitConnectModal.ts b/src/hooks/useStarknetkitConnectModal.ts index 23e0061..622889d 100644 --- a/src/hooks/useStarknetkitConnectModal.ts +++ b/src/hooks/useStarknetkitConnectModal.ts @@ -1,5 +1,5 @@ import { connect } from "../main" -import { ConnectOptions, ModalResult } from "../window/modal" +import { ConnectOptions, ModalResult } from "../types/modal" type UseStarknetkitConnectors = { starknetkitConnectModal: () => Promise diff --git a/src/main.ts b/src/main.ts index 0c2ee84..c3ff489 100644 --- a/src/main.ts +++ b/src/main.ts @@ -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 @@ -21,12 +26,14 @@ export const connect = async ({ storeVersion = getStoreVersionFromBrowser(), modalTheme, dappName, - webWalletUrl = DEFAULT_WEBWALLET_URL, - argentMobileOptions, - connectors = [], resultType = "wallet", ...restOptions -}: ConnectOptions): Promise => { +}: ConnectOptionsWithConnectors | ConnectOptions): Promise => { + 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 = @@ -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 @@ -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 => { @@ -157,7 +164,7 @@ export const connect = async ({ setTimeout(() => modal.$destroy()) } }, - theme: modalTheme === "system" ? null : modalTheme ?? null, + theme: modalTheme === "system" ? null : (modalTheme ?? null), modalWallets, }, }) @@ -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" diff --git a/src/types/modal.ts b/src/types/modal.ts new file mode 100644 index 0000000..3f0182a --- /dev/null +++ b/src/types/modal.ts @@ -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 { + 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 +}