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.

250 lines (245 loc) 12.1 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/coreWallet/coreWallet.svg var require_coreWallet = __commonJS({ "src/wallets/walletConnectors/coreWallet/coreWallet.svg"(exports, module) { module.exports = 'data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="28" height="28" fill="none"><path fill="%231A1A1C" d="M0 0h28v28H0z"/><path fill="%231A1A1C" d="m14.22 8.796 1.798 1.01.75-.728 2.507-.282 1.473 1.64.246 2.362-1.719 1.519-3.257 1.337-3.985-1.599-1.01-2.046.749-2.383 2.447-.83Z"/><path fill="%23fff" fill-rule="evenodd" d="M10.96 20.016c-1.6 0-3.1-.341-4.4-.939l5.285-4.824a3.26 3.26 0 0 1-1.196-2.526 3.26 3.26 0 0 1 1.236-2.558V8.46h2.03c.816 0 1.563.3 2.135.795a3.253 3.253 0 0 1 2.135-.795h2.03v.708a3.266 3.266 0 0 1-.632 5.51c-.395 1.166-1.137 2.214-2.131 3.067v1.507h-2.499a10.614 10.614 0 0 1-3.993.763Zm2.955-5.777c.595 0 1.14-.207 1.57-.552l.56 1.26.562-1.266a2.512 2.512 0 1 0-.557-3.278 2.512 2.512 0 1 0-2.135 3.836Zm0-.754a1.758 1.758 0 1 0 0-3.516 1.758 1.758 0 0 0 0 3.516Zm0-.753a1.005 1.005 0 1 0 0-2.01 1.005 1.005 0 0 0 0 2.01Zm6.029-1.005a1.758 1.758 0 1 1-3.517 0 1.758 1.758 0 0 1 3.517 0Zm-.754 0a1.005 1.005 0 1 1-2.01 0 1.005 1.005 0 0 1 2.01 0Z" clip-rule="evenodd"/><path fill="%231A1A1C" fill-rule="evenodd" d="M14.954 19.253h2.498v-1.507c.994-.853 1.736-1.901 2.131-3.067a3.266 3.266 0 0 0 .632-5.51V8.46h-2.03c-.816 0-1.562.3-2.135.795a3.253 3.253 0 0 0-2.135-.795h-2.03v.708a3.26 3.26 0 0 0-1.236 2.558 3.254 3.254 0 0 0 1.196 2.526L6.56 19.077c.168.077.34.15.513.219 1.176.462 2.494.72 3.887.72 1.435 0 2.791-.274 3.993-.763Zm.767-9.272a2.512 2.512 0 1 0-.235 3.706l.56 1.26.561-1.266a2.502 2.502 0 0 0 1.578.558 2.512 2.512 0 1 0-2.135-3.836 2.526 2.526 0 0 0-.329-.422Zm.324 3.715.292-.658a2.261 2.261 0 0 1-.287-.55c-.072.2-.17.389-.293.56l.288.648Zm-2.13-1.472a.497.497 0 1 0 0-.994.497.497 0 0 0 0 .994Zm4.27 0a.497.497 0 1 0 0-.994.497.497 0 0 0 0 .994Zm-2.512-.497a1.758 1.758 0 1 1-3.516 0 1.758 1.758 0 0 1 3.516 0Zm-.753 0a1.005 1.005 0 1 1-2.01 0 1.005 1.005 0 0 1 2.01 0Zm3.265 1.758a1.758 1.758 0 1 0 0-3.517 1.758 1.758 0 0 0 0 3.517Zm0-.753a1.005 1.005 0 1 0 0-2.01 1.005 1.005 0 0 0 0 2.01Z" clip-rule="evenodd"/><path fill="%23fff" fill-rule="evenodd" d="M10.96 20.016c-1.6 0-3.1-.341-4.4-.939l5.285-4.824a3.26 3.26 0 0 1-1.196-2.526 3.26 3.26 0 0 1 1.236-2.558V8.46h2.03c.816 0 1.563.3 2.135.795a3.253 3.253 0 0 1 2.135-.795h2.03v.708a3.266 3.266 0 0 1-.632 5.51c-.395 1.166-1.137 2.214-2.131 3.067v1.507h-2.499a10.614 10.614 0 0 1-3.993.763Zm2.955-5.777c.595 0 1.14-.207 1.57-.552l.56 1.26.562-1.266a2.512 2.512 0 1 0-.557-3.278 2.512 2.512 0 1 0-2.135 3.836Zm0-.754a1.758 1.758 0 1 0 0-3.516 1.758 1.758 0 0 0 0 3.516Zm0-.753a1.005 1.005 0 1 0 0-2.01 1.005 1.005 0 0 0 0 2.01Zm6.029-1.005a1.758 1.758 0 1 1-3.517 0 1.758 1.758 0 0 1 3.517 0Zm-.754 0a1.005 1.005 0 1 1-2.01 0 1.005 1.005 0 0 1 2.01 0Z" clip-rule="evenodd"/><path fill="%231A1A1C" d="M16.413 11.706a2.515 2.515 0 1 1-5.031 0 2.515 2.515 0 0 1 5.03 0Z"/><path fill="%231A1A1C" d="M20.689 11.706a2.515 2.515 0 1 1-5.03 0 2.515 2.515 0 0 1 5.03 0Z"/><path fill="%23fff" d="M15.658 11.706a1.76 1.76 0 1 1-3.521 0 1.76 1.76 0 0 1 3.521 0Zm4.276 0a1.76 1.76 0 1 1-3.521 0 1.76 1.76 0 0 1 3.521 0Z"/><path fill="%231A1A1C" d="M14.903 11.706a1.006 1.006 0 1 1-2.012 0 1.006 1.006 0 0 1 2.012 0Zm4.277 0a1.006 1.006 0 1 1-2.013 0 1.006 1.006 0 0 1 2.013 0Zm-3.15 3.224-.87-1.962h1.742l-.872 1.962Z"/></svg>'; } }); // 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/coreWallet/coreWallet.ts var coreWallet = ({ projectId, walletConnectParameters }) => { const isCoreInjected = hasInjectedProvider({ namespace: "avalanche", flag: "isAvalanche" }); const shouldUseWalletConnect = !isCoreInjected; return { id: "core", name: "Core", rdns: "app.core.extension", iconUrl: async () => (await Promise.resolve().then(() => __toESM(require_coreWallet(), 1))).default, iconBackground: "#1A1A1C", installed: !shouldUseWalletConnect ? isCoreInjected : void 0, downloadUrls: { android: "https://play.google.com/store/apps/details?id=com.avaxwallet", ios: "https://apps.apple.com/us/app/core-wallet/id6443685999", mobile: "https://core.app/?downloadCoreMobile=1", qrCode: "https://core.app/?downloadCoreMobile=1", chrome: "https://chrome.google.com/webstore/detail/core-crypto-wallet-nft-ex/agoakfejjabomempkjlepdflaleeobhb", browserExtension: "https://extension.core.app/" }, mobile: { getUri: shouldUseWalletConnect ? (uri) => uri : void 0 }, qrCode: shouldUseWalletConnect ? { getUri: (uri) => uri, instructions: { learnMoreUrl: "https://support.avax.network/en/articles/6115608-core-mobile-how-to-add-the-core-mobile-to-my-phone", steps: [ { description: "wallet_connectors.core.qr_code.step1.description", step: "install", title: "wallet_connectors.core.qr_code.step1.title" }, { description: "wallet_connectors.core.qr_code.step2.description", step: "create", title: "wallet_connectors.core.qr_code.step2.title" }, { description: "wallet_connectors.core.qr_code.step3.description", step: "scan", title: "wallet_connectors.core.qr_code.step3.title" } ] } } : void 0, extension: { instructions: { learnMoreUrl: "https://extension.core.app/", steps: [ { description: "wallet_connectors.core.extension.step1.description", step: "install", title: "wallet_connectors.core.extension.step1.title" }, { description: "wallet_connectors.core.extension.step2.description", step: "create", title: "wallet_connectors.core.extension.step2.title" }, { description: "wallet_connectors.core.extension.step3.description", step: "refresh", title: "wallet_connectors.core.extension.step3.title" } ] } }, createConnector: shouldUseWalletConnect ? getWalletConnectConnector({ projectId, walletConnectParameters }) : getInjectedConnector({ namespace: "avalanche", flag: "isAvalanche" }) }; }; export { coreWallet };