coinley-test 0.0.59 → 0.0.60
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.esm.js +175 -275
- package/dist/index.esm.js.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/dist/style.css +1 -1
- package/dist/vanilla/coinley-vanilla.umd.js +3 -3
- package/dist/vanilla/coinley-vanilla.umd.js.map +1 -1
- package/dist/vanilla/style.css +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -1302,7 +1302,7 @@ let SimplePaymentAPI$1 = class SimplePaymentAPI {
|
|
|
1302
1302
|
});
|
|
1303
1303
|
}
|
|
1304
1304
|
};
|
|
1305
|
-
|
|
1305
|
+
class SimpleMetaMaskWallet {
|
|
1306
1306
|
constructor() {
|
|
1307
1307
|
this.account = null;
|
|
1308
1308
|
this.chainId = null;
|
|
@@ -1440,7 +1440,7 @@ let SimpleMetaMaskWallet$1 = class SimpleMetaMaskWallet {
|
|
|
1440
1440
|
isConnected() {
|
|
1441
1441
|
return !!this.account;
|
|
1442
1442
|
}
|
|
1443
|
-
}
|
|
1443
|
+
}
|
|
1444
1444
|
const SimpleCoinleyPayment = ({
|
|
1445
1445
|
apiKey,
|
|
1446
1446
|
apiSecret,
|
|
@@ -1462,7 +1462,7 @@ const SimpleCoinleyPayment = ({
|
|
|
1462
1462
|
const [paymentData, setPaymentData] = useState(null);
|
|
1463
1463
|
const [loading, setLoading] = useState(false);
|
|
1464
1464
|
const [error, setError] = useState("");
|
|
1465
|
-
const [wallet, setWallet] = useState(new SimpleMetaMaskWallet
|
|
1465
|
+
const [wallet, setWallet] = useState(new SimpleMetaMaskWallet());
|
|
1466
1466
|
const [walletConnected, setWalletConnected] = useState(false);
|
|
1467
1467
|
const [processing, setProcessing] = useState(false);
|
|
1468
1468
|
const api = useRef(new SimplePaymentAPI$1(apiUrl, apiKey, apiSecret));
|
|
@@ -1481,7 +1481,7 @@ const SimpleCoinleyPayment = ({
|
|
|
1481
1481
|
setError("");
|
|
1482
1482
|
setWalletConnected(false);
|
|
1483
1483
|
setProcessing(false);
|
|
1484
|
-
setWallet(new SimpleMetaMaskWallet
|
|
1484
|
+
setWallet(new SimpleMetaMaskWallet());
|
|
1485
1485
|
};
|
|
1486
1486
|
const loadData = async () => {
|
|
1487
1487
|
var _a2, _b2;
|
|
@@ -1914,260 +1914,180 @@ class SimplePaymentAPI2 {
|
|
|
1914
1914
|
});
|
|
1915
1915
|
}
|
|
1916
1916
|
}
|
|
1917
|
-
class
|
|
1917
|
+
class UniversalWalletManager {
|
|
1918
1918
|
constructor() {
|
|
1919
|
-
this.
|
|
1920
|
-
this.
|
|
1921
|
-
this.walletType = "metamask";
|
|
1919
|
+
this.connectedWallet = null;
|
|
1920
|
+
this.walletType = null;
|
|
1922
1921
|
}
|
|
1923
|
-
|
|
1922
|
+
// Detect all available wallets
|
|
1923
|
+
getAvailableWallets() {
|
|
1924
|
+
const wallets = [];
|
|
1924
1925
|
if (!window.ethereum) {
|
|
1925
|
-
|
|
1926
|
+
return wallets;
|
|
1926
1927
|
}
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
const notRabby = provider.isRabby !== true;
|
|
1936
|
-
const hasMetaMaskProps = provider._metamask || ((_a = provider.constructor) == null ? void 0 : _a.name) === "MetaMaskInpageProvider";
|
|
1937
|
-
console.log("🔍 Provider check:", { isMetaMask, notRabby, hasMetaMaskProps });
|
|
1938
|
-
return isMetaMask && notRabby || hasMetaMaskProps;
|
|
1939
|
-
});
|
|
1940
|
-
if (metamaskProvider) {
|
|
1941
|
-
console.log("🦊 Found MetaMask in providers array!");
|
|
1942
|
-
}
|
|
1943
|
-
}
|
|
1944
|
-
if (!metamaskProvider) {
|
|
1945
|
-
console.log("🔍 Checking main ethereum provider...");
|
|
1946
|
-
if (window.ethereum.isMetaMask === true && window.ethereum.isRabby !== true) {
|
|
1947
|
-
metamaskProvider = window.ethereum;
|
|
1948
|
-
console.log("🦊 Using main ethereum provider as MetaMask!");
|
|
1949
|
-
} else if (window.ethereum._metamask) {
|
|
1950
|
-
metamaskProvider = window.ethereum;
|
|
1951
|
-
console.log("🦊 Using main ethereum provider (has _metamask property)!");
|
|
1952
|
-
}
|
|
1953
|
-
}
|
|
1954
|
-
if (!metamaskProvider && window.ethereum.providers) {
|
|
1955
|
-
console.log("🔍 Forcing MetaMask selection...");
|
|
1956
|
-
metamaskProvider = window.ethereum.providers.find(
|
|
1957
|
-
(provider) => provider.isMetaMask || provider._metamask
|
|
1958
|
-
);
|
|
1959
|
-
if (metamaskProvider) {
|
|
1960
|
-
console.log("🦊 Found potential MetaMask provider!");
|
|
1961
|
-
}
|
|
1962
|
-
}
|
|
1963
|
-
if (!metamaskProvider && (window.ethereum.isMetaMask || window.ethereum._metamask)) {
|
|
1964
|
-
console.log("🔍 Last resort - using main ethereum provider...");
|
|
1965
|
-
metamaskProvider = window.ethereum;
|
|
1966
|
-
}
|
|
1967
|
-
if (!metamaskProvider) {
|
|
1968
|
-
console.log("🔍 No MetaMask provider found, trying direct connection...");
|
|
1969
|
-
metamaskProvider = window.ethereum;
|
|
1970
|
-
}
|
|
1971
|
-
console.log("🦊 Attempting MetaMask connection with provider:", metamaskProvider);
|
|
1972
|
-
const accounts = await metamaskProvider.request({
|
|
1973
|
-
method: "eth_requestAccounts"
|
|
1928
|
+
if (this.isMetaMaskAvailable()) {
|
|
1929
|
+
wallets.push({
|
|
1930
|
+
type: "metamask",
|
|
1931
|
+
name: "MetaMask",
|
|
1932
|
+
icon: "🦊",
|
|
1933
|
+
description: "Connect using MetaMask wallet",
|
|
1934
|
+
color: "orange",
|
|
1935
|
+
isInstalled: true
|
|
1974
1936
|
});
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1937
|
+
}
|
|
1938
|
+
if (this.isRabbyAvailable()) {
|
|
1939
|
+
wallets.push({
|
|
1940
|
+
type: "rabby",
|
|
1941
|
+
name: "Rabby",
|
|
1942
|
+
icon: "🐰",
|
|
1943
|
+
description: "Connect using Rabby wallet",
|
|
1944
|
+
color: "blue",
|
|
1945
|
+
isInstalled: true
|
|
1980
1946
|
});
|
|
1981
|
-
this.account = accounts[0];
|
|
1982
|
-
this.chainId = chainId;
|
|
1983
|
-
this.provider = metamaskProvider;
|
|
1984
|
-
console.log("✅ MetaMask connected successfully:");
|
|
1985
|
-
console.log(" Account:", this.account);
|
|
1986
|
-
console.log(" Chain ID:", this.chainId);
|
|
1987
|
-
return { account: this.account, chainId: this.chainId };
|
|
1988
|
-
} catch (error) {
|
|
1989
|
-
console.error("❌ MetaMask connection failed:", error);
|
|
1990
|
-
if (error.code === 4001) {
|
|
1991
|
-
throw new Error("Connection rejected. Please approve the connection in MetaMask.");
|
|
1992
|
-
} else if (error.message.includes("User rejected")) {
|
|
1993
|
-
throw new Error("Connection cancelled. Please try again and approve the connection.");
|
|
1994
|
-
} else if (error.message.includes("Already processing")) {
|
|
1995
|
-
throw new Error("MetaMask is busy. Please wait a moment and try again.");
|
|
1996
|
-
} else {
|
|
1997
|
-
throw new Error(`MetaMask connection failed: ${error.message}`);
|
|
1998
|
-
}
|
|
1999
1947
|
}
|
|
1948
|
+
console.log("🔍 Available wallets detected:", wallets.map((w) => w.name));
|
|
1949
|
+
return wallets;
|
|
2000
1950
|
}
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
1951
|
+
// Improved MetaMask detection
|
|
1952
|
+
isMetaMaskAvailable() {
|
|
1953
|
+
if (!window.ethereum) return false;
|
|
1954
|
+
if (window.ethereum.isMetaMask && !window.ethereum.isRabby && !window.ethereum.providers) {
|
|
1955
|
+
return true;
|
|
2004
1956
|
}
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
...txParams,
|
|
2009
|
-
from: this.account
|
|
2010
|
-
};
|
|
2011
|
-
try {
|
|
2012
|
-
const gasEstimate = await this.provider.request({
|
|
2013
|
-
method: "eth_estimateGas",
|
|
2014
|
-
params: [fullTxParams]
|
|
2015
|
-
});
|
|
2016
|
-
const gasLimit = Math.floor(parseInt(gasEstimate, 16) * 1.2);
|
|
2017
|
-
fullTxParams.gas = `0x${gasLimit.toString(16)}`;
|
|
2018
|
-
console.log("⛽ MetaMask Gas estimate:", parseInt(gasEstimate, 16));
|
|
2019
|
-
console.log("⛽ MetaMask Gas limit (with buffer):", gasLimit);
|
|
2020
|
-
} catch (gasError) {
|
|
2021
|
-
console.warn("MetaMask gas estimation failed:", gasError);
|
|
2022
|
-
fullTxParams.gas = "0x15F90";
|
|
2023
|
-
}
|
|
2024
|
-
console.log("📤 MetaMask Final transaction params:", fullTxParams);
|
|
2025
|
-
const txHash = await this.provider.request({
|
|
2026
|
-
method: "eth_sendTransaction",
|
|
2027
|
-
params: [fullTxParams]
|
|
1957
|
+
if (window.ethereum.providers && Array.isArray(window.ethereum.providers)) {
|
|
1958
|
+
return window.ethereum.providers.some((provider) => {
|
|
1959
|
+
return provider.isMetaMask === true && provider.isRabby !== true || provider._metamask && !provider.isRabby;
|
|
2028
1960
|
});
|
|
2029
|
-
console.log("✅ MetaMask Transaction sent successfully:", txHash);
|
|
2030
|
-
return txHash;
|
|
2031
|
-
} catch (error) {
|
|
2032
|
-
console.error("MetaMask Transaction failed:", error);
|
|
2033
|
-
if (error.code === 4001) {
|
|
2034
|
-
throw new Error("Transaction cancelled by user");
|
|
2035
|
-
} else if (error.message.includes("insufficient funds")) {
|
|
2036
|
-
throw new Error("Insufficient funds in wallet");
|
|
2037
|
-
} else if (error.message.includes("gas")) {
|
|
2038
|
-
throw new Error("Gas estimation failed. You may not have enough ETH for gas fees.");
|
|
2039
|
-
} else {
|
|
2040
|
-
throw new Error(error.message || "Transaction failed");
|
|
2041
|
-
}
|
|
2042
1961
|
}
|
|
1962
|
+
if (window.ethereum._metamask && !window.ethereum.isRabby) {
|
|
1963
|
+
return true;
|
|
1964
|
+
}
|
|
1965
|
+
return false;
|
|
2043
1966
|
}
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
1967
|
+
// Improved Rabby detection
|
|
1968
|
+
isRabbyAvailable() {
|
|
1969
|
+
if (!window.ethereum) return false;
|
|
1970
|
+
if (window.ethereum.isRabby === true) {
|
|
1971
|
+
return true;
|
|
1972
|
+
}
|
|
1973
|
+
if (window.ethereum.providers && Array.isArray(window.ethereum.providers)) {
|
|
1974
|
+
return window.ethereum.providers.some((provider) => provider.isRabby === true);
|
|
1975
|
+
}
|
|
1976
|
+
if (window.rabby) {
|
|
1977
|
+
return true;
|
|
1978
|
+
}
|
|
1979
|
+
return false;
|
|
2054
1980
|
}
|
|
2055
|
-
|
|
1981
|
+
// Get the correct provider for a specific wallet
|
|
1982
|
+
getProviderForWallet(walletType) {
|
|
2056
1983
|
if (!window.ethereum) {
|
|
2057
|
-
throw new Error("No Ethereum wallet found
|
|
1984
|
+
throw new Error("No Ethereum wallet found");
|
|
2058
1985
|
}
|
|
2059
|
-
let
|
|
2060
|
-
|
|
2061
|
-
console.log("🐰 Starting Rabby connection process...");
|
|
1986
|
+
let targetProvider = null;
|
|
1987
|
+
if (walletType === "metamask") {
|
|
2062
1988
|
if (window.ethereum.providers && Array.isArray(window.ethereum.providers)) {
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
var _a;
|
|
2066
|
-
const isRabby = provider.isRabby === true;
|
|
2067
|
-
const hasRabbyProps = ((_a = provider.constructor) == null ? void 0 : _a.name) === "RabbyWalletProvider";
|
|
2068
|
-
console.log("🔍 Provider check for Rabby:", { isRabby, hasRabbyProps });
|
|
2069
|
-
return isRabby || hasRabbyProps;
|
|
1989
|
+
targetProvider = window.ethereum.providers.find((provider) => {
|
|
1990
|
+
return provider.isMetaMask === true && provider.isRabby !== true || provider._metamask && !provider.isRabby;
|
|
2070
1991
|
});
|
|
2071
|
-
if (rabbyProvider) {
|
|
2072
|
-
console.log("🐰 Found Rabby in providers array!");
|
|
2073
|
-
}
|
|
2074
1992
|
}
|
|
2075
|
-
if (!
|
|
2076
|
-
|
|
2077
|
-
if (window.ethereum.isRabby === true) {
|
|
2078
|
-
rabbyProvider = window.ethereum;
|
|
2079
|
-
console.log("🐰 Using main ethereum provider as Rabby!");
|
|
2080
|
-
}
|
|
1993
|
+
if (!targetProvider && window.ethereum.isMetaMask && !window.ethereum.isRabby) {
|
|
1994
|
+
targetProvider = window.ethereum;
|
|
2081
1995
|
}
|
|
2082
|
-
if (!
|
|
2083
|
-
|
|
2084
|
-
if (window.rabby.ethereum) {
|
|
2085
|
-
rabbyProvider = window.rabby.ethereum;
|
|
2086
|
-
console.log("🐰 Using window.rabby.ethereum!");
|
|
2087
|
-
} else {
|
|
2088
|
-
rabbyProvider = window.rabby;
|
|
2089
|
-
console.log("🐰 Using window.rabby directly!");
|
|
2090
|
-
}
|
|
1996
|
+
if (!targetProvider && window.ethereum._metamask && !window.ethereum.isRabby) {
|
|
1997
|
+
targetProvider = window.ethereum;
|
|
2091
1998
|
}
|
|
2092
|
-
if (!
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
1999
|
+
if (!targetProvider) {
|
|
2000
|
+
throw new Error("MetaMask not found. Please install MetaMask extension.");
|
|
2001
|
+
}
|
|
2002
|
+
} else if (walletType === "rabby") {
|
|
2003
|
+
if (window.ethereum.providers && Array.isArray(window.ethereum.providers)) {
|
|
2004
|
+
targetProvider = window.ethereum.providers.find((provider) => provider.isRabby === true);
|
|
2005
|
+
}
|
|
2006
|
+
if (!targetProvider && window.ethereum.isRabby === true) {
|
|
2007
|
+
targetProvider = window.ethereum;
|
|
2100
2008
|
}
|
|
2101
|
-
if (!
|
|
2102
|
-
|
|
2103
|
-
rabbyProvider = window.ethereum;
|
|
2009
|
+
if (!targetProvider && window.rabby) {
|
|
2010
|
+
targetProvider = window.rabby.ethereum || window.rabby;
|
|
2104
2011
|
}
|
|
2105
|
-
if (!
|
|
2106
|
-
|
|
2107
|
-
rabbyProvider = window.ethereum;
|
|
2012
|
+
if (!targetProvider) {
|
|
2013
|
+
throw new Error("Rabby wallet not found. Please install Rabby extension.");
|
|
2108
2014
|
}
|
|
2109
|
-
|
|
2110
|
-
|
|
2015
|
+
}
|
|
2016
|
+
return targetProvider;
|
|
2017
|
+
}
|
|
2018
|
+
// Connect to a specific wallet
|
|
2019
|
+
async connect(walletType) {
|
|
2020
|
+
try {
|
|
2021
|
+
console.log(`🔗 Attempting to connect to ${walletType}...`);
|
|
2022
|
+
const provider = this.getProviderForWallet(walletType);
|
|
2023
|
+
console.log(`✅ ${walletType} provider found:`, {
|
|
2024
|
+
isMetaMask: provider.isMetaMask,
|
|
2025
|
+
isRabby: provider.isRabby,
|
|
2026
|
+
hasMetaMask: !!provider._metamask
|
|
2027
|
+
});
|
|
2028
|
+
const accounts = await provider.request({
|
|
2111
2029
|
method: "eth_requestAccounts"
|
|
2112
2030
|
});
|
|
2113
2031
|
if (!accounts || accounts.length === 0) {
|
|
2114
|
-
throw new Error(
|
|
2032
|
+
throw new Error(`No accounts found. Please unlock ${walletType} and try again.`);
|
|
2115
2033
|
}
|
|
2116
|
-
const chainId = await
|
|
2034
|
+
const chainId = await provider.request({
|
|
2117
2035
|
method: "eth_chainId"
|
|
2118
2036
|
});
|
|
2119
|
-
this.
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2037
|
+
this.connectedWallet = {
|
|
2038
|
+
account: accounts[0],
|
|
2039
|
+
chainId,
|
|
2040
|
+
provider,
|
|
2041
|
+
walletType
|
|
2042
|
+
};
|
|
2043
|
+
this.walletType = walletType;
|
|
2044
|
+
console.log(`✅ ${walletType} connected successfully:`, {
|
|
2045
|
+
account: accounts[0],
|
|
2046
|
+
chainId
|
|
2047
|
+
});
|
|
2048
|
+
return this.connectedWallet;
|
|
2126
2049
|
} catch (error) {
|
|
2127
|
-
console.error(
|
|
2050
|
+
console.error(`❌ ${walletType} connection failed:`, error);
|
|
2128
2051
|
if (error.code === 4001) {
|
|
2129
|
-
throw new Error(
|
|
2052
|
+
throw new Error(`Connection rejected. Please approve the connection in ${walletType}.`);
|
|
2130
2053
|
} else if (error.message.includes("User rejected")) {
|
|
2131
|
-
throw new Error(
|
|
2132
|
-
} else if (error.message.includes("Already processing")) {
|
|
2133
|
-
throw new Error("Rabby is busy. Please wait a moment and try again.");
|
|
2054
|
+
throw new Error(`Connection cancelled. Please try again and approve the connection.`);
|
|
2134
2055
|
} else {
|
|
2135
|
-
throw new Error(
|
|
2056
|
+
throw new Error(`${walletType} connection failed: ${error.message}`);
|
|
2136
2057
|
}
|
|
2137
2058
|
}
|
|
2138
2059
|
}
|
|
2060
|
+
// Send transaction using connected wallet
|
|
2139
2061
|
async sendTransaction(txParams) {
|
|
2140
|
-
if (!this.
|
|
2141
|
-
throw new Error("
|
|
2062
|
+
if (!this.connectedWallet) {
|
|
2063
|
+
throw new Error("No wallet connected");
|
|
2142
2064
|
}
|
|
2143
2065
|
try {
|
|
2144
|
-
console.log(
|
|
2066
|
+
console.log(`📤 Sending transaction via ${this.walletType}:`, txParams);
|
|
2145
2067
|
const fullTxParams = {
|
|
2146
2068
|
...txParams,
|
|
2147
|
-
from: this.account
|
|
2069
|
+
from: this.connectedWallet.account
|
|
2148
2070
|
};
|
|
2149
2071
|
try {
|
|
2150
|
-
const gasEstimate = await this.provider.request({
|
|
2072
|
+
const gasEstimate = await this.connectedWallet.provider.request({
|
|
2151
2073
|
method: "eth_estimateGas",
|
|
2152
2074
|
params: [fullTxParams]
|
|
2153
2075
|
});
|
|
2154
2076
|
const gasLimit = Math.floor(parseInt(gasEstimate, 16) * 1.2);
|
|
2155
2077
|
fullTxParams.gas = `0x${gasLimit.toString(16)}`;
|
|
2156
|
-
console.log(
|
|
2157
|
-
console.log("⛽ Rabby Gas limit (with buffer):", gasLimit);
|
|
2078
|
+
console.log(`⛽ Gas estimate: ${parseInt(gasEstimate, 16)}, limit: ${gasLimit}`);
|
|
2158
2079
|
} catch (gasError) {
|
|
2159
|
-
console.warn("
|
|
2080
|
+
console.warn("Gas estimation failed:", gasError);
|
|
2160
2081
|
fullTxParams.gas = "0x15F90";
|
|
2161
2082
|
}
|
|
2162
|
-
|
|
2163
|
-
const txHash = await this.provider.request({
|
|
2083
|
+
const txHash = await this.connectedWallet.provider.request({
|
|
2164
2084
|
method: "eth_sendTransaction",
|
|
2165
2085
|
params: [fullTxParams]
|
|
2166
2086
|
});
|
|
2167
|
-
console.log(
|
|
2087
|
+
console.log(`✅ Transaction sent successfully via ${this.walletType}:`, txHash);
|
|
2168
2088
|
return txHash;
|
|
2169
2089
|
} catch (error) {
|
|
2170
|
-
console.error(
|
|
2090
|
+
console.error(`❌ Transaction failed via ${this.walletType}:`, error);
|
|
2171
2091
|
if (error.code === 4001) {
|
|
2172
2092
|
throw new Error("Transaction cancelled by user");
|
|
2173
2093
|
} else if (error.message.includes("insufficient funds")) {
|
|
@@ -2179,8 +2099,18 @@ class SimpleRabbyWallet {
|
|
|
2179
2099
|
}
|
|
2180
2100
|
}
|
|
2181
2101
|
}
|
|
2102
|
+
// Check if wallet is connected
|
|
2182
2103
|
isConnected() {
|
|
2183
|
-
return !!this.
|
|
2104
|
+
return !!this.connectedWallet;
|
|
2105
|
+
}
|
|
2106
|
+
// Get connected wallet info
|
|
2107
|
+
getConnectedWallet() {
|
|
2108
|
+
return this.connectedWallet;
|
|
2109
|
+
}
|
|
2110
|
+
// Disconnect wallet
|
|
2111
|
+
disconnect() {
|
|
2112
|
+
this.connectedWallet = null;
|
|
2113
|
+
this.walletType = null;
|
|
2184
2114
|
}
|
|
2185
2115
|
}
|
|
2186
2116
|
const CMC_LOGO_BASE_URL = "https://s2.coinmarketcap.com/static/img/coins/64x64";
|
|
@@ -2523,46 +2453,15 @@ const WalletSelector = ({
|
|
|
2523
2453
|
connectedWallet,
|
|
2524
2454
|
loading
|
|
2525
2455
|
}) => {
|
|
2456
|
+
var _a, _b;
|
|
2526
2457
|
const [selectedWalletType, setSelectedWalletType] = useState(null);
|
|
2527
|
-
const
|
|
2528
|
-
var _a, _b, _c, _d, _e;
|
|
2529
|
-
switch (walletType) {
|
|
2530
|
-
case "metamask":
|
|
2531
|
-
if ((_a = window.ethereum) == null ? void 0 : _a.providers) {
|
|
2532
|
-
return window.ethereum.providers.some((provider) => provider.isMetaMask && !provider.isRabby);
|
|
2533
|
-
}
|
|
2534
|
-
return ((_b = window.ethereum) == null ? void 0 : _b.isMetaMask) && !((_c = window.ethereum) == null ? void 0 : _c.isRabby);
|
|
2535
|
-
case "rabby":
|
|
2536
|
-
if ((_d = window.ethereum) == null ? void 0 : _d.providers) {
|
|
2537
|
-
return window.ethereum.providers.some((provider) => provider.isRabby);
|
|
2538
|
-
}
|
|
2539
|
-
return (_e = window.ethereum) == null ? void 0 : _e.isRabby;
|
|
2540
|
-
default:
|
|
2541
|
-
return false;
|
|
2542
|
-
}
|
|
2543
|
-
};
|
|
2458
|
+
const walletManager = useRef(new UniversalWalletManager());
|
|
2544
2459
|
const getAvailableWallets = () => {
|
|
2545
2460
|
if (!selectedNetwork) return [];
|
|
2546
|
-
const wallets = [];
|
|
2547
2461
|
if (["ethereum", "bsc", "polygon", "arbitrum", "optimism", "avalanche", "solana"].includes(selectedNetwork.shortName)) {
|
|
2548
|
-
|
|
2549
|
-
type: "metamask",
|
|
2550
|
-
name: "MetaMask",
|
|
2551
|
-
icon: "🦊",
|
|
2552
|
-
description: "Connect using MetaMask wallet",
|
|
2553
|
-
isInstalled: isWalletInstalled("metamask"),
|
|
2554
|
-
color: "orange"
|
|
2555
|
-
});
|
|
2556
|
-
wallets.push({
|
|
2557
|
-
type: "rabby",
|
|
2558
|
-
name: "Rabby",
|
|
2559
|
-
icon: "🐰",
|
|
2560
|
-
description: "Connect using Rabby wallet",
|
|
2561
|
-
isInstalled: isWalletInstalled("rabby"),
|
|
2562
|
-
color: "blue"
|
|
2563
|
-
});
|
|
2462
|
+
return walletManager.current.getAvailableWallets();
|
|
2564
2463
|
}
|
|
2565
|
-
return
|
|
2464
|
+
return [];
|
|
2566
2465
|
};
|
|
2567
2466
|
const availableWallets = getAvailableWallets();
|
|
2568
2467
|
const handleWalletClick = async (walletType) => {
|
|
@@ -2574,10 +2473,25 @@ const WalletSelector = ({
|
|
|
2574
2473
|
return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-center p-4", children: /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-gray-500", children: "Please select a network first" }) });
|
|
2575
2474
|
}
|
|
2576
2475
|
if (availableWallets.length === 0) {
|
|
2577
|
-
return /* @__PURE__ */ jsxRuntimeExports.
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2476
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "text-center p-4", children: [
|
|
2477
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("p", { className: "text-gray-500 mb-4", children: [
|
|
2478
|
+
"No compatible wallets found for ",
|
|
2479
|
+
selectedNetwork.name
|
|
2480
|
+
] }),
|
|
2481
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "p-3 bg-amber-50 rounded-lg border border-amber-200", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "text-sm text-amber-800", style: { fontFamily: "Bricolage Grotesque, sans-serif" }, children: [
|
|
2482
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "font-medium mb-2", children: "💡 Install a compatible wallet:" }),
|
|
2483
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-1 text-xs", children: [
|
|
2484
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
|
|
2485
|
+
"• ",
|
|
2486
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("a", { href: "https://metamask.io", target: "_blank", rel: "noopener noreferrer", className: "text-amber-700 underline hover:text-amber-900", children: "Install MetaMask" })
|
|
2487
|
+
] }),
|
|
2488
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
|
|
2489
|
+
"• ",
|
|
2490
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("a", { href: "https://rabby.io", target: "_blank", rel: "noopener noreferrer", className: "text-amber-700 underline hover:text-amber-900", children: "Install Rabby Wallet" })
|
|
2491
|
+
] })
|
|
2492
|
+
] })
|
|
2493
|
+
] }) })
|
|
2494
|
+
] });
|
|
2581
2495
|
}
|
|
2582
2496
|
return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-3", children: [
|
|
2583
2497
|
/* @__PURE__ */ jsxRuntimeExports.jsxs("h4", { className: "text-sm font-medium text-gray-700 mb-3", style: { fontFamily: "Bricolage Grotesque, sans-serif" }, children: [
|
|
@@ -2589,8 +2503,8 @@ const WalletSelector = ({
|
|
|
2589
2503
|
"button",
|
|
2590
2504
|
{
|
|
2591
2505
|
onClick: () => handleWalletClick(wallet.type),
|
|
2592
|
-
disabled: loading
|
|
2593
|
-
className: `w-full p-4 border-2 rounded-xl text-left transition-all duration-200 ${(connectedWallet == null ? void 0 : connectedWallet.walletType) === wallet.type ? "border-green-500 bg-green-50" :
|
|
2506
|
+
disabled: loading,
|
|
2507
|
+
className: `w-full p-4 border-2 rounded-xl text-left transition-all duration-200 ${(connectedWallet == null ? void 0 : connectedWallet.walletType) === wallet.type ? "border-green-500 bg-green-50" : "border-gray-200 hover:border-[#7042D2]/50 hover:bg-[#7042D2]/5"}`,
|
|
2594
2508
|
style: { fontFamily: "Bricolage Grotesque, sans-serif" },
|
|
2595
2509
|
children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center space-x-3", children: [
|
|
2596
2510
|
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-2xl", children: wallet.icon }),
|
|
@@ -2599,24 +2513,22 @@ const WalletSelector = ({
|
|
|
2599
2513
|
wallet.name,
|
|
2600
2514
|
wallet.type === "rabby" && /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "ml-2 px-2 py-1 bg-blue-100 text-blue-700 text-xs rounded-full", children: "NEW" })
|
|
2601
2515
|
] }),
|
|
2602
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-sm text-gray-500", children:
|
|
2516
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-sm text-gray-500", children: (connectedWallet == null ? void 0 : connectedWallet.walletType) === wallet.type ? "✅ Connected" : wallet.description })
|
|
2603
2517
|
] }),
|
|
2604
2518
|
loading && selectedWalletType === wallet.type && /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "animate-spin rounded-full h-5 w-5 border-b-2 border-[#7042D2]" })
|
|
2605
2519
|
] })
|
|
2606
2520
|
},
|
|
2607
2521
|
wallet.type
|
|
2608
2522
|
)),
|
|
2609
|
-
|
|
2610
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "font-medium
|
|
2611
|
-
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx("a", { href: "https://rabby.io", target: "_blank", rel: "noopener noreferrer", className: "text-amber-700 underline hover:text-amber-900", children: "Install Rabby Wallet" })
|
|
2619
|
-
] })
|
|
2523
|
+
connectedWallet && /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "mt-4 p-3 bg-green-50 rounded-lg border border-green-200", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "text-sm text-green-800 text-center", style: { fontFamily: "Bricolage Grotesque, sans-serif" }, children: [
|
|
2524
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "font-medium", children: "✅ Wallet Connected" }),
|
|
2525
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "text-xs mt-1", children: [
|
|
2526
|
+
(_a = connectedWallet.account) == null ? void 0 : _a.slice(0, 6),
|
|
2527
|
+
"...",
|
|
2528
|
+
(_b = connectedWallet.account) == null ? void 0 : _b.slice(-4),
|
|
2529
|
+
" (",
|
|
2530
|
+
connectedWallet.walletType,
|
|
2531
|
+
")"
|
|
2620
2532
|
] })
|
|
2621
2533
|
] }) })
|
|
2622
2534
|
] });
|
|
@@ -2930,10 +2842,7 @@ const EnhancedSimpleCoinleyPayment = ({
|
|
|
2930
2842
|
const [paymentData, setPaymentData] = useState(null);
|
|
2931
2843
|
const [loading, setLoading] = useState(false);
|
|
2932
2844
|
const [error, setError] = useState("");
|
|
2933
|
-
const
|
|
2934
|
-
metamask: new SimpleMetaMaskWallet2(),
|
|
2935
|
-
rabby: new SimpleRabbyWallet()
|
|
2936
|
-
});
|
|
2845
|
+
const walletManager = useRef(new UniversalWalletManager());
|
|
2937
2846
|
const [selectedWalletType, setSelectedWalletType] = useState(null);
|
|
2938
2847
|
const [connectedWallet, setConnectedWallet] = useState(null);
|
|
2939
2848
|
const [processing, setProcessing] = useState(false);
|
|
@@ -2955,10 +2864,7 @@ const EnhancedSimpleCoinleyPayment = ({
|
|
|
2955
2864
|
setConnectedWallet(null);
|
|
2956
2865
|
setSelectedWalletType(null);
|
|
2957
2866
|
setProcessing(false);
|
|
2958
|
-
|
|
2959
|
-
metamask: new SimpleMetaMaskWallet2(),
|
|
2960
|
-
rabby: new SimpleRabbyWallet()
|
|
2961
|
-
});
|
|
2867
|
+
walletManager.current.disconnect();
|
|
2962
2868
|
setPaymentType("wallet");
|
|
2963
2869
|
};
|
|
2964
2870
|
const loadData = async () => {
|
|
@@ -3012,13 +2918,9 @@ const EnhancedSimpleCoinleyPayment = ({
|
|
|
3012
2918
|
try {
|
|
3013
2919
|
setLoading(true);
|
|
3014
2920
|
setError("");
|
|
3015
|
-
const wallet = wallets[walletType];
|
|
3016
|
-
if (!wallet) {
|
|
3017
|
-
throw new Error(`Wallet ${walletType} not found`);
|
|
3018
|
-
}
|
|
3019
2921
|
console.log(`🔗 Connecting to ${walletType} wallet...`);
|
|
3020
|
-
const connection = await
|
|
3021
|
-
setConnectedWallet(
|
|
2922
|
+
const connection = await walletManager.current.connect(walletType);
|
|
2923
|
+
setConnectedWallet(connection);
|
|
3022
2924
|
setSelectedWalletType(walletType);
|
|
3023
2925
|
console.log(`✅ ${walletType} wallet connected successfully:`, connection.account);
|
|
3024
2926
|
} catch (err) {
|
|
@@ -3045,7 +2947,6 @@ const EnhancedSimpleCoinleyPayment = ({
|
|
|
3045
2947
|
selectedNetwork: selectedNetwork.shortName,
|
|
3046
2948
|
selectedToken: selectedToken.symbol,
|
|
3047
2949
|
walletType: selectedWalletType
|
|
3048
|
-
// Include wallet type in metadata
|
|
3049
2950
|
}
|
|
3050
2951
|
};
|
|
3051
2952
|
console.log("🔄 Creating payment:", paymentPayload);
|
|
@@ -3062,7 +2963,7 @@ const EnhancedSimpleCoinleyPayment = ({
|
|
|
3062
2963
|
};
|
|
3063
2964
|
const sendTransaction = async () => {
|
|
3064
2965
|
var _a2, _b2;
|
|
3065
|
-
if (!
|
|
2966
|
+
if (!walletManager.current.isConnected()) {
|
|
3066
2967
|
setError("No wallet connected");
|
|
3067
2968
|
return;
|
|
3068
2969
|
}
|
|
@@ -3075,7 +2976,6 @@ const EnhancedSimpleCoinleyPayment = ({
|
|
|
3075
2976
|
}
|
|
3076
2977
|
console.log(`🔄 Preparing ${selectedWalletType} transaction to:`, recipientAddress);
|
|
3077
2978
|
let txParams;
|
|
3078
|
-
let txHash;
|
|
3079
2979
|
if (["metamask", "rabby"].includes(selectedWalletType)) {
|
|
3080
2980
|
if (selectedToken.contractAddress) {
|
|
3081
2981
|
const decimals = selectedToken.decimals || 6;
|
|
@@ -3109,7 +3009,7 @@ const EnhancedSimpleCoinleyPayment = ({
|
|
|
3109
3009
|
}
|
|
3110
3010
|
}
|
|
3111
3011
|
setCurrentStep("processing");
|
|
3112
|
-
txHash = await
|
|
3012
|
+
const txHash = await walletManager.current.sendTransaction(txParams);
|
|
3113
3013
|
console.log(`✅ ${selectedWalletType} transaction sent! Hash:`, txHash);
|
|
3114
3014
|
setTimeout(() => {
|
|
3115
3015
|
setCurrentStep("success");
|
|
@@ -3119,7 +3019,6 @@ const EnhancedSimpleCoinleyPayment = ({
|
|
|
3119
3019
|
amount: paymentData.totalAmount,
|
|
3120
3020
|
method: paymentMethod,
|
|
3121
3021
|
walletType: selectedWalletType
|
|
3122
|
-
// Include wallet type in callback
|
|
3123
3022
|
});
|
|
3124
3023
|
}, 2e3);
|
|
3125
3024
|
} catch (err) {
|
|
@@ -3303,6 +3202,7 @@ const EnhancedSimpleCoinleyPayment = ({
|
|
|
3303
3202
|
setSelectedToken(null);
|
|
3304
3203
|
setConnectedWallet(null);
|
|
3305
3204
|
setSelectedWalletType(null);
|
|
3205
|
+
walletManager.current.disconnect();
|
|
3306
3206
|
},
|
|
3307
3207
|
placeholder: "Choose your network...",
|
|
3308
3208
|
renderOption: renderNetworkOption,
|