coinley-checkout 0.5.0 → 0.5.2
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 vp(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 wp(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 bp({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(...hp.QrSegment.makeSegments(e)),t)),[]);return hp.QrCode.encodeSegments(e,dp[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 Ap=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=pp,level:a=fp,bgColor:o=gp,fgColor:l=mp,includeMargin:c=_p,minVersion:u=yp,boostLevel:h,marginSize:d,imageSettings:p}=n,f=up(n,["value","size","level","bgColor","fgColor","includeMargin","minVersion","boostLevel","marginSize","imageSettings"]),{style:g}=f,m=up(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}=bp({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=wp(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,Ap?e.fill(new Path2D(vp(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=cp({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",cp({style:N,height:s,width:s,ref:w,role:"img"},m)),P)})).displayName="QRCodeCanvas";var Ep=e.forwardRef((function(t,r){const n=t,{value:i,size:s=pp,level:a=fp,bgColor:o=gp,fgColor:l=mp,includeMargin:c=_p,minVersion:u=yp,boostLevel:h,title:d,marginSize:p,imageSettings:f}=n,g=up(n,["value","size","level","bgColor","fgColor","includeMargin","minVersion","boostLevel","title","marginSize","imageSettings"]),{margin:m,cells:_,numCells:y,calculatedImageSettings:v}=bp({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=wp(_,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=vp(w,m);return e.createElement("svg",cp({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)}));Ep.displayName="QRCodeSVG";const xp=({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 Xd.jsxs("div",{className:"flex flex-col items-center",children:[c?Xd.jsxs("div",{className:"p-4 rounded-lg bg-red-100 mb-3 text-red-700 text-center",children:[Xd.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:Xd.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"})}),Xd.jsx("p",{className:"font-medium",children:c})]}):Xd.jsx("div",{className:"p-4 rounded-lg bg-white mb-3 shadow-sm border",children:o&&Xd.jsx(Ep,{value:o,size:a,bgColor:"dark"===s?"#374151":"#FFFFFF",fgColor:"dark"===s?"#FFFFFF":"#000000",level:"H",includeMargin:!0})}),Xd.jsxs("div",{className:"text-center text-sm text-gray-700 mb-4",children:[Xd.jsxs("p",{className:"font-semibold text-gray-800 flex items-center justify-center",children:[Xd.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:Xd.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]}),Xd.jsxs("p",{className:"text-xs text-gray-500 mt-1",children:["Scan with your ",f(i)," wallet app"]})]}),Xd.jsxs("div",{className:"w-full mb-4 p-3 bg-gray-50 rounded-lg",children:[Xd.jsxs("div",{className:"flex justify-between items-center",children:[Xd.jsx("span",{className:"text-sm font-medium text-gray-700",children:"Amount to Pay:"}),Xd.jsxs("span",{className:"text-lg font-bold text-[#7042D2]",children:[r," ",n]})]}),Xd.jsxs("div",{className:"flex justify-between items-center mt-1",children:[Xd.jsx("span",{className:"text-xs text-gray-500",children:"Network:"}),Xd.jsx("span",{className:"text-xs font-medium text-gray-700",children:f(i)})]})]}),!c&&Xd.jsxs("div",{className:"w-full mb-4",children:[Xd.jsx("p",{className:"text-xs text-gray-500 mb-1 text-center",children:"Or copy wallet address:"}),Xd.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})]}),Xd.jsx("div",{className:"w-full",children:Xd.jsxs("div",{className:"p-3 rounded bg-blue-50 border border-blue-200",children:[Xd.jsxs("h4",{className:"text-sm font-medium mb-2 text-blue-800 flex items-center",children:[Xd.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:Xd.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"]}),Xd.jsxs("ol",{className:"text-xs space-y-1 text-blue-700",children:[Xd.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(", "),")"]}),Xd.jsx("li",{children:"2. Scan the QR code above or copy the wallet address"}),Xd.jsxs("li",{children:["3. Send exactly ",Xd.jsxs("strong",{children:[r," ",n]})," on ",f(i)," network"]}),Xd.jsx("li",{children:'4. Click "I have sent the payment" button below after sending'})]}),Xd.jsx("div",{className:"mt-3 p-2 bg-yellow-50 border border-yellow-200 rounded",children:Xd.jsxs("p",{className:"text-xs text-yellow-800",children:[Xd.jsx("strong",{children:"Important:"})," Make sure you're sending on the correct network (",f(i),") and using the exact amount shown above."]})})]})})]});var g},kp=({status:t,message:e,theme:r="light"})=>Xd.jsxs("div",{className:"flex flex-col items-center justify-center py-6",children:[Xd.jsx("div",{className:"mb-4",children:(()=>{switch(t){case"processing":return Xd.jsx("div",{className:"animate-spin rounded-full h-12 w-12 border-4 border-t-blue-500 border-blue-500/20"});case"success":return Xd.jsx("div",{className:"rounded-full h-12 w-12 bg-green-100 flex items-center justify-center",children:Xd.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:Xd.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5 13l4 4L19 7"})})});case"error":return Xd.jsx("div",{className:"rounded-full h-12 w-12 bg-red-100 flex items-center justify-center",children:Xd.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:Xd.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})})});default:return null}})()}),Xd.jsx("h3",{className:"text-xl font-bold mb-2 "+("dark"===r?"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"}})()}),Xd.jsx("p",{className:`text-center ${(()=>{switch(t){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:e}),"processing"===t&&Xd.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"===t&&Xd.jsx("div",{className:"mt-4 p-2 rounded "+("dark"===r?"bg-gray-700":"bg-gray-100"),children:Xd.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."})})]}),Sp=({onSelect:t,selected:r,theme:n="light",supportedNetworks:i=[]})=>{const[s,a]=e.useState(md.ETHEREUM),[o,l]=e.useState({}),[c,u]=e.useState(!1);e.useEffect((()=>{l(bd())}),[]);const h=[{id:md.ETHEREUM,name:"Ethereum",description:"ERC-20 tokens"},{id:md.BSC,name:"BSC (Binance Smart Chain)",description:"BEP-20 tokens"},{id:md.TRON,name:"Tron",description:"TRC-20 tokens"},{id:md.ALGORAND,name:"Algorand",description:"ASA tokens"}],d=(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:"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTcyJyRKN0dRJWVZqoLzYgkRHdJsxKGq8nHUw&s",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:"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRHSjyW2sSnBhwztCwVW97i1BtV40g7heMMxg&s",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})(s),p=c?d:d.slice(0,4);function f(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 Xd.jsxs("div",{children:[Xd.jsx("h3",{className:"text-lg font-medium mb-4 "+("dark"===n?"text-white":"text-gray-800"),children:"Select Payment Method"}),Xd.jsxs("div",{className:"mb-6",children:[Xd.jsx("label",{className:"block text-sm font-medium mb-2 "+("dark"===n?"text-white":"text-gray-700"),children:"Blockchain Network"}),Xd.jsx("select",{value:s,onChange:e=>{return n=e.target.value,a(n),u(!1),void((null==r?void 0:r.network)!==n&&t(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((t=>0===i.length||i.includes(t.id))).map((t=>Xd.jsxs("option",{value:t.id,children:[t.name," - ",t.description]},t.id)))})]}),Xd.jsxs("div",{className:"mb-4",children:[Xd.jsx("label",{className:"block text-sm font-medium mb-3 "+("dark"===n?"text-white":"text-gray-700"),children:"Select Stablecoin"}),Xd.jsx("div",{className:"grid grid-cols-2 gap-3 mb-4",children:p.map((e=>Xd.jsx("button",{onClick:()=>(e=>{var r;t({currency:e.id,network:s,tokenConfig:null==(r=yd[e.id])?void 0:r[s],method:e})})(e),className:"p-4 rounded-lg transition-all duration-200 border-1 "+((null==r?void 0:r.currency)===e.id&&(null==r?void 0:r.network)===s?"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:Xd.jsxs("div",{className:"flex items-center text-center",children:[Xd.jsx("div",{className:"flex-shrink-0 h-10 w-10 bg-white rounded-full flex items-center justify-center mb-2 shadow-sm",children:Xd.jsx("img",{src:e.logo,alt:e.name,className:"h-6 w-6"})}),Xd.jsxs("div",{children:[Xd.jsx("h4",{className:"font-medium text-sm "+("dark"===n?"text-white":"text-gray-900"),children:e.name}),Xd.jsx("p",{className:"text-xs "+("dark"===n?"text-gray-300":"text-gray-500"),children:e.description})]}),(null==r?void 0:r.currency)===e.id&&(null==r?void 0:r.network)===s&&Xd.jsx("div",{className:"mt-2",children:Xd.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-4 w-4 text-[#7042D2]",viewBox:"0 0 20 20",fill:"currentColor",children:Xd.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"})})})]})},`${e.id}-${e.network}`)))}),d.length>4&&Xd.jsx("button",{onClick:()=>u(!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 (${d.length-4} more)`})]}),Xd.jsx("div",{className:"p-3 rounded-lg text-sm "+("dark"===n?"bg-gray-800 text-gray-300":"bg-gray-50 text-gray-600"),children:Xd.jsxs("div",{className:"flex items-center",children:[Xd.jsx("div",{className:"w-2 h-2 rounded-full mr-2 "+(o[f(s)]?"bg-green-500":"bg-red-500")}),Xd.jsx("span",{className:"text-xs",children:function(t){const e=f(t),r=o[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`}(s)})]})})]})},Np=({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?Xd.jsx("div",{className:"fixed inset-0 z-50 overflow-y-auto bg-black/50",children:Xd.jsx("div",{className:"flex min-h-screen items-center justify-center p-4",children:Xd.jsxs("div",{className:"relative p-6 w-full max-w-md mx-auto rounded-lg shadow-xl bg-white text-gray-800",children:[Xd.jsxs("div",{className:"flex justify-between items-center mb-6 bg-[#F1ECFB] p-3 rounded-xl",children:[Xd.jsx("div",{className:"flex items-center",children:Xd.jsx("h2",{className:"text-xl font-bold text-gray-900",children:Xd.jsx("img",{src:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAJQAAAAkCAYAAABv9hOhAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAmVSURBVHgB7Vzdcdu4Fv5I+X2VCoK83pkb2xVc2ikgTgVWKog8twDJBexYrsBKBXYKWJtbQWRnZl+NrWC172txcQBQBA8B/kiKV87qm4FFgMAhAX48ODg4dISOGB4/XKsfObl9e+Y9n3wViHt3QHY5ud2fYId1caDSJyc/V+kMW4q4S2VFFurcCR0Oj+/H3kq9vSv1VyDDKX5s0Fh8VSlTifrcx/cByR046QRbjE6EQmnQok9aGzlQ+QRZluDHh1BJaWFNKsJApQvs0JlQc+e4jzgelqX1HNUczfHjQqCqkRLsUCWU0jL94buHE659LGQ5G51SfafAUcfZn572Sv63hKZL1u6lYeYpk9jBo6HieKysgmulbR6VAX7lEmuSHpLWkU5tIoVW+3q6cxEhdbOaqMcPF4gzNVVEI2VsJXi5oHE4d/JSpY/YwUOoRYkwA1qxWWPcIvtSlhDbc/FBWc5i+RbblR8ZsGaKzDIJPKV42Rir9EqlNzZJ7OCzoRZTlG0lTYalBlosbsr1o33zg4JQijBKm6V0WLgRtN1hm+DSaruXDq6x//XY4wX0oJWNo9R5VF61xL1rRY4jIsrw6F4iioQuz7JX5nz8Wh2bulGU0o+2kziZMqSTu7X9UwLGCBZOGWnEFOWXoQk0ZZ945FCS+D4QKN873W8Kv122Kv6Jfmns+QrJIT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pP36g8Ip+qYyM78yZyxdPr1w3g/5yJoqv9apSGfuTX95uYgoRzrHE6hAbkrNtcG3LOVZzhnLbboqaT8aqU17mnermS+KY6Yzv5QBP7LOoOB64WR2MRxGgWsvhakNed+mkbZCzbSACSVR9Vm3BXQWEz3UNqoSquhCmJtTXbg4vjXDQFDjLtZD+pUjPQtA+F0021eRu/40NKz7ADtuMkB8urWtU/Yzq9u1UaQ+pow0WTzdV77hDlGgZgmuQLdT8HBmi1Hjfl3HnO2wbEhT2qWDniAeNIdD+z6jqQlXcuHL6MMHFYpEuDfYo2sSUtsPzQiDs6CQySTQgRldkWU6UKf+KRROxOaR4h5cF0kzk+pm2qdydUJF2D8yXH3NyPP21tf9dbYdOkDAOU3JFtF6R76EraO9PrfJC39hZv5NidG835b085Eb3qi4G/A2inrQKnVgMFAAAAABJRU5ErkJggg==",className:"w-32",alt:"Coinley Logo"})})}),Xd.jsx("button",{onClick:r,className:"text-gray-500 hover:text-gray-700 focus:outline-none",children:Xd.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-6 w-6",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:Xd.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),Xd.jsxs("div",{className:"mb-6 bg-[#F1ECFB] p-3 rounded-xl",children:[n&&Xd.jsxs("div",{className:"mb-6 p-4 rounded-lg",children:[Xd.jsxs("p",{className:"text-lg text-gray-800 font-semibold",children:["PAY: ",h]}),Xd.jsxs("div",{className:"flex justify-between items-center mt-2 bg-gray-100 px-3 rounded-lg",children:[Xd.jsx("span",{className:"font-medium text-gray-700",children:"Amount:"}),Xd.jsxs("span",{className:"font-bold text-xl text-[#7042D2]",children:["$",(P=n.totalAmount||n.amount,parseFloat(P).toFixed(2))]})]}),Xd.jsx("div",{className:"text-xs mt-1 text-right",children:Xd.jsxs("span",{className:"text-gray-500",children:["Payment ID: ",n.id?n.id.slice(0,8):"","..."]})})]}),b&&Xd.jsx("div",{className:"mb-2 text-right",children:Xd.jsx("button",{onClick:()=>{console.log("=== DEBUG INFO ==="),console.log("Current step:",v),console.log("Payment method:",s),console.log("Wallet connection:",p),Ed()},className:"text-xs bg-gray-200 p-1 rounded",children:"Debug"})}),"select-currency"===v&&Xd.jsxs("div",{children:[Xd.jsx(Sp,{onSelect:a,selected:s,theme:u,supportedNetworks:m}),s&&Xd.jsx("div",{className:"mt-6",children:Xd.jsxs("button",{onClick:()=>{console.log("Proceed button clicked, calling onPaymentMethodSelect"),a(s)},className:"w-full py-3 px-4 bg-[#7042D2] hover:bg-[#7042D2] text-white font-medium rounded-lg transition-colors",disabled:!s,children:["Proceed with ",s.currency," on ",x(s.network)]})})]}),"confirm"===v&&s&&n&&Xd.jsxs("div",{children:[Xd.jsxs("div",{className:"p-4 rounded-lg mb-4 bg-gray-100",children:[Xd.jsx("h3",{className:"text-lg font-medium mb-2 text-gray-800",children:"Payment Details"}),Xd.jsxs("div",{className:"space-y-2",children:[Xd.jsxs("div",{className:"flex justify-between",children:[Xd.jsx("span",{className:"text-[#7042D2] font-semibold",children:"Currency:"}),Xd.jsx("span",{className:"font-medium",children:s.currency})]}),Xd.jsxs("div",{className:"flex justify-between",children:[Xd.jsx("span",{className:"text-[#7042D2] font-semibold",children:"Network:"}),Xd.jsx("span",{className:"font-medium",children:x(s.network)})]}),Xd.jsxs("div",{className:"flex justify-between",children:[Xd.jsx("span",{className:"text-[#7042D2] font-semibold",children:"Fee:"}),Xd.jsx("span",{className:"font-medium",children:"1.75%"})]})]})]}),Xd.jsx("div",{className:"mb-4",children:Xd.jsxs("div",{className:"flex border-b border-gray-200",children:[Xd.jsx("button",{onClick:()=>E("wallet"),className:"py-2 px-4 text-sm font-medium "+("wallet"===A?"border-b-2 border-[#7042D2] text-[#7042D2]":"text-gray-500 hover:text-gray-700"),children:"Connect Wallet"}),Xd.jsx("button",{onClick:()=>E("qrcode"),className:"py-2 px-4 text-sm font-medium "+("qrcode"===A?"border-b-2 border-[#7042D2] text-[#7042D2]":"text-gray-500 hover:text-gray-700"),children:"QR Code"})]})}),g?Xd.jsx("div",{className:"p-4 rounded-lg mb-4 bg-blue-50",children:Xd.jsxs("div",{className:"flex items-center",children:[Xd.jsx("div",{className:"bg-[#7042D2] rounded-full p-2 mr-3",children:Xd.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:Xd.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 10V3L4 14h7v7l9-11h-7z"})})}),Xd.jsxs("div",{children:[Xd.jsx("h3",{className:"font-medium text-gray-800",children:"Test Mode Payment"}),Xd.jsx("p",{className:"text-sm text-gray-600",children:'Click "Pay Now" to simulate a successful payment'})]})]})}):"qrcode"===A?Xd.jsx("div",{className:"mb-4",children:Xd.jsx(xp,{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})}):Xd.jsxs("div",{className:"space-y-3 mb-4",children:[0===y.length?Xd.jsx("div",{className:"p-4 rounded-lg bg-yellow-50",children:Xd.jsxs("div",{className:"flex items-center",children:[Xd.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:Xd.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"})}),Xd.jsxs("div",{children:[Xd.jsx("h3",{className:"font-medium text-gray-800",children:"No Compatible Wallets"}),Xd.jsxs("p",{className:"text-sm text-gray-600",children:["No wallets detected for ",x(s.network)," network"]})]})]})}):y.map((t=>Xd.jsx("div",{className:"p-4 rounded-lg bg-blue-50",children:Xd.jsxs("div",{className:"flex items-center justify-between",children:[Xd.jsxs("div",{className:"flex items-center",children:[Xd.jsx("img",{src:S(t),alt:k(t),className:"w-8 h-8 mr-3",onError:t=>{t.target.style.display="none"}}),Xd.jsxs("div",{children:[Xd.jsx("h3",{className:"font-medium text-gray-800",children:k(t)}),Xd.jsxs("p",{className:"text-sm text-gray-600",children:["Pay with ",k(t)]})]})]}),(null==p?void 0:p.walletType)===t?Xd.jsxs("div",{className:"flex items-center space-x-2",children:[Xd.jsx("div",{className:"w-2 h-2 bg-green-500 rounded-full"}),Xd.jsx("span",{className:"text-sm text-green-600",children:"Connected"})]}):Xd.jsx("button",{onClick:()=>{console.log("Connect wallet button clicked for:",t),f(t)},className:"py-2 px-4 bg-[#7042D2] hover:bg-[#7042D2] text-white font-medium rounded-md text-sm",children:"Connect"})]})},t))),Xd.jsx("div",{className:"space-y-2",children:Object.entries(_).filter((([t,e])=>!e)).map((([t])=>Xd.jsx("div",{className:"p-3 rounded-lg bg-gray-50",children:Xd.jsxs("div",{className:"flex items-center justify-between",children:[Xd.jsxs("span",{className:"text-sm text-gray-600",children:[k(t)," not detected"]}),Xd.jsx("a",{href:wd(t),target:"_blank",rel:"noopener noreferrer",className:"text-sm text-[#7042D2] hover:underline",children:"Install"})]})},t)))})]}),c&&Xd.jsx("div",{className:"p-3 rounded-lg bg-red-50 mb-4 text-red-600 text-sm",children:c}),Xd.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[Xd.jsx("button",{type:"button",onClick:l,className:"w-full py-2 px-4 bg-gray-200 hover:bg-gray-300 text-[#7042D2] font-medium rounded-md",children:"Back"}),Xd.jsx("button",{type:"button",onClick:()=>o("qrcode"===A),className:"w-full py-2 px-4 bg-[#7042D2] hover:bg-[#7042D2] text-white font-medium rounded-md",disabled:!g&&"wallet"===A&&!p,children:"qrcode"===A?"I have sent the payment":"Pay Now"})]})]}),"processing"===v&&Xd.jsx(kp,{status:"processing",theme:u,message:"Processing your payment..."}),"success"===v&&Xd.jsxs("div",{children:[Xd.jsx(kp,{status:"success",theme:u,message:"Payment successful!"}),d&&Xd.jsxs("div",{className:"mt-4 p-3 rounded-lg bg-gray-100",children:[Xd.jsx("p",{className:"text-xs text-gray-600 mb-1",children:"Transaction Hash:"}),Xd.jsx("p",{className:"text-sm font-mono break-all text-gray-800",children:(N=d,N?N.length<=14?N:`${N.slice(0,8)}...${N.slice(-6)}`:"")}),s&&Xd.jsx("a",{href:`${Pp(s.network)}/${Cp(s.network)}/${d}`,target:"_blank",rel:"noopener noreferrer",className:"text-xs text-[#7042D2] mt-2 inline-block",children:"View on Explorer →"})]})]}),"error"===v&&Xd.jsxs("div",{children:[Xd.jsx(kp,{status:"error",theme:u,message:c||"An error occurred while processing your payment."}),Xd.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"})]})]}),Xd.jsx("div",{className:"text-center text-xs text-gray-500",children:Xd.jsxs("p",{children:["Powered by ",Xd.jsx("span",{className:"text-[#7042D2]",children:"Coinley"})," - Secure Cryptocurrency Payments"]})})]})})}):null;var N,P},Pp=t=>({ethereum:"https://etherscan.io",bsc:"https://bscscan.com",tron:"https://tronscan.org",algorand:"https://algoexplorer.io"}[t]||"https://etherscan.io"),Cp=t=>({ethereum:"tx",bsc:"tx",tron:"transaction",algorand:"tx"}[t]||"tx"),Tp=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=ep(),{theme:v}=e.useContext($d),[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),[G,B]=e.useState(null),[M,O]=e.useState({}),[I,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 Ld();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);O(t),z("Available wallets detected:",t)})))()}}),[W]),e.useImperativeHandle(_,(()=>({open:t=>{V(t)},close:()=>{J()},getPayment:()=>A,getWalletConnection:()=>G,debugWallets:()=>Ed(),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 Ld(),L(e)),z("Using wallet addresses:",e);const r=yield jd({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)}})),J=()=>{b(!1),R(null),B(null),N(null),F("select-currency"),c&&c()};return Xd.jsx(Xd.Fragment,{children:w&&Xd.jsx(Np,{isOpen:w,onClose:J,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:",I),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(G||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 Rd(G,{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 Hd({paymentId:A.id,transactionHash:r,network:S.network,currency:S.currency,senderAddress:null==G?void 0:G.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"===I?(F("select-currency"),B(null)):"error"===I&&F("confirm")},error:P,theme:H,merchantName:s,transactionHash:T,walletConnection:G,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:",M),console.log("4. Current step:",I),!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 Pd(t,S.network);B(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:M,supportedWallets:S?Cd(S.network):[],step:I,merchantWalletAddresses:U,debug:W})})}));Tp.displayName="CoinleyCheckout";t.CoinleyCheckout=Tp,t.CoinleyModal=Np,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 Fd({apiKey:t,apiSecret:r,apiUrl:n,debug:a});const e=yield Ld(),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 Ld();return g(t),t}catch(t){return console.error("Failed to refresh merchant wallets:",t),f}}))};return Xd.jsx(tp.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=Sp,t.PaymentStatus=kp,t.QRCode=xp,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]),Xd.jsx($d.Provider,{value:{theme:n,setTheme:i,toggleTheme:()=>{i((t=>"light"===t?"dark":"light"))}},children:r})},t.WALLET_TYPES=gd,t.connectWallet=Pd,t.createPayment=jd,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=Ld,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:Dd()});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:Dd()});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=Cd,t.getWalletInstallUrl=wd,t.processPayment=Hd,t.sendTransaction=Rd,t.useCoinley=ep,t.validateWalletAddress=(t,e)=>__async(this,null,(function*(){try{const n=yield fetch(`${Id.apiUrl}/api/wallets/validate`,{method:"POST",headers:Dd(),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 vp(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 wp(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 bp({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(...hp.QrSegment.makeSegments(e)),t)),[]);return hp.QrCode.encodeSegments(e,dp[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 Ap=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=pp,level:a=fp,bgColor:o=gp,fgColor:l=mp,includeMargin:c=_p,minVersion:u=yp,boostLevel:h,marginSize:d,imageSettings:p}=n,f=up(n,["value","size","level","bgColor","fgColor","includeMargin","minVersion","boostLevel","marginSize","imageSettings"]),{style:g}=f,m=up(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}=bp({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=wp(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,Ap?e.fill(new Path2D(vp(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=cp({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",cp({style:N,height:s,width:s,ref:w,role:"img"},m)),P)})).displayName="QRCodeCanvas";var Ep=e.forwardRef((function(t,r){const n=t,{value:i,size:s=pp,level:a=fp,bgColor:o=gp,fgColor:l=mp,includeMargin:c=_p,minVersion:u=yp,boostLevel:h,title:d,marginSize:p,imageSettings:f}=n,g=up(n,["value","size","level","bgColor","fgColor","includeMargin","minVersion","boostLevel","title","marginSize","imageSettings"]),{margin:m,cells:_,numCells:y,calculatedImageSettings:v}=bp({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=wp(_,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=vp(w,m);return e.createElement("svg",cp({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)}));Ep.displayName="QRCodeSVG";const xp=({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 Xd.jsxs("div",{className:"flex flex-col items-center",children:[c?Xd.jsxs("div",{className:"p-4 rounded-lg bg-red-100 mb-3 text-red-700 text-center",children:[Xd.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:Xd.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"})}),Xd.jsx("p",{className:"font-medium",children:c})]}):Xd.jsx("div",{className:"p-4 rounded-lg bg-white mb-3 shadow-sm border",children:o&&Xd.jsx(Ep,{value:o,size:a,bgColor:"dark"===s?"#374151":"#FFFFFF",fgColor:"dark"===s?"#FFFFFF":"#000000",level:"H",includeMargin:!0})}),Xd.jsxs("div",{className:"text-center text-sm text-gray-700 mb-4",children:[Xd.jsxs("p",{className:"font-semibold text-gray-800 flex items-center justify-center",children:[Xd.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:Xd.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]}),Xd.jsxs("p",{className:"text-xs text-gray-500 mt-1",children:["Scan with your ",f(i)," wallet app"]})]}),Xd.jsxs("div",{className:"w-full mb-4 p-3 bg-gray-50 rounded-lg",children:[Xd.jsxs("div",{className:"flex justify-between items-center",children:[Xd.jsx("span",{className:"text-sm font-medium text-gray-700",children:"Amount to Pay:"}),Xd.jsxs("span",{className:"text-lg font-bold text-[#7042D2]",children:[r," ",n]})]}),Xd.jsxs("div",{className:"flex justify-between items-center mt-1",children:[Xd.jsx("span",{className:"text-xs text-gray-500",children:"Network:"}),Xd.jsx("span",{className:"text-xs font-medium text-gray-700",children:f(i)})]})]}),!c&&Xd.jsxs("div",{className:"w-full mb-4",children:[Xd.jsx("p",{className:"text-xs text-gray-500 mb-1 text-center",children:"Or copy wallet address:"}),Xd.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})]}),Xd.jsx("div",{className:"w-full",children:Xd.jsxs("div",{className:"p-3 rounded bg-blue-50 border border-blue-200",children:[Xd.jsxs("h4",{className:"text-sm font-medium mb-2 text-blue-800 flex items-center",children:[Xd.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:Xd.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"]}),Xd.jsxs("ol",{className:"text-xs space-y-1 text-blue-700",children:[Xd.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(", "),")"]}),Xd.jsx("li",{children:"2. Scan the QR code above or copy the wallet address"}),Xd.jsxs("li",{children:["3. Send exactly ",Xd.jsxs("strong",{children:[r," ",n]})," on ",f(i)," network"]}),Xd.jsx("li",{children:'4. Click "I have sent the payment" button below after sending'})]}),Xd.jsx("div",{className:"mt-3 p-2 bg-yellow-50 border border-yellow-200 rounded",children:Xd.jsxs("p",{className:"text-xs text-yellow-800",children:[Xd.jsx("strong",{children:"Important:"})," Make sure you're sending on the correct network (",f(i),") and using the exact amount shown above."]})})]})})]});var g},kp=({status:t,message:e,theme:r="light"})=>Xd.jsxs("div",{className:"flex flex-col items-center justify-center py-6",children:[Xd.jsx("div",{className:"mb-4",children:(()=>{switch(t){case"processing":return Xd.jsx("div",{className:"animate-spin rounded-full h-12 w-12 border-4 border-t-blue-500 border-blue-500/20"});case"success":return Xd.jsx("div",{className:"rounded-full h-12 w-12 bg-green-100 flex items-center justify-center",children:Xd.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:Xd.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5 13l4 4L19 7"})})});case"error":return Xd.jsx("div",{className:"rounded-full h-12 w-12 bg-red-100 flex items-center justify-center",children:Xd.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:Xd.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})})});default:return null}})()}),Xd.jsx("h3",{className:"text-xl font-bold mb-2 "+("dark"===r?"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"}})()}),Xd.jsx("p",{className:`text-center ${(()=>{switch(t){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:e}),"processing"===t&&Xd.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"===t&&Xd.jsx("div",{className:"mt-4 p-2 rounded "+("dark"===r?"bg-gray-700":"bg-gray-100"),children:Xd.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."})})]}),Sp=({onSelect:t,selected:r,theme:n="light",supportedNetworks:i=[]})=>{const[s,a]=e.useState(md.ETHEREUM),[o,l]=e.useState({}),[c,u]=e.useState(!1);e.useEffect((()=>{l(bd())}),[]);const h=[{id:md.ETHEREUM,name:"Ethereum",description:"ERC-20"},{id:md.BSC,name:"BSC",description:"BEP-20"},{id:md.TRON,name:"Tron",description:"TRC-20"},{id:md.ALGORAND,name:"Algorand",description:"ASA"}],d=(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:"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTcyJyRKN0dRJWVZqoLzYgkRHdJsxKGq8nHUw&s",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:"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRHSjyW2sSnBhwztCwVW97i1BtV40g7heMMxg&s",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})(s),p=c?d:d.slice(0,4);function f(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 Xd.jsxs("div",{children:[Xd.jsxs("div",{className:"mb-6",children:[Xd.jsx("label",{className:"block text-sm font-medium mb-2 "+("dark"===n?"text-white":"text-gray-700"),children:"Blockchain Network"}),Xd.jsx("select",{value:s,onChange:e=>{return n=e.target.value,a(n),u(!1),void((null==r?void 0:r.network)!==n&&t(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((t=>0===i.length||i.includes(t.id))).map((t=>Xd.jsxs("option",{value:t.id,children:[t.name," - ",t.description]},t.id)))})]}),Xd.jsxs("div",{className:"mb-4",children:[Xd.jsx("label",{className:"block text-sm font-medium mb-3 "+("dark"===n?"text-white":"text-gray-700"),children:"Select Stablecoin"}),Xd.jsx("div",{className:"grid grid-cols-2 gap-3 mb-4",children:p.map((e=>Xd.jsx("button",{onClick:()=>(e=>{var r;t({currency:e.id,network:s,tokenConfig:null==(r=yd[e.id])?void 0:r[s],method:e})})(e),className:"p-1 rounded-xl transition-all duration-200 border "+((null==r?void 0:r.currency)===e.id&&(null==r?void 0:r.network)===s?"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-[#ECE3FF] border-gray-200 hover:border-gray-300"),children:Xd.jsxs("div",{className:"flex items-center text-center",children:[Xd.jsx("div",{className:"flex-shrink-0 py-2 w-10 bg-white rounded-full flex items-center justify-center mb-2 shadow-sm",children:Xd.jsx("img",{src:e.logo,alt:e.name,className:"h-6 w-6"})}),Xd.jsxs("div",{className:"flex gap-x-2 items-center",children:[Xd.jsx("h4",{className:"font-medium text-sm "+("dark"===n?"text-white":"text-gray-900"),children:e.name}),Xd.jsx("p",{className:"text-xs "+("dark"===n?"text-gray-300":"text-gray-500"),children:e.description})]}),(null==r?void 0:r.currency)===e.id&&(null==r?void 0:r.network)===s&&Xd.jsx("div",{className:"mt-2",children:Xd.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-4 w-4 text-[#7042D2]",viewBox:"0 0 20 20",fill:"currentColor",children:Xd.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"})})})]})},`${e.id}-${e.network}`)))}),d.length>4&&Xd.jsx("button",{onClick:()=>u(!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 (${d.length-4} more)`})]}),Xd.jsx("div",{className:"p-3 rounded-lg text-sm "+("dark"===n?"bg-gray-800 text-gray-300":"bg-gray-50 text-gray-600"),children:Xd.jsxs("div",{className:"flex items-center",children:[Xd.jsx("div",{className:"w-2 h-2 rounded-full mr-2 "+(o[f(s)]?"bg-green-500":"bg-red-500")}),Xd.jsx("span",{className:"text-xs",children:function(t){const e=f(t),r=o[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`}(s)})]})})]})},Np=({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=>parseFloat(t).toFixed(2),k=t=>({ethereum:"Ethereum",bsc:"BSC",tron:"Tron",algorand:"Algorand"}[t]||t),S=t=>({[gd.METAMASK]:"MetaMask",[gd.TRONLINK]:"TronLink",[gd.TRUST_WALLET]:"Trust Wallet",[gd.LUTE]:"Lute Wallet"}[t]||t),N=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?Xd.jsx("div",{className:"fixed inset-0 z-50 overflow-y-auto bg-black/50",children:Xd.jsx("div",{className:"flex min-h-screen items-center justify-center p-4",children:Xd.jsxs("div",{className:"coinley-modal relative p-6 w-full max-w-md mx-auto rounded-lg shadow-xl",children:[Xd.jsxs("div",{className:"coinley-header flex justify-between items-center mb-6 bg-white",children:[Xd.jsx("div",{className:"flex items-center",children:Xd.jsx("h2",{className:"text-xl font-bold",children:Xd.jsx("img",{src:"data:image/png;base64,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IdD+z6jqQlXcuHL6MMHFYpEuDfYo2sSUtsPzQiDs6CQySTQgRldkWU6UKf+KRROxOaR4h5cF0kzk+pm2qdydUJF2D8yXH3NyPP21tf9dbYdOkDAOU3JFtF6R76EraO9PrfJC39hZv5NidG835b085Eb3qi4G/A2inrQKnVgMFAAAAABJRU5ErkJggg==",className:"w-24",alt:"Coinley Logo"})})}),Xd.jsx("button",{onClick:r,className:"text-gray-500 hover:text-gray-700 focus:outline-none",children:Xd.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-6 w-6",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:Xd.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),n&&Xd.jsxs("div",{className:"coinley-payment-info mb-6",children:[Xd.jsxs("div",{className:"text-center",children:[Xd.jsx("div",{className:"text-sm text-gray-600",children:"Total Amount"}),Xd.jsxs("div",{className:"coinley-amount-display text-4xl font-extrabold",children:["$",x(n.totalAmount||n.amount)]})]}),Xd.jsxs("div",{className:"text-center",children:[Xd.jsx("div",{className:"text-sm text-gray-600",children:"Payment To"}),Xd.jsx("div",{className:"coinley-merchant-name text-lg",children:h})]}),Xd.jsxs("div",{className:"flex justify-center gap-4 text-sm",children:[Xd.jsxs("div",{className:"px-3 py-2 rounded-lg",children:[Xd.jsx("div",{className:"text-gray-600 text-xs",children:"Original Amount"}),Xd.jsxs("div",{className:"font-semibold",children:["$",x(n.amount)]})]}),Xd.jsxs("div",{className:"px-3 py-2 rounded-lg",children:[Xd.jsx("div",{className:"text-gray-600 text-xs",children:"Fee (1.75%)"}),Xd.jsxs("div",{className:"font-semibold",children:["$",x((n.totalAmount||n.amount)-n.amount)]})]})]})]}),Xd.jsxs("div",{className:"mb-6",children:[b&&Xd.jsx("div",{className:"mb-2 text-right",children:Xd.jsx("button",{onClick:()=>{console.log("=== DEBUG INFO ==="),console.log("Current step:",v),console.log("Payment method:",s),console.log("Wallet connection:",p),Ed()},className:"text-xs bg-gray-200 p-1 rounded",children:"Debug"})}),"select-currency"===v&&Xd.jsxs("div",{children:[Xd.jsx(Sp,{onSelect:a,selected:s,theme:u,supportedNetworks:m}),s&&Xd.jsx("div",{className:"mt-6",children:Xd.jsxs("button",{onClick:()=>{console.log("Proceed button clicked, calling onPaymentMethodSelect"),a(s)},className:"coinley-button-primary w-full py-3 px-4 font-medium rounded-lg transition-colors",disabled:!s,children:["Proceed with ",s.currency," on ",k(s.network)]})})]}),"confirm"===v&&s&&n&&Xd.jsxs("div",{children:[Xd.jsxs("div",{className:"p-4 rounded-lg mb-4 bg-gray-100",children:[Xd.jsx("h3",{className:"text-lg font-medium mb-2 text-gray-800",children:"Payment Details"}),Xd.jsxs("div",{className:"space-y-2",children:[Xd.jsxs("div",{className:"flex justify-between",children:[Xd.jsx("span",{className:"text-purple-600 font-semibold",children:"Currency:"}),Xd.jsx("span",{className:"font-medium",children:s.currency})]}),Xd.jsxs("div",{className:"flex justify-between",children:[Xd.jsx("span",{className:"text-purple-600 font-semibold",children:"Network:"}),Xd.jsx("span",{className:"font-medium",children:k(s.network)})]}),Xd.jsxs("div",{className:"flex justify-between",children:[Xd.jsx("span",{className:"text-purple-600 font-semibold",children:"Fee:"}),Xd.jsx("span",{className:"font-medium",children:"1.75%"})]})]})]}),Xd.jsx("div",{className:"mb-4",children:Xd.jsxs("div",{className:"flex border-b border-gray-200",children:[Xd.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"}),Xd.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?Xd.jsx("div",{className:"p-4 rounded-lg mb-4 bg-blue-50",children:Xd.jsxs("div",{className:"flex items-center",children:[Xd.jsx("div",{className:"bg-purple-600 rounded-full p-2 mr-3",children:Xd.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:Xd.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 10V3L4 14h7v7l9-11h-7z"})})}),Xd.jsxs("div",{children:[Xd.jsx("h3",{className:"font-medium text-gray-800",children:"Test Mode Payment"}),Xd.jsx("p",{className:"text-sm text-gray-600",children:'Click "Pay Now" to simulate a successful payment'})]})]})}):"qrcode"===A?Xd.jsx("div",{className:"mb-4",children:Xd.jsx(xp,{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})}):Xd.jsxs("div",{className:"space-y-3 mb-4",children:[0===y.length?Xd.jsx("div",{className:"p-4 rounded-lg bg-yellow-50",children:Xd.jsxs("div",{className:"flex items-center",children:[Xd.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:Xd.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"})}),Xd.jsxs("div",{children:[Xd.jsx("h3",{className:"font-medium text-gray-800",children:"No Compatible Wallets"}),Xd.jsxs("p",{className:"text-sm text-gray-600",children:["No wallets detected for ",k(s.network)," network"]})]})]})}):y.map((t=>Xd.jsx("div",{className:"p-4 rounded-lg bg-blue-50",children:Xd.jsxs("div",{className:"flex items-center justify-between",children:[Xd.jsxs("div",{className:"flex items-center",children:[Xd.jsx("img",{src:N(t),alt:S(t),className:"w-8 h-8 mr-3",onError:t=>{t.target.style.display="none"}}),Xd.jsxs("div",{children:[Xd.jsx("h3",{className:"font-medium text-gray-800",children:S(t)}),Xd.jsxs("p",{className:"text-sm text-gray-600",children:["Pay with ",S(t)]})]})]}),(null==p?void 0:p.walletType)===t?Xd.jsxs("div",{className:"flex items-center space-x-2",children:[Xd.jsx("div",{className:"w-2 h-2 bg-green-500 rounded-full"}),Xd.jsx("span",{className:"text-sm text-green-600",children:"Connected"})]}):Xd.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))),Xd.jsx("div",{className:"space-y-2",children:Object.entries(_).filter((([t,e])=>!e)).map((([t])=>Xd.jsx("div",{className:"p-3 rounded-lg bg-gray-50",children:Xd.jsxs("div",{className:"flex items-center justify-between",children:[Xd.jsxs("span",{className:"text-sm text-gray-600",children:[S(t)," not detected"]}),Xd.jsx("a",{href:wd(t),target:"_blank",rel:"noopener noreferrer",className:"text-sm text-purple-600 hover:underline",children:"Install"})]})},t)))})]}),c&&Xd.jsx("div",{className:"p-3 rounded-lg bg-red-50 mb-4 text-red-600 text-sm",children:c}),Xd.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[Xd.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"}),Xd.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&&Xd.jsx(kp,{status:"processing",theme:u,message:"Processing your payment..."}),"success"===v&&Xd.jsxs("div",{children:[Xd.jsx(kp,{status:"success",theme:u,message:"Payment successful!"}),d&&Xd.jsxs("div",{className:"mt-4 p-3 rounded-lg bg-gray-100",children:[Xd.jsx("p",{className:"text-xs text-gray-600 mb-1",children:"Transaction Hash:"}),Xd.jsx("p",{className:"text-sm font-mono break-all text-gray-800",children:(P=d,P?P.length<=14?P:`${P.slice(0,8)}...${P.slice(-6)}`:"")}),s&&Xd.jsx("a",{href:`${Pp(s.network)}/${Cp(s.network)}/${d}`,target:"_blank",rel:"noopener noreferrer",className:"text-xs text-purple-600 mt-2 inline-block",children:"View on Explorer →"})]})]}),"error"===v&&Xd.jsxs("div",{children:[Xd.jsx(kp,{status:"error",theme:u,message:c||"An error occurred while processing your payment."}),Xd.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"})]})]}),Xd.jsx("div",{className:"text-center text-xs text-gray-500",children:Xd.jsxs("p",{children:["Powered by ",Xd.jsx("span",{className:"text-purple-600",children:"Coinley"})," - Secure Cryptocurrency Payments"]})})]})})}):null;var P},Pp=t=>({ethereum:"https://etherscan.io",bsc:"https://bscscan.com",tron:"https://tronscan.org",algorand:"https://algoexplorer.io"}[t]||"https://etherscan.io"),Cp=t=>({ethereum:"tx",bsc:"tx",tron:"transaction",algorand:"tx"}[t]||"tx"),Tp=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=ep(),{theme:v}=e.useContext($d),[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),[G,B]=e.useState(null),[M,O]=e.useState({}),[I,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 Ld();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);O(t),z("Available wallets detected:",t)})))()}}),[W]),e.useImperativeHandle(_,(()=>({open:t=>{V(t)},close:()=>{J()},getPayment:()=>A,getWalletConnection:()=>G,debugWallets:()=>Ed(),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 Ld(),L(e)),z("Using wallet addresses:",e);const r=yield jd({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)}})),J=()=>{b(!1),R(null),B(null),N(null),F("select-currency"),c&&c()};return Xd.jsx(Xd.Fragment,{children:w&&Xd.jsx(Np,{isOpen:w,onClose:J,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:",I),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(G||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 Rd(G,{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 Hd({paymentId:A.id,transactionHash:r,network:S.network,currency:S.currency,senderAddress:null==G?void 0:G.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"===I?(F("select-currency"),B(null)):"error"===I&&F("confirm")},error:P,theme:H,merchantName:s,transactionHash:T,walletConnection:G,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:",M),console.log("4. Current step:",I),!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 Pd(t,S.network);B(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:M,supportedWallets:S?Cd(S.network):[],step:I,merchantWalletAddresses:U,debug:W})})}));Tp.displayName="CoinleyCheckout";t.CoinleyCheckout=Tp,t.CoinleyModal=Np,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 Fd({apiKey:t,apiSecret:r,apiUrl:n,debug:a});const e=yield Ld(),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 Ld();return g(t),t}catch(t){return console.error("Failed to refresh merchant wallets:",t),f}}))};return Xd.jsx(tp.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=Sp,t.PaymentStatus=kp,t.QRCode=xp,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]),Xd.jsx($d.Provider,{value:{theme:n,setTheme:i,toggleTheme:()=>{i((t=>"light"===t?"dark":"light"))}},children:r})},t.WALLET_TYPES=gd,t.connectWallet=Pd,t.createPayment=jd,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=Ld,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:Dd()});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:Dd()});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=Cd,t.getWalletInstallUrl=wd,t.processPayment=Hd,t.sendTransaction=Rd,t.useCoinley=ep,t.validateWalletAddress=(t,e)=>__async(this,null,(function*(){try{const n=yield fetch(`${Id.apiUrl}/api/wallets/validate`,{method:"POST",headers:Dd(),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
|