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.

217 lines (211 loc) 8.85 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/iopayWallet/iopayWallet.svg var require_iopayWallet = __commonJS({ "src/wallets/walletConnectors/iopayWallet/iopayWallet.svg"(exports, module) { module.exports = 'data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 40 40"><path fill="%23363647" d="M22.302 40q-5.082 0-9.087-2.108c-2.67-1.406-4.783-3.404-6.297-5.993-1.515-2.59-2.272-5.623-2.272-9.137s.757-6.548 2.272-9.137 3.627-4.587 6.297-5.993 5.739-2.109 9.167-2.109 6.457.703 9.127 2.109q3.945 2.109 6.218 5.993c1.514 2.589 2.271 5.623 2.271 9.137s-.757 6.547-2.271 9.137c-1.515 2.589-3.627 4.587-6.258 5.993C28.759 39.297 25.73 40 22.302 40"/><defs><linearGradient id="a" x1=".913" x2=".224" y1="1" y2=".166"><stop offset="0" stop-color="%2344FFB2"/><stop offset=".194" stop-color="rgba(71, 252, 181, 1)"/><stop offset="1" stop-color="%23855EFF"/></linearGradient></defs><path fill="url(%23a)" stroke="%23363647" stroke-miterlimit="8.333" stroke-width=".67" d="M36.829 20.191c0 9.679-8.158 17.548-18.248 17.548S.333 29.87.333 20.191 8.491 2.643 18.581 2.643s18.248 7.869 18.248 17.548Z"/><path fill="%23292936" d="M19.515 25.21c3.109 0 5.58-2.386 5.58-5.303s-2.511-5.304-5.58-5.304-5.58 2.387-5.58 5.304 2.471 5.303 5.58 5.303"/><path fill="%23FFF" stroke="%23343439" stroke-miterlimit="8.333" stroke-width=".4" d="m32.262 11.372 5.261-5c1.149-1.092.888-3.008-.438-4.268C35.76.845 33.763.605 32.624 1.687l-5.261 5.001c-1.148 1.092-.887 3.007.439 4.268 1.324 1.259 3.322 1.499 4.46.416Z"/></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 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/iopayWallet/iopayWallet.ts function isIoPayMobile() { return typeof navigator !== "undefined" && typeof navigator.userAgent !== "undefined" && (navigator?.userAgent.includes("IoPayAndroid") || navigator?.userAgent.includes("IoPayiOs")); } var iopayWallet = ({ projectId, walletConnectParameters }) => ({ id: "iopay", name: "ioPay Wallet", iconUrl: async () => (await Promise.resolve().then(() => __toESM(require_iopayWallet(), 1))).default, iconBackground: "#fff", downloadUrls: { android: "https://play.google.com/store/apps/details?id=io.iotex.iopay.gp&pli=1", ios: "https://apps.apple.com/us/app/iopay-multichain-crypto-wallet/id1478086371", qrCode: "https://iopay.me/", browserExtension: "https://iopay.me/" }, mobile: { getUri: (uri) => { return isAndroid() ? uri : `iopay://wc?uri=${encodeURIComponent(uri)}`; } }, qrCode: { getUri: (uri) => uri, instructions: { learnMoreUrl: "https://iopay.me/", steps: [ { description: "wallet_connectors.iopay.qr_code.step1.description", step: "install", title: "wallet_connectors.iopay.qr_code.step1.title" }, { description: "wallet_connectors.iopay.qr_code.step2.description", step: "create", title: "wallet_connectors.iopay.qr_code.step2.title" }, { description: "wallet_connectors.iopay.qr_code.step3.description", step: "scan", title: "wallet_connectors.iopay.qr_code.step3.title" } ] } }, createConnector: isIoPayMobile() ? getInjectedConnector({}) : getWalletConnectConnector({ projectId, walletConnectParameters }) }); export { iopayWallet };