coinley-checkout 0.3.2 → 0.3.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.
@@ -1,441 +1,617 @@
1
- var qe = Object.defineProperty, He = Object.defineProperties;
2
- var $e = Object.getOwnPropertyDescriptors;
3
- var ge = Object.getOwnPropertySymbols;
4
- var Ke = Object.prototype.hasOwnProperty, Ve = Object.prototype.propertyIsEnumerable;
5
- var fe = (s, t, e) => t in s ? qe(s, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[t] = e, z = (s, t) => {
6
- for (var e in t || (t = {}))
7
- Ke.call(t, e) && fe(s, e, t[e]);
8
- if (ge)
9
- for (var e of ge(t))
10
- Ve.call(t, e) && fe(s, e, t[e]);
11
- return s;
12
- }, we = (s, t) => He(s, $e(t));
13
- var R = (s, t, e) => new Promise((i, c) => {
14
- var u = (r) => {
15
- try {
16
- x(e.next(r));
17
- } catch (n) {
18
- c(n);
19
- }
20
- }, y = (r) => {
21
- try {
22
- x(e.throw(r));
23
- } catch (n) {
24
- c(n);
25
- }
26
- }, x = (r) => r.done ? i(r.value) : Promise.resolve(r.value).then(u, y);
27
- x((e = e.apply(s, t)).next());
28
- });
29
- import L, { createContext as xe, useContext as ye, useState as D, useEffect as Z, forwardRef as _e, useImperativeHandle as Je } from "react";
30
- const b = {
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+ var __async = (__this, __arguments, generator) => {
21
+ return new Promise((resolve, reject) => {
22
+ var fulfilled = (value) => {
23
+ try {
24
+ step(generator.next(value));
25
+ } catch (e) {
26
+ reject(e);
27
+ }
28
+ };
29
+ var rejected = (value) => {
30
+ try {
31
+ step(generator.throw(value));
32
+ } catch (e) {
33
+ reject(e);
34
+ }
35
+ };
36
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
37
+ step((generator = generator.apply(__this, __arguments)).next());
38
+ });
39
+ };
40
+ import React, { createContext, useContext, useState, useEffect, forwardRef, useImperativeHandle } from "react";
41
+ const styles = "";
42
+ const NETWORK_TYPES = {
31
43
  ETHEREUM: "ethereum",
32
44
  BSC: "bsc",
33
45
  TRON: "tron",
34
46
  ALGORAND: "algorand"
35
- }, N = {
47
+ };
48
+ const WALLET_TYPES = {
36
49
  METAMASK: "metamask",
37
50
  TRONLINK: "tronlink",
38
51
  TRUST_WALLET: "trust_wallet",
39
52
  LUTE: "lute"
40
- }, de = {
41
- [b.ETHEREUM]: {
53
+ };
54
+ const NETWORK_CONFIG = {
55
+ [NETWORK_TYPES.ETHEREUM]: {
42
56
  chainId: "0x1",
43
57
  chainName: "Ethereum Mainnet",
44
58
  nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
45
59
  rpcUrls: ["https://mainnet.infura.io/v3/"],
46
60
  blockExplorerUrls: ["https://etherscan.io/"],
47
- supportedWallets: [N.METAMASK, N.TRUST_WALLET]
61
+ supportedWallets: [WALLET_TYPES.METAMASK, WALLET_TYPES.TRUST_WALLET]
48
62
  },
49
- [b.BSC]: {
63
+ [NETWORK_TYPES.BSC]: {
50
64
  chainId: "0x38",
51
65
  chainName: "BNB Smart Chain",
52
66
  nativeCurrency: { name: "BNB", symbol: "BNB", decimals: 18 },
53
67
  rpcUrls: ["https://bsc-dataseed.binance.org/"],
54
68
  blockExplorerUrls: ["https://bscscan.com/"],
55
- supportedWallets: [N.METAMASK, N.TRUST_WALLET]
69
+ supportedWallets: [WALLET_TYPES.METAMASK, WALLET_TYPES.TRUST_WALLET]
56
70
  },
57
- [b.TRON]: {
71
+ [NETWORK_TYPES.TRON]: {
58
72
  fullHost: "https://api.trongrid.io",
59
73
  explorerUrl: "https://tronscan.org",
60
- supportedWallets: [N.TRONLINK]
74
+ supportedWallets: [WALLET_TYPES.TRONLINK]
61
75
  },
62
- [b.ALGORAND]: {
76
+ [NETWORK_TYPES.ALGORAND]: {
63
77
  network: "mainnet",
64
78
  explorerUrl: "https://algoexplorer.io",
65
- supportedWallets: [N.LUTE]
79
+ supportedWallets: [WALLET_TYPES.LUTE]
66
80
  }
67
- }, Ye = {
81
+ };
82
+ const TOKEN_CONFIG = {
68
83
  USDT: {
69
- [b.ETHEREUM]: {
84
+ [NETWORK_TYPES.ETHEREUM]: {
70
85
  address: "0xdAC17F958D2ee523a2206206994597C13D831ec7",
71
86
  decimals: 6
72
87
  },
73
- [b.BSC]: {
88
+ [NETWORK_TYPES.BSC]: {
74
89
  address: "0x55d398326f99059fF775485246999027B3197955",
75
90
  decimals: 18
76
91
  },
77
- [b.TRON]: {
92
+ [NETWORK_TYPES.TRON]: {
78
93
  address: "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t",
79
94
  decimals: 6
95
+ },
96
+ [NETWORK_TYPES.ALGORAND]: {
97
+ address: "312769",
98
+ // USDT ASA ID on Algorand
99
+ decimals: 6
80
100
  }
81
101
  },
82
102
  USDC: {
83
- [b.ETHEREUM]: {
103
+ [NETWORK_TYPES.ETHEREUM]: {
84
104
  address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
85
105
  decimals: 6
86
106
  },
87
- [b.BSC]: {
107
+ [NETWORK_TYPES.BSC]: {
88
108
  address: "0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d",
89
109
  decimals: 18
90
110
  },
91
- [b.TRON]: {
111
+ [NETWORK_TYPES.TRON]: {
92
112
  address: "TEkxiTehnzSmSe2XqrBj4w32RUN966rdz8",
93
113
  decimals: 6
114
+ },
115
+ [NETWORK_TYPES.ALGORAND]: {
116
+ address: "31566704",
117
+ // USDC ASA ID on Algorand
118
+ decimals: 6
119
+ }
120
+ },
121
+ PYUSD: {
122
+ [NETWORK_TYPES.ETHEREUM]: {
123
+ address: "0x6c3ea9036406852006290770BEdFcAbA0e23A0e8",
124
+ decimals: 6
125
+ }
126
+ },
127
+ FRAX: {
128
+ [NETWORK_TYPES.ETHEREUM]: {
129
+ address: "0x853d955aCEf822Db058eb8505911ED77F175b99e",
130
+ decimals: 18
131
+ },
132
+ [NETWORK_TYPES.BSC]: {
133
+ address: "0x90C97F71E18723b0Cf0dfa30ee176Ab653E89F40",
134
+ decimals: 18
135
+ }
136
+ },
137
+ USDP: {
138
+ [NETWORK_TYPES.ETHEREUM]: {
139
+ address: "0x8E870D67F660D95d5be530380D0eC0bd388289E1",
140
+ decimals: 18
141
+ }
142
+ },
143
+ DAI: {
144
+ [NETWORK_TYPES.ETHEREUM]: {
145
+ address: "0x6B175474E89094C44Da98b954EedeAC495271d0F",
146
+ decimals: 18
147
+ }
148
+ },
149
+ BUSD: {
150
+ [NETWORK_TYPES.BSC]: {
151
+ address: "0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56",
152
+ decimals: 18
153
+ }
154
+ },
155
+ USDJ: {
156
+ [NETWORK_TYPES.TRON]: {
157
+ address: "TMwFHYXLJaRUPeW6421aqXL4ZEzPRFGkGT",
158
+ decimals: 18
94
159
  }
95
160
  },
96
161
  ALGO: {
97
- [b.ALGORAND]: {
162
+ [NETWORK_TYPES.ALGORAND]: {
98
163
  address: "native",
99
164
  decimals: 6
100
165
  }
101
166
  }
102
167
  };
103
- let _ = null;
104
- const Xe = () => R(void 0, null, function* () {
105
- if (_)
106
- return _;
168
+ let Web3Cache = null;
169
+ const getWeb3Instance = () => __async(void 0, null, function* () {
170
+ if (Web3Cache) {
171
+ return Web3Cache;
172
+ }
107
173
  try {
108
- if (typeof window != "undefined" && window.Web3)
109
- return _ = window.Web3, _;
110
- const s = yield import("web3");
111
- return _ = s.default || s.Web3 || s, _;
112
- } catch (s) {
113
- throw console.error("Failed to load Web3:", s), new Error("Web3 is required for blockchain transactions. Please ensure web3 is installed: npm install web3");
174
+ if (typeof window !== "undefined" && window.Web3) {
175
+ Web3Cache = window.Web3;
176
+ return Web3Cache;
177
+ }
178
+ const Web3Module = yield import("web3");
179
+ Web3Cache = Web3Module.default || Web3Module.Web3 || Web3Module;
180
+ return Web3Cache;
181
+ } catch (error) {
182
+ console.error("Failed to load Web3:", error);
183
+ throw new Error("Web3 is required for blockchain transactions. Please ensure web3 is installed: npm install web3");
114
184
  }
115
- }), ue = () => {
116
- const s = {
117
- [N.METAMASK]: !1,
118
- [N.TRUST_WALLET]: !1,
119
- [N.TRONLINK]: !1,
120
- [N.LUTE]: !1
185
+ });
186
+ const detectWallets = () => {
187
+ const wallets = {
188
+ [WALLET_TYPES.METAMASK]: false,
189
+ [WALLET_TYPES.TRUST_WALLET]: false,
190
+ [WALLET_TYPES.TRONLINK]: false,
191
+ [WALLET_TYPES.LUTE]: false
121
192
  };
122
- if (typeof window == "undefined")
123
- return s;
193
+ if (typeof window === "undefined") {
194
+ return wallets;
195
+ }
124
196
  try {
125
- s[N.METAMASK] = !!(window.ethereum && window.ethereum.isMetaMask), s[N.TRONLINK] = !!window.tronWeb, s[N.TRUST_WALLET] = !!(window.ethereum && window.ethereum.isTrust), s[N.LUTE] = !!(window.algorand && window.algorand.isLute);
126
- } catch (t) {
127
- console.warn("Error detecting wallets:", t);
197
+ wallets[WALLET_TYPES.METAMASK] = !!(window.ethereum && window.ethereum.isMetaMask);
198
+ wallets[WALLET_TYPES.TRONLINK] = !!window.tronWeb;
199
+ wallets[WALLET_TYPES.TRUST_WALLET] = !!(window.ethereum && window.ethereum.isTrust);
200
+ wallets[WALLET_TYPES.LUTE] = !!(window.algorand && window.algorand.isLute);
201
+ } catch (error) {
202
+ console.warn("Error detecting wallets:", error);
128
203
  }
129
- return s;
130
- }, Ze = (s) => {
131
- const t = de[s];
132
- if (!t)
204
+ return wallets;
205
+ };
206
+ const getSupportedWalletsForNetwork = (network) => {
207
+ const networkConfig = NETWORK_CONFIG[network];
208
+ if (!networkConfig)
133
209
  return [];
134
- const e = ue();
135
- return t.supportedWallets.filter((i) => e[i]);
136
- }, et = (s, t) => R(void 0, null, function* () {
137
- switch (s) {
138
- case N.METAMASK:
139
- return yield tt(t);
140
- case N.TRONLINK:
141
- return yield rt();
142
- case N.TRUST_WALLET:
143
- return yield st(t);
144
- case N.LUTE:
145
- return yield nt();
210
+ const availableWallets = detectWallets();
211
+ return networkConfig.supportedWallets.filter((wallet) => availableWallets[wallet]);
212
+ };
213
+ const connectWallet = (walletType, network) => __async(void 0, null, function* () {
214
+ switch (walletType) {
215
+ case WALLET_TYPES.METAMASK:
216
+ return yield connectMetaMask(network);
217
+ case WALLET_TYPES.TRONLINK:
218
+ return yield connectTronLink();
219
+ case WALLET_TYPES.TRUST_WALLET:
220
+ return yield connectTrustWallet(network);
221
+ case WALLET_TYPES.LUTE:
222
+ return yield connectLute();
146
223
  default:
147
- throw new Error(`Unsupported wallet type: ${s}`);
224
+ throw new Error(`Unsupported wallet type: ${walletType}`);
148
225
  }
149
- }), tt = (s) => R(void 0, null, function* () {
150
- if (typeof window == "undefined" || !window.ethereum || !window.ethereum.isMetaMask)
226
+ });
227
+ const connectMetaMask = (network) => __async(void 0, null, function* () {
228
+ if (typeof window === "undefined" || !window.ethereum || !window.ethereum.isMetaMask) {
151
229
  throw new Error("MetaMask is not installed. Please install MetaMask extension.");
230
+ }
152
231
  try {
153
- const t = yield window.ethereum.request({
232
+ const accounts = yield window.ethereum.request({
154
233
  method: "eth_requestAccounts"
155
234
  });
156
- if (!t || t.length === 0)
235
+ if (!accounts || accounts.length === 0) {
157
236
  throw new Error("No accounts found. Please unlock MetaMask.");
158
- const e = de[s];
159
- return e && e.chainId && (yield be(e)), {
160
- address: t[0],
161
- network: s,
162
- walletType: N.METAMASK
237
+ }
238
+ const networkConfig = NETWORK_CONFIG[network];
239
+ if (networkConfig && networkConfig.chainId) {
240
+ yield switchEVMNetwork(networkConfig);
241
+ }
242
+ return {
243
+ address: accounts[0],
244
+ network,
245
+ walletType: WALLET_TYPES.METAMASK
163
246
  };
164
- } catch (t) {
165
- throw t.code === 4001 ? new Error("User rejected the connection request") : new Error(`Failed to connect MetaMask: ${t.message}`);
247
+ } catch (error) {
248
+ if (error.code === 4001) {
249
+ throw new Error("User rejected the connection request");
250
+ }
251
+ throw new Error(`Failed to connect MetaMask: ${error.message}`);
166
252
  }
167
- }), rt = () => R(void 0, null, function* () {
168
- var i;
169
- if (typeof window == "undefined" || !window.tronWeb)
253
+ });
254
+ const connectTronLink = () => __async(void 0, null, function* () {
255
+ var _a;
256
+ if (typeof window === "undefined" || !window.tronWeb) {
170
257
  throw new Error("TronLink is not installed. Please install TronLink extension.");
171
- let s = 0;
172
- const t = 10;
173
- for (; !window.tronWeb.ready && s < t; )
174
- yield new Promise((c) => setTimeout(c, 1e3)), s++;
175
- if (!window.tronWeb.ready)
258
+ }
259
+ let attempts = 0;
260
+ const maxAttempts = 10;
261
+ while (!window.tronWeb.ready && attempts < maxAttempts) {
262
+ yield new Promise((resolve) => setTimeout(resolve, 1e3));
263
+ attempts++;
264
+ }
265
+ if (!window.tronWeb.ready) {
176
266
  throw new Error("TronLink is not ready. Please unlock your TronLink wallet and try again.");
177
- const e = (i = window.tronWeb.defaultAddress) == null ? void 0 : i.base58;
178
- if (!e)
267
+ }
268
+ const address = (_a = window.tronWeb.defaultAddress) == null ? void 0 : _a.base58;
269
+ if (!address) {
179
270
  throw new Error("No account found in TronLink. Please make sure you have an account set up.");
271
+ }
180
272
  return {
181
- address: e,
182
- network: b.TRON,
183
- walletType: N.TRONLINK
273
+ address,
274
+ network: NETWORK_TYPES.TRON,
275
+ walletType: WALLET_TYPES.TRONLINK
184
276
  };
185
- }), st = (s) => R(void 0, null, function* () {
186
- if (typeof window == "undefined" || !window.ethereum || !window.ethereum.isTrust)
277
+ });
278
+ const connectTrustWallet = (network) => __async(void 0, null, function* () {
279
+ if (typeof window === "undefined" || !window.ethereum || !window.ethereum.isTrust) {
187
280
  throw new Error("Trust Wallet is not installed. Please install Trust Wallet extension.");
281
+ }
188
282
  try {
189
- const t = yield window.ethereum.request({
283
+ const accounts = yield window.ethereum.request({
190
284
  method: "eth_requestAccounts"
191
285
  });
192
- if (!t || t.length === 0)
286
+ if (!accounts || accounts.length === 0) {
193
287
  throw new Error("No accounts found. Please unlock Trust Wallet.");
194
- const e = de[s];
195
- return e && e.chainId && (yield be(e)), {
196
- address: t[0],
197
- network: s,
198
- walletType: N.TRUST_WALLET
288
+ }
289
+ const networkConfig = NETWORK_CONFIG[network];
290
+ if (networkConfig && networkConfig.chainId) {
291
+ yield switchEVMNetwork(networkConfig);
292
+ }
293
+ return {
294
+ address: accounts[0],
295
+ network,
296
+ walletType: WALLET_TYPES.TRUST_WALLET
199
297
  };
200
- } catch (t) {
201
- throw t.code === 4001 ? new Error("User rejected the connection request") : new Error(`Failed to connect Trust Wallet: ${t.message}`);
298
+ } catch (error) {
299
+ if (error.code === 4001) {
300
+ throw new Error("User rejected the connection request");
301
+ }
302
+ throw new Error(`Failed to connect Trust Wallet: ${error.message}`);
202
303
  }
203
- }), nt = () => R(void 0, null, function* () {
204
- if (typeof window == "undefined" || !window.algorand || !window.algorand.isLute)
304
+ });
305
+ const connectLute = () => __async(void 0, null, function* () {
306
+ if (typeof window === "undefined" || !window.algorand || !window.algorand.isLute) {
205
307
  throw new Error("Lute wallet is not installed. Please install Lute wallet extension.");
308
+ }
206
309
  try {
207
- const s = yield window.algorand.connect();
208
- if (!s || s.length === 0)
310
+ const accounts = yield window.algorand.connect();
311
+ if (!accounts || accounts.length === 0) {
209
312
  throw new Error("No accounts found. Please unlock Lute wallet.");
313
+ }
210
314
  return {
211
- address: s[0],
212
- network: b.ALGORAND,
213
- walletType: N.LUTE
315
+ address: accounts[0],
316
+ network: NETWORK_TYPES.ALGORAND,
317
+ walletType: WALLET_TYPES.LUTE
214
318
  };
215
- } catch (s) {
216
- throw new Error(`Failed to connect Lute wallet: ${s.message}`);
319
+ } catch (error) {
320
+ throw new Error(`Failed to connect Lute wallet: ${error.message}`);
217
321
  }
218
- }), be = (s) => R(void 0, null, function* () {
219
- if (typeof window == "undefined" || !window.ethereum)
322
+ });
323
+ const switchEVMNetwork = (networkConfig) => __async(void 0, null, function* () {
324
+ if (typeof window === "undefined" || !window.ethereum) {
220
325
  throw new Error("Ethereum provider not found");
326
+ }
221
327
  try {
222
328
  yield window.ethereum.request({
223
329
  method: "wallet_switchEthereumChain",
224
- params: [{ chainId: s.chainId }]
330
+ params: [{ chainId: networkConfig.chainId }]
225
331
  });
226
- } catch (t) {
227
- if (t.code === 4902)
332
+ } catch (switchError) {
333
+ if (switchError.code === 4902) {
228
334
  try {
229
335
  yield window.ethereum.request({
230
336
  method: "wallet_addEthereumChain",
231
- params: [s]
337
+ params: [networkConfig]
232
338
  });
233
- } catch (e) {
234
- throw new Error(`Failed to add ${s.chainName} to wallet: ${e.message}`);
339
+ } catch (addError) {
340
+ throw new Error(`Failed to add ${networkConfig.chainName} to wallet: ${addError.message}`);
235
341
  }
236
- else
237
- throw t.code === 4001 ? new Error("User rejected network switch request") : new Error(`Failed to switch to ${s.chainName}: ${t.message}`);
342
+ } else if (switchError.code === 4001) {
343
+ throw new Error("User rejected network switch request");
344
+ } else {
345
+ throw new Error(`Failed to switch to ${networkConfig.chainName}: ${switchError.message}`);
346
+ }
238
347
  }
239
- }), ot = (s, t) => R(void 0, null, function* () {
240
- const { walletType: e, network: i, address: c } = s, { to: u, amount: y, tokenAddress: x, tokenDecimals: r } = t;
241
- switch (e) {
242
- case N.METAMASK:
243
- case N.TRUST_WALLET:
244
- return yield at(c, u, y, x, r);
245
- case N.TRONLINK:
246
- return yield it(u, y, x, r);
247
- case N.LUTE:
248
- return yield lt(c, u, y);
348
+ });
349
+ const sendTransaction = (walletConnection, transactionData) => __async(void 0, null, function* () {
350
+ const { walletType, network, address } = walletConnection;
351
+ const { to, amount, tokenAddress, tokenDecimals } = transactionData;
352
+ switch (walletType) {
353
+ case WALLET_TYPES.METAMASK:
354
+ case WALLET_TYPES.TRUST_WALLET:
355
+ return yield sendEVMTransaction(address, to, amount, tokenAddress, tokenDecimals);
356
+ case WALLET_TYPES.TRONLINK:
357
+ return yield sendTronTransaction(to, amount, tokenAddress, tokenDecimals);
358
+ case WALLET_TYPES.LUTE:
359
+ return yield sendAlgorandTransaction(address, to, amount);
249
360
  default:
250
- throw new Error(`Unsupported wallet type: ${e}`);
361
+ throw new Error(`Unsupported wallet type: ${walletType}`);
251
362
  }
252
- }), at = (s, t, e, i, c) => R(void 0, null, function* () {
253
- if (typeof window == "undefined" || !window.ethereum)
363
+ });
364
+ const sendEVMTransaction = (from, to, amount, tokenAddress, tokenDecimals) => __async(void 0, null, function* () {
365
+ if (typeof window === "undefined" || !window.ethereum) {
254
366
  throw new Error("Ethereum provider not found");
367
+ }
255
368
  try {
256
- const u = yield Xe(), y = new u(window.ethereum), x = y.utils.toBN(
257
- Math.floor(parseFloat(e) * Math.pow(10, c || 18))
369
+ const Web3 = yield getWeb3Instance();
370
+ const web3 = new Web3(window.ethereum);
371
+ const amountInWei = web3.utils.toBN(
372
+ Math.floor(parseFloat(amount) * Math.pow(10, tokenDecimals || 18))
258
373
  );
259
- if (i && i !== "native") {
260
- const r = [
374
+ if (tokenAddress && tokenAddress !== "native") {
375
+ const tokenABI = [
261
376
  {
262
- constant: !1,
377
+ constant: false,
263
378
  inputs: [
264
379
  { name: "_to", type: "address" },
265
380
  { name: "_value", type: "uint256" }
266
381
  ],
267
382
  name: "transfer",
268
383
  outputs: [{ name: "", type: "bool" }],
269
- payable: !1,
384
+ payable: false,
270
385
  stateMutability: "nonpayable",
271
386
  type: "function"
272
387
  }
273
388
  ];
274
- return (yield new y.eth.Contract(r, i).methods.transfer(t, x).send({ from: s })).transactionHash;
275
- } else
276
- return (yield y.eth.sendTransaction({
277
- from: s,
278
- to: t,
279
- value: x
280
- })).transactionHash;
281
- } catch (u) {
282
- throw u.code === 4001 ? new Error("Transaction was rejected by user") : new Error(`Transaction failed: ${u.message}`);
389
+ const contract = new web3.eth.Contract(tokenABI, tokenAddress);
390
+ const receipt = yield contract.methods.transfer(to, amountInWei).send({ from });
391
+ return receipt.transactionHash;
392
+ } else {
393
+ const receipt = yield web3.eth.sendTransaction({
394
+ from,
395
+ to,
396
+ value: amountInWei
397
+ });
398
+ return receipt.transactionHash;
399
+ }
400
+ } catch (error) {
401
+ if (error.code === 4001) {
402
+ throw new Error("Transaction was rejected by user");
403
+ }
404
+ throw new Error(`Transaction failed: ${error.message}`);
283
405
  }
284
- }), it = (s, t, e, i) => R(void 0, null, function* () {
285
- if (typeof window == "undefined" || !window.tronWeb || !window.tronWeb.ready)
406
+ });
407
+ const sendTronTransaction = (to, amount, tokenAddress, tokenDecimals) => __async(void 0, null, function* () {
408
+ if (typeof window === "undefined" || !window.tronWeb || !window.tronWeb.ready) {
286
409
  throw new Error("TronLink is not ready");
410
+ }
287
411
  try {
288
- const c = Math.floor(parseFloat(t) * Math.pow(10, i || 6));
289
- return e && e !== "native" ? yield (yield window.tronWeb.contract().at(e)).transfer(s, c).send({
290
- feeLimit: 1e8,
291
- callValue: 0
292
- }) : (yield window.tronWeb.trx.sendTransaction(s, c)).txid;
293
- } catch (c) {
294
- throw new Error(`TRON transaction failed: ${c.message}`);
412
+ const amountInSun = Math.floor(parseFloat(amount) * Math.pow(10, tokenDecimals || 6));
413
+ if (tokenAddress && tokenAddress !== "native") {
414
+ const contract = yield window.tronWeb.contract().at(tokenAddress);
415
+ const result = yield contract.transfer(to, amountInSun).send({
416
+ feeLimit: 1e8,
417
+ callValue: 0
418
+ });
419
+ return result;
420
+ } else {
421
+ const result = yield window.tronWeb.trx.sendTransaction(to, amountInSun);
422
+ return result.txid;
423
+ }
424
+ } catch (error) {
425
+ throw new Error(`TRON transaction failed: ${error.message}`);
295
426
  }
296
- }), lt = (s, t, e) => R(void 0, null, function* () {
297
- if (typeof window == "undefined" || !window.algorand)
427
+ });
428
+ const sendAlgorandTransaction = (from, to, amount) => __async(void 0, null, function* () {
429
+ if (typeof window === "undefined" || !window.algorand) {
298
430
  throw new Error("Algorand wallet is not available");
431
+ }
299
432
  try {
300
- const i = Math.floor(parseFloat(e) * 1e6), c = {
301
- from: s,
302
- to: t,
303
- amount: i,
433
+ const microAlgos = Math.floor(parseFloat(amount) * 1e6);
434
+ const txn = {
435
+ from,
436
+ to,
437
+ amount: microAlgos,
304
438
  type: "pay"
305
- }, u = yield window.algorand.signTransaction(c);
306
- return (yield window.algorand.sendTransaction(u)).txId;
307
- } catch (i) {
308
- throw new Error(`Algorand transaction failed: ${i.message}`);
439
+ };
440
+ const signedTxn = yield window.algorand.signTransaction(txn);
441
+ const result = yield window.algorand.sendTransaction(signedTxn);
442
+ return result.txId;
443
+ } catch (error) {
444
+ throw new Error(`Algorand transaction failed: ${error.message}`);
309
445
  }
310
- }), ct = (s) => ({
311
- [N.METAMASK]: "https://metamask.io/",
312
- [N.TRONLINK]: "https://www.tronlink.org/",
313
- [N.TRUST_WALLET]: "https://trustwallet.com/",
314
- [N.LUTE]: "https://lute.app/"
315
- })[s] || "";
316
- let U = {
446
+ });
447
+ const getWalletInstallUrl = (walletType) => {
448
+ const urls = {
449
+ [WALLET_TYPES.METAMASK]: "https://metamask.io/",
450
+ [WALLET_TYPES.TRONLINK]: "https://www.tronlink.org/",
451
+ [WALLET_TYPES.TRUST_WALLET]: "https://trustwallet.com/",
452
+ [WALLET_TYPES.LUTE]: "https://lute.app/"
453
+ };
454
+ return urls[walletType] || "";
455
+ };
456
+ let apiConfig = {
317
457
  apiKey: null,
318
458
  apiSecret: null,
319
459
  apiUrl: "http://localhost:9000",
320
460
  merchantWalletAddresses: {}
321
461
  // Changed to object for multi-network support
322
462
  };
323
- const dt = (s) => {
324
- U = z(z({}, U), s), console.log("API initialized with:", {
325
- apiUrl: U.apiUrl,
326
- apiKey: U.apiKey ? `${U.apiKey.substring(0, 6)}...` : null,
327
- hasWalletAddresses: Object.keys(U.merchantWalletAddresses || {}).length > 0
463
+ const initializeApi = (config) => {
464
+ apiConfig = __spreadValues(__spreadValues({}, apiConfig), config);
465
+ console.log("API initialized with:", {
466
+ apiUrl: apiConfig.apiUrl,
467
+ apiKey: apiConfig.apiKey ? `${apiConfig.apiKey.substring(0, 6)}...` : null,
468
+ hasWalletAddresses: Object.keys(apiConfig.merchantWalletAddresses || {}).length > 0
328
469
  });
329
- }, Y = () => ({
330
- "Content-Type": "application/json",
331
- "x-api-key": U.apiKey,
332
- "x-api-secret": U.apiSecret
333
- }), ut = (s) => R(void 0, null, function* () {
470
+ };
471
+ const getHeaders = () => {
472
+ return {
473
+ "Content-Type": "application/json",
474
+ "x-api-key": apiConfig.apiKey,
475
+ "x-api-secret": apiConfig.apiSecret
476
+ };
477
+ };
478
+ const createPayment = (paymentData) => __async(void 0, null, function* () {
334
479
  try {
335
- console.log("Creating payment with data:", s), console.log("API URL:", `${U.apiUrl}/api/payments/create`);
336
- const t = we(z({}, s), {
337
- merchantWalletAddresses: z(z({}, U.merchantWalletAddresses), s.merchantWalletAddresses)
338
- }), e = yield fetch(`${U.apiUrl}/api/payments/create`, {
480
+ console.log("Creating payment with data:", paymentData);
481
+ console.log("API URL:", `${apiConfig.apiUrl}/api/payments/create`);
482
+ const enhancedPaymentData = __spreadProps(__spreadValues({}, paymentData), {
483
+ merchantWalletAddresses: __spreadValues(__spreadValues({}, apiConfig.merchantWalletAddresses), paymentData.merchantWalletAddresses)
484
+ });
485
+ const response = yield fetch(`${apiConfig.apiUrl}/api/payments/create`, {
339
486
  method: "POST",
340
- headers: Y(),
341
- body: JSON.stringify(t)
487
+ headers: getHeaders(),
488
+ body: JSON.stringify(enhancedPaymentData)
342
489
  });
343
- if (console.log("Create payment response status:", e.status), !e.ok) {
344
- const c = yield e.json();
345
- throw console.error("Error creating payment:", c), new Error(c.error || `Failed to create payment: ${e.status}`);
346
- }
347
- const i = yield e.json();
348
- return console.log("Create payment response data:", i), i;
349
- } catch (t) {
350
- throw console.error("Create payment error:", t), t;
490
+ console.log("Create payment response status:", response.status);
491
+ if (!response.ok) {
492
+ const errorData = yield response.json();
493
+ console.error("Error creating payment:", errorData);
494
+ throw new Error(errorData.error || `Failed to create payment: ${response.status}`);
495
+ }
496
+ const data = yield response.json();
497
+ console.log("Create payment response data:", data);
498
+ return data;
499
+ } catch (error) {
500
+ console.error("Create payment error:", error);
501
+ throw error;
351
502
  }
352
- }), Bt = (s) => R(void 0, null, function* () {
503
+ });
504
+ const getPayment = (paymentId) => __async(void 0, null, function* () {
353
505
  try {
354
- console.log("Getting payment:", s);
355
- const t = yield fetch(`${U.apiUrl}/api/payments/${s}`, {
506
+ console.log("Getting payment:", paymentId);
507
+ const response = yield fetch(`${apiConfig.apiUrl}/api/payments/${paymentId}`, {
356
508
  method: "GET",
357
- headers: Y()
509
+ headers: getHeaders()
358
510
  });
359
- if (!t.ok) {
360
- const i = yield t.json();
361
- throw console.error("Error getting payment:", i), new Error(i.error || `Failed to get payment: ${t.status}`);
362
- }
363
- const e = yield t.json();
364
- return console.log("Get payment response:", e), e;
365
- } catch (t) {
366
- throw console.error("Get payment error:", t), t;
511
+ if (!response.ok) {
512
+ const errorData = yield response.json();
513
+ console.error("Error getting payment:", errorData);
514
+ throw new Error(errorData.error || `Failed to get payment: ${response.status}`);
515
+ }
516
+ const data = yield response.json();
517
+ console.log("Get payment response:", data);
518
+ return data;
519
+ } catch (error) {
520
+ console.error("Get payment error:", error);
521
+ throw error;
367
522
  }
368
- }), ht = (s) => R(void 0, null, function* () {
523
+ });
524
+ const processPayment = (processData) => __async(void 0, null, function* () {
369
525
  try {
370
- console.log("Processing payment with data:", s), console.log("API URL:", `${U.apiUrl}/api/payments/process`);
371
- const t = yield fetch(`${U.apiUrl}/api/payments/process`, {
526
+ console.log("Processing payment with data:", processData);
527
+ console.log("API URL:", `${apiConfig.apiUrl}/api/payments/process`);
528
+ const response = yield fetch(`${apiConfig.apiUrl}/api/payments/process`, {
372
529
  method: "POST",
373
- headers: Y(),
374
- body: JSON.stringify(s)
530
+ headers: getHeaders(),
531
+ body: JSON.stringify(processData)
375
532
  });
376
- if (console.log("Process payment response status:", t.status), !t.ok) {
377
- const i = yield t.json();
378
- throw console.error("Error processing payment:", i), new Error(i.error || `Failed to process payment: ${t.status}`);
379
- }
380
- const e = yield t.json();
381
- return console.log("Process payment response data:", e), e;
382
- } catch (t) {
383
- throw console.error("Process payment error:", t), t;
533
+ console.log("Process payment response status:", response.status);
534
+ if (!response.ok) {
535
+ const errorData = yield response.json();
536
+ console.error("Error processing payment:", errorData);
537
+ throw new Error(errorData.error || `Failed to process payment: ${response.status}`);
538
+ }
539
+ const data = yield response.json();
540
+ console.log("Process payment response data:", data);
541
+ return data;
542
+ } catch (error) {
543
+ console.error("Process payment error:", error);
544
+ throw error;
384
545
  }
385
- }), Wt = () => R(void 0, null, function* () {
546
+ });
547
+ const getSupportedNetworks = () => __async(void 0, null, function* () {
386
548
  try {
387
- const s = yield fetch(`${U.apiUrl}/api/networks`, {
549
+ const response = yield fetch(`${apiConfig.apiUrl}/api/networks`, {
388
550
  method: "GET",
389
- headers: Y()
551
+ headers: getHeaders()
390
552
  });
391
- if (!s.ok) {
392
- const e = yield s.json();
393
- throw new Error(e.error || `Failed to get networks: ${s.status}`);
394
- }
395
- return yield s.json();
396
- } catch (s) {
397
- throw console.error("Get supported networks error:", s), s;
553
+ if (!response.ok) {
554
+ const errorData = yield response.json();
555
+ throw new Error(errorData.error || `Failed to get networks: ${response.status}`);
556
+ }
557
+ const data = yield response.json();
558
+ return data;
559
+ } catch (error) {
560
+ console.error("Get supported networks error:", error);
561
+ throw error;
398
562
  }
399
- }), Qt = () => R(void 0, null, function* () {
563
+ });
564
+ const getMerchantProfile = () => __async(void 0, null, function* () {
400
565
  try {
401
- const s = yield fetch(`${U.apiUrl}/api/merchants/profile`, {
566
+ const response = yield fetch(`${apiConfig.apiUrl}/api/merchants/profile`, {
402
567
  method: "GET",
403
- headers: Y()
568
+ headers: getHeaders()
404
569
  });
405
- if (!s.ok) {
406
- const e = yield s.json();
407
- throw new Error(e.error || `Failed to get merchant profile: ${s.status}`);
408
- }
409
- const t = yield s.json();
410
- return t.merchant && t.merchant.walletAddresses && (U.merchantWalletAddresses = z(z({}, U.merchantWalletAddresses), t.merchant.walletAddresses)), t;
411
- } catch (s) {
412
- throw console.error("Get merchant profile error:", s), s;
570
+ if (!response.ok) {
571
+ const errorData = yield response.json();
572
+ throw new Error(errorData.error || `Failed to get merchant profile: ${response.status}`);
573
+ }
574
+ const data = yield response.json();
575
+ if (data.merchant && data.merchant.walletAddresses) {
576
+ apiConfig.merchantWalletAddresses = __spreadValues(__spreadValues({}, apiConfig.merchantWalletAddresses), data.merchant.walletAddresses);
577
+ }
578
+ return data;
579
+ } catch (error) {
580
+ console.error("Get merchant profile error:", error);
581
+ throw error;
413
582
  }
414
- }), zt = (s, t) => R(void 0, null, function* () {
583
+ });
584
+ const validateWalletAddress = (address, network) => __async(void 0, null, function* () {
415
585
  try {
416
- const e = yield fetch(`${U.apiUrl}/api/wallets/validate`, {
586
+ const response = yield fetch(`${apiConfig.apiUrl}/api/wallets/validate`, {
417
587
  method: "POST",
418
- headers: Y(),
419
- body: JSON.stringify({ address: s, network: t })
588
+ headers: getHeaders(),
589
+ body: JSON.stringify({ address, network })
420
590
  });
421
- if (!e.ok) {
422
- const c = yield e.json();
423
- throw new Error(c.error || `Failed to validate address: ${e.status}`);
424
- }
425
- return yield e.json();
426
- } catch (e) {
427
- throw console.error("Validate wallet address error:", e), e;
591
+ if (!response.ok) {
592
+ const errorData = yield response.json();
593
+ throw new Error(errorData.error || `Failed to validate address: ${response.status}`);
594
+ }
595
+ const data = yield response.json();
596
+ return data;
597
+ } catch (error) {
598
+ console.error("Validate wallet address error:", error);
599
+ throw error;
428
600
  }
429
- }), Gt = (s = "ethereum") => {
430
- const e = {
601
+ });
602
+ const generateMockTransactionHash = (network = "ethereum") => {
603
+ const prefixes = {
431
604
  ethereum: "0x",
432
605
  bsc: "0x",
433
606
  tron: "",
434
607
  algorand: ""
435
- }[s] || "0x", i = Array.from({ length: 64 }, () => Math.floor(Math.random() * 16).toString(16)).join("");
436
- return `${e}${i}`;
608
+ };
609
+ const prefix = prefixes[network] || "0x";
610
+ const hash = Array.from({ length: 64 }, () => Math.floor(Math.random() * 16).toString(16)).join("");
611
+ return `${prefix}${hash}`;
437
612
  };
438
- var Ne = { exports: {} }, ne = {};
613
+ var jsxRuntime = { exports: {} };
614
+ var reactJsxRuntime_production_min = {};
439
615
  /**
440
616
  * @license React
441
617
  * react-jsx-runtime.production.min.js
@@ -445,129 +621,182 @@ var Ne = { exports: {} }, ne = {};
445
621
  * This source code is licensed under the MIT license found in the
446
622
  * LICENSE file in the root directory of this source tree.
447
623
  */
448
- var mt = L, gt = Symbol.for("react.element"), ft = Symbol.for("react.fragment"), wt = Object.prototype.hasOwnProperty, pt = mt.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, xt = { key: !0, ref: !0, __self: !0, __source: !0 };
449
- function Ee(s, t, e) {
450
- var i, c = {}, u = null, y = null;
451
- e !== void 0 && (u = "" + e), t.key !== void 0 && (u = "" + t.key), t.ref !== void 0 && (y = t.ref);
452
- for (i in t)
453
- wt.call(t, i) && !xt.hasOwnProperty(i) && (c[i] = t[i]);
454
- if (s && s.defaultProps)
455
- for (i in t = s.defaultProps, t)
456
- c[i] === void 0 && (c[i] = t[i]);
457
- return { $$typeof: gt, type: s, key: u, ref: y, props: c, _owner: pt.current };
624
+ var f = React, k = Symbol.for("react.element"), l = Symbol.for("react.fragment"), m = Object.prototype.hasOwnProperty, n = f.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, p = { key: true, ref: true, __self: true, __source: true };
625
+ function q(c, a, g) {
626
+ var b, d = {}, e = null, h = null;
627
+ void 0 !== g && (e = "" + g);
628
+ void 0 !== a.key && (e = "" + a.key);
629
+ void 0 !== a.ref && (h = a.ref);
630
+ for (b in a)
631
+ m.call(a, b) && !p.hasOwnProperty(b) && (d[b] = a[b]);
632
+ if (c && c.defaultProps)
633
+ for (b in a = c.defaultProps, a)
634
+ void 0 === d[b] && (d[b] = a[b]);
635
+ return { $$typeof: k, type: c, key: e, ref: h, props: d, _owner: n.current };
458
636
  }
459
- ne.Fragment = ft;
460
- ne.jsx = Ee;
461
- ne.jsxs = Ee;
462
- Ne.exports = ne;
463
- var o = Ne.exports;
464
- const ve = xe(), yt = () => ye(ve), qt = ({ initialTheme: s = "light", children: t }) => {
465
- const [e, i] = D(s), c = () => {
466
- i((u) => u === "light" ? "dark" : "light");
637
+ reactJsxRuntime_production_min.Fragment = l;
638
+ reactJsxRuntime_production_min.jsx = q;
639
+ reactJsxRuntime_production_min.jsxs = q;
640
+ {
641
+ jsxRuntime.exports = reactJsxRuntime_production_min;
642
+ }
643
+ var jsxRuntimeExports = jsxRuntime.exports;
644
+ const ThemeContext = createContext();
645
+ const useTheme = () => useContext(ThemeContext);
646
+ const ThemeProvider = ({ initialTheme = "light", children }) => {
647
+ const [theme, setTheme] = useState(initialTheme);
648
+ const toggleTheme = () => {
649
+ setTheme((prevTheme) => prevTheme === "light" ? "dark" : "light");
467
650
  };
468
- return Z(() => {
469
- document.documentElement.classList.remove("light", "dark"), document.documentElement.classList.add(e);
470
- }, [e]), /* @__PURE__ */ o.jsx(ve.Provider, { value: { theme: e, setTheme: i, toggleTheme: c }, children: t });
471
- }, ke = xe(), bt = () => ye(ke), Ht = ({
472
- apiKey: s,
473
- apiSecret: t,
474
- apiUrl: e = "http://localhost:9000",
475
- merchantWalletAddress: i = null,
651
+ useEffect(() => {
652
+ document.documentElement.classList.remove("light", "dark");
653
+ document.documentElement.classList.add(theme);
654
+ }, [theme]);
655
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(ThemeContext.Provider, { value: { theme, setTheme, toggleTheme }, children });
656
+ };
657
+ const CoinleyContext = createContext();
658
+ const useCoinley = () => useContext(CoinleyContext);
659
+ const CoinleyProvider = ({
660
+ apiKey,
661
+ apiSecret,
662
+ apiUrl = "http://localhost:9000",
663
+ merchantWalletAddress = null,
476
664
  // New prop for merchant wallet address
477
- merchantSolWalletAddress: c = null,
665
+ merchantSolWalletAddress = null,
478
666
  // New prop for Solana wallet address
479
- debug: u = !1,
480
- children: y
667
+ debug = false,
668
+ children
481
669
  }) => {
482
- const [x, r] = D(!1), [n, a] = D(null), [l, d] = D(null);
483
- Z(() => {
484
- if (!s || !t) {
485
- a("API key and secret are required");
670
+ const [isInitialized, setIsInitialized] = useState(false);
671
+ const [error, setError] = useState(null);
672
+ const [paymentData, setPaymentData] = useState(null);
673
+ useEffect(() => {
674
+ if (!apiKey || !apiSecret) {
675
+ setError("API key and secret are required");
486
676
  return;
487
677
  }
488
678
  try {
489
- dt({
490
- apiKey: s,
491
- apiSecret: t,
492
- apiUrl: e,
493
- merchantWalletAddress: i,
679
+ initializeApi({
680
+ apiKey,
681
+ apiSecret,
682
+ apiUrl,
683
+ merchantWalletAddress,
494
684
  // Pass wallet address to API service
495
- merchantSolWalletAddress: c
496
- }), r(!0), u && console.log("Coinley SDK initialized with:", {
497
- apiKey: s,
498
- apiUrl: e,
499
- merchantWalletAddress: i ? `${i.substring(0, 6)}...${i.substring(i.length - 4)}` : "Not provided",
500
- merchantSolWalletAddress: c ? `${c.substring(0, 6)}...${c.substring(c.length - 4)}` : "Not provided"
685
+ merchantSolWalletAddress
501
686
  });
502
- } catch (m) {
503
- a(m.message), u && console.error("Coinley SDK initialization error:", m);
504
- }
505
- }, [s, t, e, i, c, u]);
506
- const h = {
507
- apiKey: s,
508
- apiSecret: t,
509
- apiUrl: e,
510
- merchantWalletAddress: i,
511
- merchantSolWalletAddress: c,
512
- isInitialized: x,
513
- error: n,
514
- debug: u,
515
- paymentData: l,
516
- storePaymentData: (m) => (d(m), m)
687
+ setIsInitialized(true);
688
+ if (debug) {
689
+ console.log("Coinley SDK initialized with:", {
690
+ apiKey,
691
+ apiUrl,
692
+ merchantWalletAddress: merchantWalletAddress ? `${merchantWalletAddress.substring(0, 6)}...${merchantWalletAddress.substring(merchantWalletAddress.length - 4)}` : "Not provided",
693
+ merchantSolWalletAddress: merchantSolWalletAddress ? `${merchantSolWalletAddress.substring(0, 6)}...${merchantSolWalletAddress.substring(merchantSolWalletAddress.length - 4)}` : "Not provided"
694
+ });
695
+ }
696
+ } catch (err) {
697
+ setError(err.message);
698
+ if (debug) {
699
+ console.error("Coinley SDK initialization error:", err);
700
+ }
701
+ }
702
+ }, [apiKey, apiSecret, apiUrl, merchantWalletAddress, merchantSolWalletAddress, debug]);
703
+ const storePaymentData = (data) => {
704
+ setPaymentData(data);
705
+ return data;
517
706
  };
518
- return /* @__PURE__ */ o.jsx(ke.Provider, { value: h, children: y });
707
+ const value = {
708
+ apiKey,
709
+ apiSecret,
710
+ apiUrl,
711
+ merchantWalletAddress,
712
+ merchantSolWalletAddress,
713
+ isInitialized,
714
+ error,
715
+ debug,
716
+ paymentData,
717
+ storePaymentData
718
+ };
719
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(CoinleyContext.Provider, { value, children });
720
+ };
721
+ var __defProp2 = Object.defineProperty;
722
+ var __getOwnPropSymbols2 = Object.getOwnPropertySymbols;
723
+ var __hasOwnProp2 = Object.prototype.hasOwnProperty;
724
+ var __propIsEnum2 = Object.prototype.propertyIsEnumerable;
725
+ var __defNormalProp2 = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
726
+ var __spreadValues2 = (a, b) => {
727
+ for (var prop in b || (b = {}))
728
+ if (__hasOwnProp2.call(b, prop))
729
+ __defNormalProp2(a, prop, b[prop]);
730
+ if (__getOwnPropSymbols2)
731
+ for (var prop of __getOwnPropSymbols2(b)) {
732
+ if (__propIsEnum2.call(b, prop))
733
+ __defNormalProp2(a, prop, b[prop]);
734
+ }
735
+ return a;
519
736
  };
520
- var Nt = Object.defineProperty, se = Object.getOwnPropertySymbols, Te = Object.prototype.hasOwnProperty, Ae = Object.prototype.propertyIsEnumerable, pe = (s, t, e) => t in s ? Nt(s, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[t] = e, le = (s, t) => {
521
- for (var e in t || (t = {}))
522
- Te.call(t, e) && pe(s, e, t[e]);
523
- if (se)
524
- for (var e of se(t))
525
- Ae.call(t, e) && pe(s, e, t[e]);
526
- return s;
527
- }, ce = (s, t) => {
528
- var e = {};
529
- for (var i in s)
530
- Te.call(s, i) && t.indexOf(i) < 0 && (e[i] = s[i]);
531
- if (s != null && se)
532
- for (var i of se(s))
533
- t.indexOf(i) < 0 && Ae.call(s, i) && (e[i] = s[i]);
534
- return e;
737
+ var __objRest = (source, exclude) => {
738
+ var target = {};
739
+ for (var prop in source)
740
+ if (__hasOwnProp2.call(source, prop) && exclude.indexOf(prop) < 0)
741
+ target[prop] = source[prop];
742
+ if (source != null && __getOwnPropSymbols2)
743
+ for (var prop of __getOwnPropSymbols2(source)) {
744
+ if (exclude.indexOf(prop) < 0 && __propIsEnum2.call(source, prop))
745
+ target[prop] = source[prop];
746
+ }
747
+ return target;
535
748
  };
536
749
  /**
537
750
  * @license QR Code generator library (TypeScript)
538
751
  * Copyright (c) Project Nayuki.
539
752
  * SPDX-License-Identifier: MIT
540
753
  */
541
- var K;
542
- ((s) => {
543
- const t = class E {
754
+ var qrcodegen;
755
+ ((qrcodegen2) => {
756
+ const _QrCode = class _QrCode2 {
544
757
  /*-- Constructor (low level) and fields --*/
545
758
  // Creates a new QR Code with the given version number,
546
759
  // error correction level, data codeword bytes, and mask number.
547
760
  // This is a low-level API that most users should not use directly.
548
761
  // A mid-level API is the encodeSegments() function.
549
- constructor(r, n, a, l) {
550
- if (this.version = r, this.errorCorrectionLevel = n, this.modules = [], this.isFunction = [], r < E.MIN_VERSION || r > E.MAX_VERSION)
762
+ constructor(version, errorCorrectionLevel, dataCodewords, msk) {
763
+ this.version = version;
764
+ this.errorCorrectionLevel = errorCorrectionLevel;
765
+ this.modules = [];
766
+ this.isFunction = [];
767
+ if (version < _QrCode2.MIN_VERSION || version > _QrCode2.MAX_VERSION)
551
768
  throw new RangeError("Version value out of range");
552
- if (l < -1 || l > 7)
769
+ if (msk < -1 || msk > 7)
553
770
  throw new RangeError("Mask value out of range");
554
- this.size = r * 4 + 17;
555
- let d = [];
556
- for (let h = 0; h < this.size; h++)
557
- d.push(!1);
558
- for (let h = 0; h < this.size; h++)
559
- this.modules.push(d.slice()), this.isFunction.push(d.slice());
771
+ this.size = version * 4 + 17;
772
+ let row = [];
773
+ for (let i = 0; i < this.size; i++)
774
+ row.push(false);
775
+ for (let i = 0; i < this.size; i++) {
776
+ this.modules.push(row.slice());
777
+ this.isFunction.push(row.slice());
778
+ }
560
779
  this.drawFunctionPatterns();
561
- const g = this.addEccAndInterleave(a);
562
- if (this.drawCodewords(g), l == -1) {
563
- let h = 1e9;
564
- for (let m = 0; m < 8; m++) {
565
- this.applyMask(m), this.drawFormatBits(m);
566
- const f = this.getPenaltyScore();
567
- f < h && (l = m, h = f), this.applyMask(m);
780
+ const allCodewords = this.addEccAndInterleave(dataCodewords);
781
+ this.drawCodewords(allCodewords);
782
+ if (msk == -1) {
783
+ let minPenalty = 1e9;
784
+ for (let i = 0; i < 8; i++) {
785
+ this.applyMask(i);
786
+ this.drawFormatBits(i);
787
+ const penalty = this.getPenaltyScore();
788
+ if (penalty < minPenalty) {
789
+ msk = i;
790
+ minPenalty = penalty;
791
+ }
792
+ this.applyMask(i);
568
793
  }
569
794
  }
570
- c(0 <= l && l <= 7), this.mask = l, this.applyMask(l), this.drawFormatBits(l), this.isFunction = [];
795
+ assert(0 <= msk && msk <= 7);
796
+ this.mask = msk;
797
+ this.applyMask(msk);
798
+ this.drawFormatBits(msk);
799
+ this.isFunction = [];
571
800
  }
572
801
  /*-- Static factory functions (high level) --*/
573
802
  // Returns a QR Code representing the given Unicode text string at the given error correction level.
@@ -575,17 +804,17 @@ var K;
575
804
  // Unicode code points (not UTF-16 code units) if the low error correction level is used. The smallest possible
576
805
  // QR Code version is automatically chosen for the output. The ECC level of the result may be higher than the
577
806
  // ecl argument if it can be done without increasing the version.
578
- static encodeText(r, n) {
579
- const a = s.QrSegment.makeSegments(r);
580
- return E.encodeSegments(a, n);
807
+ static encodeText(text, ecl) {
808
+ const segs = qrcodegen2.QrSegment.makeSegments(text);
809
+ return _QrCode2.encodeSegments(segs, ecl);
581
810
  }
582
811
  // Returns a QR Code representing the given binary data at the given error correction level.
583
812
  // This function always encodes using the binary segment mode, not any text mode. The maximum number of
584
813
  // bytes allowed is 2953. The smallest possible QR Code version is automatically chosen for the output.
585
814
  // The ECC level of the result may be higher than the ecl argument if it can be done without increasing the version.
586
- static encodeBinary(r, n) {
587
- const a = s.QrSegment.makeBytes(r);
588
- return E.encodeSegments([a], n);
815
+ static encodeBinary(data, ecl) {
816
+ const seg = qrcodegen2.QrSegment.makeBytes(data);
817
+ return _QrCode2.encodeSegments([seg], ecl);
589
818
  }
590
819
  /*-- Static factory functions (mid level) --*/
591
820
  // Returns a QR Code representing the given segments with the given encoding parameters.
@@ -597,43 +826,52 @@ var K;
597
826
  // This function allows the user to create a custom sequence of segments that switches
598
827
  // between modes (such as alphanumeric and byte) to encode text in less space.
599
828
  // This is a mid-level API; the high-level API is encodeText() and encodeBinary().
600
- static encodeSegments(r, n, a = 1, l = 40, d = -1, g = !0) {
601
- if (!(E.MIN_VERSION <= a && a <= l && l <= E.MAX_VERSION) || d < -1 || d > 7)
829
+ static encodeSegments(segs, ecl, minVersion = 1, maxVersion = 40, mask = -1, boostEcl = true) {
830
+ if (!(_QrCode2.MIN_VERSION <= minVersion && minVersion <= maxVersion && maxVersion <= _QrCode2.MAX_VERSION) || mask < -1 || mask > 7)
602
831
  throw new RangeError("Invalid value");
603
- let h, m;
604
- for (h = a; ; h++) {
605
- const p = E.getNumDataCodewords(h, n) * 8, T = y.getTotalBits(r, h);
606
- if (T <= p) {
607
- m = T;
832
+ let version;
833
+ let dataUsedBits;
834
+ for (version = minVersion; ; version++) {
835
+ const dataCapacityBits2 = _QrCode2.getNumDataCodewords(version, ecl) * 8;
836
+ const usedBits = QrSegment.getTotalBits(segs, version);
837
+ if (usedBits <= dataCapacityBits2) {
838
+ dataUsedBits = usedBits;
608
839
  break;
609
840
  }
610
- if (h >= l)
841
+ if (version >= maxVersion)
611
842
  throw new RangeError("Data too long");
612
843
  }
613
- for (const p of [E.Ecc.MEDIUM, E.Ecc.QUARTILE, E.Ecc.HIGH])
614
- g && m <= E.getNumDataCodewords(h, p) * 8 && (n = p);
615
- let f = [];
616
- for (const p of r) {
617
- e(p.mode.modeBits, 4, f), e(p.numChars, p.mode.numCharCountBits(h), f);
618
- for (const T of p.getData())
619
- f.push(T);
844
+ for (const newEcl of [_QrCode2.Ecc.MEDIUM, _QrCode2.Ecc.QUARTILE, _QrCode2.Ecc.HIGH]) {
845
+ if (boostEcl && dataUsedBits <= _QrCode2.getNumDataCodewords(version, newEcl) * 8)
846
+ ecl = newEcl;
620
847
  }
621
- c(f.length == m);
622
- const k = E.getNumDataCodewords(h, n) * 8;
623
- c(f.length <= k), e(0, Math.min(4, k - f.length), f), e(0, (8 - f.length % 8) % 8, f), c(f.length % 8 == 0);
624
- for (let p = 236; f.length < k; p ^= 253)
625
- e(p, 8, f);
626
- let w = [];
627
- for (; w.length * 8 < f.length; )
628
- w.push(0);
629
- return f.forEach((p, T) => w[T >>> 3] |= p << 7 - (T & 7)), new E(h, n, w, d);
848
+ let bb = [];
849
+ for (const seg of segs) {
850
+ appendBits(seg.mode.modeBits, 4, bb);
851
+ appendBits(seg.numChars, seg.mode.numCharCountBits(version), bb);
852
+ for (const b of seg.getData())
853
+ bb.push(b);
854
+ }
855
+ assert(bb.length == dataUsedBits);
856
+ const dataCapacityBits = _QrCode2.getNumDataCodewords(version, ecl) * 8;
857
+ assert(bb.length <= dataCapacityBits);
858
+ appendBits(0, Math.min(4, dataCapacityBits - bb.length), bb);
859
+ appendBits(0, (8 - bb.length % 8) % 8, bb);
860
+ assert(bb.length % 8 == 0);
861
+ for (let padByte = 236; bb.length < dataCapacityBits; padByte ^= 236 ^ 17)
862
+ appendBits(padByte, 8, bb);
863
+ let dataCodewords = [];
864
+ while (dataCodewords.length * 8 < bb.length)
865
+ dataCodewords.push(0);
866
+ bb.forEach((b, i) => dataCodewords[i >>> 3] |= b << 7 - (i & 7));
867
+ return new _QrCode2(version, ecl, dataCodewords, mask);
630
868
  }
631
869
  /*-- Accessor methods --*/
632
870
  // Returns the color of the module (pixel) at the given coordinates, which is false
633
871
  // for light or true for dark. The top left corner has the coordinates (x=0, y=0).
634
872
  // If the given coordinates are out of bounds, then false (light) is returned.
635
- getModule(r, n) {
636
- return 0 <= r && r < this.size && 0 <= n && n < this.size && this.modules[n][r];
873
+ getModule(x, y) {
874
+ return 0 <= x && x < this.size && 0 <= y && y < this.size && this.modules[y][x];
637
875
  }
638
876
  // Modified to expose modules for easy access
639
877
  getModules() {
@@ -642,178 +880,253 @@ var K;
642
880
  /*-- Private helper methods for constructor: Drawing function modules --*/
643
881
  // Reads this object's version field, and draws and marks all function modules.
644
882
  drawFunctionPatterns() {
645
- for (let a = 0; a < this.size; a++)
646
- this.setFunctionModule(6, a, a % 2 == 0), this.setFunctionModule(a, 6, a % 2 == 0);
647
- this.drawFinderPattern(3, 3), this.drawFinderPattern(this.size - 4, 3), this.drawFinderPattern(3, this.size - 4);
648
- const r = this.getAlignmentPatternPositions(), n = r.length;
649
- for (let a = 0; a < n; a++)
650
- for (let l = 0; l < n; l++)
651
- a == 0 && l == 0 || a == 0 && l == n - 1 || a == n - 1 && l == 0 || this.drawAlignmentPattern(r[a], r[l]);
652
- this.drawFormatBits(0), this.drawVersion();
883
+ for (let i = 0; i < this.size; i++) {
884
+ this.setFunctionModule(6, i, i % 2 == 0);
885
+ this.setFunctionModule(i, 6, i % 2 == 0);
886
+ }
887
+ this.drawFinderPattern(3, 3);
888
+ this.drawFinderPattern(this.size - 4, 3);
889
+ this.drawFinderPattern(3, this.size - 4);
890
+ const alignPatPos = this.getAlignmentPatternPositions();
891
+ const numAlign = alignPatPos.length;
892
+ for (let i = 0; i < numAlign; i++) {
893
+ for (let j = 0; j < numAlign; j++) {
894
+ if (!(i == 0 && j == 0 || i == 0 && j == numAlign - 1 || i == numAlign - 1 && j == 0))
895
+ this.drawAlignmentPattern(alignPatPos[i], alignPatPos[j]);
896
+ }
897
+ }
898
+ this.drawFormatBits(0);
899
+ this.drawVersion();
653
900
  }
654
901
  // Draws two copies of the format bits (with its own error correction code)
655
902
  // based on the given mask and this object's error correction level field.
656
- drawFormatBits(r) {
657
- const n = this.errorCorrectionLevel.formatBits << 3 | r;
658
- let a = n;
659
- for (let d = 0; d < 10; d++)
660
- a = a << 1 ^ (a >>> 9) * 1335;
661
- const l = (n << 10 | a) ^ 21522;
662
- c(l >>> 15 == 0);
663
- for (let d = 0; d <= 5; d++)
664
- this.setFunctionModule(8, d, i(l, d));
665
- this.setFunctionModule(8, 7, i(l, 6)), this.setFunctionModule(8, 8, i(l, 7)), this.setFunctionModule(7, 8, i(l, 8));
666
- for (let d = 9; d < 15; d++)
667
- this.setFunctionModule(14 - d, 8, i(l, d));
668
- for (let d = 0; d < 8; d++)
669
- this.setFunctionModule(this.size - 1 - d, 8, i(l, d));
670
- for (let d = 8; d < 15; d++)
671
- this.setFunctionModule(8, this.size - 15 + d, i(l, d));
672
- this.setFunctionModule(8, this.size - 8, !0);
903
+ drawFormatBits(mask) {
904
+ const data = this.errorCorrectionLevel.formatBits << 3 | mask;
905
+ let rem = data;
906
+ for (let i = 0; i < 10; i++)
907
+ rem = rem << 1 ^ (rem >>> 9) * 1335;
908
+ const bits = (data << 10 | rem) ^ 21522;
909
+ assert(bits >>> 15 == 0);
910
+ for (let i = 0; i <= 5; i++)
911
+ this.setFunctionModule(8, i, getBit(bits, i));
912
+ this.setFunctionModule(8, 7, getBit(bits, 6));
913
+ this.setFunctionModule(8, 8, getBit(bits, 7));
914
+ this.setFunctionModule(7, 8, getBit(bits, 8));
915
+ for (let i = 9; i < 15; i++)
916
+ this.setFunctionModule(14 - i, 8, getBit(bits, i));
917
+ for (let i = 0; i < 8; i++)
918
+ this.setFunctionModule(this.size - 1 - i, 8, getBit(bits, i));
919
+ for (let i = 8; i < 15; i++)
920
+ this.setFunctionModule(8, this.size - 15 + i, getBit(bits, i));
921
+ this.setFunctionModule(8, this.size - 8, true);
673
922
  }
674
923
  // Draws two copies of the version bits (with its own error correction code),
675
924
  // based on this object's version field, iff 7 <= version <= 40.
676
925
  drawVersion() {
677
926
  if (this.version < 7)
678
927
  return;
679
- let r = this.version;
680
- for (let a = 0; a < 12; a++)
681
- r = r << 1 ^ (r >>> 11) * 7973;
682
- const n = this.version << 12 | r;
683
- c(n >>> 18 == 0);
684
- for (let a = 0; a < 18; a++) {
685
- const l = i(n, a), d = this.size - 11 + a % 3, g = Math.floor(a / 3);
686
- this.setFunctionModule(d, g, l), this.setFunctionModule(g, d, l);
928
+ let rem = this.version;
929
+ for (let i = 0; i < 12; i++)
930
+ rem = rem << 1 ^ (rem >>> 11) * 7973;
931
+ const bits = this.version << 12 | rem;
932
+ assert(bits >>> 18 == 0);
933
+ for (let i = 0; i < 18; i++) {
934
+ const color = getBit(bits, i);
935
+ const a = this.size - 11 + i % 3;
936
+ const b = Math.floor(i / 3);
937
+ this.setFunctionModule(a, b, color);
938
+ this.setFunctionModule(b, a, color);
687
939
  }
688
940
  }
689
941
  // Draws a 9*9 finder pattern including the border separator,
690
942
  // with the center module at (x, y). Modules can be out of bounds.
691
- drawFinderPattern(r, n) {
692
- for (let a = -4; a <= 4; a++)
693
- for (let l = -4; l <= 4; l++) {
694
- const d = Math.max(Math.abs(l), Math.abs(a)), g = r + l, h = n + a;
695
- 0 <= g && g < this.size && 0 <= h && h < this.size && this.setFunctionModule(g, h, d != 2 && d != 4);
943
+ drawFinderPattern(x, y) {
944
+ for (let dy = -4; dy <= 4; dy++) {
945
+ for (let dx = -4; dx <= 4; dx++) {
946
+ const dist = Math.max(Math.abs(dx), Math.abs(dy));
947
+ const xx = x + dx;
948
+ const yy = y + dy;
949
+ if (0 <= xx && xx < this.size && 0 <= yy && yy < this.size)
950
+ this.setFunctionModule(xx, yy, dist != 2 && dist != 4);
696
951
  }
952
+ }
697
953
  }
698
954
  // Draws a 5*5 alignment pattern, with the center module
699
955
  // at (x, y). All modules must be in bounds.
700
- drawAlignmentPattern(r, n) {
701
- for (let a = -2; a <= 2; a++)
702
- for (let l = -2; l <= 2; l++)
703
- this.setFunctionModule(r + l, n + a, Math.max(Math.abs(l), Math.abs(a)) != 1);
956
+ drawAlignmentPattern(x, y) {
957
+ for (let dy = -2; dy <= 2; dy++) {
958
+ for (let dx = -2; dx <= 2; dx++)
959
+ this.setFunctionModule(x + dx, y + dy, Math.max(Math.abs(dx), Math.abs(dy)) != 1);
960
+ }
704
961
  }
705
962
  // Sets the color of a module and marks it as a function module.
706
963
  // Only used by the constructor. Coordinates must be in bounds.
707
- setFunctionModule(r, n, a) {
708
- this.modules[n][r] = a, this.isFunction[n][r] = !0;
964
+ setFunctionModule(x, y, isDark) {
965
+ this.modules[y][x] = isDark;
966
+ this.isFunction[y][x] = true;
709
967
  }
710
968
  /*-- Private helper methods for constructor: Codewords and masking --*/
711
969
  // Returns a new byte string representing the given data with the appropriate error correction
712
970
  // codewords appended to it, based on this object's version and error correction level.
713
- addEccAndInterleave(r) {
714
- const n = this.version, a = this.errorCorrectionLevel;
715
- if (r.length != E.getNumDataCodewords(n, a))
971
+ addEccAndInterleave(data) {
972
+ const ver = this.version;
973
+ const ecl = this.errorCorrectionLevel;
974
+ if (data.length != _QrCode2.getNumDataCodewords(ver, ecl))
716
975
  throw new RangeError("Invalid argument");
717
- const l = E.NUM_ERROR_CORRECTION_BLOCKS[a.ordinal][n], d = E.ECC_CODEWORDS_PER_BLOCK[a.ordinal][n], g = Math.floor(E.getNumRawDataModules(n) / 8), h = l - g % l, m = Math.floor(g / l);
718
- let f = [];
719
- const k = E.reedSolomonComputeDivisor(d);
720
- for (let p = 0, T = 0; p < l; p++) {
721
- let C = r.slice(T, T + m - d + (p < h ? 0 : 1));
722
- T += C.length;
723
- const q = E.reedSolomonComputeRemainder(C, k);
724
- p < h && C.push(0), f.push(C.concat(q));
976
+ const numBlocks = _QrCode2.NUM_ERROR_CORRECTION_BLOCKS[ecl.ordinal][ver];
977
+ const blockEccLen = _QrCode2.ECC_CODEWORDS_PER_BLOCK[ecl.ordinal][ver];
978
+ const rawCodewords = Math.floor(_QrCode2.getNumRawDataModules(ver) / 8);
979
+ const numShortBlocks = numBlocks - rawCodewords % numBlocks;
980
+ const shortBlockLen = Math.floor(rawCodewords / numBlocks);
981
+ let blocks = [];
982
+ const rsDiv = _QrCode2.reedSolomonComputeDivisor(blockEccLen);
983
+ for (let i = 0, k2 = 0; i < numBlocks; i++) {
984
+ let dat = data.slice(k2, k2 + shortBlockLen - blockEccLen + (i < numShortBlocks ? 0 : 1));
985
+ k2 += dat.length;
986
+ const ecc = _QrCode2.reedSolomonComputeRemainder(dat, rsDiv);
987
+ if (i < numShortBlocks)
988
+ dat.push(0);
989
+ blocks.push(dat.concat(ecc));
725
990
  }
726
- let w = [];
727
- for (let p = 0; p < f[0].length; p++)
728
- f.forEach((T, C) => {
729
- (p != m - d || C >= h) && w.push(T[p]);
991
+ let result = [];
992
+ for (let i = 0; i < blocks[0].length; i++) {
993
+ blocks.forEach((block, j) => {
994
+ if (i != shortBlockLen - blockEccLen || j >= numShortBlocks)
995
+ result.push(block[i]);
730
996
  });
731
- return c(w.length == g), w;
997
+ }
998
+ assert(result.length == rawCodewords);
999
+ return result;
732
1000
  }
733
1001
  // Draws the given sequence of 8-bit codewords (data and error correction) onto the entire
734
1002
  // data area of this QR Code. Function modules need to be marked off before this is called.
735
- drawCodewords(r) {
736
- if (r.length != Math.floor(E.getNumRawDataModules(this.version) / 8))
1003
+ drawCodewords(data) {
1004
+ if (data.length != Math.floor(_QrCode2.getNumRawDataModules(this.version) / 8))
737
1005
  throw new RangeError("Invalid argument");
738
- let n = 0;
739
- for (let a = this.size - 1; a >= 1; a -= 2) {
740
- a == 6 && (a = 5);
741
- for (let l = 0; l < this.size; l++)
742
- for (let d = 0; d < 2; d++) {
743
- const g = a - d, m = (a + 1 & 2) == 0 ? this.size - 1 - l : l;
744
- !this.isFunction[m][g] && n < r.length * 8 && (this.modules[m][g] = i(r[n >>> 3], 7 - (n & 7)), n++);
1006
+ let i = 0;
1007
+ for (let right = this.size - 1; right >= 1; right -= 2) {
1008
+ if (right == 6)
1009
+ right = 5;
1010
+ for (let vert = 0; vert < this.size; vert++) {
1011
+ for (let j = 0; j < 2; j++) {
1012
+ const x = right - j;
1013
+ const upward = (right + 1 & 2) == 0;
1014
+ const y = upward ? this.size - 1 - vert : vert;
1015
+ if (!this.isFunction[y][x] && i < data.length * 8) {
1016
+ this.modules[y][x] = getBit(data[i >>> 3], 7 - (i & 7));
1017
+ i++;
1018
+ }
745
1019
  }
1020
+ }
746
1021
  }
747
- c(n == r.length * 8);
1022
+ assert(i == data.length * 8);
748
1023
  }
749
1024
  // XORs the codeword modules in this QR Code with the given mask pattern.
750
1025
  // The function modules must be marked and the codeword bits must be drawn
751
1026
  // before masking. Due to the arithmetic of XOR, calling applyMask() with
752
1027
  // the same mask value a second time will undo the mask. A final well-formed
753
1028
  // QR Code needs exactly one (not zero, two, etc.) mask applied.
754
- applyMask(r) {
755
- if (r < 0 || r > 7)
1029
+ applyMask(mask) {
1030
+ if (mask < 0 || mask > 7)
756
1031
  throw new RangeError("Mask value out of range");
757
- for (let n = 0; n < this.size; n++)
758
- for (let a = 0; a < this.size; a++) {
759
- let l;
760
- switch (r) {
1032
+ for (let y = 0; y < this.size; y++) {
1033
+ for (let x = 0; x < this.size; x++) {
1034
+ let invert;
1035
+ switch (mask) {
761
1036
  case 0:
762
- l = (a + n) % 2 == 0;
1037
+ invert = (x + y) % 2 == 0;
763
1038
  break;
764
1039
  case 1:
765
- l = n % 2 == 0;
1040
+ invert = y % 2 == 0;
766
1041
  break;
767
1042
  case 2:
768
- l = a % 3 == 0;
1043
+ invert = x % 3 == 0;
769
1044
  break;
770
1045
  case 3:
771
- l = (a + n) % 3 == 0;
1046
+ invert = (x + y) % 3 == 0;
772
1047
  break;
773
1048
  case 4:
774
- l = (Math.floor(a / 3) + Math.floor(n / 2)) % 2 == 0;
1049
+ invert = (Math.floor(x / 3) + Math.floor(y / 2)) % 2 == 0;
775
1050
  break;
776
1051
  case 5:
777
- l = a * n % 2 + a * n % 3 == 0;
1052
+ invert = x * y % 2 + x * y % 3 == 0;
778
1053
  break;
779
1054
  case 6:
780
- l = (a * n % 2 + a * n % 3) % 2 == 0;
1055
+ invert = (x * y % 2 + x * y % 3) % 2 == 0;
781
1056
  break;
782
1057
  case 7:
783
- l = ((a + n) % 2 + a * n % 3) % 2 == 0;
1058
+ invert = ((x + y) % 2 + x * y % 3) % 2 == 0;
784
1059
  break;
785
1060
  default:
786
1061
  throw new Error("Unreachable");
787
1062
  }
788
- !this.isFunction[n][a] && l && (this.modules[n][a] = !this.modules[n][a]);
1063
+ if (!this.isFunction[y][x] && invert)
1064
+ this.modules[y][x] = !this.modules[y][x];
789
1065
  }
1066
+ }
790
1067
  }
791
1068
  // Calculates and returns the penalty score based on state of this QR Code's current modules.
792
1069
  // This is used by the automatic mask choice algorithm to find the mask pattern that yields the lowest score.
793
1070
  getPenaltyScore() {
794
- let r = 0;
795
- for (let d = 0; d < this.size; d++) {
796
- let g = !1, h = 0, m = [0, 0, 0, 0, 0, 0, 0];
797
- for (let f = 0; f < this.size; f++)
798
- this.modules[d][f] == g ? (h++, h == 5 ? r += E.PENALTY_N1 : h > 5 && r++) : (this.finderPenaltyAddHistory(h, m), g || (r += this.finderPenaltyCountPatterns(m) * E.PENALTY_N3), g = this.modules[d][f], h = 1);
799
- r += this.finderPenaltyTerminateAndCount(g, h, m) * E.PENALTY_N3;
1071
+ let result = 0;
1072
+ for (let y = 0; y < this.size; y++) {
1073
+ let runColor = false;
1074
+ let runX = 0;
1075
+ let runHistory = [0, 0, 0, 0, 0, 0, 0];
1076
+ for (let x = 0; x < this.size; x++) {
1077
+ if (this.modules[y][x] == runColor) {
1078
+ runX++;
1079
+ if (runX == 5)
1080
+ result += _QrCode2.PENALTY_N1;
1081
+ else if (runX > 5)
1082
+ result++;
1083
+ } else {
1084
+ this.finderPenaltyAddHistory(runX, runHistory);
1085
+ if (!runColor)
1086
+ result += this.finderPenaltyCountPatterns(runHistory) * _QrCode2.PENALTY_N3;
1087
+ runColor = this.modules[y][x];
1088
+ runX = 1;
1089
+ }
1090
+ }
1091
+ result += this.finderPenaltyTerminateAndCount(runColor, runX, runHistory) * _QrCode2.PENALTY_N3;
800
1092
  }
801
- for (let d = 0; d < this.size; d++) {
802
- let g = !1, h = 0, m = [0, 0, 0, 0, 0, 0, 0];
803
- for (let f = 0; f < this.size; f++)
804
- this.modules[f][d] == g ? (h++, h == 5 ? r += E.PENALTY_N1 : h > 5 && r++) : (this.finderPenaltyAddHistory(h, m), g || (r += this.finderPenaltyCountPatterns(m) * E.PENALTY_N3), g = this.modules[f][d], h = 1);
805
- r += this.finderPenaltyTerminateAndCount(g, h, m) * E.PENALTY_N3;
1093
+ for (let x = 0; x < this.size; x++) {
1094
+ let runColor = false;
1095
+ let runY = 0;
1096
+ let runHistory = [0, 0, 0, 0, 0, 0, 0];
1097
+ for (let y = 0; y < this.size; y++) {
1098
+ if (this.modules[y][x] == runColor) {
1099
+ runY++;
1100
+ if (runY == 5)
1101
+ result += _QrCode2.PENALTY_N1;
1102
+ else if (runY > 5)
1103
+ result++;
1104
+ } else {
1105
+ this.finderPenaltyAddHistory(runY, runHistory);
1106
+ if (!runColor)
1107
+ result += this.finderPenaltyCountPatterns(runHistory) * _QrCode2.PENALTY_N3;
1108
+ runColor = this.modules[y][x];
1109
+ runY = 1;
1110
+ }
1111
+ }
1112
+ result += this.finderPenaltyTerminateAndCount(runColor, runY, runHistory) * _QrCode2.PENALTY_N3;
806
1113
  }
807
- for (let d = 0; d < this.size - 1; d++)
808
- for (let g = 0; g < this.size - 1; g++) {
809
- const h = this.modules[d][g];
810
- h == this.modules[d][g + 1] && h == this.modules[d + 1][g] && h == this.modules[d + 1][g + 1] && (r += E.PENALTY_N2);
1114
+ for (let y = 0; y < this.size - 1; y++) {
1115
+ for (let x = 0; x < this.size - 1; x++) {
1116
+ const color = this.modules[y][x];
1117
+ if (color == this.modules[y][x + 1] && color == this.modules[y + 1][x] && color == this.modules[y + 1][x + 1])
1118
+ result += _QrCode2.PENALTY_N2;
811
1119
  }
812
- let n = 0;
813
- for (const d of this.modules)
814
- n = d.reduce((g, h) => g + (h ? 1 : 0), n);
815
- const a = this.size * this.size, l = Math.ceil(Math.abs(n * 20 - a * 10) / a) - 1;
816
- return c(0 <= l && l <= 9), r += l * E.PENALTY_N4, c(0 <= r && r <= 2568888), r;
1120
+ }
1121
+ let dark = 0;
1122
+ for (const row of this.modules)
1123
+ dark = row.reduce((sum, color) => sum + (color ? 1 : 0), dark);
1124
+ const total = this.size * this.size;
1125
+ const k2 = Math.ceil(Math.abs(dark * 20 - total * 10) / total) - 1;
1126
+ assert(0 <= k2 && k2 <= 9);
1127
+ result += k2 * _QrCode2.PENALTY_N4;
1128
+ assert(0 <= result && result <= 2568888);
1129
+ return result;
817
1130
  }
818
1131
  /*-- Private helper functions --*/
819
1132
  // Returns an ascending list of positions of alignment patterns for this version number.
@@ -822,87 +1135,113 @@ var K;
822
1135
  getAlignmentPatternPositions() {
823
1136
  if (this.version == 1)
824
1137
  return [];
825
- {
826
- const r = Math.floor(this.version / 7) + 2, n = this.version == 32 ? 26 : Math.ceil((this.version * 4 + 4) / (r * 2 - 2)) * 2;
827
- let a = [6];
828
- for (let l = this.size - 7; a.length < r; l -= n)
829
- a.splice(1, 0, l);
830
- return a;
1138
+ else {
1139
+ const numAlign = Math.floor(this.version / 7) + 2;
1140
+ const step = this.version == 32 ? 26 : Math.ceil((this.version * 4 + 4) / (numAlign * 2 - 2)) * 2;
1141
+ let result = [6];
1142
+ for (let pos = this.size - 7; result.length < numAlign; pos -= step)
1143
+ result.splice(1, 0, pos);
1144
+ return result;
831
1145
  }
832
1146
  }
833
1147
  // Returns the number of data bits that can be stored in a QR Code of the given version number, after
834
1148
  // all function modules are excluded. This includes remainder bits, so it might not be a multiple of 8.
835
1149
  // The result is in the range [208, 29648]. This could be implemented as a 40-entry lookup table.
836
- static getNumRawDataModules(r) {
837
- if (r < E.MIN_VERSION || r > E.MAX_VERSION)
1150
+ static getNumRawDataModules(ver) {
1151
+ if (ver < _QrCode2.MIN_VERSION || ver > _QrCode2.MAX_VERSION)
838
1152
  throw new RangeError("Version number out of range");
839
- let n = (16 * r + 128) * r + 64;
840
- if (r >= 2) {
841
- const a = Math.floor(r / 7) + 2;
842
- n -= (25 * a - 10) * a - 55, r >= 7 && (n -= 36);
1153
+ let result = (16 * ver + 128) * ver + 64;
1154
+ if (ver >= 2) {
1155
+ const numAlign = Math.floor(ver / 7) + 2;
1156
+ result -= (25 * numAlign - 10) * numAlign - 55;
1157
+ if (ver >= 7)
1158
+ result -= 36;
843
1159
  }
844
- return c(208 <= n && n <= 29648), n;
1160
+ assert(208 <= result && result <= 29648);
1161
+ return result;
845
1162
  }
846
1163
  // Returns the number of 8-bit data (i.e. not error correction) codewords contained in any
847
1164
  // QR Code of the given version number and error correction level, with remainder bits discarded.
848
1165
  // This stateless pure function could be implemented as a (40*4)-cell lookup table.
849
- static getNumDataCodewords(r, n) {
850
- return Math.floor(E.getNumRawDataModules(r) / 8) - E.ECC_CODEWORDS_PER_BLOCK[n.ordinal][r] * E.NUM_ERROR_CORRECTION_BLOCKS[n.ordinal][r];
1166
+ static getNumDataCodewords(ver, ecl) {
1167
+ return Math.floor(_QrCode2.getNumRawDataModules(ver) / 8) - _QrCode2.ECC_CODEWORDS_PER_BLOCK[ecl.ordinal][ver] * _QrCode2.NUM_ERROR_CORRECTION_BLOCKS[ecl.ordinal][ver];
851
1168
  }
852
1169
  // Returns a Reed-Solomon ECC generator polynomial for the given degree. This could be
853
1170
  // implemented as a lookup table over all possible parameter values, instead of as an algorithm.
854
- static reedSolomonComputeDivisor(r) {
855
- if (r < 1 || r > 255)
1171
+ static reedSolomonComputeDivisor(degree) {
1172
+ if (degree < 1 || degree > 255)
856
1173
  throw new RangeError("Degree out of range");
857
- let n = [];
858
- for (let l = 0; l < r - 1; l++)
859
- n.push(0);
860
- n.push(1);
861
- let a = 1;
862
- for (let l = 0; l < r; l++) {
863
- for (let d = 0; d < n.length; d++)
864
- n[d] = E.reedSolomonMultiply(n[d], a), d + 1 < n.length && (n[d] ^= n[d + 1]);
865
- a = E.reedSolomonMultiply(a, 2);
1174
+ let result = [];
1175
+ for (let i = 0; i < degree - 1; i++)
1176
+ result.push(0);
1177
+ result.push(1);
1178
+ let root = 1;
1179
+ for (let i = 0; i < degree; i++) {
1180
+ for (let j = 0; j < result.length; j++) {
1181
+ result[j] = _QrCode2.reedSolomonMultiply(result[j], root);
1182
+ if (j + 1 < result.length)
1183
+ result[j] ^= result[j + 1];
1184
+ }
1185
+ root = _QrCode2.reedSolomonMultiply(root, 2);
866
1186
  }
867
- return n;
1187
+ return result;
868
1188
  }
869
1189
  // Returns the Reed-Solomon error correction codeword for the given data and divisor polynomials.
870
- static reedSolomonComputeRemainder(r, n) {
871
- let a = n.map((l) => 0);
872
- for (const l of r) {
873
- const d = l ^ a.shift();
874
- a.push(0), n.forEach((g, h) => a[h] ^= E.reedSolomonMultiply(g, d));
1190
+ static reedSolomonComputeRemainder(data, divisor) {
1191
+ let result = divisor.map((_) => 0);
1192
+ for (const b of data) {
1193
+ const factor = b ^ result.shift();
1194
+ result.push(0);
1195
+ divisor.forEach((coef, i) => result[i] ^= _QrCode2.reedSolomonMultiply(coef, factor));
875
1196
  }
876
- return a;
1197
+ return result;
877
1198
  }
878
1199
  // Returns the product of the two given field elements modulo GF(2^8/0x11D). The arguments and result
879
1200
  // are unsigned 8-bit integers. This could be implemented as a lookup table of 256*256 entries of uint8.
880
- static reedSolomonMultiply(r, n) {
881
- if (r >>> 8 || n >>> 8)
1201
+ static reedSolomonMultiply(x, y) {
1202
+ if (x >>> 8 != 0 || y >>> 8 != 0)
882
1203
  throw new RangeError("Byte out of range");
883
- let a = 0;
884
- for (let l = 7; l >= 0; l--)
885
- a = a << 1 ^ (a >>> 7) * 285, a ^= (n >>> l & 1) * r;
886
- return c(a >>> 8 == 0), a;
1204
+ let z = 0;
1205
+ for (let i = 7; i >= 0; i--) {
1206
+ z = z << 1 ^ (z >>> 7) * 285;
1207
+ z ^= (y >>> i & 1) * x;
1208
+ }
1209
+ assert(z >>> 8 == 0);
1210
+ return z;
887
1211
  }
888
1212
  // Can only be called immediately after a light run is added, and
889
1213
  // returns either 0, 1, or 2. A helper function for getPenaltyScore().
890
- finderPenaltyCountPatterns(r) {
891
- const n = r[1];
892
- c(n <= this.size * 3);
893
- const a = n > 0 && r[2] == n && r[3] == n * 3 && r[4] == n && r[5] == n;
894
- return (a && r[0] >= n * 4 && r[6] >= n ? 1 : 0) + (a && r[6] >= n * 4 && r[0] >= n ? 1 : 0);
1214
+ finderPenaltyCountPatterns(runHistory) {
1215
+ const n2 = runHistory[1];
1216
+ assert(n2 <= this.size * 3);
1217
+ const core = n2 > 0 && runHistory[2] == n2 && runHistory[3] == n2 * 3 && runHistory[4] == n2 && runHistory[5] == n2;
1218
+ return (core && runHistory[0] >= n2 * 4 && runHistory[6] >= n2 ? 1 : 0) + (core && runHistory[6] >= n2 * 4 && runHistory[0] >= n2 ? 1 : 0);
895
1219
  }
896
1220
  // Must be called at the end of a line (row or column) of modules. A helper function for getPenaltyScore().
897
- finderPenaltyTerminateAndCount(r, n, a) {
898
- return r && (this.finderPenaltyAddHistory(n, a), n = 0), n += this.size, this.finderPenaltyAddHistory(n, a), this.finderPenaltyCountPatterns(a);
1221
+ finderPenaltyTerminateAndCount(currentRunColor, currentRunLength, runHistory) {
1222
+ if (currentRunColor) {
1223
+ this.finderPenaltyAddHistory(currentRunLength, runHistory);
1224
+ currentRunLength = 0;
1225
+ }
1226
+ currentRunLength += this.size;
1227
+ this.finderPenaltyAddHistory(currentRunLength, runHistory);
1228
+ return this.finderPenaltyCountPatterns(runHistory);
899
1229
  }
900
1230
  // Pushes the given value to the front and drops the last value. A helper function for getPenaltyScore().
901
- finderPenaltyAddHistory(r, n) {
902
- n[0] == 0 && (r += this.size), n.pop(), n.unshift(r);
1231
+ finderPenaltyAddHistory(currentRunLength, runHistory) {
1232
+ if (runHistory[0] == 0)
1233
+ currentRunLength += this.size;
1234
+ runHistory.pop();
1235
+ runHistory.unshift(currentRunLength);
903
1236
  }
904
1237
  };
905
- t.MIN_VERSION = 1, t.MAX_VERSION = 40, t.PENALTY_N1 = 3, t.PENALTY_N2 = 3, t.PENALTY_N3 = 40, t.PENALTY_N4 = 10, t.ECC_CODEWORDS_PER_BLOCK = [
1238
+ _QrCode.MIN_VERSION = 1;
1239
+ _QrCode.MAX_VERSION = 40;
1240
+ _QrCode.PENALTY_N1 = 3;
1241
+ _QrCode.PENALTY_N2 = 3;
1242
+ _QrCode.PENALTY_N3 = 40;
1243
+ _QrCode.PENALTY_N4 = 10;
1244
+ _QrCode.ECC_CODEWORDS_PER_BLOCK = [
906
1245
  // Version: (note that index 0 is for padding, and is set to an illegal value)
907
1246
  //0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40 Error correction level
908
1247
  [-1, 7, 10, 15, 20, 26, 18, 20, 24, 30, 18, 20, 24, 26, 30, 22, 24, 28, 30, 28, 28, 28, 28, 30, 30, 26, 28, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30],
@@ -913,7 +1252,8 @@ var K;
913
1252
  // Quartile
914
1253
  [-1, 17, 28, 22, 16, 22, 28, 26, 26, 24, 28, 24, 28, 22, 24, 24, 30, 28, 28, 26, 28, 30, 24, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30]
915
1254
  // High
916
- ], t.NUM_ERROR_CORRECTION_BLOCKS = [
1255
+ ];
1256
+ _QrCode.NUM_ERROR_CORRECTION_BLOCKS = [
917
1257
  // Version: (note that index 0 is for padding, and is set to an illegal value)
918
1258
  //0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40 Error correction level
919
1259
  [-1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 4, 4, 4, 4, 4, 6, 6, 6, 6, 7, 8, 8, 9, 9, 10, 12, 12, 12, 13, 14, 15, 16, 17, 18, 19, 19, 20, 21, 22, 24, 25],
@@ -924,95 +1264,113 @@ var K;
924
1264
  // Quartile
925
1265
  [-1, 1, 1, 2, 4, 4, 4, 5, 6, 8, 8, 11, 11, 16, 16, 18, 16, 19, 21, 25, 25, 25, 34, 30, 32, 35, 37, 40, 42, 45, 48, 51, 54, 57, 60, 63, 66, 70, 74, 77, 81]
926
1266
  // High
927
- ], s.QrCode = t;
928
- function e(x, r, n) {
929
- if (r < 0 || r > 31 || x >>> r)
1267
+ ];
1268
+ qrcodegen2.QrCode = _QrCode;
1269
+ function appendBits(val, len, bb) {
1270
+ if (len < 0 || len > 31 || val >>> len != 0)
930
1271
  throw new RangeError("Value out of range");
931
- for (let a = r - 1; a >= 0; a--)
932
- n.push(x >>> a & 1);
1272
+ for (let i = len - 1; i >= 0; i--)
1273
+ bb.push(val >>> i & 1);
933
1274
  }
934
- function i(x, r) {
935
- return (x >>> r & 1) != 0;
1275
+ function getBit(x, i) {
1276
+ return (x >>> i & 1) != 0;
936
1277
  }
937
- function c(x) {
938
- if (!x)
1278
+ function assert(cond) {
1279
+ if (!cond)
939
1280
  throw new Error("Assertion error");
940
1281
  }
941
- const u = class j {
1282
+ const _QrSegment = class _QrSegment2 {
942
1283
  /*-- Constructor (low level) and fields --*/
943
1284
  // Creates a new QR Code segment with the given attributes and data.
944
1285
  // The character count (numChars) must agree with the mode and the bit buffer length,
945
1286
  // but the constraint isn't checked. The given bit buffer is cloned and stored.
946
- constructor(r, n, a) {
947
- if (this.mode = r, this.numChars = n, this.bitData = a, n < 0)
1287
+ constructor(mode, numChars, bitData) {
1288
+ this.mode = mode;
1289
+ this.numChars = numChars;
1290
+ this.bitData = bitData;
1291
+ if (numChars < 0)
948
1292
  throw new RangeError("Invalid argument");
949
- this.bitData = a.slice();
1293
+ this.bitData = bitData.slice();
950
1294
  }
951
1295
  /*-- Static factory functions (mid level) --*/
952
1296
  // Returns a segment representing the given binary data encoded in
953
1297
  // byte mode. All input byte arrays are acceptable. Any text string
954
1298
  // can be converted to UTF-8 bytes and encoded as a byte mode segment.
955
- static makeBytes(r) {
956
- let n = [];
957
- for (const a of r)
958
- e(a, 8, n);
959
- return new j(j.Mode.BYTE, r.length, n);
1299
+ static makeBytes(data) {
1300
+ let bb = [];
1301
+ for (const b of data)
1302
+ appendBits(b, 8, bb);
1303
+ return new _QrSegment2(_QrSegment2.Mode.BYTE, data.length, bb);
960
1304
  }
961
1305
  // Returns a segment representing the given string of decimal digits encoded in numeric mode.
962
- static makeNumeric(r) {
963
- if (!j.isNumeric(r))
1306
+ static makeNumeric(digits) {
1307
+ if (!_QrSegment2.isNumeric(digits))
964
1308
  throw new RangeError("String contains non-numeric characters");
965
- let n = [];
966
- for (let a = 0; a < r.length; ) {
967
- const l = Math.min(r.length - a, 3);
968
- e(parseInt(r.substring(a, a + l), 10), l * 3 + 1, n), a += l;
1309
+ let bb = [];
1310
+ for (let i = 0; i < digits.length; ) {
1311
+ const n2 = Math.min(digits.length - i, 3);
1312
+ appendBits(parseInt(digits.substring(i, i + n2), 10), n2 * 3 + 1, bb);
1313
+ i += n2;
969
1314
  }
970
- return new j(j.Mode.NUMERIC, r.length, n);
1315
+ return new _QrSegment2(_QrSegment2.Mode.NUMERIC, digits.length, bb);
971
1316
  }
972
1317
  // Returns a segment representing the given text string encoded in alphanumeric mode.
973
1318
  // The characters allowed are: 0 to 9, A to Z (uppercase only), space,
974
1319
  // dollar, percent, asterisk, plus, hyphen, period, slash, colon.
975
- static makeAlphanumeric(r) {
976
- if (!j.isAlphanumeric(r))
1320
+ static makeAlphanumeric(text) {
1321
+ if (!_QrSegment2.isAlphanumeric(text))
977
1322
  throw new RangeError("String contains unencodable characters in alphanumeric mode");
978
- let n = [], a;
979
- for (a = 0; a + 2 <= r.length; a += 2) {
980
- let l = j.ALPHANUMERIC_CHARSET.indexOf(r.charAt(a)) * 45;
981
- l += j.ALPHANUMERIC_CHARSET.indexOf(r.charAt(a + 1)), e(l, 11, n);
1323
+ let bb = [];
1324
+ let i;
1325
+ for (i = 0; i + 2 <= text.length; i += 2) {
1326
+ let temp = _QrSegment2.ALPHANUMERIC_CHARSET.indexOf(text.charAt(i)) * 45;
1327
+ temp += _QrSegment2.ALPHANUMERIC_CHARSET.indexOf(text.charAt(i + 1));
1328
+ appendBits(temp, 11, bb);
982
1329
  }
983
- return a < r.length && e(j.ALPHANUMERIC_CHARSET.indexOf(r.charAt(a)), 6, n), new j(j.Mode.ALPHANUMERIC, r.length, n);
1330
+ if (i < text.length)
1331
+ appendBits(_QrSegment2.ALPHANUMERIC_CHARSET.indexOf(text.charAt(i)), 6, bb);
1332
+ return new _QrSegment2(_QrSegment2.Mode.ALPHANUMERIC, text.length, bb);
984
1333
  }
985
1334
  // Returns a new mutable list of zero or more segments to represent the given Unicode text string.
986
1335
  // The result may use various segment modes and switch modes to optimize the length of the bit stream.
987
- static makeSegments(r) {
988
- return r == "" ? [] : j.isNumeric(r) ? [j.makeNumeric(r)] : j.isAlphanumeric(r) ? [j.makeAlphanumeric(r)] : [j.makeBytes(j.toUtf8ByteArray(r))];
1336
+ static makeSegments(text) {
1337
+ if (text == "")
1338
+ return [];
1339
+ else if (_QrSegment2.isNumeric(text))
1340
+ return [_QrSegment2.makeNumeric(text)];
1341
+ else if (_QrSegment2.isAlphanumeric(text))
1342
+ return [_QrSegment2.makeAlphanumeric(text)];
1343
+ else
1344
+ return [_QrSegment2.makeBytes(_QrSegment2.toUtf8ByteArray(text))];
989
1345
  }
990
1346
  // Returns a segment representing an Extended Channel Interpretation
991
1347
  // (ECI) designator with the given assignment value.
992
- static makeEci(r) {
993
- let n = [];
994
- if (r < 0)
1348
+ static makeEci(assignVal) {
1349
+ let bb = [];
1350
+ if (assignVal < 0)
995
1351
  throw new RangeError("ECI assignment value out of range");
996
- if (r < 128)
997
- e(r, 8, n);
998
- else if (r < 16384)
999
- e(2, 2, n), e(r, 14, n);
1000
- else if (r < 1e6)
1001
- e(6, 3, n), e(r, 21, n);
1002
- else
1352
+ else if (assignVal < 1 << 7)
1353
+ appendBits(assignVal, 8, bb);
1354
+ else if (assignVal < 1 << 14) {
1355
+ appendBits(2, 2, bb);
1356
+ appendBits(assignVal, 14, bb);
1357
+ } else if (assignVal < 1e6) {
1358
+ appendBits(6, 3, bb);
1359
+ appendBits(assignVal, 21, bb);
1360
+ } else
1003
1361
  throw new RangeError("ECI assignment value out of range");
1004
- return new j(j.Mode.ECI, 0, n);
1362
+ return new _QrSegment2(_QrSegment2.Mode.ECI, 0, bb);
1005
1363
  }
1006
1364
  // Tests whether the given string can be encoded as a segment in numeric mode.
1007
1365
  // A string is encodable iff each character is in the range 0 to 9.
1008
- static isNumeric(r) {
1009
- return j.NUMERIC_REGEX.test(r);
1366
+ static isNumeric(text) {
1367
+ return _QrSegment2.NUMERIC_REGEX.test(text);
1010
1368
  }
1011
1369
  // Tests whether the given string can be encoded as a segment in alphanumeric mode.
1012
1370
  // A string is encodable iff each character is in the following set: 0 to 9, A to Z
1013
1371
  // (uppercase only), space, dollar, percent, asterisk, plus, hyphen, period, slash, colon.
1014
- static isAlphanumeric(r) {
1015
- return j.ALPHANUMERIC_REGEX.test(r);
1372
+ static isAlphanumeric(text) {
1373
+ return _QrSegment2.ALPHANUMERIC_REGEX.test(text);
1016
1374
  }
1017
1375
  /*-- Methods --*/
1018
1376
  // Returns a new copy of the data bits of this segment.
@@ -1021,176 +1379,244 @@ var K;
1021
1379
  }
1022
1380
  // (Package-private) Calculates and returns the number of bits needed to encode the given segments at
1023
1381
  // the given version. The result is infinity if a segment has too many characters to fit its length field.
1024
- static getTotalBits(r, n) {
1025
- let a = 0;
1026
- for (const l of r) {
1027
- const d = l.mode.numCharCountBits(n);
1028
- if (l.numChars >= 1 << d)
1029
- return 1 / 0;
1030
- a += 4 + d + l.bitData.length;
1382
+ static getTotalBits(segs, version) {
1383
+ let result = 0;
1384
+ for (const seg of segs) {
1385
+ const ccbits = seg.mode.numCharCountBits(version);
1386
+ if (seg.numChars >= 1 << ccbits)
1387
+ return Infinity;
1388
+ result += 4 + ccbits + seg.bitData.length;
1031
1389
  }
1032
- return a;
1390
+ return result;
1033
1391
  }
1034
1392
  // Returns a new array of bytes representing the given string encoded in UTF-8.
1035
- static toUtf8ByteArray(r) {
1036
- r = encodeURI(r);
1037
- let n = [];
1038
- for (let a = 0; a < r.length; a++)
1039
- r.charAt(a) != "%" ? n.push(r.charCodeAt(a)) : (n.push(parseInt(r.substring(a + 1, a + 3), 16)), a += 2);
1040
- return n;
1393
+ static toUtf8ByteArray(str) {
1394
+ str = encodeURI(str);
1395
+ let result = [];
1396
+ for (let i = 0; i < str.length; i++) {
1397
+ if (str.charAt(i) != "%")
1398
+ result.push(str.charCodeAt(i));
1399
+ else {
1400
+ result.push(parseInt(str.substring(i + 1, i + 3), 16));
1401
+ i += 2;
1402
+ }
1403
+ }
1404
+ return result;
1041
1405
  }
1042
1406
  };
1043
- u.NUMERIC_REGEX = /^[0-9]*$/, u.ALPHANUMERIC_REGEX = /^[A-Z0-9 $%*+.\/:-]*$/, u.ALPHANUMERIC_CHARSET = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:";
1044
- let y = u;
1045
- s.QrSegment = u;
1046
- })(K || (K = {}));
1047
- ((s) => {
1048
- ((t) => {
1049
- const e = class {
1407
+ _QrSegment.NUMERIC_REGEX = /^[0-9]*$/;
1408
+ _QrSegment.ALPHANUMERIC_REGEX = /^[A-Z0-9 $%*+.\/:-]*$/;
1409
+ _QrSegment.ALPHANUMERIC_CHARSET = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:";
1410
+ let QrSegment = _QrSegment;
1411
+ qrcodegen2.QrSegment = _QrSegment;
1412
+ })(qrcodegen || (qrcodegen = {}));
1413
+ ((qrcodegen2) => {
1414
+ ((QrCode2) => {
1415
+ const _Ecc = class _Ecc {
1050
1416
  // The QR Code can tolerate about 30% erroneous codewords
1051
1417
  /*-- Constructor and fields --*/
1052
- constructor(c, u) {
1053
- this.ordinal = c, this.formatBits = u;
1418
+ constructor(ordinal, formatBits) {
1419
+ this.ordinal = ordinal;
1420
+ this.formatBits = formatBits;
1054
1421
  }
1055
1422
  };
1056
- e.LOW = new e(0, 1), e.MEDIUM = new e(1, 0), e.QUARTILE = new e(2, 3), e.HIGH = new e(3, 2), t.Ecc = e;
1057
- })(s.QrCode || (s.QrCode = {}));
1058
- })(K || (K = {}));
1059
- ((s) => {
1060
- ((t) => {
1061
- const e = class {
1423
+ _Ecc.LOW = new _Ecc(0, 1);
1424
+ _Ecc.MEDIUM = new _Ecc(1, 0);
1425
+ _Ecc.QUARTILE = new _Ecc(2, 3);
1426
+ _Ecc.HIGH = new _Ecc(3, 2);
1427
+ QrCode2.Ecc = _Ecc;
1428
+ })(qrcodegen2.QrCode || (qrcodegen2.QrCode = {}));
1429
+ })(qrcodegen || (qrcodegen = {}));
1430
+ ((qrcodegen2) => {
1431
+ ((QrSegment2) => {
1432
+ const _Mode = class _Mode {
1062
1433
  /*-- Constructor and fields --*/
1063
- constructor(c, u) {
1064
- this.modeBits = c, this.numBitsCharCount = u;
1434
+ constructor(modeBits, numBitsCharCount) {
1435
+ this.modeBits = modeBits;
1436
+ this.numBitsCharCount = numBitsCharCount;
1065
1437
  }
1066
1438
  /*-- Method --*/
1067
1439
  // (Package-private) Returns the bit width of the character count field for a segment in
1068
1440
  // this mode in a QR Code at the given version number. The result is in the range [0, 16].
1069
- numCharCountBits(c) {
1070
- return this.numBitsCharCount[Math.floor((c + 7) / 17)];
1441
+ numCharCountBits(ver) {
1442
+ return this.numBitsCharCount[Math.floor((ver + 7) / 17)];
1071
1443
  }
1072
1444
  };
1073
- e.NUMERIC = new e(1, [10, 12, 14]), e.ALPHANUMERIC = new e(2, [9, 11, 13]), e.BYTE = new e(4, [8, 16, 16]), e.KANJI = new e(8, [8, 10, 12]), e.ECI = new e(7, [0, 0, 0]), t.Mode = e;
1074
- })(s.QrSegment || (s.QrSegment = {}));
1075
- })(K || (K = {}));
1076
- var J = K;
1445
+ _Mode.NUMERIC = new _Mode(1, [10, 12, 14]);
1446
+ _Mode.ALPHANUMERIC = new _Mode(2, [9, 11, 13]);
1447
+ _Mode.BYTE = new _Mode(4, [8, 16, 16]);
1448
+ _Mode.KANJI = new _Mode(8, [8, 10, 12]);
1449
+ _Mode.ECI = new _Mode(7, [0, 0, 0]);
1450
+ QrSegment2.Mode = _Mode;
1451
+ })(qrcodegen2.QrSegment || (qrcodegen2.QrSegment = {}));
1452
+ })(qrcodegen || (qrcodegen = {}));
1453
+ var qrcodegen_default = qrcodegen;
1077
1454
  /**
1078
1455
  * @license qrcode.react
1079
1456
  * Copyright (c) Paul O'Shannessy
1080
1457
  * SPDX-License-Identifier: ISC
1081
1458
  */
1082
- var Et = {
1083
- L: J.QrCode.Ecc.LOW,
1084
- M: J.QrCode.Ecc.MEDIUM,
1085
- Q: J.QrCode.Ecc.QUARTILE,
1086
- H: J.QrCode.Ecc.HIGH
1087
- }, Ce = 128, je = "L", Me = "#FFFFFF", Re = "#000000", Se = !1, Le = 1, vt = 4, kt = 0, Tt = 0.1;
1088
- function Pe(s, t = 0) {
1089
- const e = [];
1090
- return s.forEach(function(i, c) {
1091
- let u = null;
1092
- i.forEach(function(y, x) {
1093
- if (!y && u !== null) {
1094
- e.push(
1095
- `M${u + t} ${c + t}h${x - u}v1H${u + t}z`
1096
- ), u = null;
1459
+ var ERROR_LEVEL_MAP = {
1460
+ L: qrcodegen_default.QrCode.Ecc.LOW,
1461
+ M: qrcodegen_default.QrCode.Ecc.MEDIUM,
1462
+ Q: qrcodegen_default.QrCode.Ecc.QUARTILE,
1463
+ H: qrcodegen_default.QrCode.Ecc.HIGH
1464
+ };
1465
+ var DEFAULT_SIZE = 128;
1466
+ var DEFAULT_LEVEL = "L";
1467
+ var DEFAULT_BGCOLOR = "#FFFFFF";
1468
+ var DEFAULT_FGCOLOR = "#000000";
1469
+ var DEFAULT_INCLUDEMARGIN = false;
1470
+ var DEFAULT_MINVERSION = 1;
1471
+ var SPEC_MARGIN_SIZE = 4;
1472
+ var DEFAULT_MARGIN_SIZE = 0;
1473
+ var DEFAULT_IMG_SCALE = 0.1;
1474
+ function generatePath(modules, margin = 0) {
1475
+ const ops = [];
1476
+ modules.forEach(function(row, y) {
1477
+ let start = null;
1478
+ row.forEach(function(cell, x) {
1479
+ if (!cell && start !== null) {
1480
+ ops.push(
1481
+ `M${start + margin} ${y + margin}h${x - start}v1H${start + margin}z`
1482
+ );
1483
+ start = null;
1097
1484
  return;
1098
1485
  }
1099
- if (x === i.length - 1) {
1100
- if (!y)
1486
+ if (x === row.length - 1) {
1487
+ if (!cell) {
1101
1488
  return;
1102
- u === null ? e.push(`M${x + t},${c + t} h1v1H${x + t}z`) : e.push(
1103
- `M${u + t},${c + t} h${x + 1 - u}v1H${u + t}z`
1104
- );
1489
+ }
1490
+ if (start === null) {
1491
+ ops.push(`M${x + margin},${y + margin} h1v1H${x + margin}z`);
1492
+ } else {
1493
+ ops.push(
1494
+ `M${start + margin},${y + margin} h${x + 1 - start}v1H${start + margin}z`
1495
+ );
1496
+ }
1105
1497
  return;
1106
1498
  }
1107
- y && u === null && (u = x);
1499
+ if (cell && start === null) {
1500
+ start = x;
1501
+ }
1108
1502
  });
1109
- }), e.join("");
1503
+ });
1504
+ return ops.join("");
1110
1505
  }
1111
- function De(s, t) {
1112
- return s.slice().map((e, i) => i < t.y || i >= t.y + t.h ? e : e.map((c, u) => u < t.x || u >= t.x + t.w ? c : !1));
1506
+ function excavateModules(modules, excavation) {
1507
+ return modules.slice().map((row, y) => {
1508
+ if (y < excavation.y || y >= excavation.y + excavation.h) {
1509
+ return row;
1510
+ }
1511
+ return row.map((cell, x) => {
1512
+ if (x < excavation.x || x >= excavation.x + excavation.w) {
1513
+ return cell;
1514
+ }
1515
+ return false;
1516
+ });
1517
+ });
1113
1518
  }
1114
- function At(s, t, e, i) {
1115
- if (i == null)
1519
+ function getImageSettings(cells, size, margin, imageSettings) {
1520
+ if (imageSettings == null) {
1116
1521
  return null;
1117
- const c = s.length + e * 2, u = Math.floor(t * Tt), y = c / t, x = (i.width || u) * y, r = (i.height || u) * y, n = i.x == null ? s.length / 2 - x / 2 : i.x * y, a = i.y == null ? s.length / 2 - r / 2 : i.y * y, l = i.opacity == null ? 1 : i.opacity;
1118
- let d = null;
1119
- if (i.excavate) {
1120
- let h = Math.floor(n), m = Math.floor(a), f = Math.ceil(x + n - h), k = Math.ceil(r + a - m);
1121
- d = { x: h, y: m, w: f, h: k };
1122
1522
  }
1123
- const g = i.crossOrigin;
1124
- return { x: n, y: a, h: r, w: x, excavation: d, opacity: l, crossOrigin: g };
1523
+ const numCells = cells.length + margin * 2;
1524
+ const defaultSize = Math.floor(size * DEFAULT_IMG_SCALE);
1525
+ const scale = numCells / size;
1526
+ const w = (imageSettings.width || defaultSize) * scale;
1527
+ const h = (imageSettings.height || defaultSize) * scale;
1528
+ const x = imageSettings.x == null ? cells.length / 2 - w / 2 : imageSettings.x * scale;
1529
+ const y = imageSettings.y == null ? cells.length / 2 - h / 2 : imageSettings.y * scale;
1530
+ const opacity = imageSettings.opacity == null ? 1 : imageSettings.opacity;
1531
+ let excavation = null;
1532
+ if (imageSettings.excavate) {
1533
+ let floorX = Math.floor(x);
1534
+ let floorY = Math.floor(y);
1535
+ let ceilW = Math.ceil(w + x - floorX);
1536
+ let ceilH = Math.ceil(h + y - floorY);
1537
+ excavation = { x: floorX, y: floorY, w: ceilW, h: ceilH };
1538
+ }
1539
+ const crossOrigin = imageSettings.crossOrigin;
1540
+ return { x, y, h, w, excavation, opacity, crossOrigin };
1125
1541
  }
1126
- function Ct(s, t) {
1127
- return t != null ? Math.max(Math.floor(t), 0) : s ? vt : kt;
1542
+ function getMarginSize(includeMargin, marginSize) {
1543
+ if (marginSize != null) {
1544
+ return Math.max(Math.floor(marginSize), 0);
1545
+ }
1546
+ return includeMargin ? SPEC_MARGIN_SIZE : DEFAULT_MARGIN_SIZE;
1128
1547
  }
1129
- function Ue({
1130
- value: s,
1131
- level: t,
1132
- minVersion: e,
1133
- includeMargin: i,
1134
- marginSize: c,
1135
- imageSettings: u,
1136
- size: y,
1137
- boostLevel: x
1548
+ function useQRCode({
1549
+ value,
1550
+ level,
1551
+ minVersion,
1552
+ includeMargin,
1553
+ marginSize,
1554
+ imageSettings,
1555
+ size,
1556
+ boostLevel
1138
1557
  }) {
1139
- let r = L.useMemo(() => {
1140
- const h = (Array.isArray(s) ? s : [s]).reduce((m, f) => (m.push(...J.QrSegment.makeSegments(f)), m), []);
1141
- return J.QrCode.encodeSegments(
1142
- h,
1143
- Et[t],
1144
- e,
1558
+ let qrcode = React.useMemo(() => {
1559
+ const values = Array.isArray(value) ? value : [value];
1560
+ const segments = values.reduce((accum, v) => {
1561
+ accum.push(...qrcodegen_default.QrSegment.makeSegments(v));
1562
+ return accum;
1563
+ }, []);
1564
+ return qrcodegen_default.QrCode.encodeSegments(
1565
+ segments,
1566
+ ERROR_LEVEL_MAP[level],
1567
+ minVersion,
1145
1568
  void 0,
1146
1569
  void 0,
1147
- x
1570
+ boostLevel
1148
1571
  );
1149
- }, [s, t, e, x]);
1150
- const { cells: n, margin: a, numCells: l, calculatedImageSettings: d } = L.useMemo(() => {
1151
- let g = r.getModules();
1152
- const h = Ct(i, c), m = g.length + h * 2, f = At(
1153
- g,
1154
- y,
1155
- h,
1156
- u
1572
+ }, [value, level, minVersion, boostLevel]);
1573
+ const { cells, margin, numCells, calculatedImageSettings } = React.useMemo(() => {
1574
+ let cells2 = qrcode.getModules();
1575
+ const margin2 = getMarginSize(includeMargin, marginSize);
1576
+ const numCells2 = cells2.length + margin2 * 2;
1577
+ const calculatedImageSettings2 = getImageSettings(
1578
+ cells2,
1579
+ size,
1580
+ margin2,
1581
+ imageSettings
1157
1582
  );
1158
1583
  return {
1159
- cells: g,
1160
- margin: h,
1161
- numCells: m,
1162
- calculatedImageSettings: f
1584
+ cells: cells2,
1585
+ margin: margin2,
1586
+ numCells: numCells2,
1587
+ calculatedImageSettings: calculatedImageSettings2
1163
1588
  };
1164
- }, [r, y, u, i, c]);
1589
+ }, [qrcode, size, imageSettings, includeMargin, marginSize]);
1165
1590
  return {
1166
- qrcode: r,
1167
- margin: a,
1168
- cells: n,
1169
- numCells: l,
1170
- calculatedImageSettings: d
1591
+ qrcode,
1592
+ margin,
1593
+ cells,
1594
+ numCells,
1595
+ calculatedImageSettings
1171
1596
  };
1172
1597
  }
1173
- var jt = function() {
1598
+ var SUPPORTS_PATH2D = function() {
1174
1599
  try {
1175
1600
  new Path2D().addPath(new Path2D());
1176
- } catch (s) {
1177
- return !1;
1601
+ } catch (e) {
1602
+ return false;
1178
1603
  }
1179
- return !0;
1180
- }(), Mt = L.forwardRef(
1181
- function(t, e) {
1182
- const i = t, {
1183
- value: c,
1184
- size: u = Ce,
1185
- level: y = je,
1186
- bgColor: x = Me,
1187
- fgColor: r = Re,
1188
- includeMargin: n = Se,
1189
- minVersion: a = Le,
1190
- boostLevel: l,
1191
- marginSize: d,
1192
- imageSettings: g
1193
- } = i, m = ce(i, [
1604
+ return true;
1605
+ }();
1606
+ var QRCodeCanvas = React.forwardRef(
1607
+ function QRCodeCanvas2(props, forwardedRef) {
1608
+ const _a = props, {
1609
+ value,
1610
+ size = DEFAULT_SIZE,
1611
+ level = DEFAULT_LEVEL,
1612
+ bgColor = DEFAULT_BGCOLOR,
1613
+ fgColor = DEFAULT_FGCOLOR,
1614
+ includeMargin = DEFAULT_INCLUDEMARGIN,
1615
+ minVersion = DEFAULT_MINVERSION,
1616
+ boostLevel,
1617
+ marginSize,
1618
+ imageSettings
1619
+ } = _a, extraProps = __objRest(_a, [
1194
1620
  "value",
1195
1621
  "size",
1196
1622
  "level",
@@ -1201,92 +1627,131 @@ var jt = function() {
1201
1627
  "boostLevel",
1202
1628
  "marginSize",
1203
1629
  "imageSettings"
1204
- ]), { style: f } = m, k = ce(m, ["style"]), w = g == null ? void 0 : g.src, p = L.useRef(null), T = L.useRef(null), C = L.useCallback(
1205
- (W) => {
1206
- p.current = W, typeof e == "function" ? e(W) : e && (e.current = W);
1630
+ ]);
1631
+ const _b = extraProps, { style } = _b, otherProps = __objRest(_b, ["style"]);
1632
+ const imgSrc = imageSettings == null ? void 0 : imageSettings.src;
1633
+ const _canvas = React.useRef(null);
1634
+ const _image = React.useRef(null);
1635
+ const setCanvasRef = React.useCallback(
1636
+ (node) => {
1637
+ _canvas.current = node;
1638
+ if (typeof forwardedRef === "function") {
1639
+ forwardedRef(node);
1640
+ } else if (forwardedRef) {
1641
+ forwardedRef.current = node;
1642
+ }
1207
1643
  },
1208
- [e]
1209
- ), [q, H] = L.useState(!1), { margin: O, cells: M, numCells: v, calculatedImageSettings: S } = Ue({
1210
- value: c,
1211
- level: y,
1212
- minVersion: a,
1213
- boostLevel: l,
1214
- includeMargin: n,
1215
- marginSize: d,
1216
- imageSettings: g,
1217
- size: u
1644
+ [forwardedRef]
1645
+ );
1646
+ const [isImgLoaded, setIsImageLoaded] = React.useState(false);
1647
+ const { margin, cells, numCells, calculatedImageSettings } = useQRCode({
1648
+ value,
1649
+ level,
1650
+ minVersion,
1651
+ boostLevel,
1652
+ includeMargin,
1653
+ marginSize,
1654
+ imageSettings,
1655
+ size
1218
1656
  });
1219
- L.useEffect(() => {
1220
- if (p.current != null) {
1221
- const W = p.current, I = W.getContext("2d");
1222
- if (!I)
1657
+ React.useEffect(() => {
1658
+ if (_canvas.current != null) {
1659
+ const canvas = _canvas.current;
1660
+ const ctx = canvas.getContext("2d");
1661
+ if (!ctx) {
1223
1662
  return;
1224
- let V = M;
1225
- const $ = T.current, te = S != null && $ !== null && $.complete && $.naturalHeight !== 0 && $.naturalWidth !== 0;
1226
- te && S.excavation != null && (V = De(
1227
- M,
1228
- S.excavation
1229
- ));
1230
- const X = window.devicePixelRatio || 1;
1231
- W.height = W.width = u * X;
1232
- const G = u / v * X;
1233
- I.scale(G, G), I.fillStyle = x, I.fillRect(0, 0, v, v), I.fillStyle = r, jt ? I.fill(new Path2D(Pe(V, O))) : M.forEach(function(oe, re) {
1234
- oe.forEach(function(ae, P) {
1235
- ae && I.fillRect(P + O, re + O, 1, 1);
1663
+ }
1664
+ let cellsToDraw = cells;
1665
+ const image = _image.current;
1666
+ const haveImageToRender = calculatedImageSettings != null && image !== null && image.complete && image.naturalHeight !== 0 && image.naturalWidth !== 0;
1667
+ if (haveImageToRender) {
1668
+ if (calculatedImageSettings.excavation != null) {
1669
+ cellsToDraw = excavateModules(
1670
+ cells,
1671
+ calculatedImageSettings.excavation
1672
+ );
1673
+ }
1674
+ }
1675
+ const pixelRatio = window.devicePixelRatio || 1;
1676
+ canvas.height = canvas.width = size * pixelRatio;
1677
+ const scale = size / numCells * pixelRatio;
1678
+ ctx.scale(scale, scale);
1679
+ ctx.fillStyle = bgColor;
1680
+ ctx.fillRect(0, 0, numCells, numCells);
1681
+ ctx.fillStyle = fgColor;
1682
+ if (SUPPORTS_PATH2D) {
1683
+ ctx.fill(new Path2D(generatePath(cellsToDraw, margin)));
1684
+ } else {
1685
+ cells.forEach(function(row, rdx) {
1686
+ row.forEach(function(cell, cdx) {
1687
+ if (cell) {
1688
+ ctx.fillRect(cdx + margin, rdx + margin, 1, 1);
1689
+ }
1690
+ });
1236
1691
  });
1237
- }), S && (I.globalAlpha = S.opacity), te && I.drawImage(
1238
- $,
1239
- S.x + O,
1240
- S.y + O,
1241
- S.w,
1242
- S.h
1243
- );
1244
- }
1245
- }), L.useEffect(() => {
1246
- H(!1);
1247
- }, [w]);
1248
- const B = le({ height: u, width: u }, f);
1249
- let ee = null;
1250
- return w != null && (ee = /* @__PURE__ */ L.createElement(
1251
- "img",
1252
- {
1253
- src: w,
1254
- key: w,
1255
- style: { display: "none" },
1256
- onLoad: () => {
1257
- H(!0);
1258
- },
1259
- ref: T,
1260
- crossOrigin: S == null ? void 0 : S.crossOrigin
1692
+ }
1693
+ if (calculatedImageSettings) {
1694
+ ctx.globalAlpha = calculatedImageSettings.opacity;
1695
+ }
1696
+ if (haveImageToRender) {
1697
+ ctx.drawImage(
1698
+ image,
1699
+ calculatedImageSettings.x + margin,
1700
+ calculatedImageSettings.y + margin,
1701
+ calculatedImageSettings.w,
1702
+ calculatedImageSettings.h
1703
+ );
1704
+ }
1261
1705
  }
1262
- )), /* @__PURE__ */ L.createElement(L.Fragment, null, /* @__PURE__ */ L.createElement(
1706
+ });
1707
+ React.useEffect(() => {
1708
+ setIsImageLoaded(false);
1709
+ }, [imgSrc]);
1710
+ const canvasStyle = __spreadValues2({ height: size, width: size }, style);
1711
+ let img = null;
1712
+ if (imgSrc != null) {
1713
+ img = /* @__PURE__ */ React.createElement(
1714
+ "img",
1715
+ {
1716
+ src: imgSrc,
1717
+ key: imgSrc,
1718
+ style: { display: "none" },
1719
+ onLoad: () => {
1720
+ setIsImageLoaded(true);
1721
+ },
1722
+ ref: _image,
1723
+ crossOrigin: calculatedImageSettings == null ? void 0 : calculatedImageSettings.crossOrigin
1724
+ }
1725
+ );
1726
+ }
1727
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(
1263
1728
  "canvas",
1264
- le({
1265
- style: B,
1266
- height: u,
1267
- width: u,
1268
- ref: C,
1729
+ __spreadValues2({
1730
+ style: canvasStyle,
1731
+ height: size,
1732
+ width: size,
1733
+ ref: setCanvasRef,
1269
1734
  role: "img"
1270
- }, k)
1271
- ), ee);
1735
+ }, otherProps)
1736
+ ), img);
1272
1737
  }
1273
1738
  );
1274
- Mt.displayName = "QRCodeCanvas";
1275
- var Oe = L.forwardRef(
1276
- function(t, e) {
1277
- const i = t, {
1278
- value: c,
1279
- size: u = Ce,
1280
- level: y = je,
1281
- bgColor: x = Me,
1282
- fgColor: r = Re,
1283
- includeMargin: n = Se,
1284
- minVersion: a = Le,
1285
- boostLevel: l,
1286
- title: d,
1287
- marginSize: g,
1288
- imageSettings: h
1289
- } = i, m = ce(i, [
1739
+ QRCodeCanvas.displayName = "QRCodeCanvas";
1740
+ var QRCodeSVG = React.forwardRef(
1741
+ function QRCodeSVG2(props, forwardedRef) {
1742
+ const _a = props, {
1743
+ value,
1744
+ size = DEFAULT_SIZE,
1745
+ level = DEFAULT_LEVEL,
1746
+ bgColor = DEFAULT_BGCOLOR,
1747
+ fgColor = DEFAULT_FGCOLOR,
1748
+ includeMargin = DEFAULT_INCLUDEMARGIN,
1749
+ minVersion = DEFAULT_MINVERSION,
1750
+ boostLevel,
1751
+ title,
1752
+ marginSize,
1753
+ imageSettings
1754
+ } = _a, otherProps = __objRest(_a, [
1290
1755
  "value",
1291
1756
  "size",
1292
1757
  "level",
@@ -1298,230 +1763,266 @@ var Oe = L.forwardRef(
1298
1763
  "title",
1299
1764
  "marginSize",
1300
1765
  "imageSettings"
1301
- ]), { margin: f, cells: k, numCells: w, calculatedImageSettings: p } = Ue({
1302
- value: c,
1303
- level: y,
1304
- minVersion: a,
1305
- boostLevel: l,
1306
- includeMargin: n,
1307
- marginSize: g,
1308
- imageSettings: h,
1309
- size: u
1766
+ ]);
1767
+ const { margin, cells, numCells, calculatedImageSettings } = useQRCode({
1768
+ value,
1769
+ level,
1770
+ minVersion,
1771
+ boostLevel,
1772
+ includeMargin,
1773
+ marginSize,
1774
+ imageSettings,
1775
+ size
1310
1776
  });
1311
- let T = k, C = null;
1312
- h != null && p != null && (p.excavation != null && (T = De(
1313
- k,
1314
- p.excavation
1315
- )), C = /* @__PURE__ */ L.createElement(
1316
- "image",
1317
- {
1318
- href: h.src,
1319
- height: p.h,
1320
- width: p.w,
1321
- x: p.x + f,
1322
- y: p.y + f,
1323
- preserveAspectRatio: "none",
1324
- opacity: p.opacity,
1325
- crossOrigin: p.crossOrigin
1777
+ let cellsToDraw = cells;
1778
+ let image = null;
1779
+ if (imageSettings != null && calculatedImageSettings != null) {
1780
+ if (calculatedImageSettings.excavation != null) {
1781
+ cellsToDraw = excavateModules(
1782
+ cells,
1783
+ calculatedImageSettings.excavation
1784
+ );
1326
1785
  }
1327
- ));
1328
- const q = Pe(T, f);
1329
- return /* @__PURE__ */ L.createElement(
1786
+ image = /* @__PURE__ */ React.createElement(
1787
+ "image",
1788
+ {
1789
+ href: imageSettings.src,
1790
+ height: calculatedImageSettings.h,
1791
+ width: calculatedImageSettings.w,
1792
+ x: calculatedImageSettings.x + margin,
1793
+ y: calculatedImageSettings.y + margin,
1794
+ preserveAspectRatio: "none",
1795
+ opacity: calculatedImageSettings.opacity,
1796
+ crossOrigin: calculatedImageSettings.crossOrigin
1797
+ }
1798
+ );
1799
+ }
1800
+ const fgPath = generatePath(cellsToDraw, margin);
1801
+ return /* @__PURE__ */ React.createElement(
1330
1802
  "svg",
1331
- le({
1332
- height: u,
1333
- width: u,
1334
- viewBox: `0 0 ${w} ${w}`,
1335
- ref: e,
1803
+ __spreadValues2({
1804
+ height: size,
1805
+ width: size,
1806
+ viewBox: `0 0 ${numCells} ${numCells}`,
1807
+ ref: forwardedRef,
1336
1808
  role: "img"
1337
- }, m),
1338
- !!d && /* @__PURE__ */ L.createElement("title", null, d),
1339
- /* @__PURE__ */ L.createElement(
1809
+ }, otherProps),
1810
+ !!title && /* @__PURE__ */ React.createElement("title", null, title),
1811
+ /* @__PURE__ */ React.createElement(
1340
1812
  "path",
1341
1813
  {
1342
- fill: x,
1343
- d: `M0,0 h${w}v${w}H0z`,
1814
+ fill: bgColor,
1815
+ d: `M0,0 h${numCells}v${numCells}H0z`,
1344
1816
  shapeRendering: "crispEdges"
1345
1817
  }
1346
1818
  ),
1347
- /* @__PURE__ */ L.createElement("path", { fill: r, d: q, shapeRendering: "crispEdges" }),
1348
- C
1819
+ /* @__PURE__ */ React.createElement("path", { fill: fgColor, d: fgPath, shapeRendering: "crispEdges" }),
1820
+ image
1349
1821
  );
1350
1822
  }
1351
1823
  );
1352
- Oe.displayName = "QRCodeSVG";
1353
- const Rt = ({
1354
- walletAddress: s,
1355
- amount: t,
1356
- currency: e,
1357
- network: i,
1358
- theme: c = "light",
1359
- size: u = 200
1824
+ QRCodeSVG.displayName = "QRCodeSVG";
1825
+ const QRCode = ({
1826
+ walletAddress,
1827
+ amount,
1828
+ currency,
1829
+ network,
1830
+ theme = "light",
1831
+ size = 200
1360
1832
  }) => {
1361
- const [y, x] = D(""), [r, n] = D(null);
1362
- Z(() => {
1363
- if (!s || s === "No address configured") {
1364
- n("No wallet address configured for this network");
1833
+ const [qrData, setQrData] = useState("");
1834
+ const [qrError, setQrError] = useState(null);
1835
+ useEffect(() => {
1836
+ if (!walletAddress || walletAddress === "No address configured") {
1837
+ setQrError("No wallet address configured for this network");
1365
1838
  return;
1366
1839
  }
1367
1840
  try {
1368
- let m;
1369
- switch (i) {
1841
+ let paymentData;
1842
+ switch (network) {
1370
1843
  case "tron":
1371
- e === "TRX" ? m = `tronlink://transfer?to=${s}&amount=${t}` : m = s;
1844
+ if (currency === "TRX") {
1845
+ paymentData = `tronlink://transfer?to=${walletAddress}&amount=${amount}`;
1846
+ } else {
1847
+ paymentData = walletAddress;
1848
+ }
1372
1849
  break;
1373
1850
  case "algorand":
1374
- m = `algorand://${s}?amount=${Math.floor(parseFloat(t) * 1e6)}`;
1851
+ paymentData = `algorand://${walletAddress}?amount=${Math.floor(parseFloat(amount) * 1e6)}`;
1375
1852
  break;
1376
1853
  case "bsc":
1377
- if (e === "BNB")
1378
- m = `ethereum:${s}@56?value=${d(t)}`;
1379
- else {
1380
- const f = a(e, "bsc");
1381
- f ? m = `ethereum:${f}/transfer?address=${s}&uint256=${l(t, e)}@56` : m = s;
1854
+ if (currency === "BNB") {
1855
+ paymentData = `ethereum:${walletAddress}@56?value=${convertToWei(amount)}`;
1856
+ } else {
1857
+ const tokenAddress = getTokenAddressForCurrency(currency, "bsc");
1858
+ if (tokenAddress) {
1859
+ paymentData = `ethereum:${tokenAddress}/transfer?address=${walletAddress}&uint256=${convertToSmallestUnit(amount, currency)}@56`;
1860
+ } else {
1861
+ paymentData = walletAddress;
1862
+ }
1382
1863
  }
1383
1864
  break;
1384
1865
  case "ethereum":
1385
1866
  default:
1386
- if (e === "ETH")
1387
- m = `ethereum:${s}@1?value=${d(t)}`;
1388
- else {
1389
- const f = a(e, "ethereum");
1390
- f ? m = `ethereum:${f}/transfer?address=${s}&uint256=${l(t, e)}` : m = s;
1867
+ if (currency === "ETH") {
1868
+ paymentData = `ethereum:${walletAddress}@1?value=${convertToWei(amount)}`;
1869
+ } else {
1870
+ const tokenAddress = getTokenAddressForCurrency(currency, "ethereum");
1871
+ if (tokenAddress) {
1872
+ paymentData = `ethereum:${tokenAddress}/transfer?address=${walletAddress}&uint256=${convertToSmallestUnit(amount, currency)}`;
1873
+ } else {
1874
+ paymentData = walletAddress;
1875
+ }
1391
1876
  }
1392
1877
  break;
1393
1878
  }
1394
- x(m), n(null);
1395
- } catch (m) {
1396
- console.error("Error generating QR code:", m), n("Error generating payment QR code");
1397
- }
1398
- }, [s, t, e, i]);
1399
- const a = (m, f) => {
1400
- var w;
1401
- return ((w = {
1879
+ setQrData(paymentData);
1880
+ setQrError(null);
1881
+ } catch (err) {
1882
+ console.error("Error generating QR code:", err);
1883
+ setQrError("Error generating payment QR code");
1884
+ }
1885
+ }, [walletAddress, amount, currency, network]);
1886
+ const getTokenAddressForCurrency = (currency2, network2) => {
1887
+ var _a;
1888
+ const tokenAddresses = {
1402
1889
  ethereum: {
1403
- USDT: "0xdAC17F958D2ee523a2206206994597C13D831ec7",
1404
- USDC: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"
1890
+ "USDT": "0xdAC17F958D2ee523a2206206994597C13D831ec7",
1891
+ "USDC": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"
1405
1892
  },
1406
1893
  bsc: {
1407
- USDT: "0x55d398326f99059fF775485246999027B3197955",
1408
- USDC: "0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d"
1894
+ "USDT": "0x55d398326f99059fF775485246999027B3197955",
1895
+ "USDC": "0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d"
1409
1896
  },
1410
1897
  tron: {
1411
- USDT: "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t",
1412
- USDC: "TEkxiTehnzSmSe2XqrBj4w32RUN966rdz8"
1898
+ "USDT": "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t",
1899
+ "USDC": "TEkxiTehnzSmSe2XqrBj4w32RUN966rdz8"
1413
1900
  }
1414
- }[f]) == null ? void 0 : w[m]) || "";
1415
- }, l = (m, f) => {
1416
- const k = f === "USDT" || f === "USDC" ? 6 : 18;
1417
- return Math.floor(parseFloat(m) * Math.pow(10, k)).toString();
1418
- }, d = (m) => Math.floor(parseFloat(m) * 1e18).toString(), g = (m) => ({
1419
- ethereum: "Ethereum",
1420
- bsc: "BSC",
1421
- tron: "Tron",
1422
- algorand: "Algorand"
1423
- })[m] || m, h = (m) => ({
1424
- ethereum: ["MetaMask", "Trust Wallet", "Coinbase Wallet"],
1425
- bsc: ["MetaMask", "Trust Wallet", "SafePal"],
1426
- tron: ["TronLink", "Trust Wallet"],
1427
- algorand: ["Pera Wallet", "MyAlgo Wallet"]
1428
- })[m] || ["MetaMask", "Trust Wallet"];
1429
- return /* @__PURE__ */ o.jsxs("div", { className: "flex flex-col items-center", children: [
1430
- r ? /* @__PURE__ */ o.jsxs("div", { className: "p-4 rounded-lg bg-red-100 mb-3 text-red-700 text-center", children: [
1431
- /* @__PURE__ */ o.jsx("svg", { xmlns: "http://www.w3.org/2000/svg", className: "h-8 w-8 mx-auto mb-2", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", children: /* @__PURE__ */ o.jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z" }) }),
1432
- /* @__PURE__ */ o.jsx("p", { className: "font-medium", children: r })
1433
- ] }) : /* @__PURE__ */ o.jsx("div", { className: "p-4 rounded-lg bg-white mb-3 shadow-sm border", children: y && /* @__PURE__ */ o.jsx(
1434
- Oe,
1901
+ };
1902
+ return ((_a = tokenAddresses[network2]) == null ? void 0 : _a[currency2]) || "";
1903
+ };
1904
+ const convertToSmallestUnit = (amount2, currency2) => {
1905
+ const decimals = currency2 === "USDT" || currency2 === "USDC" ? 6 : 18;
1906
+ return Math.floor(parseFloat(amount2) * Math.pow(10, decimals)).toString();
1907
+ };
1908
+ const convertToWei = (amount2) => {
1909
+ return Math.floor(parseFloat(amount2) * 1e18).toString();
1910
+ };
1911
+ const getNetworkDisplayName = (network2) => {
1912
+ const names = {
1913
+ ethereum: "Ethereum",
1914
+ bsc: "BSC",
1915
+ tron: "Tron",
1916
+ algorand: "Algorand"
1917
+ };
1918
+ return names[network2] || network2;
1919
+ };
1920
+ const getWalletSuggestions = (network2) => {
1921
+ const suggestions = {
1922
+ ethereum: ["MetaMask", "Trust Wallet", "Coinbase Wallet"],
1923
+ bsc: ["MetaMask", "Trust Wallet", "SafePal"],
1924
+ tron: ["TronLink", "Trust Wallet"],
1925
+ algorand: ["Pera Wallet", "MyAlgo Wallet"]
1926
+ };
1927
+ return suggestions[network2] || ["MetaMask", "Trust Wallet"];
1928
+ };
1929
+ return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex flex-col items-center", children: [
1930
+ qrError ? /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "p-4 rounded-lg bg-red-100 mb-3 text-red-700 text-center", children: [
1931
+ /* @__PURE__ */ jsxRuntimeExports.jsx("svg", { xmlns: "http://www.w3.org/2000/svg", className: "h-8 w-8 mx-auto mb-2", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", children: /* @__PURE__ */ jsxRuntimeExports.jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z" }) }),
1932
+ /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "font-medium", children: qrError })
1933
+ ] }) : /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "p-4 rounded-lg bg-white mb-3 shadow-sm border", children: qrData && /* @__PURE__ */ jsxRuntimeExports.jsx(
1934
+ QRCodeSVG,
1435
1935
  {
1436
- value: y,
1437
- size: u,
1438
- bgColor: c === "dark" ? "#374151" : "#FFFFFF",
1439
- fgColor: c === "dark" ? "#FFFFFF" : "#000000",
1936
+ value: qrData,
1937
+ size,
1938
+ bgColor: theme === "dark" ? "#374151" : "#FFFFFF",
1939
+ fgColor: theme === "dark" ? "#FFFFFF" : "#000000",
1440
1940
  level: "H",
1441
- includeMargin: !0
1941
+ includeMargin: true
1442
1942
  }
1443
1943
  ) }),
1444
- /* @__PURE__ */ o.jsxs("div", { className: "text-center text-sm text-gray-700 mb-4", children: [
1445
- /* @__PURE__ */ o.jsxs("p", { className: "font-semibold text-gray-800 flex items-center justify-center", children: [
1446
- /* @__PURE__ */ o.jsx("svg", { xmlns: "http://www.w3.org/2000/svg", className: "h-4 w-4 mr-1", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", children: /* @__PURE__ */ o.jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M12 4v1m6 11h2m-6 0h-2v4m0-11v3m0 0h.01M12 12h4.01M12 12h-4.01M12 12V8.01" }) }),
1944
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "text-center text-sm text-gray-700 mb-4", children: [
1945
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("p", { className: "font-semibold text-gray-800 flex items-center justify-center", children: [
1946
+ /* @__PURE__ */ jsxRuntimeExports.jsx("svg", { xmlns: "http://www.w3.org/2000/svg", className: "h-4 w-4 mr-1", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", children: /* @__PURE__ */ jsxRuntimeExports.jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M12 4v1m6 11h2m-6 0h-2v4m0-11v3m0 0h.01M12 12h4.01M12 12h-4.01M12 12V8.01" }) }),
1447
1947
  "Scan to Pay with ",
1448
- e
1948
+ currency
1449
1949
  ] }),
1450
- /* @__PURE__ */ o.jsxs("p", { className: "text-xs text-gray-500 mt-1", children: [
1950
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("p", { className: "text-xs text-gray-500 mt-1", children: [
1451
1951
  "Scan with your ",
1452
- g(i),
1952
+ getNetworkDisplayName(network),
1453
1953
  " wallet app"
1454
1954
  ] })
1455
1955
  ] }),
1456
- /* @__PURE__ */ o.jsxs("div", { className: "w-full mb-4 p-3 bg-gray-50 rounded-lg", children: [
1457
- /* @__PURE__ */ o.jsxs("div", { className: "flex justify-between items-center", children: [
1458
- /* @__PURE__ */ o.jsx("span", { className: "text-sm font-medium text-gray-700", children: "Amount to Pay:" }),
1459
- /* @__PURE__ */ o.jsxs("span", { className: "text-lg font-bold text-[#7042D2]", children: [
1460
- t,
1956
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "w-full mb-4 p-3 bg-gray-50 rounded-lg", children: [
1957
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex justify-between items-center", children: [
1958
+ /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-sm font-medium text-gray-700", children: "Amount to Pay:" }),
1959
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "text-lg font-bold text-[#7042D2]", children: [
1960
+ amount,
1461
1961
  " ",
1462
- e
1962
+ currency
1463
1963
  ] })
1464
1964
  ] }),
1465
- /* @__PURE__ */ o.jsxs("div", { className: "flex justify-between items-center mt-1", children: [
1466
- /* @__PURE__ */ o.jsx("span", { className: "text-xs text-gray-500", children: "Network:" }),
1467
- /* @__PURE__ */ o.jsx("span", { className: "text-xs font-medium text-gray-700", children: g(i) })
1965
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex justify-between items-center mt-1", children: [
1966
+ /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-xs text-gray-500", children: "Network:" }),
1967
+ /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-xs font-medium text-gray-700", children: getNetworkDisplayName(network) })
1468
1968
  ] })
1469
1969
  ] }),
1470
- !r && /* @__PURE__ */ o.jsxs("div", { className: "w-full mb-4", children: [
1471
- /* @__PURE__ */ o.jsx("p", { className: "text-xs text-gray-500 mb-1 text-center", children: "Or copy wallet address:" }),
1472
- /* @__PURE__ */ o.jsx(
1970
+ !qrError && /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "w-full mb-4", children: [
1971
+ /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xs text-gray-500 mb-1 text-center", children: "Or copy wallet address:" }),
1972
+ /* @__PURE__ */ jsxRuntimeExports.jsx(
1473
1973
  "div",
1474
1974
  {
1475
1975
  className: "text-xs font-mono p-2 rounded bg-gray-100 text-gray-700 break-all text-center select-all cursor-pointer border",
1476
1976
  onClick: () => {
1477
- var m;
1478
- return (m = navigator.clipboard) == null ? void 0 : m.writeText(s);
1977
+ var _a;
1978
+ return (_a = navigator.clipboard) == null ? void 0 : _a.writeText(walletAddress);
1479
1979
  },
1480
1980
  title: "Click to copy",
1481
- children: s
1981
+ children: walletAddress
1482
1982
  }
1483
1983
  )
1484
1984
  ] }),
1485
- /* @__PURE__ */ o.jsx("div", { className: "w-full", children: /* @__PURE__ */ o.jsxs("div", { className: "p-3 rounded bg-blue-50 border border-blue-200", children: [
1486
- /* @__PURE__ */ o.jsxs("h4", { className: "text-sm font-medium mb-2 text-blue-800 flex items-center", children: [
1487
- /* @__PURE__ */ o.jsx("svg", { xmlns: "http://www.w3.org/2000/svg", className: "h-4 w-4 mr-1", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", children: /* @__PURE__ */ o.jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" }) }),
1985
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "w-full", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "p-3 rounded bg-blue-50 border border-blue-200", children: [
1986
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("h4", { className: "text-sm font-medium mb-2 text-blue-800 flex items-center", children: [
1987
+ /* @__PURE__ */ jsxRuntimeExports.jsx("svg", { xmlns: "http://www.w3.org/2000/svg", className: "h-4 w-4 mr-1", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", children: /* @__PURE__ */ jsxRuntimeExports.jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" }) }),
1488
1988
  "Payment Instructions"
1489
1989
  ] }),
1490
- /* @__PURE__ */ o.jsxs("ol", { className: "text-xs space-y-1 text-blue-700", children: [
1491
- /* @__PURE__ */ o.jsxs("li", { children: [
1990
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("ol", { className: "text-xs space-y-1 text-blue-700", children: [
1991
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("li", { children: [
1492
1992
  "1. Open your crypto wallet app (",
1493
- h(i).join(", "),
1993
+ getWalletSuggestions(network).join(", "),
1494
1994
  ")"
1495
1995
  ] }),
1496
- /* @__PURE__ */ o.jsx("li", { children: "2. Scan the QR code above or copy the wallet address" }),
1497
- /* @__PURE__ */ o.jsxs("li", { children: [
1996
+ /* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: "2. Scan the QR code above or copy the wallet address" }),
1997
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("li", { children: [
1498
1998
  "3. Send exactly ",
1499
- /* @__PURE__ */ o.jsxs("strong", { children: [
1500
- t,
1999
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("strong", { children: [
2000
+ amount,
1501
2001
  " ",
1502
- e
2002
+ currency
1503
2003
  ] }),
1504
2004
  " on ",
1505
- g(i),
2005
+ getNetworkDisplayName(network),
1506
2006
  " network"
1507
2007
  ] }),
1508
- /* @__PURE__ */ o.jsx("li", { children: '4. Click "I have sent the payment" button below after sending' })
2008
+ /* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: '4. Click "I have sent the payment" button below after sending' })
1509
2009
  ] }),
1510
- /* @__PURE__ */ o.jsx("div", { className: "mt-3 p-2 bg-yellow-50 border border-yellow-200 rounded", children: /* @__PURE__ */ o.jsxs("p", { className: "text-xs text-yellow-800", children: [
1511
- /* @__PURE__ */ o.jsx("strong", { children: "Important:" }),
2010
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "mt-3 p-2 bg-yellow-50 border border-yellow-200 rounded", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("p", { className: "text-xs text-yellow-800", children: [
2011
+ /* @__PURE__ */ jsxRuntimeExports.jsx("strong", { children: "Important:" }),
1512
2012
  " Make sure you're sending on the correct network (",
1513
- g(i),
2013
+ getNetworkDisplayName(network),
1514
2014
  ") and using the exact amount shown above."
1515
2015
  ] }) })
1516
2016
  ] }) })
1517
2017
  ] });
1518
- }, ie = ({ status: s, message: t, theme: e = "light" }) => {
1519
- const i = () => {
1520
- switch (s) {
2018
+ };
2019
+ const PaymentStatus = ({ status, message, theme = "light" }) => {
2020
+ const renderIcon = () => {
2021
+ switch (status) {
1521
2022
  case "processing":
1522
- return /* @__PURE__ */ o.jsx("div", { className: "animate-spin rounded-full h-12 w-12 border-4 border-t-blue-500 border-blue-500/20" });
2023
+ return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "animate-spin rounded-full h-12 w-12 border-4 border-t-blue-500 border-blue-500/20" });
1523
2024
  case "success":
1524
- return /* @__PURE__ */ o.jsx("div", { className: "rounded-full h-12 w-12 bg-green-100 flex items-center justify-center", children: /* @__PURE__ */ o.jsx(
2025
+ return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "rounded-full h-12 w-12 bg-green-100 flex items-center justify-center", children: /* @__PURE__ */ jsxRuntimeExports.jsx(
1525
2026
  "svg",
1526
2027
  {
1527
2028
  xmlns: "http://www.w3.org/2000/svg",
@@ -1530,11 +2031,11 @@ const Rt = ({
1530
2031
  viewBox: "0 0 24 24",
1531
2032
  stroke: "currentColor",
1532
2033
  strokeWidth: 2,
1533
- children: /* @__PURE__ */ o.jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M5 13l4 4L19 7" })
2034
+ children: /* @__PURE__ */ jsxRuntimeExports.jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M5 13l4 4L19 7" })
1534
2035
  }
1535
2036
  ) });
1536
2037
  case "error":
1537
- return /* @__PURE__ */ o.jsx("div", { className: "rounded-full h-12 w-12 bg-red-100 flex items-center justify-center", children: /* @__PURE__ */ o.jsx(
2038
+ return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "rounded-full h-12 w-12 bg-red-100 flex items-center justify-center", children: /* @__PURE__ */ jsxRuntimeExports.jsx(
1538
2039
  "svg",
1539
2040
  {
1540
2041
  xmlns: "http://www.w3.org/2000/svg",
@@ -1543,14 +2044,15 @@ const Rt = ({
1543
2044
  viewBox: "0 0 24 24",
1544
2045
  stroke: "currentColor",
1545
2046
  strokeWidth: 2,
1546
- children: /* @__PURE__ */ o.jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M6 18L18 6M6 6l12 12" })
2047
+ children: /* @__PURE__ */ jsxRuntimeExports.jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M6 18L18 6M6 6l12 12" })
1547
2048
  }
1548
2049
  ) });
1549
2050
  default:
1550
2051
  return null;
1551
2052
  }
1552
- }, c = () => {
1553
- switch (s) {
2053
+ };
2054
+ const getStatusTitle = () => {
2055
+ switch (status) {
1554
2056
  case "processing":
1555
2057
  return "Processing Payment";
1556
2058
  case "success":
@@ -1560,192 +2062,268 @@ const Rt = ({
1560
2062
  default:
1561
2063
  return "Unknown Status";
1562
2064
  }
1563
- }, u = () => {
1564
- switch (s) {
2065
+ };
2066
+ const getMessageClasses = () => {
2067
+ switch (status) {
1565
2068
  case "processing":
1566
- return e === "dark" ? "text-blue-300" : "text-blue-600";
2069
+ return theme === "dark" ? "text-blue-300" : "text-blue-600";
1567
2070
  case "success":
1568
- return e === "dark" ? "text-green-300" : "text-green-600";
2071
+ return theme === "dark" ? "text-green-300" : "text-green-600";
1569
2072
  case "error":
1570
- return e === "dark" ? "text-red-300" : "text-red-600";
2073
+ return theme === "dark" ? "text-red-300" : "text-red-600";
1571
2074
  default:
1572
- return e === "dark" ? "text-gray-300" : "text-gray-600";
2075
+ return theme === "dark" ? "text-gray-300" : "text-gray-600";
1573
2076
  }
1574
2077
  };
1575
- return /* @__PURE__ */ o.jsxs("div", { className: "flex flex-col items-center justify-center py-6", children: [
1576
- /* @__PURE__ */ o.jsx("div", { className: "mb-4", children: i() }),
1577
- /* @__PURE__ */ o.jsx("h3", { className: `text-xl font-bold mb-2 ${e === "dark" ? "text-white" : "text-gray-900"}`, children: c() }),
1578
- /* @__PURE__ */ o.jsx("p", { className: `text-center ${u()}`, children: t }),
1579
- s === "processing" && /* @__PURE__ */ o.jsx("div", { className: `mt-4 text-xs ${e === "dark" ? "text-gray-400" : "text-gray-500"}`, children: "This may take a few moments. Please do not close this window." }),
1580
- s === "success" && /* @__PURE__ */ o.jsx("div", { className: `mt-4 p-2 rounded ${e === "dark" ? "bg-gray-700" : "bg-gray-100"}`, children: /* @__PURE__ */ o.jsx("p", { className: `text-xs ${e === "dark" ? "text-gray-300" : "text-gray-600"}`, children: "Your payment has been successfully processed. You will receive a confirmation shortly." }) })
2078
+ return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex flex-col items-center justify-center py-6", children: [
2079
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "mb-4", children: renderIcon() }),
2080
+ /* @__PURE__ */ jsxRuntimeExports.jsx("h3", { className: `text-xl font-bold mb-2 ${theme === "dark" ? "text-white" : "text-gray-900"}`, children: getStatusTitle() }),
2081
+ /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: `text-center ${getMessageClasses()}`, children: message }),
2082
+ status === "processing" && /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: `mt-4 text-xs ${theme === "dark" ? "text-gray-400" : "text-gray-500"}`, children: "This may take a few moments. Please do not close this window." }),
2083
+ status === "success" && /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: `mt-4 p-2 rounded ${theme === "dark" ? "bg-gray-700" : "bg-gray-100"}`, children: /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: `text-xs ${theme === "dark" ? "text-gray-300" : "text-gray-600"}`, children: "Your payment has been successfully processed. You will receive a confirmation shortly." }) })
1581
2084
  ] });
1582
- }, St = ({ onSelect: s, selected: t, theme: e = "light", supportedNetworks: i = [] }) => {
1583
- const [c, u] = D(b.ETHEREUM), [y, x] = D({}), [r, n] = D(!1);
1584
- Z(() => {
1585
- x(ue());
2085
+ };
2086
+ const PaymentMethods = ({ onSelect, selected, theme = "light", supportedNetworks = [] }) => {
2087
+ const [selectedNetwork, setSelectedNetwork] = useState(NETWORK_TYPES.ETHEREUM);
2088
+ const [availableWallets, setAvailableWallets] = useState({});
2089
+ const [showMore, setShowMore] = useState(false);
2090
+ useEffect(() => {
2091
+ setAvailableWallets(detectWallets());
1586
2092
  }, []);
1587
- const a = [
2093
+ const networks = [
1588
2094
  {
1589
- id: b.ETHEREUM,
2095
+ id: NETWORK_TYPES.ETHEREUM,
1590
2096
  name: "Ethereum",
1591
2097
  description: "ERC-20 tokens"
1592
2098
  },
1593
2099
  {
1594
- id: b.BSC,
2100
+ id: NETWORK_TYPES.BSC,
1595
2101
  name: "BSC (Binance Smart Chain)",
1596
2102
  description: "BEP-20 tokens"
1597
2103
  },
1598
2104
  {
1599
- id: b.TRON,
2105
+ id: NETWORK_TYPES.TRON,
1600
2106
  name: "Tron",
1601
2107
  description: "TRC-20 tokens"
1602
2108
  },
1603
2109
  {
1604
- id: b.ALGORAND,
2110
+ id: NETWORK_TYPES.ALGORAND,
1605
2111
  name: "Algorand",
1606
2112
  description: "ASA tokens"
1607
2113
  }
1608
- ], l = (w) => {
1609
- const p = [];
1610
- switch (w) {
1611
- case b.ETHEREUM:
1612
- p.push(
2114
+ ];
2115
+ const getPaymentMethodsForNetwork = (network) => {
2116
+ const methods = [];
2117
+ switch (network) {
2118
+ case NETWORK_TYPES.ETHEREUM:
2119
+ methods.push(
1613
2120
  {
1614
2121
  id: "USDT",
1615
2122
  name: "USDT",
1616
2123
  description: "Tether USD",
1617
2124
  logo: "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSj0euZAOXsLTJFQxgiKzlX7z8xbfBk-7kmJA&s",
1618
- network: b.ETHEREUM
2125
+ network: NETWORK_TYPES.ETHEREUM
1619
2126
  },
1620
2127
  {
1621
2128
  id: "USDC",
1622
2129
  name: "USDC",
1623
2130
  description: "USD Coin",
1624
2131
  logo: "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ43MuDqq54iD1ZCRL_uthAPkfwSSL-J5qI_Q&s",
1625
- network: b.ETHEREUM
2132
+ network: NETWORK_TYPES.ETHEREUM
2133
+ },
2134
+ {
2135
+ id: "PYUSD",
2136
+ name: "PYUSD",
2137
+ description: "PayPal USD",
2138
+ logo: "https://s2.coinmarketcap.com/static/img/coins/64x64/28492.png",
2139
+ network: NETWORK_TYPES.ETHEREUM
2140
+ },
2141
+ {
2142
+ id: "FRAX",
2143
+ name: "FRAX",
2144
+ description: "Frax",
2145
+ logo: "https://s2.coinmarketcap.com/static/img/coins/64x64/6952.png",
2146
+ network: NETWORK_TYPES.ETHEREUM
2147
+ },
2148
+ {
2149
+ id: "USDP",
2150
+ name: "USDP",
2151
+ description: "Pax Dollar",
2152
+ logo: "https://s2.coinmarketcap.com/static/img/coins/64x64/6662.png",
2153
+ network: NETWORK_TYPES.ETHEREUM
2154
+ },
2155
+ {
2156
+ id: "DAI",
2157
+ name: "DAI",
2158
+ description: "Dai Stablecoin",
2159
+ logo: "https://s2.coinmarketcap.com/static/img/coins/64x64/4943.png",
2160
+ network: NETWORK_TYPES.ETHEREUM
1626
2161
  },
1627
2162
  {
1628
2163
  id: "ETH",
1629
2164
  name: "ETH",
1630
2165
  description: "Ethereum",
1631
2166
  logo: "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTcyJyRKN0dRJWVZqoLzYgkRHdJsxKGq8nHUw&s",
1632
- network: b.ETHEREUM
2167
+ network: NETWORK_TYPES.ETHEREUM
1633
2168
  }
1634
2169
  );
1635
2170
  break;
1636
- case b.BSC:
1637
- p.push(
2171
+ case NETWORK_TYPES.BSC:
2172
+ methods.push(
1638
2173
  {
1639
2174
  id: "USDT",
1640
2175
  name: "USDT",
1641
2176
  description: "Tether USD",
1642
2177
  logo: "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSj0euZAOXsLTJFQxgiKzlX7z8xbfBk-7kmJA&s",
1643
- network: b.BSC
2178
+ network: NETWORK_TYPES.BSC
1644
2179
  },
1645
2180
  {
1646
2181
  id: "USDC",
1647
2182
  name: "USDC",
1648
2183
  description: "USD Coin",
1649
2184
  logo: "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ43MuDqq54iD1ZCRL_uthAPkfwSSL-J5qI_Q&s",
1650
- network: b.BSC
2185
+ network: NETWORK_TYPES.BSC
2186
+ },
2187
+ {
2188
+ id: "BUSD",
2189
+ name: "BUSD",
2190
+ description: "Binance USD",
2191
+ logo: "https://s2.coinmarketcap.com/static/img/coins/64x64/4687.png",
2192
+ network: NETWORK_TYPES.BSC
2193
+ },
2194
+ {
2195
+ id: "FRAX",
2196
+ name: "FRAX",
2197
+ description: "Frax",
2198
+ logo: "https://s2.coinmarketcap.com/static/img/coins/64x64/6952.png",
2199
+ network: NETWORK_TYPES.BSC
1651
2200
  },
1652
2201
  {
1653
2202
  id: "BNB",
1654
2203
  name: "BNB",
1655
2204
  description: "Binance Coin",
1656
2205
  logo: "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRHSjyW2sSnBhwztCwVW97i1BtV40g7heMMxg&s",
1657
- network: b.BSC
2206
+ network: NETWORK_TYPES.BSC
1658
2207
  }
1659
2208
  );
1660
2209
  break;
1661
- case b.TRON:
1662
- p.push(
2210
+ case NETWORK_TYPES.TRON:
2211
+ methods.push(
1663
2212
  {
1664
2213
  id: "USDT",
1665
2214
  name: "USDT",
1666
2215
  description: "Tether USD",
1667
2216
  logo: "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSj0euZAOXsLTJFQxgiKzlX7z8xbfBk-7kmJA&s",
1668
- network: b.TRON
2217
+ network: NETWORK_TYPES.TRON
1669
2218
  },
1670
2219
  {
1671
2220
  id: "USDC",
1672
2221
  name: "USDC",
1673
2222
  description: "USD Coin",
1674
2223
  logo: "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ43MuDqq54iD1ZCRL_uthAPkfwSSL-J5qI_Q&s",
1675
- network: b.TRON
2224
+ network: NETWORK_TYPES.TRON
2225
+ },
2226
+ {
2227
+ id: "USDJ",
2228
+ name: "USDJ",
2229
+ description: "JUST Stablecoin",
2230
+ logo: "https://s2.coinmarketcap.com/static/img/coins/64x64/5446.png",
2231
+ network: NETWORK_TYPES.TRON
1676
2232
  },
1677
2233
  {
1678
2234
  id: "TRX",
1679
2235
  name: "TRX",
1680
2236
  description: "Tron",
1681
2237
  logo: "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQKLpLNsGRHbZfCUXAjZLPSp_YFZvX5dMnAoA&s",
1682
- network: b.TRON
2238
+ network: NETWORK_TYPES.TRON
1683
2239
  }
1684
2240
  );
1685
2241
  break;
1686
- case b.ALGORAND:
1687
- p.push(
2242
+ case NETWORK_TYPES.ALGORAND:
2243
+ methods.push(
2244
+ {
2245
+ id: "USDC",
2246
+ name: "USDC",
2247
+ description: "USD Coin",
2248
+ logo: "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ43MuDqq54iD1ZCRL_uthAPkfwSSL-J5qI_Q&s",
2249
+ network: NETWORK_TYPES.ALGORAND
2250
+ },
2251
+ {
2252
+ id: "USDT",
2253
+ name: "USDT",
2254
+ description: "Tether USD",
2255
+ logo: "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSj0euZAOXsLTJFQxgiKzlX7z8xbfBk-7kmJA&s",
2256
+ network: NETWORK_TYPES.ALGORAND
2257
+ },
1688
2258
  {
1689
2259
  id: "ALGO",
1690
2260
  name: "ALGO",
1691
2261
  description: "Algorand",
1692
- logo: "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcR0Yx1Vp8qPQI5XZoJuKfQS8bj_FNiMZGCHqA&s",
1693
- network: b.ALGORAND
2262
+ logo: "https://s2.coinmarketcap.com/static/img/coins/64x64/4030.png",
2263
+ network: NETWORK_TYPES.ALGORAND
1694
2264
  }
1695
2265
  );
1696
2266
  break;
1697
2267
  }
1698
- return p;
1699
- }, d = (w) => {
1700
- u(w), n(!1), (t == null ? void 0 : t.network) !== w && s(null);
1701
- }, g = (w) => {
1702
- var p;
1703
- s({
1704
- currency: w.id,
1705
- network: c,
1706
- tokenConfig: (p = Ye[w.id]) == null ? void 0 : p[c],
1707
- method: w
2268
+ return methods;
2269
+ };
2270
+ const handleNetworkChange = (networkId) => {
2271
+ setSelectedNetwork(networkId);
2272
+ setShowMore(false);
2273
+ if ((selected == null ? void 0 : selected.network) !== networkId) {
2274
+ onSelect(null);
2275
+ }
2276
+ };
2277
+ const handleSelectPaymentMethod = (method) => {
2278
+ var _a;
2279
+ onSelect({
2280
+ currency: method.id,
2281
+ network: selectedNetwork,
2282
+ tokenConfig: (_a = TOKEN_CONFIG[method.id]) == null ? void 0 : _a[selectedNetwork],
2283
+ method
1708
2284
  });
1709
- }, h = l(c), m = r ? h : h.slice(0, 4);
1710
- return /* @__PURE__ */ o.jsxs("div", { children: [
1711
- /* @__PURE__ */ o.jsx("h3", { className: `text-lg font-medium mb-4 ${e === "dark" ? "text-white" : "text-gray-800"}`, children: "Select Payment Method" }),
1712
- /* @__PURE__ */ o.jsxs("div", { className: "mb-6", children: [
1713
- /* @__PURE__ */ o.jsx("label", { className: `block text-sm font-medium mb-2 ${e === "dark" ? "text-white" : "text-gray-700"}`, children: "Blockchain Network" }),
1714
- /* @__PURE__ */ o.jsx(
2285
+ };
2286
+ const availableMethods = getPaymentMethodsForNetwork(selectedNetwork);
2287
+ const visibleMethods = showMore ? availableMethods : availableMethods.slice(0, 4);
2288
+ return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
2289
+ /* @__PURE__ */ jsxRuntimeExports.jsx("h3", { className: `text-lg font-medium mb-4 ${theme === "dark" ? "text-white" : "text-gray-800"}`, children: "Select Payment Method" }),
2290
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "mb-6", children: [
2291
+ /* @__PURE__ */ jsxRuntimeExports.jsx("label", { className: `block text-sm font-medium mb-2 ${theme === "dark" ? "text-white" : "text-gray-700"}`, children: "Blockchain Network" }),
2292
+ /* @__PURE__ */ jsxRuntimeExports.jsx(
1715
2293
  "select",
1716
2294
  {
1717
- value: c,
1718
- onChange: (w) => d(w.target.value),
1719
- className: `w-full p-3 rounded-lg border transition-colors ${e === "dark" ? "bg-gray-700 border-gray-600 text-white focus:border-[#7042D2]" : "bg-white border-gray-300 text-gray-900 focus:border-[#7042D2]"} focus:outline-none focus:ring-2 focus:ring-[#7042D2] focus:ring-opacity-50`,
1720
- children: a.filter((w) => i.length === 0 || i.includes(w.id)).map((w) => /* @__PURE__ */ o.jsxs("option", { value: w.id, children: [
1721
- w.name,
2295
+ value: selectedNetwork,
2296
+ onChange: (e) => handleNetworkChange(e.target.value),
2297
+ className: `w-full p-3 rounded-lg border transition-colors ${theme === "dark" ? "bg-gray-700 border-gray-600 text-white focus:border-[#7042D2]" : "bg-white border-gray-300 text-gray-900 focus:border-[#7042D2]"} focus:outline-none focus:ring-2 focus:ring-[#7042D2] focus:ring-opacity-50`,
2298
+ children: networks.filter((network) => supportedNetworks.length === 0 || supportedNetworks.includes(network.id)).map((network) => /* @__PURE__ */ jsxRuntimeExports.jsxs("option", { value: network.id, children: [
2299
+ network.name,
1722
2300
  " - ",
1723
- w.description
1724
- ] }, w.id))
2301
+ network.description
2302
+ ] }, network.id))
1725
2303
  }
1726
2304
  )
1727
2305
  ] }),
1728
- /* @__PURE__ */ o.jsxs("div", { className: "mb-4", children: [
1729
- /* @__PURE__ */ o.jsx("label", { className: `block text-sm font-medium mb-3 ${e === "dark" ? "text-white" : "text-gray-700"}`, children: "Choose Cryptocurrency" }),
1730
- /* @__PURE__ */ o.jsx("div", { className: "grid grid-cols-2 gap-3 mb-4", children: m.map((w) => /* @__PURE__ */ o.jsx(
2306
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "mb-4", children: [
2307
+ /* @__PURE__ */ jsxRuntimeExports.jsx("label", { className: `block text-sm font-medium mb-3 ${theme === "dark" ? "text-white" : "text-gray-700"}`, children: "Choose Cryptocurrency" }),
2308
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "grid grid-cols-2 gap-3 mb-4", children: visibleMethods.map((method) => /* @__PURE__ */ jsxRuntimeExports.jsx(
1731
2309
  "button",
1732
2310
  {
1733
- onClick: () => g(w),
1734
- className: `p-4 rounded-lg transition-all duration-200 border-2 ${(t == null ? void 0 : t.currency) === w.id && (t == null ? void 0 : t.network) === c ? e === "dark" ? "bg-blue-900/30 border-[#7042D2] ring-2 ring-[#7042D2] ring-opacity-50" : "bg-blue-50 border-[#7042D2] ring-2 ring-[#7042D2] ring-opacity-50" : e === "dark" ? "bg-gray-700 hover:bg-gray-600 border-gray-600 hover:border-gray-500" : "bg-white hover:bg-gray-50 border-gray-200 hover:border-gray-300"}`,
1735
- children: /* @__PURE__ */ o.jsxs("div", { className: "flex flex-col items-center text-center", children: [
1736
- /* @__PURE__ */ o.jsx("div", { className: "flex-shrink-0 h-10 w-10 bg-white rounded-full flex items-center justify-center mb-2 shadow-sm", children: /* @__PURE__ */ o.jsx("img", { src: w.logo, alt: w.name, className: "h-6 w-6" }) }),
1737
- /* @__PURE__ */ o.jsxs("div", { children: [
1738
- /* @__PURE__ */ o.jsx("h4", { className: `font-medium text-sm ${e === "dark" ? "text-white" : "text-gray-900"}`, children: w.name }),
1739
- /* @__PURE__ */ o.jsx("p", { className: `text-xs ${e === "dark" ? "text-gray-300" : "text-gray-500"}`, children: w.description })
2311
+ onClick: () => handleSelectPaymentMethod(method),
2312
+ className: `p-4 rounded-lg transition-all duration-200 border-2 ${(selected == null ? void 0 : selected.currency) === method.id && (selected == null ? void 0 : selected.network) === selectedNetwork ? theme === "dark" ? "bg-blue-900/30 border-[#7042D2] ring-2 ring-[#7042D2] ring-opacity-50" : "bg-blue-50 border-[#7042D2] ring-2 ring-[#7042D2] ring-opacity-50" : theme === "dark" ? "bg-gray-700 hover:bg-gray-600 border-gray-600 hover:border-gray-500" : "bg-white hover:bg-gray-50 border-gray-200 hover:border-gray-300"}`,
2313
+ children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex flex-col items-center text-center", children: [
2314
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex-shrink-0 h-10 w-10 bg-white rounded-full flex items-center justify-center mb-2 shadow-sm", children: /* @__PURE__ */ jsxRuntimeExports.jsx("img", { src: method.logo, alt: method.name, className: "h-6 w-6" }) }),
2315
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
2316
+ /* @__PURE__ */ jsxRuntimeExports.jsx("h4", { className: `font-medium text-sm ${theme === "dark" ? "text-white" : "text-gray-900"}`, children: method.name }),
2317
+ /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: `text-xs ${theme === "dark" ? "text-gray-300" : "text-gray-500"}`, children: method.description })
1740
2318
  ] }),
1741
- (t == null ? void 0 : t.currency) === w.id && (t == null ? void 0 : t.network) === c && /* @__PURE__ */ o.jsx("div", { className: "mt-2", children: /* @__PURE__ */ o.jsx(
2319
+ (selected == null ? void 0 : selected.currency) === method.id && (selected == null ? void 0 : selected.network) === selectedNetwork && /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "mt-2", children: /* @__PURE__ */ jsxRuntimeExports.jsx(
1742
2320
  "svg",
1743
2321
  {
1744
2322
  xmlns: "http://www.w3.org/2000/svg",
1745
2323
  className: "h-4 w-4 text-[#7042D2]",
1746
2324
  viewBox: "0 0 20 20",
1747
2325
  fill: "currentColor",
1748
- children: /* @__PURE__ */ o.jsx(
2326
+ children: /* @__PURE__ */ jsxRuntimeExports.jsx(
1749
2327
  "path",
1750
2328
  {
1751
2329
  fillRule: "evenodd",
@@ -1757,302 +2335,344 @@ const Rt = ({
1757
2335
  ) })
1758
2336
  ] })
1759
2337
  },
1760
- `${w.id}-${w.network}`
2338
+ `${method.id}-${method.network}`
1761
2339
  )) }),
1762
- h.length > 4 && /* @__PURE__ */ o.jsx(
2340
+ availableMethods.length > 4 && /* @__PURE__ */ jsxRuntimeExports.jsx(
1763
2341
  "button",
1764
2342
  {
1765
- onClick: () => n(!r),
1766
- className: `w-full py-2 px-4 rounded-lg text-sm font-medium transition-colors ${e === "dark" ? "bg-gray-700 text-gray-300 hover:bg-gray-600" : "bg-gray-100 text-gray-600 hover:bg-gray-200"}`,
1767
- children: r ? "Show Less" : `Show More (${h.length - 4} more)`
2343
+ onClick: () => setShowMore(!showMore),
2344
+ className: `w-full py-2 px-4 rounded-lg text-sm font-medium transition-colors ${theme === "dark" ? "bg-gray-700 text-gray-300 hover:bg-gray-600" : "bg-gray-100 text-gray-600 hover:bg-gray-200"}`,
2345
+ children: showMore ? "Show Less" : `Show More (${availableMethods.length - 4} more)`
1768
2346
  }
1769
2347
  )
1770
2348
  ] }),
1771
- /* @__PURE__ */ o.jsx("div", { className: `p-3 rounded-lg text-sm ${e === "dark" ? "bg-gray-800 text-gray-300" : "bg-gray-50 text-gray-600"}`, children: /* @__PURE__ */ o.jsxs("div", { className: "flex items-center", children: [
1772
- /* @__PURE__ */ o.jsx("div", { className: `w-2 h-2 rounded-full mr-2 ${y[f(c)] ? "bg-green-500" : "bg-red-500"}` }),
1773
- /* @__PURE__ */ o.jsx("span", { className: "text-xs", children: k(c) })
2349
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: `p-3 rounded-lg text-sm ${theme === "dark" ? "bg-gray-800 text-gray-300" : "bg-gray-50 text-gray-600"}`, children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center", children: [
2350
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: `w-2 h-2 rounded-full mr-2 ${availableWallets[getRequiredWallet(selectedNetwork)] ? "bg-green-500" : "bg-red-500"}` }),
2351
+ /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-xs", children: getNetworkRequirement(selectedNetwork) })
1774
2352
  ] }) })
1775
2353
  ] });
1776
- function f(w) {
1777
- switch (w) {
1778
- case b.ETHEREUM:
1779
- case b.BSC:
2354
+ function getRequiredWallet(network) {
2355
+ switch (network) {
2356
+ case NETWORK_TYPES.ETHEREUM:
2357
+ case NETWORK_TYPES.BSC:
1780
2358
  return "metamask";
1781
- case b.TRON:
2359
+ case NETWORK_TYPES.TRON:
1782
2360
  return "tronlink";
1783
- case b.ALGORAND:
2361
+ case NETWORK_TYPES.ALGORAND:
1784
2362
  return "lute";
1785
2363
  default:
1786
2364
  return "metamask";
1787
2365
  }
1788
2366
  }
1789
- function k(w) {
1790
- const p = f(w), T = y[p], C = {
2367
+ function getNetworkRequirement(network) {
2368
+ const wallet = getRequiredWallet(network);
2369
+ const isAvailable = availableWallets[wallet];
2370
+ const walletNames = {
1791
2371
  metamask: "MetaMask",
1792
2372
  tronlink: "TronLink",
1793
2373
  lute: "Lute Wallet"
1794
2374
  };
1795
- return T ? `${C[p]} detected - Ready to pay` : `${C[p]} required - Please install to continue`;
2375
+ return isAvailable ? `${walletNames[wallet]} detected - Ready to pay` : `${walletNames[wallet]} required - Please install to continue`;
1796
2376
  }
1797
- }, Lt = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAJQAAAAkCAYAAABv9hOhAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAmVSURBVHgB7Vzdcdu4Fv5I+X2VCoK83pkb2xVc2ikgTgVWKog8twDJBexYrsBKBXYKWJtbQWRnZl+NrWC172txcQBQBA8B/kiKV87qm4FFgMAhAX48ODg4dISOGB4/XKsfObl9e+Y9n3wViHt3QHY5ud2fYId1caDSJyc/V+kMW4q4S2VFFurcCR0Oj+/H3kq9vSv1VyDDKX5s0Fh8VSlTifrcx/cByR046QRbjE6EQmnQok9aGzlQ+QRZluDHh1BJaWFNKsJApQvs0JlQc+e4jzgelqX1HNUczfHjQqCqkRLsUCWU0jL94buHE659LGQ5G51SfafAUcfZn572Sv63hKZL1u6lYeYpk9jBo6HieKysgmulbR6VAX7lEmuSHpLWkU5tIoVW+3q6cxEhdbOaqMcPF4gzNVVEI2VsJXi5oHE4d/JSpY/YwUOoRYkwA1qxWWPcIvtSlhDbc/FBWc5i+RbblR8ZsGaKzDIJPKV42Rir9EqlNzZJ7OCzoRZTlG0lTYalBlosbsr1o33zg4JQijBKm6V0WLgRtN1hm+DSaruXDq6x//XY4wX0oJWNo9R5VF61xL1rRY4jIsrw6F4iioQuz7JX5nz8Wh2bulGU0o+2kziZMqSTu7X9UwLGCBZOGWnEFOWXoQk0ZZ945FCS+D4QKN873W8Kv122Kv6Jfmns+QrJITl89+09cwH0LakOkS3OEPWuS42yrHiQiydjX8Q9IqVw6kjVdh1bI1FphPoV1RTGvpFryklVulTpJnD+jrX/aK9NeET5YR7Z+7lC+Jr0sD9gvQeeoF2/PjrXIfI9orxqpfEboxmkGFyn6yzsNnj664MiAH9rBLkKlJa6IU+4LsnyNyu7t7/n6rxUBvgAxj9jizWZSMNJdAd1lgjMH6IPA5gBGgXOX7SUk9hrbsK/JFpcM3eUruq47NIvd3xIEVyyOp/QDu9Z/nJJKL0K4ys6RYAlcZaItAdcabGh0kSHk3R/rIsXi4nO39p8FBU3paa5NclEA9V1oMeokoo0xBDdMLTt1oHZPWhGv0NdLr9rv8YoxmfiuY8E9aDzgpWle+RzUiu7T8pQpgq0V0dkmJmVGL6oPTu1zfJA+ZG2m3I7CZp0M+eYmF5otCyji821xlrPZqI378BTnqr0qz2mAXjv6eBYJdKcNG3R4A1q5Ejb/n+oDia128QemoTRBtLKy/fphFOH+jJEe4JcoNovaa+T2uuIwLXGMH1PbUqccyNbFgLfWpvq6yqyZA3p0U5f2tfU1iG5IcflAGavzE00LYia+o9O3T9smfDIoXpJQI5gcvLk1r9j5wbOOV/bKfz7fX0Ue4LufedIPPft3ie/zgThfUWqfx2Ql3hk1T1D3kc9g8T5iqwGQqWr4fG3Ea3w2i73N+QWGLG8RGHg+jCFMWzz4zf2NyQnDcgJXWeE1SBRaDkOKuMLFXqQr9EMfj8pjGab19yHa5ATBAwZUlTHI6Ql+QpSwi5eYmt8f0YjsvH/j39r08lNgVS0YGX0kJuIStPuIczAUd18t95F0yoQ8Hu/E6wWVdA0vr7l/Bs0Y8Dy5y3a+Izw3Ljm90lTpK+/3BhP84M9q0kGaoqa2s1dv/GrbKqf7/7zO54PguVTtF9Su6tTbn9JFMv7JqQobKscCcKuhDo5TZDoZownLD8PlPswD8iawthkOYly49ztb+7jcrEk8tIPZT3bqbV9DhS5hGKRUAa7uvhilnu+nxGcCPdYDYLlJbrhVyZDYDvQ9+TvsBqEc0zay51KScm4hDph1y5p15IfypBpj8hEKu29dhH04lOVPw1EHzwnNmGTESTWwyYWG5vA97qPCcpjnaCs9U5Z/dL0WfihlNFNEQYmGkAbY8bwyjLSFAO7n/ecg8kJtCn77aBj/Z9YXmI7sKkXjMuiY25L5VOcQHVKTd1MTJpHbbN8JaMb9ax/7jdTsvwJVsOM5QW69SVheYntAO8XEYH2VaMV0ismi9uIpJVye8rFFGw8YqV5RlYLNUBvqWzyrWhCCh4h2t7ZN0BhF8w8ctou/0cok2+Odgb2c0Bi9fFpQopyP/OVMp/uvvCG8TJqIATtMc8o+uD18Ojh7uzdt1b7PMMkGPXZFr6HRw+4ifxU5wrl/Sq+TKaBP22QQ+fHrKzr6u57w7cHJ9AMqtdEvnNPm8TJS3jGg/xQHz3OTao8VcpQOQkjaSIsFUPV9kyWZZNW/qg4O9DBebS1szpoq4O/heRVpvsRrG4Cs8oZO2V0TJ2eoDpVTeHfN6NrXKDqWpBo5+d5TnADOl/pDQL1875N7O9jTd0UPC6uer6CyM2QRsk3cL2BcTkWT+RgnKnzVxSqQnt6tv6Fyp8tZRzdf1VkVRolGk9u/7vqw6A3KbTjL+1vH367iAbk0NZLEF5W59OiQPgNJw+8+0Z2DV9JUQ8uL2+ToHzfEmWnJ72w1x55VC9f0vdR7Of1PfVCTtQxwubBITwxXCW3gUOmfpBMeTSmiXU6QRwnVtSJzke9q6Lu4oOdMsd6Fbka6G0KkVEgbGQTQdztkxThuG8a6ARhMlG7bZvuctB9+cZHwH5DCaOFEvjJdIQwuAbMMUMgINAfD8UD41yo6dHaRgNb0reSzK+aFvNwYU1QIpWJOliHVGNU96DqkML/Bk3RLf6b6h2hvWf9n8IY9XucPhARDxva+FwIhMtQg0rEJiNLGSZI7lyvDMsXhbG1LKLeMvTBTodH9vN0IhVWnP6mNg1gDOaEnc+N+DxsIwQJQ6qBlcOnAZJDRPyMeiJ9QflhSHbuJyazCVze3JE79ZRzpCj6RY7pBH6NRNe5QfvVqgxcy4uIF5hPzCO/JlG2k44pP36g8Ip+qYyM78yZyxdPr1w3g/5yJoqv9apSGfuTX95uYgoRzrHE6hAbkrNtcG3LOVZzhnLbboqaT8aqU17mnermS+KY6Yzv5QBP7LOoOB64WR2MRxGgWsvhakNed+mkbZCzbSACSVR9Vm3BXQWEz3UNqoSquhCmJtTXbg4vjXDQFDjLtZD+pUjPQtA+F0021eRu/40NKz7ADtuMkB8urWtU/Yzq9u1UaQ+pow0WTzdV77hDlGgZgmuQLdT8HBmi1Hjfl3HnO2wbEhT2qWDniAeNIdD+z6jqQlXcuHL6MMHFYpEuDfYo2sSUtsPzQiDs6CQySTQgRldkWU6UKf+KRROxOaR4h5cF0kzk+pm2qdydUJF2D8yXH3NyPP21tf9dbYdOkDAOU3JFtF6R76EraO9PrfJC39hZv5NidG835b085Eb3qi4G/A2inrQKnVgMFAAAAABJRU5ErkJggg==", Pt = ({
1798
- isOpen: s,
1799
- onClose: t,
1800
- payment: e,
1801
- paymentStatus: i,
1802
- selectedPaymentMethod: c,
1803
- onPaymentMethodSelect: u,
1804
- onPayment: y,
1805
- onBack: x,
1806
- error: r,
1807
- theme: n = "light",
1808
- merchantName: a,
1809
- transactionHash: l,
1810
- walletConnection: d,
1811
- onConnectWallet: g,
1812
- testMode: h = !1,
1813
- supportedNetworks: m = [],
1814
- availableWallets: f = {},
1815
- supportedWallets: k = [],
1816
- step: w = "select-currency"
2377
+ };
2378
+ const logo = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAJQAAAAkCAYAAABv9hOhAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAmVSURBVHgB7Vzdcdu4Fv5I+X2VCoK83pkb2xVc2ikgTgVWKog8twDJBexYrsBKBXYKWJtbQWRnZl+NrWC172txcQBQBA8B/kiKV87qm4FFgMAhAX48ODg4dISOGB4/XKsfObl9e+Y9n3wViHt3QHY5ud2fYId1caDSJyc/V+kMW4q4S2VFFurcCR0Oj+/H3kq9vSv1VyDDKX5s0Fh8VSlTifrcx/cByR046QRbjE6EQmnQok9aGzlQ+QRZluDHh1BJaWFNKsJApQvs0JlQc+e4jzgelqX1HNUczfHjQqCqkRLsUCWU0jL94buHE659LGQ5G51SfafAUcfZn572Sv63hKZL1u6lYeYpk9jBo6HieKysgmulbR6VAX7lEmuSHpLWkU5tIoVW+3q6cxEhdbOaqMcPF4gzNVVEI2VsJXi5oHE4d/JSpY/YwUOoRYkwA1qxWWPcIvtSlhDbc/FBWc5i+RbblR8ZsGaKzDIJPKV42Rir9EqlNzZJ7OCzoRZTlG0lTYalBlosbsr1o33zg4JQijBKm6V0WLgRtN1hm+DSaruXDq6x//XY4wX0oJWNo9R5VF61xL1rRY4jIsrw6F4iioQuz7JX5nz8Wh2bulGU0o+2kziZMqSTu7X9UwLGCBZOGWnEFOWXoQk0ZZ945FCS+D4QKN873W8Kv122Kv6Jfmns+QrJITl89+09cwH0LakOkS3OEPWuS42yrHiQiydjX8Q9IqVw6kjVdh1bI1FphPoV1RTGvpFryklVulTpJnD+jrX/aK9NeET5YR7Z+7lC+Jr0sD9gvQeeoF2/PjrXIfI9orxqpfEboxmkGFyn6yzsNnj664MiAH9rBLkKlJa6IU+4LsnyNyu7t7/n6rxUBvgAxj9jizWZSMNJdAd1lgjMH6IPA5gBGgXOX7SUk9hrbsK/JFpcM3eUruq47NIvd3xIEVyyOp/QDu9Z/nJJKL0K4ys6RYAlcZaItAdcabGh0kSHk3R/rIsXi4nO39p8FBU3paa5NclEA9V1oMeokoo0xBDdMLTt1oHZPWhGv0NdLr9rv8YoxmfiuY8E9aDzgpWle+RzUiu7T8pQpgq0V0dkmJmVGL6oPTu1zfJA+ZG2m3I7CZp0M+eYmF5otCyji821xlrPZqI378BTnqr0qz2mAXjv6eBYJdKcNG3R4A1q5Ejb/n+oDia128QemoTRBtLKy/fphFOH+jJEe4JcoNovaa+T2uuIwLXGMH1PbUqccyNbFgLfWpvq6yqyZA3p0U5f2tfU1iG5IcflAGavzE00LYia+o9O3T9smfDIoXpJQI5gcvLk1r9j5wbOOV/bKfz7fX0Ue4LufedIPPft3ie/zgThfUWqfx2Ql3hk1T1D3kc9g8T5iqwGQqWr4fG3Ea3w2i73N+QWGLG8RGHg+jCFMWzz4zf2NyQnDcgJXWeE1SBRaDkOKuMLFXqQr9EMfj8pjGab19yHa5ATBAwZUlTHI6Ql+QpSwi5eYmt8f0YjsvH/j39r08lNgVS0YGX0kJuIStPuIczAUd18t95F0yoQ8Hu/E6wWVdA0vr7l/Bs0Y8Dy5y3a+Izw3Ljm90lTpK+/3BhP84M9q0kGaoqa2s1dv/GrbKqf7/7zO54PguVTtF9Su6tTbn9JFMv7JqQobKscCcKuhDo5TZDoZownLD8PlPswD8iawthkOYly49ztb+7jcrEk8tIPZT3bqbV9DhS5hGKRUAa7uvhilnu+nxGcCPdYDYLlJbrhVyZDYDvQ9+TvsBqEc0zay51KScm4hDph1y5p15IfypBpj8hEKu29dhH04lOVPw1EHzwnNmGTESTWwyYWG5vA97qPCcpjnaCs9U5Z/dL0WfihlNFNEQYmGkAbY8bwyjLSFAO7n/ecg8kJtCn77aBj/Z9YXmI7sKkXjMuiY25L5VOcQHVKTd1MTJpHbbN8JaMb9ax/7jdTsvwJVsOM5QW69SVheYntAO8XEYH2VaMV0ismi9uIpJVye8rFFGw8YqV5RlYLNUBvqWzyrWhCCh4h2t7ZN0BhF8w8ctou/0cok2+Odgb2c0Bi9fFpQopyP/OVMp/uvvCG8TJqIATtMc8o+uD18Ojh7uzdt1b7PMMkGPXZFr6HRw+4ifxU5wrl/Sq+TKaBP22QQ+fHrKzr6u57w7cHJ9AMqtdEvnNPm8TJS3jGg/xQHz3OTao8VcpQOQkjaSIsFUPV9kyWZZNW/qg4O9DBebS1szpoq4O/heRVpvsRrG4Cs8oZO2V0TJ2eoDpVTeHfN6NrXKDqWpBo5+d5TnADOl/pDQL1875N7O9jTd0UPC6uer6CyM2QRsk3cL2BcTkWT+RgnKnzVxSqQnt6tv6Fyp8tZRzdf1VkVRolGk9u/7vqw6A3KbTjL+1vH367iAbk0NZLEF5W59OiQPgNJw+8+0Z2DV9JUQ8uL2+ToHzfEmWnJ72w1x55VC9f0vdR7Of1PfVCTtQxwubBITwxXCW3gUOmfpBMeTSmiXU6QRwnVtSJzke9q6Lu4oOdMsd6Fbka6G0KkVEgbGQTQdztkxThuG8a6ARhMlG7bZvuctB9+cZHwH5DCaOFEvjJdIQwuAbMMUMgINAfD8UD41yo6dHaRgNb0reSzK+aFvNwYU1QIpWJOliHVGNU96DqkML/Bk3RLf6b6h2hvWf9n8IY9XucPhARDxva+FwIhMtQg0rEJiNLGSZI7lyvDMsXhbG1LKLeMvTBTodH9vN0IhVWnP6mNg1gDOaEnc+N+DxsIwQJQ6qBlcOnAZJDRPyMeiJ9QflhSHbuJyazCVze3JE79ZRzpCj6RY7pBH6NRNe5QfvVqgxcy4uIF5hPzCO/JlG2k44pP36g8Ip+qYyM78yZyxdPr1w3g/5yJoqv9apSGfuTX95uYgoRzrHE6hAbkrNtcG3LOVZzhnLbboqaT8aqU17mnermS+KY6Yzv5QBP7LOoOB64WR2MRxGgWsvhakNed+mkbZCzbSACSVR9Vm3BXQWEz3UNqoSquhCmJtTXbg4vjXDQFDjLtZD+pUjPQtA+F0021eRu/40NKz7ADtuMkB8urWtU/Yzq9u1UaQ+pow0WTzdV77hDlGgZgmuQLdT8HBmi1Hjfl3HnO2wbEhT2qWDniAeNIdD+z6jqQlXcuHL6MMHFYpEuDfYo2sSUtsPzQiDs6CQySTQgRldkWU6UKf+KRROxOaR4h5cF0kzk+pm2qdydUJF2D8yXH3NyPP21tf9dbYdOkDAOU3JFtF6R76EraO9PrfJC39hZv5NidG835b085Eb3qi4G/A2inrQKnVgMFAAAAABJRU5ErkJggg==";
2379
+ const CoinleyModal = ({
2380
+ isOpen,
2381
+ onClose,
2382
+ payment,
2383
+ paymentStatus,
2384
+ selectedPaymentMethod,
2385
+ onPaymentMethodSelect,
2386
+ onPayment,
2387
+ onBack,
2388
+ error,
2389
+ theme = "light",
2390
+ merchantName,
2391
+ transactionHash,
2392
+ walletConnection,
2393
+ onConnectWallet,
2394
+ testMode = false,
2395
+ supportedNetworks = [],
2396
+ availableWallets = {},
2397
+ supportedWallets = [],
2398
+ step = "select-currency",
2399
+ merchantWalletAddresses = {}
2400
+ // Add this prop
1817
2401
  }) => {
1818
- const [p, T] = D("wallet"), C = (v) => parseFloat(v).toFixed(2), q = (v) => v ? v.length <= 14 ? v : `${v.slice(0, 8)}...${v.slice(-6)}` : "", H = (v) => ({
1819
- ethereum: "Ethereum",
1820
- bsc: "BSC",
1821
- tron: "Tron",
1822
- algorand: "Algorand"
1823
- })[v] || v, O = (v) => ({
1824
- [N.METAMASK]: "MetaMask",
1825
- [N.TRONLINK]: "TronLink",
1826
- [N.TRUST_WALLET]: "Trust Wallet",
1827
- [N.LUTE]: "Lute Wallet"
1828
- })[v] || v, M = (v) => ({
1829
- [N.METAMASK]: "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcT3ymr3UNKopfI0NmUY95Dr-0589vG-91KuAA&s",
1830
- [N.TRONLINK]: "https://www.tronlink.org/images/logo.png",
1831
- [N.TRUST_WALLET]: "https://trustwallet.com/assets/images/trust_logotype.svg",
1832
- [N.LUTE]: "https://lute.app/logo.png"
1833
- })[v] || "";
1834
- return s ? /* @__PURE__ */ o.jsx("div", { className: "fixed inset-0 z-50 overflow-y-auto bg-black/50", children: /* @__PURE__ */ o.jsx("div", { className: "flex min-h-screen items-center justify-center p-4", children: /* @__PURE__ */ o.jsxs("div", { className: "relative p-6 w-full max-w-md mx-auto rounded-lg shadow-xl bg-white text-gray-800", children: [
1835
- /* @__PURE__ */ o.jsxs("div", { className: "flex justify-between items-center mb-6 bg-[#F1ECFB] p-3 rounded-xl", children: [
1836
- /* @__PURE__ */ o.jsx("div", { className: "flex items-center", children: /* @__PURE__ */ o.jsx("h2", { className: "text-xl font-bold text-gray-900", children: /* @__PURE__ */ o.jsx("img", { src: Lt, className: "w-32", alt: "Coinley Logo" }) }) }),
1837
- /* @__PURE__ */ o.jsx(
2402
+ const [paymentType, setPaymentType] = useState("wallet");
2403
+ const getWalletAddressForNetwork = () => {
2404
+ if (!selectedPaymentMethod)
2405
+ return "No network selected";
2406
+ const networkAddress = merchantWalletAddresses[selectedPaymentMethod.network];
2407
+ if (networkAddress) {
2408
+ return networkAddress;
2409
+ }
2410
+ if (payment == null ? void 0 : payment.recipientWallet) {
2411
+ return payment.recipientWallet;
2412
+ }
2413
+ return "No wallet address configured for this network";
2414
+ };
2415
+ const formatAmount = (amount) => {
2416
+ return parseFloat(amount).toFixed(2);
2417
+ };
2418
+ const formatTransactionHash = (hash) => {
2419
+ if (!hash)
2420
+ return "";
2421
+ if (hash.length <= 14)
2422
+ return hash;
2423
+ return `${hash.slice(0, 8)}...${hash.slice(-6)}`;
2424
+ };
2425
+ const getNetworkDisplayName = (network) => {
2426
+ const names = {
2427
+ ethereum: "Ethereum",
2428
+ bsc: "BSC",
2429
+ tron: "Tron",
2430
+ algorand: "Algorand"
2431
+ };
2432
+ return names[network] || network;
2433
+ };
2434
+ const getWalletDisplayName = (walletType) => {
2435
+ const names = {
2436
+ [WALLET_TYPES.METAMASK]: "MetaMask",
2437
+ [WALLET_TYPES.TRONLINK]: "TronLink",
2438
+ [WALLET_TYPES.TRUST_WALLET]: "Trust Wallet",
2439
+ [WALLET_TYPES.LUTE]: "Lute Wallet"
2440
+ };
2441
+ return names[walletType] || walletType;
2442
+ };
2443
+ const getWalletIcon = (walletType) => {
2444
+ const icons = {
2445
+ [WALLET_TYPES.METAMASK]: "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcT3ymr3UNKopfI0NmUY95Dr-0589vG-91KuAA&s",
2446
+ [WALLET_TYPES.TRONLINK]: "https://www.tronlink.org/images/logo.png",
2447
+ [WALLET_TYPES.TRUST_WALLET]: "https://trustwallet.com/assets/images/trust_logotype.svg",
2448
+ [WALLET_TYPES.LUTE]: "https://lute.app/logo.png"
2449
+ };
2450
+ return icons[walletType] || "";
2451
+ };
2452
+ if (!isOpen)
2453
+ return null;
2454
+ return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "fixed inset-0 z-50 overflow-y-auto bg-black/50", children: /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex min-h-screen items-center justify-center p-4", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "relative p-6 w-full max-w-md mx-auto rounded-lg shadow-xl bg-white text-gray-800", children: [
2455
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex justify-between items-center mb-6 bg-[#F1ECFB] p-3 rounded-xl", children: [
2456
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex items-center", children: /* @__PURE__ */ jsxRuntimeExports.jsx("h2", { className: "text-xl font-bold text-gray-900", children: /* @__PURE__ */ jsxRuntimeExports.jsx("img", { src: logo, className: "w-32", alt: "Coinley Logo" }) }) }),
2457
+ /* @__PURE__ */ jsxRuntimeExports.jsx(
1838
2458
  "button",
1839
2459
  {
1840
- onClick: t,
2460
+ onClick: onClose,
1841
2461
  className: "text-gray-500 hover:text-gray-700 focus:outline-none",
1842
- children: /* @__PURE__ */ o.jsx("svg", { xmlns: "http://www.w3.org/2000/svg", className: "h-6 w-6", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", children: /* @__PURE__ */ o.jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M6 18L18 6M6 6l12 12" }) })
2462
+ children: /* @__PURE__ */ jsxRuntimeExports.jsx("svg", { xmlns: "http://www.w3.org/2000/svg", className: "h-6 w-6", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", children: /* @__PURE__ */ jsxRuntimeExports.jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M6 18L18 6M6 6l12 12" }) })
1843
2463
  }
1844
2464
  )
1845
2465
  ] }),
1846
- /* @__PURE__ */ o.jsxs("div", { className: "mb-6 bg-[#F1ECFB] p-3 rounded-xl", children: [
1847
- e && /* @__PURE__ */ o.jsxs("div", { className: "mb-6 p-4 rounded-lg", children: [
1848
- /* @__PURE__ */ o.jsxs("p", { className: "text-lg text-gray-800 font-semibold", children: [
2466
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "mb-6 bg-[#F1ECFB] p-3 rounded-xl", children: [
2467
+ payment && /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "mb-6 p-4 rounded-lg", children: [
2468
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("p", { className: "text-lg text-gray-800 font-semibold", children: [
1849
2469
  "PAY: ",
1850
- a
2470
+ merchantName
1851
2471
  ] }),
1852
- /* @__PURE__ */ o.jsxs("div", { className: "flex justify-between items-center mt-2 bg-gray-100 px-3 rounded-lg", children: [
1853
- /* @__PURE__ */ o.jsx("span", { className: "font-medium text-gray-700", children: "Amount:" }),
1854
- /* @__PURE__ */ o.jsxs("span", { className: "font-bold text-xl text-[#7042D2]", children: [
2472
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex justify-between items-center mt-2 bg-gray-100 px-3 rounded-lg", children: [
2473
+ /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "font-medium text-gray-700", children: "Amount:" }),
2474
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "font-bold text-xl text-[#7042D2]", children: [
1855
2475
  "$",
1856
- C(e.totalAmount || e.amount)
2476
+ formatAmount(payment.totalAmount || payment.amount)
1857
2477
  ] })
1858
2478
  ] }),
1859
- /* @__PURE__ */ o.jsx("div", { className: "text-xs mt-1 text-right", children: /* @__PURE__ */ o.jsxs("span", { className: "text-gray-500", children: [
2479
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-xs mt-1 text-right", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "text-gray-500", children: [
1860
2480
  "Payment ID: ",
1861
- e.id ? e.id.slice(0, 8) : "",
2481
+ payment.id ? payment.id.slice(0, 8) : "",
1862
2482
  "..."
1863
2483
  ] }) })
1864
2484
  ] }),
1865
- w === "select-currency" && /* @__PURE__ */ o.jsxs("div", { children: [
1866
- /* @__PURE__ */ o.jsx(
1867
- St,
2485
+ step === "select-currency" && /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
2486
+ /* @__PURE__ */ jsxRuntimeExports.jsx(
2487
+ PaymentMethods,
1868
2488
  {
1869
- onSelect: u,
1870
- selected: c,
1871
- theme: n,
1872
- supportedNetworks: m
2489
+ onSelect: onPaymentMethodSelect,
2490
+ selected: selectedPaymentMethod,
2491
+ theme,
2492
+ supportedNetworks
1873
2493
  }
1874
2494
  ),
1875
- c && /* @__PURE__ */ o.jsx("div", { className: "mt-6", children: /* @__PURE__ */ o.jsxs(
2495
+ selectedPaymentMethod && /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "mt-6", children: /* @__PURE__ */ jsxRuntimeExports.jsxs(
1876
2496
  "button",
1877
2497
  {
1878
- onClick: () => u(c),
2498
+ onClick: () => onPaymentMethodSelect(selectedPaymentMethod),
1879
2499
  className: "w-full py-3 px-4 bg-[#7042D2] hover:bg-[#7042D2] text-white font-medium rounded-lg transition-colors",
1880
2500
  children: [
1881
2501
  "Proceed with ",
1882
- c.currency,
2502
+ selectedPaymentMethod.currency,
1883
2503
  " on ",
1884
- H(c.network)
2504
+ getNetworkDisplayName(selectedPaymentMethod.network)
1885
2505
  ]
1886
2506
  }
1887
2507
  ) })
1888
2508
  ] }),
1889
- w === "confirm" && c && e && /* @__PURE__ */ o.jsxs("div", { children: [
1890
- /* @__PURE__ */ o.jsxs("div", { className: "p-4 rounded-lg mb-4 bg-gray-100", children: [
1891
- /* @__PURE__ */ o.jsx("h3", { className: "text-lg font-medium mb-2 text-gray-800", children: "Payment Details" }),
1892
- /* @__PURE__ */ o.jsxs("div", { className: "space-y-2", children: [
1893
- /* @__PURE__ */ o.jsxs("div", { className: "flex justify-between", children: [
1894
- /* @__PURE__ */ o.jsx("span", { className: "text-[#7042D2] font-semibold", children: "Currency:" }),
1895
- /* @__PURE__ */ o.jsx("span", { className: "font-medium", children: c.currency })
2509
+ step === "confirm" && selectedPaymentMethod && payment && /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
2510
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "p-4 rounded-lg mb-4 bg-gray-100", children: [
2511
+ /* @__PURE__ */ jsxRuntimeExports.jsx("h3", { className: "text-lg font-medium mb-2 text-gray-800", children: "Payment Details" }),
2512
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-2", children: [
2513
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex justify-between", children: [
2514
+ /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-[#7042D2] font-semibold", children: "Currency:" }),
2515
+ /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "font-medium", children: selectedPaymentMethod.currency })
1896
2516
  ] }),
1897
- /* @__PURE__ */ o.jsxs("div", { className: "flex justify-between", children: [
1898
- /* @__PURE__ */ o.jsx("span", { className: "text-[#7042D2] font-semibold", children: "Network:" }),
1899
- /* @__PURE__ */ o.jsx("span", { className: "font-medium", children: H(c.network) })
2517
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex justify-between", children: [
2518
+ /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-[#7042D2] font-semibold", children: "Network:" }),
2519
+ /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "font-medium", children: getNetworkDisplayName(selectedPaymentMethod.network) })
1900
2520
  ] }),
1901
- /* @__PURE__ */ o.jsxs("div", { className: "flex justify-between", children: [
1902
- /* @__PURE__ */ o.jsx("span", { className: "text-[#7042D2] font-semibold", children: "Fee:" }),
1903
- /* @__PURE__ */ o.jsx("span", { className: "font-medium", children: "1.75%" })
2521
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex justify-between", children: [
2522
+ /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-[#7042D2] font-semibold", children: "Fee:" }),
2523
+ /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "font-medium", children: "1.75%" })
1904
2524
  ] })
1905
2525
  ] })
1906
2526
  ] }),
1907
- /* @__PURE__ */ o.jsx("div", { className: "mb-4", children: /* @__PURE__ */ o.jsxs("div", { className: "flex border-b border-gray-200", children: [
1908
- /* @__PURE__ */ o.jsx(
2527
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "mb-4", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex border-b border-gray-200", children: [
2528
+ /* @__PURE__ */ jsxRuntimeExports.jsx(
1909
2529
  "button",
1910
2530
  {
1911
- onClick: () => T("wallet"),
1912
- className: `py-2 px-4 text-sm font-medium ${p === "wallet" ? "border-b-2 border-[#7042D2] text-[#7042D2]" : "text-gray-500 hover:text-gray-700"}`,
2531
+ onClick: () => setPaymentType("wallet"),
2532
+ className: `py-2 px-4 text-sm font-medium ${paymentType === "wallet" ? "border-b-2 border-[#7042D2] text-[#7042D2]" : "text-gray-500 hover:text-gray-700"}`,
1913
2533
  children: "Connect Wallet"
1914
2534
  }
1915
2535
  ),
1916
- /* @__PURE__ */ o.jsx(
2536
+ /* @__PURE__ */ jsxRuntimeExports.jsx(
1917
2537
  "button",
1918
2538
  {
1919
- onClick: () => T("qrcode"),
1920
- className: `py-2 px-4 text-sm font-medium ${p === "qrcode" ? "border-b-2 border-[#7042D2] text-[#7042D2]" : "text-gray-500 hover:text-gray-700"}`,
2539
+ onClick: () => setPaymentType("qrcode"),
2540
+ className: `py-2 px-4 text-sm font-medium ${paymentType === "qrcode" ? "border-b-2 border-[#7042D2] text-[#7042D2]" : "text-gray-500 hover:text-gray-700"}`,
1921
2541
  children: "QR Code"
1922
2542
  }
1923
2543
  )
1924
2544
  ] }) }),
1925
- h ? (
2545
+ testMode ? (
1926
2546
  // Test mode payment option
1927
- /* @__PURE__ */ o.jsx("div", { className: "p-4 rounded-lg mb-4 bg-blue-50", children: /* @__PURE__ */ o.jsxs("div", { className: "flex items-center", children: [
1928
- /* @__PURE__ */ o.jsx("div", { className: "bg-[#7042D2] rounded-full p-2 mr-3", children: /* @__PURE__ */ o.jsx("svg", { xmlns: "http://www.w3.org/2000/svg", className: "h-6 w-6 text-white", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", children: /* @__PURE__ */ o.jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M13 10V3L4 14h7v7l9-11h-7z" }) }) }),
1929
- /* @__PURE__ */ o.jsxs("div", { children: [
1930
- /* @__PURE__ */ o.jsx("h3", { className: "font-medium text-gray-800", children: "Test Mode Payment" }),
1931
- /* @__PURE__ */ o.jsx("p", { className: "text-sm text-gray-600", children: 'Click "Pay Now" to simulate a successful payment' })
2547
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "p-4 rounded-lg mb-4 bg-blue-50", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center", children: [
2548
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "bg-[#7042D2] rounded-full p-2 mr-3", children: /* @__PURE__ */ jsxRuntimeExports.jsx("svg", { xmlns: "http://www.w3.org/2000/svg", className: "h-6 w-6 text-white", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", children: /* @__PURE__ */ jsxRuntimeExports.jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M13 10V3L4 14h7v7l9-11h-7z" }) }) }),
2549
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
2550
+ /* @__PURE__ */ jsxRuntimeExports.jsx("h3", { className: "font-medium text-gray-800", children: "Test Mode Payment" }),
2551
+ /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm text-gray-600", children: 'Click "Pay Now" to simulate a successful payment' })
1932
2552
  ] })
1933
2553
  ] }) })
1934
- ) : p === "qrcode" ? (
2554
+ ) : paymentType === "qrcode" ? (
1935
2555
  // QR Code payment option
1936
- /* @__PURE__ */ o.jsx("div", { className: "mb-4", children: /* @__PURE__ */ o.jsx(
1937
- Rt,
2556
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "mb-4", children: /* @__PURE__ */ jsxRuntimeExports.jsx(
2557
+ QRCode,
1938
2558
  {
1939
- walletAddress: e.recipientWallet || "No address configured",
1940
- amount: e.totalAmount || e.amount,
1941
- currency: c.currency,
1942
- network: c.network,
1943
- theme: n
2559
+ walletAddress: getWalletAddressForNetwork(),
2560
+ amount: payment.totalAmount || payment.amount,
2561
+ currency: selectedPaymentMethod.currency,
2562
+ network: selectedPaymentMethod.network,
2563
+ theme
1944
2564
  }
1945
2565
  ) })
1946
2566
  ) : (
1947
2567
  // Wallet connection option
1948
- /* @__PURE__ */ o.jsxs("div", { className: "space-y-3 mb-4", children: [
1949
- k.length === 0 ? /* @__PURE__ */ o.jsx("div", { className: "p-4 rounded-lg bg-yellow-50", children: /* @__PURE__ */ o.jsxs("div", { className: "flex items-center", children: [
1950
- /* @__PURE__ */ o.jsx("svg", { xmlns: "http://www.w3.org/2000/svg", className: "h-6 w-6 text-yellow-500 mr-2", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", children: /* @__PURE__ */ o.jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z" }) }),
1951
- /* @__PURE__ */ o.jsxs("div", { children: [
1952
- /* @__PURE__ */ o.jsx("h3", { className: "font-medium text-gray-800", children: "No Compatible Wallets" }),
1953
- /* @__PURE__ */ o.jsxs("p", { className: "text-sm text-gray-600", children: [
2568
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-3 mb-4", children: [
2569
+ supportedWallets.length === 0 ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "p-4 rounded-lg bg-yellow-50", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center", children: [
2570
+ /* @__PURE__ */ jsxRuntimeExports.jsx("svg", { xmlns: "http://www.w3.org/2000/svg", className: "h-6 w-6 text-yellow-500 mr-2", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", children: /* @__PURE__ */ jsxRuntimeExports.jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z" }) }),
2571
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
2572
+ /* @__PURE__ */ jsxRuntimeExports.jsx("h3", { className: "font-medium text-gray-800", children: "No Compatible Wallets" }),
2573
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("p", { className: "text-sm text-gray-600", children: [
1954
2574
  "No wallets detected for ",
1955
- H(c.network),
2575
+ getNetworkDisplayName(selectedPaymentMethod.network),
1956
2576
  " network"
1957
2577
  ] })
1958
2578
  ] })
1959
- ] }) }) : k.map((v) => /* @__PURE__ */ o.jsx("div", { className: "p-4 rounded-lg bg-blue-50", children: /* @__PURE__ */ o.jsxs("div", { className: "flex items-center justify-between", children: [
1960
- /* @__PURE__ */ o.jsxs("div", { className: "flex items-center", children: [
1961
- /* @__PURE__ */ o.jsx(
2579
+ ] }) }) : supportedWallets.map((walletType) => /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "p-4 rounded-lg bg-blue-50", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center justify-between", children: [
2580
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center", children: [
2581
+ /* @__PURE__ */ jsxRuntimeExports.jsx(
1962
2582
  "img",
1963
2583
  {
1964
- src: M(v),
1965
- alt: O(v),
2584
+ src: getWalletIcon(walletType),
2585
+ alt: getWalletDisplayName(walletType),
1966
2586
  className: "w-8 h-8 mr-3",
1967
- onError: (S) => {
1968
- S.target.style.display = "none";
2587
+ onError: (e) => {
2588
+ e.target.style.display = "none";
1969
2589
  }
1970
2590
  }
1971
2591
  ),
1972
- /* @__PURE__ */ o.jsxs("div", { children: [
1973
- /* @__PURE__ */ o.jsx("h3", { className: "font-medium text-gray-800", children: O(v) }),
1974
- /* @__PURE__ */ o.jsxs("p", { className: "text-sm text-gray-600", children: [
2592
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
2593
+ /* @__PURE__ */ jsxRuntimeExports.jsx("h3", { className: "font-medium text-gray-800", children: getWalletDisplayName(walletType) }),
2594
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("p", { className: "text-sm text-gray-600", children: [
1975
2595
  "Pay with ",
1976
- O(v)
2596
+ getWalletDisplayName(walletType)
1977
2597
  ] })
1978
2598
  ] })
1979
2599
  ] }),
1980
- (d == null ? void 0 : d.walletType) === v ? /* @__PURE__ */ o.jsxs("div", { className: "flex items-center space-x-2", children: [
1981
- /* @__PURE__ */ o.jsx("div", { className: "w-2 h-2 bg-green-500 rounded-full" }),
1982
- /* @__PURE__ */ o.jsx("span", { className: "text-sm text-green-600", children: "Connected" })
1983
- ] }) : /* @__PURE__ */ o.jsx(
2600
+ (walletConnection == null ? void 0 : walletConnection.walletType) === walletType ? /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center space-x-2", children: [
2601
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "w-2 h-2 bg-green-500 rounded-full" }),
2602
+ /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-sm text-green-600", children: "Connected" })
2603
+ ] }) : /* @__PURE__ */ jsxRuntimeExports.jsx(
1984
2604
  "button",
1985
2605
  {
1986
- onClick: () => g(v),
2606
+ onClick: () => onConnectWallet(walletType),
1987
2607
  className: "py-2 px-4 bg-[#7042D2] hover:bg-[#7042D2] text-white font-medium rounded-md text-sm",
1988
2608
  children: "Connect"
1989
2609
  }
1990
2610
  )
1991
- ] }) }, v)),
1992
- /* @__PURE__ */ o.jsx("div", { className: "space-y-2", children: Object.entries(f).filter(([v, S]) => !S).map(([v]) => /* @__PURE__ */ o.jsx("div", { className: "p-3 rounded-lg bg-gray-50", children: /* @__PURE__ */ o.jsxs("div", { className: "flex items-center justify-between", children: [
1993
- /* @__PURE__ */ o.jsxs("span", { className: "text-sm text-gray-600", children: [
1994
- O(v),
2611
+ ] }) }, walletType)),
2612
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "space-y-2", children: Object.entries(availableWallets).filter(([walletType, isAvailable]) => !isAvailable).map(([walletType]) => /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "p-3 rounded-lg bg-gray-50", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center justify-between", children: [
2613
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "text-sm text-gray-600", children: [
2614
+ getWalletDisplayName(walletType),
1995
2615
  " not detected"
1996
2616
  ] }),
1997
- /* @__PURE__ */ o.jsx(
2617
+ /* @__PURE__ */ jsxRuntimeExports.jsx(
1998
2618
  "a",
1999
2619
  {
2000
- href: ct(v),
2620
+ href: getWalletInstallUrl(walletType),
2001
2621
  target: "_blank",
2002
2622
  rel: "noopener noreferrer",
2003
2623
  className: "text-sm text-[#7042D2] hover:underline",
2004
2624
  children: "Install"
2005
2625
  }
2006
2626
  )
2007
- ] }) }, v)) })
2627
+ ] }) }, walletType)) })
2008
2628
  ] })
2009
2629
  ),
2010
- /* @__PURE__ */ o.jsxs("div", { className: "grid grid-cols-2 gap-3", children: [
2011
- /* @__PURE__ */ o.jsx(
2630
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "grid grid-cols-2 gap-3", children: [
2631
+ /* @__PURE__ */ jsxRuntimeExports.jsx(
2012
2632
  "button",
2013
2633
  {
2014
2634
  type: "button",
2015
- onClick: x,
2635
+ onClick: onBack,
2016
2636
  className: "w-full py-2 px-4 bg-gray-200 hover:bg-gray-300 text-[#7042D2] font-medium rounded-md",
2017
2637
  children: "Back"
2018
2638
  }
2019
2639
  ),
2020
- /* @__PURE__ */ o.jsx(
2640
+ /* @__PURE__ */ jsxRuntimeExports.jsx(
2021
2641
  "button",
2022
2642
  {
2023
2643
  type: "button",
2024
- onClick: () => y(p === "qrcode"),
2644
+ onClick: () => onPayment(paymentType === "qrcode"),
2025
2645
  className: "w-full py-2 px-4 bg-[#7042D2] hover:bg-[#7042D2] text-white font-medium rounded-md",
2026
- disabled: !h && p === "wallet" && !d,
2027
- children: p === "qrcode" ? "I have sent the payment" : "Pay Now"
2646
+ disabled: !testMode && paymentType === "wallet" && !walletConnection,
2647
+ children: paymentType === "qrcode" ? "I have sent the payment" : "Pay Now"
2028
2648
  }
2029
2649
  )
2030
2650
  ] })
2031
2651
  ] }),
2032
- w === "processing" && /* @__PURE__ */ o.jsx(
2033
- ie,
2652
+ step === "processing" && /* @__PURE__ */ jsxRuntimeExports.jsx(
2653
+ PaymentStatus,
2034
2654
  {
2035
2655
  status: "processing",
2036
- theme: n,
2656
+ theme,
2037
2657
  message: "Processing your payment..."
2038
2658
  }
2039
2659
  ),
2040
- w === "success" && /* @__PURE__ */ o.jsxs("div", { children: [
2041
- /* @__PURE__ */ o.jsx(
2042
- ie,
2660
+ step === "success" && /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
2661
+ /* @__PURE__ */ jsxRuntimeExports.jsx(
2662
+ PaymentStatus,
2043
2663
  {
2044
2664
  status: "success",
2045
- theme: n,
2665
+ theme,
2046
2666
  message: "Payment successful!"
2047
2667
  }
2048
2668
  ),
2049
- l && /* @__PURE__ */ o.jsxs("div", { className: "mt-4 p-3 rounded-lg bg-gray-100", children: [
2050
- /* @__PURE__ */ o.jsx("p", { className: "text-xs text-gray-600 mb-1", children: "Transaction Hash:" }),
2051
- /* @__PURE__ */ o.jsx("p", { className: "text-sm font-mono break-all text-gray-800", children: q(l) }),
2052
- c && /* @__PURE__ */ o.jsx(
2669
+ transactionHash && /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "mt-4 p-3 rounded-lg bg-gray-100", children: [
2670
+ /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xs text-gray-600 mb-1", children: "Transaction Hash:" }),
2671
+ /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm font-mono break-all text-gray-800", children: formatTransactionHash(transactionHash) }),
2672
+ selectedPaymentMethod && /* @__PURE__ */ jsxRuntimeExports.jsx(
2053
2673
  "a",
2054
2674
  {
2055
- href: `${Dt(c.network)}/${Ut(c.network)}/${l}`,
2675
+ href: `${getExplorerUrl(selectedPaymentMethod.network)}/${getExplorerPath(selectedPaymentMethod.network)}/${transactionHash}`,
2056
2676
  target: "_blank",
2057
2677
  rel: "noopener noreferrer",
2058
2678
  className: "text-xs text-[#7042D2] mt-2 inline-block",
@@ -2061,225 +2681,305 @@ const Rt = ({
2061
2681
  )
2062
2682
  ] })
2063
2683
  ] }),
2064
- w === "error" && /* @__PURE__ */ o.jsxs("div", { children: [
2065
- /* @__PURE__ */ o.jsx(
2066
- ie,
2684
+ step === "error" && /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
2685
+ /* @__PURE__ */ jsxRuntimeExports.jsx(
2686
+ PaymentStatus,
2067
2687
  {
2068
2688
  status: "error",
2069
- theme: n,
2070
- message: r || "An error occurred while processing your payment."
2689
+ theme,
2690
+ message: error || "An error occurred while processing your payment."
2071
2691
  }
2072
2692
  ),
2073
- /* @__PURE__ */ o.jsx(
2693
+ /* @__PURE__ */ jsxRuntimeExports.jsx(
2074
2694
  "button",
2075
2695
  {
2076
2696
  type: "button",
2077
- onClick: x,
2697
+ onClick: onBack,
2078
2698
  className: "mt-4 w-full py-2 px-4 bg-gray-200 hover:bg-gray-300 text-gray-800 font-medium rounded-md",
2079
2699
  children: "Try Again"
2080
2700
  }
2081
2701
  )
2082
2702
  ] })
2083
2703
  ] }),
2084
- /* @__PURE__ */ o.jsx("div", { className: "text-center text-xs text-gray-500", children: /* @__PURE__ */ o.jsxs("p", { children: [
2704
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-center text-xs text-gray-500", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("p", { children: [
2085
2705
  "Powered by ",
2086
- /* @__PURE__ */ o.jsx("span", { className: "text-[#7042D2]", children: "Coinley" }),
2706
+ /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-[#7042D2]", children: "Coinley" }),
2087
2707
  " - Secure Cryptocurrency Payments"
2088
2708
  ] }) })
2089
- ] }) }) }) : null;
2090
- }, Dt = (s) => ({
2091
- ethereum: "https://etherscan.io",
2092
- bsc: "https://bscscan.com",
2093
- tron: "https://tronscan.org",
2094
- algorand: "https://algoexplorer.io"
2095
- })[s] || "https://etherscan.io", Ut = (s) => ({
2096
- ethereum: "tx",
2097
- bsc: "tx",
2098
- tron: "transaction",
2099
- algorand: "tx"
2100
- })[s] || "tx", Ot = _e(({
2101
- apiKey: s,
2102
- apiSecret: t,
2103
- apiUrl: e,
2104
- customerEmail: i,
2105
- merchantName: c = "Merchant",
2106
- merchantWalletAddresses: u = {},
2709
+ ] }) }) });
2710
+ };
2711
+ const getExplorerUrl = (network) => {
2712
+ const explorers = {
2713
+ ethereum: "https://etherscan.io",
2714
+ bsc: "https://bscscan.com",
2715
+ tron: "https://tronscan.org",
2716
+ algorand: "https://algoexplorer.io"
2717
+ };
2718
+ return explorers[network] || "https://etherscan.io";
2719
+ };
2720
+ const getExplorerPath = (network) => {
2721
+ const paths = {
2722
+ ethereum: "tx",
2723
+ bsc: "tx",
2724
+ tron: "transaction",
2725
+ algorand: "tx"
2726
+ };
2727
+ return paths[network] || "tx";
2728
+ };
2729
+ const CoinleyCheckout = forwardRef(({
2730
+ apiKey,
2731
+ apiSecret,
2732
+ apiUrl,
2733
+ customerEmail,
2734
+ merchantName = "Merchant",
2735
+ merchantWalletAddresses = {},
2107
2736
  // Object with network-specific addresses
2108
- onSuccess: y,
2109
- onError: x,
2110
- onClose: r,
2111
- theme: n,
2112
- autoOpen: a = !1,
2113
- debug: l = !1,
2114
- testMode: d = !1,
2115
- supportedNetworks: g = [],
2737
+ onSuccess,
2738
+ onError,
2739
+ onClose,
2740
+ theme,
2741
+ autoOpen = false,
2742
+ debug = false,
2743
+ testMode = false,
2744
+ supportedNetworks = [],
2116
2745
  // Array of supported networks
2117
- preferredNetwork: h = b.ETHEREUM,
2118
- preferredWallet: m = N.METAMASK
2119
- }, f) => {
2120
- const k = bt(), { theme: w } = yt(), [p, T] = D(a), [C, q] = D(null), [H, O] = D("idle"), [M, v] = D(null), [S, B] = D(null), [ee, W] = D(null), [I, V] = D(null), [$, te] = D({}), [X, G] = D("select-currency");
2121
- s || (k == null || k.apiKey), t || (k == null || k.apiSecret), e || (k == null || k.apiUrl);
2122
- const oe = n || w, re = l || (k == null ? void 0 : k.debug), ae = g.length > 0 ? g : [b.ETHEREUM, b.BSC, b.TRON, b.ALGORAND];
2123
- Je(f, () => ({
2124
- open: (A) => {
2125
- Ie(A);
2746
+ preferredNetwork = NETWORK_TYPES.ETHEREUM,
2747
+ preferredWallet = WALLET_TYPES.METAMASK
2748
+ }, ref) => {
2749
+ const coinleyContext = useCoinley();
2750
+ const { theme: contextTheme } = useTheme();
2751
+ const [isOpen, setIsOpen] = useState(autoOpen);
2752
+ const [payment, setPayment] = useState(null);
2753
+ const [paymentStatus, setPaymentStatus] = useState("idle");
2754
+ const [selectedPaymentMethod, setSelectedPaymentMethod] = useState(null);
2755
+ const [error, setError] = useState(null);
2756
+ const [transactionHash, setTransactionHash] = useState(null);
2757
+ const [walletConnection, setWalletConnection] = useState(null);
2758
+ const [availableWallets, setAvailableWallets] = useState({});
2759
+ const [step, setStep] = useState("select-currency");
2760
+ apiKey || (coinleyContext == null ? void 0 : coinleyContext.apiKey);
2761
+ apiSecret || (coinleyContext == null ? void 0 : coinleyContext.apiSecret);
2762
+ apiUrl || (coinleyContext == null ? void 0 : coinleyContext.apiUrl);
2763
+ const effectiveTheme = theme || contextTheme;
2764
+ const effectiveDebug = debug || (coinleyContext == null ? void 0 : coinleyContext.debug);
2765
+ const effectiveSupportedNetworks = supportedNetworks.length > 0 ? supportedNetworks : [NETWORK_TYPES.ETHEREUM, NETWORK_TYPES.BSC, NETWORK_TYPES.TRON, NETWORK_TYPES.ALGORAND];
2766
+ useImperativeHandle(ref, () => ({
2767
+ open: (paymentDetails) => {
2768
+ handleOpen(paymentDetails);
2126
2769
  },
2127
2770
  close: () => {
2128
- he();
2771
+ handleClose();
2129
2772
  },
2130
- getPayment: () => C,
2131
- getWalletConnection: () => I
2773
+ getPayment: () => payment,
2774
+ getWalletConnection: () => walletConnection
2132
2775
  }));
2133
- const P = (A, F) => {
2134
- re && console.log(`[Coinley SDK] ${A}`, F);
2776
+ const log = (message, data) => {
2777
+ if (effectiveDebug) {
2778
+ console.log(`[Coinley SDK] ${message}`, data);
2779
+ }
2135
2780
  };
2136
- Z(() => {
2137
- if (typeof window != "undefined") {
2138
- const A = ue();
2139
- te(A), P("Available wallets detected:", A);
2140
- }
2141
- }, [re]);
2142
- const Ie = (A) => R(void 0, null, function* () {
2143
- if (!A || !A.amount) {
2144
- B("Payment amount is required"), x && x(new Error("Payment amount is required"));
2781
+ useEffect(() => {
2782
+ if (typeof window !== "undefined") {
2783
+ const wallets = detectWallets();
2784
+ setAvailableWallets(wallets);
2785
+ log("Available wallets detected:", wallets);
2786
+ }
2787
+ }, [effectiveDebug]);
2788
+ const handleOpen = (paymentDetails) => __async(void 0, null, function* () {
2789
+ if (!paymentDetails || !paymentDetails.amount) {
2790
+ setError("Payment amount is required");
2791
+ if (onError)
2792
+ onError(new Error("Payment amount is required"));
2145
2793
  return;
2146
2794
  }
2147
- O("loading"), T(!0), G("select-currency");
2795
+ setPaymentStatus("loading");
2796
+ setIsOpen(true);
2797
+ setStep("select-currency");
2148
2798
  try {
2149
- P("Creating payment with details:", A);
2150
- const F = yield ut({
2151
- amount: A.amount,
2152
- currency: A.currency || "USDT",
2153
- network: A.network || h,
2154
- customerEmail: A.customerEmail || i,
2155
- callbackUrl: A.callbackUrl,
2156
- metadata: A.metadata || {},
2157
- merchantWalletAddresses: z(z({}, u), A.merchantWalletAddresses)
2799
+ log("Creating payment with details:", paymentDetails);
2800
+ const paymentResponse = yield createPayment({
2801
+ amount: paymentDetails.amount,
2802
+ currency: paymentDetails.currency || "USDT",
2803
+ network: paymentDetails.network || preferredNetwork,
2804
+ customerEmail: paymentDetails.customerEmail || customerEmail,
2805
+ callbackUrl: paymentDetails.callbackUrl,
2806
+ metadata: paymentDetails.metadata || {},
2807
+ merchantWalletAddresses: __spreadValues(__spreadValues({}, merchantWalletAddresses), paymentDetails.merchantWalletAddresses)
2158
2808
  });
2159
- P("Payment created:", F), q(F.payment), O("idle"), B(null), P("Payment created and state updated");
2160
- } catch (F) {
2161
- P("Error creating payment:", F), B(F.message || "Failed to create payment"), O("error"), x && x(F);
2162
- }
2163
- }), he = () => {
2164
- T(!1), W(null), V(null), v(null), G("select-currency"), r && r();
2165
- }, Fe = (A) => {
2166
- P("Payment method selected:", A), v(A), G("confirm");
2167
- }, Be = () => {
2168
- X === "confirm" && (G("select-currency"), V(null));
2169
- }, We = (A) => R(void 0, null, function* () {
2170
- if (!M) {
2171
- B("Please select a payment method first");
2809
+ log("Payment created:", paymentResponse);
2810
+ setPayment(paymentResponse.payment);
2811
+ setPaymentStatus("idle");
2812
+ setError(null);
2813
+ log("Payment created and state updated");
2814
+ } catch (err) {
2815
+ log("Error creating payment:", err);
2816
+ setError(err.message || "Failed to create payment");
2817
+ setPaymentStatus("error");
2818
+ if (onError)
2819
+ onError(err);
2820
+ }
2821
+ });
2822
+ const handleClose = () => {
2823
+ setIsOpen(false);
2824
+ setTransactionHash(null);
2825
+ setWalletConnection(null);
2826
+ setSelectedPaymentMethod(null);
2827
+ setStep("select-currency");
2828
+ if (onClose)
2829
+ onClose();
2830
+ };
2831
+ const handlePaymentMethodSelect = (paymentMethod) => {
2832
+ log("Payment method selected:", paymentMethod);
2833
+ setSelectedPaymentMethod(paymentMethod);
2834
+ setStep("confirm");
2835
+ };
2836
+ const handleBack = () => {
2837
+ if (step === "confirm") {
2838
+ setStep("select-currency");
2839
+ setWalletConnection(null);
2840
+ }
2841
+ };
2842
+ const handleConnectWallet = (walletType) => __async(void 0, null, function* () {
2843
+ if (!selectedPaymentMethod) {
2844
+ setError("Please select a payment method first");
2172
2845
  return;
2173
2846
  }
2174
2847
  try {
2175
- P("Connecting wallet:", { walletType: A, network: M.network });
2176
- const F = yield et(A, M.network);
2177
- V(F), B(null), P("Wallet connected successfully:", F);
2178
- } catch (F) {
2179
- P("Wallet connection error:", F), B(F.message || "Failed to connect wallet");
2180
- }
2181
- }), Qe = () => R(void 0, null, function* () {
2182
- var A, F;
2183
- if (!C || !M) {
2184
- B("Missing payment information");
2848
+ log("Connecting wallet:", { walletType, network: selectedPaymentMethod.network });
2849
+ const connection = yield connectWallet(walletType, selectedPaymentMethod.network);
2850
+ setWalletConnection(connection);
2851
+ setError(null);
2852
+ log("Wallet connected successfully:", connection);
2853
+ } catch (err) {
2854
+ log("Wallet connection error:", err);
2855
+ setError(err.message || "Failed to connect wallet");
2856
+ }
2857
+ });
2858
+ const handlePayment = () => __async(void 0, null, function* () {
2859
+ var _a, _b;
2860
+ if (!payment || !selectedPaymentMethod) {
2861
+ setError("Missing payment information");
2185
2862
  return;
2186
2863
  }
2187
- if (!I && !d) {
2188
- B("Please connect your wallet first");
2864
+ if (!walletConnection && !testMode) {
2865
+ setError("Please connect your wallet first");
2189
2866
  return;
2190
2867
  }
2191
- P("Starting payment process..."), O("loading"), W(null);
2868
+ log("Starting payment process...");
2869
+ setPaymentStatus("loading");
2870
+ setTransactionHash(null);
2192
2871
  try {
2193
- let Q;
2194
- if (d)
2195
- P("Test mode: Generating mock transaction..."), Q = `test_${Date.now().toString(16)}_${Math.random().toString(16).substring(2, 10)}`;
2196
- else {
2197
- const me = u[M.network];
2198
- if (!me)
2199
- throw new Error(`No merchant wallet address configured for ${M.network}`);
2200
- P("Sending transaction through wallet..."), Q = yield ot(I, {
2201
- to: me,
2202
- amount: C.amount,
2203
- tokenAddress: (A = M.tokenConfig) == null ? void 0 : A.address,
2204
- tokenDecimals: (F = M.tokenConfig) == null ? void 0 : F.decimals
2872
+ let txHash;
2873
+ if (testMode) {
2874
+ log("Test mode: Generating mock transaction...");
2875
+ txHash = `test_${Date.now().toString(16)}_${Math.random().toString(16).substring(2, 10)}`;
2876
+ } else {
2877
+ const merchantAddress = merchantWalletAddresses[selectedPaymentMethod.network];
2878
+ if (!merchantAddress) {
2879
+ throw new Error(`No merchant wallet address configured for ${selectedPaymentMethod.network}`);
2880
+ }
2881
+ log("Sending transaction through wallet...");
2882
+ txHash = yield sendTransaction(walletConnection, {
2883
+ to: merchantAddress,
2884
+ amount: payment.amount,
2885
+ tokenAddress: (_a = selectedPaymentMethod.tokenConfig) == null ? void 0 : _a.address,
2886
+ tokenDecimals: (_b = selectedPaymentMethod.tokenConfig) == null ? void 0 : _b.decimals
2205
2887
  });
2206
2888
  }
2207
- P("Transaction hash:", Q), W(Q), P("Processing payment with backend...");
2208
- const Ge = yield ht({
2209
- paymentId: C.id,
2210
- transactionHash: Q,
2211
- network: M.network,
2212
- currency: M.currency,
2213
- senderAddress: I == null ? void 0 : I.address
2889
+ log("Transaction hash:", txHash);
2890
+ setTransactionHash(txHash);
2891
+ log("Processing payment with backend...");
2892
+ const processResponse = yield processPayment({
2893
+ paymentId: payment.id,
2894
+ transactionHash: txHash,
2895
+ network: selectedPaymentMethod.network,
2896
+ currency: selectedPaymentMethod.currency,
2897
+ senderAddress: walletConnection == null ? void 0 : walletConnection.address
2214
2898
  });
2215
- P("Payment processed successfully:", Ge), O("success"), G("success"), y && (P("Calling onSuccess callback..."), y(C.id, Q, {
2216
- network: M.network,
2217
- currency: M.currency,
2218
- amount: C.amount
2219
- }));
2220
- } catch (Q) {
2221
- P("Payment error:", Q), B(Q.message || "Failed to process payment"), O("error"), G("error"), x && x(Q);
2222
- }
2223
- }), ze = () => M ? Ze(M.network) : [];
2224
- return /* @__PURE__ */ o.jsx(o.Fragment, { children: p && /* @__PURE__ */ o.jsx(
2225
- Pt,
2899
+ log("Payment processed successfully:", processResponse);
2900
+ setPaymentStatus("success");
2901
+ setStep("success");
2902
+ if (onSuccess) {
2903
+ log("Calling onSuccess callback...");
2904
+ onSuccess(payment.id, txHash, {
2905
+ network: selectedPaymentMethod.network,
2906
+ currency: selectedPaymentMethod.currency,
2907
+ amount: payment.amount
2908
+ });
2909
+ }
2910
+ } catch (err) {
2911
+ log("Payment error:", err);
2912
+ setError(err.message || "Failed to process payment");
2913
+ setPaymentStatus("error");
2914
+ setStep("error");
2915
+ if (onError)
2916
+ onError(err);
2917
+ }
2918
+ });
2919
+ const getSupportedWallets = () => {
2920
+ if (!selectedPaymentMethod)
2921
+ return [];
2922
+ return getSupportedWalletsForNetwork(selectedPaymentMethod.network);
2923
+ };
2924
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: isOpen && /* @__PURE__ */ jsxRuntimeExports.jsx(
2925
+ CoinleyModal,
2226
2926
  {
2227
- isOpen: p,
2228
- onClose: he,
2229
- payment: C,
2230
- paymentStatus: H,
2231
- selectedPaymentMethod: M,
2232
- onPaymentMethodSelect: Fe,
2233
- onPayment: Qe,
2234
- onBack: Be,
2235
- error: S,
2236
- theme: oe,
2237
- merchantName: c,
2238
- transactionHash: ee,
2239
- walletConnection: I,
2240
- onConnectWallet: We,
2241
- testMode: d,
2242
- supportedNetworks: ae,
2243
- availableWallets: $,
2244
- supportedWallets: ze(),
2245
- step: X
2927
+ isOpen,
2928
+ onClose: handleClose,
2929
+ payment,
2930
+ paymentStatus,
2931
+ selectedPaymentMethod,
2932
+ onPaymentMethodSelect: handlePaymentMethodSelect,
2933
+ onPayment: handlePayment,
2934
+ onBack: handleBack,
2935
+ error,
2936
+ theme: effectiveTheme,
2937
+ merchantName,
2938
+ transactionHash,
2939
+ walletConnection,
2940
+ onConnectWallet: handleConnectWallet,
2941
+ testMode,
2942
+ supportedNetworks: effectiveSupportedNetworks,
2943
+ availableWallets,
2944
+ supportedWallets: getSupportedWallets(),
2945
+ step,
2946
+ merchantWalletAddresses
2246
2947
  }
2247
2948
  ) });
2248
2949
  });
2249
- Ot.displayName = "CoinleyCheckout";
2250
- const Vt = {
2950
+ CoinleyCheckout.displayName = "CoinleyCheckout";
2951
+ const DEFAULT_CONFIG = {
2251
2952
  apiUrl: "http://localhost:9000",
2252
- debug: !1,
2253
- testMode: !1,
2953
+ debug: false,
2954
+ testMode: false,
2254
2955
  theme: "light",
2255
2956
  supportedNetworks: ["ethereum", "bsc", "tron", "algorand"]
2256
- }, _t = "0.3.2";
2957
+ };
2257
2958
  export {
2258
- Ot as CoinleyCheckout,
2259
- Pt as CoinleyModal,
2260
- Ht as CoinleyProvider,
2261
- Vt as DEFAULT_CONFIG,
2262
- de as NETWORK_CONFIG,
2263
- b as NETWORK_TYPES,
2264
- St as PaymentMethods,
2265
- ie as PaymentStatus,
2266
- Rt as QRCode,
2267
- Ye as TOKEN_CONFIG,
2268
- qt as ThemeProvider,
2269
- _t as VERSION,
2270
- N as WALLET_TYPES,
2271
- et as connectWallet,
2272
- ut as createPayment,
2273
- ue as detectWallets,
2274
- Gt as generateMockTransactionHash,
2275
- Qt as getMerchantProfile,
2276
- Bt as getPayment,
2277
- Wt as getSupportedNetworks,
2278
- Ze as getSupportedWalletsForNetwork,
2279
- ct as getWalletInstallUrl,
2280
- ht as processPayment,
2281
- ot as sendTransaction,
2282
- bt as useCoinley,
2283
- zt as validateWalletAddress
2959
+ CoinleyCheckout,
2960
+ CoinleyModal,
2961
+ CoinleyProvider,
2962
+ DEFAULT_CONFIG,
2963
+ NETWORK_CONFIG,
2964
+ NETWORK_TYPES,
2965
+ PaymentMethods,
2966
+ PaymentStatus,
2967
+ QRCode,
2968
+ TOKEN_CONFIG,
2969
+ ThemeProvider,
2970
+ WALLET_TYPES,
2971
+ connectWallet,
2972
+ createPayment,
2973
+ detectWallets,
2974
+ generateMockTransactionHash,
2975
+ getMerchantProfile,
2976
+ getPayment,
2977
+ getSupportedNetworks,
2978
+ getSupportedWalletsForNetwork,
2979
+ getWalletInstallUrl,
2980
+ processPayment,
2981
+ sendTransaction,
2982
+ useCoinley,
2983
+ validateWalletAddress
2284
2984
  };
2285
2985
  //# sourceMappingURL=coinley-checkout.es.js.map