cppay-sdk 0.0.2-beta.27 → 0.0.2-beta.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import { n as CHAIN_ICONS, r as TOKEN_ICONS, t as cppay_default } from "./cppay-BcCDwXlg.js";
1
+ import { n as CHAIN_ICONS, r as TOKEN_ICONS, t as cppay_default } from "./cppay-Dhqe5Hz_.js";
2
2
  export { CHAIN_ICONS, cppay_default as Cppay, TOKEN_ICONS };
@@ -0,0 +1 @@
1
+ var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n)),c=`._cppay-overlay{z-index:999;background-color:#00000080;justify-content:center;align-items:center;padding:1rem;display:flex;position:fixed;inset:0}._cppay-dialog{background-color:#fff;border-radius:1.5rem;flex-direction:column;width:100%;max-width:28rem;max-height:90vh;display:flex;overflow:hidden;box-shadow:0 20px 25px -5px #0000001a,0 10px 10px -5px #0000000a}._cppay-header{border-bottom:1px solid #e5e7eb;justify-content:space-between;align-items:center;padding:1rem 1.25rem;display:flex}._cppay-title{color:#111827;margin:0;font-size:1.25rem;font-weight:600}._cppay-close-btn{color:#9ca3af;cursor:pointer;background:0 0;border:none;padding:.25rem;transition:color .2s}._cppay-close-btn:hover:not(:disabled){color:#4b5563}._cppay-close-btn:disabled{opacity:.5;cursor:not-allowed}._cppay-close-btn svg{width:1.5rem;height:1.5rem}._cppay-content{flex:1;padding:1.25rem;overflow-y:auto}._cppay-section{margin-bottom:1rem}._cppay-section:last-child{margin-bottom:0}._cppay-label{color:#374151;margin-bottom:.5rem;font-size:.875rem;font-weight:500;display:block}._cppay-grid{grid-template-columns:repeat(2,1fr);gap:.75rem;display:grid}._cppay-select-btn{cursor:pointer;background:#fff;border:2px solid #e5e7eb;border-radius:.75rem;align-items:center;gap:.5rem;padding:.75rem;font-family:inherit;font-size:.875rem;transition:all .2s;display:flex}._cppay-select-btn:hover{border-color:#d1d5db}._cppay-select-btn._cppay-selected{background-color:#eff6ff;border-color:#2563eb}._cppay-select-btn img{border-radius:9999px;width:1.5rem;height:1.5rem}._cppay-select-btn span{font-weight:500}._cppay-price-box{background-color:#f9fafb;border-radius:1rem;padding:1rem}._cppay-price-row{justify-content:space-between;align-items:center;display:flex}._cppay-price-label{color:#4b5563;font-size:.875rem}._cppay-price-amount{text-align:right}._cppay-price-main{color:#111827;margin:0;font-size:1.25rem;font-weight:700}._cppay-price-sub{color:#6b7280;margin-top:.25rem;font-size:.875rem}._cppay-btn{cursor:pointer;border:none;border-radius:.75rem;width:100%;padding:.75rem;font-family:inherit;font-size:1rem;font-weight:500;transition:all .2s}._cppay-btn-primary{color:#fff;background-color:#2563eb}._cppay-btn-primary:hover:not(:disabled){background-color:#1d4ed8}._cppay-btn-primary:disabled{opacity:.5;cursor:not-allowed}._cppay-btn-secondary{color:#374151;background-color:#fff;border:1px solid #d1d5db}._cppay-btn-secondary:hover:not(:disabled){background-color:#f9fafb}._cppay-btn-secondary:disabled{opacity:.5;cursor:not-allowed}._cppay-btn-text{color:#6b7280;text-align:center;background:0 0;border:none;padding:.5rem;font-size:.875rem}._cppay-btn-text:hover:not(:disabled){color:#2563eb;background:0 0}._cppay-btn-text:disabled{opacity:.5;cursor:not-allowed}._cppay-btn-container{align-items:center;gap:.5rem;display:flex}._cppay-qr-container{justify-content:center;margin-bottom:1rem;display:flex}._cppay-qr-code{background:linear-gradient(135deg,#667eea 0%,#764ba2 100%);border-radius:1rem;padding:.75rem;box-shadow:0 4px 12px #667eea26}._cppay-qr-placeholder{background-color:#f3f4f6;border-radius:.75rem;justify-content:center;align-items:center;width:10rem;height:10rem;display:flex}._cppay-qr-placeholder span{color:#9ca3af;font-size:.875rem}._cppay-info-box{background-color:#f9fafb;border-radius:.75rem;margin-bottom:.625rem;padding:.875rem}._cppay-info-box:last-child{margin-bottom:0}._cppay-info-label{color:#4b5563;margin-bottom:.25rem;font-size:.875rem}._cppay-info-value{color:#111827;font-size:1.25rem;font-weight:700}._cppay-address-row{align-items:center;gap:.5rem;display:flex}._cppay-address-row code{text-overflow:ellipsis;white-space:nowrap;color:#111827;background:0 0;flex:1;font-family:monospace;font-size:.75rem;overflow:hidden}._cppay-copy-btn{color:#2563eb;cursor:pointer;background:0 0;border:none;justify-content:center;align-items:center;padding:.25rem;transition:color .2s;display:flex}._cppay-copy-btn:hover{color:#1d4ed8}._cppay-copy-btn svg{width:1.25rem;height:1.25rem}@keyframes _cppay-fadeIn{0%{opacity:0}to{opacity:1}}@keyframes _cppay-slideUp{0%{opacity:0;transform:translateY(1.25rem)}to{opacity:1;transform:translateY(0)}}._cppay-overlay{animation:.3s _cppay-fadeIn}._cppay-dialog{animation:.3s _cppay-slideUp}@media (max-width:640px){._cppay-dialog{margin:.5rem}._cppay-header,._cppay-content{padding:1rem}}`;function l(e){if(typeof document>`u`||document.getElementById(`_cppay-payment-dialog-style`))return;let t=document.createElement(`style`);t.id=`_cppay-payment-dialog-style`,t.textContent=e,document.head.appendChild(t)}Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return c}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return l}});
@@ -0,0 +1,7 @@
1
+ var payment_dialog_default = "._cppay-overlay{z-index:999;background-color:#00000080;justify-content:center;align-items:center;padding:1rem;display:flex;position:fixed;inset:0}._cppay-dialog{background-color:#fff;border-radius:1.5rem;flex-direction:column;width:100%;max-width:28rem;max-height:90vh;display:flex;overflow:hidden;box-shadow:0 20px 25px -5px #0000001a,0 10px 10px -5px #0000000a}._cppay-header{border-bottom:1px solid #e5e7eb;justify-content:space-between;align-items:center;padding:1rem 1.25rem;display:flex}._cppay-title{color:#111827;margin:0;font-size:1.25rem;font-weight:600}._cppay-close-btn{color:#9ca3af;cursor:pointer;background:0 0;border:none;padding:.25rem;transition:color .2s}._cppay-close-btn:hover:not(:disabled){color:#4b5563}._cppay-close-btn:disabled{opacity:.5;cursor:not-allowed}._cppay-close-btn svg{width:1.5rem;height:1.5rem}._cppay-content{flex:1;padding:1.25rem;overflow-y:auto}._cppay-section{margin-bottom:1rem}._cppay-section:last-child{margin-bottom:0}._cppay-label{color:#374151;margin-bottom:.5rem;font-size:.875rem;font-weight:500;display:block}._cppay-grid{grid-template-columns:repeat(2,1fr);gap:.75rem;display:grid}._cppay-select-btn{cursor:pointer;background:#fff;border:2px solid #e5e7eb;border-radius:.75rem;align-items:center;gap:.5rem;padding:.75rem;font-family:inherit;font-size:.875rem;transition:all .2s;display:flex}._cppay-select-btn:hover{border-color:#d1d5db}._cppay-select-btn._cppay-selected{background-color:#eff6ff;border-color:#2563eb}._cppay-select-btn img{border-radius:9999px;width:1.5rem;height:1.5rem}._cppay-select-btn span{font-weight:500}._cppay-price-box{background-color:#f9fafb;border-radius:1rem;padding:1rem}._cppay-price-row{justify-content:space-between;align-items:center;display:flex}._cppay-price-label{color:#4b5563;font-size:.875rem}._cppay-price-amount{text-align:right}._cppay-price-main{color:#111827;margin:0;font-size:1.25rem;font-weight:700}._cppay-price-sub{color:#6b7280;margin-top:.25rem;font-size:.875rem}._cppay-btn{cursor:pointer;border:none;border-radius:.75rem;width:100%;padding:.75rem;font-family:inherit;font-size:1rem;font-weight:500;transition:all .2s}._cppay-btn-primary{color:#fff;background-color:#2563eb}._cppay-btn-primary:hover:not(:disabled){background-color:#1d4ed8}._cppay-btn-primary:disabled{opacity:.5;cursor:not-allowed}._cppay-btn-secondary{color:#374151;background-color:#fff;border:1px solid #d1d5db}._cppay-btn-secondary:hover:not(:disabled){background-color:#f9fafb}._cppay-btn-secondary:disabled{opacity:.5;cursor:not-allowed}._cppay-btn-text{color:#6b7280;text-align:center;background:0 0;border:none;padding:.5rem;font-size:.875rem}._cppay-btn-text:hover:not(:disabled){color:#2563eb;background:0 0}._cppay-btn-text:disabled{opacity:.5;cursor:not-allowed}._cppay-btn-container{align-items:center;gap:.5rem;display:flex}._cppay-qr-container{justify-content:center;margin-bottom:1rem;display:flex}._cppay-qr-code{background:linear-gradient(135deg,#667eea 0%,#764ba2 100%);border-radius:1rem;padding:.75rem;box-shadow:0 4px 12px #667eea26}._cppay-qr-placeholder{background-color:#f3f4f6;border-radius:.75rem;justify-content:center;align-items:center;width:10rem;height:10rem;display:flex}._cppay-qr-placeholder span{color:#9ca3af;font-size:.875rem}._cppay-info-box{background-color:#f9fafb;border-radius:.75rem;margin-bottom:.625rem;padding:.875rem}._cppay-info-box:last-child{margin-bottom:0}._cppay-info-label{color:#4b5563;margin-bottom:.25rem;font-size:.875rem}._cppay-info-value{color:#111827;font-size:1.25rem;font-weight:700}._cppay-address-row{align-items:center;gap:.5rem;display:flex}._cppay-address-row code{text-overflow:ellipsis;white-space:nowrap;color:#111827;background:0 0;flex:1;font-family:monospace;font-size:.75rem;overflow:hidden}._cppay-copy-btn{color:#2563eb;cursor:pointer;background:0 0;border:none;justify-content:center;align-items:center;padding:.25rem;transition:color .2s;display:flex}._cppay-copy-btn:hover{color:#1d4ed8}._cppay-copy-btn svg{width:1.25rem;height:1.25rem}@keyframes _cppay-fadeIn{0%{opacity:0}to{opacity:1}}@keyframes _cppay-slideUp{0%{opacity:0;transform:translateY(1.25rem)}to{opacity:1;transform:translateY(0)}}._cppay-overlay{animation:.3s _cppay-fadeIn}._cppay-dialog{animation:.3s _cppay-slideUp}@media (max-width:640px){._cppay-dialog{margin:.5rem}._cppay-header,._cppay-content{padding:1rem}}";
2
+ function injectStyle(e) {
3
+ if (typeof document > "u" || document.getElementById("_cppay-payment-dialog-style")) return;
4
+ let t = document.createElement("style");
5
+ t.id = "_cppay-payment-dialog-style", t.textContent = e, document.head.appendChild(t);
6
+ }
7
+ export { payment_dialog_default as n, injectStyle as t };
package/dist/react.cjs CHANGED
@@ -1,6 +1 @@
1
- const e=require(`./polygon-zw79IkW8.cjs`),t=require(`./cppay-DnxPUyM2.cjs`);let n=require(`rxjs`),r=require(`viem`),i=require(`@reown/appkit`),a=require(`@reown/appkit-adapter-ethers`),o=require(`react`);o=e.g(o);var s=e.h((e=>{var t=Symbol.for(`react.transitional.element`),n=Symbol.for(`react.fragment`);function r(e,n,r){var i=null;if(r!==void 0&&(i=``+r),n.key!==void 0&&(i=``+n.key),`key`in n)for(var a in r={},n)a!==`key`&&(r[a]=n[a]);else r=n;return n=r.ref,{$$typeof:t,type:e,key:i,ref:n===void 0?null:n,props:r}}e.Fragment=n,e.jsx=r,e.jsxs=r})),c=e.h((e=>{process.env.NODE_ENV!==`production`&&(function(){function t(e){if(e==null)return null;if(typeof e==`function`)return e.$$typeof===O?null:e.displayName||e.name||null;if(typeof e==`string`)return e;switch(e){case _:return`Fragment`;case y:return`Profiler`;case v:return`StrictMode`;case C:return`Suspense`;case w:return`SuspenseList`;case D:return`Activity`}if(typeof e==`object`)switch(typeof e.tag==`number`&&console.error(`Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue.`),e.$$typeof){case g:return`Portal`;case x:return e.displayName||`Context`;case b:return(e._context.displayName||`Context`)+`.Consumer`;case S:var n=e.render;return e=e.displayName,e||=(e=n.displayName||n.name||``,e===``?`ForwardRef`:`ForwardRef(`+e+`)`),e;case T:return n=e.displayName||null,n===null?t(e.type)||`Memo`:n;case E:n=e._payload,e=e._init;try{return t(e(n))}catch{}}return null}function n(e){return``+e}function r(e){try{n(e);var t=!1}catch{t=!0}if(t){t=console;var r=t.error,i=typeof Symbol==`function`&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||`Object`;return r.call(t,`The provided key is an unsupported type %s. This value must be coerced to a string before using it here.`,i),n(e)}}function i(e){if(e===_)return`<>`;if(typeof e==`object`&&e&&e.$$typeof===E)return`<...>`;try{var n=t(e);return n?`<`+n+`>`:`<...>`}catch{return`<...>`}}function a(){var e=k.A;return e===null?null:e.getOwner()}function o(){return Error(`react-stack-top-frame`)}function s(e){if(A.call(e,`key`)){var t=Object.getOwnPropertyDescriptor(e,`key`).get;if(t&&t.isReactWarning)return!1}return e.key!==void 0}function c(e,t){function n(){N||(N=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",t))}n.isReactWarning=!0,Object.defineProperty(e,`key`,{get:n,configurable:!0})}function l(){var e=t(this.type);return P[e]||(P[e]=!0,console.error(`Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.`)),e=this.props.ref,e===void 0?null:e}function u(e,t,n,r,i,a){var o=n.ref;return e={$$typeof:h,type:e,key:t,props:n,_owner:r},(o===void 0?null:o)===null?Object.defineProperty(e,`ref`,{enumerable:!1,value:null}):Object.defineProperty(e,`ref`,{enumerable:!1,get:l}),e._store={},Object.defineProperty(e._store,`validated`,{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(e,`_debugInfo`,{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(e,`_debugStack`,{configurable:!1,enumerable:!1,writable:!0,value:i}),Object.defineProperty(e,`_debugTask`,{configurable:!1,enumerable:!1,writable:!0,value:a}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}function d(e,n,i,o,l,d){var p=n.children;if(p!==void 0)if(o)if(j(p)){for(o=0;o<p.length;o++)f(p[o]);Object.freeze&&Object.freeze(p)}else console.error(`React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.`);else f(p);if(A.call(n,`key`)){p=t(e);var m=Object.keys(n).filter(function(e){return e!==`key`});o=0<m.length?`{key: someKey, `+m.join(`: ..., `)+`: ...}`:`{key: someKey}`,L[p+o]||(m=0<m.length?`{`+m.join(`: ..., `)+`: ...}`:`{}`,console.error(`A props object containing a "key" prop is being spread into JSX:
2
- let props = %s;
3
- <%s {...props} />
4
- React keys must be passed directly to JSX without using spread:
5
- let props = %s;
6
- <%s key={someKey} {...props} />`,o,p,m,p),L[p+o]=!0)}if(p=null,i!==void 0&&(r(i),p=``+i),s(n)&&(r(n.key),p=``+n.key),`key`in n)for(var h in i={},n)h!==`key`&&(i[h]=n[h]);else i=n;return p&&c(i,typeof e==`function`?e.displayName||e.name||`Unknown`:e),u(e,p,i,a(),l,d)}function f(e){p(e)?e._store&&(e._store.validated=1):typeof e==`object`&&e&&e.$$typeof===E&&(e._payload.status===`fulfilled`?p(e._payload.value)&&e._payload.value._store&&(e._payload.value._store.validated=1):e._store&&(e._store.validated=1))}function p(e){return typeof e==`object`&&!!e&&e.$$typeof===h}var m=require(`react`),h=Symbol.for(`react.transitional.element`),g=Symbol.for(`react.portal`),_=Symbol.for(`react.fragment`),v=Symbol.for(`react.strict_mode`),y=Symbol.for(`react.profiler`),b=Symbol.for(`react.consumer`),x=Symbol.for(`react.context`),S=Symbol.for(`react.forward_ref`),C=Symbol.for(`react.suspense`),w=Symbol.for(`react.suspense_list`),T=Symbol.for(`react.memo`),E=Symbol.for(`react.lazy`),D=Symbol.for(`react.activity`),O=Symbol.for(`react.client.reference`),k=m.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,A=Object.prototype.hasOwnProperty,j=Array.isArray,M=console.createTask?console.createTask:function(){return null};m={react_stack_bottom_frame:function(e){return e()}};var N,P={},F=m.react_stack_bottom_frame.bind(m,o)(),I=M(i(o)),L={};e.Fragment=_,e.jsx=function(e,t,n){var r=1e4>k.recentlyCreatedOwnerStacks++;return d(e,t,n,!1,r?Error(`react-stack-top-frame`):F,r?M(i(e)):I)},e.jsxs=function(e,t,n){var r=1e4>k.recentlyCreatedOwnerStacks++;return d(e,t,n,!0,r?Error(`react-stack-top-frame`):F,r?M(i(e)):I)}})()})),l=e.h(((e,t)=>{process.env.NODE_ENV===`production`?t.exports=s():t.exports=c()})),u=e.g(e.f(),1),d=l(),f=({open:s,onClose:c,apikey:l,plain:f,orderId:p,amount:m,intervalDays:h,onExpired:g,onSuccess:_,onFailed:v,onError:y})=>{let b=(0,o.useMemo)(()=>new t.t(l),[l]),[x,S]=(0,o.useState)(`select`),[C,w]=(0,o.useState)(!1),[T,E]=(0,o.useState)(!1),[D,O]=(0,o.useState)([]),[k,A]=(0,o.useState)(),[j,M]=(0,o.useState)(),[N,P]=(0,o.useState)(),[F,I]=(0,o.useState)(),[L,R]=(0,o.useState)(!1),[z,B]=(0,o.useState)(),V=(0,o.useRef)(null),H=(0,o.useRef)(null);(0,o.useEffect)(()=>{typeof window<`u`&&!V.current&&(V.current=(0,i.createAppKit)({debug:!1,enableNetworkSwitch:!1,adapters:[new a.EthersAdapter],projectId:`8d2e1854d3f1782e45aa15fbd8938894`,allowUnsupportedChain:!0,networks:[e.r,e.i,e.t,e.o,e.n,e.a],metadata:{name:`Cppay`,description:`Cppay Payment Gateway`,url:window.location.origin,icons:[`https://cppay.com/icon.png`]},features:{analytics:!1}}),I(V.current.getAddress()),B(V.current.getProvider(`eip155`)),V.current.subscribeAccount(e=>{e.isConnected?I(e.address):(I(void 0),B(void 0))}),V.current.subscribeProviders(e=>{let t=e?.eip155;B(t)}))},[]);let U=async()=>{try{R(!0),V.current&&await V.current.open()}catch(e){console.error(`钱包连接失败:`,e),y?.(e)}finally{R(!1)}},W=(0,o.useMemo)(()=>D.find(e=>e.chain===k),[D,k]),G=(0,o.useMemo)(()=>W?.tokens||[],[W]),K=(0,o.useMemo)(()=>G.find(e=>e.symbol===j),[G,j]),q=e=>[`USDT`,`USDC`,`BUSD`,`DAI`,`TUSD`,`USDD`,`FDUSD`].includes(e.toUpperCase())?2:6,J=(e,t)=>{let n=parseFloat(e);return isNaN(n)?`0`:n.toFixed(t).replace(/\.?0+$/,``)},Y=(0,o.useMemo)(()=>{if(!j||!K)return`0`;let e=parseFloat(K.price);if(isNaN(e)||e===0)return`0`;let t=q(j);return J((parseFloat(m)/e).toFixed(t),t)},[m,j,K]),ee=async()=>{try{w(!0);let e=await b.getSupportedChains();O(e),e.length>0&&A(e[0].chain)}catch(e){y?.(e)}finally{w(!1)}},X=async e=>{if(z)try{await z.request({method:`wallet_switchEthereumChain`,params:[{chainId:`0x${e.toString(16)}`}]})}catch(e){throw e.code===4902?Error(`请在钱包中添加该网络`):e}},te=async()=>{if(!(!F||!z||!Z.current||!K||!W))try{w(!0);let e=Z.current;await X(W.chainId);let t=(0,r.createWalletClient)({account:F,transport:(0,r.custom)(z)});if(K.address){let n=await t.writeContract({address:K.address,abi:[{name:`transfer`,type:`function`,stateMutability:`nonpayable`,inputs:[{name:`to`,type:`address`},{name:`amount`,type:`uint256`}],outputs:[{type:`bool`}]}],functionName:`transfer`,args:[e.receiveAddress,(0,r.parseUnits)(e.paymentAmount,K.decimals)],chain:null});console.log(`转账交易哈希:`,n)}else{let n=await t.sendTransaction({to:e.receiveAddress,value:(0,r.parseUnits)(e.paymentAmount,K.decimals),chain:null});console.log(`转账交易哈希:`,n)}w(!1),E(!0),Q(e.paymentId)}catch(e){console.error(`钱包支付失败:`,e),y?.(e),w(!1)}},ne=async()=>{if(!(!F||!z||!Z.current||!K||!W))try{w(!0);let e=Z.current;await X(W.chainId);let t=(0,r.createWalletClient)({account:F,transport:(0,r.custom)(z)});if(!K.address)throw Error(`订阅支付不支持原生代币`);let n=await t.writeContract({address:K.address,abi:[{name:`approve`,type:`function`,stateMutability:`nonpayable`,inputs:[{name:`spender`,type:`address`},{name:`amount`,type:`uint256`}],outputs:[{type:`bool`}]}],functionName:`approve`,args:[e.spenderAddress,(0,r.parseUnits)(e.approveAmount,K.decimals)],chain:null});console.log(`授权交易哈希:`,n),w(!1),E(!0),Q(e.subscriptionId)}catch(e){console.error(`钱包授权失败:`,e),y?.(e),w(!1)}},re=async()=>{if(!F){y?.(Error(`请先连接钱包`));return}f===`one-time`?await te():f===`subscription`&&await ne()},Z=(0,o.useRef)(null),ie=async()=>{if(!(!k||!j))try{w(!0);let e=``;f===`one-time`?(Z.current=await b.createOnetimePayment({paymentChain:k,paymentToken:j,orderId:p,amount:Y}),e=`${k.toLowerCase()}:${Z.current.receiveAddress}?amount=${Z.current.paymentAmount}`):f===`subscription`&&(Z.current=await b.createSubscriptionPayment({paymentChain:k,paymentToken:j,orderId:p,amountOfUsd:Y,intervalDays:h||30}),e=`${k.toLowerCase()}:${Z.current.spenderAddress}?amount=${Z.current.approveAmount}`),S(`payment`),P(await u.toDataURL(e,{width:200,margin:2,errorCorrectionLevel:`H`}))}catch(e){y?.(e)}finally{w(!1)}},ae=async()=>{if(Z.current)try{E(!0),f===`one-time`?Q(Z.current.paymentId):f===`subscription`&&Q(Z.current.subscriptionId)}catch(e){console.error(`支付状态检查错误:`,e),y?.(e),E(!1)}},Q=t=>{let r=()=>(0,n.defer)(()=>f===`subscription`?b.checkSubscriptionPaymentStatus({subscriptionId:t}):b.checkOnetimePaymentStatus({paymentId:t})).pipe(e.s(15e3),e.u({count:3,delay:2e3}));H.current?.unsubscribe(),H.current=r().pipe(e.d(t=>t.status===`pending`?(0,n.timer)(2e3).pipe(e.l(()=>r())):n.EMPTY),e.c(e=>{e.status===`expired`&&(E(!1),g?.(e)),e.status===`paid`&&(E(!1),S(`success`),_?.(e)),e.status===`failed`&&(E(!1),v?.(e)),e.status===`approved`&&(E(!1),S(`success`),_?.(e))})).subscribe({error:e=>{console.error(`支付状态检查错误:`,e),E(!1),y?.(e)}})},oe=async()=>{if(!Z.current)return;let e=f===`subscription`?Z.current.spenderAddress:Z.current.receiveAddress;e&&await navigator.clipboard.writeText(e)},$=()=>{C||T||(c(),setTimeout(()=>{S(`select`),Z.current=null},300))};return(0,o.useEffect)(()=>{s&&D.length===0&&ee()},[s]),(0,o.useEffect)(()=>{G.length>0&&M(G[0].symbol)},[G]),(0,o.useEffect)(()=>()=>{H.current?.unsubscribe()},[]),s?(0,d.jsx)(`div`,{className:`_cppay-overlay`,onClick:e=>e.target===e.currentTarget&&!C&&!T&&$(),children:(0,d.jsxs)(`div`,{className:`_cppay-dialog`,children:[(0,d.jsxs)(`div`,{className:`_cppay-header`,children:[(0,d.jsx)(`h2`,{className:`_cppay-title`,children:x===`select`?`选择支付方式`:`完成支付`}),(0,d.jsx)(`button`,{onClick:$,disabled:C||T,className:`_cppay-close-btn`,children:(0,d.jsx)(`svg`,{fill:`none`,stroke:`currentColor`,viewBox:`0 0 24 24`,children:(0,d.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M6 18L18 6M6 6l12 12`})})})]}),(0,d.jsx)(`div`,{className:`_cppay-content`,children:x===`success`?(0,d.jsxs)(`div`,{style:{textAlign:`center`,padding:`2rem 0`},children:[(0,d.jsx)(`div`,{style:{fontSize:`64px`,marginBottom:`1rem`},children:`✅`}),(0,d.jsx)(`h3`,{style:{fontSize:`1.5rem`,fontWeight:600,color:`#10b981`,margin:`0 0 0.5rem 0`},children:f===`subscription`?`授权成功!`:`支付成功!`}),(0,d.jsx)(`p`,{style:{color:`#6b7280`,margin:0},children:f===`subscription`?`订阅已激活`:`交易已完成`})]}):x===`select`?(0,d.jsxs)(`div`,{children:[(0,d.jsxs)(`div`,{className:`_cppay-section`,children:[(0,d.jsx)(`label`,{className:`_cppay-label`,children:`支付网络`}),(0,d.jsx)(`div`,{className:`_cppay-grid`,children:D.map(e=>(0,d.jsxs)(`button`,{onClick:()=>A(e.chain),className:`_cppay-select-btn ${k===e.chain?`_cppay-selected`:``}`,children:[e.icon&&(0,d.jsx)(`img`,{src:e.icon,alt:e.chain}),(0,d.jsx)(`span`,{children:e.chain})]},e.chain))})]}),(0,d.jsxs)(`div`,{className:`_cppay-section`,children:[(0,d.jsx)(`label`,{className:`_cppay-label`,children:`支付代币`}),(0,d.jsx)(`div`,{className:`_cppay-grid`,children:G.map(e=>(0,d.jsxs)(`button`,{onClick:()=>M(e.symbol),className:`_cppay-select-btn ${j===e.symbol?`_cppay-selected`:``}`,children:[e.icon&&(0,d.jsx)(`img`,{src:e.icon,alt:e.symbol}),(0,d.jsx)(`span`,{children:e.symbol})]},e.symbol))})]}),(0,d.jsx)(`div`,{className:`_cppay-section`,children:(0,d.jsx)(`div`,{className:`_cppay-price-box`,children:(0,d.jsxs)(`div`,{className:`_cppay-price-row`,children:[(0,d.jsx)(`span`,{className:`_cppay-price-label`,children:`支付金额`}),(0,d.jsxs)(`div`,{className:`_cppay-price-amount`,children:[(0,d.jsxs)(`div`,{className:`_cppay-price-main`,children:[Y??`-`,` `,j??``]}),(0,d.jsxs)(`div`,{className:`_cppay-price-sub`,children:[`≈ $`,m]})]})]})})}),(0,d.jsx)(`div`,{className:`_cppay-section`,children:(0,d.jsx)(`button`,{onClick:ie,disabled:!k||!j||C,className:`_cppay-btn _cppay-btn-primary`,children:C?`处理中...`:`继续支付`})})]}):(0,d.jsxs)(`div`,{children:[(0,d.jsx)(`div`,{className:`_cppay-qr-container`,children:(0,d.jsx)(`div`,{className:`_cppay-qr-code`,children:N&&(0,d.jsx)(`img`,{src:N,alt:`Payment QR Code`,style:{width:`160px`,height:`160px`,display:`block`}})})}),(0,d.jsxs)(`div`,{className:`_cppay-section`,children:[j&&(0,d.jsxs)(`div`,{className:`_cppay-info-box`,children:[(0,d.jsx)(`div`,{className:`_cppay-info-label`,children:f===`subscription`?`授权金额`:`支付金额`}),(0,d.jsx)(`div`,{className:`_cppay-info-value`,children:f===`subscription`?`${J(Z.current.approveAmount,q(j))} ${j}`:`${J(Z.current.paymentAmount,q(j))} ${j}`})]}),(0,d.jsxs)(`div`,{className:`_cppay-info-box`,children:[(0,d.jsx)(`div`,{className:`_cppay-info-label`,children:f===`subscription`?`授权合约地址`:`支付地址`}),(0,d.jsxs)(`div`,{className:`_cppay-address-row`,children:[(0,d.jsx)(`code`,{children:f===`subscription`?Z.current.spenderAddress:Z.current.receiveAddress}),(0,d.jsx)(`button`,{onClick:oe,className:`_cppay-copy-btn`,title:`复制地址`,children:(0,d.jsx)(`svg`,{fill:`none`,stroke:`currentColor`,viewBox:`0 0 24 24`,children:(0,d.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z`})})})]})]}),f===`subscription`&&(0,d.jsxs)(`div`,{className:`_cppay-info-box`,style:{background:`#fff3cd`,borderColor:`#ffc107`},children:[(0,d.jsx)(`div`,{className:`_cppay-info-label`,style:{color:`#856404`},children:`📌 订阅说明`}),(0,d.jsx)(`div`,{className:`_cppay-info-value`,style:{fontSize:`12px`,color:`#856404`},children:`订阅支付需要授权代币给合约地址,系统将按周期自动扣款。授权后无需每次手动支付。`})]})]}),!T&&(0,d.jsx)(`div`,{className:`_cppay-section`,children:F?(0,d.jsxs)(d.Fragment,{children:[(0,d.jsxs)(`div`,{className:`_cppay-btn-container`,children:[(0,d.jsx)(`button`,{onClick:re,disabled:C,className:`_cppay-btn _cppay-btn-primary`,children:C?f===`subscription`?`授权中...`:`支付中...`:f===`subscription`?`💳 钱包授权`:`💳 钱包支付`}),(0,d.jsx)(`button`,{onClick:U,disabled:C,className:`_cppay-btn _cppay-btn-primary`,children:`💰钱包状态`})]}),(0,d.jsxs)(`div`,{style:{textAlign:`center`,marginTop:`8px`,fontSize:`12px`,color:`#666`},children:[`已连接: `,F.slice(0,6),`...`,F.slice(-4)]})]}):(0,d.jsx)(`button`,{onClick:U,disabled:L,className:`_cppay-btn _cppay-btn-secondary`,style:{display:`flex`,alignItems:`center`,justifyContent:`center`,gap:`0.5rem`,padding:`0.75rem 1rem`,width:`100%`},children:(0,d.jsx)(`span`,{children:L?`连接中...`:`💳 连接钱包`})})}),(0,d.jsx)(`div`,{className:`_cppay-section`,children:(0,d.jsx)(`button`,{onClick:ae,disabled:T,className:`_cppay-btn _cppay-btn-primary`,children:T?`检查中...`:`我已完成支付`})}),(0,d.jsx)(`div`,{className:`_cppay-section`,children:(0,d.jsx)(`button`,{onClick:()=>S(`select`),disabled:C||T,className:`_cppay-btn _cppay-btn-text`,children:`更改支付方式`})})]})})]})}):null},p=o.default.memo(f),m=(0,o.createContext)(null);const h=({apikey:e,children:t})=>{let[n,r]=(0,o.useState)(!1),[i,a]=(0,o.useState)(null),s=(0,o.useCallback)(e=>{a(e),r(!0)},[]),c=(0,o.useCallback)(()=>{r(!1)},[]),l=(0,o.useCallback)(e=>{i?.onSuccess?.(e),r(!1)},[i]),u=(0,o.useCallback)(e=>{i?.onError?.(e)},[i]);return(0,d.jsxs)(m.Provider,{value:{showPayment:s},children:[t,i&&(0,d.jsx)(p,{open:n,onClose:c,apikey:e,plain:i.plain,orderId:i.orderId,amount:i.amount,intervalDays:i.intervalDays,onSuccess:l,onError:u})]})},g=()=>{let e=(0,o.useContext)(m);if(!e)throw Error(`useCppayPayment must be used within CppayProvider`);return e};e.p(e.m),exports.CppayProvider=h,exports.PaymentDialog=p,exports.useCppayPayment=g;
1
+ const e=require(`./inject-style-CvrNZeWB.cjs`),t=require(`./cppay-DnxPUyM2.cjs`);let n=require(`qrcode`);n=e.r(n);let r=require(`rxjs`),i=require(`rxjs/operators`),a=require(`viem`),o=require(`viem/chains`),s=require(`@reown/appkit`),c=require(`@reown/appkit-adapter-ethers`),l=require(`react`);l=e.r(l);let u=require(`react/jsx-runtime`);var d=({open:e,onClose:d,apikey:f,plain:p,orderId:m,amount:h,intervalDays:ee,onExpired:g,onSuccess:_,onFailed:te,onError:v})=>{let y=(0,l.useMemo)(()=>new t.t(f),[f]),[b,x]=(0,l.useState)(`select`),[S,C]=(0,l.useState)(!1),[w,T]=(0,l.useState)(!1),[E,D]=(0,l.useState)([]),[O,k]=(0,l.useState)(),[A,j]=(0,l.useState)(),[M,ne]=(0,l.useState)(),[N,P]=(0,l.useState)(),[F,I]=(0,l.useState)(!1),[L,R]=(0,l.useState)(),z=(0,l.useRef)(null),B=(0,l.useRef)(null);(0,l.useEffect)(()=>{typeof window<`u`&&!z.current&&(z.current=(0,s.createAppKit)({debug:!1,enableNetworkSwitch:!1,adapters:[new c.EthersAdapter],projectId:`8d2e1854d3f1782e45aa15fbd8938894`,allowUnsupportedChain:!0,networks:[o.mainnet,o.bsc,o.polygon,o.arbitrum,o.optimism,o.base],metadata:{name:`Cppay`,description:`Cppay Payment Gateway`,url:window.location.origin,icons:[`https://cppay.com/icon.png`]},features:{analytics:!1}}),P(z.current.getAddress()),R(z.current.getProvider(`eip155`)),z.current.subscribeAccount(e=>{e.isConnected?P(e.address):(P(void 0),R(void 0))}),z.current.subscribeProviders(e=>{let t=e?.eip155;R(t)}))},[]);let V=async()=>{try{I(!0),z.current&&await z.current.open()}catch(e){console.error(`钱包连接失败:`,e),v?.(e)}finally{I(!1)}},H=(0,l.useMemo)(()=>E.find(e=>e.chain===O),[E,O]),U=(0,l.useMemo)(()=>H?.tokens||[],[H]),W=(0,l.useMemo)(()=>U.find(e=>e.symbol===A),[U,A]),G=e=>[`USDT`,`USDC`,`BUSD`,`DAI`,`TUSD`,`USDD`,`FDUSD`].includes(e.toUpperCase())?2:6,K=(e,t)=>{let n=parseFloat(e);return isNaN(n)?`0`:n.toFixed(t).replace(/\.?0+$/,``)},q=(0,l.useMemo)(()=>{if(!A||!W)return`0`;let e=parseFloat(W.price);if(isNaN(e)||e===0)return`0`;let t=G(A);return K((parseFloat(h)/e).toFixed(t),t)},[h,A,W]),re=async()=>{try{C(!0);let e=await y.getSupportedChains();D(e),e.length>0&&k(e[0].chain)}catch(e){v?.(e)}finally{C(!1)}},J=async e=>{if(L)try{await L.request({method:`wallet_switchEthereumChain`,params:[{chainId:`0x${e.toString(16)}`}]})}catch(e){throw e.code===4902?Error(`请在钱包中添加该网络`):e}},Y=async()=>{if(!(!N||!L||!Z.current||!W||!H))try{C(!0);let e=Z.current;await J(H.chainId);let t=(0,a.createWalletClient)({account:N,transport:(0,a.custom)(L)});if(W.address){let n=await t.writeContract({address:W.address,abi:[{name:`transfer`,type:`function`,stateMutability:`nonpayable`,inputs:[{name:`to`,type:`address`},{name:`amount`,type:`uint256`}],outputs:[{type:`bool`}]}],functionName:`transfer`,args:[e.receiveAddress,(0,a.parseUnits)(e.paymentAmount,W.decimals)],chain:null});console.log(`转账交易哈希:`,n)}else{let n=await t.sendTransaction({to:e.receiveAddress,value:(0,a.parseUnits)(e.paymentAmount,W.decimals),chain:null});console.log(`转账交易哈希:`,n)}C(!1),T(!0),Q(e.paymentId)}catch(e){console.error(`钱包支付失败:`,e),v?.(e),C(!1)}},ie=async()=>{if(!(!N||!L||!Z.current||!W||!H))try{C(!0);let e=Z.current;await J(H.chainId);let t=(0,a.createWalletClient)({account:N,transport:(0,a.custom)(L)});if(!W.address)throw Error(`订阅支付不支持原生代币`);let n=await t.writeContract({address:W.address,abi:[{name:`approve`,type:`function`,stateMutability:`nonpayable`,inputs:[{name:`spender`,type:`address`},{name:`amount`,type:`uint256`}],outputs:[{type:`bool`}]}],functionName:`approve`,args:[e.spenderAddress,(0,a.parseUnits)(e.approveAmount,W.decimals)],chain:null});console.log(`授权交易哈希:`,n),C(!1),T(!0),Q(e.subscriptionId)}catch(e){console.error(`钱包授权失败:`,e),v?.(e),C(!1)}},X=async()=>{if(!N){v?.(Error(`请先连接钱包`));return}p===`one-time`?await Y():p===`subscription`&&await ie()},Z=(0,l.useRef)(null),ae=async()=>{if(!(!O||!A))try{C(!0);let e=``;p===`one-time`?(Z.current=await y.createOnetimePayment({paymentChain:O,paymentToken:A,orderId:m,amount:q}),e=`${O.toLowerCase()}:${Z.current.receiveAddress}?amount=${Z.current.paymentAmount}`):p===`subscription`&&(Z.current=await y.createSubscriptionPayment({paymentChain:O,paymentToken:A,orderId:m,amountOfUsd:q,intervalDays:ee||30}),e=`${O.toLowerCase()}:${Z.current.spenderAddress}?amount=${Z.current.approveAmount}`),x(`payment`),ne(await n.toDataURL(e,{width:200,margin:2,errorCorrectionLevel:`H`}))}catch(e){v?.(e)}finally{C(!1)}},oe=async()=>{if(Z.current)try{T(!0),p===`one-time`?Q(Z.current.paymentId):p===`subscription`&&Q(Z.current.subscriptionId)}catch(e){console.error(`支付状态检查错误:`,e),v?.(e),T(!1)}},Q=e=>{let t=()=>(0,r.defer)(()=>p===`subscription`?y.checkSubscriptionPaymentStatus({subscriptionId:e}):y.checkOnetimePaymentStatus({paymentId:e})).pipe((0,i.timeout)(15e3),(0,i.retry)({count:3,delay:2e3}));B.current?.unsubscribe(),B.current=t().pipe((0,i.expand)(e=>e.status===`pending`?(0,r.timer)(2e3).pipe((0,i.switchMap)(()=>t())):r.EMPTY),(0,i.tap)(e=>{e.status===`expired`&&(T(!1),g?.(e)),e.status===`paid`&&(T(!1),x(`success`),_?.(e)),e.status===`failed`&&(T(!1),te?.(e)),e.status===`approved`&&(T(!1),x(`success`),_?.(e))})).subscribe({error:e=>{console.error(`支付状态检查错误:`,e),T(!1),v?.(e)}})},se=async()=>{if(!Z.current)return;let e=p===`subscription`?Z.current.spenderAddress:Z.current.receiveAddress;e&&await navigator.clipboard.writeText(e)},$=()=>{S||w||(d(),setTimeout(()=>{x(`select`),Z.current=null},300))};return(0,l.useEffect)(()=>{e&&E.length===0&&re()},[e]),(0,l.useEffect)(()=>{U.length>0&&j(U[0].symbol)},[U]),(0,l.useEffect)(()=>()=>{B.current?.unsubscribe()},[]),e?(0,u.jsx)(`div`,{className:`_cppay-overlay`,onClick:e=>e.target===e.currentTarget&&!S&&!w&&$(),children:(0,u.jsxs)(`div`,{className:`_cppay-dialog`,children:[(0,u.jsxs)(`div`,{className:`_cppay-header`,children:[(0,u.jsx)(`h2`,{className:`_cppay-title`,children:b===`select`?`选择支付方式`:`完成支付`}),(0,u.jsx)(`button`,{onClick:$,disabled:S||w,className:`_cppay-close-btn`,children:(0,u.jsx)(`svg`,{fill:`none`,stroke:`currentColor`,viewBox:`0 0 24 24`,children:(0,u.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M6 18L18 6M6 6l12 12`})})})]}),(0,u.jsx)(`div`,{className:`_cppay-content`,children:b===`success`?(0,u.jsxs)(`div`,{style:{textAlign:`center`,padding:`2rem 0`},children:[(0,u.jsx)(`div`,{style:{fontSize:`64px`,marginBottom:`1rem`},children:`✅`}),(0,u.jsx)(`h3`,{style:{fontSize:`1.5rem`,fontWeight:600,color:`#10b981`,margin:`0 0 0.5rem 0`},children:p===`subscription`?`授权成功!`:`支付成功!`}),(0,u.jsx)(`p`,{style:{color:`#6b7280`,margin:0},children:p===`subscription`?`订阅已激活`:`交易已完成`})]}):b===`select`?(0,u.jsxs)(`div`,{children:[(0,u.jsxs)(`div`,{className:`_cppay-section`,children:[(0,u.jsx)(`label`,{className:`_cppay-label`,children:`支付网络`}),(0,u.jsx)(`div`,{className:`_cppay-grid`,children:E.map(e=>(0,u.jsxs)(`button`,{onClick:()=>k(e.chain),className:`_cppay-select-btn ${O===e.chain?`_cppay-selected`:``}`,children:[e.icon&&(0,u.jsx)(`img`,{src:e.icon,alt:e.chain}),(0,u.jsx)(`span`,{children:e.chain})]},e.chain))})]}),(0,u.jsxs)(`div`,{className:`_cppay-section`,children:[(0,u.jsx)(`label`,{className:`_cppay-label`,children:`支付代币`}),(0,u.jsx)(`div`,{className:`_cppay-grid`,children:U.map(e=>(0,u.jsxs)(`button`,{onClick:()=>j(e.symbol),className:`_cppay-select-btn ${A===e.symbol?`_cppay-selected`:``}`,children:[e.icon&&(0,u.jsx)(`img`,{src:e.icon,alt:e.symbol}),(0,u.jsx)(`span`,{children:e.symbol})]},e.symbol))})]}),(0,u.jsx)(`div`,{className:`_cppay-section`,children:(0,u.jsx)(`div`,{className:`_cppay-price-box`,children:(0,u.jsxs)(`div`,{className:`_cppay-price-row`,children:[(0,u.jsx)(`span`,{className:`_cppay-price-label`,children:`支付金额`}),(0,u.jsxs)(`div`,{className:`_cppay-price-amount`,children:[(0,u.jsxs)(`div`,{className:`_cppay-price-main`,children:[q??`-`,` `,A??``]}),(0,u.jsxs)(`div`,{className:`_cppay-price-sub`,children:[`≈ $`,h]})]})]})})}),(0,u.jsx)(`div`,{className:`_cppay-section`,children:(0,u.jsx)(`button`,{onClick:ae,disabled:!O||!A||S,className:`_cppay-btn _cppay-btn-primary`,children:S?`处理中...`:`继续支付`})})]}):(0,u.jsxs)(`div`,{children:[(0,u.jsx)(`div`,{className:`_cppay-qr-container`,children:(0,u.jsx)(`div`,{className:`_cppay-qr-code`,children:M&&(0,u.jsx)(`img`,{src:M,alt:`Payment QR Code`,style:{width:`160px`,height:`160px`,display:`block`}})})}),(0,u.jsxs)(`div`,{className:`_cppay-section`,children:[A&&(0,u.jsxs)(`div`,{className:`_cppay-info-box`,children:[(0,u.jsx)(`div`,{className:`_cppay-info-label`,children:p===`subscription`?`授权金额`:`支付金额`}),(0,u.jsx)(`div`,{className:`_cppay-info-value`,children:p===`subscription`?`${K(Z.current.approveAmount,G(A))} ${A}`:`${K(Z.current.paymentAmount,G(A))} ${A}`})]}),(0,u.jsxs)(`div`,{className:`_cppay-info-box`,children:[(0,u.jsx)(`div`,{className:`_cppay-info-label`,children:p===`subscription`?`授权合约地址`:`支付地址`}),(0,u.jsxs)(`div`,{className:`_cppay-address-row`,children:[(0,u.jsx)(`code`,{children:p===`subscription`?Z.current.spenderAddress:Z.current.receiveAddress}),(0,u.jsx)(`button`,{onClick:se,className:`_cppay-copy-btn`,title:`复制地址`,children:(0,u.jsx)(`svg`,{fill:`none`,stroke:`currentColor`,viewBox:`0 0 24 24`,children:(0,u.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z`})})})]})]}),p===`subscription`&&(0,u.jsxs)(`div`,{className:`_cppay-info-box`,style:{background:`#fff3cd`,borderColor:`#ffc107`},children:[(0,u.jsx)(`div`,{className:`_cppay-info-label`,style:{color:`#856404`},children:`📌 订阅说明`}),(0,u.jsx)(`div`,{className:`_cppay-info-value`,style:{fontSize:`12px`,color:`#856404`},children:`订阅支付需要授权代币给合约地址,系统将按周期自动扣款。授权后无需每次手动支付。`})]})]}),!w&&(0,u.jsx)(`div`,{className:`_cppay-section`,children:N?(0,u.jsxs)(u.Fragment,{children:[(0,u.jsxs)(`div`,{className:`_cppay-btn-container`,children:[(0,u.jsx)(`button`,{onClick:X,disabled:S,className:`_cppay-btn _cppay-btn-primary`,children:S?p===`subscription`?`授权中...`:`支付中...`:p===`subscription`?`💳 钱包授权`:`💳 钱包支付`}),(0,u.jsx)(`button`,{onClick:V,disabled:S,className:`_cppay-btn _cppay-btn-primary`,children:`💰钱包状态`})]}),(0,u.jsxs)(`div`,{style:{textAlign:`center`,marginTop:`8px`,fontSize:`12px`,color:`#666`},children:[`已连接: `,N.slice(0,6),`...`,N.slice(-4)]})]}):(0,u.jsx)(`button`,{onClick:V,disabled:F,className:`_cppay-btn _cppay-btn-secondary`,style:{display:`flex`,alignItems:`center`,justifyContent:`center`,gap:`0.5rem`,padding:`0.75rem 1rem`,width:`100%`},children:(0,u.jsx)(`span`,{children:F?`连接中...`:`💳 连接钱包`})})}),(0,u.jsx)(`div`,{className:`_cppay-section`,children:(0,u.jsx)(`button`,{onClick:oe,disabled:w,className:`_cppay-btn _cppay-btn-primary`,children:w?`检查中...`:`我已完成支付`})}),(0,u.jsx)(`div`,{className:`_cppay-section`,children:(0,u.jsx)(`button`,{onClick:()=>x(`select`),disabled:S||w,className:`_cppay-btn _cppay-btn-text`,children:`更改支付方式`})})]})})]})}):null},f=l.default.memo(d),p=(0,l.createContext)(null);const m=({apikey:e,children:t})=>{let[n,r]=(0,l.useState)(!1),[i,a]=(0,l.useState)(null),o=(0,l.useCallback)(e=>{a(e),r(!0)},[]),s=(0,l.useCallback)(()=>{r(!1)},[]),c=(0,l.useCallback)(e=>{i?.onSuccess?.(e),r(!1)},[i]),d=(0,l.useCallback)(e=>{i?.onError?.(e)},[i]);return(0,u.jsxs)(p.Provider,{value:{showPayment:o},children:[t,i&&(0,u.jsx)(f,{open:n,onClose:s,apikey:e,plain:i.plain,orderId:i.orderId,amount:i.amount,intervalDays:i.intervalDays,onSuccess:c,onError:d})]})},h=()=>{let e=(0,l.useContext)(p);if(!e)throw Error(`useCppayPayment must be used within CppayProvider`);return e};e.t(e.n),exports.CppayProvider=m,exports.PaymentDialog=f,exports.useCppayPayment=h;