UNPKG

@kryptogo/kryptogokit-sdk-react

Version:

KryptogoKit offers a comprehensive web3 wallet solution with seamless KryptoGO Auth integration and multi-wallet connection support. Designed for users. Built for developers.

253 lines (247 loc) 9.84 kB
"use client"; var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __commonJS = (cb, mod) => function __require() { return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports; }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); // src/wallets/walletConnectors/okxWallet/okxWallet.svg var require_okxWallet = __commonJS({ "src/wallets/walletConnectors/okxWallet/okxWallet.svg"(exports, module) { module.exports = 'data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 28 28"><path fill="%23000" d="M0 0h28v28H0z"/><path fill="%23fff" fill-rule="evenodd" d="M10.819 5.556H5.93a.376.376 0 0 0-.375.375v4.888c0 .207.168.375.375.375h4.888a.376.376 0 0 0 .375-.376V5.932a.376.376 0 0 0-.376-.375Zm5.64 5.638h-4.886a.376.376 0 0 0-.376.376v4.887c0 .208.168.376.376.376h4.887a.376.376 0 0 0 .376-.375V11.57a.376.376 0 0 0-.376-.377Zm.75-5.638h4.887c.208 0 .376.168.376.375v4.888a.376.376 0 0 1-.376.375H17.21a.376.376 0 0 1-.376-.376V5.933c0-.208.169-.376.376-.376Zm-6.39 11.277H5.93a.376.376 0 0 0-.375.376v4.887c0 .208.168.376.375.376h4.888a.376.376 0 0 0 .375-.376V17.21a.376.376 0 0 0-.376-.376Zm6.39 0h4.887c.208 0 .376.169.376.376v4.887a.376.376 0 0 1-.376.376H17.21a.376.376 0 0 1-.376-.376V17.21c0-.207.169-.376.376-.376Z" clip-rule="evenodd"/></svg>'; } }); // src/utils/isMobile.ts function isAndroid() { return typeof navigator !== "undefined" && /android/i.test(navigator.userAgent); } // src/wallets/getInjectedConnector.ts import { createConnector } from "wagmi"; import { injected } from "wagmi/connectors"; function getExplicitInjectedProvider(flag) { const _window = typeof window !== "undefined" ? window : void 0; if (typeof _window === "undefined" || typeof _window.ethereum === "undefined") return; const providers = _window.ethereum.providers; return providers ? providers.find((provider) => provider[flag]) : _window.ethereum[flag] ? _window.ethereum : void 0; } function getWindowProviderNamespace(namespace) { const providerSearch = (provider, namespace2) => { const [property, ...path] = namespace2.split("."); const _provider = provider[property]; if (_provider) { if (path.length === 0) return _provider; return providerSearch(_provider, path.join(".")); } }; if (typeof window !== "undefined") return providerSearch(window, namespace); } function hasInjectedProvider({ flag, namespace }) { if (namespace && typeof getWindowProviderNamespace(namespace) !== "undefined") return true; if (flag && typeof getExplicitInjectedProvider(flag) !== "undefined") return true; return false; } function getInjectedProvider({ flag, namespace }) { const _window = typeof window !== "undefined" ? window : void 0; if (typeof _window === "undefined") return; if (namespace) { const windowProvider = getWindowProviderNamespace(namespace); if (windowProvider) return windowProvider; } const providers = _window.ethereum?.providers; if (flag) { const provider = getExplicitInjectedProvider(flag); if (provider) return provider; } if (typeof providers !== "undefined" && providers.length > 0) return providers[0]; return _window.ethereum; } function createInjectedConnector(provider) { return (walletDetails) => { const injectedConfig = provider ? { shimDisconnect: false, target: () => ({ id: walletDetails.rkDetails.id, name: walletDetails.rkDetails.name, provider }) } : { shimDisconnect: false }; return createConnector((config) => ({ // Spread the injectedConfig object, which may be empty or contain the target function ...injected(injectedConfig)(config), ...walletDetails })); }; } function getInjectedConnector({ flag, namespace, target }) { const provider = target ? target : getInjectedProvider({ flag, namespace }); return createInjectedConnector(provider); } // src/wallets/getWalletConnectConnector.ts import { createConnector as createConnector2 } from "wagmi"; import { walletConnect } from "wagmi/connectors"; var walletConnectInstances = /* @__PURE__ */ new Map(); var getOrCreateWalletConnectInstance = ({ projectId, walletConnectParameters, rkDetailsShowQrModal }) => { let config = { ...walletConnectParameters ? walletConnectParameters : {}, projectId, showQrModal: false // Required. Otherwise WalletConnect modal (Web3Modal) will popup during time of connection for a wallet }; if (rkDetailsShowQrModal) { config = { ...config, showQrModal: true }; } const serializedConfig = JSON.stringify(config); const sharedWalletConnector = walletConnectInstances.get(serializedConfig); if (sharedWalletConnector) { return sharedWalletConnector; } const newWalletConnectInstance = walletConnect(config); walletConnectInstances.set(serializedConfig, newWalletConnectInstance); return newWalletConnectInstance; }; function createWalletConnectConnector({ projectId, walletDetails, walletConnectParameters }) { return createConnector2((config) => ({ ...getOrCreateWalletConnectInstance({ projectId, walletConnectParameters, // Used in `connectorsForWallets` to add another // walletConnect wallet into kryptogokit with modal popup option rkDetailsShowQrModal: walletDetails.rkDetails.showQrModal })(config), ...walletDetails })); } function getWalletConnectConnector({ projectId, walletConnectParameters }) { const exampleProjectId = "04b90987df7d8e1e08a7d7ce0df821a6"; if (!projectId || projectId === "" || projectId === "YOUR_PROJECT_ID") { projectId = exampleProjectId; } return (walletDetails) => createWalletConnectConnector({ projectId, walletDetails, walletConnectParameters }); } // src/wallets/walletConnectors/okxWallet/okxWallet.ts var okxWallet = ({ projectId, walletConnectParameters } = { projectId: "" }) => { const isOKXInjected = hasInjectedProvider({ namespace: "okxwallet" }); const shouldUseWalletConnect = !isOKXInjected; return { id: "okx", name: "OKX Wallet", rdns: "com.okex.wallet", iconUrl: async () => (await Promise.resolve().then(() => __toESM(require_okxWallet(), 1))).default, iconAccent: "#000", iconBackground: "#000", downloadUrls: { android: "https://play.google.com/store/apps/details?id=com.okinc.okex.gp", ios: "https://itunes.apple.com/app/id1327268470?mt=8", mobile: "https://okx.com/download", qrCode: "https://okx.com/download", chrome: "https://chrome.google.com/webstore/detail/okx-wallet/mcohilncbfahbmgdjkbpemcciiolgcge", edge: "https://microsoftedge.microsoft.com/addons/detail/okx-wallet/pbpjkcldjiffchgbbndmhojiacbgflha", firefox: "https://addons.mozilla.org/firefox/addon/okexwallet/", browserExtension: "https://okx.com/download" }, mobile: { getUri: shouldUseWalletConnect ? (uri) => { return isAndroid() ? uri : `okex://main/wc?uri=${encodeURIComponent(uri)}`; } : void 0 }, qrCode: shouldUseWalletConnect ? { getUri: (uri) => uri, instructions: { learnMoreUrl: "https://okx.com/web3/", steps: [ { description: "wallet_connectors.okx.qr_code.step1.description", step: "install", title: "wallet_connectors.okx.qr_code.step1.title" }, { description: "wallet_connectors.okx.qr_code.step2.description", step: "create", title: "wallet_connectors.okx.qr_code.step2.title" }, { description: "wallet_connectors.okx.qr_code.step3.description", step: "scan", title: "wallet_connectors.okx.qr_code.step3.title" } ] } } : void 0, extension: { instructions: { learnMoreUrl: "https://okx.com/web3/", steps: [ { description: "wallet_connectors.okx.extension.step1.description", step: "install", title: "wallet_connectors.okx.extension.step1.title" }, { description: "wallet_connectors.okx.extension.step2.description", step: "create", title: "wallet_connectors.okx.extension.step2.title" }, { description: "wallet_connectors.okx.extension.step3.description", step: "refresh", title: "wallet_connectors.okx.extension.step3.title" } ] } }, createConnector: shouldUseWalletConnect ? getWalletConnectConnector({ projectId, walletConnectParameters }) : getInjectedConnector({ namespace: "okxwallet" }) }; }; export { okxWallet };