coinley-checkout 0.5.8 → 0.5.9

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.
@@ -13,5 +13,5 @@ const ba=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffff
13
13
  * @license qrcode.react
14
14
  * Copyright (c) Paul O'Shannessy
15
15
  * SPDX-License-Identifier: ISC
16
- */function yp(t,e=0){const r=[];return t.forEach((function(t,n){let i=null;t.forEach((function(s,a){if(!s&&null!==i)return r.push(`M${i+e} ${n+e}h${a-i}v1H${i+e}z`),void(i=null);if(a!==t.length-1)s&&null===i&&(i=a);else{if(!s)return;null===i?r.push(`M${a+e},${n+e} h1v1H${a+e}z`):r.push(`M${i+e},${n+e} h${a+1-i}v1H${i+e}z`)}}))})),r.join("")}function vp(t,e){return t.slice().map(((t,r)=>r<e.y||r>=e.y+e.h?t:t.map(((t,r)=>(r<e.x||r>=e.x+e.w)&&t))))}function wp({value:t,level:r,minVersion:n,includeMargin:i,marginSize:s,imageSettings:a,size:o,boostLevel:l}){let c=e.useMemo((()=>{const e=(Array.isArray(t)?t:[t]).reduce(((t,e)=>(t.push(...up.QrSegment.makeSegments(e)),t)),[]);return up.QrCode.encodeSegments(e,hp[r],n,void 0,void 0,l)}),[t,r,n,l]);const{cells:u,margin:h,numCells:d,calculatedImageSettings:p}=e.useMemo((()=>{let t=c.getModules();const e=function(t,e){return null!=e?Math.max(Math.floor(e),0):t?4:0}(i,s),r=t.length+2*e,n=function(t,e,r,n){if(null==n)return null;const i=t.length+2*r,s=Math.floor(.1*e),a=i/e,o=(n.width||s)*a,l=(n.height||s)*a,c=null==n.x?t.length/2-o/2:n.x*a,u=null==n.y?t.length/2-l/2:n.y*a,h=null==n.opacity?1:n.opacity;let d=null;if(n.excavate){let t=Math.floor(c),e=Math.floor(u);d={x:t,y:e,w:Math.ceil(o+c-t),h:Math.ceil(l+u-e)}}return{x:c,y:u,h:l,w:o,excavation:d,opacity:h,crossOrigin:n.crossOrigin}}(t,o,e,a);return{cells:t,margin:e,numCells:r,calculatedImageSettings:n}}),[c,o,a,i,s]);return{qrcode:c,margin:h,cells:u,numCells:d,calculatedImageSettings:p}}var bp=function(){try{(new Path2D).addPath(new Path2D)}catch(t){return!1}return!0}();e.forwardRef((function(t,r){const n=t,{value:i,size:s=dp,level:a=pp,bgColor:o=fp,fgColor:l=gp,includeMargin:c=mp,minVersion:u=_p,boostLevel:h,marginSize:d,imageSettings:p}=n,f=cp(n,["value","size","level","bgColor","fgColor","includeMargin","minVersion","boostLevel","marginSize","imageSettings"]),{style:g}=f,m=cp(f,["style"]),_=null==p?void 0:p.src,y=e.useRef(null),v=e.useRef(null),w=e.useCallback((t=>{y.current=t,"function"==typeof r?r(t):r&&(r.current=t)}),[r]),[b,A]=e.useState(!1),{margin:E,cells:x,numCells:k,calculatedImageSettings:S}=wp({value:i,level:a,minVersion:u,boostLevel:h,includeMargin:c,marginSize:d,imageSettings:p,size:s});e.useEffect((()=>{if(null!=y.current){const t=y.current,e=t.getContext("2d");if(!e)return;let r=x;const n=v.current,i=null!=S&&null!==n&&n.complete&&0!==n.naturalHeight&&0!==n.naturalWidth;i&&null!=S.excavation&&(r=vp(x,S.excavation));const a=window.devicePixelRatio||1;t.height=t.width=s*a;const c=s/k*a;e.scale(c,c),e.fillStyle=o,e.fillRect(0,0,k,k),e.fillStyle=l,bp?e.fill(new Path2D(yp(r,E))):x.forEach((function(t,r){t.forEach((function(t,n){t&&e.fillRect(n+E,r+E,1,1)}))})),S&&(e.globalAlpha=S.opacity),i&&e.drawImage(n,S.x+E,S.y+E,S.w,S.h)}})),e.useEffect((()=>{A(!1)}),[_]);const N=lp({height:s,width:s},g);let P=null;return null!=_&&(P=e.createElement("img",{src:_,key:_,style:{display:"none"},onLoad:()=>{A(!0)},ref:v,crossOrigin:null==S?void 0:S.crossOrigin})),e.createElement(e.Fragment,null,e.createElement("canvas",lp({style:N,height:s,width:s,ref:w,role:"img"},m)),P)})).displayName="QRCodeCanvas";var Ap=e.forwardRef((function(t,r){const n=t,{value:i,size:s=dp,level:a=pp,bgColor:o=fp,fgColor:l=gp,includeMargin:c=mp,minVersion:u=_p,boostLevel:h,title:d,marginSize:p,imageSettings:f}=n,g=cp(n,["value","size","level","bgColor","fgColor","includeMargin","minVersion","boostLevel","title","marginSize","imageSettings"]),{margin:m,cells:_,numCells:y,calculatedImageSettings:v}=wp({value:i,level:a,minVersion:u,boostLevel:h,includeMargin:c,marginSize:p,imageSettings:f,size:s});let w=_,b=null;null!=f&&null!=v&&(null!=v.excavation&&(w=vp(_,v.excavation)),b=e.createElement("image",{href:f.src,height:v.h,width:v.w,x:v.x+m,y:v.y+m,preserveAspectRatio:"none",opacity:v.opacity,crossOrigin:v.crossOrigin}));const A=yp(w,m);return e.createElement("svg",lp({height:s,width:s,viewBox:`0 0 ${y} ${y}`,ref:r,role:"img"},g),!!d&&e.createElement("title",null,d),e.createElement("path",{fill:o,d:`M0,0 h${y}v${y}H0z`,shapeRendering:"crispEdges"}),e.createElement("path",{fill:l,d:A,shapeRendering:"crispEdges"}),b)}));Ap.displayName="QRCodeSVG";const Ep=({walletAddress:t,amount:r,currency:n,network:i,theme:s="light",size:a=200})=>{const[o,l]=e.useState(""),[c,u]=e.useState(null);e.useEffect((()=>{if(t&&"No address configured"!==t)try{let e;switch(i){case"tron":e="TRX"===n?`tronlink://transfer?to=${t}&amount=${r}`:t;break;case"algorand":e=`algorand://${t}?amount=${Math.floor(1e6*parseFloat(r))}`;break;case"bsc":if("BNB"===n)e=`ethereum:${t}@56?value=${p(r)}`;else{const i=h(n,"bsc");e=i?`ethereum:${i}/transfer?address=${t}&uint256=${d(r,n)}@56`:t}break;default:if("ETH"===n)e=`ethereum:${t}@1?value=${p(r)}`;else{const i=h(n,"ethereum");e=i?`ethereum:${i}/transfer?address=${t}&uint256=${d(r,n)}`:t}}l(e),u(null)}catch(e){console.error("Error generating QR code:",e),u("Error generating payment QR code")}else u("No wallet address configured for this network")}),[t,r,n,i]);const h=(t,e)=>{var r;return(null==(r={ethereum:{USDT:"0xdAC17F958D2ee523a2206206994597C13D831ec7",USDC:"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"},bsc:{USDT:"0x55d398326f99059fF775485246999027B3197955",USDC:"0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d"},tron:{USDT:"TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t",USDC:"TEkxiTehnzSmSe2XqrBj4w32RUN966rdz8"}}[e])?void 0:r[t])||""},d=(t,e)=>{const r="USDT"===e||"USDC"===e?6:18;return Math.floor(parseFloat(t)*Math.pow(10,r)).toString()},p=t=>Math.floor(1e18*parseFloat(t)).toString(),f=t=>({ethereum:"Ethereum",bsc:"BSC",tron:"Tron",algorand:"Algorand"}[t]||t);return Zd.jsxs("div",{className:"flex flex-col items-center",children:[c?Zd.jsxs("div",{className:"p-4 rounded-lg bg-red-100 mb-3 text-red-700 text-center",children:[Zd.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:Zd.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"})}),Zd.jsx("p",{className:"font-medium",children:c})]}):Zd.jsx("div",{className:"p-4 rounded-lg bg-white mb-3 shadow-sm border",children:o&&Zd.jsx(Ap,{value:o,size:a,bgColor:"dark"===s?"#374151":"#FFFFFF",fgColor:"dark"===s?"#FFFFFF":"#000000",level:"H",includeMargin:!0})}),Zd.jsxs("div",{className:"text-center text-sm text-gray-700 mb-4",children:[Zd.jsxs("p",{className:"font-semibold text-gray-800 flex items-center justify-center",children:[Zd.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:Zd.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]}),Zd.jsxs("p",{className:"text-xs text-gray-500 mt-1",children:["Scan with your ",f(i)," wallet app"]})]}),Zd.jsxs("div",{className:"w-full mb-4 p-3 bg-gray-50 rounded-lg",children:[Zd.jsxs("div",{className:"flex justify-between items-center",children:[Zd.jsx("span",{className:"text-sm font-medium text-gray-700",children:"Amount to Pay:"}),Zd.jsxs("span",{className:"text-lg font-bold text-[#7042D2]",children:[r," ",n]})]}),Zd.jsxs("div",{className:"flex justify-between items-center mt-1",children:[Zd.jsx("span",{className:"text-xs text-gray-500",children:"Network:"}),Zd.jsx("span",{className:"text-xs font-medium text-gray-700",children:f(i)})]})]}),!c&&Zd.jsxs("div",{className:"w-full mb-4",children:[Zd.jsx("p",{className:"text-xs text-gray-500 mb-1 text-center",children:"Or copy wallet address:"}),Zd.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 e;return null==(e=navigator.clipboard)?void 0:e.writeText(t)},title:"Click to copy",children:t})]}),Zd.jsx("div",{className:"w-full",children:Zd.jsxs("div",{className:"p-3 rounded bg-blue-50 border border-blue-200",children:[Zd.jsxs("h4",{className:"text-sm font-medium mb-2 text-blue-800 flex items-center",children:[Zd.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:Zd.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"]}),Zd.jsxs("ol",{className:"text-xs space-y-1 text-blue-700",children:[Zd.jsxs("li",{children:["1. Open your crypto wallet app (",(g=i,{ethereum:["MetaMask","Trust Wallet","Coinbase Wallet"],bsc:["MetaMask","Trust Wallet","SafePal"],tron:["TronLink","Trust Wallet"],algorand:["Pera Wallet","MyAlgo Wallet"]}[g]||["MetaMask","Trust Wallet"]).join(", "),")"]}),Zd.jsx("li",{children:"2. Scan the QR code above or copy the wallet address"}),Zd.jsxs("li",{children:["3. Send exactly ",Zd.jsxs("strong",{children:[r," ",n]})," on ",f(i)," network"]}),Zd.jsx("li",{children:'4. Click "I have sent the payment" button below after sending'})]}),Zd.jsx("div",{className:"mt-3 p-2 bg-yellow-50 border border-yellow-200 rounded",children:Zd.jsxs("p",{className:"text-xs text-yellow-800",children:[Zd.jsx("strong",{children:"Important:"})," Make sure you're sending on the correct network (",f(i),") and using the exact amount shown above."]})})]})})]});var g},xp=({status:t,message:r,theme:n="light",payment:i=null,transactionHash:s=null,selectedPaymentMethod:a=null,merchantName:o="Merchant"})=>{const[l,c]=e.useState(!1),u=()=>__async(this,null,(function*(){if(s)try{yield navigator.clipboard.writeText(s),c(!0),setTimeout((()=>c(!1)),2e3)}catch(t){console.error("Failed to copy transaction hash:",t)}})),h=()=>{switch(t){case"processing":return Zd.jsx("div",{className:"animate-spin rounded-full h-12 w-12 border-4 border-t-blue-500 border-blue-500/20"});case"success":return Zd.jsx("div",{className:"rounded-full h-16 w-16 bg-green-500 flex items-center justify-center",children:Zd.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-10 w-10 text-white",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:3,children:Zd.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5 13l4 4L19 7"})})});case"error":return Zd.jsx("div",{className:"rounded-full h-12 w-12 bg-red-100 flex items-center justify-center",children:Zd.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:Zd.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})})});default:return null}};return"success"===t?Zd.jsxs("div",{className:"flex flex-col items-center justify-center py-6",children:[Zd.jsx("div",{className:"mb-6",children:h()}),Zd.jsx("h3",{className:"text-2xl font-bold mb-3 "+("dark"===n?"text-white":"text-gray-900"),children:"Payment Successful"}),i&&a&&Zd.jsxs("p",{className:"text-center mb-6 "+("dark"===n?"text-gray-300":"text-gray-600"),children:["Your payment of ",i.totalAmount||i.amount," ",a.currency," has been completed."]}),s&&Zd.jsxs("div",{className:"w-full mb-6",children:[Zd.jsx("p",{className:"text-sm font-medium mb-2 "+("dark"===n?"text-gray-300":"text-gray-700"),children:"Transaction Hash:"}),Zd.jsxs("div",{className:"flex items-center justify-between p-3 rounded-lg border cursor-pointer transition-colors "+("dark"===n?"bg-gray-700 border-gray-600 hover:bg-gray-600":"bg-gray-50 border-gray-200 hover:bg-gray-100"),onClick:u,children:[Zd.jsx("span",{className:"font-mono text-sm "+("dark"===n?"text-gray-300":"text-gray-700"),children:(f=s,f?f.length<=16?f:`${f.slice(0,8)}...${f.slice(-8)}`:"")}),Zd.jsxs("div",{className:"flex items-center",children:[l?Zd.jsx("span",{className:"text-green-500 text-xs font-medium mr-2",children:"Copied!"}):null,Zd.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-4 w-4 "+("dark"===n?"text-gray-400":"text-gray-500"),fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:Zd.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})]})]})]}),Zd.jsx("div",{className:"w-full p-4 rounded-lg border "+("dark"===n?"bg-gray-700 border-gray-600":"bg-gray-50 border-gray-200"),children:Zd.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[Zd.jsxs("div",{children:[Zd.jsx("p",{className:"text-xs font-medium mb-1 "+("dark"===n?"text-gray-400":"text-gray-500"),children:"Merchant ID:"}),Zd.jsx("p",{className:"text-sm font-medium "+("dark"===n?"text-gray-300":"text-gray-700"),children:o})]}),Zd.jsxs("div",{children:[Zd.jsx("p",{className:"text-xs font-medium mb-1 "+("dark"===n?"text-gray-400":"text-gray-500"),children:"Network:"}),Zd.jsx("p",{className:"text-sm font-medium "+("dark"===n?"text-gray-300":"text-gray-700"),children:a?(p=a.network,{ethereum:"Ethereum",bsc:"BSC",tron:"TRON",algorand:"Algorand"}[p]||p):"N/A"})]}),Zd.jsxs("div",{className:"col-span-2",children:[Zd.jsx("p",{className:"text-xs font-medium mb-1 "+("dark"===n?"text-gray-400":"text-gray-500"),children:"Recipient:"}),Zd.jsx("p",{className:"text-sm font-mono "+("dark"===n?"text-gray-300":"text-gray-700"),children:(null==i?void 0:i.recipientWallet)?(d=i.recipientWallet,d?d.length<=16?d:`${d.slice(0,6)}...${d.slice(-4)}`:"N/A"):"N/A"})]})]})})]}):Zd.jsxs("div",{className:"flex flex-col items-center justify-center py-6",children:[Zd.jsx("div",{className:"mb-4",children:h()}),Zd.jsx("h3",{className:"text-xl font-bold mb-2 "+("dark"===n?"text-white":"text-gray-900"),children:(()=>{switch(t){case"processing":return"Processing Payment";case"success":return"Payment Successful";case"error":return"Payment Failed";default:return"Unknown Status"}})()}),Zd.jsx("p",{className:`text-center ${(()=>{switch(t){case"processing":return"dark"===n?"text-blue-300":"text-blue-600";case"success":return"dark"===n?"text-green-300":"text-green-600";case"error":return"dark"===n?"text-red-300":"text-red-600";default:return"dark"===n?"text-gray-300":"text-gray-600"}})()}`,children:r}),"processing"===t&&Zd.jsx("div",{className:"mt-4 text-xs "+("dark"===n?"text-gray-400":"text-gray-500"),children:"This may take a few moments. Please do not close this window."}),"error"===t&&Zd.jsx("div",{className:"mt-4 p-2 rounded "+("dark"===n?"bg-gray-700":"bg-gray-100"),children:Zd.jsx("p",{className:"text-xs "+("dark"===n?"text-gray-300":"text-gray-600"),children:"Please try again or contact support if the problem persists."})})]});var d,p,f},kp=({onSelect:t,selected:r,theme:n="light",supportedNetworks:i=[]})=>{var s,a,o;const[l,c]=e.useState(md.ETHEREUM),[u,h]=e.useState(null),[d,p]=e.useState({}),[f,g]=e.useState(!1),m=[{id:md.ETHEREUM,name:"Ethereum",icon:"https://res.cloudinary.com/do3tlu1ph/image/upload/v1748962844/coinley/liznxm8l7iouudtrxdpi.png"},{id:md.TRON,name:"Tron",icon:"https://res.cloudinary.com/do3tlu1ph/image/upload/v1748962844/coinley/mpxxns6gtfiws4rlouxc.png"},{id:md.ALGORAND,name:"Algorand",icon:"https://res.cloudinary.com/do3tlu1ph/image/upload/v1748962844/coinley/x2lugizoduiphuqn0dej.png"},{id:"solana",name:"Solana",icon:" https://res.cloudinary.com/do3tlu1ph/image/upload/v1748962845/coinley/hmex6qxnlid1gboh4cwc.png"},{id:md.BSC,name:"Binance Smart Chain",icon:"https://res.cloudinary.com/do3tlu1ph/image/upload/v1748962844/coinley/eoavfddfqmt7qgajjxvb.png"}],[_,y]=e.useState(!1),v=e.useRef(null);e.useEffect((()=>{function t(t){v.current&&!v.current.contains(t.target)&&y(!1)}return _?document.addEventListener("mousedown",t):document.removeEventListener("mousedown",t),()=>document.removeEventListener("mousedown",t)}),[_]),e.useEffect((()=>{p(bd())}),[]);const w=(t=>{const e=[];switch(t){case md.ETHEREUM:e.push({id:"USDT",name:"USDT",description:"Tether USD",logo:"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSj0euZAOXsLTJFQxgiKzlX7z8xbfBk-7kmJA&s",network:md.ETHEREUM},{id:"USDC",name:"USDC",description:"USD Coin",logo:"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ43MuDqq54iD1ZCRL_uthAPkfwSSL-J5qI_Q&s",network:md.ETHEREUM},{id:"PYUSD",name:"PYUSD",description:"PayPal USD",logo:"https://s2.coinmarketcap.com/static/img/coins/64x64/28492.png",network:md.ETHEREUM},{id:"FRAX",name:"FRAX",description:"Frax",logo:"https://s2.coinmarketcap.com/static/img/coins/64x64/6952.png",network:md.ETHEREUM},{id:"USDP",name:"USDP",description:"Pax Dollar",logo:"https://s2.coinmarketcap.com/static/img/coins/64x64/6662.png",network:md.ETHEREUM},{id:"DAI",name:"DAI",description:"Dai Stablecoin",logo:"https://s2.coinmarketcap.com/static/img/coins/64x64/4943.png",network:md.ETHEREUM},{id:"ETH",name:"ETH",description:"Ethereum",logo:"/eth.png",network:md.ETHEREUM});break;case md.BSC:e.push({id:"USDT",name:"USDT",description:"Tether USD",logo:"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSj0euZAOXsLTJFQxgiKzlX7z8xbfBk-7kmJA&s",network:md.BSC},{id:"USDC",name:"USDC",description:"USD Coin",logo:"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ43MuDqq54iD1ZCRL_uthAPkfwSSL-J5qI_Q&s",network:md.BSC},{id:"BUSD",name:"BUSD",description:"Binance USD",logo:"https://s2.coinmarketcap.com/static/img/coins/64x64/4687.png",network:md.BSC},{id:"FRAX",name:"FRAX",description:"Frax",logo:"https://s2.coinmarketcap.com/static/img/coins/64x64/6952.png",network:md.BSC},{id:"BNB",name:"BNB",description:"Binance Coin",logo:"/bnb.png",network:md.BSC});break;case md.TRON:e.push({id:"USDT",name:"USDT",description:"Tether USD",logo:"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSj0euZAOXsLTJFQxgiKzlX7z8xbfBk-7kmJA&s",network:md.TRON},{id:"USDC",name:"USDC",description:"USD Coin",logo:"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ43MuDqq54iD1ZCRL_uthAPkfwSSL-J5qI_Q&s",network:md.TRON},{id:"USDJ",name:"USDJ",description:"JUST Stablecoin",logo:"https://s2.coinmarketcap.com/static/img/coins/64x64/5446.png",network:md.TRON},{id:"TRX",name:"TRX",description:"Tron",logo:"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQKLpLNsGRHbZfCUXAjZLPSp_YFZvX5dMnAoA&s",network:md.TRON});break;case md.ALGORAND:e.push({id:"USDC",name:"USDC",description:"USD Coin",logo:"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ43MuDqq54iD1ZCRL_uthAPkfwSSL-J5qI_Q&s",network:md.ALGORAND},{id:"USDT",name:"USDT",description:"Tether USD",logo:"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSj0euZAOXsLTJFQxgiKzlX7z8xbfBk-7kmJA&s",network:md.ALGORAND},{id:"ALGO",name:"ALGO",description:"Algorand",logo:"https://s2.coinmarketcap.com/static/img/coins/64x64/4030.png",network:md.ALGORAND})}return e})(l),b=f?w:w.slice(0,4);function A(t){switch(t){case md.ETHEREUM:case md.BSC:return gd.METAMASK;case md.TRON:return gd.TRONLINK;case md.ALGORAND:return gd.LUTE;default:return gd.METAMASK}}return Zd.jsxs("div",{className:"",children:[Zd.jsxs("div",{className:"mb-6",children:[Zd.jsx("label",{className:"block text-sm font-medium mb-2 "+("dark"===n?"text-white":"text-gray-700"),children:"Blockchain Network"}),Zd.jsxs("div",{className:"relative",ref:v,children:[Zd.jsxs("button",{type:"button",className:"w-full flex items-center justify-between px-5 py-4 bg-white rounded-2xl shadow border border-gray-200 text-gray-900 text-base font-normal focus:outline-none focus:ring-2 focus:ring-[#7042D2] focus:ring-opacity-50 transition",onClick:()=>y((t=>!t)),style:{minHeight:"56px"},children:[Zd.jsxs("span",{className:"flex items-center gap-3",children:[Zd.jsx("img",{src:null==(s=m.find((t=>t.id===l)))?void 0:s.icon,alt:null==(a=m.find((t=>t.id===l)))?void 0:a.name,className:"w-6 h-6"}),Zd.jsx("span",{className:"text-base font-normal",children:null==(o=m.find((t=>t.id===l)))?void 0:o.name})]}),Zd.jsx("svg",{className:"w-5 h-5 ml-2 transition-transform "+(_?"rotate-180":""),fill:"none",stroke:"currentColor",strokeWidth:"2",viewBox:"0 0 24 24",children:Zd.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M19 9l-7 7-7-7"})})]}),_&&Zd.jsx("div",{className:"absolute left-0 mt-2 w-full bg-white rounded-2xl shadow-lg border border-gray-100 z-20",style:{minWidth:"100%"},children:m.filter((t=>0===i.length||i.includes(t.id))).map((t=>Zd.jsxs("button",{type:"button",className:"w-full flex items-center gap-3 px-5 py-3 text-gray-900 text-base font-normal rounded-2xl transition hover:bg-gray-100 "+(l===t.id?"bg-gray-50":""),onClick:()=>{var e;y(!1),e=t.id,c(e),g(!1),h(null)},style:{minHeight:"48px"},children:[Zd.jsx("img",{src:t.icon,alt:t.name,className:"w-6 h-6"}),Zd.jsx("span",{children:t.name})]},t.id)))})]})]}),Zd.jsxs("div",{className:"mb-4",children:[Zd.jsx("label",{className:"block text-sm font-medium mb-3 "+("dark"===n?"text-white":"text-gray-700"),children:"Select Stablecoin"}),Zd.jsx("div",{className:"grid grid-cols-2 gap-3 mb-4",children:b.map((t=>{const e=(null==u?void 0:u.currency)===t.id&&(null==u?void 0:u.network)===l;return Zd.jsxs("button",{onClick:()=>(t=>{var e;const r={currency:t.id,network:l,tokenConfig:null==(e=yd[t.id])?void 0:e[l],method:t};h(r)})(t),className:`group flex items-center justify-between w-full px-5 py-4 rounded-2xl border text-left transition-all duration-200 font-medium text-base\n ${e?"bg-[#E9DDFC] border-transparent shadow-none":"bg-white border-gray-200 hover:bg-[#F6F2FF] hover:border-[#E9DDFC]"}\n `,style:{minHeight:"56px"},children:[Zd.jsxs("span",{className:"flex items-center gap-3",children:[Zd.jsx("img",{src:t.logo,alt:t.name,className:"h-6 w-6"}),Zd.jsxs("span",{className:"font-medium text-base text-gray-900",children:[t.description," (",t.name,")"]})]}),e&&Zd.jsx("span",{className:"ml-2 flex items-center justify-center w-6 h-6 rounded-full bg-[#7042D2]",children:Zd.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:Zd.jsx("path",{d:"M4 8.5L7 11.5L12 6.5",stroke:"white",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})})]},`${t.id}-${t.network}`)}))}),w.length>4&&Zd.jsx("button",{onClick:()=>g(!f),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:f?"Show Less":`Show More (${w.length-4} more)`})]}),Zd.jsx("div",{className:"p-3 rounded-lg text-sm mb-6 "+("dark"===n?"bg-gray-800 text-gray-300":"bg-gray-50 text-gray-600"),children:Zd.jsxs("div",{className:"flex items-center",children:[Zd.jsx("div",{className:"w-2 h-2 rounded-full mr-2 "+(d[A(l)]?"bg-green-500":"bg-red-500")}),Zd.jsx("span",{className:"text-xs",children:function(t){const e=A(t),r=d[e],n={[gd.METAMASK]:"MetaMask",[gd.TRONLINK]:"TronLink",[gd.TRUST_WALLET]:"Trust Wallet",[gd.LUTE]:"Lute Wallet"};return r?`${n[e]} detected - Ready to pay`:`${n[e]} required - Please install to continue`}(l)})]})}),Zd.jsx("button",{onClick:()=>{u&&t(u)},disabled:!u,className:"w-full py-3 px-4 font-medium rounded-2xl text-lg shadow-md transition-colors "+(u?"bg-[#7042D2] text-white hover:bg-[#5b34b1]":"bg-gray-300 text-gray-500 cursor-not-allowed"),style:{borderRadius:"1.5rem"},children:"Proceed"})]})},Sp=({isOpen:t,onClose:r,payment:n,paymentStatus:i,selectedPaymentMethod:s,onPaymentMethodSelect:a,onPayment:o,onBack:l,error:c,theme:u="light",merchantName:h,transactionHash:d,walletConnection:p,onConnectWallet:f,testMode:g=!1,supportedNetworks:m=[],availableWallets:_={},supportedWallets:y=[],step:v="select-currency",merchantWalletAddresses:w={},debug:b=!1})=>{const[A,E]=e.useState("wallet"),x=t=>({ethereum:"Ethereum",bsc:"BSC",tron:"Tron",algorand:"Algorand"}[t]||t),k=t=>({[gd.METAMASK]:"MetaMask",[gd.TRONLINK]:"TronLink",[gd.TRUST_WALLET]:"Trust Wallet",[gd.LUTE]:"Lute Wallet"}[t]||t),S=t=>({[gd.METAMASK]:"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcT3ymr3UNKopfI0NmUY95Dr-0589vG-91KuAA&s",[gd.TRONLINK]:"https://www.tronlink.org/images/logo.png",[gd.TRUST_WALLET]:"https://trustwallet.com/assets/images/trust_logotype.svg",[gd.LUTE]:"https://lute.app/logo.png"}[t]||"");return t?Zd.jsx("div",{className:"fixed inset-0 z-50 overflow-y-auto",children:Zd.jsx("div",{className:"flex min-h-screen items-center justify-center p-4",children:Zd.jsxs("div",{className:"coinley-modal relative p-6 w-full max-w-[490px] mx-auto rounded-3xl shadow-xl bg-gray-100",style:{maxWidth:"490px !important",width:"100% !important",minWidth:"320px !important"},children:[Zd.jsxs("div",{className:"bg-white flex justify-between items-center mb-6 py-4 px-2 rounded-full",children:[Zd.jsxs("div",{className:"flex-1 flex items-center gap-2 px-4",children:[Zd.jsx("img",{src:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAbCAYAAABm409WAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAMFSURBVHgBpVZBVtswEJXk7JsjmAM0hF13dWDTHeEEhF13MScgOQHmBIQT1Oy6KXFPACEHIDdouux7WNM/kuxIdvJeXpj3iOSR9P9oRjODFHtIevp6y2P21LsO9MlzLFQ0x3SKtdm2s0rsJ0PGS08XaXg6usFvjL+vuw7uS+BE3sDqLs/cOLJ6+rvrRMf/sFdWQ6F1nhUnqw2uXAmiGLMurObbzEQUJYLqHasGDvZ1xkK/P4Y3kGqCn1uAvKWny5taT3rh7bLuIEpqjdYv1fQ6WY75PDYAK4pDAtIz72OC4N47gHyjpr4z5thp1rhtYSyHUaQoMzclWmVFLw8IzEYpC081YpJAL2XXEcVuT16BW6stKYwd8KQd5PL9gtkbJCPopw547YjsqMupid0GHDpxXcWwRYAFy05U+xVgY+eGK0HyzhkyBfjAAEWd+9pyKS7gmll9lIMCv6XGb+ZqeBGSHo3flRrh+9IQz4+PxA5JB4tnQOFseRW8PibA9f848C0iJ9nTZ3ZB19zsAIm+HH3/B6BvO9YTrMts3v8pDhSVPR1n8OURfP4g2EVN0UiyD4hsKtJkmQjlnqAu80NdExDY1OaAynNoEm8dAceT+9XLxYHS8Upu3L4PdLYkHEyg8IZ/CFty28K5oP3ycQgB6d9tYFEIrpj8tlX0jKf8VpXpbcINKT17HW5bq2LABawCWKHUXgapz6LLEzNGUcwxwZkE866b99mQKm9aBL64zM7CG6E2cfngWBEtkNVDZO8MJeSciTl7bbeT3Fozv7UGtYgDDvCJaN/zwTQiEyv5yVvh12faqMknQWx96veSRrEzIN2G9S84PAHw2JLRwpG6/JCXVXzsPibhXmJJGh1N9ENwBBuucTGKjU5LV2WrkQ1C+3RiSHSJkq9HHKdmR8vM02RgLsXz3sBksoo84rKwROUmN5TXPoUp+blrOOtOY4GtOhEt4TYpzY2qcszE6dmysIkYxKXCMvv2+7eFXFxIPAT6usvtSNS9CUw/pju/Uzkrba+uAr9F/gPbu3s2LSnvkAAAAABJRU5ErkJggg==",className:"w-auto h-auto",alt:"Coinley Logo"}),Zd.jsx("span",{className:"text-lg font-semibold text-gray-800",children:"Payment Details"})]}),Zd.jsx("button",{onClick:r,className:"text-gray-500 hover:text-gray-700 focus:outline-none",children:Zd.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-6 w-6",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:Zd.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),n&&Zd.jsx("div",{className:"mb-6",children:Zd.jsxs("div",{className:"text-center",children:[Zd.jsx("div",{className:"text-sm text-gray-600",children:"Total amount"}),Zd.jsxs("div",{className:"coinley-amount-display text-5xl font-bold text-[#7042D2] mt-2",children:["$",(N=n.totalAmount||n.amount,parseFloat(N).toFixed(2))]}),Zd.jsx("div",{className:"text-sm text-gray-600 mt-4",children:"Payment to:"}),Zd.jsx("div",{className:"coinley-merchant-name text-base font-semibold mt-1",children:h})]})}),"select-currency"===v&&Zd.jsx("div",{className:"mb-6",children:Zd.jsx(kp,{onSelect:a,selected:s,theme:u,supportedNetworks:m})}),"confirm"===v&&s&&n&&Zd.jsxs("div",{children:[Zd.jsxs("div",{className:"p-4 rounded-lg mb-4 bg-gray-100",children:[Zd.jsx("h3",{className:"text-lg font-medium mb-2 text-gray-800",children:"Payment Details"}),Zd.jsxs("div",{className:"space-y-2",children:[Zd.jsxs("div",{className:"flex justify-between",children:[Zd.jsx("span",{className:"text-purple-600 font-semibold",children:"Currency:"}),Zd.jsx("span",{className:"font-medium",children:s.currency})]}),Zd.jsxs("div",{className:"flex justify-between",children:[Zd.jsx("span",{className:"text-purple-600 font-semibold",children:"Network:"}),Zd.jsx("span",{className:"font-medium",children:x(s.network)})]}),Zd.jsxs("div",{className:"flex justify-between",children:[Zd.jsx("span",{className:"text-purple-600 font-semibold",children:"Fee:"}),Zd.jsx("span",{className:"font-medium",children:"1.75%"})]})]})]}),Zd.jsx("div",{className:"mb-4",children:Zd.jsxs("div",{className:"flex border-b border-gray-200",children:[Zd.jsx("button",{onClick:()=>E("wallet"),className:"py-2 px-4 text-sm font-medium "+("wallet"===A?"border-b-2 border-purple-600 text-purple-600":"text-gray-500 hover:text-gray-700"),children:"Connect Wallet"}),Zd.jsx("button",{onClick:()=>E("qrcode"),className:"py-2 px-4 text-sm font-medium "+("qrcode"===A?"border-b-2 border-purple-600 text-purple-600":"text-gray-500 hover:text-gray-700"),children:"QR Code"})]})}),g?Zd.jsx("div",{className:"p-4 rounded-lg mb-4 bg-blue-50",children:Zd.jsxs("div",{className:"flex items-center",children:[Zd.jsx("div",{className:"bg-purple-600 rounded-full p-2 mr-3",children:Zd.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:Zd.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 10V3L4 14h7v7l9-11h-7z"})})}),Zd.jsxs("div",{children:[Zd.jsx("h3",{className:"font-medium text-gray-800",children:"Test Mode Payment"}),Zd.jsx("p",{className:"text-sm text-gray-600",children:'Click "Pay Now" to simulate a successful payment'})]})]})}):"qrcode"===A?Zd.jsx("div",{className:"mb-4",children:Zd.jsx(Ep,{walletAddress:(()=>{if(!s)return"No network selected";const t=w[s.network];return t||((null==n?void 0:n.recipientWallet)?n.recipientWallet:"No wallet address configured for this network")})(),amount:n.totalAmount||n.amount,currency:s.currency,network:s.network,theme:u})}):Zd.jsxs("div",{className:"space-y-3 mb-4",children:[0===y.length?Zd.jsx("div",{className:"p-4 rounded-lg bg-yellow-50",children:Zd.jsxs("div",{className:"flex items-center",children:[Zd.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:Zd.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"})}),Zd.jsxs("div",{children:[Zd.jsx("h3",{className:"font-medium text-gray-800",children:"No Compatible Wallets"}),Zd.jsxs("p",{className:"text-sm text-gray-600",children:["No wallets detected for ",x(s.network)," network"]})]})]})}):y.map((t=>Zd.jsx("div",{className:"p-4 rounded-lg bg-blue-50",children:Zd.jsxs("div",{className:"flex items-center justify-between",children:[Zd.jsxs("div",{className:"flex items-center",children:[Zd.jsx("img",{src:S(t),alt:k(t),className:"w-8 h-8 mr-3",onError:t=>{t.target.style.display="none"}}),Zd.jsxs("div",{children:[Zd.jsx("h3",{className:"font-medium text-gray-800",children:k(t)}),Zd.jsxs("p",{className:"text-sm text-gray-600",children:["Pay with ",k(t)]})]})]}),(null==p?void 0:p.walletType)===t?Zd.jsxs("div",{className:"flex items-center space-x-2",children:[Zd.jsx("div",{className:"w-2 h-2 bg-green-500 rounded-full"}),Zd.jsx("span",{className:"text-sm text-green-600",children:"Connected"})]}):Zd.jsx("button",{onClick:()=>{console.log("Connect wallet button clicked for:",t),f(t)},className:"coinley-button-primary py-2 px-4 font-medium rounded-md text-sm",children:"Connect"})]})},t))),Zd.jsx("div",{className:"space-y-2",children:Object.entries(_).filter((([t,e])=>!e)).map((([t])=>Zd.jsx("div",{className:"p-3 rounded-lg bg-gray-50",children:Zd.jsxs("div",{className:"flex items-center justify-between",children:[Zd.jsxs("span",{className:"text-sm text-gray-600",children:[k(t)," not detected"]}),Zd.jsx("a",{href:wd(t),target:"_blank",rel:"noopener noreferrer",className:"text-sm text-purple-600 hover:underline",children:"Install"})]})},t)))})]}),c&&Zd.jsx("div",{className:"p-3 rounded-lg bg-red-50 mb-4 text-red-600 text-sm",children:c}),Zd.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[Zd.jsx("button",{type:"button",onClick:l,className:"w-full py-2 px-4 bg-gray-200 hover:bg-gray-300 text-purple-600 font-medium rounded-md",children:"Back"}),Zd.jsx("button",{type:"button",onClick:()=>o("qrcode"===A),className:"coinley-button-primary w-full py-2 px-4 font-medium rounded-md",disabled:!g&&"wallet"===A&&!p,children:"qrcode"===A?"I have sent the payment":"Pay Now"})]})]}),"processing"===v&&Zd.jsx(xp,{status:"processing",theme:u,message:"Processing your payment..."}),"success"===v&&Zd.jsx(xp,{status:"success",theme:u,message:"Payment successful!",payment:n,transactionHash:d,selectedPaymentMethod:s,merchantName:h}),"error"===v&&Zd.jsxs("div",{children:[Zd.jsx(xp,{status:"error",theme:u,message:c||"An error occurred while processing your payment."}),Zd.jsx("button",{type:"button",onClick:l,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"})]}),Zd.jsxs("div",{className:"text-center text-xs text-gray-500 flex items-center justify-center gap-1 mt-6",children:[Zd.jsxs("p",{children:["Powered by ",Zd.jsx("span",{className:"text-purple-600",children:"Coinley"})," - Secure Cryptocurrency Payments"]}),Zd.jsxs("svg",{className:"inline w-4 h-4 text-green-500 ml-1",fill:"none",stroke:"currentColor",strokeWidth:"2",viewBox:"0 0 24 24",children:[Zd.jsx("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"2",fill:"none"}),Zd.jsx("path",{d:"M9 12l2 2 4-4",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]})]})]})})}):null;var N},Np=e.forwardRef((({apiKey:t,apiSecret:r,apiUrl:n,customerEmail:i,merchantName:s="Merchant",merchantWalletAddresses:a={},onSuccess:o,onError:l,onClose:c,theme:u,autoOpen:h=!1,debug:d=!1,testMode:p=!1,supportedNetworks:f=[],preferredNetwork:g=md.ETHEREUM,preferredWallet:m=gd.METAMASK},_)=>{const y=tp(),{theme:v}=e.useContext(Xd),[w,b]=e.useState(h),[A,E]=e.useState(null),[x,k]=e.useState("idle"),[S,N]=e.useState(null),[P,C]=e.useState(null),[T,R]=e.useState(null),[M,G]=e.useState(null),[B,I]=e.useState({}),[O,F]=e.useState("select-currency"),[U,L]=e.useState({}),D=t||(null==y?void 0:y.apiKey),j=r||(null==y?void 0:y.apiSecret);n||null==y||y.apiUrl;const H=u||v,W=d||(null==y?void 0:y.debug),Q=f.length>0?f:[md.ETHEREUM,md.BSC,md.TRON,md.ALGORAND],z=(t,e)=>{W&&console.log(`[Coinley SDK] ${t}`,e)};e.useEffect((()=>{D&&j&&(()=>{__async(this,null,(function*(){try{z("Fetching merchant wallet addresses from backend...");const t=yield Ud();L(t),z("Merchant wallets fetched successfully:",t)}catch(t){console.error("Failed to fetch merchant wallets:",t),L(a)}}))})()}),[D,j,a]),e.useEffect((()=>{if("undefined"!=typeof window){(()=>__async(this,null,(function*(){const t=yield Ad(3,1e3);I(t),z("Available wallets detected:",t)})))()}}),[W]),e.useImperativeHandle(_,(()=>({open:t=>{V(t)},close:()=>{K()},getPayment:()=>A,getWalletConnection:()=>M,debugWallets:()=>(()=>{var t;console.log("=== WALLET ENVIRONMENT DEBUG ==="),console.log("ethereum:","undefined"!=typeof window?Boolean(window.ethereum):"Not in browser"),console.log("tronWeb:","undefined"!=typeof window?Boolean(window.tronWeb):"Not in browser"),console.log("lute:","undefined"!=typeof window?Boolean(window.lute):"Not in browser"),"undefined"!=typeof window&&window.ethereum&&console.log("ethereum details:",{isTrust:window.ethereum.isTrust,isMetaMask:window.ethereum.isMetaMask,chainId:window.ethereum.chainId}),"undefined"!=typeof window&&window.tronWeb&&console.log("tronWeb details:",{ready:window.tronWeb.ready,fullNode:null==(t=window.tronWeb.fullNode)?void 0:t.host,defaultAddress:window.tronWeb.defaultAddress});const e=bd();console.log("Detected wallets:",e)})(),getMerchantWallets:()=>U})));const V=t=>__async(this,null,(function*(){if(!t||!t.amount)return C("Payment amount is required"),void(l&&l(new Error("Payment amount is required")));k("loading"),b(!0),F("select-currency");try{z("Creating payment with details:",t);let e=U;0===Object.keys(e).length&&(z("No wallet addresses found, fetching from backend..."),e=yield Ud(),L(e)),z("Using wallet addresses:",e);const r=yield Dd({amount:t.amount,currency:t.currency||"USDT",network:t.network||g,customerEmail:t.customerEmail||i,callbackUrl:t.callbackUrl,metadata:__spreadProps(__spreadValues({},t.metadata),{merchantWalletAddresses:e}),merchantWalletAddresses:e});z("Payment created:",r),E(r.payment),k("idle"),C(null),z("Payment created and state updated")}catch(e){z("Error creating payment:",e),C(e.message||"Failed to create payment"),k("error"),l&&l(e)}})),K=()=>{b(!1),R(null),G(null),N(null),F("select-currency"),c&&c()};return Zd.jsx(Zd.Fragment,{children:w&&Zd.jsx(Sp,{isOpen:w,onClose:K,payment:A,paymentStatus:x,selectedPaymentMethod:S,onPaymentMethodSelect:t=>{console.log("=== PAYMENT METHOD SELECTION DEBUG ==="),console.log("1. Payment method selected:",t),console.log("2. Current step before:",O),z("Payment method selected:",t),N(t),F("confirm"),console.log("3. Step should now be: confirm"),console.log("=== END PAYMENT METHOD SELECTION DEBUG ===")},onPayment:()=>__async(this,null,(function*(){var t,e;if(A&&S)if(M||p){z("Starting payment process..."),k("loading"),R(null),F("processing");try{let r;if(p)z("Test mode: Generating mock transaction..."),r=`test_${Date.now().toString(16)}_${Math.random().toString(16).substring(2,10)}`;else{let n;if(A.recipientWallet)n=A.recipientWallet;else{if(!U[S.network])throw new Error(`No merchant wallet address found for ${S.network} network`);n=U[S.network]}z("Using merchant address for payment:",n),z("Sending transaction through wallet..."),r=yield Td(M,{to:n,amount:A.totalAmount||A.amount,tokenAddress:null==(t=S.tokenConfig)?void 0:t.address,tokenDecimals:null==(e=S.tokenConfig)?void 0:e.decimals,currency:S.currency,network:S.network})}z("Transaction hash:",r),R(r),z("Processing payment with backend...");const n=yield jd({paymentId:A.id,transactionHash:r,network:S.network,currency:S.currency,senderAddress:null==M?void 0:M.address});z("Payment processed successfully:",n),k("success"),F("success"),o&&(z("Calling onSuccess callback..."),o(A.id,r,{network:S.network,currency:S.currency,amount:A.totalAmount||A.amount}))}catch(r){z("Payment error:",r),C(r.message||"Failed to process payment"),k("error"),F("error"),l&&l(r)}}else C("Please connect your wallet first");else C("Missing payment information")})),onBack:()=>{"confirm"===O?(F("select-currency"),G(null)):"error"===O&&F("confirm")},error:P,theme:H,merchantName:s,transactionHash:T,walletConnection:M,onConnectWallet:t=>__async(this,null,(function*(){if(console.log("=== WALLET CONNECTION DEBUG ==="),console.log("1. Wallet type requested:",t),console.log("2. Selected payment method:",S),console.log("3. Available wallets:",B),console.log("4. Current step:",O),!S)return console.error("No payment method selected"),void C("Please select a payment method first");try{console.log("5. Attempting to connect wallet..."),C(null),z("Connecting wallet:",{walletType:t,network:S.network});const e=yield Nd(t,S.network);G(e),C(null),console.log("6. Connection successful:",e),z("Wallet connected successfully:",e)}catch(e){console.error("7. Connection failed:",e),z("Wallet connection error:",e),C(e.message||"Failed to connect wallet")}console.log("=== END WALLET CONNECTION DEBUG ===")})),testMode:p,supportedNetworks:Q,availableWallets:B,supportedWallets:S?Pd(S.network):[],step:O,merchantWalletAddresses:U,debug:W})})}));Np.displayName="CoinleyCheckout";t.CoinleyCheckout=Np,t.CoinleyModal=Sp,t.CoinleyProvider=({apiKey:t,apiSecret:r,apiUrl:n="https://coinleyserver-production.up.railway.app",merchantWalletAddress:i=null,merchantSolWalletAddress:s=null,debug:a=!1,children:o})=>{const[l,c]=e.useState(!1),[u,h]=e.useState(null),[d,p]=e.useState(null),[f,g]=e.useState({});e.useEffect((()=>{if(!t||!r)return void h("API key and secret are required");(()=>{__async(this,null,(function*(){try{yield Od({apiKey:t,apiSecret:r,apiUrl:n,debug:a});const e=yield Ud(),o=__spreadValues(__spreadValues(__spreadValues({},e),i&&{ethereum:i}),s&&{solana:s});g(o),c(!0),a&&console.log("Coinley SDK initialized successfully with wallets:",o)}catch(e){h(e.message),a&&console.error("Coinley SDK initialization error:",e)}}))})()}),[t,r,n,i,s,a]);const m={apiKey:t,apiSecret:r,apiUrl:n,merchantWalletAddress:i,merchantSolWalletAddress:s,merchantWallets:f,isInitialized:l,error:u,debug:a,paymentData:d,storePaymentData:t=>(p(t),t),refreshMerchantWallets:()=>__async(this,null,(function*(){try{const t=yield Ud();return g(t),t}catch(t){return console.error("Failed to refresh merchant wallets:",t),f}}))};return Zd.jsx($d.Provider,{value:m,children:o})},t.DEFAULT_CONFIG={apiUrl:"https://coinleyserver-production.up.railway.app",debug:!1,testMode:!1,theme:"light",supportedNetworks:["ethereum","bsc","tron","algorand"]},t.NETWORK_CONFIG=_d,t.NETWORK_TYPES=md,t.PaymentMethods=kp,t.PaymentStatus=xp,t.QRCode=Ep,t.TOKEN_CONFIG=yd,t.ThemeProvider=({initialTheme:t="light",children:r})=>{const[n,i]=e.useState(t);return e.useEffect((()=>{document.documentElement.classList.remove("light","dark"),document.documentElement.classList.add(n)}),[n]),Zd.jsx(Xd.Provider,{value:{theme:n,setTheme:i,toggleTheme:()=>{i((t=>"light"===t?"dark":"light"))}},children:r})},t.WALLET_TYPES=gd,t.connectWallet=Nd,t.createPayment=Dd,t.detectWallets=bd,t.generateMockTransactionHash=(t="ethereum")=>`${{ethereum:"0x",bsc:"0x",tron:"",algorand:""}[t]||"0x"}${Array.from({length:64},(()=>Math.floor(16*Math.random()).toString(16))).join("")}`,t.getMerchantWallets=Ud,t.getPayment=t=>__async(this,null,(function*(){try{if(console.log("Getting payment:",t),!t)throw new Error("Payment ID is required");const r=yield fetch(`${Id.apiUrl}/api/payments/${t}`,{method:"GET",headers:Ld()});if(!r.ok){let t;try{t=yield r.json()}catch(e){throw new Error(`Failed to get payment: ${r.status} ${r.statusText}`)}throw console.error("Error getting payment:",t),new Error(t.error||`Failed to get payment: ${r.status}`)}const n=yield r.json();return console.log("Get payment response:",n),n}catch(r){throw console.error("Get payment error:",r),r}})),t.getSupportedNetworks=()=>__async(this,null,(function*(){try{const e=yield fetch(`${Id.apiUrl}/api/networks`,{method:"GET",headers:Ld()});if(!e.ok){let r;try{r=yield e.json()}catch(t){throw new Error(`Failed to get networks: ${e.status} ${e.statusText}`)}throw new Error(r.error||`Failed to get networks: ${e.status}`)}return yield e.json()}catch(e){throw console.error("Get supported networks error:",e),e}})),t.getSupportedWalletsForNetwork=Pd,t.getWalletInstallUrl=wd,t.processPayment=jd,t.sendTransaction=Td,t.useCoinley=tp,t.validateWalletAddress=(t,e)=>__async(this,null,(function*(){try{const n=yield fetch(`${Id.apiUrl}/api/wallets/validate`,{method:"POST",headers:Ld(),body:JSON.stringify({address:t,network:e})});if(!n.ok){let t;try{t=yield n.json()}catch(r){throw new Error(`Failed to validate address: ${n.status} ${n.statusText}`)}throw new Error(t.error||`Failed to validate address: ${n.status}`)}return yield n.json()}catch(n){throw console.error("Validate wallet address error:",n),n}})),Object.defineProperty(t,Symbol.toStringTag,{value:"Module"})}));
16
+ */function yp(t,e=0){const r=[];return t.forEach((function(t,n){let i=null;t.forEach((function(s,a){if(!s&&null!==i)return r.push(`M${i+e} ${n+e}h${a-i}v1H${i+e}z`),void(i=null);if(a!==t.length-1)s&&null===i&&(i=a);else{if(!s)return;null===i?r.push(`M${a+e},${n+e} h1v1H${a+e}z`):r.push(`M${i+e},${n+e} h${a+1-i}v1H${i+e}z`)}}))})),r.join("")}function vp(t,e){return t.slice().map(((t,r)=>r<e.y||r>=e.y+e.h?t:t.map(((t,r)=>(r<e.x||r>=e.x+e.w)&&t))))}function wp({value:t,level:r,minVersion:n,includeMargin:i,marginSize:s,imageSettings:a,size:o,boostLevel:l}){let c=e.useMemo((()=>{const e=(Array.isArray(t)?t:[t]).reduce(((t,e)=>(t.push(...up.QrSegment.makeSegments(e)),t)),[]);return up.QrCode.encodeSegments(e,hp[r],n,void 0,void 0,l)}),[t,r,n,l]);const{cells:u,margin:h,numCells:d,calculatedImageSettings:p}=e.useMemo((()=>{let t=c.getModules();const e=function(t,e){return null!=e?Math.max(Math.floor(e),0):t?4:0}(i,s),r=t.length+2*e,n=function(t,e,r,n){if(null==n)return null;const i=t.length+2*r,s=Math.floor(.1*e),a=i/e,o=(n.width||s)*a,l=(n.height||s)*a,c=null==n.x?t.length/2-o/2:n.x*a,u=null==n.y?t.length/2-l/2:n.y*a,h=null==n.opacity?1:n.opacity;let d=null;if(n.excavate){let t=Math.floor(c),e=Math.floor(u);d={x:t,y:e,w:Math.ceil(o+c-t),h:Math.ceil(l+u-e)}}return{x:c,y:u,h:l,w:o,excavation:d,opacity:h,crossOrigin:n.crossOrigin}}(t,o,e,a);return{cells:t,margin:e,numCells:r,calculatedImageSettings:n}}),[c,o,a,i,s]);return{qrcode:c,margin:h,cells:u,numCells:d,calculatedImageSettings:p}}var bp=function(){try{(new Path2D).addPath(new Path2D)}catch(t){return!1}return!0}();e.forwardRef((function(t,r){const n=t,{value:i,size:s=dp,level:a=pp,bgColor:o=fp,fgColor:l=gp,includeMargin:c=mp,minVersion:u=_p,boostLevel:h,marginSize:d,imageSettings:p}=n,f=cp(n,["value","size","level","bgColor","fgColor","includeMargin","minVersion","boostLevel","marginSize","imageSettings"]),{style:g}=f,m=cp(f,["style"]),_=null==p?void 0:p.src,y=e.useRef(null),v=e.useRef(null),w=e.useCallback((t=>{y.current=t,"function"==typeof r?r(t):r&&(r.current=t)}),[r]),[b,A]=e.useState(!1),{margin:E,cells:x,numCells:k,calculatedImageSettings:S}=wp({value:i,level:a,minVersion:u,boostLevel:h,includeMargin:c,marginSize:d,imageSettings:p,size:s});e.useEffect((()=>{if(null!=y.current){const t=y.current,e=t.getContext("2d");if(!e)return;let r=x;const n=v.current,i=null!=S&&null!==n&&n.complete&&0!==n.naturalHeight&&0!==n.naturalWidth;i&&null!=S.excavation&&(r=vp(x,S.excavation));const a=window.devicePixelRatio||1;t.height=t.width=s*a;const c=s/k*a;e.scale(c,c),e.fillStyle=o,e.fillRect(0,0,k,k),e.fillStyle=l,bp?e.fill(new Path2D(yp(r,E))):x.forEach((function(t,r){t.forEach((function(t,n){t&&e.fillRect(n+E,r+E,1,1)}))})),S&&(e.globalAlpha=S.opacity),i&&e.drawImage(n,S.x+E,S.y+E,S.w,S.h)}})),e.useEffect((()=>{A(!1)}),[_]);const N=lp({height:s,width:s},g);let P=null;return null!=_&&(P=e.createElement("img",{src:_,key:_,style:{display:"none"},onLoad:()=>{A(!0)},ref:v,crossOrigin:null==S?void 0:S.crossOrigin})),e.createElement(e.Fragment,null,e.createElement("canvas",lp({style:N,height:s,width:s,ref:w,role:"img"},m)),P)})).displayName="QRCodeCanvas";var Ap=e.forwardRef((function(t,r){const n=t,{value:i,size:s=dp,level:a=pp,bgColor:o=fp,fgColor:l=gp,includeMargin:c=mp,minVersion:u=_p,boostLevel:h,title:d,marginSize:p,imageSettings:f}=n,g=cp(n,["value","size","level","bgColor","fgColor","includeMargin","minVersion","boostLevel","title","marginSize","imageSettings"]),{margin:m,cells:_,numCells:y,calculatedImageSettings:v}=wp({value:i,level:a,minVersion:u,boostLevel:h,includeMargin:c,marginSize:p,imageSettings:f,size:s});let w=_,b=null;null!=f&&null!=v&&(null!=v.excavation&&(w=vp(_,v.excavation)),b=e.createElement("image",{href:f.src,height:v.h,width:v.w,x:v.x+m,y:v.y+m,preserveAspectRatio:"none",opacity:v.opacity,crossOrigin:v.crossOrigin}));const A=yp(w,m);return e.createElement("svg",lp({height:s,width:s,viewBox:`0 0 ${y} ${y}`,ref:r,role:"img"},g),!!d&&e.createElement("title",null,d),e.createElement("path",{fill:o,d:`M0,0 h${y}v${y}H0z`,shapeRendering:"crispEdges"}),e.createElement("path",{fill:l,d:A,shapeRendering:"crispEdges"}),b)}));Ap.displayName="QRCodeSVG";const Ep=({walletAddress:t,amount:r,currency:n,network:i,theme:s="light",size:a=200})=>{const[o,l]=e.useState(""),[c,u]=e.useState(null);e.useEffect((()=>{if(t&&"No address configured"!==t)try{let e;switch(i){case"tron":e="TRX"===n?`tronlink://transfer?to=${t}&amount=${r}`:t;break;case"algorand":e=`algorand://${t}?amount=${Math.floor(1e6*parseFloat(r))}`;break;case"bsc":if("BNB"===n)e=`ethereum:${t}@56?value=${p(r)}`;else{const i=h(n,"bsc");e=i?`ethereum:${i}/transfer?address=${t}&uint256=${d(r,n)}@56`:t}break;default:if("ETH"===n)e=`ethereum:${t}@1?value=${p(r)}`;else{const i=h(n,"ethereum");e=i?`ethereum:${i}/transfer?address=${t}&uint256=${d(r,n)}`:t}}l(e),u(null)}catch(e){console.error("Error generating QR code:",e),u("Error generating payment QR code")}else u("No wallet address configured for this network")}),[t,r,n,i]);const h=(t,e)=>{var r;return(null==(r={ethereum:{USDT:"0xdAC17F958D2ee523a2206206994597C13D831ec7",USDC:"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"},bsc:{USDT:"0x55d398326f99059fF775485246999027B3197955",USDC:"0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d"},tron:{USDT:"TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t",USDC:"TEkxiTehnzSmSe2XqrBj4w32RUN966rdz8"}}[e])?void 0:r[t])||""},d=(t,e)=>{const r="USDT"===e||"USDC"===e?6:18;return Math.floor(parseFloat(t)*Math.pow(10,r)).toString()},p=t=>Math.floor(1e18*parseFloat(t)).toString(),f=t=>({ethereum:"Ethereum",bsc:"BSC",tron:"Tron",algorand:"Algorand"}[t]||t);return Zd.jsxs("div",{className:"flex flex-col items-center",children:[c?Zd.jsxs("div",{className:"p-4 rounded-lg bg-red-100 mb-3 text-red-700 text-center",children:[Zd.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:Zd.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"})}),Zd.jsx("p",{className:"font-medium",children:c})]}):Zd.jsx("div",{className:"p-4 rounded-lg bg-white mb-3 shadow-sm border",children:o&&Zd.jsx(Ap,{value:o,size:a,bgColor:"dark"===s?"#374151":"#FFFFFF",fgColor:"dark"===s?"#FFFFFF":"#000000",level:"H",includeMargin:!0})}),Zd.jsxs("div",{className:"text-center text-sm text-gray-700 mb-4",children:[Zd.jsxs("p",{className:"font-semibold text-gray-800 flex items-center justify-center",children:[Zd.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:Zd.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]}),Zd.jsxs("p",{className:"text-xs text-gray-500 mt-1",children:["Scan with your ",f(i)," wallet app"]})]}),Zd.jsxs("div",{className:"w-full mb-4 p-3 bg-gray-50 rounded-lg",children:[Zd.jsxs("div",{className:"flex justify-between items-center",children:[Zd.jsx("span",{className:"text-sm font-medium text-gray-700",children:"Amount to Pay:"}),Zd.jsxs("span",{className:"text-lg font-bold text-[#7042D2]",children:[r," ",n]})]}),Zd.jsxs("div",{className:"flex justify-between items-center mt-1",children:[Zd.jsx("span",{className:"text-xs text-gray-500",children:"Network:"}),Zd.jsx("span",{className:"text-xs font-medium text-gray-700",children:f(i)})]})]}),!c&&Zd.jsxs("div",{className:"w-full mb-4",children:[Zd.jsx("p",{className:"text-xs text-gray-500 mb-1 text-center",children:"Or copy wallet address:"}),Zd.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 e;return null==(e=navigator.clipboard)?void 0:e.writeText(t)},title:"Click to copy",children:t})]}),Zd.jsx("div",{className:"w-full",children:Zd.jsxs("div",{className:"p-3 rounded bg-blue-50 border border-blue-200",children:[Zd.jsxs("h4",{className:"text-sm font-medium mb-2 text-blue-800 flex items-center",children:[Zd.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:Zd.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"]}),Zd.jsxs("ol",{className:"text-xs space-y-1 text-blue-700",children:[Zd.jsxs("li",{children:["1. Open your crypto wallet app (",(g=i,{ethereum:["MetaMask","Trust Wallet","Coinbase Wallet"],bsc:["MetaMask","Trust Wallet","SafePal"],tron:["TronLink","Trust Wallet"],algorand:["Pera Wallet","MyAlgo Wallet"]}[g]||["MetaMask","Trust Wallet"]).join(", "),")"]}),Zd.jsx("li",{children:"2. Scan the QR code above or copy the wallet address"}),Zd.jsxs("li",{children:["3. Send exactly ",Zd.jsxs("strong",{children:[r," ",n]})," on ",f(i)," network"]}),Zd.jsx("li",{children:'4. Click "I have sent the payment" button below after sending'})]}),Zd.jsx("div",{className:"mt-3 p-2 bg-yellow-50 border border-yellow-200 rounded",children:Zd.jsxs("p",{className:"text-xs text-yellow-800",children:[Zd.jsx("strong",{children:"Important:"})," Make sure you're sending on the correct network (",f(i),") and using the exact amount shown above."]})})]})})]});var g},xp=({status:t,message:r,theme:n="light",payment:i=null,transactionHash:s=null,selectedPaymentMethod:a=null,merchantName:o="Merchant"})=>{const[l,c]=e.useState(!1),u=()=>__async(this,null,(function*(){if(s)try{yield navigator.clipboard.writeText(s),c(!0),setTimeout((()=>c(!1)),2e3)}catch(t){console.error("Failed to copy transaction hash:",t)}})),h=()=>{switch(t){case"processing":return Zd.jsx("div",{className:"animate-spin rounded-full h-12 w-12 border-4 border-t-blue-500 border-blue-500/20"});case"success":return Zd.jsx("div",{className:"rounded-full h-16 w-16 bg-green-500 flex items-center justify-center",children:Zd.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-10 w-10 text-white",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:3,children:Zd.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5 13l4 4L19 7"})})});case"error":return Zd.jsx("div",{className:"rounded-full h-12 w-12 bg-red-100 flex items-center justify-center",children:Zd.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:Zd.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})})});default:return null}};return"success"===t?Zd.jsxs("div",{className:"flex flex-col items-center justify-center py-6",children:[Zd.jsx("div",{className:"mb-6",children:h()}),Zd.jsx("h3",{className:"text-2xl font-bold mb-3 "+("dark"===n?"text-white":"text-gray-900"),children:"Payment Successful"}),i&&a&&Zd.jsxs("p",{className:"text-center mb-6 "+("dark"===n?"text-gray-300":"text-gray-600"),children:["Your payment of ",i.totalAmount||i.amount," ",a.currency," has been completed."]}),s&&Zd.jsxs("div",{className:"w-full mb-6",children:[Zd.jsx("p",{className:"text-sm font-medium mb-2 "+("dark"===n?"text-gray-300":"text-gray-700"),children:"Transaction Hash:"}),Zd.jsxs("div",{className:"flex items-center justify-between p-3 rounded-lg border cursor-pointer transition-colors "+("dark"===n?"bg-gray-700 border-gray-600 hover:bg-gray-600":"bg-gray-50 border-gray-200 hover:bg-gray-100"),onClick:u,children:[Zd.jsx("span",{className:"font-mono text-sm "+("dark"===n?"text-gray-300":"text-gray-700"),children:(f=s,f?f.length<=16?f:`${f.slice(0,8)}...${f.slice(-8)}`:"")}),Zd.jsxs("div",{className:"flex items-center",children:[l?Zd.jsx("span",{className:"text-green-500 text-xs font-medium mr-2",children:"Copied!"}):null,Zd.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-4 w-4 "+("dark"===n?"text-gray-400":"text-gray-500"),fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:Zd.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})]})]})]}),Zd.jsx("div",{className:"w-full p-4 rounded-lg border "+("dark"===n?"bg-gray-700 border-gray-600":"bg-gray-50 border-gray-200"),children:Zd.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[Zd.jsxs("div",{children:[Zd.jsx("p",{className:"text-xs font-medium mb-1 "+("dark"===n?"text-gray-400":"text-gray-500"),children:"Merchant ID:"}),Zd.jsx("p",{className:"text-sm font-medium "+("dark"===n?"text-gray-300":"text-gray-700"),children:o})]}),Zd.jsxs("div",{children:[Zd.jsx("p",{className:"text-xs font-medium mb-1 "+("dark"===n?"text-gray-400":"text-gray-500"),children:"Network:"}),Zd.jsx("p",{className:"text-sm font-medium "+("dark"===n?"text-gray-300":"text-gray-700"),children:a?(p=a.network,{ethereum:"Ethereum",bsc:"BSC",tron:"TRON",algorand:"Algorand"}[p]||p):"N/A"})]}),Zd.jsxs("div",{className:"col-span-2",children:[Zd.jsx("p",{className:"text-xs font-medium mb-1 "+("dark"===n?"text-gray-400":"text-gray-500"),children:"Recipient:"}),Zd.jsx("p",{className:"text-sm font-mono "+("dark"===n?"text-gray-300":"text-gray-700"),children:(null==i?void 0:i.recipientWallet)?(d=i.recipientWallet,d?d.length<=16?d:`${d.slice(0,6)}...${d.slice(-4)}`:"N/A"):"N/A"})]})]})})]}):Zd.jsxs("div",{className:"flex flex-col items-center justify-center py-6",children:[Zd.jsx("div",{className:"mb-4",children:h()}),Zd.jsx("h3",{className:"text-xl font-bold mb-2 "+("dark"===n?"text-white":"text-gray-900"),children:(()=>{switch(t){case"processing":return"Processing Payment";case"success":return"Payment Successful";case"error":return"Payment Failed";default:return"Unknown Status"}})()}),Zd.jsx("p",{className:`text-center ${(()=>{switch(t){case"processing":return"dark"===n?"text-blue-300":"text-blue-600";case"success":return"dark"===n?"text-green-300":"text-green-600";case"error":return"dark"===n?"text-red-300":"text-red-600";default:return"dark"===n?"text-gray-300":"text-gray-600"}})()}`,children:r}),"processing"===t&&Zd.jsx("div",{className:"mt-4 text-xs "+("dark"===n?"text-gray-400":"text-gray-500"),children:"This may take a few moments. Please do not close this window."}),"error"===t&&Zd.jsx("div",{className:"mt-4 p-2 rounded "+("dark"===n?"bg-gray-700":"bg-gray-100"),children:Zd.jsx("p",{className:"text-xs "+("dark"===n?"text-gray-300":"text-gray-600"),children:"Please try again or contact support if the problem persists."})})]});var d,p,f},kp=({onSelect:t,selected:r,theme:n="light",supportedNetworks:i=[]})=>{var s,a,o;const[l,c]=e.useState(md.ETHEREUM),[u,h]=e.useState(null),[d,p]=e.useState({}),[f,g]=e.useState(!1),m=[{id:md.ETHEREUM,name:"Ethereum",icon:"https://res.cloudinary.com/do3tlu1ph/image/upload/v1748962844/coinley/liznxm8l7iouudtrxdpi.png"},{id:md.TRON,name:"Tron",icon:"https://res.cloudinary.com/do3tlu1ph/image/upload/v1748962844/coinley/mpxxns6gtfiws4rlouxc.png"},{id:md.ALGORAND,name:"Algorand",icon:"https://res.cloudinary.com/do3tlu1ph/image/upload/v1748962844/coinley/x2lugizoduiphuqn0dej.png"},{id:"solana",name:"Solana",icon:" https://res.cloudinary.com/do3tlu1ph/image/upload/v1748962845/coinley/hmex6qxnlid1gboh4cwc.png"},{id:md.BSC,name:"Binance Smart Chain",icon:"https://res.cloudinary.com/do3tlu1ph/image/upload/v1748962844/coinley/eoavfddfqmt7qgajjxvb.png"}],[_,y]=e.useState(!1),v=e.useRef(null);e.useEffect((()=>{function t(t){v.current&&!v.current.contains(t.target)&&y(!1)}return _?document.addEventListener("mousedown",t):document.removeEventListener("mousedown",t),()=>document.removeEventListener("mousedown",t)}),[_]),e.useEffect((()=>{p(bd())}),[]);const w=(t=>{const e=[];switch(t){case md.ETHEREUM:e.push({id:"USDT",name:"USDT",description:"Tether USD",logo:"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSj0euZAOXsLTJFQxgiKzlX7z8xbfBk-7kmJA&s",network:md.ETHEREUM},{id:"USDC",name:"USDC",description:"USD Coin",logo:"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ43MuDqq54iD1ZCRL_uthAPkfwSSL-J5qI_Q&s",network:md.ETHEREUM},{id:"PYUSD",name:"PYUSD",description:"PayPal USD",logo:"https://s2.coinmarketcap.com/static/img/coins/64x64/28492.png",network:md.ETHEREUM},{id:"FRAX",name:"FRAX",description:"Frax",logo:"https://s2.coinmarketcap.com/static/img/coins/64x64/6952.png",network:md.ETHEREUM},{id:"USDP",name:"USDP",description:"Pax Dollar",logo:"https://s2.coinmarketcap.com/static/img/coins/64x64/6662.png",network:md.ETHEREUM},{id:"DAI",name:"DAI",description:"Dai Stablecoin",logo:"https://s2.coinmarketcap.com/static/img/coins/64x64/4943.png",network:md.ETHEREUM},{id:"ETH",name:"ETH",description:"Ethereum",logo:"/eth.png",network:md.ETHEREUM});break;case md.BSC:e.push({id:"USDT",name:"USDT",description:"Tether USD",logo:"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSj0euZAOXsLTJFQxgiKzlX7z8xbfBk-7kmJA&s",network:md.BSC},{id:"USDC",name:"USDC",description:"USD Coin",logo:"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ43MuDqq54iD1ZCRL_uthAPkfwSSL-J5qI_Q&s",network:md.BSC},{id:"BUSD",name:"BUSD",description:"Binance USD",logo:"https://s2.coinmarketcap.com/static/img/coins/64x64/4687.png",network:md.BSC},{id:"FRAX",name:"FRAX",description:"Frax",logo:"https://s2.coinmarketcap.com/static/img/coins/64x64/6952.png",network:md.BSC},{id:"BNB",name:"BNB",description:"Binance Coin",logo:"/bnb.png",network:md.BSC});break;case md.TRON:e.push({id:"USDT",name:"USDT",description:"Tether USD",logo:"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSj0euZAOXsLTJFQxgiKzlX7z8xbfBk-7kmJA&s",network:md.TRON},{id:"USDC",name:"USDC",description:"USD Coin",logo:"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ43MuDqq54iD1ZCRL_uthAPkfwSSL-J5qI_Q&s",network:md.TRON},{id:"USDJ",name:"USDJ",description:"JUST Stablecoin",logo:"https://s2.coinmarketcap.com/static/img/coins/64x64/5446.png",network:md.TRON},{id:"TRX",name:"TRX",description:"Tron",logo:"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQKLpLNsGRHbZfCUXAjZLPSp_YFZvX5dMnAoA&s",network:md.TRON});break;case md.ALGORAND:e.push({id:"USDC",name:"USDC",description:"USD Coin",logo:"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ43MuDqq54iD1ZCRL_uthAPkfwSSL-J5qI_Q&s",network:md.ALGORAND},{id:"USDT",name:"USDT",description:"Tether USD",logo:"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSj0euZAOXsLTJFQxgiKzlX7z8xbfBk-7kmJA&s",network:md.ALGORAND},{id:"ALGO",name:"ALGO",description:"Algorand",logo:"https://s2.coinmarketcap.com/static/img/coins/64x64/4030.png",network:md.ALGORAND})}return e})(l),b=f?w:w.slice(0,4);function A(t){switch(t){case md.ETHEREUM:case md.BSC:return gd.METAMASK;case md.TRON:return gd.TRONLINK;case md.ALGORAND:return gd.LUTE;default:return gd.METAMASK}}return Zd.jsxs("div",{className:"",children:[Zd.jsxs("div",{className:"mb-6",children:[Zd.jsx("label",{className:"block text-sm font-medium mb-2 "+("dark"===n?"text-white":"text-gray-700"),children:"Blockchain Network"}),Zd.jsxs("div",{className:"relative",ref:v,children:[Zd.jsxs("button",{type:"button",className:"w-full flex items-center justify-between px-5 py-4 bg-white rounded-2xl shadow border border-gray-200 text-gray-900 text-base font-normal focus:outline-none focus:ring-2 focus:ring-[#7042D2] focus:ring-opacity-50 transition",onClick:()=>y((t=>!t)),style:{minHeight:"56px"},children:[Zd.jsxs("span",{className:"flex items-center gap-3",children:[Zd.jsx("img",{src:null==(s=m.find((t=>t.id===l)))?void 0:s.icon,alt:null==(a=m.find((t=>t.id===l)))?void 0:a.name,className:"w-6 h-6"}),Zd.jsx("span",{className:"text-base font-normal",children:null==(o=m.find((t=>t.id===l)))?void 0:o.name})]}),Zd.jsx("svg",{className:"w-5 h-5 ml-2 transition-transform "+(_?"rotate-180":""),fill:"none",stroke:"currentColor",strokeWidth:"2",viewBox:"0 0 24 24",children:Zd.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M19 9l-7 7-7-7"})})]}),_&&Zd.jsx("div",{className:"absolute left-0 mt-2 w-full bg-white rounded-2xl shadow-lg border border-gray-100 z-20",style:{minWidth:"100%"},children:m.filter((t=>0===i.length||i.includes(t.id))).map((t=>Zd.jsxs("button",{type:"button",className:"w-full flex items-center gap-3 px-5 py-3 text-gray-900 text-base font-normal rounded-2xl transition hover:bg-gray-100 "+(l===t.id?"bg-gray-50":""),onClick:()=>{var e;y(!1),e=t.id,c(e),g(!1),h(null)},style:{minHeight:"48px"},children:[Zd.jsx("img",{src:t.icon,alt:t.name,className:"w-6 h-6"}),Zd.jsx("span",{children:t.name})]},t.id)))})]})]}),Zd.jsxs("div",{className:"mb-4",children:[Zd.jsx("label",{className:"block text-sm font-medium mb-3 "+("dark"===n?"text-white":"text-gray-700"),children:"Select Stablecoin"}),Zd.jsx("div",{className:"grid grid-cols-2 gap-3 mb-4",children:b.map((t=>{const e=(null==u?void 0:u.currency)===t.id&&(null==u?void 0:u.network)===l;return Zd.jsxs("button",{onClick:()=>(t=>{var e;const r={currency:t.id,network:l,tokenConfig:null==(e=yd[t.id])?void 0:e[l],method:t};h(r)})(t),className:`group flex items-center justify-between w-full px-5 py-4 rounded-2xl border text-left transition-all duration-200 font-medium text-base\n ${e?"bg-[#E9DDFC] border-transparent shadow-none":"bg-white border-gray-200 hover:bg-[#F6F2FF] hover:border-[#E9DDFC]"}\n `,style:{minHeight:"56px"},children:[Zd.jsxs("span",{className:"flex items-center gap-3",children:[Zd.jsx("img",{src:t.logo,alt:t.name,className:"h-6 w-6"}),Zd.jsxs("span",{className:"font-medium text-base text-gray-900",children:[t.description," (",t.name,")"]})]}),e&&Zd.jsx("span",{className:"ml-2 flex items-center justify-center w-6 h-6 rounded-full bg-[#7042D2]",children:Zd.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:Zd.jsx("path",{d:"M4 8.5L7 11.5L12 6.5",stroke:"white",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})})]},`${t.id}-${t.network}`)}))}),w.length>4&&Zd.jsx("button",{onClick:()=>g(!f),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:f?"Show Less":`Show More (${w.length-4} more)`})]}),Zd.jsx("div",{className:"p-3 rounded-lg text-sm mb-6 "+("dark"===n?"bg-gray-800 text-gray-300":"bg-gray-50 text-gray-600"),children:Zd.jsxs("div",{className:"flex items-center",children:[Zd.jsx("div",{className:"w-2 h-2 rounded-full mr-2 "+(d[A(l)]?"bg-green-500":"bg-red-500")}),Zd.jsx("span",{className:"text-xs",children:function(t){const e=A(t),r=d[e],n={[gd.METAMASK]:"MetaMask",[gd.TRONLINK]:"TronLink",[gd.TRUST_WALLET]:"Trust Wallet",[gd.LUTE]:"Lute Wallet"};return r?`${n[e]} detected - Ready to pay`:`${n[e]} required - Please install to continue`}(l)})]})}),Zd.jsx("button",{onClick:()=>{u&&t(u)},disabled:!u,className:"w-full py-3 px-4 font-medium rounded-2xl text-lg shadow-md transition-colors "+(u?"bg-[#7042D2] text-white hover:bg-[#5b34b1]":"bg-gray-300 text-gray-500 cursor-not-allowed"),style:{borderRadius:"1.5rem"},children:"Proceed"})]})},Sp=({isOpen:t,onClose:r,payment:n,paymentStatus:i,selectedPaymentMethod:s,onPaymentMethodSelect:a,onPayment:o,onBack:l,error:c,theme:u="light",merchantName:h,transactionHash:d,walletConnection:p,onConnectWallet:f,testMode:g=!1,supportedNetworks:m=[],availableWallets:_={},supportedWallets:y=[],step:v="select-currency",merchantWalletAddresses:w={},debug:b=!1})=>{const[A,E]=e.useState("wallet"),x=t=>({ethereum:"Ethereum",bsc:"BSC",tron:"Tron",algorand:"Algorand"}[t]||t),k=t=>({[gd.METAMASK]:"MetaMask",[gd.TRONLINK]:"TronLink",[gd.TRUST_WALLET]:"Trust Wallet",[gd.LUTE]:"Lute Wallet"}[t]||t),S=t=>({[gd.METAMASK]:"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcT3ymr3UNKopfI0NmUY95Dr-0589vG-91KuAA&s",[gd.TRONLINK]:"https://www.tronlink.org/images/logo.png",[gd.TRUST_WALLET]:"https://trustwallet.com/assets/images/trust_logotype.svg",[gd.LUTE]:"https://lute.app/logo.png"}[t]||"");return t?Zd.jsx("div",{className:"fixed inset-0 z-50 overflow-y-auto",children:Zd.jsx("div",{className:"flex min-h-screen items-center justify-center p-4",children:Zd.jsxs("div",{className:"coinley-modal relative p-6 max-w-[490px] mx-auto rounded-3xl shadow-xl bg-gray-100",style:{maxWidth:"490px !important",width:"100% !important",minWidth:"320px !important"},children:[Zd.jsxs("div",{className:"bg-white flex justify-between items-center mb-6 py-4 px-2 rounded-full",children:[Zd.jsxs("div",{className:"flex-1 flex items-center gap-2 px-4",children:[Zd.jsx("img",{src:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAbCAYAAABm409WAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAMFSURBVHgBpVZBVtswEJXk7JsjmAM0hF13dWDTHeEEhF13MScgOQHmBIQT1Oy6KXFPACEHIDdouux7WNM/kuxIdvJeXpj3iOSR9P9oRjODFHtIevp6y2P21LsO9MlzLFQ0x3SKtdm2s0rsJ0PGS08XaXg6usFvjL+vuw7uS+BE3sDqLs/cOLJ6+rvrRMf/sFdWQ6F1nhUnqw2uXAmiGLMurObbzEQUJYLqHasGDvZ1xkK/P4Y3kGqCn1uAvKWny5taT3rh7bLuIEpqjdYv1fQ6WY75PDYAK4pDAtIz72OC4N47gHyjpr4z5thp1rhtYSyHUaQoMzclWmVFLw8IzEYpC081YpJAL2XXEcVuT16BW6stKYwd8KQd5PL9gtkbJCPopw547YjsqMupid0GHDpxXcWwRYAFy05U+xVgY+eGK0HyzhkyBfjAAEWd+9pyKS7gmll9lIMCv6XGb+ZqeBGSHo3flRrh+9IQz4+PxA5JB4tnQOFseRW8PibA9f848C0iJ9nTZ3ZB19zsAIm+HH3/B6BvO9YTrMts3v8pDhSVPR1n8OURfP4g2EVN0UiyD4hsKtJkmQjlnqAu80NdExDY1OaAynNoEm8dAceT+9XLxYHS8Upu3L4PdLYkHEyg8IZ/CFty28K5oP3ycQgB6d9tYFEIrpj8tlX0jKf8VpXpbcINKT17HW5bq2LABawCWKHUXgapz6LLEzNGUcwxwZkE866b99mQKm9aBL64zM7CG6E2cfngWBEtkNVDZO8MJeSciTl7bbeT3Fozv7UGtYgDDvCJaN/zwTQiEyv5yVvh12faqMknQWx96veSRrEzIN2G9S84PAHw2JLRwpG6/JCXVXzsPibhXmJJGh1N9ENwBBuucTGKjU5LV2WrkQ1C+3RiSHSJkq9HHKdmR8vM02RgLsXz3sBksoo84rKwROUmN5TXPoUp+blrOOtOY4GtOhEt4TYpzY2qcszE6dmysIkYxKXCMvv2+7eFXFxIPAT6usvtSNS9CUw/pju/Uzkrba+uAr9F/gPbu3s2LSnvkAAAAABJRU5ErkJggg==",className:"w-auto h-auto",alt:"Coinley Logo"}),Zd.jsx("span",{className:"text-lg font-semibold text-gray-800",children:"Payment Details"})]}),Zd.jsx("button",{onClick:r,className:"text-gray-500 hover:text-gray-700 focus:outline-none",children:Zd.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-6 w-6",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:Zd.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),n&&Zd.jsx("div",{className:"mb-6",children:Zd.jsxs("div",{className:"text-center",children:[Zd.jsx("div",{className:"text-sm text-gray-600",children:"Total amount"}),Zd.jsxs("div",{className:"coinley-amount-display text-5xl font-bold text-[#7042D2] mt-2",children:["$",(N=n.totalAmount||n.amount,parseFloat(N).toFixed(2))]}),Zd.jsx("div",{className:"text-sm text-gray-600 mt-4",children:"Payment to:"}),Zd.jsx("div",{className:"coinley-merchant-name text-base font-semibold mt-1",children:h})]})}),"select-currency"===v&&Zd.jsx("div",{className:"mb-6",children:Zd.jsx(kp,{onSelect:a,selected:s,theme:u,supportedNetworks:m})}),"confirm"===v&&s&&n&&Zd.jsxs("div",{children:[Zd.jsxs("div",{className:"p-4 rounded-lg mb-4 bg-gray-100",children:[Zd.jsx("h3",{className:"text-lg font-medium mb-2 text-gray-800",children:"Payment Details"}),Zd.jsxs("div",{className:"space-y-2",children:[Zd.jsxs("div",{className:"flex justify-between",children:[Zd.jsx("span",{className:"text-purple-600 font-semibold",children:"Currency:"}),Zd.jsx("span",{className:"font-medium",children:s.currency})]}),Zd.jsxs("div",{className:"flex justify-between",children:[Zd.jsx("span",{className:"text-purple-600 font-semibold",children:"Network:"}),Zd.jsx("span",{className:"font-medium",children:x(s.network)})]}),Zd.jsxs("div",{className:"flex justify-between",children:[Zd.jsx("span",{className:"text-purple-600 font-semibold",children:"Fee:"}),Zd.jsx("span",{className:"font-medium",children:"1.75%"})]})]})]}),Zd.jsx("div",{className:"mb-4",children:Zd.jsxs("div",{className:"flex border-b border-gray-200",children:[Zd.jsx("button",{onClick:()=>E("wallet"),className:"py-2 px-4 text-sm font-medium "+("wallet"===A?"border-b-2 border-purple-600 text-purple-600":"text-gray-500 hover:text-gray-700"),children:"Connect Wallet"}),Zd.jsx("button",{onClick:()=>E("qrcode"),className:"py-2 px-4 text-sm font-medium "+("qrcode"===A?"border-b-2 border-purple-600 text-purple-600":"text-gray-500 hover:text-gray-700"),children:"QR Code"})]})}),g?Zd.jsx("div",{className:"p-4 rounded-lg mb-4 bg-blue-50",children:Zd.jsxs("div",{className:"flex items-center",children:[Zd.jsx("div",{className:"bg-purple-600 rounded-full p-2 mr-3",children:Zd.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:Zd.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 10V3L4 14h7v7l9-11h-7z"})})}),Zd.jsxs("div",{children:[Zd.jsx("h3",{className:"font-medium text-gray-800",children:"Test Mode Payment"}),Zd.jsx("p",{className:"text-sm text-gray-600",children:'Click "Pay Now" to simulate a successful payment'})]})]})}):"qrcode"===A?Zd.jsx("div",{className:"mb-4",children:Zd.jsx(Ep,{walletAddress:(()=>{if(!s)return"No network selected";const t=w[s.network];return t||((null==n?void 0:n.recipientWallet)?n.recipientWallet:"No wallet address configured for this network")})(),amount:n.totalAmount||n.amount,currency:s.currency,network:s.network,theme:u})}):Zd.jsxs("div",{className:"space-y-3 mb-4",children:[0===y.length?Zd.jsx("div",{className:"p-4 rounded-lg bg-yellow-50",children:Zd.jsxs("div",{className:"flex items-center",children:[Zd.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:Zd.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"})}),Zd.jsxs("div",{children:[Zd.jsx("h3",{className:"font-medium text-gray-800",children:"No Compatible Wallets"}),Zd.jsxs("p",{className:"text-sm text-gray-600",children:["No wallets detected for ",x(s.network)," network"]})]})]})}):y.map((t=>Zd.jsx("div",{className:"p-4 rounded-lg bg-blue-50",children:Zd.jsxs("div",{className:"flex items-center justify-between",children:[Zd.jsxs("div",{className:"flex items-center",children:[Zd.jsx("img",{src:S(t),alt:k(t),className:"w-8 h-8 mr-3",onError:t=>{t.target.style.display="none"}}),Zd.jsxs("div",{children:[Zd.jsx("h3",{className:"font-medium text-gray-800",children:k(t)}),Zd.jsxs("p",{className:"text-sm text-gray-600",children:["Pay with ",k(t)]})]})]}),(null==p?void 0:p.walletType)===t?Zd.jsxs("div",{className:"flex items-center space-x-2",children:[Zd.jsx("div",{className:"w-2 h-2 bg-green-500 rounded-full"}),Zd.jsx("span",{className:"text-sm text-green-600",children:"Connected"})]}):Zd.jsx("button",{onClick:()=>{console.log("Connect wallet button clicked for:",t),f(t)},className:"coinley-button-primary py-2 px-4 font-medium rounded-md text-sm",children:"Connect"})]})},t))),Zd.jsx("div",{className:"space-y-2",children:Object.entries(_).filter((([t,e])=>!e)).map((([t])=>Zd.jsx("div",{className:"p-3 rounded-lg bg-gray-50",children:Zd.jsxs("div",{className:"flex items-center justify-between",children:[Zd.jsxs("span",{className:"text-sm text-gray-600",children:[k(t)," not detected"]}),Zd.jsx("a",{href:wd(t),target:"_blank",rel:"noopener noreferrer",className:"text-sm text-purple-600 hover:underline",children:"Install"})]})},t)))})]}),c&&Zd.jsx("div",{className:"p-3 rounded-lg bg-red-50 mb-4 text-red-600 text-sm",children:c}),Zd.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[Zd.jsx("button",{type:"button",onClick:l,className:"w-full py-2 px-4 bg-gray-200 hover:bg-gray-300 text-purple-600 font-medium rounded-md",children:"Back"}),Zd.jsx("button",{type:"button",onClick:()=>o("qrcode"===A),className:"coinley-button-primary w-full py-2 px-4 font-medium rounded-md",disabled:!g&&"wallet"===A&&!p,children:"qrcode"===A?"I have sent the payment":"Pay Now"})]})]}),"processing"===v&&Zd.jsx(xp,{status:"processing",theme:u,message:"Processing your payment..."}),"success"===v&&Zd.jsx(xp,{status:"success",theme:u,message:"Payment successful!",payment:n,transactionHash:d,selectedPaymentMethod:s,merchantName:h}),"error"===v&&Zd.jsxs("div",{children:[Zd.jsx(xp,{status:"error",theme:u,message:c||"An error occurred while processing your payment."}),Zd.jsx("button",{type:"button",onClick:l,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"})]}),Zd.jsxs("div",{className:"text-center text-xs text-gray-500 flex items-center justify-center gap-1 mt-6",children:[Zd.jsxs("p",{children:["Powered by ",Zd.jsx("span",{className:"text-purple-600",children:"Coinley"})," - Secure Cryptocurrency Payments"]}),Zd.jsxs("svg",{className:"inline w-4 h-4 text-green-500 ml-1",fill:"none",stroke:"currentColor",strokeWidth:"2",viewBox:"0 0 24 24",children:[Zd.jsx("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"2",fill:"none"}),Zd.jsx("path",{d:"M9 12l2 2 4-4",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]})]})]})})}):null;var N},Np=e.forwardRef((({apiKey:t,apiSecret:r,apiUrl:n,customerEmail:i,merchantName:s="Merchant",merchantWalletAddresses:a={},onSuccess:o,onError:l,onClose:c,theme:u,autoOpen:h=!1,debug:d=!1,testMode:p=!1,supportedNetworks:f=[],preferredNetwork:g=md.ETHEREUM,preferredWallet:m=gd.METAMASK},_)=>{const y=tp(),{theme:v}=e.useContext(Xd),[w,b]=e.useState(h),[A,E]=e.useState(null),[x,k]=e.useState("idle"),[S,N]=e.useState(null),[P,C]=e.useState(null),[T,R]=e.useState(null),[M,G]=e.useState(null),[B,I]=e.useState({}),[O,F]=e.useState("select-currency"),[U,L]=e.useState({}),D=t||(null==y?void 0:y.apiKey),j=r||(null==y?void 0:y.apiSecret);n||null==y||y.apiUrl;const H=u||v,W=d||(null==y?void 0:y.debug),Q=f.length>0?f:[md.ETHEREUM,md.BSC,md.TRON,md.ALGORAND],z=(t,e)=>{W&&console.log(`[Coinley SDK] ${t}`,e)};e.useEffect((()=>{D&&j&&(()=>{__async(this,null,(function*(){try{z("Fetching merchant wallet addresses from backend...");const t=yield Ud();L(t),z("Merchant wallets fetched successfully:",t)}catch(t){console.error("Failed to fetch merchant wallets:",t),L(a)}}))})()}),[D,j,a]),e.useEffect((()=>{if("undefined"!=typeof window){(()=>__async(this,null,(function*(){const t=yield Ad(3,1e3);I(t),z("Available wallets detected:",t)})))()}}),[W]),e.useImperativeHandle(_,(()=>({open:t=>{V(t)},close:()=>{K()},getPayment:()=>A,getWalletConnection:()=>M,debugWallets:()=>(()=>{var t;console.log("=== WALLET ENVIRONMENT DEBUG ==="),console.log("ethereum:","undefined"!=typeof window?Boolean(window.ethereum):"Not in browser"),console.log("tronWeb:","undefined"!=typeof window?Boolean(window.tronWeb):"Not in browser"),console.log("lute:","undefined"!=typeof window?Boolean(window.lute):"Not in browser"),"undefined"!=typeof window&&window.ethereum&&console.log("ethereum details:",{isTrust:window.ethereum.isTrust,isMetaMask:window.ethereum.isMetaMask,chainId:window.ethereum.chainId}),"undefined"!=typeof window&&window.tronWeb&&console.log("tronWeb details:",{ready:window.tronWeb.ready,fullNode:null==(t=window.tronWeb.fullNode)?void 0:t.host,defaultAddress:window.tronWeb.defaultAddress});const e=bd();console.log("Detected wallets:",e)})(),getMerchantWallets:()=>U})));const V=t=>__async(this,null,(function*(){if(!t||!t.amount)return C("Payment amount is required"),void(l&&l(new Error("Payment amount is required")));k("loading"),b(!0),F("select-currency");try{z("Creating payment with details:",t);let e=U;0===Object.keys(e).length&&(z("No wallet addresses found, fetching from backend..."),e=yield Ud(),L(e)),z("Using wallet addresses:",e);const r=yield Dd({amount:t.amount,currency:t.currency||"USDT",network:t.network||g,customerEmail:t.customerEmail||i,callbackUrl:t.callbackUrl,metadata:__spreadProps(__spreadValues({},t.metadata),{merchantWalletAddresses:e}),merchantWalletAddresses:e});z("Payment created:",r),E(r.payment),k("idle"),C(null),z("Payment created and state updated")}catch(e){z("Error creating payment:",e),C(e.message||"Failed to create payment"),k("error"),l&&l(e)}})),K=()=>{b(!1),R(null),G(null),N(null),F("select-currency"),c&&c()};return Zd.jsx(Zd.Fragment,{children:w&&Zd.jsx(Sp,{isOpen:w,onClose:K,payment:A,paymentStatus:x,selectedPaymentMethod:S,onPaymentMethodSelect:t=>{console.log("=== PAYMENT METHOD SELECTION DEBUG ==="),console.log("1. Payment method selected:",t),console.log("2. Current step before:",O),z("Payment method selected:",t),N(t),F("confirm"),console.log("3. Step should now be: confirm"),console.log("=== END PAYMENT METHOD SELECTION DEBUG ===")},onPayment:()=>__async(this,null,(function*(){var t,e;if(A&&S)if(M||p){z("Starting payment process..."),k("loading"),R(null),F("processing");try{let r;if(p)z("Test mode: Generating mock transaction..."),r=`test_${Date.now().toString(16)}_${Math.random().toString(16).substring(2,10)}`;else{let n;if(A.recipientWallet)n=A.recipientWallet;else{if(!U[S.network])throw new Error(`No merchant wallet address found for ${S.network} network`);n=U[S.network]}z("Using merchant address for payment:",n),z("Sending transaction through wallet..."),r=yield Td(M,{to:n,amount:A.totalAmount||A.amount,tokenAddress:null==(t=S.tokenConfig)?void 0:t.address,tokenDecimals:null==(e=S.tokenConfig)?void 0:e.decimals,currency:S.currency,network:S.network})}z("Transaction hash:",r),R(r),z("Processing payment with backend...");const n=yield jd({paymentId:A.id,transactionHash:r,network:S.network,currency:S.currency,senderAddress:null==M?void 0:M.address});z("Payment processed successfully:",n),k("success"),F("success"),o&&(z("Calling onSuccess callback..."),o(A.id,r,{network:S.network,currency:S.currency,amount:A.totalAmount||A.amount}))}catch(r){z("Payment error:",r),C(r.message||"Failed to process payment"),k("error"),F("error"),l&&l(r)}}else C("Please connect your wallet first");else C("Missing payment information")})),onBack:()=>{"confirm"===O?(F("select-currency"),G(null)):"error"===O&&F("confirm")},error:P,theme:H,merchantName:s,transactionHash:T,walletConnection:M,onConnectWallet:t=>__async(this,null,(function*(){if(console.log("=== WALLET CONNECTION DEBUG ==="),console.log("1. Wallet type requested:",t),console.log("2. Selected payment method:",S),console.log("3. Available wallets:",B),console.log("4. Current step:",O),!S)return console.error("No payment method selected"),void C("Please select a payment method first");try{console.log("5. Attempting to connect wallet..."),C(null),z("Connecting wallet:",{walletType:t,network:S.network});const e=yield Nd(t,S.network);G(e),C(null),console.log("6. Connection successful:",e),z("Wallet connected successfully:",e)}catch(e){console.error("7. Connection failed:",e),z("Wallet connection error:",e),C(e.message||"Failed to connect wallet")}console.log("=== END WALLET CONNECTION DEBUG ===")})),testMode:p,supportedNetworks:Q,availableWallets:B,supportedWallets:S?Pd(S.network):[],step:O,merchantWalletAddresses:U,debug:W})})}));Np.displayName="CoinleyCheckout";t.CoinleyCheckout=Np,t.CoinleyModal=Sp,t.CoinleyProvider=({apiKey:t,apiSecret:r,apiUrl:n="https://coinleyserver-production.up.railway.app",merchantWalletAddress:i=null,merchantSolWalletAddress:s=null,debug:a=!1,children:o})=>{const[l,c]=e.useState(!1),[u,h]=e.useState(null),[d,p]=e.useState(null),[f,g]=e.useState({});e.useEffect((()=>{if(!t||!r)return void h("API key and secret are required");(()=>{__async(this,null,(function*(){try{yield Od({apiKey:t,apiSecret:r,apiUrl:n,debug:a});const e=yield Ud(),o=__spreadValues(__spreadValues(__spreadValues({},e),i&&{ethereum:i}),s&&{solana:s});g(o),c(!0),a&&console.log("Coinley SDK initialized successfully with wallets:",o)}catch(e){h(e.message),a&&console.error("Coinley SDK initialization error:",e)}}))})()}),[t,r,n,i,s,a]);const m={apiKey:t,apiSecret:r,apiUrl:n,merchantWalletAddress:i,merchantSolWalletAddress:s,merchantWallets:f,isInitialized:l,error:u,debug:a,paymentData:d,storePaymentData:t=>(p(t),t),refreshMerchantWallets:()=>__async(this,null,(function*(){try{const t=yield Ud();return g(t),t}catch(t){return console.error("Failed to refresh merchant wallets:",t),f}}))};return Zd.jsx($d.Provider,{value:m,children:o})},t.DEFAULT_CONFIG={apiUrl:"https://coinleyserver-production.up.railway.app",debug:!1,testMode:!1,theme:"light",supportedNetworks:["ethereum","bsc","tron","algorand"]},t.NETWORK_CONFIG=_d,t.NETWORK_TYPES=md,t.PaymentMethods=kp,t.PaymentStatus=xp,t.QRCode=Ep,t.TOKEN_CONFIG=yd,t.ThemeProvider=({initialTheme:t="light",children:r})=>{const[n,i]=e.useState(t);return e.useEffect((()=>{document.documentElement.classList.remove("light","dark"),document.documentElement.classList.add(n)}),[n]),Zd.jsx(Xd.Provider,{value:{theme:n,setTheme:i,toggleTheme:()=>{i((t=>"light"===t?"dark":"light"))}},children:r})},t.WALLET_TYPES=gd,t.connectWallet=Nd,t.createPayment=Dd,t.detectWallets=bd,t.generateMockTransactionHash=(t="ethereum")=>`${{ethereum:"0x",bsc:"0x",tron:"",algorand:""}[t]||"0x"}${Array.from({length:64},(()=>Math.floor(16*Math.random()).toString(16))).join("")}`,t.getMerchantWallets=Ud,t.getPayment=t=>__async(this,null,(function*(){try{if(console.log("Getting payment:",t),!t)throw new Error("Payment ID is required");const r=yield fetch(`${Id.apiUrl}/api/payments/${t}`,{method:"GET",headers:Ld()});if(!r.ok){let t;try{t=yield r.json()}catch(e){throw new Error(`Failed to get payment: ${r.status} ${r.statusText}`)}throw console.error("Error getting payment:",t),new Error(t.error||`Failed to get payment: ${r.status}`)}const n=yield r.json();return console.log("Get payment response:",n),n}catch(r){throw console.error("Get payment error:",r),r}})),t.getSupportedNetworks=()=>__async(this,null,(function*(){try{const e=yield fetch(`${Id.apiUrl}/api/networks`,{method:"GET",headers:Ld()});if(!e.ok){let r;try{r=yield e.json()}catch(t){throw new Error(`Failed to get networks: ${e.status} ${e.statusText}`)}throw new Error(r.error||`Failed to get networks: ${e.status}`)}return yield e.json()}catch(e){throw console.error("Get supported networks error:",e),e}})),t.getSupportedWalletsForNetwork=Pd,t.getWalletInstallUrl=wd,t.processPayment=jd,t.sendTransaction=Td,t.useCoinley=tp,t.validateWalletAddress=(t,e)=>__async(this,null,(function*(){try{const n=yield fetch(`${Id.apiUrl}/api/wallets/validate`,{method:"POST",headers:Ld(),body:JSON.stringify({address:t,network:e})});if(!n.ok){let t;try{t=yield n.json()}catch(r){throw new Error(`Failed to validate address: ${n.status} ${n.statusText}`)}throw new Error(t.error||`Failed to validate address: ${n.status}`)}return yield n.json()}catch(n){throw console.error("Validate wallet address error:",n),n}})),Object.defineProperty(t,Symbol.toStringTag,{value:"Module"})}));
17
17
  //# sourceMappingURL=coinley-checkout.umd.js.map