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
- function renderQR(text, size) {
1110
- const matrix = generateQRMatrix(text);
1111
- const cellSize = Math.floor(size / matrix.length);
1112
- const qrSize = cellSize * matrix.length;
1113
- let svg = `<svg xmlns="http://www.w3.org/2000/svg" width="${qrSize}" height="${qrSize}" viewBox="0 0 ${qrSize} ${qrSize}">`;
1114
- svg += `<rect width="${qrSize}" height="${qrSize}" fill="white"/>`;
1115
- for (let y = 0; y < matrix.length; y++) {
1116
- for (let x = 0; x < matrix.length; x++) {
1117
- if (matrix[y][x]) {
1118
- svg += `<rect x="${x * cellSize}" y="${y * cellSize}" width="${cellSize}" height="${cellSize}" fill="black"/>`;
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}&currency=${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
- svg += "</svg>";
1123
- return svg;
1124
- }
1125
- function generateQRMatrix(text) {
1126
- const hash = simpleHash(text);
1127
- const size = 21;
1128
- const matrix = Array(size).fill().map(() => Array(size).fill(0));
1129
- addPositionPattern(matrix, 0, 0);
1130
- addPositionPattern(matrix, 0, size - 7);
1131
- addPositionPattern(matrix, size - 7, 0);
1132
- for (let i = 8; i < size - 8; i++) {
1133
- matrix[6][i] = i % 2 === 0 ? 1 : 0;
1134
- matrix[i][6] = i % 2 === 0 ? 1 : 0;
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
- addAlignmentPattern(matrix, size - 9, size - 9);
1137
- fillData(matrix, hash);
1138
- return matrix;
1139
- }
1140
- function simpleHash(str) {
1141
- let hash = 0;
1142
- for (let i = 0; i < str.length; i++) {
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
- return Math.abs(hash);
1147
- }
1148
- function addPositionPattern(matrix, row, col) {
1149
- for (let r = 0; r < 7; r++) {
1150
- for (let c = 0; c < 7; c++) {
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
- function addAlignmentPattern(matrix, row, col) {
1156
- for (let r = -2; r <= 2; r++) {
1157
- for (let c = -2; c <= 2; c++) {
1158
- matrix[row + r][col + c] = r === -2 || r === 2 || c === -2 || c === 2 || r === 0 && c === 0 ? 1 : 0;
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
- function fillData(matrix, hash) {
1163
- const size = matrix.length;
1164
- for (let r = 8; r < size - 8; r++) {
1165
- for (let c = 8; c < size - 8; c++) {
1166
- matrix[r][c] = hash * r * c % 5 < 2 ? 1 : 0;
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" }),