coinley-checkout 0.1.6 → 0.1.8
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/coinley-checkout.es.js +1307 -624
- package/dist/coinley-checkout.es.js.map +1 -1
- package/dist/style.css +0 -3
- package/package.json +1 -1
- package/dist/coinley-checkout.umd.js +0 -2013
- package/dist/coinley-checkout.umd.js.map +0 -1
@@ -1,5 +1,117 @@
|
|
1
|
-
import
|
1
|
+
import React, { createContext, useContext, useState, useEffect, forwardRef, useImperativeHandle } from "react";
|
2
2
|
const styles = "";
|
3
|
+
let apiConfig = {
|
4
|
+
apiKey: null,
|
5
|
+
apiSecret: null,
|
6
|
+
apiUrl: "https://coinleyserver-production.up.railway.app"
|
7
|
+
};
|
8
|
+
const initializeApi = (config) => {
|
9
|
+
apiConfig = { ...apiConfig, ...config };
|
10
|
+
console.log("API initialized with:", apiConfig);
|
11
|
+
};
|
12
|
+
const getHeaders = () => {
|
13
|
+
return {
|
14
|
+
"Content-Type": "application/json",
|
15
|
+
"x-api-key": apiConfig.apiKey,
|
16
|
+
"x-api-secret": apiConfig.apiSecret
|
17
|
+
};
|
18
|
+
};
|
19
|
+
const createPayment = async (paymentData) => {
|
20
|
+
try {
|
21
|
+
console.log("Creating payment with data:", paymentData);
|
22
|
+
console.log("API URL:", `${apiConfig.apiUrl}/api/payments/create`);
|
23
|
+
const response = await fetch(`${apiConfig.apiUrl}/api/payments/create`, {
|
24
|
+
method: "POST",
|
25
|
+
headers: getHeaders(),
|
26
|
+
body: JSON.stringify(paymentData)
|
27
|
+
});
|
28
|
+
console.log("Create payment response status:", response.status);
|
29
|
+
if (!response.ok) {
|
30
|
+
const errorData = await response.json();
|
31
|
+
console.error("Error creating payment:", errorData);
|
32
|
+
throw new Error(errorData.error || `Failed to create payment: ${response.status}`);
|
33
|
+
}
|
34
|
+
const data = await response.json();
|
35
|
+
console.log("Create payment response data:", data);
|
36
|
+
return data;
|
37
|
+
} catch (error) {
|
38
|
+
console.error("Create payment error:", error);
|
39
|
+
throw error;
|
40
|
+
}
|
41
|
+
};
|
42
|
+
const getPayment = async (paymentId) => {
|
43
|
+
try {
|
44
|
+
console.log("Getting payment:", paymentId);
|
45
|
+
const response = await fetch(`${apiConfig.apiUrl}/api/payments/${paymentId}`, {
|
46
|
+
method: "GET",
|
47
|
+
headers: getHeaders()
|
48
|
+
});
|
49
|
+
if (!response.ok) {
|
50
|
+
const errorData = await response.json();
|
51
|
+
console.error("Error getting payment:", errorData);
|
52
|
+
throw new Error(errorData.error || `Failed to get payment: ${response.status}`);
|
53
|
+
}
|
54
|
+
const data = await response.json();
|
55
|
+
console.log("Get payment response:", data);
|
56
|
+
return data;
|
57
|
+
} catch (error) {
|
58
|
+
console.error("Get payment error:", error);
|
59
|
+
throw error;
|
60
|
+
}
|
61
|
+
};
|
62
|
+
const processPayment = async (processData) => {
|
63
|
+
try {
|
64
|
+
console.log("Processing payment with data:", processData);
|
65
|
+
console.log("API URL:", `${apiConfig.apiUrl}/api/payments/process`);
|
66
|
+
const response = await fetch(`${apiConfig.apiUrl}/api/payments/process`, {
|
67
|
+
method: "POST",
|
68
|
+
headers: getHeaders(),
|
69
|
+
body: JSON.stringify(processData)
|
70
|
+
});
|
71
|
+
console.log("Process payment response status:", response.status);
|
72
|
+
if (!response.ok) {
|
73
|
+
const errorData = await response.json();
|
74
|
+
console.error("Error processing payment:", errorData);
|
75
|
+
throw new Error(errorData.error || `Failed to process payment: ${response.status}`);
|
76
|
+
}
|
77
|
+
const data = await response.json();
|
78
|
+
console.log("Process payment response data:", data);
|
79
|
+
return data;
|
80
|
+
} catch (error) {
|
81
|
+
console.error("Process payment error:", error);
|
82
|
+
throw error;
|
83
|
+
}
|
84
|
+
};
|
85
|
+
const isMetaMaskInstalled = () => {
|
86
|
+
return typeof window !== "undefined" && typeof window.ethereum !== "undefined";
|
87
|
+
};
|
88
|
+
const connectWallet = async () => {
|
89
|
+
if (!isMetaMaskInstalled()) {
|
90
|
+
throw new Error("MetaMask is not installed");
|
91
|
+
}
|
92
|
+
try {
|
93
|
+
const accounts = await window.ethereum.request({ method: "eth_requestAccounts" });
|
94
|
+
return accounts;
|
95
|
+
} catch (error) {
|
96
|
+
console.error("Error connecting to wallet:", error);
|
97
|
+
throw error;
|
98
|
+
}
|
99
|
+
};
|
100
|
+
const sendTransaction = async (txParams) => {
|
101
|
+
if (!isMetaMaskInstalled()) {
|
102
|
+
throw new Error("MetaMask is not installed");
|
103
|
+
}
|
104
|
+
try {
|
105
|
+
const txHash = await window.ethereum.request({
|
106
|
+
method: "eth_sendTransaction",
|
107
|
+
params: [txParams]
|
108
|
+
});
|
109
|
+
return txHash;
|
110
|
+
} catch (error) {
|
111
|
+
console.error("Error sending transaction:", error);
|
112
|
+
throw error;
|
113
|
+
}
|
114
|
+
};
|
3
115
|
var jsxRuntime = { exports: {} };
|
4
116
|
var reactJsxRuntime_production_min = {};
|
5
117
|
/**
|
@@ -16,7 +128,7 @@ function requireReactJsxRuntime_production_min() {
|
|
16
128
|
if (hasRequiredReactJsxRuntime_production_min)
|
17
129
|
return reactJsxRuntime_production_min;
|
18
130
|
hasRequiredReactJsxRuntime_production_min = 1;
|
19
|
-
var f =
|
131
|
+
var f = React, k = Symbol.for("react.element"), l = Symbol.for("react.fragment"), m = Object.prototype.hasOwnProperty, n = f.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, p = { key: true, ref: true, __self: true, __source: true };
|
20
132
|
function q(c, a, g) {
|
21
133
|
var b, d = {}, e = null, h = null;
|
22
134
|
void 0 !== g && (e = "" + g);
|
@@ -51,7 +163,7 @@ function requireReactJsxRuntime_development() {
|
|
51
163
|
hasRequiredReactJsxRuntime_development = 1;
|
52
164
|
if (process.env.NODE_ENV !== "production") {
|
53
165
|
(function() {
|
54
|
-
var React =
|
166
|
+
var React$1 = React;
|
55
167
|
var REACT_ELEMENT_TYPE = Symbol.for("react.element");
|
56
168
|
var REACT_PORTAL_TYPE = Symbol.for("react.portal");
|
57
169
|
var REACT_FRAGMENT_TYPE = Symbol.for("react.fragment");
|
@@ -77,7 +189,7 @@ function requireReactJsxRuntime_development() {
|
|
77
189
|
}
|
78
190
|
return null;
|
79
191
|
}
|
80
|
-
var ReactSharedInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
|
192
|
+
var ReactSharedInternals = React$1.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
|
81
193
|
function error(format) {
|
82
194
|
{
|
83
195
|
{
|
@@ -955,159 +1067,6 @@ const ThemeProvider = ({ initialTheme = "light", children }) => {
|
|
955
1067
|
}, [theme]);
|
956
1068
|
return /* @__PURE__ */ jsxRuntimeExports.jsx(ThemeContext.Provider, { value: { theme, setTheme, toggleTheme }, children });
|
957
1069
|
};
|
958
|
-
let apiConfig = {
|
959
|
-
apiKey: null,
|
960
|
-
apiSecret: null,
|
961
|
-
apiUrl: "https://coinleyserver-production.up.railway.app"
|
962
|
-
};
|
963
|
-
const initializeApi = (config) => {
|
964
|
-
apiConfig = { ...apiConfig, ...config };
|
965
|
-
console.log("API initialized with:", apiConfig);
|
966
|
-
};
|
967
|
-
const getHeaders = () => {
|
968
|
-
return {
|
969
|
-
"Content-Type": "application/json",
|
970
|
-
"x-api-key": apiConfig.apiKey,
|
971
|
-
"x-api-secret": apiConfig.apiSecret
|
972
|
-
};
|
973
|
-
};
|
974
|
-
const createPayment = async (paymentData) => {
|
975
|
-
try {
|
976
|
-
console.log("Creating payment with data:", paymentData);
|
977
|
-
console.log("API URL:", `${apiConfig.apiUrl}/api/payments/create`);
|
978
|
-
const response = await fetch(`${apiConfig.apiUrl}/api/payments/create`, {
|
979
|
-
method: "POST",
|
980
|
-
headers: getHeaders(),
|
981
|
-
body: JSON.stringify(paymentData)
|
982
|
-
});
|
983
|
-
console.log("Create payment response status:", response.status);
|
984
|
-
if (!response.ok) {
|
985
|
-
const errorData = await response.json();
|
986
|
-
console.error("Error creating payment:", errorData);
|
987
|
-
throw new Error(errorData.error || `Failed to create payment: ${response.status}`);
|
988
|
-
}
|
989
|
-
const data = await response.json();
|
990
|
-
console.log("Create payment response data:", data);
|
991
|
-
return data;
|
992
|
-
} catch (error) {
|
993
|
-
console.error("Create payment error:", error);
|
994
|
-
throw error;
|
995
|
-
}
|
996
|
-
};
|
997
|
-
const getPayment = async (paymentId) => {
|
998
|
-
try {
|
999
|
-
console.log("Getting payment:", paymentId);
|
1000
|
-
const response = await fetch(`${apiConfig.apiUrl}/api/payments/${paymentId}`, {
|
1001
|
-
method: "GET",
|
1002
|
-
headers: getHeaders()
|
1003
|
-
});
|
1004
|
-
if (!response.ok) {
|
1005
|
-
const errorData = await response.json();
|
1006
|
-
console.error("Error getting payment:", errorData);
|
1007
|
-
throw new Error(errorData.error || `Failed to get payment: ${response.status}`);
|
1008
|
-
}
|
1009
|
-
const data = await response.json();
|
1010
|
-
console.log("Get payment response:", data);
|
1011
|
-
return data;
|
1012
|
-
} catch (error) {
|
1013
|
-
console.error("Get payment error:", error);
|
1014
|
-
throw error;
|
1015
|
-
}
|
1016
|
-
};
|
1017
|
-
const processPayment = async (processData) => {
|
1018
|
-
try {
|
1019
|
-
console.log("Processing payment with data:", processData);
|
1020
|
-
console.log("API URL:", `${apiConfig.apiUrl}/api/payments/process`);
|
1021
|
-
const response = await fetch(`${apiConfig.apiUrl}/api/payments/process`, {
|
1022
|
-
method: "POST",
|
1023
|
-
headers: getHeaders(),
|
1024
|
-
body: JSON.stringify(processData)
|
1025
|
-
});
|
1026
|
-
console.log("Process payment response status:", response.status);
|
1027
|
-
if (!response.ok) {
|
1028
|
-
const errorData = await response.json();
|
1029
|
-
console.error("Error processing payment:", errorData);
|
1030
|
-
throw new Error(errorData.error || `Failed to process payment: ${response.status}`);
|
1031
|
-
}
|
1032
|
-
const data = await response.json();
|
1033
|
-
console.log("Process payment response data:", data);
|
1034
|
-
return data;
|
1035
|
-
} catch (error) {
|
1036
|
-
console.error("Process payment error:", error);
|
1037
|
-
throw error;
|
1038
|
-
}
|
1039
|
-
};
|
1040
|
-
const getMerchantPayments = async (options = {}) => {
|
1041
|
-
try {
|
1042
|
-
const { page = 1, limit = 10, status, currency, startDate, endDate, search } = options;
|
1043
|
-
const queryParams = new URLSearchParams();
|
1044
|
-
queryParams.append("page", page);
|
1045
|
-
queryParams.append("limit", limit);
|
1046
|
-
if (status)
|
1047
|
-
queryParams.append("status", status);
|
1048
|
-
if (currency)
|
1049
|
-
queryParams.append("currency", currency);
|
1050
|
-
if (startDate)
|
1051
|
-
queryParams.append("startDate", startDate);
|
1052
|
-
if (endDate)
|
1053
|
-
queryParams.append("endDate", endDate);
|
1054
|
-
if (search)
|
1055
|
-
queryParams.append("search", search);
|
1056
|
-
const url = `${apiConfig.apiUrl}/api/payments/merchant/list?${queryParams.toString()}`;
|
1057
|
-
const response = await fetch(url, {
|
1058
|
-
method: "GET",
|
1059
|
-
headers: getHeaders()
|
1060
|
-
});
|
1061
|
-
if (!response.ok) {
|
1062
|
-
const errorData = await response.json();
|
1063
|
-
throw new Error(errorData.error || `Failed to get payments: ${response.status}`);
|
1064
|
-
}
|
1065
|
-
return await response.json();
|
1066
|
-
} catch (error) {
|
1067
|
-
console.error("Get merchant payments error:", error);
|
1068
|
-
throw error;
|
1069
|
-
}
|
1070
|
-
};
|
1071
|
-
const getMerchantPaymentStats = async () => {
|
1072
|
-
try {
|
1073
|
-
const response = await fetch(`${apiConfig.apiUrl}/api/payments/merchant/stats`, {
|
1074
|
-
method: "GET",
|
1075
|
-
headers: getHeaders()
|
1076
|
-
});
|
1077
|
-
if (!response.ok) {
|
1078
|
-
const errorData = await response.json();
|
1079
|
-
throw new Error(errorData.error || `Failed to get payment stats: ${response.status}`);
|
1080
|
-
}
|
1081
|
-
return await response.json();
|
1082
|
-
} catch (error) {
|
1083
|
-
console.error("Get merchant payment stats error:", error);
|
1084
|
-
throw error;
|
1085
|
-
}
|
1086
|
-
};
|
1087
|
-
const getSupportedCurrencies = async () => {
|
1088
|
-
try {
|
1089
|
-
const response = await fetch(`${apiConfig.apiUrl}/api/payments/currencies`, {
|
1090
|
-
method: "GET",
|
1091
|
-
headers: getHeaders()
|
1092
|
-
});
|
1093
|
-
if (!response.ok) {
|
1094
|
-
const errorData = await response.json();
|
1095
|
-
throw new Error(errorData.error || `Failed to get currencies: ${response.status}`);
|
1096
|
-
}
|
1097
|
-
return await response.json();
|
1098
|
-
} catch (error) {
|
1099
|
-
console.error("Get supported currencies error:", error);
|
1100
|
-
return {
|
1101
|
-
currencies: [
|
1102
|
-
{ id: "USDT", name: "Tether USD", network: "ethereum" },
|
1103
|
-
{ id: "USDC", name: "USD Coin", network: "ethereum" },
|
1104
|
-
{ id: "BNB", name: "Binance Coin", network: "binance" },
|
1105
|
-
{ id: "SOL", name: "Solana", network: "solana" },
|
1106
|
-
{ id: "USDC_SOL", name: "USD Coin (Solana)", network: "solana" }
|
1107
|
-
]
|
1108
|
-
};
|
1109
|
-
}
|
1110
|
-
};
|
1111
1070
|
const CoinleyContext = createContext();
|
1112
1071
|
const useCoinley = () => useContext(CoinleyContext);
|
1113
1072
|
const CoinleyProvider = ({
|
@@ -1147,58 +1106,1171 @@ const CoinleyProvider = ({
|
|
1147
1106
|
};
|
1148
1107
|
return /* @__PURE__ */ jsxRuntimeExports.jsx(CoinleyContext.Provider, { value, children });
|
1149
1108
|
};
|
1150
|
-
|
1151
|
-
|
1152
|
-
|
1153
|
-
|
1154
|
-
|
1155
|
-
|
1156
|
-
|
1157
|
-
|
1158
|
-
|
1159
|
-
|
1160
|
-
|
1161
|
-
|
1162
|
-
|
1163
|
-
border: `1px solid ${theme === "dark" ? "#4b5563" : "#e5e7eb"}`,
|
1164
|
-
margin: "0 auto"
|
1165
|
-
},
|
1166
|
-
children: [
|
1167
|
-
currency,
|
1168
|
-
" Payment QR"
|
1169
|
-
]
|
1109
|
+
var __defProp = Object.defineProperty;
|
1110
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
1111
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
1112
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
1113
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
1114
|
+
var __spreadValues = (a, b) => {
|
1115
|
+
for (var prop in b || (b = {}))
|
1116
|
+
if (__hasOwnProp.call(b, prop))
|
1117
|
+
__defNormalProp(a, prop, b[prop]);
|
1118
|
+
if (__getOwnPropSymbols)
|
1119
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
1120
|
+
if (__propIsEnum.call(b, prop))
|
1121
|
+
__defNormalProp(a, prop, b[prop]);
|
1170
1122
|
}
|
1171
|
-
|
1172
|
-
return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex flex-col items-center", children: [
|
1173
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: `p-4 rounded-lg ${theme === "dark" ? "bg-gray-700" : "bg-white"} mb-3`, children: qrPlaceholder }),
|
1174
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: `text-center text-sm ${theme === "dark" ? "text-gray-300" : "text-gray-700"}`, children: "Scan with your wallet app to pay" }),
|
1175
|
-
walletAddress && /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "mt-3 w-full", children: [
|
1176
|
-
/* @__PURE__ */ jsxRuntimeExports.jsxs("p", { className: `text-xs ${theme === "dark" ? "text-gray-400" : "text-gray-500"} mb-1`, children: [
|
1177
|
-
"Send ",
|
1178
|
-
amount,
|
1179
|
-
" ",
|
1180
|
-
currency,
|
1181
|
-
" to:"
|
1182
|
-
] }),
|
1183
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: `text-xs font-mono p-2 rounded overflow-auto break-all ${theme === "dark" ? "bg-gray-800 text-gray-300" : "bg-gray-100 text-gray-700"}`, children: walletAddress })
|
1184
|
-
] }),
|
1185
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "mt-4 w-full", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: `p-3 rounded ${theme === "dark" ? "bg-gray-700" : "bg-gray-100"}`, children: [
|
1186
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx("h4", { className: `text-sm font-medium mb-2 ${theme === "dark" ? "text-white" : "text-gray-800"}`, children: "Payment Instructions" }),
|
1187
|
-
/* @__PURE__ */ jsxRuntimeExports.jsxs("ol", { className: `text-xs space-y-2 ${theme === "dark" ? "text-gray-300" : "text-gray-600"}`, children: [
|
1188
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: "1. Open your crypto wallet app" }),
|
1189
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: "2. Scan the QR code above" }),
|
1190
|
-
/* @__PURE__ */ jsxRuntimeExports.jsxs("li", { children: [
|
1191
|
-
"3. Send ",
|
1192
|
-
amount,
|
1193
|
-
" ",
|
1194
|
-
currency
|
1195
|
-
] }),
|
1196
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: '4. Click "Pay Now" button after sending' })
|
1197
|
-
] })
|
1198
|
-
] }) })
|
1199
|
-
] });
|
1123
|
+
return a;
|
1200
1124
|
};
|
1201
|
-
|
1125
|
+
var __objRest = (source, exclude) => {
|
1126
|
+
var target = {};
|
1127
|
+
for (var prop in source)
|
1128
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
1129
|
+
target[prop] = source[prop];
|
1130
|
+
if (source != null && __getOwnPropSymbols)
|
1131
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
1132
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
1133
|
+
target[prop] = source[prop];
|
1134
|
+
}
|
1135
|
+
return target;
|
1136
|
+
};
|
1137
|
+
/**
|
1138
|
+
* @license QR Code generator library (TypeScript)
|
1139
|
+
* Copyright (c) Project Nayuki.
|
1140
|
+
* SPDX-License-Identifier: MIT
|
1141
|
+
*/
|
1142
|
+
var qrcodegen;
|
1143
|
+
((qrcodegen2) => {
|
1144
|
+
const _QrCode = class _QrCode2 {
|
1145
|
+
/*-- Constructor (low level) and fields --*/
|
1146
|
+
// Creates a new QR Code with the given version number,
|
1147
|
+
// error correction level, data codeword bytes, and mask number.
|
1148
|
+
// This is a low-level API that most users should not use directly.
|
1149
|
+
// A mid-level API is the encodeSegments() function.
|
1150
|
+
constructor(version, errorCorrectionLevel, dataCodewords, msk) {
|
1151
|
+
this.version = version;
|
1152
|
+
this.errorCorrectionLevel = errorCorrectionLevel;
|
1153
|
+
this.modules = [];
|
1154
|
+
this.isFunction = [];
|
1155
|
+
if (version < _QrCode2.MIN_VERSION || version > _QrCode2.MAX_VERSION)
|
1156
|
+
throw new RangeError("Version value out of range");
|
1157
|
+
if (msk < -1 || msk > 7)
|
1158
|
+
throw new RangeError("Mask value out of range");
|
1159
|
+
this.size = version * 4 + 17;
|
1160
|
+
let row = [];
|
1161
|
+
for (let i = 0; i < this.size; i++)
|
1162
|
+
row.push(false);
|
1163
|
+
for (let i = 0; i < this.size; i++) {
|
1164
|
+
this.modules.push(row.slice());
|
1165
|
+
this.isFunction.push(row.slice());
|
1166
|
+
}
|
1167
|
+
this.drawFunctionPatterns();
|
1168
|
+
const allCodewords = this.addEccAndInterleave(dataCodewords);
|
1169
|
+
this.drawCodewords(allCodewords);
|
1170
|
+
if (msk == -1) {
|
1171
|
+
let minPenalty = 1e9;
|
1172
|
+
for (let i = 0; i < 8; i++) {
|
1173
|
+
this.applyMask(i);
|
1174
|
+
this.drawFormatBits(i);
|
1175
|
+
const penalty = this.getPenaltyScore();
|
1176
|
+
if (penalty < minPenalty) {
|
1177
|
+
msk = i;
|
1178
|
+
minPenalty = penalty;
|
1179
|
+
}
|
1180
|
+
this.applyMask(i);
|
1181
|
+
}
|
1182
|
+
}
|
1183
|
+
assert(0 <= msk && msk <= 7);
|
1184
|
+
this.mask = msk;
|
1185
|
+
this.applyMask(msk);
|
1186
|
+
this.drawFormatBits(msk);
|
1187
|
+
this.isFunction = [];
|
1188
|
+
}
|
1189
|
+
/*-- Static factory functions (high level) --*/
|
1190
|
+
// Returns a QR Code representing the given Unicode text string at the given error correction level.
|
1191
|
+
// As a conservative upper bound, this function is guaranteed to succeed for strings that have 738 or fewer
|
1192
|
+
// Unicode code points (not UTF-16 code units) if the low error correction level is used. The smallest possible
|
1193
|
+
// QR Code version is automatically chosen for the output. The ECC level of the result may be higher than the
|
1194
|
+
// ecl argument if it can be done without increasing the version.
|
1195
|
+
static encodeText(text, ecl) {
|
1196
|
+
const segs = qrcodegen2.QrSegment.makeSegments(text);
|
1197
|
+
return _QrCode2.encodeSegments(segs, ecl);
|
1198
|
+
}
|
1199
|
+
// Returns a QR Code representing the given binary data at the given error correction level.
|
1200
|
+
// This function always encodes using the binary segment mode, not any text mode. The maximum number of
|
1201
|
+
// bytes allowed is 2953. The smallest possible QR Code version is automatically chosen for the output.
|
1202
|
+
// The ECC level of the result may be higher than the ecl argument if it can be done without increasing the version.
|
1203
|
+
static encodeBinary(data, ecl) {
|
1204
|
+
const seg = qrcodegen2.QrSegment.makeBytes(data);
|
1205
|
+
return _QrCode2.encodeSegments([seg], ecl);
|
1206
|
+
}
|
1207
|
+
/*-- Static factory functions (mid level) --*/
|
1208
|
+
// Returns a QR Code representing the given segments with the given encoding parameters.
|
1209
|
+
// The smallest possible QR Code version within the given range is automatically
|
1210
|
+
// chosen for the output. Iff boostEcl is true, then the ECC level of the result
|
1211
|
+
// may be higher than the ecl argument if it can be done without increasing the
|
1212
|
+
// version. The mask number is either between 0 to 7 (inclusive) to force that
|
1213
|
+
// mask, or -1 to automatically choose an appropriate mask (which may be slow).
|
1214
|
+
// This function allows the user to create a custom sequence of segments that switches
|
1215
|
+
// between modes (such as alphanumeric and byte) to encode text in less space.
|
1216
|
+
// This is a mid-level API; the high-level API is encodeText() and encodeBinary().
|
1217
|
+
static encodeSegments(segs, ecl, minVersion = 1, maxVersion = 40, mask = -1, boostEcl = true) {
|
1218
|
+
if (!(_QrCode2.MIN_VERSION <= minVersion && minVersion <= maxVersion && maxVersion <= _QrCode2.MAX_VERSION) || mask < -1 || mask > 7)
|
1219
|
+
throw new RangeError("Invalid value");
|
1220
|
+
let version;
|
1221
|
+
let dataUsedBits;
|
1222
|
+
for (version = minVersion; ; version++) {
|
1223
|
+
const dataCapacityBits2 = _QrCode2.getNumDataCodewords(version, ecl) * 8;
|
1224
|
+
const usedBits = QrSegment.getTotalBits(segs, version);
|
1225
|
+
if (usedBits <= dataCapacityBits2) {
|
1226
|
+
dataUsedBits = usedBits;
|
1227
|
+
break;
|
1228
|
+
}
|
1229
|
+
if (version >= maxVersion)
|
1230
|
+
throw new RangeError("Data too long");
|
1231
|
+
}
|
1232
|
+
for (const newEcl of [_QrCode2.Ecc.MEDIUM, _QrCode2.Ecc.QUARTILE, _QrCode2.Ecc.HIGH]) {
|
1233
|
+
if (boostEcl && dataUsedBits <= _QrCode2.getNumDataCodewords(version, newEcl) * 8)
|
1234
|
+
ecl = newEcl;
|
1235
|
+
}
|
1236
|
+
let bb = [];
|
1237
|
+
for (const seg of segs) {
|
1238
|
+
appendBits(seg.mode.modeBits, 4, bb);
|
1239
|
+
appendBits(seg.numChars, seg.mode.numCharCountBits(version), bb);
|
1240
|
+
for (const b of seg.getData())
|
1241
|
+
bb.push(b);
|
1242
|
+
}
|
1243
|
+
assert(bb.length == dataUsedBits);
|
1244
|
+
const dataCapacityBits = _QrCode2.getNumDataCodewords(version, ecl) * 8;
|
1245
|
+
assert(bb.length <= dataCapacityBits);
|
1246
|
+
appendBits(0, Math.min(4, dataCapacityBits - bb.length), bb);
|
1247
|
+
appendBits(0, (8 - bb.length % 8) % 8, bb);
|
1248
|
+
assert(bb.length % 8 == 0);
|
1249
|
+
for (let padByte = 236; bb.length < dataCapacityBits; padByte ^= 236 ^ 17)
|
1250
|
+
appendBits(padByte, 8, bb);
|
1251
|
+
let dataCodewords = [];
|
1252
|
+
while (dataCodewords.length * 8 < bb.length)
|
1253
|
+
dataCodewords.push(0);
|
1254
|
+
bb.forEach((b, i) => dataCodewords[i >>> 3] |= b << 7 - (i & 7));
|
1255
|
+
return new _QrCode2(version, ecl, dataCodewords, mask);
|
1256
|
+
}
|
1257
|
+
/*-- Accessor methods --*/
|
1258
|
+
// Returns the color of the module (pixel) at the given coordinates, which is false
|
1259
|
+
// for light or true for dark. The top left corner has the coordinates (x=0, y=0).
|
1260
|
+
// If the given coordinates are out of bounds, then false (light) is returned.
|
1261
|
+
getModule(x, y) {
|
1262
|
+
return 0 <= x && x < this.size && 0 <= y && y < this.size && this.modules[y][x];
|
1263
|
+
}
|
1264
|
+
// Modified to expose modules for easy access
|
1265
|
+
getModules() {
|
1266
|
+
return this.modules;
|
1267
|
+
}
|
1268
|
+
/*-- Private helper methods for constructor: Drawing function modules --*/
|
1269
|
+
// Reads this object's version field, and draws and marks all function modules.
|
1270
|
+
drawFunctionPatterns() {
|
1271
|
+
for (let i = 0; i < this.size; i++) {
|
1272
|
+
this.setFunctionModule(6, i, i % 2 == 0);
|
1273
|
+
this.setFunctionModule(i, 6, i % 2 == 0);
|
1274
|
+
}
|
1275
|
+
this.drawFinderPattern(3, 3);
|
1276
|
+
this.drawFinderPattern(this.size - 4, 3);
|
1277
|
+
this.drawFinderPattern(3, this.size - 4);
|
1278
|
+
const alignPatPos = this.getAlignmentPatternPositions();
|
1279
|
+
const numAlign = alignPatPos.length;
|
1280
|
+
for (let i = 0; i < numAlign; i++) {
|
1281
|
+
for (let j = 0; j < numAlign; j++) {
|
1282
|
+
if (!(i == 0 && j == 0 || i == 0 && j == numAlign - 1 || i == numAlign - 1 && j == 0))
|
1283
|
+
this.drawAlignmentPattern(alignPatPos[i], alignPatPos[j]);
|
1284
|
+
}
|
1285
|
+
}
|
1286
|
+
this.drawFormatBits(0);
|
1287
|
+
this.drawVersion();
|
1288
|
+
}
|
1289
|
+
// Draws two copies of the format bits (with its own error correction code)
|
1290
|
+
// based on the given mask and this object's error correction level field.
|
1291
|
+
drawFormatBits(mask) {
|
1292
|
+
const data = this.errorCorrectionLevel.formatBits << 3 | mask;
|
1293
|
+
let rem = data;
|
1294
|
+
for (let i = 0; i < 10; i++)
|
1295
|
+
rem = rem << 1 ^ (rem >>> 9) * 1335;
|
1296
|
+
const bits = (data << 10 | rem) ^ 21522;
|
1297
|
+
assert(bits >>> 15 == 0);
|
1298
|
+
for (let i = 0; i <= 5; i++)
|
1299
|
+
this.setFunctionModule(8, i, getBit(bits, i));
|
1300
|
+
this.setFunctionModule(8, 7, getBit(bits, 6));
|
1301
|
+
this.setFunctionModule(8, 8, getBit(bits, 7));
|
1302
|
+
this.setFunctionModule(7, 8, getBit(bits, 8));
|
1303
|
+
for (let i = 9; i < 15; i++)
|
1304
|
+
this.setFunctionModule(14 - i, 8, getBit(bits, i));
|
1305
|
+
for (let i = 0; i < 8; i++)
|
1306
|
+
this.setFunctionModule(this.size - 1 - i, 8, getBit(bits, i));
|
1307
|
+
for (let i = 8; i < 15; i++)
|
1308
|
+
this.setFunctionModule(8, this.size - 15 + i, getBit(bits, i));
|
1309
|
+
this.setFunctionModule(8, this.size - 8, true);
|
1310
|
+
}
|
1311
|
+
// Draws two copies of the version bits (with its own error correction code),
|
1312
|
+
// based on this object's version field, iff 7 <= version <= 40.
|
1313
|
+
drawVersion() {
|
1314
|
+
if (this.version < 7)
|
1315
|
+
return;
|
1316
|
+
let rem = this.version;
|
1317
|
+
for (let i = 0; i < 12; i++)
|
1318
|
+
rem = rem << 1 ^ (rem >>> 11) * 7973;
|
1319
|
+
const bits = this.version << 12 | rem;
|
1320
|
+
assert(bits >>> 18 == 0);
|
1321
|
+
for (let i = 0; i < 18; i++) {
|
1322
|
+
const color = getBit(bits, i);
|
1323
|
+
const a = this.size - 11 + i % 3;
|
1324
|
+
const b = Math.floor(i / 3);
|
1325
|
+
this.setFunctionModule(a, b, color);
|
1326
|
+
this.setFunctionModule(b, a, color);
|
1327
|
+
}
|
1328
|
+
}
|
1329
|
+
// Draws a 9*9 finder pattern including the border separator,
|
1330
|
+
// with the center module at (x, y). Modules can be out of bounds.
|
1331
|
+
drawFinderPattern(x, y) {
|
1332
|
+
for (let dy = -4; dy <= 4; dy++) {
|
1333
|
+
for (let dx = -4; dx <= 4; dx++) {
|
1334
|
+
const dist = Math.max(Math.abs(dx), Math.abs(dy));
|
1335
|
+
const xx = x + dx;
|
1336
|
+
const yy = y + dy;
|
1337
|
+
if (0 <= xx && xx < this.size && 0 <= yy && yy < this.size)
|
1338
|
+
this.setFunctionModule(xx, yy, dist != 2 && dist != 4);
|
1339
|
+
}
|
1340
|
+
}
|
1341
|
+
}
|
1342
|
+
// Draws a 5*5 alignment pattern, with the center module
|
1343
|
+
// at (x, y). All modules must be in bounds.
|
1344
|
+
drawAlignmentPattern(x, y) {
|
1345
|
+
for (let dy = -2; dy <= 2; dy++) {
|
1346
|
+
for (let dx = -2; dx <= 2; dx++)
|
1347
|
+
this.setFunctionModule(x + dx, y + dy, Math.max(Math.abs(dx), Math.abs(dy)) != 1);
|
1348
|
+
}
|
1349
|
+
}
|
1350
|
+
// Sets the color of a module and marks it as a function module.
|
1351
|
+
// Only used by the constructor. Coordinates must be in bounds.
|
1352
|
+
setFunctionModule(x, y, isDark) {
|
1353
|
+
this.modules[y][x] = isDark;
|
1354
|
+
this.isFunction[y][x] = true;
|
1355
|
+
}
|
1356
|
+
/*-- Private helper methods for constructor: Codewords and masking --*/
|
1357
|
+
// Returns a new byte string representing the given data with the appropriate error correction
|
1358
|
+
// codewords appended to it, based on this object's version and error correction level.
|
1359
|
+
addEccAndInterleave(data) {
|
1360
|
+
const ver = this.version;
|
1361
|
+
const ecl = this.errorCorrectionLevel;
|
1362
|
+
if (data.length != _QrCode2.getNumDataCodewords(ver, ecl))
|
1363
|
+
throw new RangeError("Invalid argument");
|
1364
|
+
const numBlocks = _QrCode2.NUM_ERROR_CORRECTION_BLOCKS[ecl.ordinal][ver];
|
1365
|
+
const blockEccLen = _QrCode2.ECC_CODEWORDS_PER_BLOCK[ecl.ordinal][ver];
|
1366
|
+
const rawCodewords = Math.floor(_QrCode2.getNumRawDataModules(ver) / 8);
|
1367
|
+
const numShortBlocks = numBlocks - rawCodewords % numBlocks;
|
1368
|
+
const shortBlockLen = Math.floor(rawCodewords / numBlocks);
|
1369
|
+
let blocks = [];
|
1370
|
+
const rsDiv = _QrCode2.reedSolomonComputeDivisor(blockEccLen);
|
1371
|
+
for (let i = 0, k = 0; i < numBlocks; i++) {
|
1372
|
+
let dat = data.slice(k, k + shortBlockLen - blockEccLen + (i < numShortBlocks ? 0 : 1));
|
1373
|
+
k += dat.length;
|
1374
|
+
const ecc = _QrCode2.reedSolomonComputeRemainder(dat, rsDiv);
|
1375
|
+
if (i < numShortBlocks)
|
1376
|
+
dat.push(0);
|
1377
|
+
blocks.push(dat.concat(ecc));
|
1378
|
+
}
|
1379
|
+
let result = [];
|
1380
|
+
for (let i = 0; i < blocks[0].length; i++) {
|
1381
|
+
blocks.forEach((block, j) => {
|
1382
|
+
if (i != shortBlockLen - blockEccLen || j >= numShortBlocks)
|
1383
|
+
result.push(block[i]);
|
1384
|
+
});
|
1385
|
+
}
|
1386
|
+
assert(result.length == rawCodewords);
|
1387
|
+
return result;
|
1388
|
+
}
|
1389
|
+
// Draws the given sequence of 8-bit codewords (data and error correction) onto the entire
|
1390
|
+
// data area of this QR Code. Function modules need to be marked off before this is called.
|
1391
|
+
drawCodewords(data) {
|
1392
|
+
if (data.length != Math.floor(_QrCode2.getNumRawDataModules(this.version) / 8))
|
1393
|
+
throw new RangeError("Invalid argument");
|
1394
|
+
let i = 0;
|
1395
|
+
for (let right = this.size - 1; right >= 1; right -= 2) {
|
1396
|
+
if (right == 6)
|
1397
|
+
right = 5;
|
1398
|
+
for (let vert = 0; vert < this.size; vert++) {
|
1399
|
+
for (let j = 0; j < 2; j++) {
|
1400
|
+
const x = right - j;
|
1401
|
+
const upward = (right + 1 & 2) == 0;
|
1402
|
+
const y = upward ? this.size - 1 - vert : vert;
|
1403
|
+
if (!this.isFunction[y][x] && i < data.length * 8) {
|
1404
|
+
this.modules[y][x] = getBit(data[i >>> 3], 7 - (i & 7));
|
1405
|
+
i++;
|
1406
|
+
}
|
1407
|
+
}
|
1408
|
+
}
|
1409
|
+
}
|
1410
|
+
assert(i == data.length * 8);
|
1411
|
+
}
|
1412
|
+
// XORs the codeword modules in this QR Code with the given mask pattern.
|
1413
|
+
// The function modules must be marked and the codeword bits must be drawn
|
1414
|
+
// before masking. Due to the arithmetic of XOR, calling applyMask() with
|
1415
|
+
// the same mask value a second time will undo the mask. A final well-formed
|
1416
|
+
// QR Code needs exactly one (not zero, two, etc.) mask applied.
|
1417
|
+
applyMask(mask) {
|
1418
|
+
if (mask < 0 || mask > 7)
|
1419
|
+
throw new RangeError("Mask value out of range");
|
1420
|
+
for (let y = 0; y < this.size; y++) {
|
1421
|
+
for (let x = 0; x < this.size; x++) {
|
1422
|
+
let invert;
|
1423
|
+
switch (mask) {
|
1424
|
+
case 0:
|
1425
|
+
invert = (x + y) % 2 == 0;
|
1426
|
+
break;
|
1427
|
+
case 1:
|
1428
|
+
invert = y % 2 == 0;
|
1429
|
+
break;
|
1430
|
+
case 2:
|
1431
|
+
invert = x % 3 == 0;
|
1432
|
+
break;
|
1433
|
+
case 3:
|
1434
|
+
invert = (x + y) % 3 == 0;
|
1435
|
+
break;
|
1436
|
+
case 4:
|
1437
|
+
invert = (Math.floor(x / 3) + Math.floor(y / 2)) % 2 == 0;
|
1438
|
+
break;
|
1439
|
+
case 5:
|
1440
|
+
invert = x * y % 2 + x * y % 3 == 0;
|
1441
|
+
break;
|
1442
|
+
case 6:
|
1443
|
+
invert = (x * y % 2 + x * y % 3) % 2 == 0;
|
1444
|
+
break;
|
1445
|
+
case 7:
|
1446
|
+
invert = ((x + y) % 2 + x * y % 3) % 2 == 0;
|
1447
|
+
break;
|
1448
|
+
default:
|
1449
|
+
throw new Error("Unreachable");
|
1450
|
+
}
|
1451
|
+
if (!this.isFunction[y][x] && invert)
|
1452
|
+
this.modules[y][x] = !this.modules[y][x];
|
1453
|
+
}
|
1454
|
+
}
|
1455
|
+
}
|
1456
|
+
// Calculates and returns the penalty score based on state of this QR Code's current modules.
|
1457
|
+
// This is used by the automatic mask choice algorithm to find the mask pattern that yields the lowest score.
|
1458
|
+
getPenaltyScore() {
|
1459
|
+
let result = 0;
|
1460
|
+
for (let y = 0; y < this.size; y++) {
|
1461
|
+
let runColor = false;
|
1462
|
+
let runX = 0;
|
1463
|
+
let runHistory = [0, 0, 0, 0, 0, 0, 0];
|
1464
|
+
for (let x = 0; x < this.size; x++) {
|
1465
|
+
if (this.modules[y][x] == runColor) {
|
1466
|
+
runX++;
|
1467
|
+
if (runX == 5)
|
1468
|
+
result += _QrCode2.PENALTY_N1;
|
1469
|
+
else if (runX > 5)
|
1470
|
+
result++;
|
1471
|
+
} else {
|
1472
|
+
this.finderPenaltyAddHistory(runX, runHistory);
|
1473
|
+
if (!runColor)
|
1474
|
+
result += this.finderPenaltyCountPatterns(runHistory) * _QrCode2.PENALTY_N3;
|
1475
|
+
runColor = this.modules[y][x];
|
1476
|
+
runX = 1;
|
1477
|
+
}
|
1478
|
+
}
|
1479
|
+
result += this.finderPenaltyTerminateAndCount(runColor, runX, runHistory) * _QrCode2.PENALTY_N3;
|
1480
|
+
}
|
1481
|
+
for (let x = 0; x < this.size; x++) {
|
1482
|
+
let runColor = false;
|
1483
|
+
let runY = 0;
|
1484
|
+
let runHistory = [0, 0, 0, 0, 0, 0, 0];
|
1485
|
+
for (let y = 0; y < this.size; y++) {
|
1486
|
+
if (this.modules[y][x] == runColor) {
|
1487
|
+
runY++;
|
1488
|
+
if (runY == 5)
|
1489
|
+
result += _QrCode2.PENALTY_N1;
|
1490
|
+
else if (runY > 5)
|
1491
|
+
result++;
|
1492
|
+
} else {
|
1493
|
+
this.finderPenaltyAddHistory(runY, runHistory);
|
1494
|
+
if (!runColor)
|
1495
|
+
result += this.finderPenaltyCountPatterns(runHistory) * _QrCode2.PENALTY_N3;
|
1496
|
+
runColor = this.modules[y][x];
|
1497
|
+
runY = 1;
|
1498
|
+
}
|
1499
|
+
}
|
1500
|
+
result += this.finderPenaltyTerminateAndCount(runColor, runY, runHistory) * _QrCode2.PENALTY_N3;
|
1501
|
+
}
|
1502
|
+
for (let y = 0; y < this.size - 1; y++) {
|
1503
|
+
for (let x = 0; x < this.size - 1; x++) {
|
1504
|
+
const color = this.modules[y][x];
|
1505
|
+
if (color == this.modules[y][x + 1] && color == this.modules[y + 1][x] && color == this.modules[y + 1][x + 1])
|
1506
|
+
result += _QrCode2.PENALTY_N2;
|
1507
|
+
}
|
1508
|
+
}
|
1509
|
+
let dark = 0;
|
1510
|
+
for (const row of this.modules)
|
1511
|
+
dark = row.reduce((sum, color) => sum + (color ? 1 : 0), dark);
|
1512
|
+
const total = this.size * this.size;
|
1513
|
+
const k = Math.ceil(Math.abs(dark * 20 - total * 10) / total) - 1;
|
1514
|
+
assert(0 <= k && k <= 9);
|
1515
|
+
result += k * _QrCode2.PENALTY_N4;
|
1516
|
+
assert(0 <= result && result <= 2568888);
|
1517
|
+
return result;
|
1518
|
+
}
|
1519
|
+
/*-- Private helper functions --*/
|
1520
|
+
// Returns an ascending list of positions of alignment patterns for this version number.
|
1521
|
+
// Each position is in the range [0,177), and are used on both the x and y axes.
|
1522
|
+
// This could be implemented as lookup table of 40 variable-length lists of integers.
|
1523
|
+
getAlignmentPatternPositions() {
|
1524
|
+
if (this.version == 1)
|
1525
|
+
return [];
|
1526
|
+
else {
|
1527
|
+
const numAlign = Math.floor(this.version / 7) + 2;
|
1528
|
+
const step = this.version == 32 ? 26 : Math.ceil((this.version * 4 + 4) / (numAlign * 2 - 2)) * 2;
|
1529
|
+
let result = [6];
|
1530
|
+
for (let pos = this.size - 7; result.length < numAlign; pos -= step)
|
1531
|
+
result.splice(1, 0, pos);
|
1532
|
+
return result;
|
1533
|
+
}
|
1534
|
+
}
|
1535
|
+
// Returns the number of data bits that can be stored in a QR Code of the given version number, after
|
1536
|
+
// all function modules are excluded. This includes remainder bits, so it might not be a multiple of 8.
|
1537
|
+
// The result is in the range [208, 29648]. This could be implemented as a 40-entry lookup table.
|
1538
|
+
static getNumRawDataModules(ver) {
|
1539
|
+
if (ver < _QrCode2.MIN_VERSION || ver > _QrCode2.MAX_VERSION)
|
1540
|
+
throw new RangeError("Version number out of range");
|
1541
|
+
let result = (16 * ver + 128) * ver + 64;
|
1542
|
+
if (ver >= 2) {
|
1543
|
+
const numAlign = Math.floor(ver / 7) + 2;
|
1544
|
+
result -= (25 * numAlign - 10) * numAlign - 55;
|
1545
|
+
if (ver >= 7)
|
1546
|
+
result -= 36;
|
1547
|
+
}
|
1548
|
+
assert(208 <= result && result <= 29648);
|
1549
|
+
return result;
|
1550
|
+
}
|
1551
|
+
// Returns the number of 8-bit data (i.e. not error correction) codewords contained in any
|
1552
|
+
// QR Code of the given version number and error correction level, with remainder bits discarded.
|
1553
|
+
// This stateless pure function could be implemented as a (40*4)-cell lookup table.
|
1554
|
+
static getNumDataCodewords(ver, ecl) {
|
1555
|
+
return Math.floor(_QrCode2.getNumRawDataModules(ver) / 8) - _QrCode2.ECC_CODEWORDS_PER_BLOCK[ecl.ordinal][ver] * _QrCode2.NUM_ERROR_CORRECTION_BLOCKS[ecl.ordinal][ver];
|
1556
|
+
}
|
1557
|
+
// Returns a Reed-Solomon ECC generator polynomial for the given degree. This could be
|
1558
|
+
// implemented as a lookup table over all possible parameter values, instead of as an algorithm.
|
1559
|
+
static reedSolomonComputeDivisor(degree) {
|
1560
|
+
if (degree < 1 || degree > 255)
|
1561
|
+
throw new RangeError("Degree out of range");
|
1562
|
+
let result = [];
|
1563
|
+
for (let i = 0; i < degree - 1; i++)
|
1564
|
+
result.push(0);
|
1565
|
+
result.push(1);
|
1566
|
+
let root = 1;
|
1567
|
+
for (let i = 0; i < degree; i++) {
|
1568
|
+
for (let j = 0; j < result.length; j++) {
|
1569
|
+
result[j] = _QrCode2.reedSolomonMultiply(result[j], root);
|
1570
|
+
if (j + 1 < result.length)
|
1571
|
+
result[j] ^= result[j + 1];
|
1572
|
+
}
|
1573
|
+
root = _QrCode2.reedSolomonMultiply(root, 2);
|
1574
|
+
}
|
1575
|
+
return result;
|
1576
|
+
}
|
1577
|
+
// Returns the Reed-Solomon error correction codeword for the given data and divisor polynomials.
|
1578
|
+
static reedSolomonComputeRemainder(data, divisor) {
|
1579
|
+
let result = divisor.map((_) => 0);
|
1580
|
+
for (const b of data) {
|
1581
|
+
const factor = b ^ result.shift();
|
1582
|
+
result.push(0);
|
1583
|
+
divisor.forEach((coef, i) => result[i] ^= _QrCode2.reedSolomonMultiply(coef, factor));
|
1584
|
+
}
|
1585
|
+
return result;
|
1586
|
+
}
|
1587
|
+
// Returns the product of the two given field elements modulo GF(2^8/0x11D). The arguments and result
|
1588
|
+
// are unsigned 8-bit integers. This could be implemented as a lookup table of 256*256 entries of uint8.
|
1589
|
+
static reedSolomonMultiply(x, y) {
|
1590
|
+
if (x >>> 8 != 0 || y >>> 8 != 0)
|
1591
|
+
throw new RangeError("Byte out of range");
|
1592
|
+
let z = 0;
|
1593
|
+
for (let i = 7; i >= 0; i--) {
|
1594
|
+
z = z << 1 ^ (z >>> 7) * 285;
|
1595
|
+
z ^= (y >>> i & 1) * x;
|
1596
|
+
}
|
1597
|
+
assert(z >>> 8 == 0);
|
1598
|
+
return z;
|
1599
|
+
}
|
1600
|
+
// Can only be called immediately after a light run is added, and
|
1601
|
+
// returns either 0, 1, or 2. A helper function for getPenaltyScore().
|
1602
|
+
finderPenaltyCountPatterns(runHistory) {
|
1603
|
+
const n = runHistory[1];
|
1604
|
+
assert(n <= this.size * 3);
|
1605
|
+
const core = n > 0 && runHistory[2] == n && runHistory[3] == n * 3 && runHistory[4] == n && runHistory[5] == n;
|
1606
|
+
return (core && runHistory[0] >= n * 4 && runHistory[6] >= n ? 1 : 0) + (core && runHistory[6] >= n * 4 && runHistory[0] >= n ? 1 : 0);
|
1607
|
+
}
|
1608
|
+
// Must be called at the end of a line (row or column) of modules. A helper function for getPenaltyScore().
|
1609
|
+
finderPenaltyTerminateAndCount(currentRunColor, currentRunLength, runHistory) {
|
1610
|
+
if (currentRunColor) {
|
1611
|
+
this.finderPenaltyAddHistory(currentRunLength, runHistory);
|
1612
|
+
currentRunLength = 0;
|
1613
|
+
}
|
1614
|
+
currentRunLength += this.size;
|
1615
|
+
this.finderPenaltyAddHistory(currentRunLength, runHistory);
|
1616
|
+
return this.finderPenaltyCountPatterns(runHistory);
|
1617
|
+
}
|
1618
|
+
// Pushes the given value to the front and drops the last value. A helper function for getPenaltyScore().
|
1619
|
+
finderPenaltyAddHistory(currentRunLength, runHistory) {
|
1620
|
+
if (runHistory[0] == 0)
|
1621
|
+
currentRunLength += this.size;
|
1622
|
+
runHistory.pop();
|
1623
|
+
runHistory.unshift(currentRunLength);
|
1624
|
+
}
|
1625
|
+
};
|
1626
|
+
_QrCode.MIN_VERSION = 1;
|
1627
|
+
_QrCode.MAX_VERSION = 40;
|
1628
|
+
_QrCode.PENALTY_N1 = 3;
|
1629
|
+
_QrCode.PENALTY_N2 = 3;
|
1630
|
+
_QrCode.PENALTY_N3 = 40;
|
1631
|
+
_QrCode.PENALTY_N4 = 10;
|
1632
|
+
_QrCode.ECC_CODEWORDS_PER_BLOCK = [
|
1633
|
+
// Version: (note that index 0 is for padding, and is set to an illegal value)
|
1634
|
+
//0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40 Error correction level
|
1635
|
+
[-1, 7, 10, 15, 20, 26, 18, 20, 24, 30, 18, 20, 24, 26, 30, 22, 24, 28, 30, 28, 28, 28, 28, 30, 30, 26, 28, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30],
|
1636
|
+
// Low
|
1637
|
+
[-1, 10, 16, 26, 18, 24, 16, 18, 22, 22, 26, 30, 22, 22, 24, 24, 28, 28, 26, 26, 26, 26, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28],
|
1638
|
+
// Medium
|
1639
|
+
[-1, 13, 22, 18, 26, 18, 24, 18, 22, 20, 24, 28, 26, 24, 20, 30, 24, 28, 28, 26, 30, 28, 30, 30, 30, 30, 28, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30],
|
1640
|
+
// Quartile
|
1641
|
+
[-1, 17, 28, 22, 16, 22, 28, 26, 26, 24, 28, 24, 28, 22, 24, 24, 30, 28, 28, 26, 28, 30, 24, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30]
|
1642
|
+
// High
|
1643
|
+
];
|
1644
|
+
_QrCode.NUM_ERROR_CORRECTION_BLOCKS = [
|
1645
|
+
// Version: (note that index 0 is for padding, and is set to an illegal value)
|
1646
|
+
//0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40 Error correction level
|
1647
|
+
[-1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 4, 4, 4, 4, 4, 6, 6, 6, 6, 7, 8, 8, 9, 9, 10, 12, 12, 12, 13, 14, 15, 16, 17, 18, 19, 19, 20, 21, 22, 24, 25],
|
1648
|
+
// Low
|
1649
|
+
[-1, 1, 1, 1, 2, 2, 4, 4, 4, 5, 5, 5, 8, 9, 9, 10, 10, 11, 13, 14, 16, 17, 17, 18, 20, 21, 23, 25, 26, 28, 29, 31, 33, 35, 37, 38, 40, 43, 45, 47, 49],
|
1650
|
+
// Medium
|
1651
|
+
[-1, 1, 1, 2, 2, 4, 4, 6, 6, 8, 8, 8, 10, 12, 16, 12, 17, 16, 18, 21, 20, 23, 23, 25, 27, 29, 34, 34, 35, 38, 40, 43, 45, 48, 51, 53, 56, 59, 62, 65, 68],
|
1652
|
+
// Quartile
|
1653
|
+
[-1, 1, 1, 2, 4, 4, 4, 5, 6, 8, 8, 11, 11, 16, 16, 18, 16, 19, 21, 25, 25, 25, 34, 30, 32, 35, 37, 40, 42, 45, 48, 51, 54, 57, 60, 63, 66, 70, 74, 77, 81]
|
1654
|
+
// High
|
1655
|
+
];
|
1656
|
+
qrcodegen2.QrCode = _QrCode;
|
1657
|
+
function appendBits(val, len, bb) {
|
1658
|
+
if (len < 0 || len > 31 || val >>> len != 0)
|
1659
|
+
throw new RangeError("Value out of range");
|
1660
|
+
for (let i = len - 1; i >= 0; i--)
|
1661
|
+
bb.push(val >>> i & 1);
|
1662
|
+
}
|
1663
|
+
function getBit(x, i) {
|
1664
|
+
return (x >>> i & 1) != 0;
|
1665
|
+
}
|
1666
|
+
function assert(cond) {
|
1667
|
+
if (!cond)
|
1668
|
+
throw new Error("Assertion error");
|
1669
|
+
}
|
1670
|
+
const _QrSegment = class _QrSegment2 {
|
1671
|
+
/*-- Constructor (low level) and fields --*/
|
1672
|
+
// Creates a new QR Code segment with the given attributes and data.
|
1673
|
+
// The character count (numChars) must agree with the mode and the bit buffer length,
|
1674
|
+
// but the constraint isn't checked. The given bit buffer is cloned and stored.
|
1675
|
+
constructor(mode, numChars, bitData) {
|
1676
|
+
this.mode = mode;
|
1677
|
+
this.numChars = numChars;
|
1678
|
+
this.bitData = bitData;
|
1679
|
+
if (numChars < 0)
|
1680
|
+
throw new RangeError("Invalid argument");
|
1681
|
+
this.bitData = bitData.slice();
|
1682
|
+
}
|
1683
|
+
/*-- Static factory functions (mid level) --*/
|
1684
|
+
// Returns a segment representing the given binary data encoded in
|
1685
|
+
// byte mode. All input byte arrays are acceptable. Any text string
|
1686
|
+
// can be converted to UTF-8 bytes and encoded as a byte mode segment.
|
1687
|
+
static makeBytes(data) {
|
1688
|
+
let bb = [];
|
1689
|
+
for (const b of data)
|
1690
|
+
appendBits(b, 8, bb);
|
1691
|
+
return new _QrSegment2(_QrSegment2.Mode.BYTE, data.length, bb);
|
1692
|
+
}
|
1693
|
+
// Returns a segment representing the given string of decimal digits encoded in numeric mode.
|
1694
|
+
static makeNumeric(digits) {
|
1695
|
+
if (!_QrSegment2.isNumeric(digits))
|
1696
|
+
throw new RangeError("String contains non-numeric characters");
|
1697
|
+
let bb = [];
|
1698
|
+
for (let i = 0; i < digits.length; ) {
|
1699
|
+
const n = Math.min(digits.length - i, 3);
|
1700
|
+
appendBits(parseInt(digits.substring(i, i + n), 10), n * 3 + 1, bb);
|
1701
|
+
i += n;
|
1702
|
+
}
|
1703
|
+
return new _QrSegment2(_QrSegment2.Mode.NUMERIC, digits.length, bb);
|
1704
|
+
}
|
1705
|
+
// Returns a segment representing the given text string encoded in alphanumeric mode.
|
1706
|
+
// The characters allowed are: 0 to 9, A to Z (uppercase only), space,
|
1707
|
+
// dollar, percent, asterisk, plus, hyphen, period, slash, colon.
|
1708
|
+
static makeAlphanumeric(text) {
|
1709
|
+
if (!_QrSegment2.isAlphanumeric(text))
|
1710
|
+
throw new RangeError("String contains unencodable characters in alphanumeric mode");
|
1711
|
+
let bb = [];
|
1712
|
+
let i;
|
1713
|
+
for (i = 0; i + 2 <= text.length; i += 2) {
|
1714
|
+
let temp = _QrSegment2.ALPHANUMERIC_CHARSET.indexOf(text.charAt(i)) * 45;
|
1715
|
+
temp += _QrSegment2.ALPHANUMERIC_CHARSET.indexOf(text.charAt(i + 1));
|
1716
|
+
appendBits(temp, 11, bb);
|
1717
|
+
}
|
1718
|
+
if (i < text.length)
|
1719
|
+
appendBits(_QrSegment2.ALPHANUMERIC_CHARSET.indexOf(text.charAt(i)), 6, bb);
|
1720
|
+
return new _QrSegment2(_QrSegment2.Mode.ALPHANUMERIC, text.length, bb);
|
1721
|
+
}
|
1722
|
+
// Returns a new mutable list of zero or more segments to represent the given Unicode text string.
|
1723
|
+
// The result may use various segment modes and switch modes to optimize the length of the bit stream.
|
1724
|
+
static makeSegments(text) {
|
1725
|
+
if (text == "")
|
1726
|
+
return [];
|
1727
|
+
else if (_QrSegment2.isNumeric(text))
|
1728
|
+
return [_QrSegment2.makeNumeric(text)];
|
1729
|
+
else if (_QrSegment2.isAlphanumeric(text))
|
1730
|
+
return [_QrSegment2.makeAlphanumeric(text)];
|
1731
|
+
else
|
1732
|
+
return [_QrSegment2.makeBytes(_QrSegment2.toUtf8ByteArray(text))];
|
1733
|
+
}
|
1734
|
+
// Returns a segment representing an Extended Channel Interpretation
|
1735
|
+
// (ECI) designator with the given assignment value.
|
1736
|
+
static makeEci(assignVal) {
|
1737
|
+
let bb = [];
|
1738
|
+
if (assignVal < 0)
|
1739
|
+
throw new RangeError("ECI assignment value out of range");
|
1740
|
+
else if (assignVal < 1 << 7)
|
1741
|
+
appendBits(assignVal, 8, bb);
|
1742
|
+
else if (assignVal < 1 << 14) {
|
1743
|
+
appendBits(2, 2, bb);
|
1744
|
+
appendBits(assignVal, 14, bb);
|
1745
|
+
} else if (assignVal < 1e6) {
|
1746
|
+
appendBits(6, 3, bb);
|
1747
|
+
appendBits(assignVal, 21, bb);
|
1748
|
+
} else
|
1749
|
+
throw new RangeError("ECI assignment value out of range");
|
1750
|
+
return new _QrSegment2(_QrSegment2.Mode.ECI, 0, bb);
|
1751
|
+
}
|
1752
|
+
// Tests whether the given string can be encoded as a segment in numeric mode.
|
1753
|
+
// A string is encodable iff each character is in the range 0 to 9.
|
1754
|
+
static isNumeric(text) {
|
1755
|
+
return _QrSegment2.NUMERIC_REGEX.test(text);
|
1756
|
+
}
|
1757
|
+
// Tests whether the given string can be encoded as a segment in alphanumeric mode.
|
1758
|
+
// A string is encodable iff each character is in the following set: 0 to 9, A to Z
|
1759
|
+
// (uppercase only), space, dollar, percent, asterisk, plus, hyphen, period, slash, colon.
|
1760
|
+
static isAlphanumeric(text) {
|
1761
|
+
return _QrSegment2.ALPHANUMERIC_REGEX.test(text);
|
1762
|
+
}
|
1763
|
+
/*-- Methods --*/
|
1764
|
+
// Returns a new copy of the data bits of this segment.
|
1765
|
+
getData() {
|
1766
|
+
return this.bitData.slice();
|
1767
|
+
}
|
1768
|
+
// (Package-private) Calculates and returns the number of bits needed to encode the given segments at
|
1769
|
+
// the given version. The result is infinity if a segment has too many characters to fit its length field.
|
1770
|
+
static getTotalBits(segs, version) {
|
1771
|
+
let result = 0;
|
1772
|
+
for (const seg of segs) {
|
1773
|
+
const ccbits = seg.mode.numCharCountBits(version);
|
1774
|
+
if (seg.numChars >= 1 << ccbits)
|
1775
|
+
return Infinity;
|
1776
|
+
result += 4 + ccbits + seg.bitData.length;
|
1777
|
+
}
|
1778
|
+
return result;
|
1779
|
+
}
|
1780
|
+
// Returns a new array of bytes representing the given string encoded in UTF-8.
|
1781
|
+
static toUtf8ByteArray(str) {
|
1782
|
+
str = encodeURI(str);
|
1783
|
+
let result = [];
|
1784
|
+
for (let i = 0; i < str.length; i++) {
|
1785
|
+
if (str.charAt(i) != "%")
|
1786
|
+
result.push(str.charCodeAt(i));
|
1787
|
+
else {
|
1788
|
+
result.push(parseInt(str.substring(i + 1, i + 3), 16));
|
1789
|
+
i += 2;
|
1790
|
+
}
|
1791
|
+
}
|
1792
|
+
return result;
|
1793
|
+
}
|
1794
|
+
};
|
1795
|
+
_QrSegment.NUMERIC_REGEX = /^[0-9]*$/;
|
1796
|
+
_QrSegment.ALPHANUMERIC_REGEX = /^[A-Z0-9 $%*+.\/:-]*$/;
|
1797
|
+
_QrSegment.ALPHANUMERIC_CHARSET = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:";
|
1798
|
+
let QrSegment = _QrSegment;
|
1799
|
+
qrcodegen2.QrSegment = _QrSegment;
|
1800
|
+
})(qrcodegen || (qrcodegen = {}));
|
1801
|
+
((qrcodegen2) => {
|
1802
|
+
((QrCode2) => {
|
1803
|
+
const _Ecc = class _Ecc {
|
1804
|
+
// The QR Code can tolerate about 30% erroneous codewords
|
1805
|
+
/*-- Constructor and fields --*/
|
1806
|
+
constructor(ordinal, formatBits) {
|
1807
|
+
this.ordinal = ordinal;
|
1808
|
+
this.formatBits = formatBits;
|
1809
|
+
}
|
1810
|
+
};
|
1811
|
+
_Ecc.LOW = new _Ecc(0, 1);
|
1812
|
+
_Ecc.MEDIUM = new _Ecc(1, 0);
|
1813
|
+
_Ecc.QUARTILE = new _Ecc(2, 3);
|
1814
|
+
_Ecc.HIGH = new _Ecc(3, 2);
|
1815
|
+
QrCode2.Ecc = _Ecc;
|
1816
|
+
})(qrcodegen2.QrCode || (qrcodegen2.QrCode = {}));
|
1817
|
+
})(qrcodegen || (qrcodegen = {}));
|
1818
|
+
((qrcodegen2) => {
|
1819
|
+
((QrSegment2) => {
|
1820
|
+
const _Mode = class _Mode {
|
1821
|
+
/*-- Constructor and fields --*/
|
1822
|
+
constructor(modeBits, numBitsCharCount) {
|
1823
|
+
this.modeBits = modeBits;
|
1824
|
+
this.numBitsCharCount = numBitsCharCount;
|
1825
|
+
}
|
1826
|
+
/*-- Method --*/
|
1827
|
+
// (Package-private) Returns the bit width of the character count field for a segment in
|
1828
|
+
// this mode in a QR Code at the given version number. The result is in the range [0, 16].
|
1829
|
+
numCharCountBits(ver) {
|
1830
|
+
return this.numBitsCharCount[Math.floor((ver + 7) / 17)];
|
1831
|
+
}
|
1832
|
+
};
|
1833
|
+
_Mode.NUMERIC = new _Mode(1, [10, 12, 14]);
|
1834
|
+
_Mode.ALPHANUMERIC = new _Mode(2, [9, 11, 13]);
|
1835
|
+
_Mode.BYTE = new _Mode(4, [8, 16, 16]);
|
1836
|
+
_Mode.KANJI = new _Mode(8, [8, 10, 12]);
|
1837
|
+
_Mode.ECI = new _Mode(7, [0, 0, 0]);
|
1838
|
+
QrSegment2.Mode = _Mode;
|
1839
|
+
})(qrcodegen2.QrSegment || (qrcodegen2.QrSegment = {}));
|
1840
|
+
})(qrcodegen || (qrcodegen = {}));
|
1841
|
+
var qrcodegen_default = qrcodegen;
|
1842
|
+
/**
|
1843
|
+
* @license qrcode.react
|
1844
|
+
* Copyright (c) Paul O'Shannessy
|
1845
|
+
* SPDX-License-Identifier: ISC
|
1846
|
+
*/
|
1847
|
+
var ERROR_LEVEL_MAP = {
|
1848
|
+
L: qrcodegen_default.QrCode.Ecc.LOW,
|
1849
|
+
M: qrcodegen_default.QrCode.Ecc.MEDIUM,
|
1850
|
+
Q: qrcodegen_default.QrCode.Ecc.QUARTILE,
|
1851
|
+
H: qrcodegen_default.QrCode.Ecc.HIGH
|
1852
|
+
};
|
1853
|
+
var DEFAULT_SIZE = 128;
|
1854
|
+
var DEFAULT_LEVEL = "L";
|
1855
|
+
var DEFAULT_BGCOLOR = "#FFFFFF";
|
1856
|
+
var DEFAULT_FGCOLOR = "#000000";
|
1857
|
+
var DEFAULT_INCLUDEMARGIN = false;
|
1858
|
+
var DEFAULT_MINVERSION = 1;
|
1859
|
+
var SPEC_MARGIN_SIZE = 4;
|
1860
|
+
var DEFAULT_MARGIN_SIZE = 0;
|
1861
|
+
var DEFAULT_IMG_SCALE = 0.1;
|
1862
|
+
function generatePath(modules, margin = 0) {
|
1863
|
+
const ops = [];
|
1864
|
+
modules.forEach(function(row, y) {
|
1865
|
+
let start = null;
|
1866
|
+
row.forEach(function(cell, x) {
|
1867
|
+
if (!cell && start !== null) {
|
1868
|
+
ops.push(
|
1869
|
+
`M${start + margin} ${y + margin}h${x - start}v1H${start + margin}z`
|
1870
|
+
);
|
1871
|
+
start = null;
|
1872
|
+
return;
|
1873
|
+
}
|
1874
|
+
if (x === row.length - 1) {
|
1875
|
+
if (!cell) {
|
1876
|
+
return;
|
1877
|
+
}
|
1878
|
+
if (start === null) {
|
1879
|
+
ops.push(`M${x + margin},${y + margin} h1v1H${x + margin}z`);
|
1880
|
+
} else {
|
1881
|
+
ops.push(
|
1882
|
+
`M${start + margin},${y + margin} h${x + 1 - start}v1H${start + margin}z`
|
1883
|
+
);
|
1884
|
+
}
|
1885
|
+
return;
|
1886
|
+
}
|
1887
|
+
if (cell && start === null) {
|
1888
|
+
start = x;
|
1889
|
+
}
|
1890
|
+
});
|
1891
|
+
});
|
1892
|
+
return ops.join("");
|
1893
|
+
}
|
1894
|
+
function excavateModules(modules, excavation) {
|
1895
|
+
return modules.slice().map((row, y) => {
|
1896
|
+
if (y < excavation.y || y >= excavation.y + excavation.h) {
|
1897
|
+
return row;
|
1898
|
+
}
|
1899
|
+
return row.map((cell, x) => {
|
1900
|
+
if (x < excavation.x || x >= excavation.x + excavation.w) {
|
1901
|
+
return cell;
|
1902
|
+
}
|
1903
|
+
return false;
|
1904
|
+
});
|
1905
|
+
});
|
1906
|
+
}
|
1907
|
+
function getImageSettings(cells, size, margin, imageSettings) {
|
1908
|
+
if (imageSettings == null) {
|
1909
|
+
return null;
|
1910
|
+
}
|
1911
|
+
const numCells = cells.length + margin * 2;
|
1912
|
+
const defaultSize = Math.floor(size * DEFAULT_IMG_SCALE);
|
1913
|
+
const scale = numCells / size;
|
1914
|
+
const w = (imageSettings.width || defaultSize) * scale;
|
1915
|
+
const h = (imageSettings.height || defaultSize) * scale;
|
1916
|
+
const x = imageSettings.x == null ? cells.length / 2 - w / 2 : imageSettings.x * scale;
|
1917
|
+
const y = imageSettings.y == null ? cells.length / 2 - h / 2 : imageSettings.y * scale;
|
1918
|
+
const opacity = imageSettings.opacity == null ? 1 : imageSettings.opacity;
|
1919
|
+
let excavation = null;
|
1920
|
+
if (imageSettings.excavate) {
|
1921
|
+
let floorX = Math.floor(x);
|
1922
|
+
let floorY = Math.floor(y);
|
1923
|
+
let ceilW = Math.ceil(w + x - floorX);
|
1924
|
+
let ceilH = Math.ceil(h + y - floorY);
|
1925
|
+
excavation = { x: floorX, y: floorY, w: ceilW, h: ceilH };
|
1926
|
+
}
|
1927
|
+
const crossOrigin = imageSettings.crossOrigin;
|
1928
|
+
return { x, y, h, w, excavation, opacity, crossOrigin };
|
1929
|
+
}
|
1930
|
+
function getMarginSize(includeMargin, marginSize) {
|
1931
|
+
if (marginSize != null) {
|
1932
|
+
return Math.max(Math.floor(marginSize), 0);
|
1933
|
+
}
|
1934
|
+
return includeMargin ? SPEC_MARGIN_SIZE : DEFAULT_MARGIN_SIZE;
|
1935
|
+
}
|
1936
|
+
function useQRCode({
|
1937
|
+
value,
|
1938
|
+
level,
|
1939
|
+
minVersion,
|
1940
|
+
includeMargin,
|
1941
|
+
marginSize,
|
1942
|
+
imageSettings,
|
1943
|
+
size,
|
1944
|
+
boostLevel
|
1945
|
+
}) {
|
1946
|
+
let qrcode = React.useMemo(() => {
|
1947
|
+
const values = Array.isArray(value) ? value : [value];
|
1948
|
+
const segments = values.reduce((accum, v) => {
|
1949
|
+
accum.push(...qrcodegen_default.QrSegment.makeSegments(v));
|
1950
|
+
return accum;
|
1951
|
+
}, []);
|
1952
|
+
return qrcodegen_default.QrCode.encodeSegments(
|
1953
|
+
segments,
|
1954
|
+
ERROR_LEVEL_MAP[level],
|
1955
|
+
minVersion,
|
1956
|
+
void 0,
|
1957
|
+
void 0,
|
1958
|
+
boostLevel
|
1959
|
+
);
|
1960
|
+
}, [value, level, minVersion, boostLevel]);
|
1961
|
+
const { cells, margin, numCells, calculatedImageSettings } = React.useMemo(() => {
|
1962
|
+
let cells2 = qrcode.getModules();
|
1963
|
+
const margin2 = getMarginSize(includeMargin, marginSize);
|
1964
|
+
const numCells2 = cells2.length + margin2 * 2;
|
1965
|
+
const calculatedImageSettings2 = getImageSettings(
|
1966
|
+
cells2,
|
1967
|
+
size,
|
1968
|
+
margin2,
|
1969
|
+
imageSettings
|
1970
|
+
);
|
1971
|
+
return {
|
1972
|
+
cells: cells2,
|
1973
|
+
margin: margin2,
|
1974
|
+
numCells: numCells2,
|
1975
|
+
calculatedImageSettings: calculatedImageSettings2
|
1976
|
+
};
|
1977
|
+
}, [qrcode, size, imageSettings, includeMargin, marginSize]);
|
1978
|
+
return {
|
1979
|
+
qrcode,
|
1980
|
+
margin,
|
1981
|
+
cells,
|
1982
|
+
numCells,
|
1983
|
+
calculatedImageSettings
|
1984
|
+
};
|
1985
|
+
}
|
1986
|
+
var SUPPORTS_PATH2D = function() {
|
1987
|
+
try {
|
1988
|
+
new Path2D().addPath(new Path2D());
|
1989
|
+
} catch (e) {
|
1990
|
+
return false;
|
1991
|
+
}
|
1992
|
+
return true;
|
1993
|
+
}();
|
1994
|
+
var QRCodeCanvas = React.forwardRef(
|
1995
|
+
function QRCodeCanvas2(props, forwardedRef) {
|
1996
|
+
const _a = props, {
|
1997
|
+
value,
|
1998
|
+
size = DEFAULT_SIZE,
|
1999
|
+
level = DEFAULT_LEVEL,
|
2000
|
+
bgColor = DEFAULT_BGCOLOR,
|
2001
|
+
fgColor = DEFAULT_FGCOLOR,
|
2002
|
+
includeMargin = DEFAULT_INCLUDEMARGIN,
|
2003
|
+
minVersion = DEFAULT_MINVERSION,
|
2004
|
+
boostLevel,
|
2005
|
+
marginSize,
|
2006
|
+
imageSettings
|
2007
|
+
} = _a, extraProps = __objRest(_a, [
|
2008
|
+
"value",
|
2009
|
+
"size",
|
2010
|
+
"level",
|
2011
|
+
"bgColor",
|
2012
|
+
"fgColor",
|
2013
|
+
"includeMargin",
|
2014
|
+
"minVersion",
|
2015
|
+
"boostLevel",
|
2016
|
+
"marginSize",
|
2017
|
+
"imageSettings"
|
2018
|
+
]);
|
2019
|
+
const _b = extraProps, { style } = _b, otherProps = __objRest(_b, ["style"]);
|
2020
|
+
const imgSrc = imageSettings == null ? void 0 : imageSettings.src;
|
2021
|
+
const _canvas = React.useRef(null);
|
2022
|
+
const _image = React.useRef(null);
|
2023
|
+
const setCanvasRef = React.useCallback(
|
2024
|
+
(node) => {
|
2025
|
+
_canvas.current = node;
|
2026
|
+
if (typeof forwardedRef === "function") {
|
2027
|
+
forwardedRef(node);
|
2028
|
+
} else if (forwardedRef) {
|
2029
|
+
forwardedRef.current = node;
|
2030
|
+
}
|
2031
|
+
},
|
2032
|
+
[forwardedRef]
|
2033
|
+
);
|
2034
|
+
const [isImgLoaded, setIsImageLoaded] = React.useState(false);
|
2035
|
+
const { margin, cells, numCells, calculatedImageSettings } = useQRCode({
|
2036
|
+
value,
|
2037
|
+
level,
|
2038
|
+
minVersion,
|
2039
|
+
boostLevel,
|
2040
|
+
includeMargin,
|
2041
|
+
marginSize,
|
2042
|
+
imageSettings,
|
2043
|
+
size
|
2044
|
+
});
|
2045
|
+
React.useEffect(() => {
|
2046
|
+
if (_canvas.current != null) {
|
2047
|
+
const canvas = _canvas.current;
|
2048
|
+
const ctx = canvas.getContext("2d");
|
2049
|
+
if (!ctx) {
|
2050
|
+
return;
|
2051
|
+
}
|
2052
|
+
let cellsToDraw = cells;
|
2053
|
+
const image = _image.current;
|
2054
|
+
const haveImageToRender = calculatedImageSettings != null && image !== null && image.complete && image.naturalHeight !== 0 && image.naturalWidth !== 0;
|
2055
|
+
if (haveImageToRender) {
|
2056
|
+
if (calculatedImageSettings.excavation != null) {
|
2057
|
+
cellsToDraw = excavateModules(
|
2058
|
+
cells,
|
2059
|
+
calculatedImageSettings.excavation
|
2060
|
+
);
|
2061
|
+
}
|
2062
|
+
}
|
2063
|
+
const pixelRatio = window.devicePixelRatio || 1;
|
2064
|
+
canvas.height = canvas.width = size * pixelRatio;
|
2065
|
+
const scale = size / numCells * pixelRatio;
|
2066
|
+
ctx.scale(scale, scale);
|
2067
|
+
ctx.fillStyle = bgColor;
|
2068
|
+
ctx.fillRect(0, 0, numCells, numCells);
|
2069
|
+
ctx.fillStyle = fgColor;
|
2070
|
+
if (SUPPORTS_PATH2D) {
|
2071
|
+
ctx.fill(new Path2D(generatePath(cellsToDraw, margin)));
|
2072
|
+
} else {
|
2073
|
+
cells.forEach(function(row, rdx) {
|
2074
|
+
row.forEach(function(cell, cdx) {
|
2075
|
+
if (cell) {
|
2076
|
+
ctx.fillRect(cdx + margin, rdx + margin, 1, 1);
|
2077
|
+
}
|
2078
|
+
});
|
2079
|
+
});
|
2080
|
+
}
|
2081
|
+
if (calculatedImageSettings) {
|
2082
|
+
ctx.globalAlpha = calculatedImageSettings.opacity;
|
2083
|
+
}
|
2084
|
+
if (haveImageToRender) {
|
2085
|
+
ctx.drawImage(
|
2086
|
+
image,
|
2087
|
+
calculatedImageSettings.x + margin,
|
2088
|
+
calculatedImageSettings.y + margin,
|
2089
|
+
calculatedImageSettings.w,
|
2090
|
+
calculatedImageSettings.h
|
2091
|
+
);
|
2092
|
+
}
|
2093
|
+
}
|
2094
|
+
});
|
2095
|
+
React.useEffect(() => {
|
2096
|
+
setIsImageLoaded(false);
|
2097
|
+
}, [imgSrc]);
|
2098
|
+
const canvasStyle = __spreadValues({ height: size, width: size }, style);
|
2099
|
+
let img = null;
|
2100
|
+
if (imgSrc != null) {
|
2101
|
+
img = /* @__PURE__ */ React.createElement(
|
2102
|
+
"img",
|
2103
|
+
{
|
2104
|
+
src: imgSrc,
|
2105
|
+
key: imgSrc,
|
2106
|
+
style: { display: "none" },
|
2107
|
+
onLoad: () => {
|
2108
|
+
setIsImageLoaded(true);
|
2109
|
+
},
|
2110
|
+
ref: _image,
|
2111
|
+
crossOrigin: calculatedImageSettings == null ? void 0 : calculatedImageSettings.crossOrigin
|
2112
|
+
}
|
2113
|
+
);
|
2114
|
+
}
|
2115
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(
|
2116
|
+
"canvas",
|
2117
|
+
__spreadValues({
|
2118
|
+
style: canvasStyle,
|
2119
|
+
height: size,
|
2120
|
+
width: size,
|
2121
|
+
ref: setCanvasRef,
|
2122
|
+
role: "img"
|
2123
|
+
}, otherProps)
|
2124
|
+
), img);
|
2125
|
+
}
|
2126
|
+
);
|
2127
|
+
QRCodeCanvas.displayName = "QRCodeCanvas";
|
2128
|
+
var QRCodeSVG = React.forwardRef(
|
2129
|
+
function QRCodeSVG2(props, forwardedRef) {
|
2130
|
+
const _a = props, {
|
2131
|
+
value,
|
2132
|
+
size = DEFAULT_SIZE,
|
2133
|
+
level = DEFAULT_LEVEL,
|
2134
|
+
bgColor = DEFAULT_BGCOLOR,
|
2135
|
+
fgColor = DEFAULT_FGCOLOR,
|
2136
|
+
includeMargin = DEFAULT_INCLUDEMARGIN,
|
2137
|
+
minVersion = DEFAULT_MINVERSION,
|
2138
|
+
boostLevel,
|
2139
|
+
title,
|
2140
|
+
marginSize,
|
2141
|
+
imageSettings
|
2142
|
+
} = _a, otherProps = __objRest(_a, [
|
2143
|
+
"value",
|
2144
|
+
"size",
|
2145
|
+
"level",
|
2146
|
+
"bgColor",
|
2147
|
+
"fgColor",
|
2148
|
+
"includeMargin",
|
2149
|
+
"minVersion",
|
2150
|
+
"boostLevel",
|
2151
|
+
"title",
|
2152
|
+
"marginSize",
|
2153
|
+
"imageSettings"
|
2154
|
+
]);
|
2155
|
+
const { margin, cells, numCells, calculatedImageSettings } = useQRCode({
|
2156
|
+
value,
|
2157
|
+
level,
|
2158
|
+
minVersion,
|
2159
|
+
boostLevel,
|
2160
|
+
includeMargin,
|
2161
|
+
marginSize,
|
2162
|
+
imageSettings,
|
2163
|
+
size
|
2164
|
+
});
|
2165
|
+
let cellsToDraw = cells;
|
2166
|
+
let image = null;
|
2167
|
+
if (imageSettings != null && calculatedImageSettings != null) {
|
2168
|
+
if (calculatedImageSettings.excavation != null) {
|
2169
|
+
cellsToDraw = excavateModules(
|
2170
|
+
cells,
|
2171
|
+
calculatedImageSettings.excavation
|
2172
|
+
);
|
2173
|
+
}
|
2174
|
+
image = /* @__PURE__ */ React.createElement(
|
2175
|
+
"image",
|
2176
|
+
{
|
2177
|
+
href: imageSettings.src,
|
2178
|
+
height: calculatedImageSettings.h,
|
2179
|
+
width: calculatedImageSettings.w,
|
2180
|
+
x: calculatedImageSettings.x + margin,
|
2181
|
+
y: calculatedImageSettings.y + margin,
|
2182
|
+
preserveAspectRatio: "none",
|
2183
|
+
opacity: calculatedImageSettings.opacity,
|
2184
|
+
crossOrigin: calculatedImageSettings.crossOrigin
|
2185
|
+
}
|
2186
|
+
);
|
2187
|
+
}
|
2188
|
+
const fgPath = generatePath(cellsToDraw, margin);
|
2189
|
+
return /* @__PURE__ */ React.createElement(
|
2190
|
+
"svg",
|
2191
|
+
__spreadValues({
|
2192
|
+
height: size,
|
2193
|
+
width: size,
|
2194
|
+
viewBox: `0 0 ${numCells} ${numCells}`,
|
2195
|
+
ref: forwardedRef,
|
2196
|
+
role: "img"
|
2197
|
+
}, otherProps),
|
2198
|
+
!!title && /* @__PURE__ */ React.createElement("title", null, title),
|
2199
|
+
/* @__PURE__ */ React.createElement(
|
2200
|
+
"path",
|
2201
|
+
{
|
2202
|
+
fill: bgColor,
|
2203
|
+
d: `M0,0 h${numCells}v${numCells}H0z`,
|
2204
|
+
shapeRendering: "crispEdges"
|
2205
|
+
}
|
2206
|
+
),
|
2207
|
+
/* @__PURE__ */ React.createElement("path", { fill: fgColor, d: fgPath, shapeRendering: "crispEdges" }),
|
2208
|
+
image
|
2209
|
+
);
|
2210
|
+
}
|
2211
|
+
);
|
2212
|
+
QRCodeSVG.displayName = "QRCodeSVG";
|
2213
|
+
const QRCode = ({
|
2214
|
+
walletAddress,
|
2215
|
+
amount,
|
2216
|
+
currency,
|
2217
|
+
theme = "light",
|
2218
|
+
size = 200
|
2219
|
+
}) => {
|
2220
|
+
const getQRCodeData = () => {
|
2221
|
+
if (!walletAddress)
|
2222
|
+
return "";
|
2223
|
+
const schemes = {
|
2224
|
+
"USDT": "ethereum",
|
2225
|
+
"USDC": "ethereum",
|
2226
|
+
"BNB": "binance",
|
2227
|
+
"SOL": "solana",
|
2228
|
+
"USDC_SOL": "solana"
|
2229
|
+
};
|
2230
|
+
const scheme = schemes[currency] || "ethereum";
|
2231
|
+
return `${scheme}:${walletAddress}?amount=${amount}¤cy=${currency}`;
|
2232
|
+
};
|
2233
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex flex-col items-center", children: [
|
2234
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: `p-4 rounded-lg ${theme === "dark" ? "bg-gray-700" : "bg-white"} mb-3`, children: /* @__PURE__ */ jsxRuntimeExports.jsx(
|
2235
|
+
QRCodeSVG,
|
2236
|
+
{
|
2237
|
+
value: getQRCodeData(),
|
2238
|
+
size,
|
2239
|
+
bgColor: theme === "dark" ? "#374151" : "#ffffff",
|
2240
|
+
fgColor: theme === "dark" ? "#ffffff" : "#000000",
|
2241
|
+
level: "M",
|
2242
|
+
includeMargin: true
|
2243
|
+
}
|
2244
|
+
) }),
|
2245
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: `text-center text-sm ${theme === "dark" ? "text-gray-300" : "text-gray-700"}`, children: "Scan with your wallet app to pay" }),
|
2246
|
+
walletAddress && /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "mt-3 w-full", children: [
|
2247
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("p", { className: `text-xs ${theme === "dark" ? "text-gray-400" : "text-gray-500"} mb-1`, children: [
|
2248
|
+
"Send ",
|
2249
|
+
amount,
|
2250
|
+
" ",
|
2251
|
+
currency,
|
2252
|
+
" to:"
|
2253
|
+
] }),
|
2254
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: `text-xs font-mono p-2 rounded overflow-auto break-all ${theme === "dark" ? "bg-gray-800 text-gray-300" : "bg-gray-100 text-gray-700"}`, children: walletAddress })
|
2255
|
+
] }),
|
2256
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "mt-4 w-full", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: `p-3 rounded ${theme === "dark" ? "bg-gray-700" : "bg-gray-100"}`, children: [
|
2257
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("h4", { className: `text-sm font-medium mb-2 ${theme === "dark" ? "text-white" : "text-gray-800"}`, children: "Payment Instructions" }),
|
2258
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("ol", { className: `text-xs space-y-2 ${theme === "dark" ? "text-gray-300" : "text-gray-600"}`, children: [
|
2259
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: "1. Open your crypto wallet app" }),
|
2260
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: "2. Scan the QR code above" }),
|
2261
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("li", { children: [
|
2262
|
+
"3. Confirm the payment amount (",
|
2263
|
+
amount,
|
2264
|
+
" ",
|
2265
|
+
currency,
|
2266
|
+
")"
|
2267
|
+
] }),
|
2268
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: '4. Click "Pay Now" button below after sending the payment' })
|
2269
|
+
] })
|
2270
|
+
] }) })
|
2271
|
+
] });
|
2272
|
+
};
|
2273
|
+
const PaymentStatus = ({ status, message, theme = "light" }) => {
|
1202
2274
|
const renderIcon = () => {
|
1203
2275
|
switch (status) {
|
1204
2276
|
case "processing":
|
@@ -1331,155 +2403,23 @@ const PaymentMethods = ({ onSelect, selected, theme = "light" }) => {
|
|
1331
2403
|
)) })
|
1332
2404
|
] });
|
1333
2405
|
};
|
1334
|
-
const
|
1335
|
-
|
1336
|
-
|
1337
|
-
|
1338
|
-
|
1339
|
-
|
1340
|
-
|
1341
|
-
|
1342
|
-
|
1343
|
-
|
1344
|
-
|
1345
|
-
|
1346
|
-
|
1347
|
-
|
1348
|
-
|
1349
|
-
|
1350
|
-
|
1351
|
-
throw new Error("MetaMask is not installed");
|
1352
|
-
}
|
1353
|
-
try {
|
1354
|
-
const accounts = await window.ethereum.request({ method: "eth_accounts" });
|
1355
|
-
return accounts;
|
1356
|
-
} catch (error) {
|
1357
|
-
console.error("Error getting accounts:", error);
|
1358
|
-
throw error;
|
1359
|
-
}
|
1360
|
-
};
|
1361
|
-
const getChainId = async () => {
|
1362
|
-
if (!isMetaMaskInstalled()) {
|
1363
|
-
throw new Error("MetaMask is not installed");
|
1364
|
-
}
|
1365
|
-
try {
|
1366
|
-
const chainId = await window.ethereum.request({ method: "eth_chainId" });
|
1367
|
-
return chainId;
|
1368
|
-
} catch (error) {
|
1369
|
-
console.error("Error getting chain ID:", error);
|
1370
|
-
throw error;
|
1371
|
-
}
|
1372
|
-
};
|
1373
|
-
const sendTransaction = async (txParams) => {
|
1374
|
-
if (!isMetaMaskInstalled()) {
|
1375
|
-
throw new Error("MetaMask is not installed");
|
1376
|
-
}
|
1377
|
-
try {
|
1378
|
-
const txHash = await window.ethereum.request({
|
1379
|
-
method: "eth_sendTransaction",
|
1380
|
-
params: [txParams]
|
1381
|
-
});
|
1382
|
-
return txHash;
|
1383
|
-
} catch (error) {
|
1384
|
-
console.error("Error sending transaction:", error);
|
1385
|
-
throw error;
|
1386
|
-
}
|
1387
|
-
};
|
1388
|
-
const sendToken = async (tokenAddress, toAddress, amount) => {
|
1389
|
-
if (!isMetaMaskInstalled()) {
|
1390
|
-
throw new Error("MetaMask is not installed");
|
1391
|
-
}
|
1392
|
-
try {
|
1393
|
-
const accounts = await window.ethereum.request({ method: "eth_requestAccounts" });
|
1394
|
-
const fromAddress = accounts[0];
|
1395
|
-
const transferFunctionSignature = "0xa9059cbb";
|
1396
|
-
const paddedToAddress = toAddress.slice(2).padStart(64, "0");
|
1397
|
-
const paddedAmount = amount.toString(16).padStart(64, "0");
|
1398
|
-
const data = `${transferFunctionSignature}${paddedToAddress}${paddedAmount}`;
|
1399
|
-
const txParams = {
|
1400
|
-
from: fromAddress,
|
1401
|
-
to: tokenAddress,
|
1402
|
-
data
|
1403
|
-
};
|
1404
|
-
const txHash = await window.ethereum.request({
|
1405
|
-
method: "eth_sendTransaction",
|
1406
|
-
params: [txParams]
|
1407
|
-
});
|
1408
|
-
return txHash;
|
1409
|
-
} catch (error) {
|
1410
|
-
console.error("Error sending token:", error);
|
1411
|
-
throw error;
|
1412
|
-
}
|
1413
|
-
};
|
1414
|
-
const isWalletConnected = async () => {
|
1415
|
-
try {
|
1416
|
-
const accounts = await getAccounts();
|
1417
|
-
return accounts.length > 0;
|
1418
|
-
} catch (error) {
|
1419
|
-
return false;
|
1420
|
-
}
|
1421
|
-
};
|
1422
|
-
const getNetworkName = (chainId) => {
|
1423
|
-
const networks = {
|
1424
|
-
"0x1": "Ethereum Mainnet",
|
1425
|
-
"0x3": "Ropsten Testnet",
|
1426
|
-
"0x4": "Rinkeby Testnet",
|
1427
|
-
"0x5": "Goerli Testnet",
|
1428
|
-
"0x2a": "Kovan Testnet",
|
1429
|
-
"0x38": "Binance Smart Chain",
|
1430
|
-
"0x89": "Polygon",
|
1431
|
-
"0xa86a": "Avalanche"
|
1432
|
-
};
|
1433
|
-
return networks[chainId] || `Unknown Network (${chainId})`;
|
1434
|
-
};
|
1435
|
-
const getTokenBalance = async (tokenAddress, userAddress) => {
|
1436
|
-
if (!isMetaMaskInstalled()) {
|
1437
|
-
throw new Error("MetaMask is not installed");
|
1438
|
-
}
|
1439
|
-
try {
|
1440
|
-
const balanceOfSignature = "0x70a08231";
|
1441
|
-
const paddedAddress = userAddress.slice(2).padStart(64, "0");
|
1442
|
-
const data = `${balanceOfSignature}${paddedAddress}`;
|
1443
|
-
const balance = await window.ethereum.request({
|
1444
|
-
method: "eth_call",
|
1445
|
-
params: [
|
1446
|
-
{
|
1447
|
-
to: tokenAddress,
|
1448
|
-
data
|
1449
|
-
},
|
1450
|
-
"latest"
|
1451
|
-
]
|
1452
|
-
});
|
1453
|
-
return parseInt(balance, 16).toString();
|
1454
|
-
} catch (error) {
|
1455
|
-
console.error("Error getting token balance:", error);
|
1456
|
-
throw error;
|
1457
|
-
}
|
1458
|
-
};
|
1459
|
-
const TOKEN_ADDRESSES = {
|
1460
|
-
USDT: "0xdAC17F958D2ee523a2206206994597C13D831ec7",
|
1461
|
-
USDC: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
|
1462
|
-
DAI: "0x6B175474E89094C44Da98b954EedeAC495271d0F",
|
1463
|
-
WETH: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
1464
|
-
WBTC: "0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599"
|
1465
|
-
};
|
1466
|
-
const Logo = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAHgAAAAcCAYAAACqAXueAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAiaSURBVHgB7VrdddNIFL4zNuDAw2orQDQATgUoUABQAU4FOGcLiF0BpoI4FcQ0QLQVxAHOvqLtwDyQOBBr9rszI2n058jeBEhOvnNkS6M7o7m6c39HRA3Qf/bxLR+l9uDIR/sXHD26trjTJeoMiO6/pEuCEBuHOBQfZuxfB9mQjpnv958d9/O9W2/w6+N4StcSHV+INoQhdoVQB7ju0Q1DUwFbiN1Cw6Wt+l+EHg4vu5TXdKHWIydgmFyv//xjWWhCzOyZB5pA0xo63zSrf0vjQNvZhNPvjTB/Gf9NNwx5DZZyQIoOSn5VOYxLaRaAUkHaFotpcgqhdmG6j7Aq4LNbXfqtMQ+VUts4xkrRDq7HdMOQF3BMkT3zcez1n30yJjmOJymNsv5WyCdZx0XIvzvB59cQ7qHur1SUtP/eYKHOt4lOR3QD0XYvRuGTUX/r+A1Msm9a1ACm9isEPMYFm2kP94zPUsq3/+9H4eaMNVdJTWe7iiG301ro+PgJKHUBEhYixjGPGvRN+uFQeD5bl3l4wbMskvE98Di3vrmDMWaz8thaGcJmc1r67ICW8unOxZ1jHfL07dJ9Fb8iobXQErGpJTxUDe15kX6kfa1sHTiNEO6TMa2MTsARLRmm3YfwPLC27o/jOB5WMSnlxhuY2QHlgiZh/zcijIu+J8NiP7R/SZ+iOltmMcz7dh5o4+vONq73yvPSY09g4ndWE/QqfM67oD3M5rixs8zaCHGGeYqXhlaFpSgaWjeleAFGKdM+0dodfXiCQdU7HO/to94ZQW6GEC5P1rftQ9AOaEWwgCwjQR0NJtwDzVE+Z/U8zjshXGbaq+nqo+8AL+4or7EXA8/zL5jXS3Pf85qMJ+X93YZ8Hpq5ausTZvOhF1QLzZsbJO+3jfZx4CTYp7JQjyHgEMcm/OyhNtfCTAaCS/NgI/CMSdNXC3cNX9bpWQG5mIHRqWFKcLCWvEAIVO0pdSci+jHFimXLEbgdMdbUmGfd17mnoA3yQClvKzO7F8LPxlUhadOsMAfZde75rPX4HywbyFgZNSjwOMF/koU8dearFxbmugkrMnTaA+MqKt1OULgO22lQlJtJi61FSAqarAiMtJavznixzYOt53O52JDLr8E0DV0zpJSmGzh0nonQdZQeZHRaANuuuYTZ5fHZtdiVrbpNhFFAhLG3KsblxaUzBZxDeN6ofuF0fOtCLMRUsTssmHaMG9hx+Z37Up7txvF8h90MpXLSJjgsPgH9XmfjiDHeYSTRGlEVWGtli/3TbBQ+HtMSQLCT9QMqN8jgiZ1vVfuY+YBTGRYijkcc/eYXhg6mtsq+cA7hnOJF0iSlhDCamlQzJ7VdPS773hQY75tfP4roU2aFoirh2nHBn9jOns3FGM/Ds/bTkQS9Ls8/DdgsYk0vaXH+yvjTGiR57xWhvOp+TOupWfCJENOI1vb9sU1LUBbGSUDNMKuPwovt9ZYOQnmazUWEy4OykwllMRBHxZBBZ1Ro6xc6Bc55lMytbTWPq04jaCwTvchSoRj+OF7Dp66EbnZ6/p6aw3fOZ8sXBoNf6MY0e572oRO6AEkccAlI+UQMAYFtBNQcPpt+mO93idXC/wvX5BurZGAWkEEaRUPQESpSEbH0uUihCxViqtuvFs6qlyuYeeVqS9N+67qRy4b2rxccVdZg7Jx3rRUja54dRYnTdFDnwbqurAiBiC1eZOih0OGvk/asAFNAMfAb9yLhCqupP23sd68ALp8cPa+ymC2ttkIhWXPM2qw4GDb+PcHUNf9tXY7Mh+55xDVB2OWBTWDAJ+yPMeFxs24trvokF96S1MGiuMppCe2VIOUTPO5X+NBGwMIopExcBzh74dzPxVMw0apXMxavmjFJVb3D5KAffO7SmkA06frdgOjB6zpaUyTY+GL2bb/xC4uSe6bSVBcZ80uQTqUtC0J+FvDi0w0bEwUvK7gwH3V708XCh64D+A5B6FJL5LA7lAUSM53/mqiaA5CeLk9ih+mvZ/88pDrIeFd/9YFtQloZG2PKCSoesyDzL8DzUCR4a4sEvhFmZ8Cr2RkI7WdHmV9KwHnl90OT/xpAg+qzhitDPgo2laq7FYrD+fXZAfOI97BXtRDKSpG0cxaSj84FVaD//NMRqPNayZUt2YYpiL9ytcp83SEejj483tGCFfIIKjbjtGv1wEwn94cVNyL77xfa2YdtMjNSdsZgrKj1eJHsWpRX7AvhYuHqvFjDfFaT3FO2Fp0VVUzxhFOzalT159IppeaYF+F8YPns2Zp2kUdU5ATz5FOpKuf2T6DNMtcovDztAnx9z2UGpVq0/vaqKFwdUetS5AC7RMbe6wqXTq8CnWpx4s4TRGVsdU3Wyf0rKke5PpWFG5liiFmpqPL0KjTSsxrr59ngYsG9pfny1WJu951z8HG85PozNRIug1OmUu0iKgqXUfyiw+e/IhFv/dkNhTKEabebFK/0hFvtNYR8wrsym27FpgBmaqjUvc1yznvaNxv3VJmzcrutRvVWqEFfEU5HXIlbwifZat1WtXATaJPv9MlyXxc5Ew2zOyh/d6Xe8SYDf+VBZo/VXh/jATa5jhd/JqVK+0UHm6gJzPea2qL3NB0NXEBwD6JmwtE+yx6cVzfdR/5V4JhBgt/YM/O9GzbkM2fubfk2KlLl94MV+XmRW2Ga77B83RQnKyX7TAcC5WBhzKesyaDXO1HWfIe0MjSDYaGNmkEzGdG1QTGaP7m4S2GDxsYJURVlQcDxAIHUQ+1z48V+Jhzp+OSFEWy8mECwdgXlfbYNsh6tF1Xfoh7GslnN9Z0btZay8MmOFkw5YpR2MKW3BCNLO0O0HZqP78QfVYP/jx2mW5TAmcbZYTHxsYFYVNer2XfRyobjxWh1cT607T7d4qejPsrO0EzAgv0u/HH4OBeGaxPO94Q6plv8FECovJc8uTjKNvgPcUpIo0ZgmzUAAAAASUVORK5CYII=";
|
1467
|
-
const CoinleyModal = ({
|
1468
|
-
isOpen,
|
1469
|
-
onClose,
|
1470
|
-
payment,
|
1471
|
-
paymentStatus,
|
1472
|
-
selectedCurrency,
|
1473
|
-
onCurrencySelect,
|
1474
|
-
onPayment,
|
1475
|
-
error,
|
1476
|
-
theme = "light",
|
1477
|
-
merchantName,
|
1478
|
-
transactionHash,
|
1479
|
-
walletConnected,
|
1480
|
-
onConnectWallet,
|
1481
|
-
testMode = false
|
1482
|
-
}) => {
|
2406
|
+
const CoinleyModal = (props) => {
|
2407
|
+
const {
|
2408
|
+
isOpen,
|
2409
|
+
onClose,
|
2410
|
+
payment,
|
2411
|
+
paymentStatus,
|
2412
|
+
selectedCurrency,
|
2413
|
+
onCurrencySelect,
|
2414
|
+
onPayment,
|
2415
|
+
error,
|
2416
|
+
theme = "light",
|
2417
|
+
merchantName,
|
2418
|
+
transactionHash,
|
2419
|
+
walletConnected,
|
2420
|
+
onConnectWallet,
|
2421
|
+
testMode = false
|
2422
|
+
} = props;
|
1483
2423
|
const [step, setStep] = useState("select-currency");
|
1484
2424
|
const [isMetaMaskAvailable, setIsMetaMaskAvailable] = useState(false);
|
1485
2425
|
const [paymentMethod, setPaymentMethod] = useState("wallet");
|
@@ -1499,263 +2439,17 @@ const CoinleyModal = ({
|
|
1499
2439
|
setStep("select-currency");
|
1500
2440
|
}
|
1501
2441
|
}, [paymentStatus, payment]);
|
1502
|
-
const handleCurrencySelect = (currency) => {
|
1503
|
-
onCurrencySelect(currency);
|
1504
|
-
setStep("confirm");
|
1505
|
-
};
|
1506
|
-
const handlePaymentConfirm = () => {
|
1507
|
-
onPayment(paymentMethod === "qrcode");
|
1508
|
-
};
|
1509
|
-
const handleBack = () => {
|
1510
|
-
if (step === "confirm") {
|
1511
|
-
setStep("select-currency");
|
1512
|
-
}
|
1513
|
-
};
|
1514
|
-
const handleClose = () => {
|
1515
|
-
onClose();
|
1516
|
-
};
|
1517
|
-
const formatAmount = (amount) => {
|
1518
|
-
return parseFloat(amount).toFixed(2);
|
1519
|
-
};
|
1520
|
-
const formatTransactionHash = (hash) => {
|
1521
|
-
if (!hash)
|
1522
|
-
return "";
|
1523
|
-
if (hash.length <= 14)
|
1524
|
-
return hash;
|
1525
|
-
return `${hash.slice(0, 8)}...${hash.slice(-6)}`;
|
1526
|
-
};
|
1527
|
-
const togglePaymentMethod = (method) => {
|
1528
|
-
setPaymentMethod(method);
|
1529
|
-
};
|
1530
|
-
const modalBaseClasses = `fixed inset-0 z-50 overflow-y-auto ${theme === "dark" ? "bg-gray-900/75" : "bg-black/50"}`;
|
1531
|
-
const modalContentClasses = `relative p-6 w-full max-w-md mx-auto rounded-lg shadow-xl ${theme === "dark" ? "bg-gray-800 text-white" : "bg-white text-gray-800"}`;
|
1532
|
-
const headerClasses = `text-xl font-bold mb-4 ${theme === "dark" ? "text-white" : "text-gray-900"}`;
|
1533
|
-
const buttonPrimaryClasses = `w-full py-2 px-4 rounded-md font-medium transition-colors focus:outline-none focus:ring-2 focus:ring-offset-2 ${theme === "dark" ? "bg-blue-600 hover:bg-blue-700 text-white focus:ring-blue-500" : "bg-blue-500 hover:bg-blue-600 text-white focus:ring-blue-500"}`;
|
1534
|
-
const buttonSecondaryClasses = `w-full py-2 px-4 rounded-md font-medium transition-colors focus:outline-none focus:ring-2 focus:ring-offset-2 ${theme === "dark" ? "bg-gray-700 hover:bg-gray-600 text-white focus:ring-gray-500" : "bg-gray-200 hover:bg-gray-300 text-gray-800 focus:ring-gray-500"}`;
|
1535
|
-
const tabButtonClasses = `py-2 px-4 text-sm font-medium focus:outline-none transition-colors`;
|
1536
|
-
const activeTabClasses = `${theme === "dark" ? "bg-gray-700 text-white" : "bg-gray-100 text-gray-800"} rounded-t-md`;
|
1537
|
-
const inactiveTabClasses = `${theme === "dark" ? "text-gray-400 hover:text-gray-300" : "text-gray-500 hover:text-gray-700"}`;
|
1538
2442
|
if (!isOpen)
|
1539
2443
|
return null;
|
1540
|
-
return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className:
|
1541
|
-
|
1542
|
-
|
1543
|
-
|
1544
|
-
|
1545
|
-
|
1546
|
-
|
1547
|
-
|
1548
|
-
|
1549
|
-
onClick: handleClose,
|
1550
|
-
className: `text-gray-500 hover:text-gray-700 focus:outline-none ${theme === "dark" ? "text-gray-400 hover:text-gray-300" : ""}`,
|
1551
|
-
children: /* @__PURE__ */ jsxRuntimeExports.jsx("svg", { xmlns: "http://www.w3.org/2000/svg", className: "h-6 w-6", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", children: /* @__PURE__ */ jsxRuntimeExports.jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M6 18L18 6M6 6l12 12" }) })
|
1552
|
-
}
|
1553
|
-
)
|
1554
|
-
] }),
|
1555
|
-
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "mb-6", children: [
|
1556
|
-
payment && /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: `mb-6 p-4 rounded-lg ${theme === "dark" ? "bg-gray-700" : "bg-gray-100"}`, children: [
|
1557
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: `text-sm ${theme === "dark" ? "text-gray-300" : "text-gray-600"}`, children: merchantName }),
|
1558
|
-
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex justify-between items-center mt-2", children: [
|
1559
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: `font-medium ${theme === "dark" ? "text-gray-300" : "text-gray-700"}`, children: "Amount:" }),
|
1560
|
-
/* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "font-bold text-xl", children: [
|
1561
|
-
"$",
|
1562
|
-
formatAmount(payment.totalAmount || payment.amount)
|
1563
|
-
] })
|
1564
|
-
] }),
|
1565
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-xs mt-1 text-right", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: `${theme === "dark" ? "text-gray-400" : "text-gray-500"}`, children: [
|
1566
|
-
"Payment ID: ",
|
1567
|
-
payment.id && payment.id.slice(0, 8),
|
1568
|
-
"..."
|
1569
|
-
] }) })
|
1570
|
-
] }),
|
1571
|
-
step === "select-currency" && /* @__PURE__ */ jsxRuntimeExports.jsx(
|
1572
|
-
PaymentMethods,
|
1573
|
-
{
|
1574
|
-
onSelect: handleCurrencySelect,
|
1575
|
-
selected: selectedCurrency,
|
1576
|
-
theme
|
1577
|
-
}
|
1578
|
-
),
|
1579
|
-
step === "confirm" && payment && /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
|
1580
|
-
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: `p-4 rounded-lg mb-4 ${theme === "dark" ? "bg-gray-700" : "bg-gray-100"}`, children: [
|
1581
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx("h3", { className: `text-lg font-medium mb-2 ${theme === "dark" ? "text-white" : "text-gray-800"}`, children: "Payment Details" }),
|
1582
|
-
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-2", children: [
|
1583
|
-
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex justify-between", children: [
|
1584
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: theme === "dark" ? "text-gray-300" : "text-gray-600", children: "Currency:" }),
|
1585
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "font-medium", children: selectedCurrency })
|
1586
|
-
] }),
|
1587
|
-
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex justify-between", children: [
|
1588
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: theme === "dark" ? "text-gray-300" : "text-gray-600", children: "Network:" }),
|
1589
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "font-medium", children: selectedCurrency === "SOL" || selectedCurrency === "USDC_SOL" ? "Solana" : "Ethereum" })
|
1590
|
-
] }),
|
1591
|
-
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex justify-between", children: [
|
1592
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: theme === "dark" ? "text-gray-300" : "text-gray-600", children: "Fee:" }),
|
1593
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "font-medium", children: "1.75%" })
|
1594
|
-
] })
|
1595
|
-
] })
|
1596
|
-
] }),
|
1597
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "mb-4", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex border-b border-gray-200", children: [
|
1598
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
1599
|
-
"button",
|
1600
|
-
{
|
1601
|
-
onClick: () => togglePaymentMethod("wallet"),
|
1602
|
-
className: `${tabButtonClasses} ${paymentMethod === "wallet" ? activeTabClasses : inactiveTabClasses}`,
|
1603
|
-
children: "Connect Wallet"
|
1604
|
-
}
|
1605
|
-
),
|
1606
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
1607
|
-
"button",
|
1608
|
-
{
|
1609
|
-
onClick: () => togglePaymentMethod("qrcode"),
|
1610
|
-
className: `${tabButtonClasses} ${paymentMethod === "qrcode" ? activeTabClasses : inactiveTabClasses}`,
|
1611
|
-
children: "QR Code"
|
1612
|
-
}
|
1613
|
-
)
|
1614
|
-
] }) }),
|
1615
|
-
testMode ? (
|
1616
|
-
// Test mode payment option
|
1617
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: `p-4 rounded-lg mb-4 ${theme === "dark" ? "bg-blue-900/20" : "bg-blue-50"}`, children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center", children: [
|
1618
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "bg-blue-500 rounded-full p-2 mr-3", children: /* @__PURE__ */ jsxRuntimeExports.jsx("svg", { xmlns: "http://www.w3.org/2000/svg", className: "h-6 w-6 text-white", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", children: /* @__PURE__ */ jsxRuntimeExports.jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M13 10V3L4 14h7v7l9-11h-7z" }) }) }),
|
1619
|
-
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
|
1620
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx("h3", { className: `font-medium ${theme === "dark" ? "text-white" : "text-gray-800"}`, children: "Test Mode Payment" }),
|
1621
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: `text-sm ${theme === "dark" ? "text-gray-300" : "text-gray-600"}`, children: 'Click "Pay Now" to simulate a successful payment' })
|
1622
|
-
] })
|
1623
|
-
] }) })
|
1624
|
-
) : paymentMethod === "qrcode" ? (
|
1625
|
-
// QR Code payment option
|
1626
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: `p-4 rounded-lg mb-4 ${theme === "dark" ? "bg-blue-900/20" : "bg-blue-50"}`, children: /* @__PURE__ */ jsxRuntimeExports.jsx(
|
1627
|
-
QRCode,
|
1628
|
-
{
|
1629
|
-
walletAddress: payment.walletAddress || "0x742d35Cc6634C0532925a3b844Bc454e4438f44e",
|
1630
|
-
amount: payment.totalAmount || payment.amount,
|
1631
|
-
currency: selectedCurrency,
|
1632
|
-
theme
|
1633
|
-
}
|
1634
|
-
) })
|
1635
|
-
) : isMetaMaskAvailable ? (
|
1636
|
-
// MetaMask available option
|
1637
|
-
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: `p-4 rounded-lg mb-4 ${theme === "dark" ? "bg-blue-900/20" : "bg-blue-50"}`, children: [
|
1638
|
-
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center", children: [
|
1639
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
1640
|
-
"img",
|
1641
|
-
{
|
1642
|
-
src: "https://metamask.io/images/metamask-fox.svg",
|
1643
|
-
alt: "MetaMask",
|
1644
|
-
className: "w-8 h-8 mr-2"
|
1645
|
-
}
|
1646
|
-
),
|
1647
|
-
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
|
1648
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx("h3", { className: `font-medium ${theme === "dark" ? "text-white" : "text-gray-800"}`, children: "Pay with MetaMask" }),
|
1649
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: `text-sm ${theme === "dark" ? "text-gray-300" : "text-gray-600"}`, children: walletConnected ? "Your wallet is connected. Click 'Pay Now' to proceed." : "Click 'Connect Wallet' to proceed with payment." })
|
1650
|
-
] })
|
1651
|
-
] }),
|
1652
|
-
!walletConnected && /* @__PURE__ */ jsxRuntimeExports.jsx(
|
1653
|
-
"button",
|
1654
|
-
{
|
1655
|
-
onClick: onConnectWallet,
|
1656
|
-
className: `mt-3 ${buttonPrimaryClasses}`,
|
1657
|
-
children: "Connect Wallet"
|
1658
|
-
}
|
1659
|
-
)
|
1660
|
-
] })
|
1661
|
-
) : (
|
1662
|
-
// MetaMask not available warning
|
1663
|
-
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: `p-4 rounded-lg mb-4 ${theme === "dark" ? "bg-yellow-900/20" : "bg-yellow-50"}`, children: [
|
1664
|
-
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center", children: [
|
1665
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx("svg", { xmlns: "http://www.w3.org/2000/svg", className: "h-6 w-6 text-yellow-500 mr-2", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", children: /* @__PURE__ */ jsxRuntimeExports.jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z" }) }),
|
1666
|
-
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
|
1667
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx("h3", { className: `font-medium ${theme === "dark" ? "text-white" : "text-gray-800"}`, children: "MetaMask Not Detected" }),
|
1668
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: `text-sm ${theme === "dark" ? "text-gray-300" : "text-gray-600"}`, children: "Please install MetaMask extension to make payments" })
|
1669
|
-
] })
|
1670
|
-
] }),
|
1671
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
1672
|
-
"a",
|
1673
|
-
{
|
1674
|
-
href: "https://metamask.io/download/",
|
1675
|
-
target: "_blank",
|
1676
|
-
rel: "noopener noreferrer",
|
1677
|
-
className: `block mt-3 text-center ${buttonPrimaryClasses}`,
|
1678
|
-
children: "Install MetaMask"
|
1679
|
-
}
|
1680
|
-
)
|
1681
|
-
] })
|
1682
|
-
),
|
1683
|
-
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "mt-6 grid grid-cols-2 gap-3", children: [
|
1684
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
1685
|
-
"button",
|
1686
|
-
{
|
1687
|
-
type: "button",
|
1688
|
-
onClick: handleBack,
|
1689
|
-
className: buttonSecondaryClasses,
|
1690
|
-
children: "Back"
|
1691
|
-
}
|
1692
|
-
),
|
1693
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
1694
|
-
"button",
|
1695
|
-
{
|
1696
|
-
type: "button",
|
1697
|
-
onClick: handlePaymentConfirm,
|
1698
|
-
className: buttonPrimaryClasses,
|
1699
|
-
disabled: !testMode && paymentMethod === "wallet" && isMetaMaskAvailable && !walletConnected,
|
1700
|
-
children: "Pay Now"
|
1701
|
-
}
|
1702
|
-
)
|
1703
|
-
] })
|
1704
|
-
] }),
|
1705
|
-
step === "processing" && /* @__PURE__ */ jsxRuntimeExports.jsx(
|
1706
|
-
PaymentStatus,
|
1707
|
-
{
|
1708
|
-
status: "processing",
|
1709
|
-
theme,
|
1710
|
-
message: "Processing your payment..."
|
1711
|
-
}
|
1712
|
-
),
|
1713
|
-
step === "success" && /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
|
1714
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
1715
|
-
PaymentStatus,
|
1716
|
-
{
|
1717
|
-
status: "success",
|
1718
|
-
theme,
|
1719
|
-
message: "Payment successful!"
|
1720
|
-
}
|
1721
|
-
),
|
1722
|
-
transactionHash && /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: `mt-4 p-3 rounded-lg ${theme === "dark" ? "bg-gray-700" : "bg-gray-100"}`, children: [
|
1723
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: `text-xs ${theme === "dark" ? "text-gray-300" : "text-gray-600"} mb-1`, children: "Transaction Hash:" }),
|
1724
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: `text-sm font-mono break-all ${theme === "dark" ? "text-white" : "text-gray-800"}`, children: formatTransactionHash(transactionHash) }),
|
1725
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
1726
|
-
"a",
|
1727
|
-
{
|
1728
|
-
href: `https://etherscan.io/tx/${transactionHash}`,
|
1729
|
-
target: "_blank",
|
1730
|
-
rel: "noopener noreferrer",
|
1731
|
-
className: `text-xs ${theme === "dark" ? "text-blue-400" : "text-blue-600"} mt-2 inline-block`,
|
1732
|
-
children: "View on Etherscan →"
|
1733
|
-
}
|
1734
|
-
)
|
1735
|
-
] })
|
1736
|
-
] }),
|
1737
|
-
step === "error" && /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
|
1738
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
1739
|
-
PaymentStatus,
|
1740
|
-
{
|
1741
|
-
status: "error",
|
1742
|
-
theme,
|
1743
|
-
message: error || "An error occurred while processing your payment."
|
1744
|
-
}
|
1745
|
-
),
|
1746
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
1747
|
-
"button",
|
1748
|
-
{
|
1749
|
-
type: "button",
|
1750
|
-
onClick: handleBack,
|
1751
|
-
className: `mt-4 ${buttonSecondaryClasses}`,
|
1752
|
-
children: "Try Again"
|
1753
|
-
}
|
1754
|
-
)
|
1755
|
-
] })
|
1756
|
-
] }),
|
1757
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: `text-center text-xs ${theme === "dark" ? "text-gray-400" : "text-gray-500"}`, children: /* @__PURE__ */ jsxRuntimeExports.jsx("p", { children: "Powered by Coinley - Secure Cryptocurrency Payments" }) })
|
1758
|
-
] }) }) });
|
2444
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: theme === "dark" ? "bg-gray-900/75" : "bg-black/50", style: { position: "fixed", inset: 0, zIndex: 50 }, children: /* @__PURE__ */ jsxRuntimeExports.jsx("div", { style: { minHeight: "100vh", display: "flex", alignItems: "center", justifyContent: "center", padding: "16px" }, children: /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: theme === "dark" ? "bg-gray-800 text-white" : "bg-white text-gray-800", style: { position: "relative", padding: "24px", width: "100%", maxWidth: "28rem", borderRadius: "8px", boxShadow: "0 20px 25px -5px rgb(0 0 0 / 0.1)" }, children: step === "confirm" && payment && paymentMethod === "qrcode" && /* @__PURE__ */ jsxRuntimeExports.jsx("div", { style: { marginTop: "16px" }, children: /* @__PURE__ */ jsxRuntimeExports.jsx(
|
2445
|
+
QRCode,
|
2446
|
+
{
|
2447
|
+
walletAddress: payment.walletAddress || "0x742d35Cc6634C0532925a3b844Bc454e4438f44e",
|
2448
|
+
amount: payment.totalAmount || payment.amount,
|
2449
|
+
currency: selectedCurrency,
|
2450
|
+
theme
|
2451
|
+
}
|
2452
|
+
) }) }) }) });
|
1759
2453
|
};
|
1760
2454
|
const CoinleyCheckout = forwardRef(({
|
1761
2455
|
apiKey,
|
@@ -1979,7 +2673,7 @@ const DEFAULT_CONFIG = {
|
|
1979
2673
|
testMode: false,
|
1980
2674
|
theme: "light"
|
1981
2675
|
};
|
1982
|
-
const VERSION = "1.0.
|
2676
|
+
const VERSION = "1.0.8";
|
1983
2677
|
export {
|
1984
2678
|
CoinleyCheckout,
|
1985
2679
|
CoinleyModal,
|
@@ -1988,23 +2682,12 @@ export {
|
|
1988
2682
|
PaymentMethods,
|
1989
2683
|
PaymentStatus,
|
1990
2684
|
QRCode,
|
1991
|
-
TOKEN_ADDRESSES,
|
1992
2685
|
ThemeProvider,
|
1993
2686
|
VERSION,
|
1994
2687
|
connectWallet,
|
1995
2688
|
createPayment,
|
1996
|
-
getAccounts,
|
1997
|
-
getChainId,
|
1998
|
-
getMerchantPaymentStats,
|
1999
|
-
getMerchantPayments,
|
2000
|
-
getNetworkName,
|
2001
2689
|
getPayment,
|
2002
|
-
getSupportedCurrencies,
|
2003
|
-
getTokenBalance,
|
2004
2690
|
isMetaMaskInstalled,
|
2005
|
-
|
2006
|
-
processPayment,
|
2007
|
-
sendToken,
|
2008
|
-
sendTransaction
|
2691
|
+
processPayment
|
2009
2692
|
};
|
2010
2693
|
//# sourceMappingURL=coinley-checkout.es.js.map
|