@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.
236 lines (230 loc) • 12.4 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/rainbowWallet/rainbowWallet.svg
var require_rainbowWallet = __commonJS({
"src/wallets/walletConnectors/rainbowWallet/rainbowWallet.svg"(exports, module) {
module.exports = 'data:image/svg+xml,<svg width="120" height="120" viewBox="0 0 120 120" fill="none" xmlns="http://www.w3.org/2000/svg">%0A<rect width="120" height="120" fill="url(%23paint0_linear_62_329)"/>%0A<path d="M20 38H26C56.9279 38 82 63.0721 82 94V100H94C97.3137 100 100 97.3137 100 94C100 53.1309 66.8691 20 26 20C22.6863 20 20 22.6863 20 26V38Z" fill="url(%23paint1_radial_62_329)"/>%0A<path d="M84 94H100C100 97.3137 97.3137 100 94 100H84V94Z" fill="url(%23paint2_linear_62_329)"/>%0A<path d="M26 20L26 36H20L20 26C20 22.6863 22.6863 20 26 20Z" fill="url(%23paint3_linear_62_329)"/>%0A<path d="M20 36H26C58.0325 36 84 61.9675 84 94V100H66V94C66 71.9086 48.0914 54 26 54H20V36Z" fill="url(%23paint4_radial_62_329)"/>%0A<path d="M68 94H84V100H68V94Z" fill="url(%23paint5_linear_62_329)"/>%0A<path d="M20 52L20 36L26 36L26 52H20Z" fill="url(%23paint6_linear_62_329)"/>%0A<path d="M20 62C20 65.3137 22.6863 68 26 68C40.3594 68 52 79.6406 52 94C52 97.3137 54.6863 100 58 100H68V94C68 70.804 49.196 52 26 52H20V62Z" fill="url(%23paint7_radial_62_329)"/>%0A<path d="M52 94H68V100H58C54.6863 100 52 97.3137 52 94Z" fill="url(%23paint8_radial_62_329)"/>%0A<path d="M26 68C22.6863 68 20 65.3137 20 62L20 52L26 52L26 68Z" fill="url(%23paint9_radial_62_329)"/>%0A<defs>%0A<linearGradient id="paint0_linear_62_329" x1="60" y1="0" x2="60" y2="120" gradientUnits="userSpaceOnUse">%0A<stop stop-color="%23174299"/>%0A<stop offset="1" stop-color="%23001E59"/>%0A</linearGradient>%0A<radialGradient id="paint1_radial_62_329" cx="0" cy="0" r="1" gradientUnits="userSpaceOnUse" gradientTransform="translate(26 94) rotate(-90) scale(74)">%0A<stop offset="0.770277" stop-color="%23FF4000"/>%0A<stop offset="1" stop-color="%238754C9"/>%0A</radialGradient>%0A<linearGradient id="paint2_linear_62_329" x1="83" y1="97" x2="100" y2="97" gradientUnits="userSpaceOnUse">%0A<stop stop-color="%23FF4000"/>%0A<stop offset="1" stop-color="%238754C9"/>%0A</linearGradient>%0A<linearGradient id="paint3_linear_62_329" x1="23" y1="20" x2="23" y2="37" gradientUnits="userSpaceOnUse">%0A<stop stop-color="%238754C9"/>%0A<stop offset="1" stop-color="%23FF4000"/>%0A</linearGradient>%0A<radialGradient id="paint4_radial_62_329" cx="0" cy="0" r="1" gradientUnits="userSpaceOnUse" gradientTransform="translate(26 94) rotate(-90) scale(58)">%0A<stop offset="0.723929" stop-color="%23FFF700"/>%0A<stop offset="1" stop-color="%23FF9901"/>%0A</radialGradient>%0A<linearGradient id="paint5_linear_62_329" x1="68" y1="97" x2="84" y2="97" gradientUnits="userSpaceOnUse">%0A<stop stop-color="%23FFF700"/>%0A<stop offset="1" stop-color="%23FF9901"/>%0A</linearGradient>%0A<linearGradient id="paint6_linear_62_329" x1="23" y1="52" x2="23" y2="36" gradientUnits="userSpaceOnUse">%0A<stop stop-color="%23FFF700"/>%0A<stop offset="1" stop-color="%23FF9901"/>%0A</linearGradient>%0A<radialGradient id="paint7_radial_62_329" cx="0" cy="0" r="1" gradientUnits="userSpaceOnUse" gradientTransform="translate(26 94) rotate(-90) scale(42)">%0A<stop offset="0.59513" stop-color="%2300AAFF"/>%0A<stop offset="1" stop-color="%2301DA40"/>%0A</radialGradient>%0A<radialGradient id="paint8_radial_62_329" cx="0" cy="0" r="1" gradientUnits="userSpaceOnUse" gradientTransform="translate(51 97) scale(17 45.3333)">%0A<stop stop-color="%2300AAFF"/>%0A<stop offset="1" stop-color="%2301DA40"/>%0A</radialGradient>%0A<radialGradient id="paint9_radial_62_329" cx="0" cy="0" r="1" gradientUnits="userSpaceOnUse" gradientTransform="translate(23 69) rotate(-90) scale(17 322.37)">%0A<stop stop-color="%2300AAFF"/>%0A<stop offset="1" stop-color="%2301DA40"/>%0A</radialGradient>%0A</defs>%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/rainbowWallet/rainbowWallet.ts
var rainbowWallet = ({ projectId, walletConnectParameters }) => {
const isRainbowInjected = hasInjectedProvider({ flag: "isRainbow" });
const shouldUseWalletConnect = !isRainbowInjected;
const getUri = (uri) => {
return isAndroid() ? uri : isIOS() ? `rainbow://wc?uri=${encodeURIComponent(uri)}&connector=rainbowkit` : `https://rnbwapp.com/wc?uri=${encodeURIComponent(uri)}&connector=rainbowkit`;
};
return {
id: "rainbow",
name: "Rainbow",
rdns: "me.rainbow",
iconUrl: async () => (await Promise.resolve().then(() => __toESM(require_rainbowWallet(), 1))).default,
iconBackground: "#0c2f78",
installed: !shouldUseWalletConnect ? isRainbowInjected : void 0,
downloadUrls: {
android: "https://play.google.com/store/apps/details?id=me.rainbow&referrer=utm_source%3Drainbowkit&utm_source=rainbowkit",
ios: "https://apps.apple.com/app/apple-store/id1457119021?pt=119997837&ct=rainbowkit&mt=8",
mobile: "https://rainbow.download?utm_source=rainbowkit",
qrCode: "https://rainbow.download?utm_source=rainbowkit&utm_medium=qrcode",
browserExtension: "https://rainbow.me/extension?utm_source=rainbowkit"
},
mobile: { getUri: shouldUseWalletConnect ? getUri : void 0 },
qrCode: shouldUseWalletConnect ? {
getUri,
instructions: {
learnMoreUrl: "https://learn.rainbow.me/connect-to-a-website-or-app?utm_source=rainbowkit&utm_medium=connector&utm_campaign=learnmore",
steps: [
{
description: "wallet_connectors.rainbow.qr_code.step1.description",
step: "install",
title: "wallet_connectors.rainbow.qr_code.step1.title"
},
{
description: "wallet_connectors.rainbow.qr_code.step2.description",
step: "create",
title: "wallet_connectors.rainbow.qr_code.step2.title"
},
{
description: "wallet_connectors.rainbow.qr_code.step3.description",
step: "scan",
title: "wallet_connectors.rainbow.qr_code.step3.title"
}
]
}
} : void 0,
createConnector: shouldUseWalletConnect ? getWalletConnectConnector({
projectId,
walletConnectParameters
}) : getInjectedConnector({ flag: "isRainbow" })
};
};
export {
rainbowWallet
};