@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.
351 lines (345 loc) • 18.3 kB
JavaScript
"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/metaMaskWallet/metaMaskWallet.svg
var require_metaMaskWallet = __commonJS({
"src/wallets/walletConnectors/metaMaskWallet/metaMaskWallet.svg"(exports, module) {
module.exports = 'data:image/svg+xml,<svg width="28" height="28" viewBox="0 0 28 28" fill="none" xmlns="http://www.w3.org/2000/svg">%0A<rect width="28" height="28" fill="white"/>%0A<path d="M24.0891 3.1199L15.3446 9.61456L16.9617 5.7828L24.0891 3.1199Z" fill="%23E2761B" stroke="%23E2761B" stroke-width="0.0878845" stroke-linecap="round" stroke-linejoin="round"/>%0A<path d="M3.90207 3.1199L12.5763 9.67608L11.0383 5.7828L3.90207 3.1199Z" fill="%23E4761B" stroke="%23E4761B" stroke-width="0.0878845" stroke-linecap="round" stroke-linejoin="round"/>%0A<path d="M20.9429 18.1745L18.6139 21.7426L23.597 23.1136L25.0295 18.2536L20.9429 18.1745Z" fill="%23E4761B" stroke="%23E4761B" stroke-width="0.0878845" stroke-linecap="round" stroke-linejoin="round"/>%0A<path d="M2.97929 18.2536L4.40301 23.1136L9.38607 21.7426L7.05713 18.1745L2.97929 18.2536Z" fill="%23E4761B" stroke="%23E4761B" stroke-width="0.0878845" stroke-linecap="round" stroke-linejoin="round"/>%0A<path d="M9.10483 12.1456L7.71626 14.2461L12.6642 14.4658L12.4884 9.14877L9.10483 12.1456Z" fill="%23E4761B" stroke="%23E4761B" stroke-width="0.0878845" stroke-linecap="round" stroke-linejoin="round"/>%0A<path d="M18.8864 12.1456L15.4589 9.08725L15.3446 14.4658L20.2837 14.2461L18.8864 12.1456Z" fill="%23E4761B" stroke="%23E4761B" stroke-width="0.0878845" stroke-linecap="round" stroke-linejoin="round"/>%0A<path d="M9.38606 21.7426L12.3566 20.2925L9.79033 18.2888L9.38606 21.7426Z" fill="%23E4761B" stroke="%23E4761B" stroke-width="0.0878845" stroke-linecap="round" stroke-linejoin="round"/>%0A<path d="M15.6347 20.2925L18.6139 21.7426L18.2009 18.2888L15.6347 20.2925Z" fill="%23E4761B" stroke="%23E4761B" stroke-width="0.0878845" stroke-linecap="round" stroke-linejoin="round"/>%0A<path d="M18.6139 21.7426L15.6347 20.2925L15.8719 22.2348L15.8456 23.0521L18.6139 21.7426Z" fill="%23D7C1B3" stroke="%23D7C1B3" stroke-width="0.0878845" stroke-linecap="round" stroke-linejoin="round"/>%0A<path d="M9.38606 21.7426L12.1544 23.0521L12.1368 22.2348L12.3566 20.2925L9.38606 21.7426Z" fill="%23D7C1B3" stroke="%23D7C1B3" stroke-width="0.0878845" stroke-linecap="round" stroke-linejoin="round"/>%0A<path d="M12.1984 17.0056L9.72002 16.2762L11.4689 15.4765L12.1984 17.0056Z" fill="%23233447" stroke="%23233447" stroke-width="0.0878845" stroke-linecap="round" stroke-linejoin="round"/>%0A<path d="M15.7928 17.0056L16.5223 15.4765L18.28 16.2762L15.7928 17.0056Z" fill="%23233447" stroke="%23233447" stroke-width="0.0878845" stroke-linecap="round" stroke-linejoin="round"/>%0A<path d="M9.38606 21.7426L9.80791 18.1745L7.05712 18.2536L9.38606 21.7426Z" fill="%23CD6116" stroke="%23CD6116" stroke-width="0.0878845" stroke-linecap="round" stroke-linejoin="round"/>%0A<path d="M18.1921 18.1745L18.6139 21.7426L20.9429 18.2536L18.1921 18.1745Z" fill="%23CD6116" stroke="%23CD6116" stroke-width="0.0878845" stroke-linecap="round" stroke-linejoin="round"/>%0A<path d="M20.2837 14.2461L15.3446 14.4658L15.8016 17.0057L16.5311 15.4765L18.2888 16.2762L20.2837 14.2461Z" fill="%23CD6116" stroke="%23CD6116" stroke-width="0.0878845" stroke-linecap="round" stroke-linejoin="round"/>%0A<path d="M9.72002 16.2762L11.4777 15.4765L12.1984 17.0057L12.6642 14.4658L7.71626 14.2461L9.72002 16.2762Z" fill="%23CD6116" stroke="%23CD6116" stroke-width="0.0878845" stroke-linecap="round" stroke-linejoin="round"/>%0A<path d="M7.71626 14.2461L9.79033 18.2888L9.72002 16.2762L7.71626 14.2461Z" fill="%23E4751F" stroke="%23E4751F" stroke-width="0.0878845" stroke-linecap="round" stroke-linejoin="round"/>%0A<path d="M18.2888 16.2762L18.2009 18.2888L20.2837 14.2461L18.2888 16.2762Z" fill="%23E4751F" stroke="%23E4751F" stroke-width="0.0878845" stroke-linecap="round" stroke-linejoin="round"/>%0A<path d="M12.6642 14.4658L12.1984 17.0057L12.7784 20.0025L12.9102 16.0565L12.6642 14.4658Z" fill="%23E4751F" stroke="%23E4751F" stroke-width="0.0878845" stroke-linecap="round" stroke-linejoin="round"/>%0A<path d="M15.3446 14.4658L15.1073 16.0477L15.2128 20.0025L15.8016 17.0057L15.3446 14.4658Z" fill="%23E4751F" stroke="%23E4751F" stroke-width="0.0878845" stroke-linecap="round" stroke-linejoin="round"/>%0A<path d="M15.8016 17.0056L15.2128 20.0025L15.6347 20.2925L18.2009 18.2888L18.2888 16.2762L15.8016 17.0056Z" fill="%23F6851B" stroke="%23F6851B" stroke-width="0.0878845" stroke-linecap="round" stroke-linejoin="round"/>%0A<path d="M9.72002 16.2762L9.79033 18.2888L12.3566 20.2925L12.7784 20.0025L12.1984 17.0056L9.72002 16.2762Z" fill="%23F6851B" stroke="%23F6851B" stroke-width="0.0878845" stroke-linecap="round" stroke-linejoin="round"/>%0A<path d="M15.8456 23.0521L15.8719 22.2348L15.6522 22.0414H12.339L12.1368 22.2348L12.1544 23.0521L9.38606 21.7426L10.3528 22.5336L12.3126 23.8958H15.6786L17.6472 22.5336L18.6139 21.7426L15.8456 23.0521Z" fill="%23C0AD9E" stroke="%23C0AD9E" stroke-width="0.0878845" stroke-linecap="round" stroke-linejoin="round"/>%0A<path d="M15.6347 20.2925L15.2128 20.0025H12.7784L12.3566 20.2925L12.1368 22.2348L12.339 22.0414H15.6522L15.8719 22.2348L15.6347 20.2925Z" fill="%23161616" stroke="%23161616" stroke-width="0.0878845" stroke-linecap="round" stroke-linejoin="round"/>%0A<path d="M24.4583 10.0364L25.2053 6.45072L24.0891 3.1199L15.6347 9.39485L18.8864 12.1456L23.4827 13.4903L24.5022 12.3038L24.0628 11.9874L24.7658 11.3459L24.221 10.924L24.924 10.3879L24.4583 10.0364Z" fill="%23763D16" stroke="%23763D16" stroke-width="0.0878845" stroke-linecap="round" stroke-linejoin="round"/>%0A<path d="M2.79472 6.45072L3.54174 10.0364L3.06717 10.3879L3.77024 10.924L3.23415 11.3459L3.93722 11.9874L3.4978 12.3038L4.50847 13.4903L9.10483 12.1456L12.3566 9.39485L3.90207 3.1199L2.79472 6.45072Z" fill="%23763D16" stroke="%23763D16" stroke-width="0.0878845" stroke-linecap="round" stroke-linejoin="round"/>%0A<path d="M23.4827 13.4903L18.8864 12.1456L20.2837 14.2461L18.2009 18.2888L20.9429 18.2536H25.0295L23.4827 13.4903Z" fill="%23F6851B" stroke="%23F6851B" stroke-width="0.0878845" stroke-linecap="round" stroke-linejoin="round"/>%0A<path d="M9.10484 12.1456L4.50848 13.4903L2.97929 18.2536H7.05713L9.79033 18.2888L7.71626 14.2461L9.10484 12.1456Z" fill="%23F6851B" stroke="%23F6851B" stroke-width="0.0878845" stroke-linecap="round" stroke-linejoin="round"/>%0A<path d="M15.3446 14.4658L15.6347 9.39485L16.9705 5.7828H11.0383L12.3566 9.39485L12.6642 14.4658L12.7696 16.0653L12.7784 20.0025H15.2128L15.2304 16.0653L15.3446 14.4658Z" fill="%23F6851B" stroke="%23F6851B" stroke-width="0.0878845" stroke-linecap="round" stroke-linejoin="round"/>%0A</svg>%0A';
}
});
// src/utils/isMobile.ts
function isAndroid() {
return typeof navigator !== "undefined" && /android/i.test(navigator.userAgent);
}
function isSmallIOS() {
return typeof navigator !== "undefined" && /iPhone|iPod/.test(navigator.userAgent);
}
function isLargeIOS() {
return typeof navigator !== "undefined" && (/iPad/.test(navigator.userAgent) || navigator.platform === "MacIntel" && navigator.maxTouchPoints > 1);
}
function isIOS() {
return isSmallIOS() || isLargeIOS();
}
// 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/metaMaskWallet/metaMaskWallet.ts
function isMetaMask(ethereum) {
if (!ethereum?.isMetaMask)
return false;
if (ethereum.isBraveWallet && !ethereum._events && !ethereum._state)
return false;
if (ethereum.isApexWallet)
return false;
if (ethereum.isAvalanche)
return false;
if (ethereum.isBackpack)
return false;
if (ethereum.isBifrost)
return false;
if (ethereum.isBitKeep)
return false;
if (ethereum.isBitski)
return false;
if (ethereum.isBlockWallet)
return false;
if (ethereum.isCoinbaseWallet)
return false;
if (ethereum.isDawn)
return false;
if (ethereum.isEnkrypt)
return false;
if (ethereum.isExodus)
return false;
if (ethereum.isFrame)
return false;
if (ethereum.isFrontier)
return false;
if (ethereum.isGamestop)
return false;
if (ethereum.isHyperPay)
return false;
if (ethereum.isImToken)
return false;
if (ethereum.isKryptogo)
return false;
if (ethereum.isKuCoinWallet)
return false;
if (ethereum.isMathWallet)
return false;
if (ethereum.isNestWallet)
return false;
if (ethereum.isOkxWallet || ethereum.isOKExWallet)
return false;
if (ethereum.isOneInchIOSWallet || ethereum.isOneInchAndroidWallet)
return false;
if (ethereum.isOpera)
return false;
if (ethereum.isPhantom)
return false;
if (ethereum.isPortal)
return false;
if (ethereum.isRabby)
return false;
if (ethereum.isRainbow)
return false;
if (ethereum.isStatus)
return false;
if (ethereum.isTalisman)
return false;
if (ethereum.isTally)
return false;
if (ethereum.isTokenPocket)
return false;
if (ethereum.isTokenary)
return false;
if (ethereum.isTrust || ethereum.isTrustWallet)
return false;
if (ethereum.isXDEFI)
return false;
if (ethereum.isZeal)
return false;
if (ethereum.isZerion)
return false;
if (ethereum.__seif)
return false;
return true;
}
var metaMaskWallet = ({ projectId, walletConnectParameters }) => {
const isMetaMaskInjected = hasInjectedProvider({ flag: "isMetaMask" });
const shouldUseWalletConnect = !isMetaMaskInjected;
const getUri = (uri) => {
return isAndroid() ? uri : isIOS() ? (
// currently broken in MetaMask v6.5.0 https://github.com/MetaMask/metamask-mobile/issues/6457
`metamask://wc?uri=${encodeURIComponent(uri)}`
) : `https://metamask.app.link/wc?uri=${encodeURIComponent(uri)}`;
};
return {
id: "metaMask",
name: "MetaMask",
rdns: "io.metamask",
iconUrl: async () => (await Promise.resolve().then(() => __toESM(require_metaMaskWallet(), 1))).default,
iconAccent: "#f6851a",
iconBackground: "#fff",
installed: !shouldUseWalletConnect ? isMetaMaskInjected : void 0,
downloadUrls: {
android: "https://play.google.com/store/apps/details?id=io.metamask",
ios: "https://apps.apple.com/us/app/metamask/id1438144202",
mobile: "https://metamask.io/download",
qrCode: "https://metamask.io/download",
chrome: "https://chrome.google.com/webstore/detail/metamask/nkbihfbeogaeaoehlefnkodbefgpgknn",
edge: "https://microsoftedge.microsoft.com/addons/detail/metamask/ejbalbakoplchlghecdalmeeeajnimhm",
firefox: "https://addons.mozilla.org/firefox/addon/ether-metamask",
opera: "https://addons.opera.com/extensions/details/metamask-10",
browserExtension: "https://metamask.io/download"
},
mobile: {
getUri: shouldUseWalletConnect ? getUri : void 0
},
qrCode: shouldUseWalletConnect ? {
getUri,
instructions: {
learnMoreUrl: "https://metamask.io/faqs/",
steps: [
{
description: "wallet_connectors.metamask.qr_code.step1.description",
step: "install",
title: "wallet_connectors.metamask.qr_code.step1.title"
},
{
description: "wallet_connectors.metamask.qr_code.step2.description",
step: "create",
title: "wallet_connectors.metamask.qr_code.step2.title"
},
{
description: "wallet_connectors.metamask.qr_code.step3.description",
step: "refresh",
title: "wallet_connectors.metamask.qr_code.step3.title"
}
]
}
} : void 0,
extension: {
instructions: {
learnMoreUrl: "https://metamask.io/faqs/",
steps: [
{
description: "wallet_connectors.metamask.extension.step1.description",
step: "install",
title: "wallet_connectors.metamask.extension.step1.title"
},
{
description: "wallet_connectors.metamask.extension.step2.description",
step: "create",
title: "wallet_connectors.metamask.extension.step2.title"
},
{
description: "wallet_connectors.metamask.extension.step3.description",
step: "refresh",
title: "wallet_connectors.metamask.extension.step3.title"
}
]
}
},
createConnector: shouldUseWalletConnect ? getWalletConnectConnector({
projectId,
walletConnectParameters
}) : getInjectedConnector({
target: typeof window !== "undefined" ? window.ethereum?.providers?.find(isMetaMask) ?? window.ethereum : void 0
})
};
};
export {
metaMaskWallet
};