@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 (246 loc) • 10.5 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/bybitWallet/bybitWallet.svg
var require_bybitWallet = __commonJS({
"src/wallets/walletConnectors/bybitWallet/bybitWallet.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="%23404347" d="M0 0h28v28H0z"/><path fill="url(%23b)" d="M2.41 8.53a1.556 1.556 0 0 1 1.171-1.955l14.75-3.133a1.556 1.556 0 0 1 1.722.844l6.625 13.68L8.01 27.845 2.41 8.53Z"/><path fill="%23fff" d="M2.603 9.597a1.556 1.556 0 0 1 1.295-1.975l19.548-2.535a1.556 1.556 0 0 1 1.726 1.24L28 20.612 7.856 27.767 2.603 9.597Z"/><path fill="%23000" d="M0 10.889a3.111 3.111 0 0 1 3.111-3.111h18.667A6.222 6.222 0 0 1 28 14v14H0V10.889Z"/><path fill="%23F7A600" d="M18.524 19.471v-5.829h1.138v5.83h-1.137Z"/><path fill="%23fff" d="M5.55 21.211H3.11v-5.829h2.34c1.137 0 1.8.638 1.8 1.637 0 .647-.426 1.065-.72 1.204.352.164.802.532.802 1.31 0 1.089-.745 1.678-1.784 1.678m-.189-4.814H4.248v1.343H5.36c.483 0 .753-.27.753-.67 0-.403-.27-.673-.753-.673Zm.074 2.367H4.248v1.432h1.186c.515 0 .76-.328.76-.72.001-.394-.244-.712-.76-.712m5.032.056v2.391h-1.13v-2.39l-1.75-3.44h1.235l1.088 2.35 1.072-2.35h1.235l-1.75 3.44Zm4.986 2.391h-2.438v-5.829h2.34c1.137 0 1.8.638 1.8 1.637 0 .647-.426 1.065-.72 1.204.352.164.802.532.802 1.31-.001 1.089-.746 1.678-1.784 1.678Zm-.188-4.814H14.15v1.343h1.113c.482 0 .753-.27.753-.67-.001-.403-.27-.673-.753-.673Zm.073 2.367h-1.186v1.432h1.186c.516 0 .76-.328.76-.72 0-.394-.245-.712-.76-.712Zm8.03-2.367v4.814H22.23v-4.814h-1.521v-1.015h4.18v1.015h-1.522Z"/></g><defs><linearGradient id="b" x1="2.333" x2="26.93" y1="8.144" y2="6.912" gradientUnits="userSpaceOnUse"><stop stop-color="%23FFD748"/><stop offset="1" stop-color="%23F7A600"/></linearGradient><clipPath id="a"><path fill="%23fff" d="M0 0h28v28H0z"/></clipPath></defs></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/bybitWallet/bybitWallet.ts
var bybitWallet = ({ projectId, walletConnectParameters }) => {
const isBybitInjected = hasInjectedProvider({
namespace: "bybitWallet"
});
const shouldUseWalletConnect = !isBybitInjected;
const getUri = (uri) => {
return `bybitapp://open/route?targetUrl=by://web3/walletconnect/wc?uri=${encodeURIComponent(uri)}`;
};
return {
id: "bybit",
name: "Bybit Wallet",
rdns: "com.bybit",
iconUrl: async () => (await Promise.resolve().then(() => __toESM(require_bybitWallet(), 1))).default,
installed: !shouldUseWalletConnect ? isBybitInjected : void 0,
iconBackground: "#000000",
downloadUrls: {
chrome: "https://chromewebstore.google.com/detail/bybit-wallet/pdliaogehgdbhbnmkklieghmmjkpigpa",
browserExtension: "https://www.bybit.com/en/web3",
android: "https://play.google.com/store/apps/details?id=com.bybit.app",
ios: "https://apps.apple.com/us/app/bybit-buy-trade-crypto/id1488296980",
mobile: "https://www.bybit.com/en/web3",
qrCode: "https://www.bybit.com/en/web3"
},
mobile: {
getUri: shouldUseWalletConnect ? getUri : void 0
},
qrCode: shouldUseWalletConnect ? {
getUri: (uri) => uri,
instructions: {
learnMoreUrl: "https://www.bybit.com/en/web3",
steps: [
{
description: "wallet_connectors.bybit.qr_code.step1.description",
step: "install",
title: "wallet_connectors.bybit.qr_code.step1.title"
},
{
description: "wallet_connectors.bybit.qr_code.step2.description",
step: "create",
title: "wallet_connectors.bybit.qr_code.step2.title"
},
{
description: "wallet_connectors.bybit.qr_code.step3.description",
step: "scan",
title: "wallet_connectors.bybit.qr_code.step3.title"
}
]
}
} : void 0,
extension: {
instructions: {
learnMoreUrl: "https://www.bybit.com/en/web3",
steps: [
{
description: "wallet_connectors.bybit.extension.step1.description",
step: "install",
title: "wallet_connectors.bybit.extension.step1.title"
},
{
description: "wallet_connectors.bybit.extension.step2.description",
step: "create",
title: "wallet_connectors.bybit.extension.step2.title"
},
{
description: "wallet_connectors.bybit.extension.step3.description",
step: "refresh",
title: "wallet_connectors.bybit.extension.step3.title"
}
]
}
},
createConnector: shouldUseWalletConnect ? getWalletConnectConnector({
projectId,
walletConnectParameters
}) : getInjectedConnector({
namespace: "bybitWallet"
})
};
};
export {
bybitWallet
};