coinley-checkout 0.3.2 → 0.3.4
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.
- package/dist/coinley-checkout.es.js +2079 -1379
- package/dist/coinley-checkout.es.js.map +1 -1
- package/dist/coinley-checkout.umd.js +6 -17
- package/dist/coinley-checkout.umd.js.map +1 -1
- package/dist/style.css +1 -1
- package/package.json +3 -2
@@ -1,18 +1,7 @@
|
|
1
|
-
(function(b,f){typeof exports=="object"&&typeof module!="undefined"?f(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],f):(b=typeof globalThis!="undefined"?globalThis:b||self,f(b.CoinleyCheckout={},b.React))})(this,function(b,f){"use strict";var It=Object.defineProperty,Ft=Object.defineProperties;var Wt=Object.getOwnPropertyDescriptors;var He=Object.getOwnPropertySymbols;var Bt=Object.prototype.hasOwnProperty,Qt=Object.prototype.propertyIsEnumerable;var $e=(b,f,W)=>f in b?It(b,f,{enumerable:!0,configurable:!0,writable:!0,value:W}):b[f]=W,q=(b,f)=>{for(var W in f||(f={}))Bt.call(f,W)&&$e(b,W,f[W]);if(He)for(var W of He(f))Qt.call(f,W)&&$e(b,W,f[W]);return b},Ke=(b,f)=>Ft(b,Wt(f));var P=(b,f,W)=>new Promise((N,E)=>{var X=H=>{try{z(W.next(H))}catch(K){E(K)}},se=H=>{try{z(W.throw(H))}catch(K){E(K)}},z=H=>H.done?N(H.value):Promise.resolve(H.value).then(X,se);z((W=W.apply(b,f)).next())});const W="",N={ETHEREUM:"ethereum",BSC:"bsc",TRON:"tron",ALGORAND:"algorand"},E={METAMASK:"metamask",TRONLINK:"tronlink",TRUST_WALLET:"trust_wallet",LUTE:"lute"},X={[N.ETHEREUM]:{chainId:"0x1",chainName:"Ethereum Mainnet",nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18},rpcUrls:["https://mainnet.infura.io/v3/"],blockExplorerUrls:["https://etherscan.io/"],supportedWallets:[E.METAMASK,E.TRUST_WALLET]},[N.BSC]:{chainId:"0x38",chainName:"BNB Smart Chain",nativeCurrency:{name:"BNB",symbol:"BNB",decimals:18},rpcUrls:["https://bsc-dataseed.binance.org/"],blockExplorerUrls:["https://bscscan.com/"],supportedWallets:[E.METAMASK,E.TRUST_WALLET]},[N.TRON]:{fullHost:"https://api.trongrid.io",explorerUrl:"https://tronscan.org",supportedWallets:[E.TRONLINK]},[N.ALGORAND]:{network:"mainnet",explorerUrl:"https://algoexplorer.io",supportedWallets:[E.LUTE]}},se={USDT:{[N.ETHEREUM]:{address:"0xdAC17F958D2ee523a2206206994597C13D831ec7",decimals:6},[N.BSC]:{address:"0x55d398326f99059fF775485246999027B3197955",decimals:18},[N.TRON]:{address:"TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t",decimals:6}},USDC:{[N.ETHEREUM]:{address:"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",decimals:6},[N.BSC]:{address:"0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d",decimals:18},[N.TRON]:{address:"TEkxiTehnzSmSe2XqrBj4w32RUN966rdz8",decimals:6}},ALGO:{[N.ALGORAND]:{address:"native",decimals:6}}};let z=null;const H=()=>P(this,null,function*(){if(z)return z;try{if(typeof window!="undefined"&&window.Web3)return z=window.Web3,z;const s=yield import("web3");return z=s.default||s.Web3||s,z}catch(s){throw console.error("Failed to load Web3:",s),new Error("Web3 is required for blockchain transactions. Please ensure web3 is installed: npm install web3")}}),K=()=>{const s={[E.METAMASK]:!1,[E.TRUST_WALLET]:!1,[E.TRONLINK]:!1,[E.LUTE]:!1};if(typeof window=="undefined")return s;try{s[E.METAMASK]=!!(window.ethereum&&window.ethereum.isMetaMask),s[E.TRONLINK]=!!window.tronWeb,s[E.TRUST_WALLET]=!!(window.ethereum&&window.ethereum.isTrust),s[E.LUTE]=!!(window.algorand&&window.algorand.isLute)}catch(r){console.warn("Error detecting wallets:",r)}return s},fe=s=>{const r=X[s];if(!r)return[];const t=K();return r.supportedWallets.filter(l=>t[l])},ge=(s,r)=>P(this,null,function*(){switch(s){case E.METAMASK:return yield Ve(r);case E.TRONLINK:return yield _e();case E.TRUST_WALLET:return yield Je(r);case E.LUTE:return yield Ye();default:throw new Error(`Unsupported wallet type: ${s}`)}}),Ve=s=>P(this,null,function*(){if(typeof window=="undefined"||!window.ethereum||!window.ethereum.isMetaMask)throw new Error("MetaMask is not installed. Please install MetaMask extension.");try{const r=yield window.ethereum.request({method:"eth_requestAccounts"});if(!r||r.length===0)throw new Error("No accounts found. Please unlock MetaMask.");const t=X[s];return t&&t.chainId&&(yield we(t)),{address:r[0],network:s,walletType:E.METAMASK}}catch(r){throw r.code===4001?new Error("User rejected the connection request"):new Error(`Failed to connect MetaMask: ${r.message}`)}}),_e=()=>P(this,null,function*(){var l;if(typeof window=="undefined"||!window.tronWeb)throw new Error("TronLink is not installed. Please install TronLink extension.");let s=0;const r=10;for(;!window.tronWeb.ready&&s<r;)yield new Promise(d=>setTimeout(d,1e3)),s++;if(!window.tronWeb.ready)throw new Error("TronLink is not ready. Please unlock your TronLink wallet and try again.");const t=(l=window.tronWeb.defaultAddress)==null?void 0:l.base58;if(!t)throw new Error("No account found in TronLink. Please make sure you have an account set up.");return{address:t,network:N.TRON,walletType:E.TRONLINK}}),Je=s=>P(this,null,function*(){if(typeof window=="undefined"||!window.ethereum||!window.ethereum.isTrust)throw new Error("Trust Wallet is not installed. Please install Trust Wallet extension.");try{const r=yield window.ethereum.request({method:"eth_requestAccounts"});if(!r||r.length===0)throw new Error("No accounts found. Please unlock Trust Wallet.");const t=X[s];return t&&t.chainId&&(yield we(t)),{address:r[0],network:s,walletType:E.TRUST_WALLET}}catch(r){throw r.code===4001?new Error("User rejected the connection request"):new Error(`Failed to connect Trust Wallet: ${r.message}`)}}),Ye=()=>P(this,null,function*(){if(typeof window=="undefined"||!window.algorand||!window.algorand.isLute)throw new Error("Lute wallet is not installed. Please install Lute wallet extension.");try{const s=yield window.algorand.connect();if(!s||s.length===0)throw new Error("No accounts found. Please unlock Lute wallet.");return{address:s[0],network:N.ALGORAND,walletType:E.LUTE}}catch(s){throw new Error(`Failed to connect Lute wallet: ${s.message}`)}}),we=s=>P(this,null,function*(){if(typeof window=="undefined"||!window.ethereum)throw new Error("Ethereum provider not found");try{yield window.ethereum.request({method:"wallet_switchEthereumChain",params:[{chainId:s.chainId}]})}catch(r){if(r.code===4902)try{yield window.ethereum.request({method:"wallet_addEthereumChain",params:[s]})}catch(t){throw new Error(`Failed to add ${s.chainName} to wallet: ${t.message}`)}else throw r.code===4001?new Error("User rejected network switch request"):new Error(`Failed to switch to ${s.chainName}: ${r.message}`)}}),pe=(s,r)=>P(this,null,function*(){const{walletType:t,network:l,address:d}=s,{to:u,amount:v,tokenAddress:y,tokenDecimals:e}=r;switch(t){case E.METAMASK:case E.TRUST_WALLET:return yield Xe(d,u,v,y,e);case E.TRONLINK:return yield Ze(u,v,y,e);case E.LUTE:return yield et(d,u,v);default:throw new Error(`Unsupported wallet type: ${t}`)}}),Xe=(s,r,t,l,d)=>P(this,null,function*(){if(typeof window=="undefined"||!window.ethereum)throw new Error("Ethereum provider not found");try{const u=yield H(),v=new u(window.ethereum),y=v.utils.toBN(Math.floor(parseFloat(t)*Math.pow(10,d||18)));if(l&&l!=="native"){const e=[{constant:!1,inputs:[{name:"_to",type:"address"},{name:"_value",type:"uint256"}],name:"transfer",outputs:[{name:"",type:"bool"}],payable:!1,stateMutability:"nonpayable",type:"function"}];return(yield new v.eth.Contract(e,l).methods.transfer(r,y).send({from:s})).transactionHash}else return(yield v.eth.sendTransaction({from:s,to:r,value:y})).transactionHash}catch(u){throw u.code===4001?new Error("Transaction was rejected by user"):new Error(`Transaction failed: ${u.message}`)}}),Ze=(s,r,t,l)=>P(this,null,function*(){if(typeof window=="undefined"||!window.tronWeb||!window.tronWeb.ready)throw new Error("TronLink is not ready");try{const d=Math.floor(parseFloat(r)*Math.pow(10,l||6));return t&&t!=="native"?yield(yield window.tronWeb.contract().at(t)).transfer(s,d).send({feeLimit:1e8,callValue:0}):(yield window.tronWeb.trx.sendTransaction(s,d)).txid}catch(d){throw new Error(`TRON transaction failed: ${d.message}`)}}),et=(s,r,t)=>P(this,null,function*(){if(typeof window=="undefined"||!window.algorand)throw new Error("Algorand wallet is not available");try{const l=Math.floor(parseFloat(t)*1e6),d={from:s,to:r,amount:l,type:"pay"},u=yield window.algorand.signTransaction(d);return(yield window.algorand.sendTransaction(u)).txId}catch(l){throw new Error(`Algorand transaction failed: ${l.message}`)}}),xe=s=>({[E.METAMASK]:"https://metamask.io/",[E.TRONLINK]:"https://www.tronlink.org/",[E.TRUST_WALLET]:"https://trustwallet.com/",[E.LUTE]:"https://lute.app/"})[s]||"";let D={apiKey:null,apiSecret:null,apiUrl:"http://localhost:9000",merchantWalletAddresses:{}};const tt=s=>{D=q(q({},D),s),console.log("API initialized with:",{apiUrl:D.apiUrl,apiKey:D.apiKey?`${D.apiKey.substring(0,6)}...`:null,hasWalletAddresses:Object.keys(D.merchantWalletAddresses||{}).length>0})},Z=()=>({"Content-Type":"application/json","x-api-key":D.apiKey,"x-api-secret":D.apiSecret}),ye=s=>P(this,null,function*(){try{console.log("Creating payment with data:",s),console.log("API URL:",`${D.apiUrl}/api/payments/create`);const r=Ke(q({},s),{merchantWalletAddresses:q(q({},D.merchantWalletAddresses),s.merchantWalletAddresses)}),t=yield fetch(`${D.apiUrl}/api/payments/create`,{method:"POST",headers:Z(),body:JSON.stringify(r)});if(console.log("Create payment response status:",t.status),!t.ok){const d=yield t.json();throw console.error("Error creating payment:",d),new Error(d.error||`Failed to create payment: ${t.status}`)}const l=yield t.json();return console.log("Create payment response data:",l),l}catch(r){throw console.error("Create payment error:",r),r}}),rt=s=>P(this,null,function*(){try{console.log("Getting payment:",s);const r=yield fetch(`${D.apiUrl}/api/payments/${s}`,{method:"GET",headers:Z()});if(!r.ok){const l=yield r.json();throw console.error("Error getting payment:",l),new Error(l.error||`Failed to get payment: ${r.status}`)}const t=yield r.json();return console.log("Get payment response:",t),t}catch(r){throw console.error("Get payment error:",r),r}}),be=s=>P(this,null,function*(){try{console.log("Processing payment with data:",s),console.log("API URL:",`${D.apiUrl}/api/payments/process`);const r=yield fetch(`${D.apiUrl}/api/payments/process`,{method:"POST",headers:Z(),body:JSON.stringify(s)});if(console.log("Process payment response status:",r.status),!r.ok){const l=yield r.json();throw console.error("Error processing payment:",l),new Error(l.error||`Failed to process payment: ${r.status}`)}const t=yield r.json();return console.log("Process payment response data:",t),t}catch(r){throw console.error("Process payment error:",r),r}}),st=()=>P(this,null,function*(){try{const s=yield fetch(`${D.apiUrl}/api/networks`,{method:"GET",headers:Z()});if(!s.ok){const t=yield s.json();throw new Error(t.error||`Failed to get networks: ${s.status}`)}return yield s.json()}catch(s){throw console.error("Get supported networks error:",s),s}}),nt=()=>P(this,null,function*(){try{const s=yield fetch(`${D.apiUrl}/api/merchants/profile`,{method:"GET",headers:Z()});if(!s.ok){const t=yield s.json();throw new Error(t.error||`Failed to get merchant profile: ${s.status}`)}const r=yield s.json();return r.merchant&&r.merchant.walletAddresses&&(D.merchantWalletAddresses=q(q({},D.merchantWalletAddresses),r.merchant.walletAddresses)),r}catch(s){throw console.error("Get merchant profile error:",s),s}}),ot=(s,r)=>P(this,null,function*(){try{const t=yield fetch(`${D.apiUrl}/api/wallets/validate`,{method:"POST",headers:Z(),body:JSON.stringify({address:s,network:r})});if(!t.ok){const d=yield t.json();throw new Error(d.error||`Failed to validate address: ${t.status}`)}return yield t.json()}catch(t){throw console.error("Validate wallet address error:",t),t}}),at=(s="ethereum")=>{const t={ethereum:"0x",bsc:"0x",tron:"",algorand:""}[s]||"0x",l=Array.from({length:64},()=>Math.floor(Math.random()*16).toString(16)).join("");return`${t}${l}`};var Ne={exports:{}},ne={};/**
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
*
|
7
|
-
* This source code is licensed under the MIT license found in the
|
8
|
-
* LICENSE file in the root directory of this source tree.
|
9
|
-
*/var it=f,lt=Symbol.for("react.element"),ct=Symbol.for("react.fragment"),dt=Object.prototype.hasOwnProperty,ut=it.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,ht={key:!0,ref:!0,__self:!0,__source:!0};function Ee(s,r,t){var l,d={},u=null,v=null;t!==void 0&&(u=""+t),r.key!==void 0&&(u=""+r.key),r.ref!==void 0&&(v=r.ref);for(l in r)dt.call(r,l)&&!ht.hasOwnProperty(l)&&(d[l]=r[l]);if(s&&s.defaultProps)for(l in r=s.defaultProps,r)d[l]===void 0&&(d[l]=r[l]);return{$$typeof:lt,type:s,key:u,ref:v,props:d,_owner:ut.current}}ne.Fragment=ct,ne.jsx=Ee,ne.jsxs=Ee,Ne.exports=ne;var n=Ne.exports;const ve=f.createContext(),mt=()=>f.useContext(ve),ft=({initialTheme:s="light",children:r})=>{const[t,l]=f.useState(s),d=()=>{l(u=>u==="light"?"dark":"light")};return f.useEffect(()=>{document.documentElement.classList.remove("light","dark"),document.documentElement.classList.add(t)},[t]),n.jsx(ve.Provider,{value:{theme:t,setTheme:l,toggleTheme:d},children:r})},Te=f.createContext(),ke=()=>f.useContext(Te),gt=({apiKey:s,apiSecret:r,apiUrl:t="http://localhost:9000",merchantWalletAddress:l=null,merchantSolWalletAddress:d=null,debug:u=!1,children:v})=>{const[y,e]=f.useState(!1),[o,a]=f.useState(null),[i,c]=f.useState(null);f.useEffect(()=>{if(!s||!r){a("API key and secret are required");return}try{tt({apiKey:s,apiSecret:r,apiUrl:t,merchantWalletAddress:l,merchantSolWalletAddress:d}),e(!0),u&&console.log("Coinley SDK initialized with:",{apiKey:s,apiUrl:t,merchantWalletAddress:l?`${l.substring(0,6)}...${l.substring(l.length-4)}`:"Not provided",merchantSolWalletAddress:d?`${d.substring(0,6)}...${d.substring(d.length-4)}`:"Not provided"})}catch(m){a(m.message),u&&console.error("Coinley SDK initialization error:",m)}},[s,r,t,l,d,u]);const h={apiKey:s,apiSecret:r,apiUrl:t,merchantWalletAddress:l,merchantSolWalletAddress:d,isInitialized:y,error:o,debug:u,paymentData:i,storePaymentData:m=>(c(m),m)};return n.jsx(Te.Provider,{value:h,children:v})};var wt=Object.defineProperty,oe=Object.getOwnPropertySymbols,Ae=Object.prototype.hasOwnProperty,Ce=Object.prototype.propertyIsEnumerable,je=(s,r,t)=>r in s?wt(s,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[r]=t,de=(s,r)=>{for(var t in r||(r={}))Ae.call(r,t)&&je(s,t,r[t]);if(oe)for(var t of oe(r))Ce.call(r,t)&&je(s,t,r[t]);return s},ue=(s,r)=>{var t={};for(var l in s)Ae.call(s,l)&&r.indexOf(l)<0&&(t[l]=s[l]);if(s!=null&&oe)for(var l of oe(s))r.indexOf(l)<0&&Ce.call(s,l)&&(t[l]=s[l]);return t};/**
|
10
|
-
* @license QR Code generator library (TypeScript)
|
11
|
-
* Copyright (c) Project Nayuki.
|
12
|
-
* SPDX-License-Identifier: MIT
|
13
|
-
*/var J;(s=>{const r=class T{constructor(e,o,a,i){if(this.version=e,this.errorCorrectionLevel=o,this.modules=[],this.isFunction=[],e<T.MIN_VERSION||e>T.MAX_VERSION)throw new RangeError("Version value out of range");if(i<-1||i>7)throw new RangeError("Mask value out of range");this.size=e*4+17;let c=[];for(let h=0;h<this.size;h++)c.push(!1);for(let h=0;h<this.size;h++)this.modules.push(c.slice()),this.isFunction.push(c.slice());this.drawFunctionPatterns();const g=this.addEccAndInterleave(a);if(this.drawCodewords(g),i==-1){let h=1e9;for(let m=0;m<8;m++){this.applyMask(m),this.drawFormatBits(m);const w=this.getPenaltyScore();w<h&&(i=m,h=w),this.applyMask(m)}}d(0<=i&&i<=7),this.mask=i,this.applyMask(i),this.drawFormatBits(i),this.isFunction=[]}static encodeText(e,o){const a=s.QrSegment.makeSegments(e);return T.encodeSegments(a,o)}static encodeBinary(e,o){const a=s.QrSegment.makeBytes(e);return T.encodeSegments([a],o)}static encodeSegments(e,o,a=1,i=40,c=-1,g=!0){if(!(T.MIN_VERSION<=a&&a<=i&&i<=T.MAX_VERSION)||c<-1||c>7)throw new RangeError("Invalid value");let h,m;for(h=a;;h++){const x=T.getNumDataCodewords(h,o)*8,C=v.getTotalBits(e,h);if(C<=x){m=C;break}if(h>=i)throw new RangeError("Data too long")}for(const x of[T.Ecc.MEDIUM,T.Ecc.QUARTILE,T.Ecc.HIGH])g&&m<=T.getNumDataCodewords(h,x)*8&&(o=x);let w=[];for(const x of e){t(x.mode.modeBits,4,w),t(x.numChars,x.mode.numCharCountBits(h),w);for(const C of x.getData())w.push(C)}d(w.length==m);const A=T.getNumDataCodewords(h,o)*8;d(w.length<=A),t(0,Math.min(4,A-w.length),w),t(0,(8-w.length%8)%8,w),d(w.length%8==0);for(let x=236;w.length<A;x^=253)t(x,8,w);let p=[];for(;p.length*8<w.length;)p.push(0);return w.forEach((x,C)=>p[C>>>3]|=x<<7-(C&7)),new T(h,o,p,c)}getModule(e,o){return 0<=e&&e<this.size&&0<=o&&o<this.size&&this.modules[o][e]}getModules(){return this.modules}drawFunctionPatterns(){for(let a=0;a<this.size;a++)this.setFunctionModule(6,a,a%2==0),this.setFunctionModule(a,6,a%2==0);this.drawFinderPattern(3,3),this.drawFinderPattern(this.size-4,3),this.drawFinderPattern(3,this.size-4);const e=this.getAlignmentPatternPositions(),o=e.length;for(let a=0;a<o;a++)for(let i=0;i<o;i++)a==0&&i==0||a==0&&i==o-1||a==o-1&&i==0||this.drawAlignmentPattern(e[a],e[i]);this.drawFormatBits(0),this.drawVersion()}drawFormatBits(e){const o=this.errorCorrectionLevel.formatBits<<3|e;let a=o;for(let c=0;c<10;c++)a=a<<1^(a>>>9)*1335;const i=(o<<10|a)^21522;d(i>>>15==0);for(let c=0;c<=5;c++)this.setFunctionModule(8,c,l(i,c));this.setFunctionModule(8,7,l(i,6)),this.setFunctionModule(8,8,l(i,7)),this.setFunctionModule(7,8,l(i,8));for(let c=9;c<15;c++)this.setFunctionModule(14-c,8,l(i,c));for(let c=0;c<8;c++)this.setFunctionModule(this.size-1-c,8,l(i,c));for(let c=8;c<15;c++)this.setFunctionModule(8,this.size-15+c,l(i,c));this.setFunctionModule(8,this.size-8,!0)}drawVersion(){if(this.version<7)return;let e=this.version;for(let a=0;a<12;a++)e=e<<1^(e>>>11)*7973;const o=this.version<<12|e;d(o>>>18==0);for(let a=0;a<18;a++){const i=l(o,a),c=this.size-11+a%3,g=Math.floor(a/3);this.setFunctionModule(c,g,i),this.setFunctionModule(g,c,i)}}drawFinderPattern(e,o){for(let a=-4;a<=4;a++)for(let i=-4;i<=4;i++){const c=Math.max(Math.abs(i),Math.abs(a)),g=e+i,h=o+a;0<=g&&g<this.size&&0<=h&&h<this.size&&this.setFunctionModule(g,h,c!=2&&c!=4)}}drawAlignmentPattern(e,o){for(let a=-2;a<=2;a++)for(let i=-2;i<=2;i++)this.setFunctionModule(e+i,o+a,Math.max(Math.abs(i),Math.abs(a))!=1)}setFunctionModule(e,o,a){this.modules[o][e]=a,this.isFunction[o][e]=!0}addEccAndInterleave(e){const o=this.version,a=this.errorCorrectionLevel;if(e.length!=T.getNumDataCodewords(o,a))throw new RangeError("Invalid argument");const i=T.NUM_ERROR_CORRECTION_BLOCKS[a.ordinal][o],c=T.ECC_CODEWORDS_PER_BLOCK[a.ordinal][o],g=Math.floor(T.getNumRawDataModules(o)/8),h=i-g%i,m=Math.floor(g/i);let w=[];const A=T.reedSolomonComputeDivisor(c);for(let x=0,C=0;x<i;x++){let S=e.slice(C,C+m-c+(x<h?0:1));C+=S.length;const V=T.reedSolomonComputeRemainder(S,A);x<h&&S.push(0),w.push(S.concat(V))}let p=[];for(let x=0;x<w[0].length;x++)w.forEach((C,S)=>{(x!=m-c||S>=h)&&p.push(C[x])});return d(p.length==g),p}drawCodewords(e){if(e.length!=Math.floor(T.getNumRawDataModules(this.version)/8))throw new RangeError("Invalid argument");let o=0;for(let a=this.size-1;a>=1;a-=2){a==6&&(a=5);for(let i=0;i<this.size;i++)for(let c=0;c<2;c++){const g=a-c,m=(a+1&2)==0?this.size-1-i:i;!this.isFunction[m][g]&&o<e.length*8&&(this.modules[m][g]=l(e[o>>>3],7-(o&7)),o++)}}d(o==e.length*8)}applyMask(e){if(e<0||e>7)throw new RangeError("Mask value out of range");for(let o=0;o<this.size;o++)for(let a=0;a<this.size;a++){let i;switch(e){case 0:i=(a+o)%2==0;break;case 1:i=o%2==0;break;case 2:i=a%3==0;break;case 3:i=(a+o)%3==0;break;case 4:i=(Math.floor(a/3)+Math.floor(o/2))%2==0;break;case 5:i=a*o%2+a*o%3==0;break;case 6:i=(a*o%2+a*o%3)%2==0;break;case 7:i=((a+o)%2+a*o%3)%2==0;break;default:throw new Error("Unreachable")}!this.isFunction[o][a]&&i&&(this.modules[o][a]=!this.modules[o][a])}}getPenaltyScore(){let e=0;for(let c=0;c<this.size;c++){let g=!1,h=0,m=[0,0,0,0,0,0,0];for(let w=0;w<this.size;w++)this.modules[c][w]==g?(h++,h==5?e+=T.PENALTY_N1:h>5&&e++):(this.finderPenaltyAddHistory(h,m),g||(e+=this.finderPenaltyCountPatterns(m)*T.PENALTY_N3),g=this.modules[c][w],h=1);e+=this.finderPenaltyTerminateAndCount(g,h,m)*T.PENALTY_N3}for(let c=0;c<this.size;c++){let g=!1,h=0,m=[0,0,0,0,0,0,0];for(let w=0;w<this.size;w++)this.modules[w][c]==g?(h++,h==5?e+=T.PENALTY_N1:h>5&&e++):(this.finderPenaltyAddHistory(h,m),g||(e+=this.finderPenaltyCountPatterns(m)*T.PENALTY_N3),g=this.modules[w][c],h=1);e+=this.finderPenaltyTerminateAndCount(g,h,m)*T.PENALTY_N3}for(let c=0;c<this.size-1;c++)for(let g=0;g<this.size-1;g++){const h=this.modules[c][g];h==this.modules[c][g+1]&&h==this.modules[c+1][g]&&h==this.modules[c+1][g+1]&&(e+=T.PENALTY_N2)}let o=0;for(const c of this.modules)o=c.reduce((g,h)=>g+(h?1:0),o);const a=this.size*this.size,i=Math.ceil(Math.abs(o*20-a*10)/a)-1;return d(0<=i&&i<=9),e+=i*T.PENALTY_N4,d(0<=e&&e<=2568888),e}getAlignmentPatternPositions(){if(this.version==1)return[];{const e=Math.floor(this.version/7)+2,o=this.version==32?26:Math.ceil((this.version*4+4)/(e*2-2))*2;let a=[6];for(let i=this.size-7;a.length<e;i-=o)a.splice(1,0,i);return a}}static getNumRawDataModules(e){if(e<T.MIN_VERSION||e>T.MAX_VERSION)throw new RangeError("Version number out of range");let o=(16*e+128)*e+64;if(e>=2){const a=Math.floor(e/7)+2;o-=(25*a-10)*a-55,e>=7&&(o-=36)}return d(208<=o&&o<=29648),o}static getNumDataCodewords(e,o){return Math.floor(T.getNumRawDataModules(e)/8)-T.ECC_CODEWORDS_PER_BLOCK[o.ordinal][e]*T.NUM_ERROR_CORRECTION_BLOCKS[o.ordinal][e]}static reedSolomonComputeDivisor(e){if(e<1||e>255)throw new RangeError("Degree out of range");let o=[];for(let i=0;i<e-1;i++)o.push(0);o.push(1);let a=1;for(let i=0;i<e;i++){for(let c=0;c<o.length;c++)o[c]=T.reedSolomonMultiply(o[c],a),c+1<o.length&&(o[c]^=o[c+1]);a=T.reedSolomonMultiply(a,2)}return o}static reedSolomonComputeRemainder(e,o){let a=o.map(i=>0);for(const i of e){const c=i^a.shift();a.push(0),o.forEach((g,h)=>a[h]^=T.reedSolomonMultiply(g,c))}return a}static reedSolomonMultiply(e,o){if(e>>>8||o>>>8)throw new RangeError("Byte out of range");let a=0;for(let i=7;i>=0;i--)a=a<<1^(a>>>7)*285,a^=(o>>>i&1)*e;return d(a>>>8==0),a}finderPenaltyCountPatterns(e){const o=e[1];d(o<=this.size*3);const a=o>0&&e[2]==o&&e[3]==o*3&&e[4]==o&&e[5]==o;return(a&&e[0]>=o*4&&e[6]>=o?1:0)+(a&&e[6]>=o*4&&e[0]>=o?1:0)}finderPenaltyTerminateAndCount(e,o,a){return e&&(this.finderPenaltyAddHistory(o,a),o=0),o+=this.size,this.finderPenaltyAddHistory(o,a),this.finderPenaltyCountPatterns(a)}finderPenaltyAddHistory(e,o){o[0]==0&&(e+=this.size),o.pop(),o.unshift(e)}};r.MIN_VERSION=1,r.MAX_VERSION=40,r.PENALTY_N1=3,r.PENALTY_N2=3,r.PENALTY_N3=40,r.PENALTY_N4=10,r.ECC_CODEWORDS_PER_BLOCK=[[-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],[-1,10,16,26,18,24,16,18,22,22,26,30,22,22,24,24,28,28,26,26,26,26,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28],[-1,13,22,18,26,18,24,18,22,20,24,28,26,24,20,30,24,28,28,26,30,28,30,30,30,30,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-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]],r.NUM_ERROR_CORRECTION_BLOCKS=[[-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],[-1,1,1,1,2,2,4,4,4,5,5,5,8,9,9,10,10,11,13,14,16,17,17,18,20,21,23,25,26,28,29,31,33,35,37,38,40,43,45,47,49],[-1,1,1,2,2,4,4,6,6,8,8,8,10,12,16,12,17,16,18,21,20,23,23,25,27,29,34,34,35,38,40,43,45,48,51,53,56,59,62,65,68],[-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]],s.QrCode=r;function t(y,e,o){if(e<0||e>31||y>>>e)throw new RangeError("Value out of range");for(let a=e-1;a>=0;a--)o.push(y>>>a&1)}function l(y,e){return(y>>>e&1)!=0}function d(y){if(!y)throw new Error("Assertion error")}const u=class M{constructor(e,o,a){if(this.mode=e,this.numChars=o,this.bitData=a,o<0)throw new RangeError("Invalid argument");this.bitData=a.slice()}static makeBytes(e){let o=[];for(const a of e)t(a,8,o);return new M(M.Mode.BYTE,e.length,o)}static makeNumeric(e){if(!M.isNumeric(e))throw new RangeError("String contains non-numeric characters");let o=[];for(let a=0;a<e.length;){const i=Math.min(e.length-a,3);t(parseInt(e.substring(a,a+i),10),i*3+1,o),a+=i}return new M(M.Mode.NUMERIC,e.length,o)}static makeAlphanumeric(e){if(!M.isAlphanumeric(e))throw new RangeError("String contains unencodable characters in alphanumeric mode");let o=[],a;for(a=0;a+2<=e.length;a+=2){let i=M.ALPHANUMERIC_CHARSET.indexOf(e.charAt(a))*45;i+=M.ALPHANUMERIC_CHARSET.indexOf(e.charAt(a+1)),t(i,11,o)}return a<e.length&&t(M.ALPHANUMERIC_CHARSET.indexOf(e.charAt(a)),6,o),new M(M.Mode.ALPHANUMERIC,e.length,o)}static makeSegments(e){return e==""?[]:M.isNumeric(e)?[M.makeNumeric(e)]:M.isAlphanumeric(e)?[M.makeAlphanumeric(e)]:[M.makeBytes(M.toUtf8ByteArray(e))]}static makeEci(e){let o=[];if(e<0)throw new RangeError("ECI assignment value out of range");if(e<128)t(e,8,o);else if(e<16384)t(2,2,o),t(e,14,o);else if(e<1e6)t(6,3,o),t(e,21,o);else throw new RangeError("ECI assignment value out of range");return new M(M.Mode.ECI,0,o)}static isNumeric(e){return M.NUMERIC_REGEX.test(e)}static isAlphanumeric(e){return M.ALPHANUMERIC_REGEX.test(e)}getData(){return this.bitData.slice()}static getTotalBits(e,o){let a=0;for(const i of e){const c=i.mode.numCharCountBits(o);if(i.numChars>=1<<c)return 1/0;a+=4+c+i.bitData.length}return a}static toUtf8ByteArray(e){e=encodeURI(e);let o=[];for(let a=0;a<e.length;a++)e.charAt(a)!="%"?o.push(e.charCodeAt(a)):(o.push(parseInt(e.substring(a+1,a+3),16)),a+=2);return o}};u.NUMERIC_REGEX=/^[0-9]*$/,u.ALPHANUMERIC_REGEX=/^[A-Z0-9 $%*+.\/:-]*$/,u.ALPHANUMERIC_CHARSET="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:";let v=u;s.QrSegment=u})(J||(J={})),(s=>{(r=>{const t=class{constructor(d,u){this.ordinal=d,this.formatBits=u}};t.LOW=new t(0,1),t.MEDIUM=new t(1,0),t.QUARTILE=new t(2,3),t.HIGH=new t(3,2),r.Ecc=t})(s.QrCode||(s.QrCode={}))})(J||(J={})),(s=>{(r=>{const t=class{constructor(d,u){this.modeBits=d,this.numBitsCharCount=u}numCharCountBits(d){return this.numBitsCharCount[Math.floor((d+7)/17)]}};t.NUMERIC=new t(1,[10,12,14]),t.ALPHANUMERIC=new t(2,[9,11,13]),t.BYTE=new t(4,[8,16,16]),t.KANJI=new t(8,[8,10,12]),t.ECI=new t(7,[0,0,0]),r.Mode=t})(s.QrSegment||(s.QrSegment={}))})(J||(J={}));var ee=J;/**
|
14
|
-
* @license qrcode.react
|
15
|
-
* Copyright (c) Paul O'Shannessy
|
16
|
-
* SPDX-License-Identifier: ISC
|
17
|
-
*/var pt={L:ee.QrCode.Ecc.LOW,M:ee.QrCode.Ecc.MEDIUM,Q:ee.QrCode.Ecc.QUARTILE,H:ee.QrCode.Ecc.HIGH},Se=128,Me="L",Le="#FFFFFF",Pe="#000000",Re=!1,De=1,xt=4,yt=0,bt=.1;function Ue(s,r=0){const t=[];return s.forEach(function(l,d){let u=null;l.forEach(function(v,y){if(!v&&u!==null){t.push(`M${u+r} ${d+r}h${y-u}v1H${u+r}z`),u=null;return}if(y===l.length-1){if(!v)return;u===null?t.push(`M${y+r},${d+r} h1v1H${y+r}z`):t.push(`M${u+r},${d+r} h${y+1-u}v1H${u+r}z`);return}v&&u===null&&(u=y)})}),t.join("")}function Oe(s,r){return s.slice().map((t,l)=>l<r.y||l>=r.y+r.h?t:t.map((d,u)=>u<r.x||u>=r.x+r.w?d:!1))}function Nt(s,r,t,l){if(l==null)return null;const d=s.length+t*2,u=Math.floor(r*bt),v=d/r,y=(l.width||u)*v,e=(l.height||u)*v,o=l.x==null?s.length/2-y/2:l.x*v,a=l.y==null?s.length/2-e/2:l.y*v,i=l.opacity==null?1:l.opacity;let c=null;if(l.excavate){let h=Math.floor(o),m=Math.floor(a),w=Math.ceil(y+o-h),A=Math.ceil(e+a-m);c={x:h,y:m,w,h:A}}const g=l.crossOrigin;return{x:o,y:a,h:e,w:y,excavation:c,opacity:i,crossOrigin:g}}function Et(s,r){return r!=null?Math.max(Math.floor(r),0):s?xt:yt}function Ie({value:s,level:r,minVersion:t,includeMargin:l,marginSize:d,imageSettings:u,size:v,boostLevel:y}){let e=f.useMemo(()=>{const h=(Array.isArray(s)?s:[s]).reduce((m,w)=>(m.push(...ee.QrSegment.makeSegments(w)),m),[]);return ee.QrCode.encodeSegments(h,pt[r],t,void 0,void 0,y)},[s,r,t,y]);const{cells:o,margin:a,numCells:i,calculatedImageSettings:c}=f.useMemo(()=>{let g=e.getModules();const h=Et(l,d),m=g.length+h*2,w=Nt(g,v,h,u);return{cells:g,margin:h,numCells:m,calculatedImageSettings:w}},[e,v,u,l,d]);return{qrcode:e,margin:a,cells:o,numCells:i,calculatedImageSettings:c}}var vt=function(){try{new Path2D().addPath(new Path2D)}catch(s){return!1}return!0}(),Tt=f.forwardRef(function(r,t){const l=r,{value:d,size:u=Se,level:v=Me,bgColor:y=Le,fgColor:e=Pe,includeMargin:o=Re,minVersion:a=De,boostLevel:i,marginSize:c,imageSettings:g}=l,m=ue(l,["value","size","level","bgColor","fgColor","includeMargin","minVersion","boostLevel","marginSize","imageSettings"]),{style:w}=m,A=ue(m,["style"]),p=g==null?void 0:g.src,x=f.useRef(null),C=f.useRef(null),S=f.useCallback(Q=>{x.current=Q,typeof t=="function"?t(Q):t&&(t.current=Q)},[t]),[V,_]=f.useState(!1),{margin:O,cells:L,numCells:k,calculatedImageSettings:R}=Ie({value:d,level:v,minVersion:a,boostLevel:i,includeMargin:o,marginSize:c,imageSettings:g,size:u});f.useEffect(()=>{if(x.current!=null){const Q=x.current,I=Q.getContext("2d");if(!I)return;let te=L;const Y=C.current,le=R!=null&&Y!==null&&Y.complete&&Y.naturalHeight!==0&&Y.naturalWidth!==0;le&&R.excavation!=null&&(te=Oe(L,R.excavation));const re=window.devicePixelRatio||1;Q.height=Q.width=u*re;const $=u/k*re;I.scale($,$),I.fillStyle=y,I.fillRect(0,0,k,k),I.fillStyle=e,vt?I.fill(new Path2D(Ue(te,O))):L.forEach(function(he,ce){he.forEach(function(me,U){me&&I.fillRect(U+O,ce+O,1,1)})}),R&&(I.globalAlpha=R.opacity),le&&I.drawImage(Y,R.x+O,R.y+O,R.w,R.h)}}),f.useEffect(()=>{_(!1)},[p]);const B=de({height:u,width:u},w);let ie=null;return p!=null&&(ie=f.createElement("img",{src:p,key:p,style:{display:"none"},onLoad:()=>{_(!0)},ref:C,crossOrigin:R==null?void 0:R.crossOrigin})),f.createElement(f.Fragment,null,f.createElement("canvas",de({style:B,height:u,width:u,ref:S,role:"img"},A)),ie)});Tt.displayName="QRCodeCanvas";var Fe=f.forwardRef(function(r,t){const l=r,{value:d,size:u=Se,level:v=Me,bgColor:y=Le,fgColor:e=Pe,includeMargin:o=Re,minVersion:a=De,boostLevel:i,title:c,marginSize:g,imageSettings:h}=l,m=ue(l,["value","size","level","bgColor","fgColor","includeMargin","minVersion","boostLevel","title","marginSize","imageSettings"]),{margin:w,cells:A,numCells:p,calculatedImageSettings:x}=Ie({value:d,level:v,minVersion:a,boostLevel:i,includeMargin:o,marginSize:g,imageSettings:h,size:u});let C=A,S=null;h!=null&&x!=null&&(x.excavation!=null&&(C=Oe(A,x.excavation)),S=f.createElement("image",{href:h.src,height:x.h,width:x.w,x:x.x+w,y:x.y+w,preserveAspectRatio:"none",opacity:x.opacity,crossOrigin:x.crossOrigin}));const V=Ue(C,w);return f.createElement("svg",de({height:u,width:u,viewBox:`0 0 ${p} ${p}`,ref:t,role:"img"},m),!!c&&f.createElement("title",null,c),f.createElement("path",{fill:y,d:`M0,0 h${p}v${p}H0z`,shapeRendering:"crispEdges"}),f.createElement("path",{fill:e,d:V,shapeRendering:"crispEdges"}),S)});Fe.displayName="QRCodeSVG";const We=({walletAddress:s,amount:r,currency:t,network:l,theme:d="light",size:u=200})=>{const[v,y]=f.useState(""),[e,o]=f.useState(null);f.useEffect(()=>{if(!s||s==="No address configured"){o("No wallet address configured for this network");return}try{let m;switch(l){case"tron":t==="TRX"?m=`tronlink://transfer?to=${s}&amount=${r}`:m=s;break;case"algorand":m=`algorand://${s}?amount=${Math.floor(parseFloat(r)*1e6)}`;break;case"bsc":if(t==="BNB")m=`ethereum:${s}@56?value=${c(r)}`;else{const w=a(t,"bsc");w?m=`ethereum:${w}/transfer?address=${s}&uint256=${i(r,t)}@56`:m=s}break;case"ethereum":default:if(t==="ETH")m=`ethereum:${s}@1?value=${c(r)}`;else{const w=a(t,"ethereum");w?m=`ethereum:${w}/transfer?address=${s}&uint256=${i(r,t)}`:m=s}break}y(m),o(null)}catch(m){console.error("Error generating QR code:",m),o("Error generating payment QR code")}},[s,r,t,l]);const a=(m,w)=>{var p;return((p={ethereum:{USDT:"0xdAC17F958D2ee523a2206206994597C13D831ec7",USDC:"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"},bsc:{USDT:"0x55d398326f99059fF775485246999027B3197955",USDC:"0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d"},tron:{USDT:"TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t",USDC:"TEkxiTehnzSmSe2XqrBj4w32RUN966rdz8"}}[w])==null?void 0:p[m])||""},i=(m,w)=>{const A=w==="USDT"||w==="USDC"?6:18;return Math.floor(parseFloat(m)*Math.pow(10,A)).toString()},c=m=>Math.floor(parseFloat(m)*1e18).toString(),g=m=>({ethereum:"Ethereum",bsc:"BSC",tron:"Tron",algorand:"Algorand"})[m]||m,h=m=>({ethereum:["MetaMask","Trust Wallet","Coinbase Wallet"],bsc:["MetaMask","Trust Wallet","SafePal"],tron:["TronLink","Trust Wallet"],algorand:["Pera Wallet","MyAlgo Wallet"]})[m]||["MetaMask","Trust Wallet"];return n.jsxs("div",{className:"flex flex-col items-center",children:[e?n.jsxs("div",{className:"p-4 rounded-lg bg-red-100 mb-3 text-red-700 text-center",children:[n.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:n.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"})}),n.jsx("p",{className:"font-medium",children:e})]}):n.jsx("div",{className:"p-4 rounded-lg bg-white mb-3 shadow-sm border",children:v&&n.jsx(Fe,{value:v,size:u,bgColor:d==="dark"?"#374151":"#FFFFFF",fgColor:d==="dark"?"#FFFFFF":"#000000",level:"H",includeMargin:!0})}),n.jsxs("div",{className:"text-center text-sm text-gray-700 mb-4",children:[n.jsxs("p",{className:"font-semibold text-gray-800 flex items-center justify-center",children:[n.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:n.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"})}),"Scan to Pay with ",t]}),n.jsxs("p",{className:"text-xs text-gray-500 mt-1",children:["Scan with your ",g(l)," wallet app"]})]}),n.jsxs("div",{className:"w-full mb-4 p-3 bg-gray-50 rounded-lg",children:[n.jsxs("div",{className:"flex justify-between items-center",children:[n.jsx("span",{className:"text-sm font-medium text-gray-700",children:"Amount to Pay:"}),n.jsxs("span",{className:"text-lg font-bold text-[#7042D2]",children:[r," ",t]})]}),n.jsxs("div",{className:"flex justify-between items-center mt-1",children:[n.jsx("span",{className:"text-xs text-gray-500",children:"Network:"}),n.jsx("span",{className:"text-xs font-medium text-gray-700",children:g(l)})]})]}),!e&&n.jsxs("div",{className:"w-full mb-4",children:[n.jsx("p",{className:"text-xs text-gray-500 mb-1 text-center",children:"Or copy wallet address:"}),n.jsx("div",{className:"text-xs font-mono p-2 rounded bg-gray-100 text-gray-700 break-all text-center select-all cursor-pointer border",onClick:()=>{var m;return(m=navigator.clipboard)==null?void 0:m.writeText(s)},title:"Click to copy",children:s})]}),n.jsx("div",{className:"w-full",children:n.jsxs("div",{className:"p-3 rounded bg-blue-50 border border-blue-200",children:[n.jsxs("h4",{className:"text-sm font-medium mb-2 text-blue-800 flex items-center",children:[n.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:n.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"})}),"Payment Instructions"]}),n.jsxs("ol",{className:"text-xs space-y-1 text-blue-700",children:[n.jsxs("li",{children:["1. Open your crypto wallet app (",h(l).join(", "),")"]}),n.jsx("li",{children:"2. Scan the QR code above or copy the wallet address"}),n.jsxs("li",{children:["3. Send exactly ",n.jsxs("strong",{children:[r," ",t]})," on ",g(l)," network"]}),n.jsx("li",{children:'4. Click "I have sent the payment" button below after sending'})]}),n.jsx("div",{className:"mt-3 p-2 bg-yellow-50 border border-yellow-200 rounded",children:n.jsxs("p",{className:"text-xs text-yellow-800",children:[n.jsx("strong",{children:"Important:"})," Make sure you're sending on the correct network (",g(l),") and using the exact amount shown above."]})})]})})]})},ae=({status:s,message:r,theme:t="light"})=>{const l=()=>{switch(s){case"processing":return n.jsx("div",{className:"animate-spin rounded-full h-12 w-12 border-4 border-t-blue-500 border-blue-500/20"});case"success":return n.jsx("div",{className:"rounded-full h-12 w-12 bg-green-100 flex items-center justify-center",children:n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-8 w-8 text-green-500",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:n.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5 13l4 4L19 7"})})});case"error":return n.jsx("div",{className:"rounded-full h-12 w-12 bg-red-100 flex items-center justify-center",children:n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-8 w-8 text-red-500",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:n.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})})});default:return null}},d=()=>{switch(s){case"processing":return"Processing Payment";case"success":return"Payment Successful";case"error":return"Payment Failed";default:return"Unknown Status"}},u=()=>{switch(s){case"processing":return t==="dark"?"text-blue-300":"text-blue-600";case"success":return t==="dark"?"text-green-300":"text-green-600";case"error":return t==="dark"?"text-red-300":"text-red-600";default:return t==="dark"?"text-gray-300":"text-gray-600"}};return n.jsxs("div",{className:"flex flex-col items-center justify-center py-6",children:[n.jsx("div",{className:"mb-4",children:l()}),n.jsx("h3",{className:`text-xl font-bold mb-2 ${t==="dark"?"text-white":"text-gray-900"}`,children:d()}),n.jsx("p",{className:`text-center ${u()}`,children:r}),s==="processing"&&n.jsx("div",{className:`mt-4 text-xs ${t==="dark"?"text-gray-400":"text-gray-500"}`,children:"This may take a few moments. Please do not close this window."}),s==="success"&&n.jsx("div",{className:`mt-4 p-2 rounded ${t==="dark"?"bg-gray-700":"bg-gray-100"}`,children:n.jsx("p",{className:`text-xs ${t==="dark"?"text-gray-300":"text-gray-600"}`,children:"Your payment has been successfully processed. You will receive a confirmation shortly."})})]})},Be=({onSelect:s,selected:r,theme:t="light",supportedNetworks:l=[]})=>{const[d,u]=f.useState(N.ETHEREUM),[v,y]=f.useState({}),[e,o]=f.useState(!1);f.useEffect(()=>{y(K())},[]);const a=[{id:N.ETHEREUM,name:"Ethereum",description:"ERC-20 tokens"},{id:N.BSC,name:"BSC (Binance Smart Chain)",description:"BEP-20 tokens"},{id:N.TRON,name:"Tron",description:"TRC-20 tokens"},{id:N.ALGORAND,name:"Algorand",description:"ASA tokens"}],i=p=>{const x=[];switch(p){case N.ETHEREUM:x.push({id:"USDT",name:"USDT",description:"Tether USD",logo:"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSj0euZAOXsLTJFQxgiKzlX7z8xbfBk-7kmJA&s",network:N.ETHEREUM},{id:"USDC",name:"USDC",description:"USD Coin",logo:"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ43MuDqq54iD1ZCRL_uthAPkfwSSL-J5qI_Q&s",network:N.ETHEREUM},{id:"ETH",name:"ETH",description:"Ethereum",logo:"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTcyJyRKN0dRJWVZqoLzYgkRHdJsxKGq8nHUw&s",network:N.ETHEREUM});break;case N.BSC:x.push({id:"USDT",name:"USDT",description:"Tether USD",logo:"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSj0euZAOXsLTJFQxgiKzlX7z8xbfBk-7kmJA&s",network:N.BSC},{id:"USDC",name:"USDC",description:"USD Coin",logo:"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ43MuDqq54iD1ZCRL_uthAPkfwSSL-J5qI_Q&s",network:N.BSC},{id:"BNB",name:"BNB",description:"Binance Coin",logo:"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRHSjyW2sSnBhwztCwVW97i1BtV40g7heMMxg&s",network:N.BSC});break;case N.TRON:x.push({id:"USDT",name:"USDT",description:"Tether USD",logo:"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSj0euZAOXsLTJFQxgiKzlX7z8xbfBk-7kmJA&s",network:N.TRON},{id:"USDC",name:"USDC",description:"USD Coin",logo:"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ43MuDqq54iD1ZCRL_uthAPkfwSSL-J5qI_Q&s",network:N.TRON},{id:"TRX",name:"TRX",description:"Tron",logo:"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQKLpLNsGRHbZfCUXAjZLPSp_YFZvX5dMnAoA&s",network:N.TRON});break;case N.ALGORAND:x.push({id:"ALGO",name:"ALGO",description:"Algorand",logo:"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcR0Yx1Vp8qPQI5XZoJuKfQS8bj_FNiMZGCHqA&s",network:N.ALGORAND});break}return x},c=p=>{u(p),o(!1),(r==null?void 0:r.network)!==p&&s(null)},g=p=>{var x;s({currency:p.id,network:d,tokenConfig:(x=se[p.id])==null?void 0:x[d],method:p})},h=i(d),m=e?h:h.slice(0,4);return n.jsxs("div",{children:[n.jsx("h3",{className:`text-lg font-medium mb-4 ${t==="dark"?"text-white":"text-gray-800"}`,children:"Select Payment Method"}),n.jsxs("div",{className:"mb-6",children:[n.jsx("label",{className:`block text-sm font-medium mb-2 ${t==="dark"?"text-white":"text-gray-700"}`,children:"Blockchain Network"}),n.jsx("select",{value:d,onChange:p=>c(p.target.value),className:`w-full p-3 rounded-lg border transition-colors ${t==="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`,children:a.filter(p=>l.length===0||l.includes(p.id)).map(p=>n.jsxs("option",{value:p.id,children:[p.name," - ",p.description]},p.id))})]}),n.jsxs("div",{className:"mb-4",children:[n.jsx("label",{className:`block text-sm font-medium mb-3 ${t==="dark"?"text-white":"text-gray-700"}`,children:"Choose Cryptocurrency"}),n.jsx("div",{className:"grid grid-cols-2 gap-3 mb-4",children:m.map(p=>n.jsx("button",{onClick:()=>g(p),className:`p-4 rounded-lg transition-all duration-200 border-2 ${(r==null?void 0:r.currency)===p.id&&(r==null?void 0:r.network)===d?t==="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":t==="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"}`,children:n.jsxs("div",{className:"flex flex-col items-center text-center",children:[n.jsx("div",{className:"flex-shrink-0 h-10 w-10 bg-white rounded-full flex items-center justify-center mb-2 shadow-sm",children:n.jsx("img",{src:p.logo,alt:p.name,className:"h-6 w-6"})}),n.jsxs("div",{children:[n.jsx("h4",{className:`font-medium text-sm ${t==="dark"?"text-white":"text-gray-900"}`,children:p.name}),n.jsx("p",{className:`text-xs ${t==="dark"?"text-gray-300":"text-gray-500"}`,children:p.description})]}),(r==null?void 0:r.currency)===p.id&&(r==null?void 0:r.network)===d&&n.jsx("div",{className:"mt-2",children:n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-4 w-4 text-[#7042D2]",viewBox:"0 0 20 20",fill:"currentColor",children:n.jsx("path",{fillRule:"evenodd",d:"M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z",clipRule:"evenodd"})})})]})},`${p.id}-${p.network}`))}),h.length>4&&n.jsx("button",{onClick:()=>o(!e),className:`w-full py-2 px-4 rounded-lg text-sm font-medium transition-colors ${t==="dark"?"bg-gray-700 text-gray-300 hover:bg-gray-600":"bg-gray-100 text-gray-600 hover:bg-gray-200"}`,children:e?"Show Less":`Show More (${h.length-4} more)`})]}),n.jsx("div",{className:`p-3 rounded-lg text-sm ${t==="dark"?"bg-gray-800 text-gray-300":"bg-gray-50 text-gray-600"}`,children:n.jsxs("div",{className:"flex items-center",children:[n.jsx("div",{className:`w-2 h-2 rounded-full mr-2 ${v[w(d)]?"bg-green-500":"bg-red-500"}`}),n.jsx("span",{className:"text-xs",children:A(d)})]})})]});function w(p){switch(p){case N.ETHEREUM:case N.BSC:return"metamask";case N.TRON:return"tronlink";case N.ALGORAND:return"lute";default:return"metamask"}}function A(p){const x=w(p),C=v[x],S={metamask:"MetaMask",tronlink:"TronLink",lute:"Lute Wallet"};return C?`${S[x]} detected - Ready to pay`:`${S[x]} required - Please install to continue`}},kt="data:image/png;base64,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",Qe=({isOpen:s,onClose:r,payment:t,paymentStatus:l,selectedPaymentMethod:d,onPaymentMethodSelect:u,onPayment:v,onBack:y,error:e,theme:o="light",merchantName:a,transactionHash:i,walletConnection:c,onConnectWallet:g,testMode:h=!1,supportedNetworks:m=[],availableWallets:w={},supportedWallets:A=[],step:p="select-currency"})=>{const[x,C]=f.useState("wallet"),S=k=>parseFloat(k).toFixed(2),V=k=>k?k.length<=14?k:`${k.slice(0,8)}...${k.slice(-6)}`:"",_=k=>({ethereum:"Ethereum",bsc:"BSC",tron:"Tron",algorand:"Algorand"})[k]||k,O=k=>({[E.METAMASK]:"MetaMask",[E.TRONLINK]:"TronLink",[E.TRUST_WALLET]:"Trust Wallet",[E.LUTE]:"Lute Wallet"})[k]||k,L=k=>({[E.METAMASK]:"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcT3ymr3UNKopfI0NmUY95Dr-0589vG-91KuAA&s",[E.TRONLINK]:"https://www.tronlink.org/images/logo.png",[E.TRUST_WALLET]:"https://trustwallet.com/assets/images/trust_logotype.svg",[E.LUTE]:"https://lute.app/logo.png"})[k]||"";return s?n.jsx("div",{className:"fixed inset-0 z-50 overflow-y-auto bg-black/50",children:n.jsx("div",{className:"flex min-h-screen items-center justify-center p-4",children:n.jsxs("div",{className:"relative p-6 w-full max-w-md mx-auto rounded-lg shadow-xl bg-white text-gray-800",children:[n.jsxs("div",{className:"flex justify-between items-center mb-6 bg-[#F1ECFB] p-3 rounded-xl",children:[n.jsx("div",{className:"flex items-center",children:n.jsx("h2",{className:"text-xl font-bold text-gray-900",children:n.jsx("img",{src:kt,className:"w-32",alt:"Coinley Logo"})})}),n.jsx("button",{onClick:r,className:"text-gray-500 hover:text-gray-700 focus:outline-none",children:n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-6 w-6",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:n.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),n.jsxs("div",{className:"mb-6 bg-[#F1ECFB] p-3 rounded-xl",children:[t&&n.jsxs("div",{className:"mb-6 p-4 rounded-lg",children:[n.jsxs("p",{className:"text-lg text-gray-800 font-semibold",children:["PAY: ",a]}),n.jsxs("div",{className:"flex justify-between items-center mt-2 bg-gray-100 px-3 rounded-lg",children:[n.jsx("span",{className:"font-medium text-gray-700",children:"Amount:"}),n.jsxs("span",{className:"font-bold text-xl text-[#7042D2]",children:["$",S(t.totalAmount||t.amount)]})]}),n.jsx("div",{className:"text-xs mt-1 text-right",children:n.jsxs("span",{className:"text-gray-500",children:["Payment ID: ",t.id?t.id.slice(0,8):"","..."]})})]}),p==="select-currency"&&n.jsxs("div",{children:[n.jsx(Be,{onSelect:u,selected:d,theme:o,supportedNetworks:m}),d&&n.jsx("div",{className:"mt-6",children:n.jsxs("button",{onClick:()=>u(d),className:"w-full py-3 px-4 bg-[#7042D2] hover:bg-[#7042D2] text-white font-medium rounded-lg transition-colors",children:["Proceed with ",d.currency," on ",_(d.network)]})})]}),p==="confirm"&&d&&t&&n.jsxs("div",{children:[n.jsxs("div",{className:"p-4 rounded-lg mb-4 bg-gray-100",children:[n.jsx("h3",{className:"text-lg font-medium mb-2 text-gray-800",children:"Payment Details"}),n.jsxs("div",{className:"space-y-2",children:[n.jsxs("div",{className:"flex justify-between",children:[n.jsx("span",{className:"text-[#7042D2] font-semibold",children:"Currency:"}),n.jsx("span",{className:"font-medium",children:d.currency})]}),n.jsxs("div",{className:"flex justify-between",children:[n.jsx("span",{className:"text-[#7042D2] font-semibold",children:"Network:"}),n.jsx("span",{className:"font-medium",children:_(d.network)})]}),n.jsxs("div",{className:"flex justify-between",children:[n.jsx("span",{className:"text-[#7042D2] font-semibold",children:"Fee:"}),n.jsx("span",{className:"font-medium",children:"1.75%"})]})]})]}),n.jsx("div",{className:"mb-4",children:n.jsxs("div",{className:"flex border-b border-gray-200",children:[n.jsx("button",{onClick:()=>C("wallet"),className:`py-2 px-4 text-sm font-medium ${x==="wallet"?"border-b-2 border-[#7042D2] text-[#7042D2]":"text-gray-500 hover:text-gray-700"}`,children:"Connect Wallet"}),n.jsx("button",{onClick:()=>C("qrcode"),className:`py-2 px-4 text-sm font-medium ${x==="qrcode"?"border-b-2 border-[#7042D2] text-[#7042D2]":"text-gray-500 hover:text-gray-700"}`,children:"QR Code"})]})}),h?n.jsx("div",{className:"p-4 rounded-lg mb-4 bg-blue-50",children:n.jsxs("div",{className:"flex items-center",children:[n.jsx("div",{className:"bg-[#7042D2] rounded-full p-2 mr-3",children:n.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:n.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 10V3L4 14h7v7l9-11h-7z"})})}),n.jsxs("div",{children:[n.jsx("h3",{className:"font-medium text-gray-800",children:"Test Mode Payment"}),n.jsx("p",{className:"text-sm text-gray-600",children:'Click "Pay Now" to simulate a successful payment'})]})]})}):x==="qrcode"?n.jsx("div",{className:"mb-4",children:n.jsx(We,{walletAddress:t.recipientWallet||"No address configured",amount:t.totalAmount||t.amount,currency:d.currency,network:d.network,theme:o})}):n.jsxs("div",{className:"space-y-3 mb-4",children:[A.length===0?n.jsx("div",{className:"p-4 rounded-lg bg-yellow-50",children:n.jsxs("div",{className:"flex items-center",children:[n.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:n.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"})}),n.jsxs("div",{children:[n.jsx("h3",{className:"font-medium text-gray-800",children:"No Compatible Wallets"}),n.jsxs("p",{className:"text-sm text-gray-600",children:["No wallets detected for ",_(d.network)," network"]})]})]})}):A.map(k=>n.jsx("div",{className:"p-4 rounded-lg bg-blue-50",children:n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs("div",{className:"flex items-center",children:[n.jsx("img",{src:L(k),alt:O(k),className:"w-8 h-8 mr-3",onError:R=>{R.target.style.display="none"}}),n.jsxs("div",{children:[n.jsx("h3",{className:"font-medium text-gray-800",children:O(k)}),n.jsxs("p",{className:"text-sm text-gray-600",children:["Pay with ",O(k)]})]})]}),(c==null?void 0:c.walletType)===k?n.jsxs("div",{className:"flex items-center space-x-2",children:[n.jsx("div",{className:"w-2 h-2 bg-green-500 rounded-full"}),n.jsx("span",{className:"text-sm text-green-600",children:"Connected"})]}):n.jsx("button",{onClick:()=>g(k),className:"py-2 px-4 bg-[#7042D2] hover:bg-[#7042D2] text-white font-medium rounded-md text-sm",children:"Connect"})]})},k)),n.jsx("div",{className:"space-y-2",children:Object.entries(w).filter(([k,R])=>!R).map(([k])=>n.jsx("div",{className:"p-3 rounded-lg bg-gray-50",children:n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs("span",{className:"text-sm text-gray-600",children:[O(k)," not detected"]}),n.jsx("a",{href:xe(k),target:"_blank",rel:"noopener noreferrer",className:"text-sm text-[#7042D2] hover:underline",children:"Install"})]})},k))})]}),n.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[n.jsx("button",{type:"button",onClick:y,className:"w-full py-2 px-4 bg-gray-200 hover:bg-gray-300 text-[#7042D2] font-medium rounded-md",children:"Back"}),n.jsx("button",{type:"button",onClick:()=>v(x==="qrcode"),className:"w-full py-2 px-4 bg-[#7042D2] hover:bg-[#7042D2] text-white font-medium rounded-md",disabled:!h&&x==="wallet"&&!c,children:x==="qrcode"?"I have sent the payment":"Pay Now"})]})]}),p==="processing"&&n.jsx(ae,{status:"processing",theme:o,message:"Processing your payment..."}),p==="success"&&n.jsxs("div",{children:[n.jsx(ae,{status:"success",theme:o,message:"Payment successful!"}),i&&n.jsxs("div",{className:"mt-4 p-3 rounded-lg bg-gray-100",children:[n.jsx("p",{className:"text-xs text-gray-600 mb-1",children:"Transaction Hash:"}),n.jsx("p",{className:"text-sm font-mono break-all text-gray-800",children:V(i)}),d&&n.jsx("a",{href:`${At(d.network)}/${Ct(d.network)}/${i}`,target:"_blank",rel:"noopener noreferrer",className:"text-xs text-[#7042D2] mt-2 inline-block",children:"View on Explorer →"})]})]}),p==="error"&&n.jsxs("div",{children:[n.jsx(ae,{status:"error",theme:o,message:e||"An error occurred while processing your payment."}),n.jsx("button",{type:"button",onClick:y,className:"mt-4 w-full py-2 px-4 bg-gray-200 hover:bg-gray-300 text-gray-800 font-medium rounded-md",children:"Try Again"})]})]}),n.jsx("div",{className:"text-center text-xs text-gray-500",children:n.jsxs("p",{children:["Powered by ",n.jsx("span",{className:"text-[#7042D2]",children:"Coinley"})," - Secure Cryptocurrency Payments"]})})]})})}):null},At=s=>({ethereum:"https://etherscan.io",bsc:"https://bscscan.com",tron:"https://tronscan.org",algorand:"https://algoexplorer.io"})[s]||"https://etherscan.io",Ct=s=>({ethereum:"tx",bsc:"tx",tron:"transaction",algorand:"tx"})[s]||"tx",ze=f.forwardRef(({apiKey:s,apiSecret:r,apiUrl:t,customerEmail:l,merchantName:d="Merchant",merchantWalletAddresses:u={},onSuccess:v,onError:y,onClose:e,theme:o,autoOpen:a=!1,debug:i=!1,testMode:c=!1,supportedNetworks:g=[],preferredNetwork:h=N.ETHEREUM,preferredWallet:m=E.METAMASK},w)=>{const A=ke(),{theme:p}=mt(),[x,C]=f.useState(a),[S,V]=f.useState(null),[_,O]=f.useState("idle"),[L,k]=f.useState(null),[R,B]=f.useState(null),[ie,Q]=f.useState(null),[I,te]=f.useState(null),[Y,le]=f.useState({}),[re,$]=f.useState("select-currency");s||(A==null||A.apiKey),r||(A==null||A.apiSecret),t||(A==null||A.apiUrl);const he=o||p,ce=i||(A==null?void 0:A.debug),me=g.length>0?g:[N.ETHEREUM,N.BSC,N.TRON,N.ALGORAND];f.useImperativeHandle(w,()=>({open:j=>{Mt(j)},close:()=>{Ge()},getPayment:()=>S,getWalletConnection:()=>I}));const U=(j,F)=>{ce&&console.log(`[Coinley SDK] ${j}`,F)};f.useEffect(()=>{if(typeof window!="undefined"){const j=K();le(j),U("Available wallets detected:",j)}},[ce]);const Mt=j=>P(this,null,function*(){if(!j||!j.amount){B("Payment amount is required"),y&&y(new Error("Payment amount is required"));return}O("loading"),C(!0),$("select-currency");try{U("Creating payment with details:",j);const F=yield ye({amount:j.amount,currency:j.currency||"USDT",network:j.network||h,customerEmail:j.customerEmail||l,callbackUrl:j.callbackUrl,metadata:j.metadata||{},merchantWalletAddresses:q(q({},u),j.merchantWalletAddresses)});U("Payment created:",F),V(F.payment),O("idle"),B(null),U("Payment created and state updated")}catch(F){U("Error creating payment:",F),B(F.message||"Failed to create payment"),O("error"),y&&y(F)}}),Ge=()=>{C(!1),Q(null),te(null),k(null),$("select-currency"),e&&e()},Lt=j=>{U("Payment method selected:",j),k(j),$("confirm")},Pt=()=>{re==="confirm"&&($("select-currency"),te(null))},Rt=j=>P(this,null,function*(){if(!L){B("Please select a payment method first");return}try{U("Connecting wallet:",{walletType:j,network:L.network});const F=yield ge(j,L.network);te(F),B(null),U("Wallet connected successfully:",F)}catch(F){U("Wallet connection error:",F),B(F.message||"Failed to connect wallet")}}),Dt=()=>P(this,null,function*(){var j,F;if(!S||!L){B("Missing payment information");return}if(!I&&!c){B("Please connect your wallet first");return}U("Starting payment process..."),O("loading"),Q(null);try{let G;if(c)U("Test mode: Generating mock transaction..."),G=`test_${Date.now().toString(16)}_${Math.random().toString(16).substring(2,10)}`;else{const qe=u[L.network];if(!qe)throw new Error(`No merchant wallet address configured for ${L.network}`);U("Sending transaction through wallet..."),G=yield pe(I,{to:qe,amount:S.amount,tokenAddress:(j=L.tokenConfig)==null?void 0:j.address,tokenDecimals:(F=L.tokenConfig)==null?void 0:F.decimals})}U("Transaction hash:",G),Q(G),U("Processing payment with backend...");const Ot=yield be({paymentId:S.id,transactionHash:G,network:L.network,currency:L.currency,senderAddress:I==null?void 0:I.address});U("Payment processed successfully:",Ot),O("success"),$("success"),v&&(U("Calling onSuccess callback..."),v(S.id,G,{network:L.network,currency:L.currency,amount:S.amount}))}catch(G){U("Payment error:",G),B(G.message||"Failed to process payment"),O("error"),$("error"),y&&y(G)}}),Ut=()=>L?fe(L.network):[];return n.jsx(n.Fragment,{children:x&&n.jsx(Qe,{isOpen:x,onClose:Ge,payment:S,paymentStatus:_,selectedPaymentMethod:L,onPaymentMethodSelect:Lt,onPayment:Dt,onBack:Pt,error:R,theme:he,merchantName:d,transactionHash:ie,walletConnection:I,onConnectWallet:Rt,testMode:c,supportedNetworks:me,availableWallets:Y,supportedWallets:Ut(),step:re})})});ze.displayName="CoinleyCheckout";const jt={apiUrl:"http://localhost:9000",debug:!1,testMode:!1,theme:"light",supportedNetworks:["ethereum","bsc","tron","algorand"]},St="0.3.2";b.CoinleyCheckout=ze,b.CoinleyModal=Qe,b.CoinleyProvider=gt,b.DEFAULT_CONFIG=jt,b.NETWORK_CONFIG=X,b.NETWORK_TYPES=N,b.PaymentMethods=Be,b.PaymentStatus=ae,b.QRCode=We,b.TOKEN_CONFIG=se,b.ThemeProvider=ft,b.VERSION=St,b.WALLET_TYPES=E,b.connectWallet=ge,b.createPayment=ye,b.detectWallets=K,b.generateMockTransactionHash=at,b.getMerchantProfile=nt,b.getPayment=rt,b.getSupportedNetworks=st,b.getSupportedWalletsForNetwork=fe,b.getWalletInstallUrl=xe,b.processPayment=be,b.sendTransaction=pe,b.useCoinley=ke,b.validateWalletAddress=ot,Object.defineProperty(b,Symbol.toStringTag,{value:"Module"})});
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).CoinleyCheckout={},e.React)}(this,(function(e,t){"use strict";var r=Object.defineProperty,n=Object.defineProperties,s=Object.getOwnPropertyDescriptors,o=Object.getOwnPropertySymbols,a=Object.prototype.hasOwnProperty,l=Object.prototype.propertyIsEnumerable,i=(e,t,n)=>t in e?r(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,c=(e,t)=>{for(var r in t||(t={}))a.call(t,r)&&i(e,r,t[r]);if(o)for(var r of o(t))l.call(t,r)&&i(e,r,t[r]);return e},d=(e,t,r)=>new Promise(((n,s)=>{var o=e=>{try{l(r.next(e))}catch(t){s(t)}},a=e=>{try{l(r.throw(e))}catch(t){s(t)}},l=e=>e.done?n(e.value):Promise.resolve(e.value).then(o,a);l((r=r.apply(e,t)).next())}));const u={ETHEREUM:"ethereum",BSC:"bsc",TRON:"tron",ALGORAND:"algorand"},h={METAMASK:"metamask",TRONLINK:"tronlink",TRUST_WALLET:"trust_wallet",LUTE:"lute"},m={[u.ETHEREUM]:{chainId:"0x1",chainName:"Ethereum Mainnet",nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18},rpcUrls:["https://mainnet.infura.io/v3/"],blockExplorerUrls:["https://etherscan.io/"],supportedWallets:[h.METAMASK,h.TRUST_WALLET]},[u.BSC]:{chainId:"0x38",chainName:"BNB Smart Chain",nativeCurrency:{name:"BNB",symbol:"BNB",decimals:18},rpcUrls:["https://bsc-dataseed.binance.org/"],blockExplorerUrls:["https://bscscan.com/"],supportedWallets:[h.METAMASK,h.TRUST_WALLET]},[u.TRON]:{fullHost:"https://api.trongrid.io",explorerUrl:"https://tronscan.org",supportedWallets:[h.TRONLINK]},[u.ALGORAND]:{network:"mainnet",explorerUrl:"https://algoexplorer.io",supportedWallets:[h.LUTE]}},g={USDT:{[u.ETHEREUM]:{address:"0xdAC17F958D2ee523a2206206994597C13D831ec7",decimals:6},[u.BSC]:{address:"0x55d398326f99059fF775485246999027B3197955",decimals:18},[u.TRON]:{address:"TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t",decimals:6},[u.ALGORAND]:{address:"312769",decimals:6}},USDC:{[u.ETHEREUM]:{address:"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",decimals:6},[u.BSC]:{address:"0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d",decimals:18},[u.TRON]:{address:"TEkxiTehnzSmSe2XqrBj4w32RUN966rdz8",decimals:6},[u.ALGORAND]:{address:"31566704",decimals:6}},PYUSD:{[u.ETHEREUM]:{address:"0x6c3ea9036406852006290770BEdFcAbA0e23A0e8",decimals:6}},FRAX:{[u.ETHEREUM]:{address:"0x853d955aCEf822Db058eb8505911ED77F175b99e",decimals:18},[u.BSC]:{address:"0x90C97F71E18723b0Cf0dfa30ee176Ab653E89F40",decimals:18}},USDP:{[u.ETHEREUM]:{address:"0x8E870D67F660D95d5be530380D0eC0bd388289E1",decimals:18}},DAI:{[u.ETHEREUM]:{address:"0x6B175474E89094C44Da98b954EedeAC495271d0F",decimals:18}},BUSD:{[u.BSC]:{address:"0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56",decimals:18}},USDJ:{[u.TRON]:{address:"TMwFHYXLJaRUPeW6421aqXL4ZEzPRFGkGT",decimals:18}},ALGO:{[u.ALGORAND]:{address:"native",decimals:6}}};let p=null;const w=()=>d(this,null,(function*(){if(p)return p;try{if("undefined"!=typeof window&&window.Web3)return p=window.Web3,p;const e=yield import("web3");return p=e.default||e.Web3||e,p}catch(e){throw console.error("Failed to load Web3:",e),new Error("Web3 is required for blockchain transactions. Please ensure web3 is installed: npm install web3")}})),f=()=>{const e={[h.METAMASK]:!1,[h.TRUST_WALLET]:!1,[h.TRONLINK]:!1,[h.LUTE]:!1};if("undefined"==typeof window)return e;try{e[h.METAMASK]=!(!window.ethereum||!window.ethereum.isMetaMask),e[h.TRONLINK]=!!window.tronWeb,e[h.TRUST_WALLET]=!(!window.ethereum||!window.ethereum.isTrust),e[h.LUTE]=!(!window.algorand||!window.algorand.isLute)}catch(t){console.warn("Error detecting wallets:",t)}return e},y=e=>{const t=m[e];if(!t)return[];const r=f();return t.supportedWallets.filter((e=>r[e]))},x=(e,t)=>d(this,null,(function*(){switch(e){case h.METAMASK:return yield b(t);case h.TRONLINK:return yield N();case h.TRUST_WALLET:return yield E(t);case h.LUTE:return yield k();default:throw new Error(`Unsupported wallet type: ${e}`)}})),b=e=>d(this,null,(function*(){if("undefined"==typeof window||!window.ethereum||!window.ethereum.isMetaMask)throw new Error("MetaMask is not installed. Please install MetaMask extension.");try{const t=yield window.ethereum.request({method:"eth_requestAccounts"});if(!t||0===t.length)throw new Error("No accounts found. Please unlock MetaMask.");const r=m[e];return r&&r.chainId&&(yield v(r)),{address:t[0],network:e,walletType:h.METAMASK}}catch(t){if(4001===t.code)throw new Error("User rejected the connection request");throw new Error(`Failed to connect MetaMask: ${t.message}`)}})),N=()=>d(this,null,(function*(){var e;if("undefined"==typeof window||!window.tronWeb)throw new Error("TronLink is not installed. Please install TronLink extension.");let t=0;for(;!window.tronWeb.ready&&t<10;)yield new Promise((e=>setTimeout(e,1e3))),t++;if(!window.tronWeb.ready)throw new Error("TronLink is not ready. Please unlock your TronLink wallet and try again.");const r=null==(e=window.tronWeb.defaultAddress)?void 0:e.base58;if(!r)throw new Error("No account found in TronLink. Please make sure you have an account set up.");return{address:r,network:u.TRON,walletType:h.TRONLINK}})),E=e=>d(this,null,(function*(){if("undefined"==typeof window||!window.ethereum||!window.ethereum.isTrust)throw new Error("Trust Wallet is not installed. Please install Trust Wallet extension.");try{const t=yield window.ethereum.request({method:"eth_requestAccounts"});if(!t||0===t.length)throw new Error("No accounts found. Please unlock Trust Wallet.");const r=m[e];return r&&r.chainId&&(yield v(r)),{address:t[0],network:e,walletType:h.TRUST_WALLET}}catch(t){if(4001===t.code)throw new Error("User rejected the connection request");throw new Error(`Failed to connect Trust Wallet: ${t.message}`)}})),k=()=>d(this,null,(function*(){if("undefined"==typeof window||!window.algorand||!window.algorand.isLute)throw new Error("Lute wallet is not installed. Please install Lute wallet extension.");try{const e=yield window.algorand.connect();if(!e||0===e.length)throw new Error("No accounts found. Please unlock Lute wallet.");return{address:e[0],network:u.ALGORAND,walletType:h.LUTE}}catch(e){throw new Error(`Failed to connect Lute wallet: ${e.message}`)}})),v=e=>d(this,null,(function*(){if("undefined"==typeof window||!window.ethereum)throw new Error("Ethereum provider not found");try{yield window.ethereum.request({method:"wallet_switchEthereumChain",params:[{chainId:e.chainId}]})}catch(t){if(4902!==t.code)throw 4001===t.code?new Error("User rejected network switch request"):new Error(`Failed to switch to ${e.chainName}: ${t.message}`);try{yield window.ethereum.request({method:"wallet_addEthereumChain",params:[e]})}catch(r){throw new Error(`Failed to add ${e.chainName} to wallet: ${r.message}`)}}})),A=(e,t)=>d(this,null,(function*(){const{walletType:r,network:n,address:s}=e,{to:o,amount:a,tokenAddress:l,tokenDecimals:i}=t;switch(r){case h.METAMASK:case h.TRUST_WALLET:return yield S(s,o,a,l,i);case h.TRONLINK:return yield T(o,a,l,i);case h.LUTE:return yield C(s,o,a);default:throw new Error(`Unsupported wallet type: ${r}`)}})),S=(e,t,r,n,s)=>d(this,null,(function*(){if("undefined"==typeof window||!window.ethereum)throw new Error("Ethereum provider not found");try{const o=new(yield w())(window.ethereum),a=o.utils.toBN(Math.floor(parseFloat(r)*Math.pow(10,s||18)));if(n&&"native"!==n){const r=[{constant:!1,inputs:[{name:"_to",type:"address"},{name:"_value",type:"uint256"}],name:"transfer",outputs:[{name:"",type:"bool"}],payable:!1,stateMutability:"nonpayable",type:"function"}],s=new o.eth.Contract(r,n);return(yield s.methods.transfer(t,a).send({from:e})).transactionHash}return(yield o.eth.sendTransaction({from:e,to:t,value:a})).transactionHash}catch(o){if(4001===o.code)throw new Error("Transaction was rejected by user");throw new Error(`Transaction failed: ${o.message}`)}})),T=(e,t,r,n)=>d(this,null,(function*(){if("undefined"==typeof window||!window.tronWeb||!window.tronWeb.ready)throw new Error("TronLink is not ready");try{const s=Math.floor(parseFloat(t)*Math.pow(10,n||6));if(r&&"native"!==r){const t=yield window.tronWeb.contract().at(r);return yield t.transfer(e,s).send({feeLimit:1e8,callValue:0})}return(yield window.tronWeb.trx.sendTransaction(e,s)).txid}catch(s){throw new Error(`TRON transaction failed: ${s.message}`)}})),C=(e,t,r)=>d(this,null,(function*(){if("undefined"==typeof window||!window.algorand)throw new Error("Algorand wallet is not available");try{const n=Math.floor(1e6*parseFloat(r)),s={from:e,to:t,amount:n,type:"pay"},o=yield window.algorand.signTransaction(s);return(yield window.algorand.sendTransaction(o)).txId}catch(n){throw new Error(`Algorand transaction failed: ${n.message}`)}})),j=e=>({[h.METAMASK]:"https://metamask.io/",[h.TRONLINK]:"https://www.tronlink.org/",[h.TRUST_WALLET]:"https://trustwallet.com/",[h.LUTE]:"https://lute.app/"}[e]||"");let M={apiKey:null,apiSecret:null,apiUrl:"http://localhost:9000",merchantWalletAddresses:{}};const R=()=>({"Content-Type":"application/json","x-api-key":M.apiKey,"x-api-secret":M.apiSecret}),L=e=>d(this,null,(function*(){try{console.log("Creating payment with data:",e),console.log("API URL:",`${M.apiUrl}/api/payments/create`);const o=(t=c({},e),r={merchantWalletAddresses:c(c({},M.merchantWalletAddresses),e.merchantWalletAddresses)},n(t,s(r))),a=yield fetch(`${M.apiUrl}/api/payments/create`,{method:"POST",headers:R(),body:JSON.stringify(o)});if(console.log("Create payment response status:",a.status),!a.ok){const e=yield a.json();throw console.error("Error creating payment:",e),new Error(e.error||`Failed to create payment: ${a.status}`)}const l=yield a.json();return console.log("Create payment response data:",l),l}catch(o){throw console.error("Create payment error:",o),o}var t,r})),D=e=>d(this,null,(function*(){try{console.log("Processing payment with data:",e),console.log("API URL:",`${M.apiUrl}/api/payments/process`);const t=yield fetch(`${M.apiUrl}/api/payments/process`,{method:"POST",headers:R(),body:JSON.stringify(e)});if(console.log("Process payment response status:",t.status),!t.ok){const e=yield t.json();throw console.error("Error processing payment:",e),new Error(e.error||`Failed to process payment: ${t.status}`)}const r=yield t.json();return console.log("Process payment response data:",r),r}catch(t){throw console.error("Process payment error:",t),t}}));var U={exports:{}},P={},O=t,F=Symbol.for("react.element"),W=Symbol.for("react.fragment"),B=Object.prototype.hasOwnProperty,I=O.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,z={key:!0,ref:!0,__self:!0,__source:!0};function H(e,t,r){var n,s={},o=null,a=null;for(n in void 0!==r&&(o=""+r),void 0!==t.key&&(o=""+t.key),void 0!==t.ref&&(a=t.ref),t)B.call(t,n)&&!z.hasOwnProperty(n)&&(s[n]=t[n]);if(e&&e.defaultProps)for(n in t=e.defaultProps)void 0===s[n]&&(s[n]=t[n]);return{$$typeof:F,type:e,key:o,ref:a,props:s,_owner:I.current}}P.Fragment=W,P.jsx=H,P.jsxs=H,U.exports=P;var Q=U.exports;const q=t.createContext(),G=t.createContext(),K=()=>t.useContext(G);var _,V,J=Object.defineProperty,$=Object.getOwnPropertySymbols,Y=Object.prototype.hasOwnProperty,X=Object.prototype.propertyIsEnumerable,Z=(e,t,r)=>t in e?J(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,ee=(e,t)=>{for(var r in t||(t={}))Y.call(t,r)&&Z(e,r,t[r]);if($)for(var r of $(t))X.call(t,r)&&Z(e,r,t[r]);return e},te=(e,t)=>{var r={};for(var n in e)Y.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(null!=e&&$)for(var n of $(e))t.indexOf(n)<0&&X.call(e,n)&&(r[n]=e[n]);return r};(e=>{const t=class t{constructor(e,r,n,o){if(this.version=e,this.errorCorrectionLevel=r,this.modules=[],this.isFunction=[],e<t.MIN_VERSION||e>t.MAX_VERSION)throw new RangeError("Version value out of range");if(o<-1||o>7)throw new RangeError("Mask value out of range");this.size=4*e+17;let a=[];for(let t=0;t<this.size;t++)a.push(!1);for(let t=0;t<this.size;t++)this.modules.push(a.slice()),this.isFunction.push(a.slice());this.drawFunctionPatterns();const l=this.addEccAndInterleave(n);if(this.drawCodewords(l),-1==o){let e=1e9;for(let t=0;t<8;t++){this.applyMask(t),this.drawFormatBits(t);const r=this.getPenaltyScore();r<e&&(o=t,e=r),this.applyMask(t)}}s(0<=o&&o<=7),this.mask=o,this.applyMask(o),this.drawFormatBits(o),this.isFunction=[]}static encodeText(r,n){const s=e.QrSegment.makeSegments(r);return t.encodeSegments(s,n)}static encodeBinary(r,n){const s=e.QrSegment.makeBytes(r);return t.encodeSegments([s],n)}static encodeSegments(e,n,o=1,l=40,i=-1,c=!0){if(!(t.MIN_VERSION<=o&&o<=l&&l<=t.MAX_VERSION)||i<-1||i>7)throw new RangeError("Invalid value");let d,u;for(d=o;;d++){const r=8*t.getNumDataCodewords(d,n),s=a.getTotalBits(e,d);if(s<=r){u=s;break}if(d>=l)throw new RangeError("Data too long")}for(const r of[t.Ecc.MEDIUM,t.Ecc.QUARTILE,t.Ecc.HIGH])c&&u<=8*t.getNumDataCodewords(d,r)&&(n=r);let h=[];for(const t of e){r(t.mode.modeBits,4,h),r(t.numChars,t.mode.numCharCountBits(d),h);for(const e of t.getData())h.push(e)}s(h.length==u);const m=8*t.getNumDataCodewords(d,n);s(h.length<=m),r(0,Math.min(4,m-h.length),h),r(0,(8-h.length%8)%8,h),s(h.length%8==0);for(let t=236;h.length<m;t^=253)r(t,8,h);let g=[];for(;8*g.length<h.length;)g.push(0);return h.forEach(((e,t)=>g[t>>>3]|=e<<7-(7&t))),new t(d,n,g,i)}getModule(e,t){return 0<=e&&e<this.size&&0<=t&&t<this.size&&this.modules[t][e]}getModules(){return this.modules}drawFunctionPatterns(){for(let r=0;r<this.size;r++)this.setFunctionModule(6,r,r%2==0),this.setFunctionModule(r,6,r%2==0);this.drawFinderPattern(3,3),this.drawFinderPattern(this.size-4,3),this.drawFinderPattern(3,this.size-4);const e=this.getAlignmentPatternPositions(),t=e.length;for(let r=0;r<t;r++)for(let n=0;n<t;n++)0==r&&0==n||0==r&&n==t-1||r==t-1&&0==n||this.drawAlignmentPattern(e[r],e[n]);this.drawFormatBits(0),this.drawVersion()}drawFormatBits(e){const t=this.errorCorrectionLevel.formatBits<<3|e;let r=t;for(let n=0;n<10;n++)r=r<<1^1335*(r>>>9);const o=21522^(t<<10|r);s(o>>>15==0);for(let s=0;s<=5;s++)this.setFunctionModule(8,s,n(o,s));this.setFunctionModule(8,7,n(o,6)),this.setFunctionModule(8,8,n(o,7)),this.setFunctionModule(7,8,n(o,8));for(let s=9;s<15;s++)this.setFunctionModule(14-s,8,n(o,s));for(let s=0;s<8;s++)this.setFunctionModule(this.size-1-s,8,n(o,s));for(let s=8;s<15;s++)this.setFunctionModule(8,this.size-15+s,n(o,s));this.setFunctionModule(8,this.size-8,!0)}drawVersion(){if(this.version<7)return;let e=this.version;for(let r=0;r<12;r++)e=e<<1^7973*(e>>>11);const t=this.version<<12|e;s(t>>>18==0);for(let r=0;r<18;r++){const e=n(t,r),s=this.size-11+r%3,o=Math.floor(r/3);this.setFunctionModule(s,o,e),this.setFunctionModule(o,s,e)}}drawFinderPattern(e,t){for(let r=-4;r<=4;r++)for(let n=-4;n<=4;n++){const s=Math.max(Math.abs(n),Math.abs(r)),o=e+n,a=t+r;0<=o&&o<this.size&&0<=a&&a<this.size&&this.setFunctionModule(o,a,2!=s&&4!=s)}}drawAlignmentPattern(e,t){for(let r=-2;r<=2;r++)for(let n=-2;n<=2;n++)this.setFunctionModule(e+n,t+r,1!=Math.max(Math.abs(n),Math.abs(r)))}setFunctionModule(e,t,r){this.modules[t][e]=r,this.isFunction[t][e]=!0}addEccAndInterleave(e){const r=this.version,n=this.errorCorrectionLevel;if(e.length!=t.getNumDataCodewords(r,n))throw new RangeError("Invalid argument");const o=t.NUM_ERROR_CORRECTION_BLOCKS[n.ordinal][r],a=t.ECC_CODEWORDS_PER_BLOCK[n.ordinal][r],l=Math.floor(t.getNumRawDataModules(r)/8),i=o-l%o,c=Math.floor(l/o);let d=[];const u=t.reedSolomonComputeDivisor(a);for(let s=0,m=0;s<o;s++){let r=e.slice(m,m+c-a+(s<i?0:1));m+=r.length;const n=t.reedSolomonComputeRemainder(r,u);s<i&&r.push(0),d.push(r.concat(n))}let h=[];for(let t=0;t<d[0].length;t++)d.forEach(((e,r)=>{(t!=c-a||r>=i)&&h.push(e[t])}));return s(h.length==l),h}drawCodewords(e){if(e.length!=Math.floor(t.getNumRawDataModules(this.version)/8))throw new RangeError("Invalid argument");let r=0;for(let t=this.size-1;t>=1;t-=2){6==t&&(t=5);for(let s=0;s<this.size;s++)for(let o=0;o<2;o++){const a=t-o,l=!(t+1&2)?this.size-1-s:s;!this.isFunction[l][a]&&r<8*e.length&&(this.modules[l][a]=n(e[r>>>3],7-(7&r)),r++)}}s(r==8*e.length)}applyMask(e){if(e<0||e>7)throw new RangeError("Mask value out of range");for(let t=0;t<this.size;t++)for(let r=0;r<this.size;r++){let n;switch(e){case 0:n=(r+t)%2==0;break;case 1:n=t%2==0;break;case 2:n=r%3==0;break;case 3:n=(r+t)%3==0;break;case 4:n=(Math.floor(r/3)+Math.floor(t/2))%2==0;break;case 5:n=r*t%2+r*t%3==0;break;case 6:n=(r*t%2+r*t%3)%2==0;break;case 7:n=((r+t)%2+r*t%3)%2==0;break;default:throw new Error("Unreachable")}!this.isFunction[t][r]&&n&&(this.modules[t][r]=!this.modules[t][r])}}getPenaltyScore(){let e=0;for(let s=0;s<this.size;s++){let r=!1,n=0,o=[0,0,0,0,0,0,0];for(let a=0;a<this.size;a++)this.modules[s][a]==r?(n++,5==n?e+=t.PENALTY_N1:n>5&&e++):(this.finderPenaltyAddHistory(n,o),r||(e+=this.finderPenaltyCountPatterns(o)*t.PENALTY_N3),r=this.modules[s][a],n=1);e+=this.finderPenaltyTerminateAndCount(r,n,o)*t.PENALTY_N3}for(let s=0;s<this.size;s++){let r=!1,n=0,o=[0,0,0,0,0,0,0];for(let a=0;a<this.size;a++)this.modules[a][s]==r?(n++,5==n?e+=t.PENALTY_N1:n>5&&e++):(this.finderPenaltyAddHistory(n,o),r||(e+=this.finderPenaltyCountPatterns(o)*t.PENALTY_N3),r=this.modules[a][s],n=1);e+=this.finderPenaltyTerminateAndCount(r,n,o)*t.PENALTY_N3}for(let s=0;s<this.size-1;s++)for(let r=0;r<this.size-1;r++){const n=this.modules[s][r];n==this.modules[s][r+1]&&n==this.modules[s+1][r]&&n==this.modules[s+1][r+1]&&(e+=t.PENALTY_N2)}let r=0;for(const t of this.modules)r=t.reduce(((e,t)=>e+(t?1:0)),r);const n=this.size*this.size,o=Math.ceil(Math.abs(20*r-10*n)/n)-1;return s(0<=o&&o<=9),e+=o*t.PENALTY_N4,s(0<=e&&e<=2568888),e}getAlignmentPatternPositions(){if(1==this.version)return[];{const e=Math.floor(this.version/7)+2,t=32==this.version?26:2*Math.ceil((4*this.version+4)/(2*e-2));let r=[6];for(let n=this.size-7;r.length<e;n-=t)r.splice(1,0,n);return r}}static getNumRawDataModules(e){if(e<t.MIN_VERSION||e>t.MAX_VERSION)throw new RangeError("Version number out of range");let r=(16*e+128)*e+64;if(e>=2){const t=Math.floor(e/7)+2;r-=(25*t-10)*t-55,e>=7&&(r-=36)}return s(208<=r&&r<=29648),r}static getNumDataCodewords(e,r){return Math.floor(t.getNumRawDataModules(e)/8)-t.ECC_CODEWORDS_PER_BLOCK[r.ordinal][e]*t.NUM_ERROR_CORRECTION_BLOCKS[r.ordinal][e]}static reedSolomonComputeDivisor(e){if(e<1||e>255)throw new RangeError("Degree out of range");let r=[];for(let t=0;t<e-1;t++)r.push(0);r.push(1);let n=1;for(let s=0;s<e;s++){for(let e=0;e<r.length;e++)r[e]=t.reedSolomonMultiply(r[e],n),e+1<r.length&&(r[e]^=r[e+1]);n=t.reedSolomonMultiply(n,2)}return r}static reedSolomonComputeRemainder(e,r){let n=r.map((e=>0));for(const s of e){const e=s^n.shift();n.push(0),r.forEach(((r,s)=>n[s]^=t.reedSolomonMultiply(r,e)))}return n}static reedSolomonMultiply(e,t){if(e>>>8!=0||t>>>8!=0)throw new RangeError("Byte out of range");let r=0;for(let n=7;n>=0;n--)r=r<<1^285*(r>>>7),r^=(t>>>n&1)*e;return s(r>>>8==0),r}finderPenaltyCountPatterns(e){const t=e[1];s(t<=3*this.size);const r=t>0&&e[2]==t&&e[3]==3*t&&e[4]==t&&e[5]==t;return(r&&e[0]>=4*t&&e[6]>=t?1:0)+(r&&e[6]>=4*t&&e[0]>=t?1:0)}finderPenaltyTerminateAndCount(e,t,r){return e&&(this.finderPenaltyAddHistory(t,r),t=0),t+=this.size,this.finderPenaltyAddHistory(t,r),this.finderPenaltyCountPatterns(r)}finderPenaltyAddHistory(e,t){0==t[0]&&(e+=this.size),t.pop(),t.unshift(e)}};function r(e,t,r){if(t<0||t>31||e>>>t!=0)throw new RangeError("Value out of range");for(let n=t-1;n>=0;n--)r.push(e>>>n&1)}function n(e,t){return!!(e>>>t&1)}function s(e){if(!e)throw new Error("Assertion error")}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=[[-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],[-1,10,16,26,18,24,16,18,22,22,26,30,22,22,24,24,28,28,26,26,26,26,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28],[-1,13,22,18,26,18,24,18,22,20,24,28,26,24,20,30,24,28,28,26,30,28,30,30,30,30,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-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]],t.NUM_ERROR_CORRECTION_BLOCKS=[[-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],[-1,1,1,1,2,2,4,4,4,5,5,5,8,9,9,10,10,11,13,14,16,17,17,18,20,21,23,25,26,28,29,31,33,35,37,38,40,43,45,47,49],[-1,1,1,2,2,4,4,6,6,8,8,8,10,12,16,12,17,16,18,21,20,23,23,25,27,29,34,34,35,38,40,43,45,48,51,53,56,59,62,65,68],[-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]],e.QrCode=t;const o=class e{constructor(e,t,r){if(this.mode=e,this.numChars=t,this.bitData=r,t<0)throw new RangeError("Invalid argument");this.bitData=r.slice()}static makeBytes(t){let n=[];for(const e of t)r(e,8,n);return new e(e.Mode.BYTE,t.length,n)}static makeNumeric(t){if(!e.isNumeric(t))throw new RangeError("String contains non-numeric characters");let n=[];for(let e=0;e<t.length;){const s=Math.min(t.length-e,3);r(parseInt(t.substring(e,e+s),10),3*s+1,n),e+=s}return new e(e.Mode.NUMERIC,t.length,n)}static makeAlphanumeric(t){if(!e.isAlphanumeric(t))throw new RangeError("String contains unencodable characters in alphanumeric mode");let n,s=[];for(n=0;n+2<=t.length;n+=2){let o=45*e.ALPHANUMERIC_CHARSET.indexOf(t.charAt(n));o+=e.ALPHANUMERIC_CHARSET.indexOf(t.charAt(n+1)),r(o,11,s)}return n<t.length&&r(e.ALPHANUMERIC_CHARSET.indexOf(t.charAt(n)),6,s),new e(e.Mode.ALPHANUMERIC,t.length,s)}static makeSegments(t){return""==t?[]:e.isNumeric(t)?[e.makeNumeric(t)]:e.isAlphanumeric(t)?[e.makeAlphanumeric(t)]:[e.makeBytes(e.toUtf8ByteArray(t))]}static makeEci(t){let n=[];if(t<0)throw new RangeError("ECI assignment value out of range");if(t<128)r(t,8,n);else if(t<16384)r(2,2,n),r(t,14,n);else{if(!(t<1e6))throw new RangeError("ECI assignment value out of range");r(6,3,n),r(t,21,n)}return new e(e.Mode.ECI,0,n)}static isNumeric(t){return e.NUMERIC_REGEX.test(t)}static isAlphanumeric(t){return e.ALPHANUMERIC_REGEX.test(t)}getData(){return this.bitData.slice()}static getTotalBits(e,t){let r=0;for(const n of e){const e=n.mode.numCharCountBits(t);if(n.numChars>=1<<e)return 1/0;r+=4+e+n.bitData.length}return r}static toUtf8ByteArray(e){e=encodeURI(e);let t=[];for(let r=0;r<e.length;r++)"%"!=e.charAt(r)?t.push(e.charCodeAt(r)):(t.push(parseInt(e.substring(r+1,r+3),16)),r+=2);return t}};o.NUMERIC_REGEX=/^[0-9]*$/,o.ALPHANUMERIC_REGEX=/^[A-Z0-9 $%*+.\/:-]*$/,o.ALPHANUMERIC_CHARSET="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:";let a=o;e.QrSegment=o})(_||(_={})),(e=>{const t=class{constructor(e,t){this.ordinal=e,this.formatBits=t}};t.LOW=new t(0,1),t.MEDIUM=new t(1,0),t.QUARTILE=new t(2,3),t.HIGH=new t(3,2),e.Ecc=t})((V=_||(_={})).QrCode||(V.QrCode={})),(e=>{(e=>{const t=class{constructor(e,t){this.modeBits=e,this.numBitsCharCount=t}numCharCountBits(e){return this.numBitsCharCount[Math.floor((e+7)/17)]}};t.NUMERIC=new t(1,[10,12,14]),t.ALPHANUMERIC=new t(2,[9,11,13]),t.BYTE=new t(4,[8,16,16]),t.KANJI=new t(8,[8,10,12]),t.ECI=new t(7,[0,0,0]),e.Mode=t})(e.QrSegment||(e.QrSegment={}))})(_||(_={}));var re=_,ne={L:re.QrCode.Ecc.LOW,M:re.QrCode.Ecc.MEDIUM,Q:re.QrCode.Ecc.QUARTILE,H:re.QrCode.Ecc.HIGH},se=128,oe="L",ae="#FFFFFF",le="#000000",ie=!1,ce=1;
|
2
|
+
/**
|
3
|
+
* @license qrcode.react
|
4
|
+
* Copyright (c) Paul O'Shannessy
|
5
|
+
* SPDX-License-Identifier: ISC
|
6
|
+
*/function de(e,t=0){const r=[];return e.forEach((function(e,n){let s=null;e.forEach((function(o,a){if(!o&&null!==s)return r.push(`M${s+t} ${n+t}h${a-s}v1H${s+t}z`),void(s=null);if(a!==e.length-1)o&&null===s&&(s=a);else{if(!o)return;null===s?r.push(`M${a+t},${n+t} h1v1H${a+t}z`):r.push(`M${s+t},${n+t} h${a+1-s}v1H${s+t}z`)}}))})),r.join("")}function ue(e,t){return e.slice().map(((e,r)=>r<t.y||r>=t.y+t.h?e:e.map(((e,r)=>(r<t.x||r>=t.x+t.w)&&e))))}function he({value:e,level:r,minVersion:n,includeMargin:s,marginSize:o,imageSettings:a,size:l,boostLevel:i}){let c=t.useMemo((()=>{const t=(Array.isArray(e)?e:[e]).reduce(((e,t)=>(e.push(...re.QrSegment.makeSegments(t)),e)),[]);return re.QrCode.encodeSegments(t,ne[r],n,void 0,void 0,i)}),[e,r,n,i]);const{cells:d,margin:u,numCells:h,calculatedImageSettings:m}=t.useMemo((()=>{let e=c.getModules();const t=function(e,t){return null!=t?Math.max(Math.floor(t),0):e?4:0}(s,o),r=e.length+2*t,n=function(e,t,r,n){if(null==n)return null;const s=e.length+2*r,o=Math.floor(.1*t),a=s/t,l=(n.width||o)*a,i=(n.height||o)*a,c=null==n.x?e.length/2-l/2:n.x*a,d=null==n.y?e.length/2-i/2:n.y*a,u=null==n.opacity?1:n.opacity;let h=null;if(n.excavate){let e=Math.floor(c),t=Math.floor(d);h={x:e,y:t,w:Math.ceil(l+c-e),h:Math.ceil(i+d-t)}}return{x:c,y:d,h:i,w:l,excavation:h,opacity:u,crossOrigin:n.crossOrigin}}(e,l,t,a);return{cells:e,margin:t,numCells:r,calculatedImageSettings:n}}),[c,l,a,s,o]);return{qrcode:c,margin:u,cells:d,numCells:h,calculatedImageSettings:m}}var me=function(){try{(new Path2D).addPath(new Path2D)}catch(e){return!1}return!0}();t.forwardRef((function(e,r){const n=e,{value:s,size:o=se,level:a=oe,bgColor:l=ae,fgColor:i=le,includeMargin:c=ie,minVersion:d=ce,boostLevel:u,marginSize:h,imageSettings:m}=n,g=te(n,["value","size","level","bgColor","fgColor","includeMargin","minVersion","boostLevel","marginSize","imageSettings"]),{style:p}=g,w=te(g,["style"]),f=null==m?void 0:m.src,y=t.useRef(null),x=t.useRef(null),b=t.useCallback((e=>{y.current=e,"function"==typeof r?r(e):r&&(r.current=e)}),[r]),[N,E]=t.useState(!1),{margin:k,cells:v,numCells:A,calculatedImageSettings:S}=he({value:s,level:a,minVersion:d,boostLevel:u,includeMargin:c,marginSize:h,imageSettings:m,size:o});t.useEffect((()=>{if(null!=y.current){const e=y.current,t=e.getContext("2d");if(!t)return;let r=v;const n=x.current,s=null!=S&&null!==n&&n.complete&&0!==n.naturalHeight&&0!==n.naturalWidth;s&&null!=S.excavation&&(r=ue(v,S.excavation));const a=window.devicePixelRatio||1;e.height=e.width=o*a;const c=o/A*a;t.scale(c,c),t.fillStyle=l,t.fillRect(0,0,A,A),t.fillStyle=i,me?t.fill(new Path2D(de(r,k))):v.forEach((function(e,r){e.forEach((function(e,n){e&&t.fillRect(n+k,r+k,1,1)}))})),S&&(t.globalAlpha=S.opacity),s&&t.drawImage(n,S.x+k,S.y+k,S.w,S.h)}})),t.useEffect((()=>{E(!1)}),[f]);const T=ee({height:o,width:o},p);let C=null;return null!=f&&(C=t.createElement("img",{src:f,key:f,style:{display:"none"},onLoad:()=>{E(!0)},ref:x,crossOrigin:null==S?void 0:S.crossOrigin})),t.createElement(t.Fragment,null,t.createElement("canvas",ee({style:T,height:o,width:o,ref:b,role:"img"},w)),C)})).displayName="QRCodeCanvas";var ge=t.forwardRef((function(e,r){const n=e,{value:s,size:o=se,level:a=oe,bgColor:l=ae,fgColor:i=le,includeMargin:c=ie,minVersion:d=ce,boostLevel:u,title:h,marginSize:m,imageSettings:g}=n,p=te(n,["value","size","level","bgColor","fgColor","includeMargin","minVersion","boostLevel","title","marginSize","imageSettings"]),{margin:w,cells:f,numCells:y,calculatedImageSettings:x}=he({value:s,level:a,minVersion:d,boostLevel:u,includeMargin:c,marginSize:m,imageSettings:g,size:o});let b=f,N=null;null!=g&&null!=x&&(null!=x.excavation&&(b=ue(f,x.excavation)),N=t.createElement("image",{href:g.src,height:x.h,width:x.w,x:x.x+w,y:x.y+w,preserveAspectRatio:"none",opacity:x.opacity,crossOrigin:x.crossOrigin}));const E=de(b,w);return t.createElement("svg",ee({height:o,width:o,viewBox:`0 0 ${y} ${y}`,ref:r,role:"img"},p),!!h&&t.createElement("title",null,h),t.createElement("path",{fill:l,d:`M0,0 h${y}v${y}H0z`,shapeRendering:"crispEdges"}),t.createElement("path",{fill:i,d:E,shapeRendering:"crispEdges"}),N)}));ge.displayName="QRCodeSVG";const pe=({walletAddress:e,amount:r,currency:n,network:s,theme:o="light",size:a=200})=>{const[l,i]=t.useState(""),[c,d]=t.useState(null);t.useEffect((()=>{if(e&&"No address configured"!==e)try{let t;switch(s){case"tron":t="TRX"===n?`tronlink://transfer?to=${e}&amount=${r}`:e;break;case"algorand":t=`algorand://${e}?amount=${Math.floor(1e6*parseFloat(r))}`;break;case"bsc":if("BNB"===n)t=`ethereum:${e}@56?value=${m(r)}`;else{const s=u(n,"bsc");t=s?`ethereum:${s}/transfer?address=${e}&uint256=${h(r,n)}@56`:e}break;default:if("ETH"===n)t=`ethereum:${e}@1?value=${m(r)}`;else{const s=u(n,"ethereum");t=s?`ethereum:${s}/transfer?address=${e}&uint256=${h(r,n)}`:e}}i(t),d(null)}catch(t){console.error("Error generating QR code:",t),d("Error generating payment QR code")}else d("No wallet address configured for this network")}),[e,r,n,s]);const u=(e,t)=>{var r;return(null==(r={ethereum:{USDT:"0xdAC17F958D2ee523a2206206994597C13D831ec7",USDC:"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"},bsc:{USDT:"0x55d398326f99059fF775485246999027B3197955",USDC:"0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d"},tron:{USDT:"TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t",USDC:"TEkxiTehnzSmSe2XqrBj4w32RUN966rdz8"}}[t])?void 0:r[e])||""},h=(e,t)=>{const r="USDT"===t||"USDC"===t?6:18;return Math.floor(parseFloat(e)*Math.pow(10,r)).toString()},m=e=>Math.floor(1e18*parseFloat(e)).toString(),g=e=>({ethereum:"Ethereum",bsc:"BSC",tron:"Tron",algorand:"Algorand"}[e]||e);return Q.jsxs("div",{className:"flex flex-col items-center",children:[c?Q.jsxs("div",{className:"p-4 rounded-lg bg-red-100 mb-3 text-red-700 text-center",children:[Q.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:Q.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"})}),Q.jsx("p",{className:"font-medium",children:c})]}):Q.jsx("div",{className:"p-4 rounded-lg bg-white mb-3 shadow-sm border",children:l&&Q.jsx(ge,{value:l,size:a,bgColor:"dark"===o?"#374151":"#FFFFFF",fgColor:"dark"===o?"#FFFFFF":"#000000",level:"H",includeMargin:!0})}),Q.jsxs("div",{className:"text-center text-sm text-gray-700 mb-4",children:[Q.jsxs("p",{className:"font-semibold text-gray-800 flex items-center justify-center",children:[Q.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:Q.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"})}),"Scan to Pay with ",n]}),Q.jsxs("p",{className:"text-xs text-gray-500 mt-1",children:["Scan with your ",g(s)," wallet app"]})]}),Q.jsxs("div",{className:"w-full mb-4 p-3 bg-gray-50 rounded-lg",children:[Q.jsxs("div",{className:"flex justify-between items-center",children:[Q.jsx("span",{className:"text-sm font-medium text-gray-700",children:"Amount to Pay:"}),Q.jsxs("span",{className:"text-lg font-bold text-[#7042D2]",children:[r," ",n]})]}),Q.jsxs("div",{className:"flex justify-between items-center mt-1",children:[Q.jsx("span",{className:"text-xs text-gray-500",children:"Network:"}),Q.jsx("span",{className:"text-xs font-medium text-gray-700",children:g(s)})]})]}),!c&&Q.jsxs("div",{className:"w-full mb-4",children:[Q.jsx("p",{className:"text-xs text-gray-500 mb-1 text-center",children:"Or copy wallet address:"}),Q.jsx("div",{className:"text-xs font-mono p-2 rounded bg-gray-100 text-gray-700 break-all text-center select-all cursor-pointer border",onClick:()=>{var t;return null==(t=navigator.clipboard)?void 0:t.writeText(e)},title:"Click to copy",children:e})]}),Q.jsx("div",{className:"w-full",children:Q.jsxs("div",{className:"p-3 rounded bg-blue-50 border border-blue-200",children:[Q.jsxs("h4",{className:"text-sm font-medium mb-2 text-blue-800 flex items-center",children:[Q.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:Q.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"})}),"Payment Instructions"]}),Q.jsxs("ol",{className:"text-xs space-y-1 text-blue-700",children:[Q.jsxs("li",{children:["1. Open your crypto wallet app (",(p=s,{ethereum:["MetaMask","Trust Wallet","Coinbase Wallet"],bsc:["MetaMask","Trust Wallet","SafePal"],tron:["TronLink","Trust Wallet"],algorand:["Pera Wallet","MyAlgo Wallet"]}[p]||["MetaMask","Trust Wallet"]).join(", "),")"]}),Q.jsx("li",{children:"2. Scan the QR code above or copy the wallet address"}),Q.jsxs("li",{children:["3. Send exactly ",Q.jsxs("strong",{children:[r," ",n]})," on ",g(s)," network"]}),Q.jsx("li",{children:'4. Click "I have sent the payment" button below after sending'})]}),Q.jsx("div",{className:"mt-3 p-2 bg-yellow-50 border border-yellow-200 rounded",children:Q.jsxs("p",{className:"text-xs text-yellow-800",children:[Q.jsx("strong",{children:"Important:"})," Make sure you're sending on the correct network (",g(s),") and using the exact amount shown above."]})})]})})]});var p},we=({status:e,message:t,theme:r="light"})=>Q.jsxs("div",{className:"flex flex-col items-center justify-center py-6",children:[Q.jsx("div",{className:"mb-4",children:(()=>{switch(e){case"processing":return Q.jsx("div",{className:"animate-spin rounded-full h-12 w-12 border-4 border-t-blue-500 border-blue-500/20"});case"success":return Q.jsx("div",{className:"rounded-full h-12 w-12 bg-green-100 flex items-center justify-center",children:Q.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-8 w-8 text-green-500",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:Q.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5 13l4 4L19 7"})})});case"error":return Q.jsx("div",{className:"rounded-full h-12 w-12 bg-red-100 flex items-center justify-center",children:Q.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-8 w-8 text-red-500",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:Q.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})})});default:return null}})()}),Q.jsx("h3",{className:"text-xl font-bold mb-2 "+("dark"===r?"text-white":"text-gray-900"),children:(()=>{switch(e){case"processing":return"Processing Payment";case"success":return"Payment Successful";case"error":return"Payment Failed";default:return"Unknown Status"}})()}),Q.jsx("p",{className:`text-center ${(()=>{switch(e){case"processing":return"dark"===r?"text-blue-300":"text-blue-600";case"success":return"dark"===r?"text-green-300":"text-green-600";case"error":return"dark"===r?"text-red-300":"text-red-600";default:return"dark"===r?"text-gray-300":"text-gray-600"}})()}`,children:t}),"processing"===e&&Q.jsx("div",{className:"mt-4 text-xs "+("dark"===r?"text-gray-400":"text-gray-500"),children:"This may take a few moments. Please do not close this window."}),"success"===e&&Q.jsx("div",{className:"mt-4 p-2 rounded "+("dark"===r?"bg-gray-700":"bg-gray-100"),children:Q.jsx("p",{className:"text-xs "+("dark"===r?"text-gray-300":"text-gray-600"),children:"Your payment has been successfully processed. You will receive a confirmation shortly."})})]}),fe=({onSelect:e,selected:r,theme:n="light",supportedNetworks:s=[]})=>{const[o,a]=t.useState(u.ETHEREUM),[l,i]=t.useState({}),[c,d]=t.useState(!1);t.useEffect((()=>{i(f())}),[]);const h=[{id:u.ETHEREUM,name:"Ethereum",description:"ERC-20 tokens"},{id:u.BSC,name:"BSC (Binance Smart Chain)",description:"BEP-20 tokens"},{id:u.TRON,name:"Tron",description:"TRC-20 tokens"},{id:u.ALGORAND,name:"Algorand",description:"ASA tokens"}],m=(e=>{const t=[];switch(e){case u.ETHEREUM:t.push({id:"USDT",name:"USDT",description:"Tether USD",logo:"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSj0euZAOXsLTJFQxgiKzlX7z8xbfBk-7kmJA&s",network:u.ETHEREUM},{id:"USDC",name:"USDC",description:"USD Coin",logo:"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ43MuDqq54iD1ZCRL_uthAPkfwSSL-J5qI_Q&s",network:u.ETHEREUM},{id:"PYUSD",name:"PYUSD",description:"PayPal USD",logo:"https://s2.coinmarketcap.com/static/img/coins/64x64/28492.png",network:u.ETHEREUM},{id:"FRAX",name:"FRAX",description:"Frax",logo:"https://s2.coinmarketcap.com/static/img/coins/64x64/6952.png",network:u.ETHEREUM},{id:"USDP",name:"USDP",description:"Pax Dollar",logo:"https://s2.coinmarketcap.com/static/img/coins/64x64/6662.png",network:u.ETHEREUM},{id:"DAI",name:"DAI",description:"Dai Stablecoin",logo:"https://s2.coinmarketcap.com/static/img/coins/64x64/4943.png",network:u.ETHEREUM},{id:"ETH",name:"ETH",description:"Ethereum",logo:"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTcyJyRKN0dRJWVZqoLzYgkRHdJsxKGq8nHUw&s",network:u.ETHEREUM});break;case u.BSC:t.push({id:"USDT",name:"USDT",description:"Tether USD",logo:"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSj0euZAOXsLTJFQxgiKzlX7z8xbfBk-7kmJA&s",network:u.BSC},{id:"USDC",name:"USDC",description:"USD Coin",logo:"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ43MuDqq54iD1ZCRL_uthAPkfwSSL-J5qI_Q&s",network:u.BSC},{id:"BUSD",name:"BUSD",description:"Binance USD",logo:"https://s2.coinmarketcap.com/static/img/coins/64x64/4687.png",network:u.BSC},{id:"FRAX",name:"FRAX",description:"Frax",logo:"https://s2.coinmarketcap.com/static/img/coins/64x64/6952.png",network:u.BSC},{id:"BNB",name:"BNB",description:"Binance Coin",logo:"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRHSjyW2sSnBhwztCwVW97i1BtV40g7heMMxg&s",network:u.BSC});break;case u.TRON:t.push({id:"USDT",name:"USDT",description:"Tether USD",logo:"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSj0euZAOXsLTJFQxgiKzlX7z8xbfBk-7kmJA&s",network:u.TRON},{id:"USDC",name:"USDC",description:"USD Coin",logo:"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ43MuDqq54iD1ZCRL_uthAPkfwSSL-J5qI_Q&s",network:u.TRON},{id:"USDJ",name:"USDJ",description:"JUST Stablecoin",logo:"https://s2.coinmarketcap.com/static/img/coins/64x64/5446.png",network:u.TRON},{id:"TRX",name:"TRX",description:"Tron",logo:"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQKLpLNsGRHbZfCUXAjZLPSp_YFZvX5dMnAoA&s",network:u.TRON});break;case u.ALGORAND:t.push({id:"USDC",name:"USDC",description:"USD Coin",logo:"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ43MuDqq54iD1ZCRL_uthAPkfwSSL-J5qI_Q&s",network:u.ALGORAND},{id:"USDT",name:"USDT",description:"Tether USD",logo:"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSj0euZAOXsLTJFQxgiKzlX7z8xbfBk-7kmJA&s",network:u.ALGORAND},{id:"ALGO",name:"ALGO",description:"Algorand",logo:"https://s2.coinmarketcap.com/static/img/coins/64x64/4030.png",network:u.ALGORAND})}return t})(o),p=c?m:m.slice(0,4);return Q.jsxs("div",{children:[Q.jsx("h3",{className:"text-lg font-medium mb-4 "+("dark"===n?"text-white":"text-gray-800"),children:"Select Payment Method"}),Q.jsxs("div",{className:"mb-6",children:[Q.jsx("label",{className:"block text-sm font-medium mb-2 "+("dark"===n?"text-white":"text-gray-700"),children:"Blockchain Network"}),Q.jsx("select",{value:o,onChange:t=>{return n=t.target.value,a(n),d(!1),void((null==r?void 0:r.network)!==n&&e(null));var n},className:`w-full p-3 rounded-lg border transition-colors ${"dark"===n?"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`,children:h.filter((e=>0===s.length||s.includes(e.id))).map((e=>Q.jsxs("option",{value:e.id,children:[e.name," - ",e.description]},e.id)))})]}),Q.jsxs("div",{className:"mb-4",children:[Q.jsx("label",{className:"block text-sm font-medium mb-3 "+("dark"===n?"text-white":"text-gray-700"),children:"Choose Cryptocurrency"}),Q.jsx("div",{className:"grid grid-cols-2 gap-3 mb-4",children:p.map((t=>Q.jsx("button",{onClick:()=>(t=>{var r;e({currency:t.id,network:o,tokenConfig:null==(r=g[t.id])?void 0:r[o],method:t})})(t),className:"p-4 rounded-lg transition-all duration-200 border-2 "+((null==r?void 0:r.currency)===t.id&&(null==r?void 0:r.network)===o?"dark"===n?"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":"dark"===n?"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"),children:Q.jsxs("div",{className:"flex flex-col items-center text-center",children:[Q.jsx("div",{className:"flex-shrink-0 h-10 w-10 bg-white rounded-full flex items-center justify-center mb-2 shadow-sm",children:Q.jsx("img",{src:t.logo,alt:t.name,className:"h-6 w-6"})}),Q.jsxs("div",{children:[Q.jsx("h4",{className:"font-medium text-sm "+("dark"===n?"text-white":"text-gray-900"),children:t.name}),Q.jsx("p",{className:"text-xs "+("dark"===n?"text-gray-300":"text-gray-500"),children:t.description})]}),(null==r?void 0:r.currency)===t.id&&(null==r?void 0:r.network)===o&&Q.jsx("div",{className:"mt-2",children:Q.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-4 w-4 text-[#7042D2]",viewBox:"0 0 20 20",fill:"currentColor",children:Q.jsx("path",{fillRule:"evenodd",d:"M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z",clipRule:"evenodd"})})})]})},`${t.id}-${t.network}`)))}),m.length>4&&Q.jsx("button",{onClick:()=>d(!c),className:"w-full py-2 px-4 rounded-lg text-sm font-medium transition-colors "+("dark"===n?"bg-gray-700 text-gray-300 hover:bg-gray-600":"bg-gray-100 text-gray-600 hover:bg-gray-200"),children:c?"Show Less":`Show More (${m.length-4} more)`})]}),Q.jsx("div",{className:"p-3 rounded-lg text-sm "+("dark"===n?"bg-gray-800 text-gray-300":"bg-gray-50 text-gray-600"),children:Q.jsxs("div",{className:"flex items-center",children:[Q.jsx("div",{className:"w-2 h-2 rounded-full mr-2 "+(l[w(o)]?"bg-green-500":"bg-red-500")}),Q.jsx("span",{className:"text-xs",children:function(e){const t=w(e),r=l[t],n={metamask:"MetaMask",tronlink:"TronLink",lute:"Lute Wallet"};return r?`${n[t]} detected - Ready to pay`:`${n[t]} required - Please install to continue`}(o)})]})})]});function w(e){switch(e){case u.ETHEREUM:case u.BSC:return"metamask";case u.TRON:return"tronlink";case u.ALGORAND:return"lute";default:return"metamask"}}},ye=({isOpen:e,onClose:r,payment:n,paymentStatus:s,selectedPaymentMethod:o,onPaymentMethodSelect:a,onPayment:l,onBack:i,error:c,theme:d="light",merchantName:u,transactionHash:m,walletConnection:g,onConnectWallet:p,testMode:w=!1,supportedNetworks:f=[],availableWallets:y={},supportedWallets:x=[],step:b="select-currency",merchantWalletAddresses:N={}})=>{const[E,k]=t.useState("wallet"),v=e=>({ethereum:"Ethereum",bsc:"BSC",tron:"Tron",algorand:"Algorand"}[e]||e),A=e=>({[h.METAMASK]:"MetaMask",[h.TRONLINK]:"TronLink",[h.TRUST_WALLET]:"Trust Wallet",[h.LUTE]:"Lute Wallet"}[e]||e),S=e=>({[h.METAMASK]:"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcT3ymr3UNKopfI0NmUY95Dr-0589vG-91KuAA&s",[h.TRONLINK]:"https://www.tronlink.org/images/logo.png",[h.TRUST_WALLET]:"https://trustwallet.com/assets/images/trust_logotype.svg",[h.LUTE]:"https://lute.app/logo.png"}[e]||"");return e?Q.jsx("div",{className:"fixed inset-0 z-50 overflow-y-auto bg-black/50",children:Q.jsx("div",{className:"flex min-h-screen items-center justify-center p-4",children:Q.jsxs("div",{className:"relative p-6 w-full max-w-md mx-auto rounded-lg shadow-xl bg-white text-gray-800",children:[Q.jsxs("div",{className:"flex justify-between items-center mb-6 bg-[#F1ECFB] p-3 rounded-xl",children:[Q.jsx("div",{className:"flex items-center",children:Q.jsx("h2",{className:"text-xl font-bold text-gray-900",children:Q.jsx("img",{src:"data:image/png;base64,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",className:"w-32",alt:"Coinley Logo"})})}),Q.jsx("button",{onClick:r,className:"text-gray-500 hover:text-gray-700 focus:outline-none",children:Q.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-6 w-6",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:Q.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),Q.jsxs("div",{className:"mb-6 bg-[#F1ECFB] p-3 rounded-xl",children:[n&&Q.jsxs("div",{className:"mb-6 p-4 rounded-lg",children:[Q.jsxs("p",{className:"text-lg text-gray-800 font-semibold",children:["PAY: ",u]}),Q.jsxs("div",{className:"flex justify-between items-center mt-2 bg-gray-100 px-3 rounded-lg",children:[Q.jsx("span",{className:"font-medium text-gray-700",children:"Amount:"}),Q.jsxs("span",{className:"font-bold text-xl text-[#7042D2]",children:["$",(C=n.totalAmount||n.amount,parseFloat(C).toFixed(2))]})]}),Q.jsx("div",{className:"text-xs mt-1 text-right",children:Q.jsxs("span",{className:"text-gray-500",children:["Payment ID: ",n.id?n.id.slice(0,8):"","..."]})})]}),"select-currency"===b&&Q.jsxs("div",{children:[Q.jsx(fe,{onSelect:a,selected:o,theme:d,supportedNetworks:f}),o&&Q.jsx("div",{className:"mt-6",children:Q.jsxs("button",{onClick:()=>a(o),className:"w-full py-3 px-4 bg-[#7042D2] hover:bg-[#7042D2] text-white font-medium rounded-lg transition-colors",children:["Proceed with ",o.currency," on ",v(o.network)]})})]}),"confirm"===b&&o&&n&&Q.jsxs("div",{children:[Q.jsxs("div",{className:"p-4 rounded-lg mb-4 bg-gray-100",children:[Q.jsx("h3",{className:"text-lg font-medium mb-2 text-gray-800",children:"Payment Details"}),Q.jsxs("div",{className:"space-y-2",children:[Q.jsxs("div",{className:"flex justify-between",children:[Q.jsx("span",{className:"text-[#7042D2] font-semibold",children:"Currency:"}),Q.jsx("span",{className:"font-medium",children:o.currency})]}),Q.jsxs("div",{className:"flex justify-between",children:[Q.jsx("span",{className:"text-[#7042D2] font-semibold",children:"Network:"}),Q.jsx("span",{className:"font-medium",children:v(o.network)})]}),Q.jsxs("div",{className:"flex justify-between",children:[Q.jsx("span",{className:"text-[#7042D2] font-semibold",children:"Fee:"}),Q.jsx("span",{className:"font-medium",children:"1.75%"})]})]})]}),Q.jsx("div",{className:"mb-4",children:Q.jsxs("div",{className:"flex border-b border-gray-200",children:[Q.jsx("button",{onClick:()=>k("wallet"),className:"py-2 px-4 text-sm font-medium "+("wallet"===E?"border-b-2 border-[#7042D2] text-[#7042D2]":"text-gray-500 hover:text-gray-700"),children:"Connect Wallet"}),Q.jsx("button",{onClick:()=>k("qrcode"),className:"py-2 px-4 text-sm font-medium "+("qrcode"===E?"border-b-2 border-[#7042D2] text-[#7042D2]":"text-gray-500 hover:text-gray-700"),children:"QR Code"})]})}),w?Q.jsx("div",{className:"p-4 rounded-lg mb-4 bg-blue-50",children:Q.jsxs("div",{className:"flex items-center",children:[Q.jsx("div",{className:"bg-[#7042D2] rounded-full p-2 mr-3",children:Q.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:Q.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 10V3L4 14h7v7l9-11h-7z"})})}),Q.jsxs("div",{children:[Q.jsx("h3",{className:"font-medium text-gray-800",children:"Test Mode Payment"}),Q.jsx("p",{className:"text-sm text-gray-600",children:'Click "Pay Now" to simulate a successful payment'})]})]})}):"qrcode"===E?Q.jsx("div",{className:"mb-4",children:Q.jsx(pe,{walletAddress:(()=>{if(!o)return"No network selected";const e=N[o.network];return e||((null==n?void 0:n.recipientWallet)?n.recipientWallet:"No wallet address configured for this network")})(),amount:n.totalAmount||n.amount,currency:o.currency,network:o.network,theme:d})}):Q.jsxs("div",{className:"space-y-3 mb-4",children:[0===x.length?Q.jsx("div",{className:"p-4 rounded-lg bg-yellow-50",children:Q.jsxs("div",{className:"flex items-center",children:[Q.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:Q.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"})}),Q.jsxs("div",{children:[Q.jsx("h3",{className:"font-medium text-gray-800",children:"No Compatible Wallets"}),Q.jsxs("p",{className:"text-sm text-gray-600",children:["No wallets detected for ",v(o.network)," network"]})]})]})}):x.map((e=>Q.jsx("div",{className:"p-4 rounded-lg bg-blue-50",children:Q.jsxs("div",{className:"flex items-center justify-between",children:[Q.jsxs("div",{className:"flex items-center",children:[Q.jsx("img",{src:S(e),alt:A(e),className:"w-8 h-8 mr-3",onError:e=>{e.target.style.display="none"}}),Q.jsxs("div",{children:[Q.jsx("h3",{className:"font-medium text-gray-800",children:A(e)}),Q.jsxs("p",{className:"text-sm text-gray-600",children:["Pay with ",A(e)]})]})]}),(null==g?void 0:g.walletType)===e?Q.jsxs("div",{className:"flex items-center space-x-2",children:[Q.jsx("div",{className:"w-2 h-2 bg-green-500 rounded-full"}),Q.jsx("span",{className:"text-sm text-green-600",children:"Connected"})]}):Q.jsx("button",{onClick:()=>p(e),className:"py-2 px-4 bg-[#7042D2] hover:bg-[#7042D2] text-white font-medium rounded-md text-sm",children:"Connect"})]})},e))),Q.jsx("div",{className:"space-y-2",children:Object.entries(y).filter((([e,t])=>!t)).map((([e])=>Q.jsx("div",{className:"p-3 rounded-lg bg-gray-50",children:Q.jsxs("div",{className:"flex items-center justify-between",children:[Q.jsxs("span",{className:"text-sm text-gray-600",children:[A(e)," not detected"]}),Q.jsx("a",{href:j(e),target:"_blank",rel:"noopener noreferrer",className:"text-sm text-[#7042D2] hover:underline",children:"Install"})]})},e)))})]}),Q.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[Q.jsx("button",{type:"button",onClick:i,className:"w-full py-2 px-4 bg-gray-200 hover:bg-gray-300 text-[#7042D2] font-medium rounded-md",children:"Back"}),Q.jsx("button",{type:"button",onClick:()=>l("qrcode"===E),className:"w-full py-2 px-4 bg-[#7042D2] hover:bg-[#7042D2] text-white font-medium rounded-md",disabled:!w&&"wallet"===E&&!g,children:"qrcode"===E?"I have sent the payment":"Pay Now"})]})]}),"processing"===b&&Q.jsx(we,{status:"processing",theme:d,message:"Processing your payment..."}),"success"===b&&Q.jsxs("div",{children:[Q.jsx(we,{status:"success",theme:d,message:"Payment successful!"}),m&&Q.jsxs("div",{className:"mt-4 p-3 rounded-lg bg-gray-100",children:[Q.jsx("p",{className:"text-xs text-gray-600 mb-1",children:"Transaction Hash:"}),Q.jsx("p",{className:"text-sm font-mono break-all text-gray-800",children:(T=m,T?T.length<=14?T:`${T.slice(0,8)}...${T.slice(-6)}`:"")}),o&&Q.jsx("a",{href:`${xe(o.network)}/${be(o.network)}/${m}`,target:"_blank",rel:"noopener noreferrer",className:"text-xs text-[#7042D2] mt-2 inline-block",children:"View on Explorer →"})]})]}),"error"===b&&Q.jsxs("div",{children:[Q.jsx(we,{status:"error",theme:d,message:c||"An error occurred while processing your payment."}),Q.jsx("button",{type:"button",onClick:i,className:"mt-4 w-full py-2 px-4 bg-gray-200 hover:bg-gray-300 text-gray-800 font-medium rounded-md",children:"Try Again"})]})]}),Q.jsx("div",{className:"text-center text-xs text-gray-500",children:Q.jsxs("p",{children:["Powered by ",Q.jsx("span",{className:"text-[#7042D2]",children:"Coinley"})," - Secure Cryptocurrency Payments"]})})]})})}):null;var T,C},xe=e=>({ethereum:"https://etherscan.io",bsc:"https://bscscan.com",tron:"https://tronscan.org",algorand:"https://algoexplorer.io"}[e]||"https://etherscan.io"),be=e=>({ethereum:"tx",bsc:"tx",tron:"transaction",algorand:"tx"}[e]||"tx"),Ne=t.forwardRef((({apiKey:e,apiSecret:r,apiUrl:n,customerEmail:s,merchantName:o="Merchant",merchantWalletAddresses:a={},onSuccess:l,onError:i,onClose:m,theme:g,autoOpen:p=!1,debug:w=!1,testMode:b=!1,supportedNetworks:N=[],preferredNetwork:E=u.ETHEREUM,preferredWallet:k=h.METAMASK},v)=>{const S=K(),{theme:T}=t.useContext(q),[C,j]=t.useState(p),[M,R]=t.useState(null),[U,P]=t.useState("idle"),[O,F]=t.useState(null),[W,B]=t.useState(null),[I,z]=t.useState(null),[H,G]=t.useState(null),[_,V]=t.useState({}),[J,$]=t.useState("select-currency");e||null==S||S.apiKey,r||null==S||S.apiSecret,n||null==S||S.apiUrl;const Y=g||T,X=w||(null==S?void 0:S.debug),Z=N.length>0?N:[u.ETHEREUM,u.BSC,u.TRON,u.ALGORAND];t.useImperativeHandle(v,(()=>({open:e=>{te(e)},close:()=>{re()},getPayment:()=>M,getWalletConnection:()=>H})));const ee=(e,t)=>{X&&console.log(`[Coinley SDK] ${e}`,t)};t.useEffect((()=>{if("undefined"!=typeof window){const e=f();V(e),ee("Available wallets detected:",e)}}),[X]);const te=e=>d(this,null,(function*(){if(!e||!e.amount)return B("Payment amount is required"),void(i&&i(new Error("Payment amount is required")));P("loading"),j(!0),$("select-currency");try{ee("Creating payment with details:",e);const t=yield L({amount:e.amount,currency:e.currency||"USDT",network:e.network||E,customerEmail:e.customerEmail||s,callbackUrl:e.callbackUrl,metadata:e.metadata||{},merchantWalletAddresses:c(c({},a),e.merchantWalletAddresses)});ee("Payment created:",t),R(t.payment),P("idle"),B(null),ee("Payment created and state updated")}catch(t){ee("Error creating payment:",t),B(t.message||"Failed to create payment"),P("error"),i&&i(t)}})),re=()=>{j(!1),z(null),G(null),F(null),$("select-currency"),m&&m()};return Q.jsx(Q.Fragment,{children:C&&Q.jsx(ye,{isOpen:C,onClose:re,payment:M,paymentStatus:U,selectedPaymentMethod:O,onPaymentMethodSelect:e=>{ee("Payment method selected:",e),F(e),$("confirm")},onPayment:()=>d(this,null,(function*(){var e,t;if(M&&O)if(H||b){ee("Starting payment process..."),P("loading"),z(null);try{let r;if(b)ee("Test mode: Generating mock transaction..."),r=`test_${Date.now().toString(16)}_${Math.random().toString(16).substring(2,10)}`;else{const n=a[O.network];if(!n)throw new Error(`No merchant wallet address configured for ${O.network}`);ee("Sending transaction through wallet..."),r=yield A(H,{to:n,amount:M.amount,tokenAddress:null==(e=O.tokenConfig)?void 0:e.address,tokenDecimals:null==(t=O.tokenConfig)?void 0:t.decimals})}ee("Transaction hash:",r),z(r),ee("Processing payment with backend...");const n=yield D({paymentId:M.id,transactionHash:r,network:O.network,currency:O.currency,senderAddress:null==H?void 0:H.address});ee("Payment processed successfully:",n),P("success"),$("success"),l&&(ee("Calling onSuccess callback..."),l(M.id,r,{network:O.network,currency:O.currency,amount:M.amount}))}catch(r){ee("Payment error:",r),B(r.message||"Failed to process payment"),P("error"),$("error"),i&&i(r)}}else B("Please connect your wallet first");else B("Missing payment information")})),onBack:()=>{"confirm"===J&&($("select-currency"),G(null))},error:W,theme:Y,merchantName:o,transactionHash:I,walletConnection:H,onConnectWallet:e=>d(this,null,(function*(){if(O)try{ee("Connecting wallet:",{walletType:e,network:O.network});const t=yield x(e,O.network);G(t),B(null),ee("Wallet connected successfully:",t)}catch(t){ee("Wallet connection error:",t),B(t.message||"Failed to connect wallet")}else B("Please select a payment method first")})),testMode:b,supportedNetworks:Z,availableWallets:_,supportedWallets:O?y(O.network):[],step:J,merchantWalletAddresses:a})})}));Ne.displayName="CoinleyCheckout";e.CoinleyCheckout=Ne,e.CoinleyModal=ye,e.CoinleyProvider=({apiKey:e,apiSecret:r,apiUrl:n="http://localhost:9000",merchantWalletAddress:s=null,merchantSolWalletAddress:o=null,debug:a=!1,children:l})=>{const[i,d]=t.useState(!1),[u,h]=t.useState(null),[m,g]=t.useState(null);t.useEffect((()=>{var t;if(e&&r)try{t={apiKey:e,apiSecret:r,apiUrl:n,merchantWalletAddress:s,merchantSolWalletAddress:o},M=c(c({},M),t),console.log("API initialized with:",{apiUrl:M.apiUrl,apiKey:M.apiKey?`${M.apiKey.substring(0,6)}...`:null,hasWalletAddresses:Object.keys(M.merchantWalletAddresses||{}).length>0}),d(!0),a&&console.log("Coinley SDK initialized with:",{apiKey:e,apiUrl:n,merchantWalletAddress:s?`${s.substring(0,6)}...${s.substring(s.length-4)}`:"Not provided",merchantSolWalletAddress:o?`${o.substring(0,6)}...${o.substring(o.length-4)}`:"Not provided"})}catch(l){h(l.message),a&&console.error("Coinley SDK initialization error:",l)}else h("API key and secret are required")}),[e,r,n,s,o,a]);const p={apiKey:e,apiSecret:r,apiUrl:n,merchantWalletAddress:s,merchantSolWalletAddress:o,isInitialized:i,error:u,debug:a,paymentData:m,storePaymentData:e=>(g(e),e)};return Q.jsx(G.Provider,{value:p,children:l})},e.DEFAULT_CONFIG={apiUrl:"http://localhost:9000",debug:!1,testMode:!1,theme:"light",supportedNetworks:["ethereum","bsc","tron","algorand"]},e.NETWORK_CONFIG=m,e.NETWORK_TYPES=u,e.PaymentMethods=fe,e.PaymentStatus=we,e.QRCode=pe,e.TOKEN_CONFIG=g,e.ThemeProvider=({initialTheme:e="light",children:r})=>{const[n,s]=t.useState(e);return t.useEffect((()=>{document.documentElement.classList.remove("light","dark"),document.documentElement.classList.add(n)}),[n]),Q.jsx(q.Provider,{value:{theme:n,setTheme:s,toggleTheme:()=>{s((e=>"light"===e?"dark":"light"))}},children:r})},e.WALLET_TYPES=h,e.connectWallet=x,e.createPayment=L,e.detectWallets=f,e.generateMockTransactionHash=(e="ethereum")=>`${{ethereum:"0x",bsc:"0x",tron:"",algorand:""}[e]||"0x"}${Array.from({length:64},(()=>Math.floor(16*Math.random()).toString(16))).join("")}`,e.getMerchantProfile=()=>d(this,null,(function*(){try{const e=yield fetch(`${M.apiUrl}/api/merchants/profile`,{method:"GET",headers:R()});if(!e.ok){const t=yield e.json();throw new Error(t.error||`Failed to get merchant profile: ${e.status}`)}const t=yield e.json();return t.merchant&&t.merchant.walletAddresses&&(M.merchantWalletAddresses=c(c({},M.merchantWalletAddresses),t.merchant.walletAddresses)),t}catch(e){throw console.error("Get merchant profile error:",e),e}})),e.getPayment=e=>d(this,null,(function*(){try{console.log("Getting payment:",e);const t=yield fetch(`${M.apiUrl}/api/payments/${e}`,{method:"GET",headers:R()});if(!t.ok){const e=yield t.json();throw console.error("Error getting payment:",e),new Error(e.error||`Failed to get payment: ${t.status}`)}const r=yield t.json();return console.log("Get payment response:",r),r}catch(t){throw console.error("Get payment error:",t),t}})),e.getSupportedNetworks=()=>d(this,null,(function*(){try{const e=yield fetch(`${M.apiUrl}/api/networks`,{method:"GET",headers:R()});if(!e.ok){const t=yield e.json();throw new Error(t.error||`Failed to get networks: ${e.status}`)}return yield e.json()}catch(e){throw console.error("Get supported networks error:",e),e}})),e.getSupportedWalletsForNetwork=y,e.getWalletInstallUrl=j,e.processPayment=D,e.sendTransaction=A,e.useCoinley=K,e.validateWalletAddress=(e,t)=>d(this,null,(function*(){try{const r=yield fetch(`${M.apiUrl}/api/wallets/validate`,{method:"POST",headers:R(),body:JSON.stringify({address:e,network:t})});if(!r.ok){const e=yield r.json();throw new Error(e.error||`Failed to validate address: ${r.status}`)}return yield r.json()}catch(r){throw console.error("Validate wallet address error:",r),r}})),Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})}));
|
18
7
|
//# sourceMappingURL=coinley-checkout.umd.js.map
|