@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.
258 lines (253 loc) • 9.97 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/subWallet/subWallet.svg
var require_subWallet = __commonJS({
"src/wallets/walletConnectors/subWallet/subWallet.svg"(exports, module) {
module.exports = 'data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="28" height="28"><defs><linearGradient id="a" x1="352" x2="352" y1="0" y2="704" gradientTransform="scale(.03977)" gradientUnits="userSpaceOnUse"><stop offset="0" style="stop-color:%23004bff;stop-opacity:1"/><stop offset="1" style="stop-color:%234ceaac;stop-opacity:1"/></linearGradient><clipPath id="b"><path d="M7.637 4.453h12.726v19.094H7.637Zm0 0"/></clipPath></defs><path d="M0 0h28v28H0z" style="fill:url(%23a);stroke:none"/><g clip-path="url(%23b)"><path d="M20.363 11.36V8.71L9.753 4.454 7.638 5.531l.011 8.246 7.934 3.196-4.238 1.804v-1.394l-1.946-.793-1.75.828v5.05l2.11 1.079 10.605-4.785v-3.395l-9.547-3.82v-2.32l7.575 3.027Zm0 0" style="stroke:none;fill-rule:nonzero;fill:%23fff;fill-opacity:1"/></g></svg>%0A';
}
});
// 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/subWallet/subWallet.ts
var subWallet = ({ projectId, walletConnectParameters }) => {
const isSubWalletInjected = hasInjectedProvider({ namespace: "SubWallet" });
const shouldUseWalletConnect = !isSubWalletInjected;
const getUriMobile = (uri) => {
return `subwallet://wc?uri=${encodeURIComponent(uri)}`;
};
const getUriQR = (uri) => {
return uri;
};
const mobileConnector = {
getUri: shouldUseWalletConnect ? getUriMobile : void 0
};
let qrConnector = void 0;
if (shouldUseWalletConnect) {
qrConnector = {
getUri: getUriQR,
instructions: {
learnMoreUrl: "https://www.subwallet.app/",
steps: [
{
description: "wallet_connectors.subwallet.qr_code.step1.description",
step: "install",
title: "wallet_connectors.subwallet.qr_code.step1.title"
},
{
description: "wallet_connectors.subwallet.qr_code.step2.description",
step: "create",
title: "wallet_connectors.subwallet.qr_code.step2.title"
},
{
description: "wallet_connectors.subwallet.qr_code.step3.description",
step: "scan",
title: "wallet_connectors.subwallet.qr_code.step3.title"
}
]
}
};
}
const extensionConnector = {
instructions: {
learnMoreUrl: "https://www.subwallet.app/",
steps: [
{
description: "wallet_connectors.subwallet.extension.step1.description",
step: "install",
title: "wallet_connectors.subwallet.extension.step1.title"
},
{
description: "wallet_connectors.subwallet.extension.step2.description",
step: "create",
title: "wallet_connectors.subwallet.extension.step2.title"
},
{
description: "wallet_connectors.subwallet.extension.step3.description",
step: "refresh",
title: "wallet_connectors.subwallet.extension.step3.title"
}
]
}
};
return {
id: "subwallet",
name: "SubWallet",
rdns: "app.subwallet",
iconUrl: async () => (await Promise.resolve().then(() => __toESM(require_subWallet(), 1))).default,
iconBackground: "#fff",
installed: isSubWalletInjected || void 0,
downloadUrls: {
browserExtension: "https://www.subwallet.app/download",
chrome: "https://chrome.google.com/webstore/detail/subwallet-polkadot-wallet/onhogfjeacnfoofkfgppdlbmlmnplgbn",
firefox: "https://addons.mozilla.org/en-US/firefox/addon/subwallet/",
edge: "https://chrome.google.com/webstore/detail/subwallet-polkadot-wallet/onhogfjeacnfoofkfgppdlbmlmnplgbn",
mobile: "https://www.subwallet.app/download",
android: "https://play.google.com/store/apps/details?id=app.subwallet.mobile",
ios: "https://apps.apple.com/us/app/subwallet-polkadot-wallet/id1633050285",
qrCode: "https://www.subwallet.app/download"
},
mobile: mobileConnector,
qrCode: qrConnector,
extension: extensionConnector,
createConnector: shouldUseWalletConnect ? getWalletConnectConnector({
projectId,
walletConnectParameters
}) : getInjectedConnector({ namespace: "SubWallet" })
};
};
export {
subWallet
};