coinley-checkout 0.4.1 → 0.4.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.
@@ -1,7 +1,7 @@
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).CoinleyCheckout={},e.React)}(this,(function(e,t){"use strict";var r=Object.defineProperty,n=Object.defineProperties,s=Object.getOwnPropertyDescriptors,o=Object.getOwnPropertySymbols,a=Object.prototype.hasOwnProperty,l=Object.prototype.propertyIsEnumerable,i=(e,t,n)=>t in e?r(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,c=(e,t)=>{for(var r in t||(t={}))a.call(t,r)&&i(e,r,t[r]);if(o)for(var r of o(t))l.call(t,r)&&i(e,r,t[r]);return e},d=(e,t,r)=>new Promise(((n,s)=>{var o=e=>{try{l(r.next(e))}catch(t){s(t)}},a=e=>{try{l(r.throw(e))}catch(t){s(t)}},l=e=>e.done?n(e.value):Promise.resolve(e.value).then(o,a);l((r=r.apply(e,t)).next())}));const u={ETHEREUM:"ethereum",BSC:"bsc",TRON:"tron",ALGORAND:"algorand"},h={METAMASK:"metamask",TRONLINK:"tronlink",TRUST_WALLET:"trust_wallet",LUTE:"lute"},m={[u.ETHEREUM]:{chainId:"0x1",chainName:"Ethereum Mainnet",nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18},rpcUrls:["https://mainnet.infura.io/v3/"],blockExplorerUrls:["https://etherscan.io/"],supportedWallets:[h.METAMASK,h.TRUST_WALLET]},[u.BSC]:{chainId:"0x38",chainName:"BNB Smart Chain",nativeCurrency:{name:"BNB",symbol:"BNB",decimals:18},rpcUrls:["https://bsc-dataseed.binance.org/"],blockExplorerUrls:["https://bscscan.com/"],supportedWallets:[h.METAMASK,h.TRUST_WALLET]},[u.TRON]:{fullHost:"https://api.trongrid.io",explorerUrl:"https://tronscan.org",supportedWallets:[h.TRONLINK]},[u.ALGORAND]:{network:"mainnet",explorerUrl:"https://algoexplorer.io",supportedWallets:[h.LUTE]}},g={USDT:{[u.ETHEREUM]:{address:"0xdAC17F958D2ee523a2206206994597C13D831ec7",decimals:6},[u.BSC]:{address:"0x55d398326f99059fF775485246999027B3197955",decimals:18},[u.TRON]:{address:"TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t",decimals:6},[u.ALGORAND]:{address:"312769",decimals:6}},USDC:{[u.ETHEREUM]:{address:"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",decimals:6},[u.BSC]:{address:"0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d",decimals:18},[u.TRON]:{address:"TEkxiTehnzSmSe2XqrBj4w32RUN966rdz8",decimals:6},[u.ALGORAND]:{address:"31566704",decimals:6}},PYUSD:{[u.ETHEREUM]:{address:"0x6c3ea9036406852006290770BEdFcAbA0e23A0e8",decimals:6}},FRAX:{[u.ETHEREUM]:{address:"0x853d955aCEf822Db058eb8505911ED77F175b99e",decimals:18},[u.BSC]:{address:"0x90C97F71E18723b0Cf0dfa30ee176Ab653E89F40",decimals:18}},USDP:{[u.ETHEREUM]:{address:"0x8E870D67F660D95d5be530380D0eC0bd388289E1",decimals:18}},DAI:{[u.ETHEREUM]:{address:"0x6B175474E89094C44Da98b954EedeAC495271d0F",decimals:18}},BUSD:{[u.BSC]:{address:"0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56",decimals:18}},USDJ:{[u.TRON]:{address:"TMwFHYXLJaRUPeW6421aqXL4ZEzPRFGkGT",decimals:18}},ALGO:{[u.ALGORAND]:{address:"native",decimals:6}}},w=()=>{const e={[h.METAMASK]:!1,[h.TRUST_WALLET]:!1,[h.TRONLINK]:!1,[h.LUTE]:!1};if("undefined"==typeof window)return e;try{if(console.log("=== ENHANCED WALLET DETECTION DEBUG ==="),window.ethereum&&(window.ethereum.isMetaMask&&(e[h.METAMASK]=!0,console.log("✅ MetaMask detected via direct isMetaMask")),window.ethereum.providers&&Array.isArray(window.ethereum.providers))){window.ethereum.providers.find((e=>e.isMetaMask))&&(e[h.METAMASK]=!0,console.log("✅ MetaMask detected via providers array"))}if(window.ethereum){if((window.ethereum.isTrust||window.ethereum.isTrustWallet)&&(e[h.TRUST_WALLET]=!0,console.log("✅ Trust Wallet detected via direct property")),window.ethereum.providers&&Array.isArray(window.ethereum.providers)){window.ethereum.providers.find((e=>e.isTrust||e.isTrustWallet||e.constructor&&"TrustWallet"===e.constructor.name))&&(e[h.TRUST_WALLET]=!0,console.log("✅ Trust Wallet detected via providers array"))}navigator.userAgent&&navigator.userAgent.includes("Trust")&&(e[h.TRUST_WALLET]=!0,console.log("✅ Trust Wallet detected via user agent")),(window.ethereum.isTrustWallet||window.trustwallet)&&(e[h.TRUST_WALLET]=!0,console.log("✅ Trust Wallet detected via specific methods"))}if(window.tronWeb&&window.tronWeb.defaultAddress&&(e[h.TRONLINK]=!0,console.log("✅ TronLink detected via tronWeb")),window.tronLink&&(e[h.TRONLINK]=!0,console.log("✅ TronLink detected via tronLink object")),window.tron&&(e[h.TRONLINK]=!0,console.log("✅ TronLink detected via tron object")),window.tronWeb&&(window.tronWeb.ready||window.tronWeb.installed)&&(e[h.TRONLINK]=!0,console.log("✅ TronLink detected via ready/installed properties")),window.algorand&&(window.algorand.isLute?(e[h.LUTE]=!0,console.log("✅ Lute Wallet detected via algorand.isLute")):(e[h.LUTE]=!0,console.log("✅ Algorand wallet detected (assuming Lute)"))),window.navigator&&window.navigator.userAgent){const t=window.navigator.userAgent.toLowerCase();t.includes("trustwallet")&&(e[h.TRUST_WALLET]=!0,console.log("✅ Trust Wallet detected via mobile user agent")),t.includes("tronlink")&&(e[h.TRONLINK]=!0,console.log("✅ TronLink detected via mobile user agent"))}console.log("Final wallet detection results:",e),console.log("=== END ENHANCED WALLET DETECTION DEBUG ===")}catch(t){console.warn("Error detecting wallets:",t)}return e},p=e=>{const t=m[e];if(!t)return[];const r=w();return t.supportedWallets.filter((e=>r[e]))},f=(e,t)=>d(this,null,(function*(){switch(console.log("connectWallet called with:",{walletType:e,network:t}),e){case h.METAMASK:return yield y(t);case h.TRONLINK:return yield x();case h.TRUST_WALLET:return yield E(t);case h.LUTE:return yield b();default:throw new Error(`Unsupported wallet type: ${e}`)}})),y=e=>d(this,null,(function*(){if(console.log("Attempting to connect MetaMask for network:",e),"undefined"==typeof window||!window.ethereum)throw new Error("MetaMask is not installed. Please install MetaMask extension.");try{console.log("Requesting accounts from MetaMask...");const t=yield window.ethereum.request({method:"eth_requestAccounts"});if(console.log("Accounts received:",t),!t||0===t.length)throw new Error("No accounts found. Please unlock MetaMask.");const r=m[e];r&&r.chainId&&(console.log("Switching to network:",r.chainName),yield N(r));const n={address:t[0],network:e,walletType:h.METAMASK};return console.log("MetaMask connected successfully:",n),n}catch(t){if(console.error("MetaMask connection error:",t),4001===t.code)throw new Error("Connection rejected by user.");if(-32002===t.code)throw new Error("Connection request pending. Please check MetaMask.");throw new Error(`Failed to connect MetaMask: ${t.message}`)}})),x=()=>d(this,null,(function*(){var e;if("undefined"==typeof window||!window.tronWeb)throw new Error("TronLink is not installed.");let t=0;for(;!window.tronWeb.ready&&t<10;)yield new Promise((e=>setTimeout(e,1e3))),t++;if(!window.tronWeb.ready)throw new Error("TronLink is not ready. Please unlock your wallet.");const r=null==(e=window.tronWeb.defaultAddress)?void 0:e.base58;if(!r)throw new Error("No account found in TronLink.");return{address:r,network:u.TRON,walletType:h.TRONLINK}})),E=e=>d(this,null,(function*(){if("undefined"==typeof window||!window.ethereum||!window.ethereum.isTrust)throw new Error("Trust Wallet is not installed.");try{const t=yield window.ethereum.request({method:"eth_requestAccounts"});if(!t||0===t.length)throw new Error("No accounts found. Please unlock Trust Wallet.");const r=m[e];return r&&r.chainId&&(yield N(r)),{address:t[0],network:e,walletType:h.TRUST_WALLET}}catch(t){if(4001===t.code)throw new Error("User rejected the connection request");throw new Error(`Failed to connect Trust Wallet: ${t.message}`)}})),b=()=>d(this,null,(function*(){if("undefined"==typeof window||!window.algorand||!window.algorand.isLute)throw new Error("Lute wallet is not installed.");try{const e=yield window.algorand.connect();if(!e||0===e.length)throw new Error("No accounts found. Please unlock Lute wallet.");return{address:e[0],network:u.ALGORAND,walletType:h.LUTE}}catch(e){throw new Error(`Failed to connect Lute wallet: ${e.message}`)}})),N=e=>d(this,null,(function*(){if("undefined"==typeof window||!window.ethereum)throw new Error("Ethereum provider not found");try{console.log("Attempting to switch to:",e.chainName),yield window.ethereum.request({method:"wallet_switchEthereumChain",params:[{chainId:e.chainId}]}),console.log("Network switched successfully")}catch(t){if(console.error("Network switch error:",t),4902!==t.code)throw 4001===t.code?new Error("User rejected network switch request."):new Error(`Failed to switch to ${e.chainName}.`);try{yield window.ethereum.request({method:"wallet_addEthereumChain",params:[e]}),console.log("Network added successfully")}catch(r){throw new Error(`Failed to add ${e.chainName} to wallet.`)}}})),A=(e,t)=>d(this,null,(function*(){const{walletType:r,network:n,address:s}=e,{to:o,amount:a,tokenAddress:l,tokenDecimals:i,currency:c}=t;switch(console.log("sendTransaction called with:",{walletConnection:e,transactionData:t}),r){case h.METAMASK:case h.TRUST_WALLET:return yield k(s,o,a,l,i,c,n);case h.TRONLINK:return yield v(o,a,l,i);case h.LUTE:return yield T(s,o,a);default:throw new Error(`Unsupported wallet type: ${r}`)}})),k=(e,t,r,n,s,o,a)=>d(this,null,(function*(){if(console.log("sendEVMTransactionNative called with:",{from:e,to:t,amount:r,tokenAddress:n,tokenDecimals:s,currency:o,network:a}),"undefined"==typeof window||!window.ethereum)throw new Error("Ethereum provider not found");try{let c=n,d=s;if(o&&a)try{const e=((e,t)=>{console.log("getTokenConfig called with:",{currency:e,network:t});const r=g[e];if(!r)throw new Error(`Unsupported currency: ${e}`);const n=r[t];if(!n)throw new Error(`Currency ${e} not supported on network ${t}`);return console.log("Token config found:",n),n})(o,a);c=e.address,d=e.decimals,console.log("Using token config:",{currency:o,network:a,address:c,decimals:d})}catch(i){console.warn("Could not get token config, using provided values:",i.message)}if(c&&"native"!==c){console.log("Preparing ERC20 token transfer...");const n=d||18,s=((e,t)=>{console.log("calculateTokenAmount called with:",{amount:e,decimals:t});const r=parseInt(t)||18,n=parseFloat(e);if(isNaN(n)||n<=0)throw new Error(`Invalid amount: ${e}`);const s=Math.pow(10,r),o=Math.floor(n*s),a="0x"+o.toString(16);return console.log("Amount calculation:",{originalAmount:e,decimals:r,multiplier:s,calculatedAmount:o,hexAmount:a}),a})(r,n),a="0xa9059cbb",l=t.replace("0x","").toLowerCase().padStart(64,"0"),i=s.replace("0x","").padStart(64,"0"),u=a+l+i;console.log("ERC20 transaction details:",{currency:o,tokenAddress:c,decimals:n,amountHex:s,transferMethodId:a,paddedToAddress:l,paddedAmount:i,data:u});const h=yield window.ethereum.request({method:"eth_sendTransaction",params:[{from:e,to:c,data:u,gas:"0x15F90"}]});return console.log("ERC20 transaction successful:",h),h}{console.log("Preparing native token transfer...");const n=(l=r,"0x"+Math.floor(parseFloat(l)*Math.pow(10,18)).toString(16));console.log("Native transaction amount:",{amount:r,amountHex:n});const s=yield window.ethereum.request({method:"eth_sendTransaction",params:[{from:e,to:t,value:n,gas:"0x5208"}]});return console.log("Native transaction successful:",s),s}}catch(c){if(console.error("EVM transaction error:",c),4001===c.code)throw new Error("Transaction was rejected by user");if(c.message&&c.message.includes("insufficient funds"))throw new Error("Insufficient balance to complete the transaction");if(c.message&&c.message.includes("gas"))throw new Error("Transaction failed due to gas estimation issues. Please try again.");throw new Error(`Transaction failed: ${c.message||"Unknown error"}`)}var l})),v=(e,t,r,n)=>d(this,null,(function*(){if("undefined"==typeof window||!window.tronWeb||!window.tronWeb.ready)throw new Error("TronLink is not ready");try{const s=Math.floor(parseFloat(t)*Math.pow(10,n||6));if(r&&"native"!==r){const t=yield window.tronWeb.contract().at(r);return yield t.transfer(e,s).send({feeLimit:1e8,callValue:0})}return(yield window.tronWeb.trx.sendTransaction(e,s)).txid}catch(s){throw new Error(`TRON transaction failed: ${s.message}`)}})),T=(e,t,r)=>d(this,null,(function*(){if("undefined"==typeof window||!window.algorand)throw new Error("Algorand wallet is not available");try{const n=Math.floor(1e6*parseFloat(r)),s={from:e,to:t,amount:n,type:"pay"},o=yield window.algorand.signTransaction(s);return(yield window.algorand.sendTransaction(o)).txId}catch(n){throw new Error(`Algorand transaction failed: ${n.message}`)}})),S=e=>({[h.METAMASK]:"https://metamask.io/",[h.TRONLINK]:"https://www.tronlink.org/",[h.TRUST_WALLET]:"https://trustwallet.com/",[h.LUTE]:"https://lute.app/"}[e]||"");let C={apiKey:null,apiSecret:null,apiUrl:"http://localhost:9000",merchantWalletAddresses:{}};const M=()=>({"Content-Type":"application/json","x-api-key":C.apiKey,"x-api-secret":C.apiSecret}),j=e=>d(this,null,(function*(){try{console.log("Creating payment with data:",e),console.log("API URL:",`${C.apiUrl}/api/payments/create`);const o=(t=c({},e),r={merchantWalletAddresses:c(c({},C.merchantWalletAddresses),e.merchantWalletAddresses)},n(t,s(r))),a=yield fetch(`${C.apiUrl}/api/payments/create`,{method:"POST",headers:M(),body:JSON.stringify(o)});if(console.log("Create payment response status:",a.status),!a.ok){const e=yield a.json();throw console.error("Error creating payment:",e),new Error(e.error||`Failed to create payment: ${a.status}`)}const l=yield a.json();return console.log("Create payment response data:",l),l}catch(o){throw console.error("Create payment error:",o),o}var t,r})),R=e=>d(this,null,(function*(){try{console.log("Processing payment with data:",e),console.log("API URL:",`${C.apiUrl}/api/payments/process`);const t=yield fetch(`${C.apiUrl}/api/payments/process`,{method:"POST",headers:M(),body:JSON.stringify(e)});if(console.log("Process payment response status:",t.status),!t.ok){const e=yield t.json();throw console.error("Error processing payment:",e),new Error(e.error||`Failed to process payment: ${t.status}`)}const r=yield t.json();return console.log("Process payment response data:",r),r}catch(t){throw console.error("Process payment error:",t),t}}));var L={exports:{}},D={},U=t,P=Symbol.for("react.element"),O=Symbol.for("react.fragment"),W=Object.prototype.hasOwnProperty,I=U.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,F={key:!0,ref:!0,__self:!0,__source:!0};function B(e,t,r){var n,s={},o=null,a=null;for(n in void 0!==r&&(o=""+r),void 0!==t.key&&(o=""+t.key),void 0!==t.ref&&(a=t.ref),t)W.call(t,n)&&!F.hasOwnProperty(n)&&(s[n]=t[n]);if(e&&e.defaultProps)for(n in t=e.defaultProps)void 0===s[n]&&(s[n]=t[n]);return{$$typeof:P,type:e,key:o,ref:a,props:s,_owner:I.current}}D.Fragment=O,D.jsx=B,D.jsxs=B,L.exports=D;var z=L.exports;const H=t.createContext(),G=t.createContext(),q=()=>t.useContext(G);var K,Q,_=Object.defineProperty,V=Object.getOwnPropertySymbols,J=Object.prototype.hasOwnProperty,$=Object.prototype.propertyIsEnumerable,Y=(e,t,r)=>t in e?_(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,X=(e,t)=>{for(var r in t||(t={}))J.call(t,r)&&Y(e,r,t[r]);if(V)for(var r of V(t))$.call(t,r)&&Y(e,r,t[r]);return e},Z=(e,t)=>{var r={};for(var n in e)J.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(null!=e&&V)for(var n of V(e))t.indexOf(n)<0&&$.call(e,n)&&(r[n]=e[n]);return r};(e=>{const t=class t{constructor(e,r,n,o){if(this.version=e,this.errorCorrectionLevel=r,this.modules=[],this.isFunction=[],e<t.MIN_VERSION||e>t.MAX_VERSION)throw new RangeError("Version value out of range");if(o<-1||o>7)throw new RangeError("Mask value out of range");this.size=4*e+17;let a=[];for(let t=0;t<this.size;t++)a.push(!1);for(let t=0;t<this.size;t++)this.modules.push(a.slice()),this.isFunction.push(a.slice());this.drawFunctionPatterns();const l=this.addEccAndInterleave(n);if(this.drawCodewords(l),-1==o){let e=1e9;for(let t=0;t<8;t++){this.applyMask(t),this.drawFormatBits(t);const r=this.getPenaltyScore();r<e&&(o=t,e=r),this.applyMask(t)}}s(0<=o&&o<=7),this.mask=o,this.applyMask(o),this.drawFormatBits(o),this.isFunction=[]}static encodeText(r,n){const s=e.QrSegment.makeSegments(r);return t.encodeSegments(s,n)}static encodeBinary(r,n){const s=e.QrSegment.makeBytes(r);return t.encodeSegments([s],n)}static encodeSegments(e,n,o=1,l=40,i=-1,c=!0){if(!(t.MIN_VERSION<=o&&o<=l&&l<=t.MAX_VERSION)||i<-1||i>7)throw new RangeError("Invalid value");let d,u;for(d=o;;d++){const r=8*t.getNumDataCodewords(d,n),s=a.getTotalBits(e,d);if(s<=r){u=s;break}if(d>=l)throw new RangeError("Data too long")}for(const r of[t.Ecc.MEDIUM,t.Ecc.QUARTILE,t.Ecc.HIGH])c&&u<=8*t.getNumDataCodewords(d,r)&&(n=r);let h=[];for(const t of e){r(t.mode.modeBits,4,h),r(t.numChars,t.mode.numCharCountBits(d),h);for(const e of t.getData())h.push(e)}s(h.length==u);const m=8*t.getNumDataCodewords(d,n);s(h.length<=m),r(0,Math.min(4,m-h.length),h),r(0,(8-h.length%8)%8,h),s(h.length%8==0);for(let t=236;h.length<m;t^=253)r(t,8,h);let g=[];for(;8*g.length<h.length;)g.push(0);return h.forEach(((e,t)=>g[t>>>3]|=e<<7-(7&t))),new t(d,n,g,i)}getModule(e,t){return 0<=e&&e<this.size&&0<=t&&t<this.size&&this.modules[t][e]}getModules(){return this.modules}drawFunctionPatterns(){for(let r=0;r<this.size;r++)this.setFunctionModule(6,r,r%2==0),this.setFunctionModule(r,6,r%2==0);this.drawFinderPattern(3,3),this.drawFinderPattern(this.size-4,3),this.drawFinderPattern(3,this.size-4);const e=this.getAlignmentPatternPositions(),t=e.length;for(let r=0;r<t;r++)for(let n=0;n<t;n++)0==r&&0==n||0==r&&n==t-1||r==t-1&&0==n||this.drawAlignmentPattern(e[r],e[n]);this.drawFormatBits(0),this.drawVersion()}drawFormatBits(e){const t=this.errorCorrectionLevel.formatBits<<3|e;let r=t;for(let n=0;n<10;n++)r=r<<1^1335*(r>>>9);const o=21522^(t<<10|r);s(o>>>15==0);for(let s=0;s<=5;s++)this.setFunctionModule(8,s,n(o,s));this.setFunctionModule(8,7,n(o,6)),this.setFunctionModule(8,8,n(o,7)),this.setFunctionModule(7,8,n(o,8));for(let s=9;s<15;s++)this.setFunctionModule(14-s,8,n(o,s));for(let s=0;s<8;s++)this.setFunctionModule(this.size-1-s,8,n(o,s));for(let s=8;s<15;s++)this.setFunctionModule(8,this.size-15+s,n(o,s));this.setFunctionModule(8,this.size-8,!0)}drawVersion(){if(this.version<7)return;let e=this.version;for(let r=0;r<12;r++)e=e<<1^7973*(e>>>11);const t=this.version<<12|e;s(t>>>18==0);for(let r=0;r<18;r++){const e=n(t,r),s=this.size-11+r%3,o=Math.floor(r/3);this.setFunctionModule(s,o,e),this.setFunctionModule(o,s,e)}}drawFinderPattern(e,t){for(let r=-4;r<=4;r++)for(let n=-4;n<=4;n++){const s=Math.max(Math.abs(n),Math.abs(r)),o=e+n,a=t+r;0<=o&&o<this.size&&0<=a&&a<this.size&&this.setFunctionModule(o,a,2!=s&&4!=s)}}drawAlignmentPattern(e,t){for(let r=-2;r<=2;r++)for(let n=-2;n<=2;n++)this.setFunctionModule(e+n,t+r,1!=Math.max(Math.abs(n),Math.abs(r)))}setFunctionModule(e,t,r){this.modules[t][e]=r,this.isFunction[t][e]=!0}addEccAndInterleave(e){const r=this.version,n=this.errorCorrectionLevel;if(e.length!=t.getNumDataCodewords(r,n))throw new RangeError("Invalid argument");const o=t.NUM_ERROR_CORRECTION_BLOCKS[n.ordinal][r],a=t.ECC_CODEWORDS_PER_BLOCK[n.ordinal][r],l=Math.floor(t.getNumRawDataModules(r)/8),i=o-l%o,c=Math.floor(l/o);let d=[];const u=t.reedSolomonComputeDivisor(a);for(let s=0,m=0;s<o;s++){let r=e.slice(m,m+c-a+(s<i?0:1));m+=r.length;const n=t.reedSolomonComputeRemainder(r,u);s<i&&r.push(0),d.push(r.concat(n))}let h=[];for(let t=0;t<d[0].length;t++)d.forEach(((e,r)=>{(t!=c-a||r>=i)&&h.push(e[t])}));return s(h.length==l),h}drawCodewords(e){if(e.length!=Math.floor(t.getNumRawDataModules(this.version)/8))throw new RangeError("Invalid argument");let r=0;for(let t=this.size-1;t>=1;t-=2){6==t&&(t=5);for(let s=0;s<this.size;s++)for(let o=0;o<2;o++){const a=t-o,l=!(t+1&2)?this.size-1-s:s;!this.isFunction[l][a]&&r<8*e.length&&(this.modules[l][a]=n(e[r>>>3],7-(7&r)),r++)}}s(r==8*e.length)}applyMask(e){if(e<0||e>7)throw new RangeError("Mask value out of range");for(let t=0;t<this.size;t++)for(let r=0;r<this.size;r++){let n;switch(e){case 0:n=(r+t)%2==0;break;case 1:n=t%2==0;break;case 2:n=r%3==0;break;case 3:n=(r+t)%3==0;break;case 4:n=(Math.floor(r/3)+Math.floor(t/2))%2==0;break;case 5:n=r*t%2+r*t%3==0;break;case 6:n=(r*t%2+r*t%3)%2==0;break;case 7:n=((r+t)%2+r*t%3)%2==0;break;default:throw new Error("Unreachable")}!this.isFunction[t][r]&&n&&(this.modules[t][r]=!this.modules[t][r])}}getPenaltyScore(){let e=0;for(let s=0;s<this.size;s++){let r=!1,n=0,o=[0,0,0,0,0,0,0];for(let a=0;a<this.size;a++)this.modules[s][a]==r?(n++,5==n?e+=t.PENALTY_N1:n>5&&e++):(this.finderPenaltyAddHistory(n,o),r||(e+=this.finderPenaltyCountPatterns(o)*t.PENALTY_N3),r=this.modules[s][a],n=1);e+=this.finderPenaltyTerminateAndCount(r,n,o)*t.PENALTY_N3}for(let s=0;s<this.size;s++){let r=!1,n=0,o=[0,0,0,0,0,0,0];for(let a=0;a<this.size;a++)this.modules[a][s]==r?(n++,5==n?e+=t.PENALTY_N1:n>5&&e++):(this.finderPenaltyAddHistory(n,o),r||(e+=this.finderPenaltyCountPatterns(o)*t.PENALTY_N3),r=this.modules[a][s],n=1);e+=this.finderPenaltyTerminateAndCount(r,n,o)*t.PENALTY_N3}for(let s=0;s<this.size-1;s++)for(let r=0;r<this.size-1;r++){const n=this.modules[s][r];n==this.modules[s][r+1]&&n==this.modules[s+1][r]&&n==this.modules[s+1][r+1]&&(e+=t.PENALTY_N2)}let r=0;for(const t of this.modules)r=t.reduce(((e,t)=>e+(t?1:0)),r);const n=this.size*this.size,o=Math.ceil(Math.abs(20*r-10*n)/n)-1;return s(0<=o&&o<=9),e+=o*t.PENALTY_N4,s(0<=e&&e<=2568888),e}getAlignmentPatternPositions(){if(1==this.version)return[];{const e=Math.floor(this.version/7)+2,t=32==this.version?26:2*Math.ceil((4*this.version+4)/(2*e-2));let r=[6];for(let n=this.size-7;r.length<e;n-=t)r.splice(1,0,n);return r}}static getNumRawDataModules(e){if(e<t.MIN_VERSION||e>t.MAX_VERSION)throw new RangeError("Version number out of range");let r=(16*e+128)*e+64;if(e>=2){const t=Math.floor(e/7)+2;r-=(25*t-10)*t-55,e>=7&&(r-=36)}return s(208<=r&&r<=29648),r}static getNumDataCodewords(e,r){return Math.floor(t.getNumRawDataModules(e)/8)-t.ECC_CODEWORDS_PER_BLOCK[r.ordinal][e]*t.NUM_ERROR_CORRECTION_BLOCKS[r.ordinal][e]}static reedSolomonComputeDivisor(e){if(e<1||e>255)throw new RangeError("Degree out of range");let r=[];for(let t=0;t<e-1;t++)r.push(0);r.push(1);let n=1;for(let s=0;s<e;s++){for(let e=0;e<r.length;e++)r[e]=t.reedSolomonMultiply(r[e],n),e+1<r.length&&(r[e]^=r[e+1]);n=t.reedSolomonMultiply(n,2)}return r}static reedSolomonComputeRemainder(e,r){let n=r.map((e=>0));for(const s of e){const e=s^n.shift();n.push(0),r.forEach(((r,s)=>n[s]^=t.reedSolomonMultiply(r,e)))}return n}static reedSolomonMultiply(e,t){if(e>>>8!=0||t>>>8!=0)throw new RangeError("Byte out of range");let r=0;for(let n=7;n>=0;n--)r=r<<1^285*(r>>>7),r^=(t>>>n&1)*e;return s(r>>>8==0),r}finderPenaltyCountPatterns(e){const t=e[1];s(t<=3*this.size);const r=t>0&&e[2]==t&&e[3]==3*t&&e[4]==t&&e[5]==t;return(r&&e[0]>=4*t&&e[6]>=t?1:0)+(r&&e[6]>=4*t&&e[0]>=t?1:0)}finderPenaltyTerminateAndCount(e,t,r){return e&&(this.finderPenaltyAddHistory(t,r),t=0),t+=this.size,this.finderPenaltyAddHistory(t,r),this.finderPenaltyCountPatterns(r)}finderPenaltyAddHistory(e,t){0==t[0]&&(e+=this.size),t.pop(),t.unshift(e)}};function r(e,t,r){if(t<0||t>31||e>>>t!=0)throw new RangeError("Value out of range");for(let n=t-1;n>=0;n--)r.push(e>>>n&1)}function n(e,t){return!!(e>>>t&1)}function s(e){if(!e)throw new Error("Assertion error")}t.MIN_VERSION=1,t.MAX_VERSION=40,t.PENALTY_N1=3,t.PENALTY_N2=3,t.PENALTY_N3=40,t.PENALTY_N4=10,t.ECC_CODEWORDS_PER_BLOCK=[[-1,7,10,15,20,26,18,20,24,30,18,20,24,26,30,22,24,28,30,28,28,28,28,30,30,26,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,10,16,26,18,24,16,18,22,22,26,30,22,22,24,24,28,28,26,26,26,26,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28],[-1,13,22,18,26,18,24,18,22,20,24,28,26,24,20,30,24,28,28,26,30,28,30,30,30,30,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,17,28,22,16,22,28,26,26,24,28,24,28,22,24,24,30,28,28,26,28,30,24,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30]],t.NUM_ERROR_CORRECTION_BLOCKS=[[-1,1,1,1,1,1,2,2,2,2,4,4,4,4,4,6,6,6,6,7,8,8,9,9,10,12,12,12,13,14,15,16,17,18,19,19,20,21,22,24,25],[-1,1,1,1,2,2,4,4,4,5,5,5,8,9,9,10,10,11,13,14,16,17,17,18,20,21,23,25,26,28,29,31,33,35,37,38,40,43,45,47,49],[-1,1,1,2,2,4,4,6,6,8,8,8,10,12,16,12,17,16,18,21,20,23,23,25,27,29,34,34,35,38,40,43,45,48,51,53,56,59,62,65,68],[-1,1,1,2,4,4,4,5,6,8,8,11,11,16,16,18,16,19,21,25,25,25,34,30,32,35,37,40,42,45,48,51,54,57,60,63,66,70,74,77,81]],e.QrCode=t;const o=class e{constructor(e,t,r){if(this.mode=e,this.numChars=t,this.bitData=r,t<0)throw new RangeError("Invalid argument");this.bitData=r.slice()}static makeBytes(t){let n=[];for(const e of t)r(e,8,n);return new e(e.Mode.BYTE,t.length,n)}static makeNumeric(t){if(!e.isNumeric(t))throw new RangeError("String contains non-numeric characters");let n=[];for(let e=0;e<t.length;){const s=Math.min(t.length-e,3);r(parseInt(t.substring(e,e+s),10),3*s+1,n),e+=s}return new e(e.Mode.NUMERIC,t.length,n)}static makeAlphanumeric(t){if(!e.isAlphanumeric(t))throw new RangeError("String contains unencodable characters in alphanumeric mode");let n,s=[];for(n=0;n+2<=t.length;n+=2){let o=45*e.ALPHANUMERIC_CHARSET.indexOf(t.charAt(n));o+=e.ALPHANUMERIC_CHARSET.indexOf(t.charAt(n+1)),r(o,11,s)}return n<t.length&&r(e.ALPHANUMERIC_CHARSET.indexOf(t.charAt(n)),6,s),new e(e.Mode.ALPHANUMERIC,t.length,s)}static makeSegments(t){return""==t?[]:e.isNumeric(t)?[e.makeNumeric(t)]:e.isAlphanumeric(t)?[e.makeAlphanumeric(t)]:[e.makeBytes(e.toUtf8ByteArray(t))]}static makeEci(t){let n=[];if(t<0)throw new RangeError("ECI assignment value out of range");if(t<128)r(t,8,n);else if(t<16384)r(2,2,n),r(t,14,n);else{if(!(t<1e6))throw new RangeError("ECI assignment value out of range");r(6,3,n),r(t,21,n)}return new e(e.Mode.ECI,0,n)}static isNumeric(t){return e.NUMERIC_REGEX.test(t)}static isAlphanumeric(t){return e.ALPHANUMERIC_REGEX.test(t)}getData(){return this.bitData.slice()}static getTotalBits(e,t){let r=0;for(const n of e){const e=n.mode.numCharCountBits(t);if(n.numChars>=1<<e)return 1/0;r+=4+e+n.bitData.length}return r}static toUtf8ByteArray(e){e=encodeURI(e);let t=[];for(let r=0;r<e.length;r++)"%"!=e.charAt(r)?t.push(e.charCodeAt(r)):(t.push(parseInt(e.substring(r+1,r+3),16)),r+=2);return t}};o.NUMERIC_REGEX=/^[0-9]*$/,o.ALPHANUMERIC_REGEX=/^[A-Z0-9 $%*+.\/:-]*$/,o.ALPHANUMERIC_CHARSET="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:";let a=o;e.QrSegment=o})(K||(K={})),(e=>{const t=class{constructor(e,t){this.ordinal=e,this.formatBits=t}};t.LOW=new t(0,1),t.MEDIUM=new t(1,0),t.QUARTILE=new t(2,3),t.HIGH=new t(3,2),e.Ecc=t})((Q=K||(K={})).QrCode||(Q.QrCode={})),(e=>{(e=>{const t=class{constructor(e,t){this.modeBits=e,this.numBitsCharCount=t}numCharCountBits(e){return this.numBitsCharCount[Math.floor((e+7)/17)]}};t.NUMERIC=new t(1,[10,12,14]),t.ALPHANUMERIC=new t(2,[9,11,13]),t.BYTE=new t(4,[8,16,16]),t.KANJI=new t(8,[8,10,12]),t.ECI=new t(7,[0,0,0]),e.Mode=t})(e.QrSegment||(e.QrSegment={}))})(K||(K={}));var ee=K,te={L:ee.QrCode.Ecc.LOW,M:ee.QrCode.Ecc.MEDIUM,Q:ee.QrCode.Ecc.QUARTILE,H:ee.QrCode.Ecc.HIGH},re=128,ne="L",se="#FFFFFF",oe="#000000",ae=!1,le=1;
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).CoinleyCheckout={},e.React)}(this,(function(e,t){"use strict";var r=Object.defineProperty,n=Object.defineProperties,o=Object.getOwnPropertyDescriptors,s=Object.getOwnPropertySymbols,a=Object.prototype.hasOwnProperty,l=Object.prototype.propertyIsEnumerable,i=(e,t,n)=>t in e?r(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,c=(e,t)=>{for(var r in t||(t={}))a.call(t,r)&&i(e,r,t[r]);if(s)for(var r of s(t))l.call(t,r)&&i(e,r,t[r]);return e},d=(e,t,r)=>new Promise(((n,o)=>{var s=e=>{try{l(r.next(e))}catch(t){o(t)}},a=e=>{try{l(r.throw(e))}catch(t){o(t)}},l=e=>e.done?n(e.value):Promise.resolve(e.value).then(s,a);l((r=r.apply(e,t)).next())}));const u={ETHEREUM:"ethereum",BSC:"bsc",TRON:"tron",ALGORAND:"algorand"},h={METAMASK:"metamask",TRONLINK:"tronlink",TRUST_WALLET:"trust_wallet",LUTE:"lute"},m={[u.ETHEREUM]:{chainId:"0x1",chainName:"Ethereum Mainnet",nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18},rpcUrls:["https://mainnet.infura.io/v3/"],blockExplorerUrls:["https://etherscan.io/"],supportedWallets:[h.METAMASK,h.TRUST_WALLET]},[u.BSC]:{chainId:"0x38",chainName:"BNB Smart Chain",nativeCurrency:{name:"BNB",symbol:"BNB",decimals:18},rpcUrls:["https://bsc-dataseed.binance.org/"],blockExplorerUrls:["https://bscscan.com/"],supportedWallets:[h.METAMASK,h.TRUST_WALLET]},[u.TRON]:{fullHost:"https://api.trongrid.io",explorerUrl:"https://tronscan.org",supportedWallets:[h.TRONLINK]},[u.ALGORAND]:{network:"mainnet",explorerUrl:"https://algoexplorer.io",supportedWallets:[h.LUTE]}},g={USDT:{[u.ETHEREUM]:{address:"0xdAC17F958D2ee523a2206206994597C13D831ec7",decimals:6},[u.BSC]:{address:"0x55d398326f99059fF775485246999027B3197955",decimals:18},[u.TRON]:{address:"TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t",decimals:6},[u.ALGORAND]:{address:"312769",decimals:6}},USDC:{[u.ETHEREUM]:{address:"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",decimals:6},[u.BSC]:{address:"0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d",decimals:18},[u.TRON]:{address:"TEkxiTehnzSmSe2XqrBj4w32RUN966rdz8",decimals:6},[u.ALGORAND]:{address:"31566704",decimals:6}},PYUSD:{[u.ETHEREUM]:{address:"0x6c3ea9036406852006290770BEdFcAbA0e23A0e8",decimals:6}},FRAX:{[u.ETHEREUM]:{address:"0x853d955aCEf822Db058eb8505911ED77F175b99e",decimals:18},[u.BSC]:{address:"0x90C97F71E18723b0Cf0dfa30ee176Ab653E89F40",decimals:18}},USDP:{[u.ETHEREUM]:{address:"0x8E870D67F660D95d5be530380D0eC0bd388289E1",decimals:18}},DAI:{[u.ETHEREUM]:{address:"0x6B175474E89094C44Da98b954EedeAC495271d0F",decimals:18}},BUSD:{[u.BSC]:{address:"0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56",decimals:18}},USDJ:{[u.TRON]:{address:"TMwFHYXLJaRUPeW6421aqXL4ZEzPRFGkGT",decimals:18}},ALGO:{[u.ALGORAND]:{address:"native",decimals:6}}},w=()=>{var e;const t={[h.METAMASK]:!1,[h.TRUST_WALLET]:!1,[h.TRONLINK]:!1,[h.LUTE]:!1};if("undefined"==typeof window)return t;try{console.log("=== ENHANCED WALLET DETECTION DEBUG ===");const r=[];window.ethereum&&(r.push(window.ethereum),console.log("Found window.ethereum provider")),(null==(e=window.ethereum)?void 0:e.providers)&&Array.isArray(window.ethereum.providers)&&window.ethereum.providers.forEach((e=>{r.push(e),console.log("Found provider in ethereum.providers array")}));for(const e of r)if(e.isMetaMask){t[h.METAMASK]=!0,console.log("✅ MetaMask detected via provider",e);break}for(const e of r)if(e.isTrust||e.isTrustWallet){t[h.TRUST_WALLET]=!0,console.log("✅ Trust Wallet detected via provider",e);break}t[h.TRUST_WALLET]||((window.trustwallet||window.trustWallet)&&(t[h.TRUST_WALLET]=!0,console.log("✅ Trust Wallet detected via trustwallet object")),navigator.userAgent&&navigator.userAgent.toLowerCase().includes("trust")&&(t[h.TRUST_WALLET]=!0,console.log("✅ Trust Wallet detected via user agent"))),window.tronWeb&&window.tronWeb.defaultAddress?(t[h.TRONLINK]=!0,console.log("✅ TronLink detected via tronWeb")):window.tronLink?(t[h.TRONLINK]=!0,console.log("✅ TronLink detected via tronLink object")):window.tron&&(t[h.TRONLINK]=!0,console.log("✅ TronLink detected via tron object")),window.algorand&&(t[h.LUTE]=!0,console.log("✅ Algorand wallet detected")),console.log("Final wallet detection results:",t),console.log("=== END ENHANCED WALLET DETECTION DEBUG ===")}catch(r){console.warn("Error detecting wallets:",r)}return t},p=(e=3,t=1e3)=>d(this,null,(function*(){let r=w(),n=0;for(;n<e&&!(r[h.METAMASK]&&r[h.TRUST_WALLET]&&r[h.TRONLINK]);)n>0&&(console.log(`Retrying wallet detection (attempt ${n+1}/${e})...`),yield new Promise((e=>setTimeout(e,t)))),r=w(),n++;return r})),f=e=>{const t=m[e];if(!t)return[];const r=w();return t.supportedWallets.filter((e=>r[e]))},y=(e,t=18)=>{console.log("calculateTokenAmount input:",{amount:e,decimals:t});const r=parseFloat(e),n=parseInt(t);if(isNaN(r)||r<=0)throw new Error(`Invalid amount: ${e}`);if(isNaN(n)||n<0)throw new Error(`Invalid decimals: ${t}`);try{const e=Math.pow(10,n),t=Math.floor(r*e);return console.log("Token amount calculation:",{tokenAmount:r,tokenDecimals:n,multiplier:e,amountInSmallestUnit:t}),t}catch(o){throw console.error("Error calculating token amount:",o),new Error(`Failed to calculate token amount: ${o.message}`)}},x=(e,t,r=2)=>d(this,null,(function*(){console.log("connectWallet called with:",{walletType:e,network:t,retryCount:r});const n=r=>d(this,null,(function*(){try{switch(e){case h.METAMASK:return yield E(t);case h.TRUST_WALLET:return yield b(t);case h.TRONLINK:return yield N();case h.LUTE:return yield v();default:throw new Error(`Unsupported wallet type: ${e}`)}}catch(o){if(4001===o.code||o.message&&o.message.includes("rejected"))throw o;if(r>0)return console.log(`Connection attempt failed, retrying... (${r} attempts left)`),yield new Promise((e=>setTimeout(e,delay=1e3))),n(r-1);throw o}}));return n(r)})),E=e=>d(this,null,(function*(){if(console.log("Attempting to connect MetaMask for network:",e),"undefined"==typeof window)throw new Error("Browser environment required");const t=(()=>{var e,t;let r=null;return(null==(e=window.ethereum)?void 0:e.providers)&&Array.isArray(window.ethereum.providers)&&(r=window.ethereum.providers.find((e=>e.isMetaMask)),r)?(console.log("Found MetaMask in providers array"),r):(null==(t=window.ethereum)?void 0:t.isMetaMask)?(console.log("Using main ethereum object for MetaMask"),window.ethereum):window.ethereum?(console.warn("No MetaMask-specific provider found, using generic ethereum provider"),window.ethereum):null})();if(!t)throw new Error("MetaMask is not installed. Please install MetaMask extension.");try{console.log("Requesting accounts from MetaMask...");const r=yield t.request({method:"eth_requestAccounts"});if(console.log("Accounts received:",r),!r||0===r.length)throw new Error("No accounts found. Please unlock MetaMask.");const n=m[e];n&&n.chainId&&(console.log("Switching to network:",n.chainName),yield k(n,t));const o={address:r[0],network:e,walletType:h.METAMASK,provider:t};return console.log("MetaMask connected successfully:",o),o}catch(r){if(console.error("MetaMask connection error:",r),4001===r.code)throw new Error("Connection rejected by user.");if(-32002===r.code)throw new Error("Connection request pending. Please check MetaMask.");throw new Error(`Failed to connect MetaMask: ${r.message}`)}})),b=e=>d(this,null,(function*(){if(console.log("Attempting to connect Trust Wallet for network:",e),"undefined"==typeof window)throw new Error("Browser environment required");const t=(()=>{var e,t,r;let n=null;return(null==(e=window.ethereum)?void 0:e.providers)&&Array.isArray(window.ethereum.providers)&&(n=window.ethereum.providers.find((e=>e.isTrust||e.isTrustWallet)),n)?(console.log("Found Trust Wallet in providers array"),n):(null==(t=window.ethereum)?void 0:t.isTrust)||(null==(r=window.ethereum)?void 0:r.isTrustWallet)?(console.log("Using main ethereum object for Trust Wallet"),window.ethereum):window.trustwallet?(console.log("Using trustwallet object"),window.trustwallet):window.trustWallet?(console.log("Using trustWallet object"),window.trustWallet):navigator.userAgent&&navigator.userAgent.toLowerCase().includes("trust")&&window.ethereum?(console.log("Using generic ethereum provider for Trust mobile"),window.ethereum):null})();if(!t)throw new Error("Trust Wallet is not installed or not detected.");try{console.log("Requesting accounts from Trust Wallet provider");const n=yield t.request({method:"eth_requestAccounts"});if(console.log("Trust Wallet accounts received:",n),!n||0===n.length)throw new Error("No accounts found. Please unlock Trust Wallet.");try{const r=m[e];r&&r.chainId&&(console.log("Switching network in Trust Wallet to:",r.chainName),yield k(r,t))}catch(r){console.warn("Network switching failed in Trust Wallet (may not be supported):",r)}return{address:n[0],network:e,walletType:h.TRUST_WALLET,provider:t}}catch(n){if(console.error("Trust Wallet connection error:",n),4001===n.code)throw new Error("User rejected the connection request");throw new Error(`Failed to connect Trust Wallet: ${n.message}`)}})),N=()=>d(this,null,(function*(){var e;if("undefined"==typeof window||!window.tronWeb)throw new Error("TronLink is not installed.");let t=0;for(;!window.tronWeb.ready&&t<10;)yield new Promise((e=>setTimeout(e,1e3))),t++,console.log(`Waiting for TronLink to be ready... Attempt ${t}`);if(!window.tronWeb.ready)throw new Error("TronLink is not ready. Please unlock your wallet.");const r=null==(e=window.tronWeb.defaultAddress)?void 0:e.base58;if(!r)throw new Error("No account found in TronLink.");return{address:r,network:u.TRON,walletType:h.TRONLINK,provider:window.tronWeb}})),v=()=>d(this,null,(function*(){if("undefined"==typeof window||!window.algorand)throw new Error("Lute wallet is not installed.");try{const e=yield window.algorand.connect();if(!e||0===e.length)throw new Error("No accounts found. Please unlock Lute wallet.");return{address:e[0],network:u.ALGORAND,walletType:h.LUTE,provider:window.algorand}}catch(e){throw new Error(`Failed to connect Lute wallet: ${e.message}`)}})),k=(e,t)=>d(this,null,(function*(){if(!t)throw new Error("No provider specified for network switching");try{console.log("Attempting to switch to:",e.chainName),yield t.request({method:"wallet_switchEthereumChain",params:[{chainId:e.chainId}]}),console.log("Network switched successfully")}catch(r){if(console.error("Network switch error:",r),4902!==r.code)throw 4001===r.code?new Error("User rejected network switch request."):new Error(`Failed to switch to ${e.chainName}.`);try{yield t.request({method:"wallet_addEthereumChain",params:[e]}),console.log("Network added successfully")}catch(n){throw new Error(`Failed to add ${e.chainName} to wallet.`)}}})),T=(e,t)=>d(this,null,(function*(){const{walletType:r,network:n,address:o,provider:s}=e,{to:a,amount:l,tokenAddress:i,tokenDecimals:c,currency:d}=t;switch(console.log("sendTransaction called with:",{walletConnection:{walletType:r,network:n,address:o,hasProvider:!!s},transactionData:t}),r){case h.METAMASK:case h.TRUST_WALLET:return yield A(o,a,l,i,c,d,n,s);case h.TRONLINK:return yield S(a,l,i,c);case h.LUTE:return yield C(o,a,l);default:throw new Error(`Unsupported wallet type: ${r}`)}})),A=(e,t,r,n,o,s,a,l)=>d(this,null,(function*(){console.log("sendEVMTransaction called with:",{from:e,to:t,amount:r,tokenAddress:n,tokenDecimals:o,currency:s,network:a});const i=l||window.ethereum;if(!i)throw new Error("Ethereum provider not found");try{let l=n,d=o;if(s&&a)try{const e=((e,t)=>{console.log("getTokenConfig called with:",{currency:e,network:t});const r=g[e];if(!r)throw new Error(`Unsupported currency: ${e}`);const n=r[t];if(!n)throw new Error(`Currency ${e} not supported on network ${t}`);return console.log("Token config found:",n),n})(s,a);l=e.address,d=e.decimals,console.log("Using token config:",{currency:s,network:a,address:l,decimals:d})}catch(c){console.warn("Could not get token config, using provided values:",c.message)}if(l&&"native"!==l){console.log("Preparing ERC20 token transfer for:",s);const n=((e,t,r)=>{try{const n="0xa9059cbb",o=e.toLowerCase().replace("0x",""),s=o.padStart(64,"0"),a=y(t,r),l=a.toString(16).padStart(64,"0"),i=`0x${n}${s}${l}`;return console.log("Encoded ERC20 transfer data:",{methodId:n,toAddress:o,amount:t,tokenAmount:a,hexAmount:l,data:i}),i}catch(n){throw console.error("Error encoding ERC20 transfer data:",n),new Error(`Failed to encode transfer data: ${n.message}`)}})(t,r,d);console.log("ERC20 transaction details:",{from:e,to:l,data:n,gas:"0x30D40"});const o=yield i.request({method:"eth_sendTransaction",params:[{from:e,to:l,data:n,gas:"0x30D40"}]});return console.log("ERC20 transaction successful:",o),o}{console.log("Preparing native token transfer");const n=y(r,18),o="0x"+n.toString(16);console.log("Native transaction amount:",{amount:r,amountInWei:n,amountHex:o});const s=yield i.request({method:"eth_sendTransaction",params:[{from:e,to:t,value:o,gas:"0x5208"}]});return console.log("Native transaction successful:",s),s}}catch(d){if(console.error("EVM transaction error:",d),4001===d.code)throw new Error("Transaction was rejected by user");if(d.message&&d.message.includes("insufficient funds"))throw new Error("Insufficient balance to complete the transaction");throw new Error(`Transaction failed: ${d.message||"Unknown error"}`)}})),S=(e,t,r,n)=>d(this,null,(function*(){if("undefined"==typeof window||!window.tronWeb||!window.tronWeb.ready)throw new Error("TronLink is not ready");try{const o=y(t,n||6);if(r&&"native"!==r){console.log("Sending TRC20 token:",{to:e,amount:t,tokenAddress:r,amountInSun:o});const n=yield window.tronWeb.contract().at(r),s=yield n.transfer(e,o).send({feeLimit:1e8,callValue:0});return console.log("TRC20 transfer result:",s),s}{console.log("Sending native TRX:",{to:e,amount:t,amountInSun:o});const r=yield window.tronWeb.trx.sendTransaction(e,o);return console.log("TRX transfer result:",r),r.txid}}catch(o){throw console.error("Tron transaction error:",o),new Error(`TRON transaction failed: ${o.message}`)}})),C=(e,t,r)=>d(this,null,(function*(){if("undefined"==typeof window||!window.algorand)throw new Error("Algorand wallet is not available");try{const n=y(r,6),o={from:e,to:t,amount:n,type:"pay"};console.log("Sending Algorand transaction:",o);const s=yield window.algorand.signTransaction(o),a=yield window.algorand.sendTransaction(s);return console.log("Algorand transaction result:",a),a.txId}catch(n){throw console.error("Algorand transaction error:",n),new Error(`Algorand transaction failed: ${n.message}`)}})),M=e=>({[h.METAMASK]:"https://metamask.io/",[h.TRONLINK]:"https://www.tronlink.org/",[h.TRUST_WALLET]:"https://trustwallet.com/",[h.LUTE]:"https://lute.app/"}[e]||""),j=()=>{var e;return console.group("Wallet Environment Debug"),console.log("User Agent:",navigator.userAgent),console.log("Main ethereum object:",window.ethereum),(null==(e=window.ethereum)?void 0:e.providers)&&(console.log("Providers array:"),window.ethereum.providers.forEach(((e,t)=>{var r;console.log(`Provider ${t}:`,{isMetaMask:e.isMetaMask,isTrust:e.isTrust,isTrustWallet:e.isTrustWallet,constructor:null==(r=e.constructor)?void 0:r.name})}))),console.log("TronWeb object:",window.tronWeb),console.log("TronLink object:",window.tronLink),console.log("Tron object:",window.tron),console.log("Algorand object:",window.algorand),console.log("Trust wallet objects:",{trustwallet:window.trustwallet,trustWallet:window.trustWallet}),console.groupEnd(),w()};let R={apiKey:null,apiSecret:null,apiUrl:"http://localhost:9000",merchantWalletAddresses:{}};const L=()=>({"Content-Type":"application/json","x-api-key":R.apiKey,"x-api-secret":R.apiSecret}),D=e=>d(this,null,(function*(){try{if(console.log("Creating payment with data:",e),console.log("API URL:",`${R.apiUrl}/api/payments/create`),!e.amount)throw new Error("Payment amount is required");const a=(t=c({},e),r={merchantWalletAddresses:c(c({},R.merchantWalletAddresses),e.merchantWalletAddresses)},n(t,o(r))),l=yield fetch(`${R.apiUrl}/api/payments/create`,{method:"POST",headers:L(),body:JSON.stringify(a)});if(console.log("Create payment response status:",l.status),!l.ok){let e;try{e=yield l.json()}catch(s){throw new Error(`Failed to create payment: ${l.status} ${l.statusText}`)}throw console.error("Error creating payment:",e),new Error(e.error||`Failed to create payment: ${l.status}`)}const i=yield l.json();return console.log("Create payment response data:",i),i}catch(a){throw console.error("Create payment error:",a),a}var t,r})),U=e=>d(this,null,(function*(){try{if(console.log("Processing payment with data:",e),!e.paymentId)throw new Error("Payment ID is required");if(!e.transactionHash)throw new Error("Transaction hash is required");console.log("API URL:",`${R.apiUrl}/api/payments/process`);const r=yield fetch(`${R.apiUrl}/api/payments/process`,{method:"POST",headers:L(),body:JSON.stringify(e)});if(console.log("Process payment response status:",r.status),!r.ok){let e;try{e=yield r.json()}catch(t){throw new Error(`Failed to process payment: ${r.status} ${r.statusText}`)}throw console.error("Error processing payment:",e),new Error(e.error||`Failed to process payment: ${r.status}`)}const n=yield r.json();return console.log("Process payment response data:",n),n}catch(r){throw console.error("Process payment error:",r),r}}));var P={exports:{}},O={},W=t,I=Symbol.for("react.element"),F=Symbol.for("react.fragment"),B=Object.prototype.hasOwnProperty,z=W.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,H={key:!0,ref:!0,__self:!0,__source:!0};function q(e,t,r){var n,o={},s=null,a=null;for(n in void 0!==r&&(s=""+r),void 0!==t.key&&(s=""+t.key),void 0!==t.ref&&(a=t.ref),t)B.call(t,n)&&!H.hasOwnProperty(n)&&(o[n]=t[n]);if(e&&e.defaultProps)for(n in t=e.defaultProps)void 0===o[n]&&(o[n]=t[n]);return{$$typeof:I,type:e,key:s,ref:a,props:o,_owner:z.current}}O.Fragment=F,O.jsx=q,O.jsxs=q,P.exports=O;var G=P.exports;const Q=t.createContext(),K=t.createContext(),$=()=>t.useContext(K);var _,V,J=Object.defineProperty,Y=Object.getOwnPropertySymbols,X=Object.prototype.hasOwnProperty,Z=Object.prototype.propertyIsEnumerable,ee=(e,t,r)=>t in e?J(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,te=(e,t)=>{for(var r in t||(t={}))X.call(t,r)&&ee(e,r,t[r]);if(Y)for(var r of Y(t))Z.call(t,r)&&ee(e,r,t[r]);return e},re=(e,t)=>{var r={};for(var n in e)X.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(null!=e&&Y)for(var n of Y(e))t.indexOf(n)<0&&Z.call(e,n)&&(r[n]=e[n]);return r};(e=>{const t=class t{constructor(e,r,n,s){if(this.version=e,this.errorCorrectionLevel=r,this.modules=[],this.isFunction=[],e<t.MIN_VERSION||e>t.MAX_VERSION)throw new RangeError("Version value out of range");if(s<-1||s>7)throw new RangeError("Mask value out of range");this.size=4*e+17;let a=[];for(let t=0;t<this.size;t++)a.push(!1);for(let t=0;t<this.size;t++)this.modules.push(a.slice()),this.isFunction.push(a.slice());this.drawFunctionPatterns();const l=this.addEccAndInterleave(n);if(this.drawCodewords(l),-1==s){let e=1e9;for(let t=0;t<8;t++){this.applyMask(t),this.drawFormatBits(t);const r=this.getPenaltyScore();r<e&&(s=t,e=r),this.applyMask(t)}}o(0<=s&&s<=7),this.mask=s,this.applyMask(s),this.drawFormatBits(s),this.isFunction=[]}static encodeText(r,n){const o=e.QrSegment.makeSegments(r);return t.encodeSegments(o,n)}static encodeBinary(r,n){const o=e.QrSegment.makeBytes(r);return t.encodeSegments([o],n)}static encodeSegments(e,n,s=1,l=40,i=-1,c=!0){if(!(t.MIN_VERSION<=s&&s<=l&&l<=t.MAX_VERSION)||i<-1||i>7)throw new RangeError("Invalid value");let d,u;for(d=s;;d++){const r=8*t.getNumDataCodewords(d,n),o=a.getTotalBits(e,d);if(o<=r){u=o;break}if(d>=l)throw new RangeError("Data too long")}for(const r of[t.Ecc.MEDIUM,t.Ecc.QUARTILE,t.Ecc.HIGH])c&&u<=8*t.getNumDataCodewords(d,r)&&(n=r);let h=[];for(const t of e){r(t.mode.modeBits,4,h),r(t.numChars,t.mode.numCharCountBits(d),h);for(const e of t.getData())h.push(e)}o(h.length==u);const m=8*t.getNumDataCodewords(d,n);o(h.length<=m),r(0,Math.min(4,m-h.length),h),r(0,(8-h.length%8)%8,h),o(h.length%8==0);for(let t=236;h.length<m;t^=253)r(t,8,h);let g=[];for(;8*g.length<h.length;)g.push(0);return h.forEach(((e,t)=>g[t>>>3]|=e<<7-(7&t))),new t(d,n,g,i)}getModule(e,t){return 0<=e&&e<this.size&&0<=t&&t<this.size&&this.modules[t][e]}getModules(){return this.modules}drawFunctionPatterns(){for(let r=0;r<this.size;r++)this.setFunctionModule(6,r,r%2==0),this.setFunctionModule(r,6,r%2==0);this.drawFinderPattern(3,3),this.drawFinderPattern(this.size-4,3),this.drawFinderPattern(3,this.size-4);const e=this.getAlignmentPatternPositions(),t=e.length;for(let r=0;r<t;r++)for(let n=0;n<t;n++)0==r&&0==n||0==r&&n==t-1||r==t-1&&0==n||this.drawAlignmentPattern(e[r],e[n]);this.drawFormatBits(0),this.drawVersion()}drawFormatBits(e){const t=this.errorCorrectionLevel.formatBits<<3|e;let r=t;for(let n=0;n<10;n++)r=r<<1^1335*(r>>>9);const s=21522^(t<<10|r);o(s>>>15==0);for(let o=0;o<=5;o++)this.setFunctionModule(8,o,n(s,o));this.setFunctionModule(8,7,n(s,6)),this.setFunctionModule(8,8,n(s,7)),this.setFunctionModule(7,8,n(s,8));for(let o=9;o<15;o++)this.setFunctionModule(14-o,8,n(s,o));for(let o=0;o<8;o++)this.setFunctionModule(this.size-1-o,8,n(s,o));for(let o=8;o<15;o++)this.setFunctionModule(8,this.size-15+o,n(s,o));this.setFunctionModule(8,this.size-8,!0)}drawVersion(){if(this.version<7)return;let e=this.version;for(let r=0;r<12;r++)e=e<<1^7973*(e>>>11);const t=this.version<<12|e;o(t>>>18==0);for(let r=0;r<18;r++){const e=n(t,r),o=this.size-11+r%3,s=Math.floor(r/3);this.setFunctionModule(o,s,e),this.setFunctionModule(s,o,e)}}drawFinderPattern(e,t){for(let r=-4;r<=4;r++)for(let n=-4;n<=4;n++){const o=Math.max(Math.abs(n),Math.abs(r)),s=e+n,a=t+r;0<=s&&s<this.size&&0<=a&&a<this.size&&this.setFunctionModule(s,a,2!=o&&4!=o)}}drawAlignmentPattern(e,t){for(let r=-2;r<=2;r++)for(let n=-2;n<=2;n++)this.setFunctionModule(e+n,t+r,1!=Math.max(Math.abs(n),Math.abs(r)))}setFunctionModule(e,t,r){this.modules[t][e]=r,this.isFunction[t][e]=!0}addEccAndInterleave(e){const r=this.version,n=this.errorCorrectionLevel;if(e.length!=t.getNumDataCodewords(r,n))throw new RangeError("Invalid argument");const s=t.NUM_ERROR_CORRECTION_BLOCKS[n.ordinal][r],a=t.ECC_CODEWORDS_PER_BLOCK[n.ordinal][r],l=Math.floor(t.getNumRawDataModules(r)/8),i=s-l%s,c=Math.floor(l/s);let d=[];const u=t.reedSolomonComputeDivisor(a);for(let o=0,m=0;o<s;o++){let r=e.slice(m,m+c-a+(o<i?0:1));m+=r.length;const n=t.reedSolomonComputeRemainder(r,u);o<i&&r.push(0),d.push(r.concat(n))}let h=[];for(let t=0;t<d[0].length;t++)d.forEach(((e,r)=>{(t!=c-a||r>=i)&&h.push(e[t])}));return o(h.length==l),h}drawCodewords(e){if(e.length!=Math.floor(t.getNumRawDataModules(this.version)/8))throw new RangeError("Invalid argument");let r=0;for(let t=this.size-1;t>=1;t-=2){6==t&&(t=5);for(let o=0;o<this.size;o++)for(let s=0;s<2;s++){const a=t-s,l=!(t+1&2)?this.size-1-o:o;!this.isFunction[l][a]&&r<8*e.length&&(this.modules[l][a]=n(e[r>>>3],7-(7&r)),r++)}}o(r==8*e.length)}applyMask(e){if(e<0||e>7)throw new RangeError("Mask value out of range");for(let t=0;t<this.size;t++)for(let r=0;r<this.size;r++){let n;switch(e){case 0:n=(r+t)%2==0;break;case 1:n=t%2==0;break;case 2:n=r%3==0;break;case 3:n=(r+t)%3==0;break;case 4:n=(Math.floor(r/3)+Math.floor(t/2))%2==0;break;case 5:n=r*t%2+r*t%3==0;break;case 6:n=(r*t%2+r*t%3)%2==0;break;case 7:n=((r+t)%2+r*t%3)%2==0;break;default:throw new Error("Unreachable")}!this.isFunction[t][r]&&n&&(this.modules[t][r]=!this.modules[t][r])}}getPenaltyScore(){let e=0;for(let o=0;o<this.size;o++){let r=!1,n=0,s=[0,0,0,0,0,0,0];for(let a=0;a<this.size;a++)this.modules[o][a]==r?(n++,5==n?e+=t.PENALTY_N1:n>5&&e++):(this.finderPenaltyAddHistory(n,s),r||(e+=this.finderPenaltyCountPatterns(s)*t.PENALTY_N3),r=this.modules[o][a],n=1);e+=this.finderPenaltyTerminateAndCount(r,n,s)*t.PENALTY_N3}for(let o=0;o<this.size;o++){let r=!1,n=0,s=[0,0,0,0,0,0,0];for(let a=0;a<this.size;a++)this.modules[a][o]==r?(n++,5==n?e+=t.PENALTY_N1:n>5&&e++):(this.finderPenaltyAddHistory(n,s),r||(e+=this.finderPenaltyCountPatterns(s)*t.PENALTY_N3),r=this.modules[a][o],n=1);e+=this.finderPenaltyTerminateAndCount(r,n,s)*t.PENALTY_N3}for(let o=0;o<this.size-1;o++)for(let r=0;r<this.size-1;r++){const n=this.modules[o][r];n==this.modules[o][r+1]&&n==this.modules[o+1][r]&&n==this.modules[o+1][r+1]&&(e+=t.PENALTY_N2)}let r=0;for(const t of this.modules)r=t.reduce(((e,t)=>e+(t?1:0)),r);const n=this.size*this.size,s=Math.ceil(Math.abs(20*r-10*n)/n)-1;return o(0<=s&&s<=9),e+=s*t.PENALTY_N4,o(0<=e&&e<=2568888),e}getAlignmentPatternPositions(){if(1==this.version)return[];{const e=Math.floor(this.version/7)+2,t=32==this.version?26:2*Math.ceil((4*this.version+4)/(2*e-2));let r=[6];for(let n=this.size-7;r.length<e;n-=t)r.splice(1,0,n);return r}}static getNumRawDataModules(e){if(e<t.MIN_VERSION||e>t.MAX_VERSION)throw new RangeError("Version number out of range");let r=(16*e+128)*e+64;if(e>=2){const t=Math.floor(e/7)+2;r-=(25*t-10)*t-55,e>=7&&(r-=36)}return o(208<=r&&r<=29648),r}static getNumDataCodewords(e,r){return Math.floor(t.getNumRawDataModules(e)/8)-t.ECC_CODEWORDS_PER_BLOCK[r.ordinal][e]*t.NUM_ERROR_CORRECTION_BLOCKS[r.ordinal][e]}static reedSolomonComputeDivisor(e){if(e<1||e>255)throw new RangeError("Degree out of range");let r=[];for(let t=0;t<e-1;t++)r.push(0);r.push(1);let n=1;for(let o=0;o<e;o++){for(let e=0;e<r.length;e++)r[e]=t.reedSolomonMultiply(r[e],n),e+1<r.length&&(r[e]^=r[e+1]);n=t.reedSolomonMultiply(n,2)}return r}static reedSolomonComputeRemainder(e,r){let n=r.map((e=>0));for(const o of e){const e=o^n.shift();n.push(0),r.forEach(((r,o)=>n[o]^=t.reedSolomonMultiply(r,e)))}return n}static reedSolomonMultiply(e,t){if(e>>>8!=0||t>>>8!=0)throw new RangeError("Byte out of range");let r=0;for(let n=7;n>=0;n--)r=r<<1^285*(r>>>7),r^=(t>>>n&1)*e;return o(r>>>8==0),r}finderPenaltyCountPatterns(e){const t=e[1];o(t<=3*this.size);const r=t>0&&e[2]==t&&e[3]==3*t&&e[4]==t&&e[5]==t;return(r&&e[0]>=4*t&&e[6]>=t?1:0)+(r&&e[6]>=4*t&&e[0]>=t?1:0)}finderPenaltyTerminateAndCount(e,t,r){return e&&(this.finderPenaltyAddHistory(t,r),t=0),t+=this.size,this.finderPenaltyAddHistory(t,r),this.finderPenaltyCountPatterns(r)}finderPenaltyAddHistory(e,t){0==t[0]&&(e+=this.size),t.pop(),t.unshift(e)}};function r(e,t,r){if(t<0||t>31||e>>>t!=0)throw new RangeError("Value out of range");for(let n=t-1;n>=0;n--)r.push(e>>>n&1)}function n(e,t){return!!(e>>>t&1)}function o(e){if(!e)throw new Error("Assertion error")}t.MIN_VERSION=1,t.MAX_VERSION=40,t.PENALTY_N1=3,t.PENALTY_N2=3,t.PENALTY_N3=40,t.PENALTY_N4=10,t.ECC_CODEWORDS_PER_BLOCK=[[-1,7,10,15,20,26,18,20,24,30,18,20,24,26,30,22,24,28,30,28,28,28,28,30,30,26,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,10,16,26,18,24,16,18,22,22,26,30,22,22,24,24,28,28,26,26,26,26,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28],[-1,13,22,18,26,18,24,18,22,20,24,28,26,24,20,30,24,28,28,26,30,28,30,30,30,30,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,17,28,22,16,22,28,26,26,24,28,24,28,22,24,24,30,28,28,26,28,30,24,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30]],t.NUM_ERROR_CORRECTION_BLOCKS=[[-1,1,1,1,1,1,2,2,2,2,4,4,4,4,4,6,6,6,6,7,8,8,9,9,10,12,12,12,13,14,15,16,17,18,19,19,20,21,22,24,25],[-1,1,1,1,2,2,4,4,4,5,5,5,8,9,9,10,10,11,13,14,16,17,17,18,20,21,23,25,26,28,29,31,33,35,37,38,40,43,45,47,49],[-1,1,1,2,2,4,4,6,6,8,8,8,10,12,16,12,17,16,18,21,20,23,23,25,27,29,34,34,35,38,40,43,45,48,51,53,56,59,62,65,68],[-1,1,1,2,4,4,4,5,6,8,8,11,11,16,16,18,16,19,21,25,25,25,34,30,32,35,37,40,42,45,48,51,54,57,60,63,66,70,74,77,81]],e.QrCode=t;const s=class e{constructor(e,t,r){if(this.mode=e,this.numChars=t,this.bitData=r,t<0)throw new RangeError("Invalid argument");this.bitData=r.slice()}static makeBytes(t){let n=[];for(const e of t)r(e,8,n);return new e(e.Mode.BYTE,t.length,n)}static makeNumeric(t){if(!e.isNumeric(t))throw new RangeError("String contains non-numeric characters");let n=[];for(let e=0;e<t.length;){const o=Math.min(t.length-e,3);r(parseInt(t.substring(e,e+o),10),3*o+1,n),e+=o}return new e(e.Mode.NUMERIC,t.length,n)}static makeAlphanumeric(t){if(!e.isAlphanumeric(t))throw new RangeError("String contains unencodable characters in alphanumeric mode");let n,o=[];for(n=0;n+2<=t.length;n+=2){let s=45*e.ALPHANUMERIC_CHARSET.indexOf(t.charAt(n));s+=e.ALPHANUMERIC_CHARSET.indexOf(t.charAt(n+1)),r(s,11,o)}return n<t.length&&r(e.ALPHANUMERIC_CHARSET.indexOf(t.charAt(n)),6,o),new e(e.Mode.ALPHANUMERIC,t.length,o)}static makeSegments(t){return""==t?[]:e.isNumeric(t)?[e.makeNumeric(t)]:e.isAlphanumeric(t)?[e.makeAlphanumeric(t)]:[e.makeBytes(e.toUtf8ByteArray(t))]}static makeEci(t){let n=[];if(t<0)throw new RangeError("ECI assignment value out of range");if(t<128)r(t,8,n);else if(t<16384)r(2,2,n),r(t,14,n);else{if(!(t<1e6))throw new RangeError("ECI assignment value out of range");r(6,3,n),r(t,21,n)}return new e(e.Mode.ECI,0,n)}static isNumeric(t){return e.NUMERIC_REGEX.test(t)}static isAlphanumeric(t){return e.ALPHANUMERIC_REGEX.test(t)}getData(){return this.bitData.slice()}static getTotalBits(e,t){let r=0;for(const n of e){const e=n.mode.numCharCountBits(t);if(n.numChars>=1<<e)return 1/0;r+=4+e+n.bitData.length}return r}static toUtf8ByteArray(e){e=encodeURI(e);let t=[];for(let r=0;r<e.length;r++)"%"!=e.charAt(r)?t.push(e.charCodeAt(r)):(t.push(parseInt(e.substring(r+1,r+3),16)),r+=2);return t}};s.NUMERIC_REGEX=/^[0-9]*$/,s.ALPHANUMERIC_REGEX=/^[A-Z0-9 $%*+.\/:-]*$/,s.ALPHANUMERIC_CHARSET="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:";let a=s;e.QrSegment=s})(_||(_={})),(e=>{const t=class{constructor(e,t){this.ordinal=e,this.formatBits=t}};t.LOW=new t(0,1),t.MEDIUM=new t(1,0),t.QUARTILE=new t(2,3),t.HIGH=new t(3,2),e.Ecc=t})((V=_||(_={})).QrCode||(V.QrCode={})),(e=>{(e=>{const t=class{constructor(e,t){this.modeBits=e,this.numBitsCharCount=t}numCharCountBits(e){return this.numBitsCharCount[Math.floor((e+7)/17)]}};t.NUMERIC=new t(1,[10,12,14]),t.ALPHANUMERIC=new t(2,[9,11,13]),t.BYTE=new t(4,[8,16,16]),t.KANJI=new t(8,[8,10,12]),t.ECI=new t(7,[0,0,0]),e.Mode=t})(e.QrSegment||(e.QrSegment={}))})(_||(_={}));var ne=_,oe={L:ne.QrCode.Ecc.LOW,M:ne.QrCode.Ecc.MEDIUM,Q:ne.QrCode.Ecc.QUARTILE,H:ne.QrCode.Ecc.HIGH},se=128,ae="L",le="#FFFFFF",ie="#000000",ce=!1,de=1;
|
2
2
|
/**
|
3
3
|
* @license qrcode.react
|
4
4
|
* Copyright (c) Paul O'Shannessy
|
5
5
|
* SPDX-License-Identifier: ISC
|
6
|
-
*/function ie(e,t=0){const r=[];return e.forEach((function(e,n){let s=null;e.forEach((function(o,a){if(!o&&null!==s)return r.push(`M${s+t} ${n+t}h${a-s}v1H${s+t}z`),void(s=null);if(a!==e.length-1)o&&null===s&&(s=a);else{if(!o)return;null===s?r.push(`M${a+t},${n+t} h1v1H${a+t}z`):r.push(`M${s+t},${n+t} h${a+1-s}v1H${s+t}z`)}}))})),r.join("")}function ce(e,t){return e.slice().map(((e,r)=>r<t.y||r>=t.y+t.h?e:e.map(((e,r)=>(r<t.x||r>=t.x+t.w)&&e))))}function de({value:e,level:r,minVersion:n,includeMargin:s,marginSize:o,imageSettings:a,size:l,boostLevel:i}){let c=t.useMemo((()=>{const t=(Array.isArray(e)?e:[e]).reduce(((e,t)=>(e.push(...ee.QrSegment.makeSegments(t)),e)),[]);return ee.QrCode.encodeSegments(t,te[r],n,void 0,void 0,i)}),[e,r,n,i]);const{cells:d,margin:u,numCells:h,calculatedImageSettings:m}=t.useMemo((()=>{let e=c.getModules();const t=function(e,t){return null!=t?Math.max(Math.floor(t),0):e?4:0}(s,o),r=e.length+2*t,n=function(e,t,r,n){if(null==n)return null;const s=e.length+2*r,o=Math.floor(.1*t),a=s/t,l=(n.width||o)*a,i=(n.height||o)*a,c=null==n.x?e.length/2-l/2:n.x*a,d=null==n.y?e.length/2-i/2:n.y*a,u=null==n.opacity?1:n.opacity;let h=null;if(n.excavate){let e=Math.floor(c),t=Math.floor(d);h={x:e,y:t,w:Math.ceil(l+c-e),h:Math.ceil(i+d-t)}}return{x:c,y:d,h:i,w:l,excavation:h,opacity:u,crossOrigin:n.crossOrigin}}(e,l,t,a);return{cells:e,margin:t,numCells:r,calculatedImageSettings:n}}),[c,l,a,s,o]);return{qrcode:c,margin:u,cells:d,numCells:h,calculatedImageSettings:m}}var ue=function(){try{(new Path2D).addPath(new Path2D)}catch(e){return!1}return!0}();t.forwardRef((function(e,r){const n=e,{value:s,size:o=re,level:a=ne,bgColor:l=se,fgColor:i=oe,includeMargin:c=ae,minVersion:d=le,boostLevel:u,marginSize:h,imageSettings:m}=n,g=Z(n,["value","size","level","bgColor","fgColor","includeMargin","minVersion","boostLevel","marginSize","imageSettings"]),{style:w}=g,p=Z(g,["style"]),f=null==m?void 0:m.src,y=t.useRef(null),x=t.useRef(null),E=t.useCallback((e=>{y.current=e,"function"==typeof r?r(e):r&&(r.current=e)}),[r]),[b,N]=t.useState(!1),{margin:A,cells:k,numCells:v,calculatedImageSettings:T}=de({value:s,level:a,minVersion:d,boostLevel:u,includeMargin:c,marginSize:h,imageSettings:m,size:o});t.useEffect((()=>{if(null!=y.current){const e=y.current,t=e.getContext("2d");if(!t)return;let r=k;const n=x.current,s=null!=T&&null!==n&&n.complete&&0!==n.naturalHeight&&0!==n.naturalWidth;s&&null!=T.excavation&&(r=ce(k,T.excavation));const a=window.devicePixelRatio||1;e.height=e.width=o*a;const c=o/v*a;t.scale(c,c),t.fillStyle=l,t.fillRect(0,0,v,v),t.fillStyle=i,ue?t.fill(new Path2D(ie(r,A))):k.forEach((function(e,r){e.forEach((function(e,n){e&&t.fillRect(n+A,r+A,1,1)}))})),T&&(t.globalAlpha=T.opacity),s&&t.drawImage(n,T.x+A,T.y+A,T.w,T.h)}})),t.useEffect((()=>{N(!1)}),[f]);const S=X({height:o,width:o},w);let C=null;return null!=f&&(C=t.createElement("img",{src:f,key:f,style:{display:"none"},onLoad:()=>{N(!0)},ref:x,crossOrigin:null==T?void 0:T.crossOrigin})),t.createElement(t.Fragment,null,t.createElement("canvas",X({style:S,height:o,width:o,ref:E,role:"img"},p)),C)})).displayName="QRCodeCanvas";var he=t.forwardRef((function(e,r){const n=e,{value:s,size:o=re,level:a=ne,bgColor:l=se,fgColor:i=oe,includeMargin:c=ae,minVersion:d=le,boostLevel:u,title:h,marginSize:m,imageSettings:g}=n,w=Z(n,["value","size","level","bgColor","fgColor","includeMargin","minVersion","boostLevel","title","marginSize","imageSettings"]),{margin:p,cells:f,numCells:y,calculatedImageSettings:x}=de({value:s,level:a,minVersion:d,boostLevel:u,includeMargin:c,marginSize:m,imageSettings:g,size:o});let E=f,b=null;null!=g&&null!=x&&(null!=x.excavation&&(E=ce(f,x.excavation)),b=t.createElement("image",{href:g.src,height:x.h,width:x.w,x:x.x+p,y:x.y+p,preserveAspectRatio:"none",opacity:x.opacity,crossOrigin:x.crossOrigin}));const N=ie(E,p);return t.createElement("svg",X({height:o,width:o,viewBox:`0 0 ${y} ${y}`,ref:r,role:"img"},w),!!h&&t.createElement("title",null,h),t.createElement("path",{fill:l,d:`M0,0 h${y}v${y}H0z`,shapeRendering:"crispEdges"}),t.createElement("path",{fill:i,d:N,shapeRendering:"crispEdges"}),b)}));he.displayName="QRCodeSVG";const me=({walletAddress:e,amount:r,currency:n,network:s,theme:o="light",size:a=200})=>{const[l,i]=t.useState(""),[c,d]=t.useState(null);t.useEffect((()=>{if(e&&"No address configured"!==e)try{let t;switch(s){case"tron":t="TRX"===n?`tronlink://transfer?to=${e}&amount=${r}`:e;break;case"algorand":t=`algorand://${e}?amount=${Math.floor(1e6*parseFloat(r))}`;break;case"bsc":if("BNB"===n)t=`ethereum:${e}@56?value=${m(r)}`;else{const s=u(n,"bsc");t=s?`ethereum:${s}/transfer?address=${e}&uint256=${h(r,n)}@56`:e}break;default:if("ETH"===n)t=`ethereum:${e}@1?value=${m(r)}`;else{const s=u(n,"ethereum");t=s?`ethereum:${s}/transfer?address=${e}&uint256=${h(r,n)}`:e}}i(t),d(null)}catch(t){console.error("Error generating QR code:",t),d("Error generating payment QR code")}else d("No wallet address configured for this network")}),[e,r,n,s]);const u=(e,t)=>{var r;return(null==(r={ethereum:{USDT:"0xdAC17F958D2ee523a2206206994597C13D831ec7",USDC:"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"},bsc:{USDT:"0x55d398326f99059fF775485246999027B3197955",USDC:"0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d"},tron:{USDT:"TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t",USDC:"TEkxiTehnzSmSe2XqrBj4w32RUN966rdz8"}}[t])?void 0:r[e])||""},h=(e,t)=>{const r="USDT"===t||"USDC"===t?6:18;return Math.floor(parseFloat(e)*Math.pow(10,r)).toString()},m=e=>Math.floor(1e18*parseFloat(e)).toString(),g=e=>({ethereum:"Ethereum",bsc:"BSC",tron:"Tron",algorand:"Algorand"}[e]||e);return z.jsxs("div",{className:"flex flex-col items-center",children:[c?z.jsxs("div",{className:"p-4 rounded-lg bg-red-100 mb-3 text-red-700 text-center",children:[z.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:z.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"})}),z.jsx("p",{className:"font-medium",children:c})]}):z.jsx("div",{className:"p-4 rounded-lg bg-white mb-3 shadow-sm border",children:l&&z.jsx(he,{value:l,size:a,bgColor:"dark"===o?"#374151":"#FFFFFF",fgColor:"dark"===o?"#FFFFFF":"#000000",level:"H",includeMargin:!0})}),z.jsxs("div",{className:"text-center text-sm text-gray-700 mb-4",children:[z.jsxs("p",{className:"font-semibold text-gray-800 flex items-center justify-center",children:[z.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:z.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]}),z.jsxs("p",{className:"text-xs text-gray-500 mt-1",children:["Scan with your ",g(s)," wallet app"]})]}),z.jsxs("div",{className:"w-full mb-4 p-3 bg-gray-50 rounded-lg",children:[z.jsxs("div",{className:"flex justify-between items-center",children:[z.jsx("span",{className:"text-sm font-medium text-gray-700",children:"Amount to Pay:"}),z.jsxs("span",{className:"text-lg font-bold text-[#7042D2]",children:[r," ",n]})]}),z.jsxs("div",{className:"flex justify-between items-center mt-1",children:[z.jsx("span",{className:"text-xs text-gray-500",children:"Network:"}),z.jsx("span",{className:"text-xs font-medium text-gray-700",children:g(s)})]})]}),!c&&z.jsxs("div",{className:"w-full mb-4",children:[z.jsx("p",{className:"text-xs text-gray-500 mb-1 text-center",children:"Or copy wallet address:"}),z.jsx("div",{className:"text-xs font-mono p-2 rounded bg-gray-100 text-gray-700 break-all text-center select-all cursor-pointer border",onClick:()=>{var t;return null==(t=navigator.clipboard)?void 0:t.writeText(e)},title:"Click to copy",children:e})]}),z.jsx("div",{className:"w-full",children:z.jsxs("div",{className:"p-3 rounded bg-blue-50 border border-blue-200",children:[z.jsxs("h4",{className:"text-sm font-medium mb-2 text-blue-800 flex items-center",children:[z.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:z.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"]}),z.jsxs("ol",{className:"text-xs space-y-1 text-blue-700",children:[z.jsxs("li",{children:["1. Open your crypto wallet app (",(w=s,{ethereum:["MetaMask","Trust Wallet","Coinbase Wallet"],bsc:["MetaMask","Trust Wallet","SafePal"],tron:["TronLink","Trust Wallet"],algorand:["Pera Wallet","MyAlgo Wallet"]}[w]||["MetaMask","Trust Wallet"]).join(", "),")"]}),z.jsx("li",{children:"2. Scan the QR code above or copy the wallet address"}),z.jsxs("li",{children:["3. Send exactly ",z.jsxs("strong",{children:[r," ",n]})," on ",g(s)," network"]}),z.jsx("li",{children:'4. Click "I have sent the payment" button below after sending'})]}),z.jsx("div",{className:"mt-3 p-2 bg-yellow-50 border border-yellow-200 rounded",children:z.jsxs("p",{className:"text-xs text-yellow-800",children:[z.jsx("strong",{children:"Important:"})," Make sure you're sending on the correct network (",g(s),") and using the exact amount shown above."]})})]})})]});var w},ge=({status:e,message:t,theme:r="light"})=>z.jsxs("div",{className:"flex flex-col items-center justify-center py-6",children:[z.jsx("div",{className:"mb-4",children:(()=>{switch(e){case"processing":return z.jsx("div",{className:"animate-spin rounded-full h-12 w-12 border-4 border-t-blue-500 border-blue-500/20"});case"success":return z.jsx("div",{className:"rounded-full h-12 w-12 bg-green-100 flex items-center justify-center",children:z.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:z.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5 13l4 4L19 7"})})});case"error":return z.jsx("div",{className:"rounded-full h-12 w-12 bg-red-100 flex items-center justify-center",children:z.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:z.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})})});default:return null}})()}),z.jsx("h3",{className:"text-xl font-bold mb-2 "+("dark"===r?"text-white":"text-gray-900"),children:(()=>{switch(e){case"processing":return"Processing Payment";case"success":return"Payment Successful";case"error":return"Payment Failed";default:return"Unknown Status"}})()}),z.jsx("p",{className:`text-center ${(()=>{switch(e){case"processing":return"dark"===r?"text-blue-300":"text-blue-600";case"success":return"dark"===r?"text-green-300":"text-green-600";case"error":return"dark"===r?"text-red-300":"text-red-600";default:return"dark"===r?"text-gray-300":"text-gray-600"}})()}`,children:t}),"processing"===e&&z.jsx("div",{className:"mt-4 text-xs "+("dark"===r?"text-gray-400":"text-gray-500"),children:"This may take a few moments. Please do not close this window."}),"success"===e&&z.jsx("div",{className:"mt-4 p-2 rounded "+("dark"===r?"bg-gray-700":"bg-gray-100"),children:z.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."})})]}),we=({onSelect:e,selected:r,theme:n="light",supportedNetworks:s=[]})=>{const[o,a]=t.useState(u.ETHEREUM),[l,i]=t.useState({}),[c,d]=t.useState(!1);t.useEffect((()=>{i(w())}),[]);const m=[{id:u.ETHEREUM,name:"Ethereum",description:"ERC-20 tokens"},{id:u.BSC,name:"BSC (Binance Smart Chain)",description:"BEP-20 tokens"},{id:u.TRON,name:"Tron",description:"TRC-20 tokens"},{id:u.ALGORAND,name:"Algorand",description:"ASA tokens"}],p=(e=>{const t=[];switch(e){case u.ETHEREUM:t.push({id:"USDT",name:"USDT",description:"Tether USD",logo:"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSj0euZAOXsLTJFQxgiKzlX7z8xbfBk-7kmJA&s",network:u.ETHEREUM},{id:"USDC",name:"USDC",description:"USD Coin",logo:"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ43MuDqq54iD1ZCRL_uthAPkfwSSL-J5qI_Q&s",network:u.ETHEREUM},{id:"PYUSD",name:"PYUSD",description:"PayPal USD",logo:"https://s2.coinmarketcap.com/static/img/coins/64x64/28492.png",network:u.ETHEREUM},{id:"FRAX",name:"FRAX",description:"Frax",logo:"https://s2.coinmarketcap.com/static/img/coins/64x64/6952.png",network:u.ETHEREUM},{id:"USDP",name:"USDP",description:"Pax Dollar",logo:"https://s2.coinmarketcap.com/static/img/coins/64x64/6662.png",network:u.ETHEREUM},{id:"DAI",name:"DAI",description:"Dai Stablecoin",logo:"https://s2.coinmarketcap.com/static/img/coins/64x64/4943.png",network:u.ETHEREUM},{id:"ETH",name:"ETH",description:"Ethereum",logo:"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTcyJyRKN0dRJWVZqoLzYgkRHdJsxKGq8nHUw&s",network:u.ETHEREUM});break;case u.BSC:t.push({id:"USDT",name:"USDT",description:"Tether USD",logo:"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSj0euZAOXsLTJFQxgiKzlX7z8xbfBk-7kmJA&s",network:u.BSC},{id:"USDC",name:"USDC",description:"USD Coin",logo:"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ43MuDqq54iD1ZCRL_uthAPkfwSSL-J5qI_Q&s",network:u.BSC},{id:"BUSD",name:"BUSD",description:"Binance USD",logo:"https://s2.coinmarketcap.com/static/img/coins/64x64/4687.png",network:u.BSC},{id:"FRAX",name:"FRAX",description:"Frax",logo:"https://s2.coinmarketcap.com/static/img/coins/64x64/6952.png",network:u.BSC},{id:"BNB",name:"BNB",description:"Binance Coin",logo:"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRHSjyW2sSnBhwztCwVW97i1BtV40g7heMMxg&s",network:u.BSC});break;case u.TRON:t.push({id:"USDT",name:"USDT",description:"Tether USD",logo:"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSj0euZAOXsLTJFQxgiKzlX7z8xbfBk-7kmJA&s",network:u.TRON},{id:"USDC",name:"USDC",description:"USD Coin",logo:"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ43MuDqq54iD1ZCRL_uthAPkfwSSL-J5qI_Q&s",network:u.TRON},{id:"USDJ",name:"USDJ",description:"JUST Stablecoin",logo:"https://s2.coinmarketcap.com/static/img/coins/64x64/5446.png",network:u.TRON},{id:"TRX",name:"TRX",description:"Tron",logo:"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQKLpLNsGRHbZfCUXAjZLPSp_YFZvX5dMnAoA&s",network:u.TRON});break;case u.ALGORAND:t.push({id:"USDC",name:"USDC",description:"USD Coin",logo:"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ43MuDqq54iD1ZCRL_uthAPkfwSSL-J5qI_Q&s",network:u.ALGORAND},{id:"USDT",name:"USDT",description:"Tether USD",logo:"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSj0euZAOXsLTJFQxgiKzlX7z8xbfBk-7kmJA&s",network:u.ALGORAND},{id:"ALGO",name:"ALGO",description:"Algorand",logo:"https://s2.coinmarketcap.com/static/img/coins/64x64/4030.png",network:u.ALGORAND})}return t})(o),f=c?p:p.slice(0,4);function y(e){switch(e){case u.ETHEREUM:case u.BSC:return h.METAMASK;case u.TRON:return h.TRONLINK;case u.ALGORAND:return h.LUTE;default:return h.METAMASK}}return z.jsxs("div",{children:[z.jsx("h3",{className:"text-lg font-medium mb-4 "+("dark"===n?"text-white":"text-gray-800"),children:"Select Payment Method"}),z.jsxs("div",{className:"mb-6",children:[z.jsx("label",{className:"block text-sm font-medium mb-2 "+("dark"===n?"text-white":"text-gray-700"),children:"Blockchain Network"}),z.jsx("select",{value:o,onChange:t=>{return n=t.target.value,a(n),d(!1),void((null==r?void 0:r.network)!==n&&e(null));var n},className:`w-full p-3 rounded-lg border transition-colors ${"dark"===n?"bg-gray-700 border-gray-600 text-white focus:border-[#7042D2]":"bg-white border-gray-300 text-gray-900 focus:border-[#7042D2]"} focus:outline-none focus:ring-2 focus:ring-[#7042D2] focus:ring-opacity-50`,children:m.filter((e=>0===s.length||s.includes(e.id))).map((e=>z.jsxs("option",{value:e.id,children:[e.name," - ",e.description]},e.id)))})]}),z.jsxs("div",{className:"mb-4",children:[z.jsx("label",{className:"block text-sm font-medium mb-3 "+("dark"===n?"text-white":"text-gray-700"),children:"Choose Cryptocurrency"}),z.jsx("div",{className:"grid grid-cols-2 gap-3 mb-4",children:f.map((t=>z.jsx("button",{onClick:()=>(t=>{var r;e({currency:t.id,network:o,tokenConfig:null==(r=g[t.id])?void 0:r[o],method:t})})(t),className:"p-4 rounded-lg transition-all duration-200 border-2 "+((null==r?void 0:r.currency)===t.id&&(null==r?void 0:r.network)===o?"dark"===n?"bg-blue-900/30 border-[#7042D2] ring-2 ring-[#7042D2] ring-opacity-50":"bg-blue-50 border-[#7042D2] ring-2 ring-[#7042D2] ring-opacity-50":"dark"===n?"bg-gray-700 hover:bg-gray-600 border-gray-600 hover:border-gray-500":"bg-white hover:bg-gray-50 border-gray-200 hover:border-gray-300"),children:z.jsxs("div",{className:"flex flex-col items-center text-center",children:[z.jsx("div",{className:"flex-shrink-0 h-10 w-10 bg-white rounded-full flex items-center justify-center mb-2 shadow-sm",children:z.jsx("img",{src:t.logo,alt:t.name,className:"h-6 w-6"})}),z.jsxs("div",{children:[z.jsx("h4",{className:"font-medium text-sm "+("dark"===n?"text-white":"text-gray-900"),children:t.name}),z.jsx("p",{className:"text-xs "+("dark"===n?"text-gray-300":"text-gray-500"),children:t.description})]}),(null==r?void 0:r.currency)===t.id&&(null==r?void 0:r.network)===o&&z.jsx("div",{className:"mt-2",children:z.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-4 w-4 text-[#7042D2]",viewBox:"0 0 20 20",fill:"currentColor",children:z.jsx("path",{fillRule:"evenodd",d:"M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z",clipRule:"evenodd"})})})]})},`${t.id}-${t.network}`)))}),p.length>4&&z.jsx("button",{onClick:()=>d(!c),className:"w-full py-2 px-4 rounded-lg text-sm font-medium transition-colors "+("dark"===n?"bg-gray-700 text-gray-300 hover:bg-gray-600":"bg-gray-100 text-gray-600 hover:bg-gray-200"),children:c?"Show Less":`Show More (${p.length-4} more)`})]}),z.jsx("div",{className:"p-3 rounded-lg text-sm "+("dark"===n?"bg-gray-800 text-gray-300":"bg-gray-50 text-gray-600"),children:z.jsxs("div",{className:"flex items-center",children:[z.jsx("div",{className:"w-2 h-2 rounded-full mr-2 "+(l[y(o)]?"bg-green-500":"bg-red-500")}),z.jsx("span",{className:"text-xs",children:function(e){const t=y(e),r=l[t],n={[h.METAMASK]:"MetaMask",[h.TRONLINK]:"TronLink",[h.LUTE]:"Lute Wallet"};return r?`${n[t]} detected - Ready to pay`:`${n[t]} required - Please install to continue`}(o)})]})})]})},pe=({isOpen:e,onClose:r,payment:n,paymentStatus:s,selectedPaymentMethod:o,onPaymentMethodSelect:a,onPayment:l,onBack:i,error:c,theme:d="light",merchantName:u,transactionHash:m,walletConnection:g,onConnectWallet:w,testMode:p=!1,supportedNetworks:f=[],availableWallets:y={},supportedWallets:x=[],step:E="select-currency",merchantWalletAddresses:b={}})=>{const[N,A]=t.useState("wallet"),k=e=>({ethereum:"Ethereum",bsc:"BSC",tron:"Tron",algorand:"Algorand"}[e]||e),v=e=>({[h.METAMASK]:"MetaMask",[h.TRONLINK]:"TronLink",[h.TRUST_WALLET]:"Trust Wallet",[h.LUTE]:"Lute Wallet"}[e]||e),T=e=>({[h.METAMASK]:"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcT3ymr3UNKopfI0NmUY95Dr-0589vG-91KuAA&s",[h.TRONLINK]:"https://www.tronlink.org/images/logo.png",[h.TRUST_WALLET]:"https://trustwallet.com/assets/images/trust_logotype.svg",[h.LUTE]:"https://lute.app/logo.png"}[e]||"");return e?z.jsx("div",{className:"fixed inset-0 z-50 overflow-y-auto bg-black/50",children:z.jsx("div",{className:"flex min-h-screen items-center justify-center p-4",children:z.jsxs("div",{className:"relative p-6 w-full max-w-md mx-auto rounded-lg shadow-xl bg-white text-gray-800",children:[z.jsxs("div",{className:"flex justify-between items-center mb-6 bg-[#F1ECFB] p-3 rounded-xl",children:[z.jsx("div",{className:"flex items-center",children:z.jsx("h2",{className:"text-xl font-bold text-gray-900",children:z.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+QrJITl89+09cwH0LakOkS3OEPWuS42yrHiQiydjX8Q9IqVw6kjVdh1bI1FphPoV1RTGvpFryklVulTpJnD+jrX/aK9NeET5YR7Z+7lC+Jr0sD9gvQeeoF2/PjrXIfI9orxqpfEboxmkGFyn6yzsNnj664MiAH9rBLkKlJa6IU+4LsnyNyu7t7/n6rxUBvgAxj9jizWZSMNJdAd1lgjMH6IPA5gBGgXOX7SUk9hrbsK/JFpcM3eUruq47NIvd3xIEVyyOp/QDu9Z/nJJKL0K4ys6RYAlcZaItAdcabGh0kSHk3R/rIsXi4nO39p8FBU3paa5NclEA9V1oMeokoo0xBDdMLTt1oHZPWhGv0NdLr9rv8YoxmfiuY8E9aDzgpWle+RzUiu7T8pQpgq0V0dkmJmVGL6oPTu1zfJA+ZG2m3I7CZp0M+eYmF5otCyji821xlrPZqI378BTnqr0qz2mAXjv6eBYJdKcNG3R4A1q5Ejb/n+oDia128QemoTRBtLKy/fphFOH+jJEe4JcoNovaa+T2uuIwLXGMH1PbUqccyNbFgLfWpvq6yqyZA3p0U5f2tfU1iG5IcflAGavzE00LYia+o9O3T9smfDIoXpJQI5gcvLk1r9j5wbOOV/bKfz7fX0Ue4LufedIPPft3ie/zgThfUWqfx2Ql3hk1T1D3kc9g8T5iqwGQqWr4fG3Ea3w2i73N+QWGLG8RGHg+jCFMWzz4zf2NyQnDcgJXWeE1SBRaDkOKuMLFXqQr9EMfj8pjGab19yHa5ATBAwZUlTHI6Ql+QpSwi5eYmt8f0YjsvH/j39r08lNgVS0YGX0kJuIStPuIczAUd18t95F0yoQ8Hu/E6wWVdA0vr7l/Bs0Y8Dy5y3a+Izw3Ljm90lTpK+/3BhP84M9q0kGaoqa2s1dv/GrbKqf7/7zO54PguVTtF9Su6tTbn9JFMv7JqQobKscCcKuhDo5TZDoZownLD8PlPswD8iawthkOYly49ztb+7jcrEk8tIPZT3bqbV9DhS5hGKRUAa7uvhilnu+nxGcCPdYDYLlJbrhVyZDYDvQ9+TvsBqEc0zay51KScm4hDph1y5p15IfypBpj8hEKu29dhH04lOVPw1EHzwnNmGTESTWwyYWG5vA97qPCcpjnaCs9U5Z/dL0WfihlNFNEQYmGkAbY8bwyjLSFAO7n/ecg8kJtCn77aBj/Z9YXmI7sKkXjMuiY25L5VOcQHVKTd1MTJpHbbN8JaMb9ax/7jdTsvwJVsOM5QW69SVheYntAO8XEYH2VaMV0ismi9uIpJVye8rFFGw8YqV5RlYLNUBvqWzyrWhCCh4h2t7ZN0BhF8w8ctou/0cok2+Odgb2c0Bi9fFpQopyP/OVMp/uvvCG8TJqIATtMc8o+uD18Ojh7uzdt1b7PMMkGPXZFr6HRw+4ifxU5wrl/Sq+TKaBP22QQ+fHrKzr6u57w7cHJ9AMqtdEvnNPm8TJS3jGg/xQHz3OTao8VcpQOQkjaSIsFUPV9kyWZZNW/qg4O9DBebS1szpoq4O/heRVpvsRrG4Cs8oZO2V0TJ2eoDpVTeHfN6NrXKDqWpBo5+d5TnADOl/pDQL1875N7O9jTd0UPC6uer6CyM2QRsk3cL2BcTkWT+RgnKnzVxSqQnt6tv6Fyp8tZRzdf1VkVRolGk9u/7vqw6A3KbTjL+1vH367iAbk0NZLEF5W59OiQPgNJw+8+0Z2DV9JUQ8uL2+ToHzfEmWnJ72w1x55VC9f0vdR7Of1PfVCTtQxwubBITwxXCW3gUOmfpBMeTSmiXU6QRwnVtSJzke9q6Lu4oOdMsd6Fbka6G0KkVEgbGQTQdztkxThuG8a6ARhMlG7bZvuctB9+cZHwH5DCaOFEvjJdIQwuAbMMUMgINAfD8UD41yo6dHaRgNb0reSzK+aFvNwYU1QIpWJOliHVGNU96DqkML/Bk3RLf6b6h2hvWf9n8IY9XucPhARDxva+FwIhMtQg0rEJiNLGSZI7lyvDMsXhbG1LKLeMvTBTodH9vN0IhVWnP6mNg1gDOaEnc+N+DxsIwQJQ6qBlcOnAZJDRPyMeiJ9QflhSHbuJyazCVze3JE79ZRzpCj6RY7pBH6NRNe5QfvVqgxcy4uIF5hPzCO/JlG2k44pP36g8Ip+qYyM78yZyxdPr1w3g/5yJoqv9apSGfuTX95uYgoRzrHE6hAbkrNtcG3LOVZzhnLbboqaT8aqU17mnermS+KY6Yzv5QBP7LOoOB64WR2MRxGgWsvhakNed+mkbZCzbSACSVR9Vm3BXQWEz3UNqoSquhCmJtTXbg4vjXDQFDjLtZD+pUjPQtA+F0021eRu/40NKz7ADtuMkB8urWtU/Yzq9u1UaQ+pow0WTzdV77hDlGgZgmuQLdT8HBmi1Hjfl3HnO2wbEhT2qWDniAeNIdD+z6jqQlXcuHL6MMHFYpEuDfYo2sSUtsPzQiDs6CQySTQgRldkWU6UKf+KRROxOaR4h5cF0kzk+pm2qdydUJF2D8yXH3NyPP21tf9dbYdOkDAOU3JFtF6R76EraO9PrfJC39hZv5NidG835b085Eb3qi4G/A2inrQKnVgMFAAAAABJRU5ErkJggg==",className:"w-32",alt:"Coinley Logo"})})}),z.jsx("button",{onClick:r,className:"text-gray-500 hover:text-gray-700 focus:outline-none",children:z.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-6 w-6",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:z.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),z.jsxs("div",{className:"mb-6 bg-[#F1ECFB] p-3 rounded-xl",children:[n&&z.jsxs("div",{className:"mb-6 p-4 rounded-lg",children:[z.jsxs("p",{className:"text-lg text-gray-800 font-semibold",children:["PAY: ",u]}),z.jsxs("div",{className:"flex justify-between items-center mt-2 bg-gray-100 px-3 rounded-lg",children:[z.jsx("span",{className:"font-medium text-gray-700",children:"Amount:"}),z.jsxs("span",{className:"font-bold text-xl text-[#7042D2]",children:["$",(M=n.totalAmount||n.amount,parseFloat(M).toFixed(2))]})]}),z.jsx("div",{className:"text-xs mt-1 text-right",children:z.jsxs("span",{className:"text-gray-500",children:["Payment ID: ",n.id?n.id.slice(0,8):"","..."]})})]}),"select-currency"===E&&z.jsxs("div",{children:[z.jsx(we,{onSelect:a,selected:o,theme:d,supportedNetworks:f}),o&&z.jsx("div",{className:"mt-6",children:z.jsxs("button",{onClick:()=>{console.log("Proceed button clicked, calling onPaymentMethodSelect"),a(o)},className:"w-full py-3 px-4 bg-[#7042D2] hover:bg-[#7042D2] text-white font-medium rounded-lg transition-colors",disabled:!o,children:["Proceed with ",o.currency," on ",k(o.network)]})})]}),"confirm"===E&&o&&n&&z.jsxs("div",{children:[z.jsxs("div",{className:"p-4 rounded-lg mb-4 bg-gray-100",children:[z.jsx("h3",{className:"text-lg font-medium mb-2 text-gray-800",children:"Payment Details"}),z.jsxs("div",{className:"space-y-2",children:[z.jsxs("div",{className:"flex justify-between",children:[z.jsx("span",{className:"text-[#7042D2] font-semibold",children:"Currency:"}),z.jsx("span",{className:"font-medium",children:o.currency})]}),z.jsxs("div",{className:"flex justify-between",children:[z.jsx("span",{className:"text-[#7042D2] font-semibold",children:"Network:"}),z.jsx("span",{className:"font-medium",children:k(o.network)})]}),z.jsxs("div",{className:"flex justify-between",children:[z.jsx("span",{className:"text-[#7042D2] font-semibold",children:"Fee:"}),z.jsx("span",{className:"font-medium",children:"1.75%"})]})]})]}),z.jsx("div",{className:"mb-4",children:z.jsxs("div",{className:"flex border-b border-gray-200",children:[z.jsx("button",{onClick:()=>A("wallet"),className:"py-2 px-4 text-sm font-medium "+("wallet"===N?"border-b-2 border-[#7042D2] text-[#7042D2]":"text-gray-500 hover:text-gray-700"),children:"Connect Wallet"}),z.jsx("button",{onClick:()=>A("qrcode"),className:"py-2 px-4 text-sm font-medium "+("qrcode"===N?"border-b-2 border-[#7042D2] text-[#7042D2]":"text-gray-500 hover:text-gray-700"),children:"QR Code"})]})}),p?z.jsx("div",{className:"p-4 rounded-lg mb-4 bg-blue-50",children:z.jsxs("div",{className:"flex items-center",children:[z.jsx("div",{className:"bg-[#7042D2] rounded-full p-2 mr-3",children:z.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:z.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 10V3L4 14h7v7l9-11h-7z"})})}),z.jsxs("div",{children:[z.jsx("h3",{className:"font-medium text-gray-800",children:"Test Mode Payment"}),z.jsx("p",{className:"text-sm text-gray-600",children:'Click "Pay Now" to simulate a successful payment'})]})]})}):"qrcode"===N?z.jsx("div",{className:"mb-4",children:z.jsx(me,{walletAddress:(()=>{if(!o)return"No network selected";const e=b[o.network];return e||((null==n?void 0:n.recipientWallet)?n.recipientWallet:"No wallet address configured for this network")})(),amount:n.totalAmount||n.amount,currency:o.currency,network:o.network,theme:d})}):z.jsxs("div",{className:"space-y-3 mb-4",children:[0===x.length?z.jsx("div",{className:"p-4 rounded-lg bg-yellow-50",children:z.jsxs("div",{className:"flex items-center",children:[z.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:z.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"})}),z.jsxs("div",{children:[z.jsx("h3",{className:"font-medium text-gray-800",children:"No Compatible Wallets"}),z.jsxs("p",{className:"text-sm text-gray-600",children:["No wallets detected for ",k(o.network)," network"]})]})]})}):x.map((e=>z.jsx("div",{className:"p-4 rounded-lg bg-blue-50",children:z.jsxs("div",{className:"flex items-center justify-between",children:[z.jsxs("div",{className:"flex items-center",children:[z.jsx("img",{src:T(e),alt:v(e),className:"w-8 h-8 mr-3",onError:e=>{e.target.style.display="none"}}),z.jsxs("div",{children:[z.jsx("h3",{className:"font-medium text-gray-800",children:v(e)}),z.jsxs("p",{className:"text-sm text-gray-600",children:["Pay with ",v(e)]})]})]}),(null==g?void 0:g.walletType)===e?z.jsxs("div",{className:"flex items-center space-x-2",children:[z.jsx("div",{className:"w-2 h-2 bg-green-500 rounded-full"}),z.jsx("span",{className:"text-sm text-green-600",children:"Connected"})]}):z.jsx("button",{onClick:()=>{console.log("Connect wallet button clicked for:",e),w(e)},className:"py-2 px-4 bg-[#7042D2] hover:bg-[#7042D2] text-white font-medium rounded-md text-sm",children:"Connect"})]})},e))),z.jsx("div",{className:"space-y-2",children:Object.entries(y).filter((([e,t])=>!t)).map((([e])=>z.jsx("div",{className:"p-3 rounded-lg bg-gray-50",children:z.jsxs("div",{className:"flex items-center justify-between",children:[z.jsxs("span",{className:"text-sm text-gray-600",children:[v(e)," not detected"]}),z.jsx("a",{href:S(e),target:"_blank",rel:"noopener noreferrer",className:"text-sm text-[#7042D2] hover:underline",children:"Install"})]})},e)))})]}),z.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[z.jsx("button",{type:"button",onClick:i,className:"w-full py-2 px-4 bg-gray-200 hover:bg-gray-300 text-[#7042D2] font-medium rounded-md",children:"Back"}),z.jsx("button",{type:"button",onClick:()=>l("qrcode"===N),className:"w-full py-2 px-4 bg-[#7042D2] hover:bg-[#7042D2] text-white font-medium rounded-md",disabled:!p&&"wallet"===N&&!g,children:"qrcode"===N?"I have sent the payment":"Pay Now"})]})]}),"processing"===E&&z.jsx(ge,{status:"processing",theme:d,message:"Processing your payment..."}),"success"===E&&z.jsxs("div",{children:[z.jsx(ge,{status:"success",theme:d,message:"Payment successful!"}),m&&z.jsxs("div",{className:"mt-4 p-3 rounded-lg bg-gray-100",children:[z.jsx("p",{className:"text-xs text-gray-600 mb-1",children:"Transaction Hash:"}),z.jsx("p",{className:"text-sm font-mono break-all text-gray-800",children:(C=m,C?C.length<=14?C:`${C.slice(0,8)}...${C.slice(-6)}`:"")}),o&&z.jsx("a",{href:`${fe(o.network)}/${ye(o.network)}/${m}`,target:"_blank",rel:"noopener noreferrer",className:"text-xs text-[#7042D2] mt-2 inline-block",children:"View on Explorer →"})]})]}),"error"===E&&z.jsxs("div",{children:[z.jsx(ge,{status:"error",theme:d,message:c||"An error occurred while processing your payment."}),z.jsx("button",{type:"button",onClick:i,className:"mt-4 w-full py-2 px-4 bg-gray-200 hover:bg-gray-300 text-gray-800 font-medium rounded-md",children:"Try Again"})]})]}),z.jsx("div",{className:"text-center text-xs text-gray-500",children:z.jsxs("p",{children:["Powered by ",z.jsx("span",{className:"text-[#7042D2]",children:"Coinley"})," - Secure Cryptocurrency Payments"]})})]})})}):null;var C,M},fe=e=>({ethereum:"https://etherscan.io",bsc:"https://bscscan.com",tron:"https://tronscan.org",algorand:"https://algoexplorer.io"}[e]||"https://etherscan.io"),ye=e=>({ethereum:"tx",bsc:"tx",tron:"transaction",algorand:"tx"}[e]||"tx"),xe=t.forwardRef((({apiKey:e,apiSecret:r,apiUrl:n,customerEmail:s,merchantName:o="Merchant",merchantWalletAddresses:a={},onSuccess:l,onError:i,onClose:m,theme:g,autoOpen:y=!1,debug:x=!1,testMode:E=!1,supportedNetworks:b=[],preferredNetwork:N=u.ETHEREUM,preferredWallet:k=h.METAMASK},v)=>{const T=q(),{theme:S}=t.useContext(H),[C,M]=t.useState(y),[L,D]=t.useState(null),[U,P]=t.useState("idle"),[O,W]=t.useState(null),[I,F]=t.useState(null),[B,G]=t.useState(null),[K,Q]=t.useState(null),[_,V]=t.useState({}),[J,$]=t.useState("select-currency");e||null==T||T.apiKey,r||null==T||T.apiSecret,n||null==T||T.apiUrl;const Y=g||S,X=x||(null==T?void 0:T.debug),Z=b.length>0?b:[u.ETHEREUM,u.BSC,u.TRON,u.ALGORAND];t.useImperativeHandle(v,(()=>({open:e=>{te(e)},close:()=>{re()},getPayment:()=>L,getWalletConnection:()=>K})));const ee=(e,t)=>{X&&console.log(`[Coinley SDK] ${e}`,t)};t.useEffect((()=>{if("undefined"!=typeof window){const e=w();V(e),ee("Available wallets detected:",e)}}),[X]);const te=e=>d(this,null,(function*(){if(!e||!e.amount)return F("Payment amount is required"),void(i&&i(new Error("Payment amount is required")));P("loading"),M(!0),$("select-currency");try{ee("Creating payment with details:",e);const t=yield j({amount:e.amount,currency:e.currency||"USDT",network:e.network||N,customerEmail:e.customerEmail||s,callbackUrl:e.callbackUrl,metadata:e.metadata||{},merchantWalletAddresses:c(c({},a),e.merchantWalletAddresses)});ee("Payment created:",t),D(t.payment),P("idle"),F(null),ee("Payment created and state updated")}catch(t){ee("Error creating payment:",t),F(t.message||"Failed to create payment"),P("error"),i&&i(t)}})),re=()=>{M(!1),G(null),Q(null),W(null),$("select-currency"),m&&m()};return z.jsx(z.Fragment,{children:C&&z.jsx(pe,{isOpen:C,onClose:re,payment:L,paymentStatus:U,selectedPaymentMethod:O,onPaymentMethodSelect:e=>{console.log("=== PAYMENT METHOD SELECTION DEBUG ==="),console.log("1. Payment method selected:",e),console.log("2. Current step before:",J),ee("Payment method selected:",e),W(e),$("confirm"),console.log("3. Step should now be: confirm"),console.log("=== END PAYMENT METHOD SELECTION DEBUG ===")},onPayment:()=>d(this,null,(function*(){var e,t;if(L&&O)if(K||E){ee("Starting payment process..."),P("loading"),G(null);try{let r;if(E)ee("Test mode: Generating mock transaction..."),r=`test_${Date.now().toString(16)}_${Math.random().toString(16).substring(2,10)}`;else{const n=a[O.network];if(!n)throw new Error(`No merchant wallet address configured for ${O.network}`);ee("Sending transaction through wallet..."),r=yield A(K,{to:n,amount:L.amount,tokenAddress:null==(e=O.tokenConfig)?void 0:e.address,tokenDecimals:null==(t=O.tokenConfig)?void 0:t.decimals})}ee("Transaction hash:",r),G(r),ee("Processing payment with backend...");const n=yield R({paymentId:L.id,transactionHash:r,network:O.network,currency:O.currency,senderAddress:null==K?void 0:K.address});ee("Payment processed successfully:",n),P("success"),$("success"),l&&(ee("Calling onSuccess callback..."),l(L.id,r,{network:O.network,currency:O.currency,amount:L.amount}))}catch(r){ee("Payment error:",r),F(r.message||"Failed to process payment"),P("error"),$("error"),i&&i(r)}}else F("Please connect your wallet first");else F("Missing payment information")})),onBack:()=>{"confirm"===J&&($("select-currency"),Q(null))},error:I,theme:Y,merchantName:o,transactionHash:B,walletConnection:K,onConnectWallet:e=>d(this,null,(function*(){if(console.log("=== WALLET CONNECTION DEBUG ==="),console.log("1. Wallet type requested:",e),console.log("2. Selected payment method:",O),console.log("3. Available wallets:",_),console.log("4. Current step:",J),!O)return console.error("No payment method selected"),void F("Please select a payment method first");try{console.log("5. Attempting to connect wallet..."),F(null),ee("Connecting wallet:",{walletType:e,network:O.network});const t=yield f(e,O.network);Q(t),F(null),console.log("6. Connection successful:",t),ee("Wallet connected successfully:",t)}catch(t){console.error("7. Connection failed:",t),ee("Wallet connection error:",t),F(t.message||"Failed to connect wallet")}console.log("=== END WALLET CONNECTION DEBUG ===")})),testMode:E,supportedNetworks:Z,availableWallets:_,supportedWallets:O?p(O.network):[],step:J,merchantWalletAddresses:a})})}));xe.displayName="CoinleyCheckout";e.CoinleyCheckout=xe,e.CoinleyModal=pe,e.CoinleyProvider=({apiKey:e,apiSecret:r,apiUrl:n="http://localhost:9000",merchantWalletAddress:s=null,merchantSolWalletAddress:o=null,debug:a=!1,children:l})=>{const[i,d]=t.useState(!1),[u,h]=t.useState(null),[m,g]=t.useState(null);t.useEffect((()=>{var t;if(e&&r)try{t={apiKey:e,apiSecret:r,apiUrl:n,merchantWalletAddress:s,merchantSolWalletAddress:o},C=c(c({},C),t),console.log("API initialized with:",{apiUrl:C.apiUrl,apiKey:C.apiKey?`${C.apiKey.substring(0,6)}...`:null,hasWalletAddresses:Object.keys(C.merchantWalletAddresses||{}).length>0}),d(!0),a&&console.log("Coinley SDK initialized with:",{apiKey:e,apiUrl:n,merchantWalletAddress:s?`${s.substring(0,6)}...${s.substring(s.length-4)}`:"Not provided",merchantSolWalletAddress:o?`${o.substring(0,6)}...${o.substring(o.length-4)}`:"Not provided"})}catch(l){h(l.message),a&&console.error("Coinley SDK initialization error:",l)}else h("API key and secret are required")}),[e,r,n,s,o,a]);const w={apiKey:e,apiSecret:r,apiUrl:n,merchantWalletAddress:s,merchantSolWalletAddress:o,isInitialized:i,error:u,debug:a,paymentData:m,storePaymentData:e=>(g(e),e)};return z.jsx(G.Provider,{value:w,children:l})},e.DEFAULT_CONFIG={apiUrl:"http://localhost:9000",debug:!1,testMode:!1,theme:"light",supportedNetworks:["ethereum","bsc","tron","algorand"]},e.NETWORK_CONFIG=m,e.NETWORK_TYPES=u,e.PaymentMethods=we,e.PaymentStatus=ge,e.QRCode=me,e.TOKEN_CONFIG=g,e.ThemeProvider=({initialTheme:e="light",children:r})=>{const[n,s]=t.useState(e);return t.useEffect((()=>{document.documentElement.classList.remove("light","dark"),document.documentElement.classList.add(n)}),[n]),z.jsx(H.Provider,{value:{theme:n,setTheme:s,toggleTheme:()=>{s((e=>"light"===e?"dark":"light"))}},children:r})},e.WALLET_TYPES=h,e.connectWallet=f,e.createPayment=j,e.detectWallets=w,e.generateMockTransactionHash=(e="ethereum")=>`${{ethereum:"0x",bsc:"0x",tron:"",algorand:""}[e]||"0x"}${Array.from({length:64},(()=>Math.floor(16*Math.random()).toString(16))).join("")}`,e.getMerchantProfile=()=>d(this,null,(function*(){try{const e=yield fetch(`${C.apiUrl}/api/merchants/profile`,{method:"GET",headers:M()});if(!e.ok){const t=yield e.json();throw new Error(t.error||`Failed to get merchant profile: ${e.status}`)}const t=yield e.json();return t.merchant&&t.merchant.walletAddresses&&(C.merchantWalletAddresses=c(c({},C.merchantWalletAddresses),t.merchant.walletAddresses)),t}catch(e){throw console.error("Get merchant profile error:",e),e}})),e.getPayment=e=>d(this,null,(function*(){try{console.log("Getting payment:",e);const t=yield fetch(`${C.apiUrl}/api/payments/${e}`,{method:"GET",headers:M()});if(!t.ok){const e=yield t.json();throw console.error("Error getting payment:",e),new Error(e.error||`Failed to get payment: ${t.status}`)}const r=yield t.json();return console.log("Get payment response:",r),r}catch(t){throw console.error("Get payment error:",t),t}})),e.getSupportedNetworks=()=>d(this,null,(function*(){try{const e=yield fetch(`${C.apiUrl}/api/networks`,{method:"GET",headers:M()});if(!e.ok){const t=yield e.json();throw new Error(t.error||`Failed to get networks: ${e.status}`)}return yield e.json()}catch(e){throw console.error("Get supported networks error:",e),e}})),e.getSupportedWalletsForNetwork=p,e.getWalletInstallUrl=S,e.processPayment=R,e.sendTransaction=A,e.useCoinley=q,e.validateWalletAddress=(e,t)=>d(this,null,(function*(){try{const r=yield fetch(`${C.apiUrl}/api/wallets/validate`,{method:"POST",headers:M(),body:JSON.stringify({address:e,network:t})});if(!r.ok){const e=yield r.json();throw new Error(e.error||`Failed to validate address: ${r.status}`)}return yield r.json()}catch(r){throw console.error("Validate wallet address error:",r),r}})),Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})}));
|
6
|
+
*/function ue(e,t=0){const r=[];return e.forEach((function(e,n){let o=null;e.forEach((function(s,a){if(!s&&null!==o)return r.push(`M${o+t} ${n+t}h${a-o}v1H${o+t}z`),void(o=null);if(a!==e.length-1)s&&null===o&&(o=a);else{if(!s)return;null===o?r.push(`M${a+t},${n+t} h1v1H${a+t}z`):r.push(`M${o+t},${n+t} h${a+1-o}v1H${o+t}z`)}}))})),r.join("")}function he(e,t){return e.slice().map(((e,r)=>r<t.y||r>=t.y+t.h?e:e.map(((e,r)=>(r<t.x||r>=t.x+t.w)&&e))))}function me({value:e,level:r,minVersion:n,includeMargin:o,marginSize:s,imageSettings:a,size:l,boostLevel:i}){let c=t.useMemo((()=>{const t=(Array.isArray(e)?e:[e]).reduce(((e,t)=>(e.push(...ne.QrSegment.makeSegments(t)),e)),[]);return ne.QrCode.encodeSegments(t,oe[r],n,void 0,void 0,i)}),[e,r,n,i]);const{cells:d,margin:u,numCells:h,calculatedImageSettings:m}=t.useMemo((()=>{let e=c.getModules();const t=function(e,t){return null!=t?Math.max(Math.floor(t),0):e?4:0}(o,s),r=e.length+2*t,n=function(e,t,r,n){if(null==n)return null;const o=e.length+2*r,s=Math.floor(.1*t),a=o/t,l=(n.width||s)*a,i=(n.height||s)*a,c=null==n.x?e.length/2-l/2:n.x*a,d=null==n.y?e.length/2-i/2:n.y*a,u=null==n.opacity?1:n.opacity;let h=null;if(n.excavate){let e=Math.floor(c),t=Math.floor(d);h={x:e,y:t,w:Math.ceil(l+c-e),h:Math.ceil(i+d-t)}}return{x:c,y:d,h:i,w:l,excavation:h,opacity:u,crossOrigin:n.crossOrigin}}(e,l,t,a);return{cells:e,margin:t,numCells:r,calculatedImageSettings:n}}),[c,l,a,o,s]);return{qrcode:c,margin:u,cells:d,numCells:h,calculatedImageSettings:m}}var ge=function(){try{(new Path2D).addPath(new Path2D)}catch(e){return!1}return!0}();t.forwardRef((function(e,r){const n=e,{value:o,size:s=se,level:a=ae,bgColor:l=le,fgColor:i=ie,includeMargin:c=ce,minVersion:d=de,boostLevel:u,marginSize:h,imageSettings:m}=n,g=re(n,["value","size","level","bgColor","fgColor","includeMargin","minVersion","boostLevel","marginSize","imageSettings"]),{style:w}=g,p=re(g,["style"]),f=null==m?void 0:m.src,y=t.useRef(null),x=t.useRef(null),E=t.useCallback((e=>{y.current=e,"function"==typeof r?r(e):r&&(r.current=e)}),[r]),[b,N]=t.useState(!1),{margin:v,cells:k,numCells:T,calculatedImageSettings:A}=me({value:o,level:a,minVersion:d,boostLevel:u,includeMargin:c,marginSize:h,imageSettings:m,size:s});t.useEffect((()=>{if(null!=y.current){const e=y.current,t=e.getContext("2d");if(!t)return;let r=k;const n=x.current,o=null!=A&&null!==n&&n.complete&&0!==n.naturalHeight&&0!==n.naturalWidth;o&&null!=A.excavation&&(r=he(k,A.excavation));const a=window.devicePixelRatio||1;e.height=e.width=s*a;const c=s/T*a;t.scale(c,c),t.fillStyle=l,t.fillRect(0,0,T,T),t.fillStyle=i,ge?t.fill(new Path2D(ue(r,v))):k.forEach((function(e,r){e.forEach((function(e,n){e&&t.fillRect(n+v,r+v,1,1)}))})),A&&(t.globalAlpha=A.opacity),o&&t.drawImage(n,A.x+v,A.y+v,A.w,A.h)}})),t.useEffect((()=>{N(!1)}),[f]);const S=te({height:s,width:s},w);let C=null;return null!=f&&(C=t.createElement("img",{src:f,key:f,style:{display:"none"},onLoad:()=>{N(!0)},ref:x,crossOrigin:null==A?void 0:A.crossOrigin})),t.createElement(t.Fragment,null,t.createElement("canvas",te({style:S,height:s,width:s,ref:E,role:"img"},p)),C)})).displayName="QRCodeCanvas";var we=t.forwardRef((function(e,r){const n=e,{value:o,size:s=se,level:a=ae,bgColor:l=le,fgColor:i=ie,includeMargin:c=ce,minVersion:d=de,boostLevel:u,title:h,marginSize:m,imageSettings:g}=n,w=re(n,["value","size","level","bgColor","fgColor","includeMargin","minVersion","boostLevel","title","marginSize","imageSettings"]),{margin:p,cells:f,numCells:y,calculatedImageSettings:x}=me({value:o,level:a,minVersion:d,boostLevel:u,includeMargin:c,marginSize:m,imageSettings:g,size:s});let E=f,b=null;null!=g&&null!=x&&(null!=x.excavation&&(E=he(f,x.excavation)),b=t.createElement("image",{href:g.src,height:x.h,width:x.w,x:x.x+p,y:x.y+p,preserveAspectRatio:"none",opacity:x.opacity,crossOrigin:x.crossOrigin}));const N=ue(E,p);return t.createElement("svg",te({height:s,width:s,viewBox:`0 0 ${y} ${y}`,ref:r,role:"img"},w),!!h&&t.createElement("title",null,h),t.createElement("path",{fill:l,d:`M0,0 h${y}v${y}H0z`,shapeRendering:"crispEdges"}),t.createElement("path",{fill:i,d:N,shapeRendering:"crispEdges"}),b)}));we.displayName="QRCodeSVG";const pe=({walletAddress:e,amount:r,currency:n,network:o,theme:s="light",size:a=200})=>{const[l,i]=t.useState(""),[c,d]=t.useState(null);t.useEffect((()=>{if(e&&"No address configured"!==e)try{let t;switch(o){case"tron":t="TRX"===n?`tronlink://transfer?to=${e}&amount=${r}`:e;break;case"algorand":t=`algorand://${e}?amount=${Math.floor(1e6*parseFloat(r))}`;break;case"bsc":if("BNB"===n)t=`ethereum:${e}@56?value=${m(r)}`;else{const o=u(n,"bsc");t=o?`ethereum:${o}/transfer?address=${e}&uint256=${h(r,n)}@56`:e}break;default:if("ETH"===n)t=`ethereum:${e}@1?value=${m(r)}`;else{const o=u(n,"ethereum");t=o?`ethereum:${o}/transfer?address=${e}&uint256=${h(r,n)}`:e}}i(t),d(null)}catch(t){console.error("Error generating QR code:",t),d("Error generating payment QR code")}else d("No wallet address configured for this network")}),[e,r,n,o]);const u=(e,t)=>{var r;return(null==(r={ethereum:{USDT:"0xdAC17F958D2ee523a2206206994597C13D831ec7",USDC:"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"},bsc:{USDT:"0x55d398326f99059fF775485246999027B3197955",USDC:"0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d"},tron:{USDT:"TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t",USDC:"TEkxiTehnzSmSe2XqrBj4w32RUN966rdz8"}}[t])?void 0:r[e])||""},h=(e,t)=>{const r="USDT"===t||"USDC"===t?6:18;return Math.floor(parseFloat(e)*Math.pow(10,r)).toString()},m=e=>Math.floor(1e18*parseFloat(e)).toString(),g=e=>({ethereum:"Ethereum",bsc:"BSC",tron:"Tron",algorand:"Algorand"}[e]||e);return G.jsxs("div",{className:"flex flex-col items-center",children:[c?G.jsxs("div",{className:"p-4 rounded-lg bg-red-100 mb-3 text-red-700 text-center",children:[G.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:G.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"})}),G.jsx("p",{className:"font-medium",children:c})]}):G.jsx("div",{className:"p-4 rounded-lg bg-white mb-3 shadow-sm border",children:l&&G.jsx(we,{value:l,size:a,bgColor:"dark"===s?"#374151":"#FFFFFF",fgColor:"dark"===s?"#FFFFFF":"#000000",level:"H",includeMargin:!0})}),G.jsxs("div",{className:"text-center text-sm text-gray-700 mb-4",children:[G.jsxs("p",{className:"font-semibold text-gray-800 flex items-center justify-center",children:[G.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:G.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]}),G.jsxs("p",{className:"text-xs text-gray-500 mt-1",children:["Scan with your ",g(o)," wallet app"]})]}),G.jsxs("div",{className:"w-full mb-4 p-3 bg-gray-50 rounded-lg",children:[G.jsxs("div",{className:"flex justify-between items-center",children:[G.jsx("span",{className:"text-sm font-medium text-gray-700",children:"Amount to Pay:"}),G.jsxs("span",{className:"text-lg font-bold text-[#7042D2]",children:[r," ",n]})]}),G.jsxs("div",{className:"flex justify-between items-center mt-1",children:[G.jsx("span",{className:"text-xs text-gray-500",children:"Network:"}),G.jsx("span",{className:"text-xs font-medium text-gray-700",children:g(o)})]})]}),!c&&G.jsxs("div",{className:"w-full mb-4",children:[G.jsx("p",{className:"text-xs text-gray-500 mb-1 text-center",children:"Or copy wallet address:"}),G.jsx("div",{className:"text-xs font-mono p-2 rounded bg-gray-100 text-gray-700 break-all text-center select-all cursor-pointer border",onClick:()=>{var t;return null==(t=navigator.clipboard)?void 0:t.writeText(e)},title:"Click to copy",children:e})]}),G.jsx("div",{className:"w-full",children:G.jsxs("div",{className:"p-3 rounded bg-blue-50 border border-blue-200",children:[G.jsxs("h4",{className:"text-sm font-medium mb-2 text-blue-800 flex items-center",children:[G.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:G.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"]}),G.jsxs("ol",{className:"text-xs space-y-1 text-blue-700",children:[G.jsxs("li",{children:["1. Open your crypto wallet app (",(w=o,{ethereum:["MetaMask","Trust Wallet","Coinbase Wallet"],bsc:["MetaMask","Trust Wallet","SafePal"],tron:["TronLink","Trust Wallet"],algorand:["Pera Wallet","MyAlgo Wallet"]}[w]||["MetaMask","Trust Wallet"]).join(", "),")"]}),G.jsx("li",{children:"2. Scan the QR code above or copy the wallet address"}),G.jsxs("li",{children:["3. Send exactly ",G.jsxs("strong",{children:[r," ",n]})," on ",g(o)," network"]}),G.jsx("li",{children:'4. Click "I have sent the payment" button below after sending'})]}),G.jsx("div",{className:"mt-3 p-2 bg-yellow-50 border border-yellow-200 rounded",children:G.jsxs("p",{className:"text-xs text-yellow-800",children:[G.jsx("strong",{children:"Important:"})," Make sure you're sending on the correct network (",g(o),") and using the exact amount shown above."]})})]})})]});var w},fe=({status:e,message:t,theme:r="light"})=>G.jsxs("div",{className:"flex flex-col items-center justify-center py-6",children:[G.jsx("div",{className:"mb-4",children:(()=>{switch(e){case"processing":return G.jsx("div",{className:"animate-spin rounded-full h-12 w-12 border-4 border-t-blue-500 border-blue-500/20"});case"success":return G.jsx("div",{className:"rounded-full h-12 w-12 bg-green-100 flex items-center justify-center",children:G.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:G.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5 13l4 4L19 7"})})});case"error":return G.jsx("div",{className:"rounded-full h-12 w-12 bg-red-100 flex items-center justify-center",children:G.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:G.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})})});default:return null}})()}),G.jsx("h3",{className:"text-xl font-bold mb-2 "+("dark"===r?"text-white":"text-gray-900"),children:(()=>{switch(e){case"processing":return"Processing Payment";case"success":return"Payment Successful";case"error":return"Payment Failed";default:return"Unknown Status"}})()}),G.jsx("p",{className:`text-center ${(()=>{switch(e){case"processing":return"dark"===r?"text-blue-300":"text-blue-600";case"success":return"dark"===r?"text-green-300":"text-green-600";case"error":return"dark"===r?"text-red-300":"text-red-600";default:return"dark"===r?"text-gray-300":"text-gray-600"}})()}`,children:t}),"processing"===e&&G.jsx("div",{className:"mt-4 text-xs "+("dark"===r?"text-gray-400":"text-gray-500"),children:"This may take a few moments. Please do not close this window."}),"success"===e&&G.jsx("div",{className:"mt-4 p-2 rounded "+("dark"===r?"bg-gray-700":"bg-gray-100"),children:G.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."})})]}),ye=({onSelect:e,selected:r,theme:n="light",supportedNetworks:o=[]})=>{const[s,a]=t.useState(u.ETHEREUM),[l,i]=t.useState({}),[c,d]=t.useState(!1);t.useEffect((()=>{i(w())}),[]);const m=[{id:u.ETHEREUM,name:"Ethereum",description:"ERC-20 tokens"},{id:u.BSC,name:"BSC (Binance Smart Chain)",description:"BEP-20 tokens"},{id:u.TRON,name:"Tron",description:"TRC-20 tokens"},{id:u.ALGORAND,name:"Algorand",description:"ASA tokens"}],p=(e=>{const t=[];switch(e){case u.ETHEREUM:t.push({id:"USDT",name:"USDT",description:"Tether USD",logo:"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSj0euZAOXsLTJFQxgiKzlX7z8xbfBk-7kmJA&s",network:u.ETHEREUM},{id:"USDC",name:"USDC",description:"USD Coin",logo:"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ43MuDqq54iD1ZCRL_uthAPkfwSSL-J5qI_Q&s",network:u.ETHEREUM},{id:"PYUSD",name:"PYUSD",description:"PayPal USD",logo:"https://s2.coinmarketcap.com/static/img/coins/64x64/28492.png",network:u.ETHEREUM},{id:"FRAX",name:"FRAX",description:"Frax",logo:"https://s2.coinmarketcap.com/static/img/coins/64x64/6952.png",network:u.ETHEREUM},{id:"USDP",name:"USDP",description:"Pax Dollar",logo:"https://s2.coinmarketcap.com/static/img/coins/64x64/6662.png",network:u.ETHEREUM},{id:"DAI",name:"DAI",description:"Dai Stablecoin",logo:"https://s2.coinmarketcap.com/static/img/coins/64x64/4943.png",network:u.ETHEREUM},{id:"ETH",name:"ETH",description:"Ethereum",logo:"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTcyJyRKN0dRJWVZqoLzYgkRHdJsxKGq8nHUw&s",network:u.ETHEREUM});break;case u.BSC:t.push({id:"USDT",name:"USDT",description:"Tether USD",logo:"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSj0euZAOXsLTJFQxgiKzlX7z8xbfBk-7kmJA&s",network:u.BSC},{id:"USDC",name:"USDC",description:"USD Coin",logo:"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ43MuDqq54iD1ZCRL_uthAPkfwSSL-J5qI_Q&s",network:u.BSC},{id:"BUSD",name:"BUSD",description:"Binance USD",logo:"https://s2.coinmarketcap.com/static/img/coins/64x64/4687.png",network:u.BSC},{id:"FRAX",name:"FRAX",description:"Frax",logo:"https://s2.coinmarketcap.com/static/img/coins/64x64/6952.png",network:u.BSC},{id:"BNB",name:"BNB",description:"Binance Coin",logo:"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRHSjyW2sSnBhwztCwVW97i1BtV40g7heMMxg&s",network:u.BSC});break;case u.TRON:t.push({id:"USDT",name:"USDT",description:"Tether USD",logo:"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSj0euZAOXsLTJFQxgiKzlX7z8xbfBk-7kmJA&s",network:u.TRON},{id:"USDC",name:"USDC",description:"USD Coin",logo:"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ43MuDqq54iD1ZCRL_uthAPkfwSSL-J5qI_Q&s",network:u.TRON},{id:"USDJ",name:"USDJ",description:"JUST Stablecoin",logo:"https://s2.coinmarketcap.com/static/img/coins/64x64/5446.png",network:u.TRON},{id:"TRX",name:"TRX",description:"Tron",logo:"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQKLpLNsGRHbZfCUXAjZLPSp_YFZvX5dMnAoA&s",network:u.TRON});break;case u.ALGORAND:t.push({id:"USDC",name:"USDC",description:"USD Coin",logo:"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ43MuDqq54iD1ZCRL_uthAPkfwSSL-J5qI_Q&s",network:u.ALGORAND},{id:"USDT",name:"USDT",description:"Tether USD",logo:"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSj0euZAOXsLTJFQxgiKzlX7z8xbfBk-7kmJA&s",network:u.ALGORAND},{id:"ALGO",name:"ALGO",description:"Algorand",logo:"https://s2.coinmarketcap.com/static/img/coins/64x64/4030.png",network:u.ALGORAND})}return t})(s),f=c?p:p.slice(0,4);function y(e){switch(e){case u.ETHEREUM:case u.BSC:return h.METAMASK;case u.TRON:return h.TRONLINK;case u.ALGORAND:return h.LUTE;default:return h.METAMASK}}return G.jsxs("div",{children:[G.jsx("h3",{className:"text-lg font-medium mb-4 "+("dark"===n?"text-white":"text-gray-800"),children:"Select Payment Method"}),G.jsxs("div",{className:"mb-6",children:[G.jsx("label",{className:"block text-sm font-medium mb-2 "+("dark"===n?"text-white":"text-gray-700"),children:"Blockchain Network"}),G.jsx("select",{value:s,onChange:t=>{return n=t.target.value,a(n),d(!1),void((null==r?void 0:r.network)!==n&&e(null));var n},className:`w-full p-3 rounded-lg border transition-colors ${"dark"===n?"bg-gray-700 border-gray-600 text-white focus:border-[#7042D2]":"bg-white border-gray-300 text-gray-900 focus:border-[#7042D2]"} focus:outline-none focus:ring-2 focus:ring-[#7042D2] focus:ring-opacity-50`,children:m.filter((e=>0===o.length||o.includes(e.id))).map((e=>G.jsxs("option",{value:e.id,children:[e.name," - ",e.description]},e.id)))})]}),G.jsxs("div",{className:"mb-4",children:[G.jsx("label",{className:"block text-sm font-medium mb-3 "+("dark"===n?"text-white":"text-gray-700"),children:"Choose Cryptocurrency"}),G.jsx("div",{className:"grid grid-cols-2 gap-3 mb-4",children:f.map((t=>G.jsx("button",{onClick:()=>(t=>{var r;e({currency:t.id,network:s,tokenConfig:null==(r=g[t.id])?void 0:r[s],method:t})})(t),className:"p-4 rounded-lg transition-all duration-200 border-2 "+((null==r?void 0:r.currency)===t.id&&(null==r?void 0:r.network)===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:G.jsxs("div",{className:"flex flex-col items-center text-center",children:[G.jsx("div",{className:"flex-shrink-0 h-10 w-10 bg-white rounded-full flex items-center justify-center mb-2 shadow-sm",children:G.jsx("img",{src:t.logo,alt:t.name,className:"h-6 w-6"})}),G.jsxs("div",{children:[G.jsx("h4",{className:"font-medium text-sm "+("dark"===n?"text-white":"text-gray-900"),children:t.name}),G.jsx("p",{className:"text-xs "+("dark"===n?"text-gray-300":"text-gray-500"),children:t.description})]}),(null==r?void 0:r.currency)===t.id&&(null==r?void 0:r.network)===s&&G.jsx("div",{className:"mt-2",children:G.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-4 w-4 text-[#7042D2]",viewBox:"0 0 20 20",fill:"currentColor",children:G.jsx("path",{fillRule:"evenodd",d:"M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z",clipRule:"evenodd"})})})]})},`${t.id}-${t.network}`)))}),p.length>4&&G.jsx("button",{onClick:()=>d(!c),className:"w-full py-2 px-4 rounded-lg text-sm font-medium transition-colors "+("dark"===n?"bg-gray-700 text-gray-300 hover:bg-gray-600":"bg-gray-100 text-gray-600 hover:bg-gray-200"),children:c?"Show Less":`Show More (${p.length-4} more)`})]}),G.jsx("div",{className:"p-3 rounded-lg text-sm "+("dark"===n?"bg-gray-800 text-gray-300":"bg-gray-50 text-gray-600"),children:G.jsxs("div",{className:"flex items-center",children:[G.jsx("div",{className:"w-2 h-2 rounded-full mr-2 "+(l[y(s)]?"bg-green-500":"bg-red-500")}),G.jsx("span",{className:"text-xs",children:function(e){const t=y(e),r=l[t],n={[h.METAMASK]:"MetaMask",[h.TRONLINK]:"TronLink",[h.TRUST_WALLET]:"Trust Wallet",[h.LUTE]:"Lute Wallet"};return r?`${n[t]} detected - Ready to pay`:`${n[t]} required - Please install to continue`}(s)})]})})]})},xe=({isOpen:e,onClose:r,payment:n,paymentStatus:o,selectedPaymentMethod:s,onPaymentMethodSelect:a,onPayment:l,onBack:i,error:c,theme:d="light",merchantName:u,transactionHash:m,walletConnection:g,onConnectWallet:w,testMode:p=!1,supportedNetworks:f=[],availableWallets:y={},supportedWallets:x=[],step:E="select-currency",merchantWalletAddresses:b={},debug:N=!1})=>{const[v,k]=t.useState("wallet"),T=e=>({ethereum:"Ethereum",bsc:"BSC",tron:"Tron",algorand:"Algorand"}[e]||e),A=e=>({[h.METAMASK]:"MetaMask",[h.TRONLINK]:"TronLink",[h.TRUST_WALLET]:"Trust Wallet",[h.LUTE]:"Lute Wallet"}[e]||e),S=e=>({[h.METAMASK]:"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcT3ymr3UNKopfI0NmUY95Dr-0589vG-91KuAA&s",[h.TRONLINK]:"https://www.tronlink.org/images/logo.png",[h.TRUST_WALLET]:"https://trustwallet.com/assets/images/trust_logotype.svg",[h.LUTE]:"https://lute.app/logo.png"}[e]||"");return e?G.jsx("div",{className:"fixed inset-0 z-50 overflow-y-auto bg-black/50",children:G.jsx("div",{className:"flex min-h-screen items-center justify-center p-4",children:G.jsxs("div",{className:"relative p-6 w-full max-w-md mx-auto rounded-lg shadow-xl bg-white text-gray-800",children:[G.jsxs("div",{className:"flex justify-between items-center mb-6 bg-[#F1ECFB] p-3 rounded-xl",children:[G.jsx("div",{className:"flex items-center",children:G.jsx("h2",{className:"text-xl font-bold text-gray-900",children:G.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+QrJITl89+09cwH0LakOkS3OEPWuS42yrHiQiydjX8Q9IqVw6kjVdh1bI1FphPoV1RTGvpFryklVulTpJnD+jrX/aK9NeET5YR7Z+7lC+Jr0sD9gvQeeoF2/PjrXIfI9orxqpfEboxmkGFyn6yzsNnj664MiAH9rBLkKlJa6IU+4LsnyNyu7t7/n6rxUBvgAxj9jizWZSMNJdAd1lgjMH6IPA5gBGgXOX7SUk9hrbsK/JFpcM3eUruq47NIvd3xIEVyyOp/QDu9Z/nJJKL0K4ys6RYAlcZaItAdcabGh0kSHk3R/rIsXi4nO39p8FBU3paa5NclEA9V1oMeokoo0xBDdMLTt1oHZPWhGv0NdLr9rv8YoxmfiuY8E9aDzgpWle+RzUiu7T8pQpgq0V0dkmJmVGL6oPTu1zfJA+ZG2m3I7CZp0M+eYmF5otCyji821xlrPZqI378BTnqr0qz2mAXjv6eBYJdKcNG3R4A1q5Ejb/n+oDia128QemoTRBtLKy/fphFOH+jJEe4JcoNovaa+T2uuIwLXGMH1PbUqccyNbFgLfWpvq6yqyZA3p0U5f2tfU1iG5IcflAGavzE00LYia+o9O3T9smfDIoXpJQI5gcvLk1r9j5wbOOV/bKfz7fX0Ue4LufedIPPft3ie/zgThfUWqfx2Ql3hk1T1D3kc9g8T5iqwGQqWr4fG3Ea3w2i73N+QWGLG8RGHg+jCFMWzz4zf2NyQnDcgJXWeE1SBRaDkOKuMLFXqQr9EMfj8pjGab19yHa5ATBAwZUlTHI6Ql+QpSwi5eYmt8f0YjsvH/j39r08lNgVS0YGX0kJuIStPuIczAUd18t95F0yoQ8Hu/E6wWVdA0vr7l/Bs0Y8Dy5y3a+Izw3Ljm90lTpK+/3BhP84M9q0kGaoqa2s1dv/GrbKqf7/7zO54PguVTtF9Su6tTbn9JFMv7JqQobKscCcKuhDo5TZDoZownLD8PlPswD8iawthkOYly49ztb+7jcrEk8tIPZT3bqbV9DhS5hGKRUAa7uvhilnu+nxGcCPdYDYLlJbrhVyZDYDvQ9+TvsBqEc0zay51KScm4hDph1y5p15IfypBpj8hEKu29dhH04lOVPw1EHzwnNmGTESTWwyYWG5vA97qPCcpjnaCs9U5Z/dL0WfihlNFNEQYmGkAbY8bwyjLSFAO7n/ecg8kJtCn77aBj/Z9YXmI7sKkXjMuiY25L5VOcQHVKTd1MTJpHbbN8JaMb9ax/7jdTsvwJVsOM5QW69SVheYntAO8XEYH2VaMV0ismi9uIpJVye8rFFGw8YqV5RlYLNUBvqWzyrWhCCh4h2t7ZN0BhF8w8ctou/0cok2+Odgb2c0Bi9fFpQopyP/OVMp/uvvCG8TJqIATtMc8o+uD18Ojh7uzdt1b7PMMkGPXZFr6HRw+4ifxU5wrl/Sq+TKaBP22QQ+fHrKzr6u57w7cHJ9AMqtdEvnNPm8TJS3jGg/xQHz3OTao8VcpQOQkjaSIsFUPV9kyWZZNW/qg4O9DBebS1szpoq4O/heRVpvsRrG4Cs8oZO2V0TJ2eoDpVTeHfN6NrXKDqWpBo5+d5TnADOl/pDQL1875N7O9jTd0UPC6uer6CyM2QRsk3cL2BcTkWT+RgnKnzVxSqQnt6tv6Fyp8tZRzdf1VkVRolGk9u/7vqw6A3KbTjL+1vH367iAbk0NZLEF5W59OiQPgNJw+8+0Z2DV9JUQ8uL2+ToHzfEmWnJ72w1x55VC9f0vdR7Of1PfVCTtQxwubBITwxXCW3gUOmfpBMeTSmiXU6QRwnVtSJzke9q6Lu4oOdMsd6Fbka6G0KkVEgbGQTQdztkxThuG8a6ARhMlG7bZvuctB9+cZHwH5DCaOFEvjJdIQwuAbMMUMgINAfD8UD41yo6dHaRgNb0reSzK+aFvNwYU1QIpWJOliHVGNU96DqkML/Bk3RLf6b6h2hvWf9n8IY9XucPhARDxva+FwIhMtQg0rEJiNLGSZI7lyvDMsXhbG1LKLeMvTBTodH9vN0IhVWnP6mNg1gDOaEnc+N+DxsIwQJQ6qBlcOnAZJDRPyMeiJ9QflhSHbuJyazCVze3JE79ZRzpCj6RY7pBH6NRNe5QfvVqgxcy4uIF5hPzCO/JlG2k44pP36g8Ip+qYyM78yZyxdPr1w3g/5yJoqv9apSGfuTX95uYgoRzrHE6hAbkrNtcG3LOVZzhnLbboqaT8aqU17mnermS+KY6Yzv5QBP7LOoOB64WR2MRxGgWsvhakNed+mkbZCzbSACSVR9Vm3BXQWEz3UNqoSquhCmJtTXbg4vjXDQFDjLtZD+pUjPQtA+F0021eRu/40NKz7ADtuMkB8urWtU/Yzq9u1UaQ+pow0WTzdV77hDlGgZgmuQLdT8HBmi1Hjfl3HnO2wbEhT2qWDniAeNIdD+z6jqQlXcuHL6MMHFYpEuDfYo2sSUtsPzQiDs6CQySTQgRldkWU6UKf+KRROxOaR4h5cF0kzk+pm2qdydUJF2D8yXH3NyPP21tf9dbYdOkDAOU3JFtF6R76EraO9PrfJC39hZv5NidG835b085Eb3qi4G/A2inrQKnVgMFAAAAABJRU5ErkJggg==",className:"w-32",alt:"Coinley Logo"})})}),G.jsx("button",{onClick:r,className:"text-gray-500 hover:text-gray-700 focus:outline-none",children:G.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-6 w-6",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:G.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),G.jsxs("div",{className:"mb-6 bg-[#F1ECFB] p-3 rounded-xl",children:[n&&G.jsxs("div",{className:"mb-6 p-4 rounded-lg",children:[G.jsxs("p",{className:"text-lg text-gray-800 font-semibold",children:["PAY: ",u]}),G.jsxs("div",{className:"flex justify-between items-center mt-2 bg-gray-100 px-3 rounded-lg",children:[G.jsx("span",{className:"font-medium text-gray-700",children:"Amount:"}),G.jsxs("span",{className:"font-bold text-xl text-[#7042D2]",children:["$",(R=n.totalAmount||n.amount,parseFloat(R).toFixed(2))]})]}),G.jsx("div",{className:"text-xs mt-1 text-right",children:G.jsxs("span",{className:"text-gray-500",children:["Payment ID: ",n.id?n.id.slice(0,8):"","..."]})})]}),N&&G.jsx("div",{className:"mb-2 text-right",children:G.jsx("button",{onClick:()=>{console.log("=== DEBUG INFO ==="),console.log("Current step:",E),console.log("Payment method:",s),console.log("Wallet connection:",g),j()},className:"text-xs bg-gray-200 p-1 rounded",children:"Debug"})}),"select-currency"===E&&G.jsxs("div",{children:[G.jsx(ye,{onSelect:a,selected:s,theme:d,supportedNetworks:f}),s&&G.jsx("div",{className:"mt-6",children:G.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 ",T(s.network)]})})]}),"confirm"===E&&s&&n&&G.jsxs("div",{children:[G.jsxs("div",{className:"p-4 rounded-lg mb-4 bg-gray-100",children:[G.jsx("h3",{className:"text-lg font-medium mb-2 text-gray-800",children:"Payment Details"}),G.jsxs("div",{className:"space-y-2",children:[G.jsxs("div",{className:"flex justify-between",children:[G.jsx("span",{className:"text-[#7042D2] font-semibold",children:"Currency:"}),G.jsx("span",{className:"font-medium",children:s.currency})]}),G.jsxs("div",{className:"flex justify-between",children:[G.jsx("span",{className:"text-[#7042D2] font-semibold",children:"Network:"}),G.jsx("span",{className:"font-medium",children:T(s.network)})]}),G.jsxs("div",{className:"flex justify-between",children:[G.jsx("span",{className:"text-[#7042D2] font-semibold",children:"Fee:"}),G.jsx("span",{className:"font-medium",children:"1.75%"})]})]})]}),G.jsx("div",{className:"mb-4",children:G.jsxs("div",{className:"flex border-b border-gray-200",children:[G.jsx("button",{onClick:()=>k("wallet"),className:"py-2 px-4 text-sm font-medium "+("wallet"===v?"border-b-2 border-[#7042D2] text-[#7042D2]":"text-gray-500 hover:text-gray-700"),children:"Connect Wallet"}),G.jsx("button",{onClick:()=>k("qrcode"),className:"py-2 px-4 text-sm font-medium "+("qrcode"===v?"border-b-2 border-[#7042D2] text-[#7042D2]":"text-gray-500 hover:text-gray-700"),children:"QR Code"})]})}),p?G.jsx("div",{className:"p-4 rounded-lg mb-4 bg-blue-50",children:G.jsxs("div",{className:"flex items-center",children:[G.jsx("div",{className:"bg-[#7042D2] rounded-full p-2 mr-3",children:G.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:G.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 10V3L4 14h7v7l9-11h-7z"})})}),G.jsxs("div",{children:[G.jsx("h3",{className:"font-medium text-gray-800",children:"Test Mode Payment"}),G.jsx("p",{className:"text-sm text-gray-600",children:'Click "Pay Now" to simulate a successful payment'})]})]})}):"qrcode"===v?G.jsx("div",{className:"mb-4",children:G.jsx(pe,{walletAddress:(()=>{if(!s)return"No network selected";const e=b[s.network];return e||((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:d})}):G.jsxs("div",{className:"space-y-3 mb-4",children:[0===x.length?G.jsx("div",{className:"p-4 rounded-lg bg-yellow-50",children:G.jsxs("div",{className:"flex items-center",children:[G.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:G.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"})}),G.jsxs("div",{children:[G.jsx("h3",{className:"font-medium text-gray-800",children:"No Compatible Wallets"}),G.jsxs("p",{className:"text-sm text-gray-600",children:["No wallets detected for ",T(s.network)," network"]})]})]})}):x.map((e=>G.jsx("div",{className:"p-4 rounded-lg bg-blue-50",children:G.jsxs("div",{className:"flex items-center justify-between",children:[G.jsxs("div",{className:"flex items-center",children:[G.jsx("img",{src:S(e),alt:A(e),className:"w-8 h-8 mr-3",onError:e=>{e.target.style.display="none"}}),G.jsxs("div",{children:[G.jsx("h3",{className:"font-medium text-gray-800",children:A(e)}),G.jsxs("p",{className:"text-sm text-gray-600",children:["Pay with ",A(e)]})]})]}),(null==g?void 0:g.walletType)===e?G.jsxs("div",{className:"flex items-center space-x-2",children:[G.jsx("div",{className:"w-2 h-2 bg-green-500 rounded-full"}),G.jsx("span",{className:"text-sm text-green-600",children:"Connected"})]}):G.jsx("button",{onClick:()=>{console.log("Connect wallet button clicked for:",e),w(e)},className:"py-2 px-4 bg-[#7042D2] hover:bg-[#7042D2] text-white font-medium rounded-md text-sm",children:"Connect"})]})},e))),G.jsx("div",{className:"space-y-2",children:Object.entries(y).filter((([e,t])=>!t)).map((([e])=>G.jsx("div",{className:"p-3 rounded-lg bg-gray-50",children:G.jsxs("div",{className:"flex items-center justify-between",children:[G.jsxs("span",{className:"text-sm text-gray-600",children:[A(e)," not detected"]}),G.jsx("a",{href:M(e),target:"_blank",rel:"noopener noreferrer",className:"text-sm text-[#7042D2] hover:underline",children:"Install"})]})},e)))})]}),c&&G.jsx("div",{className:"p-3 rounded-lg bg-red-50 mb-4 text-red-600 text-sm",children:c}),G.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[G.jsx("button",{type:"button",onClick:i,className:"w-full py-2 px-4 bg-gray-200 hover:bg-gray-300 text-[#7042D2] font-medium rounded-md",children:"Back"}),G.jsx("button",{type:"button",onClick:()=>l("qrcode"===v),className:"w-full py-2 px-4 bg-[#7042D2] hover:bg-[#7042D2] text-white font-medium rounded-md",disabled:!p&&"wallet"===v&&!g,children:"qrcode"===v?"I have sent the payment":"Pay Now"})]})]}),"processing"===E&&G.jsx(fe,{status:"processing",theme:d,message:"Processing your payment..."}),"success"===E&&G.jsxs("div",{children:[G.jsx(fe,{status:"success",theme:d,message:"Payment successful!"}),m&&G.jsxs("div",{className:"mt-4 p-3 rounded-lg bg-gray-100",children:[G.jsx("p",{className:"text-xs text-gray-600 mb-1",children:"Transaction Hash:"}),G.jsx("p",{className:"text-sm font-mono break-all text-gray-800",children:(C=m,C?C.length<=14?C:`${C.slice(0,8)}...${C.slice(-6)}`:"")}),s&&G.jsx("a",{href:`${Ee(s.network)}/${be(s.network)}/${m}`,target:"_blank",rel:"noopener noreferrer",className:"text-xs text-[#7042D2] mt-2 inline-block",children:"View on Explorer →"})]})]}),"error"===E&&G.jsxs("div",{children:[G.jsx(fe,{status:"error",theme:d,message:c||"An error occurred while processing your payment."}),G.jsx("button",{type:"button",onClick:i,className:"mt-4 w-full py-2 px-4 bg-gray-200 hover:bg-gray-300 text-gray-800 font-medium rounded-md",children:"Try Again"})]})]}),G.jsx("div",{className:"text-center text-xs text-gray-500",children:G.jsxs("p",{children:["Powered by ",G.jsx("span",{className:"text-[#7042D2]",children:"Coinley"})," - Secure Cryptocurrency Payments"]})})]})})}):null;var C,R},Ee=e=>({ethereum:"https://etherscan.io",bsc:"https://bscscan.com",tron:"https://tronscan.org",algorand:"https://algoexplorer.io"}[e]||"https://etherscan.io"),be=e=>({ethereum:"tx",bsc:"tx",tron:"transaction",algorand:"tx"}[e]||"tx"),Ne=t.forwardRef((({apiKey:e,apiSecret:r,apiUrl:n,customerEmail:o,merchantName:s="Merchant",merchantWalletAddresses:a={},onSuccess:l,onError:i,onClose:m,theme:g,autoOpen:w=!1,debug:y=!1,testMode:E=!1,supportedNetworks:b=[],preferredNetwork:N=u.ETHEREUM,preferredWallet:v=h.METAMASK},k)=>{const A=$(),{theme:S}=t.useContext(Q),[C,M]=t.useState(w),[R,L]=t.useState(null),[P,O]=t.useState("idle"),[W,I]=t.useState(null),[F,B]=t.useState(null),[z,H]=t.useState(null),[q,K]=t.useState(null),[_,V]=t.useState({}),[J,Y]=t.useState("select-currency");e||null==A||A.apiKey,r||null==A||A.apiSecret,n||null==A||A.apiUrl;const X=g||S,Z=y||(null==A?void 0:A.debug),ee=b.length>0?b:[u.ETHEREUM,u.BSC,u.TRON,u.ALGORAND];t.useImperativeHandle(k,(()=>({open:e=>{re(e)},close:()=>{ne()},getPayment:()=>R,getWalletConnection:()=>q,debugWallets:()=>j()})));const te=(e,t)=>{Z&&console.log(`[Coinley SDK] ${e}`,t)};t.useEffect((()=>{if("undefined"!=typeof window){(()=>d(this,null,(function*(){const e=yield p(3,1e3);V(e),te("Available wallets detected:",e)})))()}}),[Z]);const re=e=>d(this,null,(function*(){if(!e||!e.amount)return B("Payment amount is required"),void(i&&i(new Error("Payment amount is required")));O("loading"),M(!0),Y("select-currency");try{te("Creating payment with details:",e);const t=yield D({amount:e.amount,currency:e.currency||"USDT",network:e.network||N,customerEmail:e.customerEmail||o,callbackUrl:e.callbackUrl,metadata:e.metadata||{},merchantWalletAddresses:c(c({},a),e.merchantWalletAddresses)});te("Payment created:",t),L(t.payment),O("idle"),B(null),te("Payment created and state updated")}catch(t){te("Error creating payment:",t),B(t.message||"Failed to create payment"),O("error"),i&&i(t)}})),ne=()=>{M(!1),H(null),K(null),I(null),Y("select-currency"),m&&m()};return G.jsx(G.Fragment,{children:C&&G.jsx(xe,{isOpen:C,onClose:ne,payment:R,paymentStatus:P,selectedPaymentMethod:W,onPaymentMethodSelect:e=>{console.log("=== PAYMENT METHOD SELECTION DEBUG ==="),console.log("1. Payment method selected:",e),console.log("2. Current step before:",J),te("Payment method selected:",e),I(e),Y("confirm"),console.log("3. Step should now be: confirm"),console.log("=== END PAYMENT METHOD SELECTION DEBUG ===")},onPayment:()=>d(this,null,(function*(){var e,t;if(R&&W)if(q||E){te("Starting payment process..."),O("loading"),H(null),Y("processing");try{let r;if(E)te("Test mode: Generating mock transaction..."),r=`test_${Date.now().toString(16)}_${Math.random().toString(16).substring(2,10)}`;else{const n=a[W.network];if(!n)throw new Error(`No merchant wallet address configured for ${W.network}`);te("Sending transaction through wallet..."),r=yield T(q,{to:n,amount:R.amount,tokenAddress:null==(e=W.tokenConfig)?void 0:e.address,tokenDecimals:null==(t=W.tokenConfig)?void 0:t.decimals,currency:W.currency,network:W.network})}te("Transaction hash:",r),H(r),te("Processing payment with backend...");const n=yield U({paymentId:R.id,transactionHash:r,network:W.network,currency:W.currency,senderAddress:null==q?void 0:q.address});te("Payment processed successfully:",n),O("success"),Y("success"),l&&(te("Calling onSuccess callback..."),l(R.id,r,{network:W.network,currency:W.currency,amount:R.amount}))}catch(r){te("Payment error:",r),B(r.message||"Failed to process payment"),O("error"),Y("error"),i&&i(r)}}else B("Please connect your wallet first");else B("Missing payment information")})),onBack:()=>{"confirm"===J?(Y("select-currency"),K(null)):"error"===J&&Y("confirm")},error:F,theme:X,merchantName:s,transactionHash:z,walletConnection:q,onConnectWallet:e=>d(this,null,(function*(){if(console.log("=== WALLET CONNECTION DEBUG ==="),console.log("1. Wallet type requested:",e),console.log("2. Selected payment method:",W),console.log("3. Available wallets:",_),console.log("4. Current step:",J),!W)return console.error("No payment method selected"),void B("Please select a payment method first");try{console.log("5. Attempting to connect wallet..."),B(null),te("Connecting wallet:",{walletType:e,network:W.network});const t=yield x(e,W.network,2);K(t),B(null),console.log("6. Connection successful:",t),te("Wallet connected successfully:",t)}catch(t){console.error("7. Connection failed:",t),te("Wallet connection error:",t),B(t.message||"Failed to connect wallet")}console.log("=== END WALLET CONNECTION DEBUG ===")})),testMode:E,supportedNetworks:ee,availableWallets:_,supportedWallets:W?f(W.network):[],step:J,merchantWalletAddresses:a,debug:Z})})}));Ne.displayName="CoinleyCheckout";e.CoinleyCheckout=Ne,e.CoinleyModal=xe,e.CoinleyProvider=({apiKey:e,apiSecret:r,apiUrl:n="http://localhost:9000",merchantWalletAddress:o=null,merchantSolWalletAddress:s=null,debug:a=!1,children:l})=>{const[i,d]=t.useState(!1),[u,h]=t.useState(null),[m,g]=t.useState(null);t.useEffect((()=>{var t;if(e&&r)try{t={apiKey:e,apiSecret:r,apiUrl:n,merchantWalletAddress:o,merchantSolWalletAddress:s},R=c(c({},R),t),console.log("API initialized with:",{apiUrl:R.apiUrl,apiKey:R.apiKey?`${R.apiKey.substring(0,6)}...`:null,hasWalletAddresses:Object.keys(R.merchantWalletAddresses||{}).length>0}),d(!0),a&&console.log("Coinley SDK initialized with:",{apiKey:e,apiUrl:n,merchantWalletAddress:o?`${o.substring(0,6)}...${o.substring(o.length-4)}`:"Not provided",merchantSolWalletAddress:s?`${s.substring(0,6)}...${s.substring(s.length-4)}`:"Not provided"})}catch(l){h(l.message),a&&console.error("Coinley SDK initialization error:",l)}else h("API key and secret are required")}),[e,r,n,o,s,a]);const w={apiKey:e,apiSecret:r,apiUrl:n,merchantWalletAddress:o,merchantSolWalletAddress:s,isInitialized:i,error:u,debug:a,paymentData:m,storePaymentData:e=>(g(e),e)};return G.jsx(K.Provider,{value:w,children:l})},e.DEFAULT_CONFIG={apiUrl:"http://localhost:9000",debug:!1,testMode:!1,theme:"light",supportedNetworks:["ethereum","bsc","tron","algorand"]},e.NETWORK_CONFIG=m,e.NETWORK_TYPES=u,e.PaymentMethods=ye,e.PaymentStatus=fe,e.QRCode=pe,e.TOKEN_CONFIG=g,e.ThemeProvider=({initialTheme:e="light",children:r})=>{const[n,o]=t.useState(e);return t.useEffect((()=>{document.documentElement.classList.remove("light","dark"),document.documentElement.classList.add(n)}),[n]),G.jsx(Q.Provider,{value:{theme:n,setTheme:o,toggleTheme:()=>{o((e=>"light"===e?"dark":"light"))}},children:r})},e.WALLET_TYPES=h,e.connectWallet=x,e.createPayment=D,e.detectWallets=w,e.generateMockTransactionHash=(e="ethereum")=>`${{ethereum:"0x",bsc:"0x",tron:"",algorand:""}[e]||"0x"}${Array.from({length:64},(()=>Math.floor(16*Math.random()).toString(16))).join("")}`,e.getMerchantProfile=()=>d(this,null,(function*(){try{const t=yield fetch(`${R.apiUrl}/api/merchants/profile`,{method:"GET",headers:L()});if(!t.ok){let r;try{r=yield t.json()}catch(e){throw new Error(`Failed to get merchant profile: ${t.status} ${t.statusText}`)}throw new Error(r.error||`Failed to get merchant profile: ${t.status}`)}const r=yield t.json();return r.merchant&&r.merchant.walletAddresses&&(R.merchantWalletAddresses=c(c({},R.merchantWalletAddresses),r.merchant.walletAddresses)),r}catch(t){throw console.error("Get merchant profile error:",t),t}})),e.getPayment=e=>d(this,null,(function*(){try{if(console.log("Getting payment:",e),!e)throw new Error("Payment ID is required");const r=yield fetch(`${R.apiUrl}/api/payments/${e}`,{method:"GET",headers:L()});if(!r.ok){let e;try{e=yield r.json()}catch(t){throw new Error(`Failed to get payment: ${r.status} ${r.statusText}`)}throw console.error("Error getting payment:",e),new Error(e.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}})),e.getSupportedNetworks=()=>d(this,null,(function*(){try{const t=yield fetch(`${R.apiUrl}/api/networks`,{method:"GET",headers:L()});if(!t.ok){let r;try{r=yield t.json()}catch(e){throw new Error(`Failed to get networks: ${t.status} ${t.statusText}`)}throw new Error(r.error||`Failed to get networks: ${t.status}`)}return yield t.json()}catch(t){throw console.error("Get supported networks error:",t),t}})),e.getSupportedWalletsForNetwork=f,e.getWalletInstallUrl=M,e.processPayment=U,e.sendTransaction=T,e.useCoinley=$,e.validateWalletAddress=(e,t)=>d(this,null,(function*(){try{const n=yield fetch(`${R.apiUrl}/api/wallets/validate`,{method:"POST",headers:L(),body:JSON.stringify({address:e,network:t})});if(!n.ok){let e;try{e=yield n.json()}catch(r){throw new Error(`Failed to validate address: ${n.status} ${n.statusText}`)}throw new Error(e.error||`Failed to validate address: ${n.status}`)}return yield n.json()}catch(n){throw console.error("Validate wallet address error:",n),n}})),Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})}));
|
7
7
|
//# sourceMappingURL=coinley-checkout.umd.js.map
|