starknetkit
Version:
<!-- logo --> <p align="center"> <img width='300' src="https://starknetkit-website-git-blo-1541-argentlabs.vercel.app/starknetKit-logo.svg"> </p>
139 lines (138 loc) • 4.8 kB
JavaScript
import { m as w } from "./core-7c9d487b.js";
import { M as $, g as B, L as a } from "./Modal-897c4ec2.js";
import { i as I, f as y, m as D, e as j, A as x, g as E } from "./index-42161a8d.js";
import "starknet";
import "./connector-4bc69b15.js";
import { ArgentX as R } from "./argentX.js";
import "./trpc-d914d822.js";
import { BraavosMobileBaseConnector as z } from "./braavosMobile.js";
import { KeplrMobileBaseConnector as F } from "./keplrMobile.js";
import { ControllerConnector as Q } from "./controllerConnector.js";
import { Braavos as q } from "./braavos.js";
import { Fordefi as W } from "./fordefi.js";
import { Keplr as k } from "./keplr.js";
import { Xverse as v } from "./xverse.js";
import { MetaMask as A } from "./metamask.js";
import { r as M, s as K } from "./lastConnected-c0cae438.js";
import "./index-40f0fb49.js";
const P = () => {
const t = navigator.userAgent.toLowerCase(), i = /android|webos|iphone|ipad|ipod|blackberry|windows phone/.test(t), c = "ontouchstart" in window || navigator.maxTouchPoints > 0, p = window.innerWidth <= 768;
return i && (c || p);
}, T = () => typeof window < "u" ? /^((?!chrome|android).)*safari/i.test(navigator.userAgent) : !1, X = () => {
const t = (
// | StarknetkitCompoundConnector
[]
);
return t.push(new R()), T() || (t.push(new q()), A.isWalletInjected() && t.push(new A()), W.isWalletInjected() && t.push(new W()), k.isWalletInjected() && t.push(new k()), v.isWalletInjected() && t.push(new v())), t.push(new Q()), P() && (t.push(new z()), t.push(new F())), t;
}, it = (t) => ({
starknetkitConnectModal: async () => await _({
...t,
skipEmit: !0,
resultType: void 0
})
});
let o = null;
const _ = async ({
modalMode: t = "canAsk",
storeVersion: i = E(),
modalTheme: c,
dappName: p,
resultType: g = "wallet",
skipEmit: b = !1,
...u
}) => {
const { connectors: l } = u;
o = null;
const d = !l || l.length === 0 ? X() : l;
b && d?.map((e) => {
I(e) && "connector" in e && "_options" in e.connector && (e.connector._options.shouldEmit = !1);
});
const f = localStorage.getItem("starknetLastConnectedWallet");
if (t === "neverAsk")
try {
const e = y(d, f);
let s = null;
return e && g === "wallet" && (s = await e.connect({
onlyQRCode: !0
})), {
connector: e,
wallet: e?.wallet ?? null,
connectorData: s
};
} catch (e) {
throw M(), new Error(e);
}
const m = await w.getAvailableWallets(u);
if (t === "canAsk" && f && ((await w.getAuthorizedWallets(u)).find((n) => n.id === f) ?? m.length === 1 ? m[0] : void 0)) {
const n = y(d, f);
let r = null;
return g === "wallet" && (r = await n?.connect({
onlyQRCode: !0
}) ?? null), n && (o = n), {
connector: o,
connectorData: r,
wallet: n?.wallet ?? null
};
}
const C = (await w.getDiscoveryWallets(u)).map(
(e) => e.id.toLowerCase() === "argentx" ? {
...e,
name: "Ready Wallet (formerly Argent)"
} : e
), S = D({
availableConnectors: d,
installedWallets: m,
discoveryWallets: C,
storeVersion: i,
customOrder: l ? l?.length > 0 : !1
});
return new Promise((e, s) => {
const n = new $({
target: B(),
props: {
dappName: p,
callback: async (r, L = !1) => {
try {
if (!r)
throw new Error("Connector error");
if (n.$set({ selectedWallet: r }), !r.installed) {
n.$set({ layout: a.download });
return;
}
if (o = j(
r.connector,
L
), g === "wallet") {
o instanceof x ? n.$set({ layout: a.qrCode }) : n.$set({ layout: a.connecting });
const h = await o?.connect({
onlyQRCode: !0
}) ?? null;
o !== null && K(o.id), e({
connector: o,
connectorData: h,
wallet: o?.wallet ?? null
}), n.$set({ layout: a.success }), setTimeout(() => n.$destroy(), 500);
} else
e({
connector: o,
wallet: null,
connectorData: null
}), n.$destroy();
} catch (h) {
[a.connecting, a.qrCode].includes(n.getLayout()) ? n.$set({ layout: a.loginFailure }) : s(h);
}
},
theme: c === "system" ? null : c ?? null,
modalWallets: S,
discoveryWallets: C,
installedWallets: m
}
});
});
}, ct = () => o ? o.wallet : null, ut = async (t = {}) => (M(), o && await o.disconnect(), o = null, w.disconnect(t));
export {
_ as connect,
ut as disconnect,
ct as getSelectedConnectorWallet,
it as useStarknetkitConnectModal
};