coinley-checkout 0.2.4 → 0.2.5
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.
@@ -1110,19 +1110,88 @@ const QRCode = ({
|
|
1110
1110
|
walletAddress,
|
1111
1111
|
amount,
|
1112
1112
|
currency,
|
1113
|
-
theme = "light"
|
1113
|
+
theme = "light",
|
1114
|
+
size = 200
|
1114
1115
|
}) => {
|
1115
|
-
const
|
1116
|
-
|
1117
|
-
|
1118
|
-
|
1119
|
-
|
1120
|
-
|
1121
|
-
|
1122
|
-
|
1123
|
-
|
1116
|
+
const [qrSvg, setQrSvg] = useState("");
|
1117
|
+
useEffect(() => {
|
1118
|
+
const scheme = currency === "SOL" || currency === "USDC_SOL" ? "solana" : "ethereum";
|
1119
|
+
const paymentUri = `${scheme}:${walletAddress || "0x742d35Cc6634C0532925a3b844Bc454e4438f44e"}?amount=${amount}¤cy=${currency}`;
|
1120
|
+
const qrcode = generateQRCode(paymentUri, size, theme === "dark");
|
1121
|
+
setQrSvg(qrcode);
|
1122
|
+
}, [walletAddress, amount, currency, theme, size]);
|
1123
|
+
function generateQRCode(text, size2, isDarkTheme) {
|
1124
|
+
const matrix = generateQRMatrix(text);
|
1125
|
+
const cellSize = Math.floor(size2 / matrix.length);
|
1126
|
+
const qrSize = cellSize * matrix.length;
|
1127
|
+
const bgColor = isDarkTheme ? "#374151" : "#FFFFFF";
|
1128
|
+
const fgColor = isDarkTheme ? "#FFFFFF" : "#000000";
|
1129
|
+
let svg = `<svg xmlns="http://www.w3.org/2000/svg" width="${qrSize}" height="${qrSize}" viewBox="0 0 ${qrSize} ${qrSize}">`;
|
1130
|
+
svg += `<rect width="${qrSize}" height="${qrSize}" fill="${bgColor}"/>`;
|
1131
|
+
for (let y = 0; y < matrix.length; y++) {
|
1132
|
+
for (let x = 0; x < matrix.length; x++) {
|
1133
|
+
if (matrix[y][x]) {
|
1134
|
+
svg += `<rect x="${x * cellSize}" y="${y * cellSize}" width="${cellSize}" height="${cellSize}" fill="${fgColor}"/>`;
|
1135
|
+
}
|
1124
1136
|
}
|
1125
|
-
|
1137
|
+
}
|
1138
|
+
svg += "</svg>";
|
1139
|
+
return svg;
|
1140
|
+
}
|
1141
|
+
function generateQRMatrix(text) {
|
1142
|
+
const hash = simpleHash(text);
|
1143
|
+
const size2 = 25;
|
1144
|
+
const matrix = Array(size2).fill().map(() => Array(size2).fill(0));
|
1145
|
+
addPositionPattern(matrix, 0, 0);
|
1146
|
+
addPositionPattern(matrix, 0, size2 - 7);
|
1147
|
+
addPositionPattern(matrix, size2 - 7, 0);
|
1148
|
+
for (let i = 8; i < size2 - 8; i++) {
|
1149
|
+
matrix[6][i] = i % 2 === 0 ? 1 : 0;
|
1150
|
+
matrix[i][6] = i % 2 === 0 ? 1 : 0;
|
1151
|
+
}
|
1152
|
+
addAlignmentPattern(matrix, size2 - 9, size2 - 9);
|
1153
|
+
fillData(matrix, hash, text);
|
1154
|
+
return matrix;
|
1155
|
+
}
|
1156
|
+
function simpleHash(str) {
|
1157
|
+
let hash = 0;
|
1158
|
+
for (let i = 0; i < str.length; i++) {
|
1159
|
+
hash = (hash << 5) - hash + str.charCodeAt(i);
|
1160
|
+
hash = hash & hash;
|
1161
|
+
}
|
1162
|
+
return Math.abs(hash);
|
1163
|
+
}
|
1164
|
+
function addPositionPattern(matrix, row, col) {
|
1165
|
+
for (let r = 0; r < 7; r++) {
|
1166
|
+
for (let c = 0; c < 7; c++) {
|
1167
|
+
matrix[row + r][col + c] = r === 0 || r === 6 || c === 0 || c === 6 || r >= 2 && r <= 4 && c >= 2 && c <= 4 ? 1 : 0;
|
1168
|
+
}
|
1169
|
+
}
|
1170
|
+
}
|
1171
|
+
function addAlignmentPattern(matrix, row, col) {
|
1172
|
+
for (let r = -2; r <= 2; r++) {
|
1173
|
+
for (let c = -2; c <= 2; c++) {
|
1174
|
+
if (row + r >= 0 && row + r < matrix.length && col + c >= 0 && col + c < matrix.length) {
|
1175
|
+
matrix[row + r][col + c] = r === -2 || r === 2 || c === -2 || c === 2 || r === 0 && c === 0 ? 1 : 0;
|
1176
|
+
}
|
1177
|
+
}
|
1178
|
+
}
|
1179
|
+
}
|
1180
|
+
function fillData(matrix, hash, text) {
|
1181
|
+
const size2 = matrix.length;
|
1182
|
+
for (let r = 0; r < size2; r++) {
|
1183
|
+
for (let c = 0; c < size2; c++) {
|
1184
|
+
if (r < 7 && c < 7 || r < 7 && c >= size2 - 7 || r >= size2 - 7 && c < 7 || r === 6 || c === 6) {
|
1185
|
+
continue;
|
1186
|
+
}
|
1187
|
+
const index = (r * size2 + c) % text.length;
|
1188
|
+
const charCode = text.charCodeAt(index);
|
1189
|
+
matrix[r][c] = hash * charCode * (r + c) % 4 === 0 ? 1 : 0;
|
1190
|
+
}
|
1191
|
+
}
|
1192
|
+
}
|
1193
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex flex-col items-center", children: [
|
1194
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "p-4 rounded-lg bg-white mb-3", children: /* @__PURE__ */ jsxRuntimeExports.jsx("div", { dangerouslySetInnerHTML: { __html: qrSvg } }) }),
|
1126
1195
|
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-center text-sm text-gray-700", children: "Scan with your wallet app to pay" }),
|
1127
1196
|
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "mt-3 w-full", children: [
|
1128
1197
|
/* @__PURE__ */ jsxRuntimeExports.jsxs("p", { className: "text-xs text-gray-500 mb-1", children: [
|
@@ -1132,8 +1201,23 @@ const QRCode = ({
|
|
1132
1201
|
currency,
|
1133
1202
|
" to:"
|
1134
1203
|
] }),
|
1135
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-xs font-mono p-2 rounded overflow-auto break-all bg-gray-100 text-gray-700", children: walletAddress })
|
1136
|
-
] })
|
1204
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-xs font-mono p-2 rounded overflow-auto break-all bg-gray-100 text-gray-700", children: walletAddress || "0x742d35Cc6634C0532925a3b844Bc454e4438f44e" })
|
1205
|
+
] }),
|
1206
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "mt-4 w-full", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "p-3 rounded bg-gray-100", children: [
|
1207
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("h4", { className: "text-sm font-medium mb-2 text-gray-800", children: "Payment Instructions" }),
|
1208
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("ol", { className: "text-xs space-y-2 text-gray-600", children: [
|
1209
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: "1. Open your crypto wallet app" }),
|
1210
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: "2. Scan the QR code above" }),
|
1211
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("li", { children: [
|
1212
|
+
"3. Confirm the payment amount (",
|
1213
|
+
amount,
|
1214
|
+
" ",
|
1215
|
+
currency,
|
1216
|
+
")"
|
1217
|
+
] }),
|
1218
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: '4. Click "Pay Now" button below after sending the payment' })
|
1219
|
+
] })
|
1220
|
+
] }) })
|
1137
1221
|
] });
|
1138
1222
|
};
|
1139
1223
|
const PaymentStatus = ({ status, message, theme = "light" }) => {
|