coinley-checkout 0.2.1 → 0.2.3

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,23 +1106,77 @@ 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"/>`;
1119
+ }
1120
+ }
1121
+ }
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;
1135
+ }
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;
1145
+ }
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;
1152
+ }
1153
+ }
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;
1159
+ }
1160
+ }
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;
1167
+ }
1168
+ }
1169
+ }
1109
1170
  const QRCode = ({
1110
1171
  walletAddress,
1111
1172
  amount,
1112
1173
  currency,
1113
1174
  theme = "light"
1114
1175
  }) => {
1115
- const qrCodeUrl = `https://chart.googleapis.com/chart?cht=qr&chs=200x200&chl=${encodeURIComponent(`${currency}:${walletAddress}?amount=${amount}`)}&choe=UTF-8`;
1176
+ const qrData = `${currency}:${walletAddress}?amount=${amount}`;
1177
+ const qrSvg = renderQR(qrData, 200);
1116
1178
  return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex flex-col items-center", children: [
1117
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "p-4 rounded-lg bg-white mb-3", children: /* @__PURE__ */ jsxRuntimeExports.jsx(
1118
- "img",
1119
- {
1120
- src: qrCodeUrl,
1121
- alt: `QR Code for ${currency} payment`,
1122
- width: "200",
1123
- height: "200"
1124
- }
1125
- ) }),
1179
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "p-4 rounded-lg bg-white mb-3", children: /* @__PURE__ */ jsxRuntimeExports.jsx("div", { dangerouslySetInnerHTML: { __html: qrSvg } }) }),
1126
1180
  /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-center text-sm text-gray-700", children: "Scan with your wallet app to pay" }),
1127
1181
  /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "mt-3 w-full", children: [
1128
1182
  /* @__PURE__ */ jsxRuntimeExports.jsxs("p", { className: "text-xs text-gray-500 mb-1", children: [
@@ -1132,8 +1186,23 @@ const QRCode = ({
1132
1186
  currency,
1133
1187
  " to:"
1134
1188
  ] }),
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
- ] })
1189
+ /* @__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" })
1190
+ ] }),
1191
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "mt-4 w-full", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "p-3 rounded bg-gray-100", children: [
1192
+ /* @__PURE__ */ jsxRuntimeExports.jsx("h4", { className: "text-sm font-medium mb-2 text-gray-800", children: "Payment Instructions" }),
1193
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("ol", { className: "text-xs space-y-2 text-gray-600", children: [
1194
+ /* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: "1. Open your crypto wallet app" }),
1195
+ /* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: "2. Scan the QR code above" }),
1196
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("li", { children: [
1197
+ "3. Confirm the payment amount (",
1198
+ amount,
1199
+ " ",
1200
+ currency,
1201
+ ")"
1202
+ ] }),
1203
+ /* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: '4. Click "Pay Now" button below after sending the payment' })
1204
+ ] })
1205
+ ] }) })
1137
1206
  ] });
1138
1207
  };
1139
1208
  const PaymentStatus = ({ status, message, theme = "light" }) => {