@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.
228 lines (222 loc) • 10.1 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/bifrostWallet/bifrostWallet.svg
var require_bifrostWallet = __commonJS({
"src/wallets/walletConnectors/bifrostWallet/bifrostWallet.svg"(exports, module) {
module.exports = 'data:image/svg+xml,<svg width="512" height="512" viewBox="0 0 512 512" fill="none" xmlns="http://www.w3.org/2000/svg">%0A <g clip-path="url(%23clip0_1618_12583)">%0A <path d="M512 0H0V512H512V0Z" fill="url(%23paint0_radial_1618_12583)"/>%0A <path d="M125.918 87.0209C122.011 86.7026 119 90.0541 119 94.2288V152C119 161.353 123.137 171.555 132.852 174.757L360.798 251.479C368.09 253.932 377.708 260.783 368.074 270.214C376.547 265.493 392 261.759 392 245.406V203.184C392 183.182 382.617 175.555 367.685 170.392L127.644 87.3937C127.055 87.1828 126.477 87.0668 125.917 87.0206L125.918 87.0209ZM259.62 222.633L200.122 243.2C185.191 248.363 175.807 256.005 175.807 276.008V318.229C175.807 335.984 190.136 340.465 199.734 343.037C190.1 333.606 199.722 326.757 207.01 324.303L360.59 272.615C365.458 270.976 367.409 267.04 366.893 263.568C366.3 259.578 361.583 256.955 355.932 255.052C323.828 244.246 259.62 222.633 259.62 222.633ZM308.063 295.938C308.063 295.938 245.514 316.992 214.239 327.519C209.876 328.986 204.109 331.887 203.387 336.275C202.914 339.152 204.278 344.585 209.584 346.371C245.535 358.469 317.438 382.664 317.438 382.664C324.73 385.117 333.089 392.885 323.455 402.315C333.053 399.742 348.656 394.344 348.656 376.59V334.353C348.656 314.351 339.257 306.724 324.325 301.561L308.063 295.938ZM224.064 356.629V412.241C224.064 418.982 232.378 425.553 239.736 423.674L315.329 404.366C320.947 402.933 321.728 397.625 321.294 395.151C320.523 390.765 315.616 387.437 311.312 385.989L224.064 356.629Z" fill="white"/>%0A </g>%0A <defs>%0A <radialGradient id="paint0_radial_1618_12583" cx="0" cy="0" r="1" gradientUnits="userSpaceOnUse" gradientTransform="translate(180.544 188.072) rotate(43.8972) scale(366.433 366.622)">%0A <stop stop-color="%23435AE1" stop-opacity="0.996078"/>%0A <stop offset="1" stop-color="%233247C7"/>%0A </radialGradient>%0A <clipPath id="clip0_1618_12583">%0A <rect width="512" height="512" fill="white"/>%0A </clipPath>%0A </defs>%0A </svg>%0A';
}
});
// 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/bifrostWallet/bifrostWallet.ts
var bifrostWallet = ({ projectId, walletConnectParameters }) => {
const isBifrostInjected = hasInjectedProvider({ flag: "isBifrost" });
const shouldUseWalletConnect = !isBifrostInjected;
const getUri = (uri) => {
return isAndroid() ? uri : `https://app.bifrostwallet.com/wc?uri=${encodeURIComponent(uri)}`;
};
return {
id: "bifrostWallet",
name: "Bifrost Wallet",
iconUrl: async () => (await Promise.resolve().then(() => __toESM(require_bifrostWallet(), 1))).default,
iconBackground: "#fff",
installed: !shouldUseWalletConnect ? isBifrostInjected : void 0,
downloadUrls: {
android: "https://play.google.com/store/apps/details?id=com.bifrostwallet.app",
ios: "https://apps.apple.com/us/app/bifrost-wallet/id1577198351",
qrCode: "https://bifrostwallet.com/#download-app"
},
mobile: {
getUri: shouldUseWalletConnect ? getUri : void 0
},
qrCode: shouldUseWalletConnect ? {
getUri: (uri) => uri,
instructions: {
learnMoreUrl: "https://support.bifrostwallet.com/en/articles/6886814-how-to-use-walletconnect",
steps: [
{
description: "wallet_connectors.bifrost.qr_code.step1.description",
step: "install",
title: "wallet_connectors.bifrost.qr_code.step1.title"
},
{
description: "wallet_connectors.bifrost.qr_code.step2.description",
step: "create",
title: "wallet_connectors.bifrost.qr_code.step2.title"
},
{
description: "wallet_connectors.bifrost.qr_code.step3.description",
step: "scan",
title: "wallet_connectors.bifrost.qr_code.step3.title"
}
]
}
} : void 0,
createConnector: shouldUseWalletConnect ? getWalletConnectConnector({
projectId,
walletConnectParameters
}) : getInjectedConnector({
flag: "isBifrost"
})
};
};
export {
bifrostWallet
};