coinley-checkout 0.2.3 → 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.
@@ -1106,75 +1106,90 @@ const CoinleyProvider = ({
|
|
1106
1106
|
};
|
1107
1107
|
return /* @__PURE__ */ jsxRuntimeExports.jsx(CoinleyContext.Provider, { value, children });
|
1108
1108
|
};
|
1109
|
-
|
1110
|
-
|
1111
|
-
|
1112
|
-
|
1113
|
-
|
1114
|
-
|
1115
|
-
|
1116
|
-
|
1117
|
-
|
1118
|
-
|
1109
|
+
const QRCode = ({
|
1110
|
+
walletAddress,
|
1111
|
+
amount,
|
1112
|
+
currency,
|
1113
|
+
theme = "light",
|
1114
|
+
size = 200
|
1115
|
+
}) => {
|
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
|
+
}
|
1119
1136
|
}
|
1120
1137
|
}
|
1138
|
+
svg += "</svg>";
|
1139
|
+
return svg;
|
1121
1140
|
}
|
1122
|
-
|
1123
|
-
|
1124
|
-
|
1125
|
-
|
1126
|
-
|
1127
|
-
|
1128
|
-
|
1129
|
-
|
1130
|
-
|
1131
|
-
|
1132
|
-
|
1133
|
-
matrix
|
1134
|
-
matrix
|
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;
|
1135
1155
|
}
|
1136
|
-
|
1137
|
-
|
1138
|
-
|
1139
|
-
|
1140
|
-
|
1141
|
-
|
1142
|
-
|
1143
|
-
hash = (hash << 5) - hash + str.charCodeAt(i);
|
1144
|
-
hash = hash & hash;
|
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);
|
1145
1163
|
}
|
1146
|
-
|
1147
|
-
|
1148
|
-
|
1149
|
-
|
1150
|
-
|
1151
|
-
matrix[row + r][col + c] = r === 0 || r === 6 || c === 0 || c === 6 || r >= 2 && r <= 4 && c >= 2 && c <= 4 ? 1 : 0;
|
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
|
+
}
|
1152
1169
|
}
|
1153
1170
|
}
|
1154
|
-
|
1155
|
-
|
1156
|
-
|
1157
|
-
|
1158
|
-
|
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
|
+
}
|
1159
1178
|
}
|
1160
1179
|
}
|
1161
|
-
|
1162
|
-
|
1163
|
-
|
1164
|
-
|
1165
|
-
|
1166
|
-
|
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
|
+
}
|
1167
1191
|
}
|
1168
1192
|
}
|
1169
|
-
}
|
1170
|
-
const QRCode = ({
|
1171
|
-
walletAddress,
|
1172
|
-
amount,
|
1173
|
-
currency,
|
1174
|
-
theme = "light"
|
1175
|
-
}) => {
|
1176
|
-
const qrData = `${currency}:${walletAddress}?amount=${amount}`;
|
1177
|
-
const qrSvg = renderQR(qrData, 200);
|
1178
1193
|
return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex flex-col items-center", children: [
|
1179
1194
|
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "p-4 rounded-lg bg-white mb-3", children: /* @__PURE__ */ jsxRuntimeExports.jsx("div", { dangerouslySetInnerHTML: { __html: qrSvg } }) }),
|
1180
1195
|
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-center text-sm text-gray-700", children: "Scan with your wallet app to pay" }),
|