coinley-checkout 0.1.7 → 0.1.9

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.
@@ -1106,48 +1106,113 @@ const CoinleyProvider = ({
1106
1106
  };
1107
1107
  return /* @__PURE__ */ jsxRuntimeExports.jsx(CoinleyContext.Provider, { value, children });
1108
1108
  };
1109
- const QRCode = ({ walletAddress, amount, currency, theme = "light" }) => {
1110
- const qrDisplay = /* @__PURE__ */ jsxRuntimeExports.jsxs(
1111
- "div",
1112
- {
1113
- style: {
1114
- width: "200px",
1115
- height: "200px",
1116
- backgroundColor: theme === "dark" ? "#374151" : "#f3f4f6",
1117
- display: "flex",
1118
- alignItems: "center",
1119
- justifyContent: "center",
1120
- color: theme === "dark" ? "white" : "black",
1121
- fontWeight: "bold",
1122
- border: `1px solid ${theme === "dark" ? "#4b5563" : "#e5e7eb"}`,
1123
- margin: "0 auto"
1124
- },
1125
- children: [
1126
- currency,
1127
- " Payment QR"
1128
- ]
1109
+ const QRCode = ({
1110
+ walletAddress,
1111
+ amount,
1112
+ currency,
1113
+ theme = "light",
1114
+ size = 200
1115
+ }) => {
1116
+ const [qrCodeSvg, setQrCodeSvg] = useState("");
1117
+ const getQRCodeData = () => {
1118
+ if (!walletAddress)
1119
+ return "";
1120
+ const schemes = {
1121
+ "USDT": "ethereum",
1122
+ "USDC": "ethereum",
1123
+ "BNB": "binance",
1124
+ "SOL": "solana",
1125
+ "USDC_SOL": "solana"
1126
+ };
1127
+ const scheme = schemes[currency] || "ethereum";
1128
+ return `${scheme}:${walletAddress}?amount=${amount}&currency=${currency}`;
1129
+ };
1130
+ useEffect(() => {
1131
+ const generateQRCode = async () => {
1132
+ try {
1133
+ const qrcode = await Promise.resolve().then(() => qrcodeGenerator);
1134
+ const data = getQRCodeData();
1135
+ if (data) {
1136
+ const svg = qrcode.generateQR(data, size, theme === "dark");
1137
+ setQrCodeSvg(svg);
1138
+ }
1139
+ } catch (error) {
1140
+ console.error("Failed to generate QR code:", error);
1141
+ setQrCodeSvg(generateFallbackQR());
1142
+ }
1143
+ };
1144
+ generateQRCode();
1145
+ }, [walletAddress, amount, currency, theme, size]);
1146
+ const generateFallbackQR = () => {
1147
+ const darkMode = theme === "dark";
1148
+ const cellSize = Math.floor(size / 25);
1149
+ const svgSize = size;
1150
+ let svg = `
1151
+ <svg
1152
+ xmlns="http://www.w3.org/2000/svg"
1153
+ width="${svgSize}"
1154
+ height="${svgSize}"
1155
+ viewBox="0 0 ${svgSize} ${svgSize}"
1156
+ >
1157
+ `;
1158
+ svg += `<rect width="${svgSize}" height="${svgSize}" fill="${darkMode ? "#1f2937" : "white"}"/>`;
1159
+ svg += `<rect x="0" y="0" width="${cellSize * 7}" height="${cellSize * 7}" fill="${darkMode ? "white" : "black"}"/>`;
1160
+ svg += `<rect x="${cellSize}" y="${cellSize}" width="${cellSize * 5}" height="${cellSize * 5}" fill="${darkMode ? "#1f2937" : "white"}"/>`;
1161
+ svg += `<rect x="${cellSize * 2}" y="${cellSize * 2}" width="${cellSize * 3}" height="${cellSize * 3}" fill="${darkMode ? "white" : "black"}"/>`;
1162
+ svg += `<rect x="${svgSize - cellSize * 7}" y="0" width="${cellSize * 7}" height="${cellSize * 7}" fill="${darkMode ? "white" : "black"}"/>`;
1163
+ svg += `<rect x="${svgSize - cellSize * 6}" y="${cellSize}" width="${cellSize * 5}" height="${cellSize * 5}" fill="${darkMode ? "#1f2937" : "white"}"/>`;
1164
+ svg += `<rect x="${svgSize - cellSize * 5}" y="${cellSize * 2}" width="${cellSize * 3}" height="${cellSize * 3}" fill="${darkMode ? "white" : "black"}"/>`;
1165
+ svg += `<rect x="0" y="${svgSize - cellSize * 7}" width="${cellSize * 7}" height="${cellSize * 7}" fill="${darkMode ? "white" : "black"}"/>`;
1166
+ svg += `<rect x="${cellSize}" y="${svgSize - cellSize * 6}" width="${cellSize * 5}" height="${cellSize * 5}" fill="${darkMode ? "#1f2937" : "white"}"/>`;
1167
+ svg += `<rect x="${cellSize * 2}" y="${svgSize - cellSize * 5}" width="${cellSize * 3}" height="${cellSize * 3}" fill="${darkMode ? "white" : "black"}"/>`;
1168
+ for (let i = 0; i < 10; i++) {
1169
+ for (let j = 0; j < 10; j++) {
1170
+ if (i < 3 && j < 3 || i < 3 && j > 6 || i > 6 && j < 3)
1171
+ continue;
1172
+ if (Math.random() > 0.5) {
1173
+ const x = cellSize * (i * 2 + 3);
1174
+ const y = cellSize * (j * 2 + 3);
1175
+ svg += `<rect x="${x}" y="${y}" width="${cellSize * 2}" height="${cellSize * 2}" fill="${darkMode ? "white" : "black"}"/>`;
1176
+ }
1177
+ }
1129
1178
  }
1130
- );
1131
- return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
1132
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: theme === "dark" ? "bg-gray-700" : "bg-white", children: qrDisplay }),
1133
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { style: { textAlign: "center", marginTop: "12px", fontSize: "14px" }, children: "Scan with your wallet app to pay" }),
1134
- walletAddress && /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { style: { marginTop: "12px" }, children: [
1135
- /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { style: { fontSize: "12px", marginBottom: "4px" }, children: [
1179
+ svg += "</svg>";
1180
+ return svg;
1181
+ };
1182
+ return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex flex-col items-center", children: [
1183
+ /* @__PURE__ */ jsxRuntimeExports.jsx(
1184
+ "div",
1185
+ {
1186
+ className: `p-4 rounded-lg ${theme === "dark" ? "bg-gray-700" : "bg-white"} mb-3`,
1187
+ dangerouslySetInnerHTML: { __html: qrCodeSvg }
1188
+ }
1189
+ ),
1190
+ /* @__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" }),
1191
+ walletAddress && /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "mt-3 w-full", children: [
1192
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("p", { className: `text-xs ${theme === "dark" ? "text-gray-400" : "text-gray-500"} mb-1`, children: [
1136
1193
  "Send ",
1137
1194
  amount,
1138
1195
  " ",
1139
1196
  currency,
1140
1197
  " to:"
1141
1198
  ] }),
1142
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { style: {
1143
- fontSize: "12px",
1144
- fontFamily: "monospace",
1145
- padding: "8px",
1146
- backgroundColor: theme === "dark" ? "#1f2937" : "#f3f4f6",
1147
- borderRadius: "4px",
1148
- overflowWrap: "break-word"
1149
- }, children: walletAddress })
1150
- ] })
1199
+ /* @__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 })
1200
+ ] }),
1201
+ /* @__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: [
1202
+ /* @__PURE__ */ jsxRuntimeExports.jsx("h4", { className: `text-sm font-medium mb-2 ${theme === "dark" ? "text-white" : "text-gray-800"}`, children: "Payment Instructions" }),
1203
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("ol", { className: `text-xs space-y-2 ${theme === "dark" ? "text-gray-300" : "text-gray-600"}`, children: [
1204
+ /* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: "1. Open your crypto wallet app" }),
1205
+ /* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: "2. Scan the QR code above" }),
1206
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("li", { children: [
1207
+ "3. Confirm the payment amount (",
1208
+ amount,
1209
+ " ",
1210
+ currency,
1211
+ ")"
1212
+ ] }),
1213
+ /* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: '4. Click "Pay Now" button below after sending the payment' })
1214
+ ] })
1215
+ ] }) })
1151
1216
  ] });
1152
1217
  };
1153
1218
  const PaymentStatus = ({ status, message, theme = "light" }) => {
@@ -1553,7 +1618,77 @@ const DEFAULT_CONFIG = {
1553
1618
  testMode: false,
1554
1619
  theme: "light"
1555
1620
  };
1556
- const VERSION = "1.0.7";
1621
+ const VERSION = "1.0.9";
1622
+ const hashString = (str) => {
1623
+ let hash = 0;
1624
+ for (let i = 0; i < str.length; i++) {
1625
+ const char = str.charCodeAt(i);
1626
+ hash = (hash << 5) - hash + char;
1627
+ hash = hash & hash;
1628
+ }
1629
+ return Math.abs(hash);
1630
+ };
1631
+ const generateQR = (data, size = 200, darkMode = false) => {
1632
+ const dataHash = hashString(data);
1633
+ const moduleCount = 25;
1634
+ const moduleSize = Math.floor(size / moduleCount);
1635
+ const quietZone = moduleSize * 2;
1636
+ const svgSize = size + quietZone * 2;
1637
+ const darkColor = darkMode ? "#FFFFFF" : "#000000";
1638
+ const lightColor = darkMode ? "#1F2937" : "#FFFFFF";
1639
+ let svg = `
1640
+ <svg
1641
+ xmlns="http://www.w3.org/2000/svg"
1642
+ width="${svgSize}"
1643
+ height="${svgSize}"
1644
+ viewBox="0 0 ${svgSize} ${svgSize}"
1645
+ >
1646
+ `;
1647
+ svg += `<rect width="${svgSize}" height="${svgSize}" fill="${lightColor}"/>`;
1648
+ svg += createPositionPattern(quietZone, quietZone, moduleSize, darkColor, lightColor);
1649
+ svg += createPositionPattern(svgSize - quietZone - moduleSize * 7, quietZone, moduleSize, darkColor, lightColor);
1650
+ svg += createPositionPattern(quietZone, svgSize - quietZone - moduleSize * 7, moduleSize, darkColor, lightColor);
1651
+ for (let row = 0; row < moduleCount; row++) {
1652
+ for (let col = 0; col < moduleCount; col++) {
1653
+ if (row < 7 && col < 7 || // Top left
1654
+ row < 7 && col >= moduleCount - 7 || // Top right
1655
+ row >= moduleCount - 7 && col < 7) {
1656
+ continue;
1657
+ }
1658
+ const shouldFill = (dataHash + row * 37 + col * 17) % 3 === 0;
1659
+ if (shouldFill) {
1660
+ const x = quietZone + col * moduleSize;
1661
+ const y = quietZone + row * moduleSize;
1662
+ svg += `<rect x="${x}" y="${y}" width="${moduleSize}" height="${moduleSize}" fill="${darkColor}"/>`;
1663
+ }
1664
+ }
1665
+ }
1666
+ for (let i = 8; i < moduleCount - 8; i++) {
1667
+ if (i % 2 === 0) {
1668
+ svg += `<rect x="${quietZone + i * moduleSize}" y="${quietZone + 6 * moduleSize}" width="${moduleSize}" height="${moduleSize}" fill="${darkColor}"/>`;
1669
+ }
1670
+ }
1671
+ for (let i = 8; i < moduleCount - 8; i++) {
1672
+ if (i % 2 === 0) {
1673
+ svg += `<rect x="${quietZone + 6 * moduleSize}" y="${quietZone + i * moduleSize}" width="${moduleSize}" height="${moduleSize}" fill="${darkColor}"/>`;
1674
+ }
1675
+ }
1676
+ svg += `<rect x="${quietZone + moduleSize * 12}" y="${quietZone + moduleSize * 12}" width="${moduleSize * 3}" height="${moduleSize * 3}" fill="${darkColor}"/>`;
1677
+ svg += `<rect x="${quietZone + moduleSize * 13}" y="${quietZone + moduleSize * 13}" width="${moduleSize}" height="${moduleSize}" fill="${lightColor}"/>`;
1678
+ svg += "</svg>";
1679
+ return svg;
1680
+ };
1681
+ const createPositionPattern = (x, y, size, darkColor, lightColor) => {
1682
+ let pattern = "";
1683
+ pattern += `<rect x="${x}" y="${y}" width="${size * 7}" height="${size * 7}" fill="${darkColor}"/>`;
1684
+ pattern += `<rect x="${x + size}" y="${y + size}" width="${size * 5}" height="${size * 5}" fill="${lightColor}"/>`;
1685
+ pattern += `<rect x="${x + size * 2}" y="${y + size * 2}" width="${size * 3}" height="${size * 3}" fill="${darkColor}"/>`;
1686
+ return pattern;
1687
+ };
1688
+ const qrcodeGenerator = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
1689
+ __proto__: null,
1690
+ generateQR
1691
+ }, Symbol.toStringTag, { value: "Module" }));
1557
1692
  export {
1558
1693
  CoinleyCheckout,
1559
1694
  CoinleyModal,