diff --git a/src/connectors/argentMobile/modal/starknet/adapter.ts b/src/connectors/argentMobile/modal/starknet/adapter.ts index 39366e0..8c4152a 100644 --- a/src/connectors/argentMobile/modal/starknet/adapter.ts +++ b/src/connectors/argentMobile/modal/starknet/adapter.ts @@ -36,8 +36,8 @@ export class StarknetAdapter extends NamespaceAdapter implements ConnectedStarknetWindowObject { - id = "starknetkit" - name = "Starknet Kit" + id = "argentMobile" + name = "Argent Mobile" version = "0.1.0" icon = "" provider: ProviderInterface diff --git a/src/helpers/lastConnected.ts b/src/helpers/lastConnected.ts new file mode 100644 index 0000000..aa34de6 --- /dev/null +++ b/src/helpers/lastConnected.ts @@ -0,0 +1,7 @@ +export const setStarknetLastConnectedWallet = (id: string) => { + localStorage.setItem("starknetLastConnectedWallet", id) +} + +export const removeStarknetLastConnectedWallet = () => { + localStorage.removeItem("starknetLastConnectedWallet") +} diff --git a/src/main.ts b/src/main.ts index 118f185..bb936a1 100644 --- a/src/main.ts +++ b/src/main.ts @@ -9,6 +9,10 @@ import { mapModalWallets } from "./helpers/mapModalWallets" import { resetWalletConnect } from "./helpers/resetWalletConnect" import Modal from "./modal/Modal.svelte" import type { ConnectOptions, ModalWallet } from "./types/modal" +import { + removeStarknetLastConnectedWallet, + setStarknetLastConnectedWallet, +} from "./helpers/lastConnected" export const connect = async ({ modalMode = "canAsk", @@ -28,9 +32,9 @@ export const connect = async ({ }) : connectors - const lastWallet = await sn.getLastConnectedWallet() + const lastWalletId = localStorage.getItem("starknetLastConnectedWallet") if (modalMode === "neverAsk") { - const connector = availableConnectors.find((c) => c.id === lastWallet?.id) + const connector = availableConnectors.find((c) => c.id === lastWalletId) await connector?.connect() return connector?.wallet || null } @@ -38,19 +42,19 @@ export const connect = async ({ const installedWallets = await sn.getAvailableWallets(restOptions) // we return/display wallet options once per first-dapp (ever) connect - if (modalMode === "canAsk" && lastWallet) { + if (modalMode === "canAsk" && lastWalletId) { const preAuthorizedWallets = await sn.getPreAuthorizedWallets({ ...restOptions, }) const wallet = - preAuthorizedWallets.find((w) => w.id === lastWallet?.id) ?? + preAuthorizedWallets.find((w) => w.id === lastWalletId) ?? installedWallets.length === 1 ? installedWallets[0] : undefined if (wallet) { - const connector = availableConnectors.find((c) => c.id === lastWallet?.id) + const connector = availableConnectors.find((c) => c.id === lastWalletId) await connector?.connect() return wallet } // otherwise fallback to modal @@ -70,6 +74,9 @@ export const connect = async ({ dappName, callback: async (value: StarknetWindowObject | null) => { try { + if (value.id !== "argentWebWallet") { + setStarknetLastConnectedWallet(value.id) + } resolve(value) } finally { setTimeout(() => modal.$destroy()) @@ -84,5 +91,6 @@ export const connect = async ({ export function disconnect(options: DisconnectOptions = {}): Promise { resetWalletConnect() + removeStarknetLastConnectedWallet() return sn.disconnect(options) }