@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) • 9.83 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/coin98Wallet/coin98Wallet.svg
var require_coin98Wallet = __commonJS({
"src/wallets/walletConnectors/coin98Wallet/coin98Wallet.svg"(exports, module) {
module.exports = 'data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="28" height="28" fill="none"><g clip-path="url(%23a)"><path fill="url(%23b)" d="M0 0h28v28H0z"/><path fill="%23252525" d="M9.428 7a4.372 4.372 0 0 0-3.088 7.461A4.371 4.371 0 1 0 9.428 7Zm0 6.951a2.58 2.58 0 1 1 2.58-2.579 2.587 2.587 0 0 1-2.58 2.58Zm12.888-3.212a3.678 3.678 0 0 1-.46 1.789 5.022 5.022 0 0 0-1.57-.865 1.946 1.946 0 1 0-3.66-.924c-.001.323.08.641.235.924a5.026 5.026 0 0 0-1.57.865A3.735 3.735 0 0 1 18.575 7a3.745 3.745 0 0 1 3.74 3.74Zm-3.741 1.513a4.372 4.372 0 0 0-3.098 7.46 4.371 4.371 0 0 0 7.466-3.084 4.38 4.38 0 0 0-4.368-4.376Zm0 6.947a2.576 2.576 0 1 1 .006-5.152 2.576 2.576 0 0 1-.006 5.152Zm-5.406-1.945a3.741 3.741 0 0 1-7.484 0H7.48a1.945 1.945 0 0 0 3.893 0h1.796Z"/></g><defs><linearGradient id="b" x1="26.572" x2="1.815" y1="1.428" y2="26.185" gradientUnits="userSpaceOnUse"><stop stop-color="%23F1D961"/><stop offset="1" stop-color="%23CDA146"/></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/coin98Wallet/coin98Wallet.ts
var coin98Wallet = ({ projectId, walletConnectParameters }) => {
const isCoin98WalletInjected = hasInjectedProvider({
namespace: "coin98.provider",
flag: "isCoin98"
});
const shouldUseWalletConnect = !isCoin98WalletInjected;
return {
id: "coin98",
name: "Coin98 Wallet",
iconUrl: async () => (await Promise.resolve().then(() => __toESM(require_coin98Wallet(), 1))).default,
installed: isCoin98WalletInjected,
iconAccent: "#CDA349",
iconBackground: "#fff",
rdns: "coin98.com",
downloadUrls: {
android: "https://play.google.com/store/apps/details?id=coin98.crypto.finance.media",
ios: "https://apps.apple.com/vn/app/coin98-super-app/id1561969966",
mobile: "https://coin98.com/wallet",
qrCode: "https://coin98.com/wallet",
chrome: "https://chrome.google.com/webstore/detail/coin98-wallet/aeachknmefphepccionboohckonoeemg",
browserExtension: "https://coin98.com/wallet"
},
mobile: {
getUri: shouldUseWalletConnect ? (uri) => uri : void 0
},
qrCode: shouldUseWalletConnect ? {
getUri: (uri) => uri,
instructions: {
learnMoreUrl: "https://coin98.com/wallet",
steps: [
{
description: "wallet_connectors.coin98.qr_code.step1.description",
step: "install",
title: "wallet_connectors.coin98.qr_code.step1.title"
},
{
description: "wallet_connectors.coin98.qr_code.step2.description",
step: "create",
title: "wallet_connectors.coin98.qr_code.step2.title"
},
{
description: "wallet_connectors.coin98.qr_code.step3.description",
step: "scan",
title: "wallet_connectors.coin98.qr_code.step3.title"
}
]
}
} : void 0,
extension: {
instructions: {
learnMoreUrl: "https://coin98.com/wallet",
steps: [
{
description: "wallet_connectors.coin98.extension.step1.description",
step: "install",
title: "wallet_connectors.coin98.extension.step1.title"
},
{
description: "wallet_connectors.coin98.extension.step2.description",
step: "create",
title: "wallet_connectors.coin98.extension.step2.title"
},
{
description: "wallet_connectors.coin98.extension.step3.description",
step: "refresh",
title: "wallet_connectors.coin98.extension.step3.title"
}
]
}
},
createConnector: shouldUseWalletConnect ? getWalletConnectConnector({
projectId,
walletConnectParameters
}) : getInjectedConnector({
namespace: "coin98Wallet",
flag: "isCoin98"
})
};
};
export {
coin98Wallet
};