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.

251 lines (245 loc) 11.3 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/gateWallet/gateWallet.svg var require_gateWallet = __commonJS({ "src/wallets/walletConnectors/gateWallet/gateWallet.svg"(exports, module) { module.exports = 'data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 28 28"><g clip-path="url(%23a)"><path fill="%23fff" d="M0 0h28v28H0z"/><mask id="b" width="28" height="28" x="0" y="0" maskUnits="userSpaceOnUse" style="mask-type:luminance"><path fill="%23fff" d="M0 0h28v28H0V0Z"/></mask><g mask="url(%23b)"><path fill="%230255EB" d="M0 22.512h28V28H0v-5.488Zm14-7.071a4.238 4.238 0 0 1-2.354-7.76A4.236 4.236 0 0 1 14 6.968V3.501a7.706 7.706 0 0 0-7.556 9.205 7.701 7.701 0 0 0 6.053 6.051 7.705 7.705 0 0 0 9.207-7.554h-3.47A4.231 4.231 0 0 1 14 15.44Z"/><path fill="%2300E697" d="M18.237 6.967H14v4.236h4.237V6.967Z"/><path fill="url(%23c)" d="M27.997 21.874c-4.201-1.007-8.955-1.576-13.999-1.576-5.044 0-9.797.569-13.998 1.576v.63a5.493 5.493 0 0 0 5.494 5.494h17.012A5.495 5.495 0 0 0 28 22.505l-.003-.63Z"/><path fill="%230255EB" d="M27.997 22.508c-4.17-1.052-8.935-1.65-13.999-1.65-5.063 0-9.829.598-13.998 1.65A5.493 5.493 0 0 0 5.494 28h17.012A5.493 5.493 0 0 0 28 22.507h-.003Z"/><path fill="%23fff" d="M10.977 25.786h-.74l-.576-2.563-.588 2.563h-.74l-.651-2.942h.508l.522 2.472.583-2.471h.736l.568 2.462.519-2.462h.517l-.658 2.94Zm3.034-2.23v2.226h-.483v-.299a.98.98 0 0 1-.736.336c-.194.001-.385-.053-.55-.156a1.179 1.179 0 0 1-.404-1.57c.095-.172.233-.316.401-.418.166-.102.356-.155.55-.154a.944.944 0 0 1 .41.09c.124.058.235.14.326.241v-.298l.486.001Zm-.81 1.728a.684.684 0 0 0 .346-.607.703.703 0 0 0-1.316-.359.708.708 0 0 0 .254.966.717.717 0 0 0 .71 0h.005Zm1.277.502v-2.942h.483v2.942h-.483Zm.945 0v-2.942h.484v2.942h-.484Zm2.597-2.111a1.14 1.14 0 0 1 .56 1.17h-1.807c.018.101.058.197.117.282a.666.666 0 0 0 .555.26c.125 0 .248-.029.36-.084.1-.045.19-.11.264-.193l.425.117a.977.977 0 0 1-.425.42c-.192.11-.41.169-.63.17a1.16 1.16 0 0 1-1.151-1.152 1.141 1.141 0 0 1 .575-.994 1.153 1.153 0 0 1 1.151 0l.006.004Zm-.867.355a.71.71 0 0 0-.24.18.621.621 0 0 0-.132.264h1.341a.665.665 0 0 0-.374-.444.69.69 0 0 0-.595 0Zm2.053-1.004h.474v.533h.686v.425h-.686v1.042c0 .059.016.117.047.167.03.05.073.093.124.123a.33.33 0 0 0 .17.046h.366v.424h-.467a.72.72 0 0 1-.718-.72v-1.08h-.42v-.425h.42l.004-.535Z"/></g></g><defs><linearGradient id="c" x1="-18.993" x2="48.217" y1="24.148" y2="24.148" gradientUnits="userSpaceOnUse"><stop offset=".25" stop-color="%23fff"/><stop offset=".5" stop-color="%2300E79D"/><stop offset=".75" stop-color="%23fff"/></linearGradient><clipPath id="a"><path fill="%23fff" d="M0 0h28v28H0z"/></clipPath></defs></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/gateWallet/gateWallet.ts var gateWallet = ({ projectId, walletConnectParameters }) => { const isGateInjected = hasInjectedProvider({ namespace: "gatewallet" }); const shouldUseWalletConnect = !isGateInjected; return { id: "gate", name: "Gate Wallet", rdns: "io.gate.wallet", iconUrl: async () => (await Promise.resolve().then(() => __toESM(require_gateWallet(), 1))).default, iconAccent: "#fff", iconBackground: "#fff", downloadUrls: { android: "https://play.google.com/store/apps/details?id=com.gateio.gateio", ios: "https://apps.apple.com/us/app/gate-io-buy-bitcoin-crypto/id1294998195", mobile: "https://www.gate.io/mobileapp", qrCode: "https://www.gate.io/web3", chrome: "https://chromewebstore.google.com/detail/gate-wallet/cpmkedoipcpimgecpmgpldfpohjplkpp", browserExtension: "https://www.gate.io/web3" }, mobile: { getUri: shouldUseWalletConnect ? (uri) => { return isAndroid() ? uri : `gtweb3wallet://wc?uri=${encodeURIComponent(uri)}`; } : void 0 }, qrCode: shouldUseWalletConnect ? { getUri: (uri) => uri, instructions: { learnMoreUrl: "https://www.gate.io/learn", steps: [ { description: "wallet_connectors.gate.qr_code.step1.description", step: "install", title: "wallet_connectors.gate.qr_code.step1.title" }, { description: "wallet_connectors.gate.qr_code.step2.description", step: "create", title: "wallet_connectors.gate.qr_code.step2.title" }, { description: "wallet_connectors.gate.qr_code.step3.description", step: "scan", title: "wallet_connectors.gate.qr_code.step3.title" } ] } } : void 0, extension: { instructions: { learnMoreUrl: "https://www.gate.io/learn", steps: [ { description: "wallet_connectors.gate.extension.step1.description", step: "install", title: "wallet_connectors.gate.extension.step1.title" }, { description: "wallet_connectors.gate.extension.step2.description", step: "create", title: "wallet_connectors.gate.extension.step2.title" }, { description: "wallet_connectors.gate.extension.step3.description", step: "refresh", title: "wallet_connectors.gate.extension.step3.title" } ] } }, createConnector: shouldUseWalletConnect ? getWalletConnectConnector({ projectId, walletConnectParameters }) : getInjectedConnector({ namespace: "gatewallet" }) }; }; export { gateWallet };