cppay-sdk 0.0.2-beta.5 → 0.0.2-beta.7
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/{cppay-rxbtyzyZ.cjs → cppay-Bvf-Bb7R.cjs} +1 -1
- package/dist/{cppay-gIC4-2qD.js → cppay-Bz0NCjpC.js} +5 -5
- package/dist/cppay-sdk.css +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/inject-style-Dz7JsQxo.cjs +1 -0
- package/dist/inject-style-qX_0AjjE.js +7 -0
- package/dist/react.cjs +1 -6
- package/dist/react.js +121 -297
- package/dist/vue.cjs +1 -1
- package/dist/vue.js +45 -44
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
const e={Ethereum:`https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/info/logo.png`,BSC:`https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/binance/info/logo.png`,"bsc-testnet":`https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/binance/info/logo.png`,Tron:`https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/tron/info/logo.png`,Polygon:`https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/polygon/info/logo.png`,Solana:`https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/solana/info/logo.png`},t={USDT:`https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0xdAC17F958D2ee523a2206206994597C13D831ec7/logo.png`,USDC:`https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48/logo.png`,ETH:`https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/info/logo.png`,BNB:`https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/binance/info/logo.png`,tBNB:`https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/binance/info/logo.png`,TRX:`https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/tron/info/logo.png`,SOL:`https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/solana/info/logo.png`};var n=`http://192.168.0.162:8000`,r=async(e,t,r)=>{let i=Object.assign({timeout:15e3},r),a=new AbortController,o=setTimeout(()=>a.abort(),i.timeout);try{let r=await fetch(new URL(e,n),{signal:a.signal,...t});clearTimeout(o);let i=r.headers.get(`Content-Type`)??``;if(i.includes(`json`))return await r.json();try{return await r.json()}catch{throw Error(`URL: ${e}, Unsupport Content Type: ${i}`)}}catch(t){throw clearTimeout(o),t instanceof DOMException&&t.name===`AbortError`?Error(`URL: ${e}, Request timeout after ${i.timeout}ms`):t}},i=0;const a=async(e,t)=>{let n=await r(t.url
|
|
1
|
+
const e={Ethereum:`https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/info/logo.png`,BSC:`https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/binance/info/logo.png`,"bsc-testnet":`https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/binance/info/logo.png`,Tron:`https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/tron/info/logo.png`,Polygon:`https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/polygon/info/logo.png`,Solana:`https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/solana/info/logo.png`},t={USDT:`https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0xdAC17F958D2ee523a2206206994597C13D831ec7/logo.png`,USDC:`https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48/logo.png`,ETH:`https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/info/logo.png`,BNB:`https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/binance/info/logo.png`,tBNB:`https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/binance/info/logo.png`,TRX:`https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/tron/info/logo.png`,SOL:`https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/solana/info/logo.png`};var n=`http://192.168.0.162:8000`,r=async(e,t,r)=>{let i=Object.assign({timeout:15e3},r),a=new AbortController,o=setTimeout(()=>a.abort(),i.timeout);try{let r=await fetch(new URL(e,n),{signal:a.signal,...t});clearTimeout(o);let i=r.headers.get(`Content-Type`)??``;if(i.includes(`json`))return await r.json();try{return await r.json()}catch{throw Error(`URL: ${e}, Unsupport Content Type: ${i}`)}}catch(t){throw clearTimeout(o),t instanceof DOMException&&t.name===`AbortError`?Error(`URL: ${e}, Request timeout after ${i.timeout}ms`):t}},i=0;const a=async(e,t)=>{let n=new URLSearchParams(t.params),a=await r(`${t.url}${n.size?`?${n.toString()}`:``}`,{method:t.method??`get`,headers:{Authorization:e,...t.headers},body:t.data?JSON.stringify(t.data):void 0});if(a.code!==i)throw Error(`Request ${t.url} Failed. ${a.message}`);return a.data},o=(e=1e3)=>new Promise(t=>setTimeout(t,e));var s=class{apikey;constructor(e){this.apikey=e}async getSupportedChains(){let n=(await a(this.apikey,{url:`/api/payment/token`})).reduce((n,r)=>{let i=n[r.chain]??{chain:r.chain,tokens:[],icon:e[r.chain]};return i.tokens.push({symbol:r.token_symbol,decimals:r.token_decimals,address:r.token_address,receiveAddresses:r.receive_addresses,icon:t[r.token_symbol]}),n[r.chain]=i,n},{});return Object.values(n)}async createPayment(e){let t={chain:e.paymentChain,token:e.paymentToken,order_no:e.orderId,amount:e.amount},n=await a(this.apikey,{url:`/api/payment/create`,method:`post`,data:t});return{orderId:e.orderId,paymentId:n.payment_id,paymentAmount:n.pay_amount,paymentChain:e.paymentChain,paymentToken:e.paymentToken}}async checkPaymentStatus(e,t=1e3){let n=15;for(;n--;){let n={payment_id:e};if((await a(this.apikey,{url:`/api/payment/query`,params:n})).status===`success`)return;await o(t)}throw Error(`Check Payment Status Timeout, PaymentId: ${e}`)}},c=s;Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return e}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return t}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return c}});
|
|
@@ -34,16 +34,16 @@ var BASE_URL = "http://192.168.0.162:8000", request = async (e, n, i) => {
|
|
|
34
34
|
}
|
|
35
35
|
}, SUCCESS_CODE = 0;
|
|
36
36
|
const cppayRequest = async (e, n) => {
|
|
37
|
-
let r = await request(n.url
|
|
37
|
+
let r = new URLSearchParams(n.params), o = await request(`${n.url}${r.size ? `?${r.toString()}` : ""}`, {
|
|
38
38
|
method: n.method ?? "get",
|
|
39
39
|
headers: {
|
|
40
40
|
Authorization: e,
|
|
41
41
|
...n.headers
|
|
42
42
|
},
|
|
43
|
-
body: JSON.stringify(n.data)
|
|
43
|
+
body: n.data ? JSON.stringify(n.data) : void 0
|
|
44
44
|
});
|
|
45
|
-
if (
|
|
46
|
-
return
|
|
45
|
+
if (o.code !== SUCCESS_CODE) throw Error(`Request ${n.url} Failed. ${o.message}`);
|
|
46
|
+
return o.data;
|
|
47
47
|
}, sleep = (e = 1e3) => new Promise((n) => setTimeout(n, e));
|
|
48
48
|
var cppay_default = class {
|
|
49
49
|
apikey;
|
|
@@ -92,7 +92,7 @@ var cppay_default = class {
|
|
|
92
92
|
let r = { payment_id: e };
|
|
93
93
|
if ((await cppayRequest(this.apikey, {
|
|
94
94
|
url: "/api/payment/query",
|
|
95
|
-
|
|
95
|
+
params: r
|
|
96
96
|
})).status === "success") return;
|
|
97
97
|
await sleep(n);
|
|
98
98
|
}
|
package/dist/cppay-sdk.css
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
._cppay-
|
|
1
|
+
._cppay-fade-enter-active[data-v-a66fc55b],._cppay-fade-leave-active[data-v-a66fc55b]{transition:opacity .3s}._cppay-fade-enter-from[data-v-a66fc55b],._cppay-fade-leave-to[data-v-a66fc55b]{opacity:0}._cppay-fade-enter-active ._cppay-dialog[data-v-a66fc55b]{animation:.3s _cppay-slideUp}
|
|
2
2
|
/*$vite$:1*/
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require(`./cppay-
|
|
1
|
+
const e=require(`./cppay-Bvf-Bb7R.cjs`);exports.CHAIN_ICONS=e.n,exports.Cppay=e.t,exports.TOKEN_ICONS=e.r;
|
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-
|
|
1
|
+
import { n as CHAIN_ICONS, r as TOKEN_ICONS, t as cppay_default } from "./cppay-Bz0NCjpC.js";
|
|
2
2
|
export { CHAIN_ICONS, cppay_default as Cppay, TOKEN_ICONS };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e=`._cppay-overlay{z-index:9999;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;width:100%;max-width:28rem;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:1.5rem;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{padding:1.5rem}._cppay-section{margin-bottom:1.5rem}._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-qr-container{justify-content:center;margin-bottom:1.5rem;display:flex}._cppay-qr-placeholder{background-color:#f3f4f6;border-radius:1rem;justify-content:center;align-items:center;width:12rem;height:12rem;display:flex}._cppay-qr-placeholder span{color:#9ca3af;font-size:.875rem}._cppay-info-box{background-color:#f9fafb;border-radius:.75rem;margin-bottom:.75rem;padding:1rem}._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 t(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 e}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return t}});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
var payment_dialog_default = "._cppay-overlay{z-index:9999;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;width:100%;max-width:28rem;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:1.5rem;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{padding:1.5rem}._cppay-section{margin-bottom:1.5rem}._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-qr-container{justify-content:center;margin-bottom:1.5rem;display:flex}._cppay-qr-placeholder{background-color:#f3f4f6;border-radius:1rem;justify-content:center;align-items:center;width:12rem;height:12rem;display:flex}._cppay-qr-placeholder span{color:#9ca3af;font-size:.875rem}._cppay-info-box{background-color:#f9fafb;border-radius:.75rem;margin-bottom:.75rem;padding:1rem}._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
|
-
var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,
|
|
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)}})()})),p=o(((e,t)=>{process.env.NODE_ENV===`production`?t.exports=d():t.exports=f()})),m=p(),h=({open:e,onClose:t,apiKey:n,orderId:r,amount:i,onSuccess:a,onError:o})=>{let s=(0,u.useMemo)(()=>new l.t(n),[n]),[c,d]=(0,u.useState)(`select`),[f,p]=(0,u.useState)(!1),[h,g]=(0,u.useState)([]),[_,v]=(0,u.useState)(``),[y,b]=(0,u.useState)(``),[x,S]=(0,u.useState)(null),C=(0,u.useMemo)(()=>h.find(e=>e.chain===_),[h,_]),w=(0,u.useMemo)(()=>C?.tokens||[],[C]),T=(0,u.useMemo)(()=>w.find(e=>e.symbol===y),[w,y]),E=(0,u.useMemo)(()=>y?(parseFloat(i)/1).toFixed(6):`0`,[i,y,1]),D=async()=>{try{p(!0);let e=await s.getSupportedChains();g(e),e.length>0&&v(e[0].chain)}catch(e){o?.(e)}finally{p(!1)}},O=async()=>{if(!(!_||!y))try{p(!0);let e=await s.createPayment({paymentChain:_,paymentToken:y,orderId:r,amount:E});S({paymentId:e.paymentId,paymentAmount:e.paymentAmount,receiveAddress:T?.receiveAddresses[0]||``}),d(`payment`)}catch(e){o?.(e)}finally{p(!1)}},k=async()=>{if(x)try{p(!0),await s.checkPaymentStatus(x.paymentId,1e3),a?.(x.paymentId),j()}catch(e){o?.(e)}finally{p(!1)}},A=async()=>{x?.receiveAddress&&await navigator.clipboard.writeText(x.receiveAddress)},j=()=>{t(),setTimeout(()=>{d(`select`),S(null)},300)};return(0,u.useEffect)(()=>{e&&h.length===0&&D()},[e]),(0,u.useEffect)(()=>{w.length>0&&b(w[0].symbol)},[w]),e?(0,m.jsx)(`div`,{className:`_cppay-overlay`,onClick:e=>e.target===e.currentTarget&&j(),children:(0,m.jsxs)(`div`,{className:`_cppay-dialog`,children:[(0,m.jsxs)(`div`,{className:`_cppay-header`,children:[(0,m.jsx)(`h2`,{className:`_cppay-title`,children:c===`select`?`选择支付方式`:`完成支付`}),(0,m.jsx)(`button`,{onClick:j,disabled:f,className:`_cppay-close-btn`,children:(0,m.jsx)(`svg`,{fill:`none`,stroke:`currentColor`,viewBox:`0 0 24 24`,children:(0,m.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M6 18L18 6M6 6l12 12`})})})]}),(0,m.jsx)(`div`,{className:`_cppay-content`,children:c===`select`?(0,m.jsxs)(`div`,{children:[(0,m.jsxs)(`div`,{className:`_cppay-section`,children:[(0,m.jsx)(`label`,{className:`_cppay-label`,children:`支付网络`}),(0,m.jsx)(`div`,{className:`_cppay-grid`,children:h.map(e=>(0,m.jsxs)(`button`,{onClick:()=>v(e.chain),className:`_cppay-select-btn ${_===e.chain?`_cppay-selected`:``}`,children:[e.icon&&(0,m.jsx)(`img`,{src:e.icon,alt:e.chain}),(0,m.jsx)(`span`,{children:e.chain})]},e.chain))})]}),(0,m.jsxs)(`div`,{className:`_cppay-section`,children:[(0,m.jsx)(`label`,{className:`_cppay-label`,children:`支付代币`}),(0,m.jsx)(`div`,{className:`_cppay-grid`,children:w.map(e=>(0,m.jsxs)(`button`,{onClick:()=>b(e.symbol),className:`_cppay-select-btn ${y===e.symbol?`_cppay-selected`:``}`,children:[e.icon&&(0,m.jsx)(`img`,{src:e.icon,alt:e.symbol}),(0,m.jsx)(`span`,{children:e.symbol})]},e.symbol))})]}),(0,m.jsx)(`div`,{className:`_cppay-section`,children:(0,m.jsx)(`div`,{className:`_cppay-price-box`,children:(0,m.jsxs)(`div`,{className:`_cppay-price-row`,children:[(0,m.jsx)(`span`,{className:`_cppay-price-label`,children:`支付金额`}),(0,m.jsxs)(`div`,{className:`_cppay-price-amount`,children:[(0,m.jsxs)(`div`,{className:`_cppay-price-main`,children:[E,` `,y]}),(0,m.jsxs)(`div`,{className:`_cppay-price-sub`,children:[`≈ $`,i]})]})]})})}),(0,m.jsx)(`div`,{className:`_cppay-section`,children:(0,m.jsx)(`button`,{onClick:O,disabled:!_||!y||f,className:`_cppay-btn _cppay-btn-primary`,children:f?`处理中...`:`继续支付`})})]}):x&&(0,m.jsxs)(`div`,{children:[(0,m.jsx)(`div`,{className:`_cppay-qr-container`,children:(0,m.jsx)(`div`,{className:`_cppay-qr-placeholder`,children:(0,m.jsx)(`span`,{children:`扫码支付`})})}),(0,m.jsxs)(`div`,{className:`_cppay-section`,children:[(0,m.jsxs)(`div`,{className:`_cppay-info-box`,children:[(0,m.jsx)(`div`,{className:`_cppay-info-label`,children:`支付金额`}),(0,m.jsxs)(`div`,{className:`_cppay-info-value`,children:[x.paymentAmount,` `,y]})]}),(0,m.jsxs)(`div`,{className:`_cppay-info-box`,children:[(0,m.jsx)(`div`,{className:`_cppay-info-label`,children:`支付地址`}),(0,m.jsxs)(`div`,{className:`_cppay-address-row`,children:[(0,m.jsx)(`code`,{children:x.receiveAddress}),(0,m.jsx)(`button`,{onClick:A,className:`_cppay-copy-btn`,title:`复制地址`,children:(0,m.jsx)(`svg`,{fill:`none`,stroke:`currentColor`,viewBox:`0 0 24 24`,children:(0,m.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`})})})]})]})]}),(0,m.jsx)(`div`,{className:`_cppay-section`,children:(0,m.jsx)(`button`,{onClick:k,disabled:f,className:`_cppay-btn _cppay-btn-primary`,children:f?`检查支付状态...`:`我已完成支付`})}),(0,m.jsx)(`div`,{className:`_cppay-section`,children:(0,m.jsx)(`button`,{onClick:()=>d(`select`),disabled:f,className:`_cppay-btn _cppay-btn-secondary`,children:`更改支付方式`})})]})})]})}):null},g=u.default.memo(h);exports.PaymentDialog=g,exports.t=c;
|
|
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));const c=require(`./cppay-Bvf-Bb7R.cjs`),l=require(`./inject-style-Dz7JsQxo.cjs`);let u=require(`react`);u=s(u);let d=require(`react/jsx-runtime`);var f=({open:e,onClose:t,apiKey:n,orderId:r,amount:i,onSuccess:a,onError:o})=>{let s=(0,u.useMemo)(()=>new c.t(n),[n]),[l,f]=(0,u.useState)(`select`),[p,m]=(0,u.useState)(!1),[h,g]=(0,u.useState)([]),[_,v]=(0,u.useState)(``),[y,b]=(0,u.useState)(``),[x,S]=(0,u.useState)(null),C=(0,u.useMemo)(()=>h.find(e=>e.chain===_),[h,_]),w=(0,u.useMemo)(()=>C?.tokens||[],[C]),T=(0,u.useMemo)(()=>w.find(e=>e.symbol===y),[w,y]),E=(0,u.useMemo)(()=>y?(parseFloat(i)/1).toFixed(6):`0`,[i,y,1]),D=async()=>{try{m(!0);let e=await s.getSupportedChains();g(e),e.length>0&&v(e[0].chain)}catch(e){o?.(e)}finally{m(!1)}},O=async()=>{if(!(!_||!y))try{m(!0);let e=await s.createPayment({paymentChain:_,paymentToken:y,orderId:r,amount:E});S({paymentId:e.paymentId,paymentAmount:e.paymentAmount,receiveAddress:T?.receiveAddresses[0]||``}),f(`payment`)}catch(e){o?.(e)}finally{m(!1)}},k=async()=>{if(x)try{m(!0),await s.checkPaymentStatus(x.paymentId,1e3),a?.(x.paymentId),j()}catch(e){o?.(e)}finally{m(!1)}},A=async()=>{x?.receiveAddress&&await navigator.clipboard.writeText(x.receiveAddress)},j=()=>{t(),setTimeout(()=>{f(`select`),S(null)},300)};return(0,u.useEffect)(()=>{e&&h.length===0&&D()},[e]),(0,u.useEffect)(()=>{w.length>0&&b(w[0].symbol)},[w]),e?(0,d.jsx)(`div`,{className:`_cppay-overlay`,onClick:e=>e.target===e.currentTarget&&j(),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:l===`select`?`选择支付方式`:`完成支付`}),(0,d.jsx)(`button`,{onClick:j,disabled:p,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:l===`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:h.map(e=>(0,d.jsxs)(`button`,{onClick:()=>v(e.chain),className:`_cppay-select-btn ${_===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:w.map(e=>(0,d.jsxs)(`button`,{onClick:()=>b(e.symbol),className:`_cppay-select-btn ${y===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:[E,` `,y]}),(0,d.jsxs)(`div`,{className:`_cppay-price-sub`,children:[`≈ $`,i]})]})]})})}),(0,d.jsx)(`div`,{className:`_cppay-section`,children:(0,d.jsx)(`button`,{onClick:O,disabled:!_||!y||p,className:`_cppay-btn _cppay-btn-primary`,children:p?`处理中...`:`继续支付`})})]}):x&&(0,d.jsxs)(`div`,{children:[(0,d.jsx)(`div`,{className:`_cppay-qr-container`,children:(0,d.jsx)(`div`,{className:`_cppay-qr-placeholder`,children:(0,d.jsx)(`span`,{children:`扫码支付`})})}),(0,d.jsxs)(`div`,{className:`_cppay-section`,children:[(0,d.jsxs)(`div`,{className:`_cppay-info-box`,children:[(0,d.jsx)(`div`,{className:`_cppay-info-label`,children:`支付金额`}),(0,d.jsxs)(`div`,{className:`_cppay-info-value`,children:[x.paymentAmount,` `,y]})]}),(0,d.jsxs)(`div`,{className:`_cppay-info-box`,children:[(0,d.jsx)(`div`,{className:`_cppay-info-label`,children:`支付地址`}),(0,d.jsxs)(`div`,{className:`_cppay-address-row`,children:[(0,d.jsx)(`code`,{children:x.receiveAddress}),(0,d.jsx)(`button`,{onClick:A,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`})})})]})]})]}),(0,d.jsx)(`div`,{className:`_cppay-section`,children:(0,d.jsx)(`button`,{onClick:k,disabled:p,className:`_cppay-btn _cppay-btn-primary`,children:p?`检查支付状态...`:`我已完成支付`})}),(0,d.jsx)(`div`,{className:`_cppay-section`,children:(0,d.jsx)(`button`,{onClick:()=>f(`select`),disabled:p,className:`_cppay-btn _cppay-btn-secondary`,children:`更改支付方式`})})]})})]})}):null},p=u.default.memo(f);l.t(l.n),exports.PaymentDialog=p,exports.t=s;
|
package/dist/react.js
CHANGED
|
@@ -1,256 +1,79 @@
|
|
|
1
|
-
import { t as cppay_default } from "./cppay-
|
|
2
|
-
|
|
1
|
+
import { t as cppay_default } from "./cppay-Bz0NCjpC.js";
|
|
2
|
+
import { n as payment_dialog_default, t as injectStyle } from "./inject-style-qX_0AjjE.js";
|
|
3
3
|
import React, { useEffect, useMemo, useState } from "react";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
function n(e, n, r) {
|
|
10
|
-
var i = null;
|
|
11
|
-
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]);
|
|
12
|
-
else r = n;
|
|
13
|
-
return n = r.ref, {
|
|
14
|
-
$$typeof: t,
|
|
15
|
-
type: e,
|
|
16
|
-
key: i,
|
|
17
|
-
ref: n === void 0 ? null : n,
|
|
18
|
-
props: r
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
e.jsx = n, e.jsxs = n;
|
|
22
|
-
})), require_react_jsx_runtime_development = /* @__PURE__ */ __commonJSMin(((e) => {
|
|
23
|
-
process.env.NODE_ENV !== "production" && (function() {
|
|
24
|
-
function t(e) {
|
|
25
|
-
if (e == null) return null;
|
|
26
|
-
if (typeof e == "function") return e.$$typeof === k ? null : e.displayName || e.name || null;
|
|
27
|
-
if (typeof e == "string") return e;
|
|
28
|
-
switch (e) {
|
|
29
|
-
case v: return "Fragment";
|
|
30
|
-
case b: return "Profiler";
|
|
31
|
-
case y: return "StrictMode";
|
|
32
|
-
case w: return "Suspense";
|
|
33
|
-
case T: return "SuspenseList";
|
|
34
|
-
case O: return "Activity";
|
|
35
|
-
}
|
|
36
|
-
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) {
|
|
37
|
-
case _: return "Portal";
|
|
38
|
-
case S: return e.displayName || "Context";
|
|
39
|
-
case x: return (e._context.displayName || "Context") + ".Consumer";
|
|
40
|
-
case C:
|
|
41
|
-
var n = e.render;
|
|
42
|
-
return e = e.displayName, e ||= (e = n.displayName || n.name || "", e === "" ? "ForwardRef" : "ForwardRef(" + e + ")"), e;
|
|
43
|
-
case E: return n = e.displayName || null, n === null ? t(e.type) || "Memo" : n;
|
|
44
|
-
case D:
|
|
45
|
-
n = e._payload, e = e._init;
|
|
46
|
-
try {
|
|
47
|
-
return t(e(n));
|
|
48
|
-
} catch {}
|
|
49
|
-
}
|
|
50
|
-
return null;
|
|
51
|
-
}
|
|
52
|
-
function n(e) {
|
|
53
|
-
return "" + e;
|
|
54
|
-
}
|
|
55
|
-
function r(e) {
|
|
56
|
-
try {
|
|
57
|
-
n(e);
|
|
58
|
-
var t = !1;
|
|
59
|
-
} catch {
|
|
60
|
-
t = !0;
|
|
61
|
-
}
|
|
62
|
-
if (t) {
|
|
63
|
-
t = console;
|
|
64
|
-
var r = t.error, i = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
|
|
65
|
-
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);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
function i(e) {
|
|
69
|
-
if (e === v) return "<>";
|
|
70
|
-
if (typeof e == "object" && e && e.$$typeof === D) return "<...>";
|
|
71
|
-
try {
|
|
72
|
-
var n = t(e);
|
|
73
|
-
return n ? "<" + n + ">" : "<...>";
|
|
74
|
-
} catch {
|
|
75
|
-
return "<...>";
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
function a() {
|
|
79
|
-
var e = A.A;
|
|
80
|
-
return e === null ? null : e.getOwner();
|
|
81
|
-
}
|
|
82
|
-
function s() {
|
|
83
|
-
return Error("react-stack-top-frame");
|
|
84
|
-
}
|
|
85
|
-
function c(e) {
|
|
86
|
-
if (j.call(e, "key")) {
|
|
87
|
-
var t = Object.getOwnPropertyDescriptor(e, "key").get;
|
|
88
|
-
if (t && t.isReactWarning) return !1;
|
|
89
|
-
}
|
|
90
|
-
return e.key !== void 0;
|
|
91
|
-
}
|
|
92
|
-
function l(e, t) {
|
|
93
|
-
function n() {
|
|
94
|
-
P || (P = !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));
|
|
95
|
-
}
|
|
96
|
-
n.isReactWarning = !0, Object.defineProperty(e, "key", {
|
|
97
|
-
get: n,
|
|
98
|
-
configurable: !0
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
function u() {
|
|
102
|
-
var e = t(this.type);
|
|
103
|
-
return F[e] || (F[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;
|
|
104
|
-
}
|
|
105
|
-
function d(e, t, n, r, i, a) {
|
|
106
|
-
var o = n.ref;
|
|
107
|
-
return e = {
|
|
108
|
-
$$typeof: g,
|
|
109
|
-
type: e,
|
|
110
|
-
key: t,
|
|
111
|
-
props: n,
|
|
112
|
-
_owner: r
|
|
113
|
-
}, (o === void 0 ? null : o) === null ? Object.defineProperty(e, "ref", {
|
|
114
|
-
enumerable: !1,
|
|
115
|
-
value: null
|
|
116
|
-
}) : Object.defineProperty(e, "ref", {
|
|
117
|
-
enumerable: !1,
|
|
118
|
-
get: u
|
|
119
|
-
}), e._store = {}, Object.defineProperty(e._store, "validated", {
|
|
120
|
-
configurable: !1,
|
|
121
|
-
enumerable: !1,
|
|
122
|
-
writable: !0,
|
|
123
|
-
value: 0
|
|
124
|
-
}), Object.defineProperty(e, "_debugInfo", {
|
|
125
|
-
configurable: !1,
|
|
126
|
-
enumerable: !1,
|
|
127
|
-
writable: !0,
|
|
128
|
-
value: null
|
|
129
|
-
}), Object.defineProperty(e, "_debugStack", {
|
|
130
|
-
configurable: !1,
|
|
131
|
-
enumerable: !1,
|
|
132
|
-
writable: !0,
|
|
133
|
-
value: i
|
|
134
|
-
}), Object.defineProperty(e, "_debugTask", {
|
|
135
|
-
configurable: !1,
|
|
136
|
-
enumerable: !1,
|
|
137
|
-
writable: !0,
|
|
138
|
-
value: a
|
|
139
|
-
}), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
|
|
140
|
-
}
|
|
141
|
-
function f(e, n, i, o, s, u) {
|
|
142
|
-
var f = n.children;
|
|
143
|
-
if (f !== void 0) if (o) if (M(f)) {
|
|
144
|
-
for (o = 0; o < f.length; o++) p(f[o]);
|
|
145
|
-
Object.freeze && Object.freeze(f);
|
|
146
|
-
} 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.");
|
|
147
|
-
else p(f);
|
|
148
|
-
if (j.call(n, "key")) {
|
|
149
|
-
f = t(e);
|
|
150
|
-
var m = Object.keys(n).filter(function(e) {
|
|
151
|
-
return e !== "key";
|
|
152
|
-
});
|
|
153
|
-
o = 0 < m.length ? "{key: someKey, " + m.join(": ..., ") + ": ...}" : "{key: someKey}", R[f + o] || (m = 0 < m.length ? "{" + m.join(": ..., ") + ": ...}" : "{}", console.error("A props object containing a \"key\" prop is being spread into JSX:\n let props = %s;\n <%s {...props} />\nReact keys must be passed directly to JSX without using spread:\n let props = %s;\n <%s key={someKey} {...props} />", o, f, m, f), R[f + o] = !0);
|
|
154
|
-
}
|
|
155
|
-
if (f = null, i !== void 0 && (r(i), f = "" + i), c(n) && (r(n.key), f = "" + n.key), "key" in n) for (var h in i = {}, n) h !== "key" && (i[h] = n[h]);
|
|
156
|
-
else i = n;
|
|
157
|
-
return f && l(i, typeof e == "function" ? e.displayName || e.name || "Unknown" : e), d(e, f, i, a(), s, u);
|
|
158
|
-
}
|
|
159
|
-
function p(e) {
|
|
160
|
-
m(e) ? e._store && (e._store.validated = 1) : typeof e == "object" && e && e.$$typeof === D && (e._payload.status === "fulfilled" ? m(e._payload.value) && e._payload.value._store && (e._payload.value._store.validated = 1) : e._store && (e._store.validated = 1));
|
|
161
|
-
}
|
|
162
|
-
function m(e) {
|
|
163
|
-
return typeof e == "object" && !!e && e.$$typeof === g;
|
|
164
|
-
}
|
|
165
|
-
var h = __require("react"), g = Symbol.for("react.transitional.element"), _ = Symbol.for("react.portal"), v = Symbol.for("react.fragment"), y = Symbol.for("react.strict_mode"), b = Symbol.for("react.profiler"), x = Symbol.for("react.consumer"), S = Symbol.for("react.context"), C = Symbol.for("react.forward_ref"), w = Symbol.for("react.suspense"), T = Symbol.for("react.suspense_list"), E = Symbol.for("react.memo"), D = Symbol.for("react.lazy"), O = Symbol.for("react.activity"), k = Symbol.for("react.client.reference"), A = h.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, j = Object.prototype.hasOwnProperty, M = Array.isArray, N = console.createTask ? console.createTask : function() {
|
|
166
|
-
return null;
|
|
167
|
-
};
|
|
168
|
-
h = { react_stack_bottom_frame: function(e) {
|
|
169
|
-
return e();
|
|
170
|
-
} };
|
|
171
|
-
var P, F = {}, I = h.react_stack_bottom_frame.bind(h, s)(), L = N(i(s)), R = {};
|
|
172
|
-
e.Fragment = v, e.jsx = function(e, t, n) {
|
|
173
|
-
var r = 1e4 > A.recentlyCreatedOwnerStacks++;
|
|
174
|
-
return f(e, t, n, !1, r ? Error("react-stack-top-frame") : I, r ? N(i(e)) : L);
|
|
175
|
-
}, e.jsxs = function(e, t, n) {
|
|
176
|
-
var r = 1e4 > A.recentlyCreatedOwnerStacks++;
|
|
177
|
-
return f(e, t, n, !0, r ? Error("react-stack-top-frame") : I, r ? N(i(e)) : L);
|
|
178
|
-
};
|
|
179
|
-
})();
|
|
180
|
-
})), import_jsx_runtime = (/* @__PURE__ */ __commonJSMin(((e, t) => {
|
|
181
|
-
process.env.NODE_ENV === "production" ? t.exports = require_react_jsx_runtime_production() : t.exports = require_react_jsx_runtime_development();
|
|
182
|
-
})))(), PaymentDialog_default = React.memo(({ open: t, onClose: a, apiKey: o, orderId: s, amount: c, onSuccess: u, onError: d }) => {
|
|
183
|
-
let f = useMemo(() => new cppay_default(o), [o]), [p, m] = useState("select"), [h, g] = useState(!1), [_, v] = useState([]), [y, b] = useState(""), [x, S] = useState(""), [C, w] = useState(null), T = useMemo(() => _.find((e) => e.chain === y), [_, y]), E = useMemo(() => T?.tokens || [], [T]), D = useMemo(() => E.find((e) => e.symbol === x), [E, x]), O = useMemo(() => x ? (parseFloat(c) / 1).toFixed(6) : "0", [
|
|
184
|
-
c,
|
|
185
|
-
x,
|
|
4
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
+
var PaymentDialog_default = React.memo(({ open: o, onClose: s, apiKey: c, orderId: l, amount: u, onSuccess: d, onError: f }) => {
|
|
6
|
+
let p = useMemo(() => new cppay_default(c), [c]), [m, h] = useState("select"), [g, _] = useState(!1), [v, y] = useState([]), [b, x] = useState(""), [S, C] = useState(""), [w, T] = useState(null), E = useMemo(() => v.find((t) => t.chain === b), [v, b]), D = useMemo(() => E?.tokens || [], [E]), O = useMemo(() => D.find((t) => t.symbol === S), [D, S]), k = useMemo(() => S ? (parseFloat(u) / 1).toFixed(6) : "0", [
|
|
7
|
+
u,
|
|
8
|
+
S,
|
|
186
9
|
1
|
|
187
|
-
]),
|
|
10
|
+
]), A = async () => {
|
|
188
11
|
try {
|
|
189
|
-
|
|
190
|
-
let
|
|
191
|
-
|
|
192
|
-
} catch (
|
|
193
|
-
|
|
12
|
+
_(!0);
|
|
13
|
+
let t = await p.getSupportedChains();
|
|
14
|
+
y(t), t.length > 0 && x(t[0].chain);
|
|
15
|
+
} catch (t) {
|
|
16
|
+
f?.(t);
|
|
194
17
|
} finally {
|
|
195
|
-
|
|
18
|
+
_(!1);
|
|
196
19
|
}
|
|
197
|
-
},
|
|
198
|
-
if (!(!
|
|
199
|
-
|
|
200
|
-
let
|
|
201
|
-
paymentChain:
|
|
202
|
-
paymentToken:
|
|
203
|
-
orderId:
|
|
204
|
-
amount:
|
|
20
|
+
}, j = async () => {
|
|
21
|
+
if (!(!b || !S)) try {
|
|
22
|
+
_(!0);
|
|
23
|
+
let t = await p.createPayment({
|
|
24
|
+
paymentChain: b,
|
|
25
|
+
paymentToken: S,
|
|
26
|
+
orderId: l,
|
|
27
|
+
amount: k
|
|
205
28
|
});
|
|
206
|
-
|
|
207
|
-
paymentId:
|
|
208
|
-
paymentAmount:
|
|
209
|
-
receiveAddress:
|
|
210
|
-
}),
|
|
211
|
-
} catch (
|
|
212
|
-
|
|
29
|
+
T({
|
|
30
|
+
paymentId: t.paymentId,
|
|
31
|
+
paymentAmount: t.paymentAmount,
|
|
32
|
+
receiveAddress: O?.receiveAddresses[0] || ""
|
|
33
|
+
}), h("payment");
|
|
34
|
+
} catch (t) {
|
|
35
|
+
f?.(t);
|
|
213
36
|
} finally {
|
|
214
|
-
|
|
37
|
+
_(!1);
|
|
215
38
|
}
|
|
216
|
-
},
|
|
217
|
-
if (
|
|
218
|
-
|
|
219
|
-
} catch (
|
|
220
|
-
|
|
39
|
+
}, M = async () => {
|
|
40
|
+
if (w) try {
|
|
41
|
+
_(!0), await p.checkPaymentStatus(w.paymentId, 1e3), d?.(w.paymentId), P();
|
|
42
|
+
} catch (t) {
|
|
43
|
+
f?.(t);
|
|
221
44
|
} finally {
|
|
222
|
-
|
|
45
|
+
_(!1);
|
|
223
46
|
}
|
|
224
|
-
},
|
|
225
|
-
|
|
226
|
-
},
|
|
227
|
-
|
|
228
|
-
|
|
47
|
+
}, N = async () => {
|
|
48
|
+
w?.receiveAddress && await navigator.clipboard.writeText(w.receiveAddress);
|
|
49
|
+
}, P = () => {
|
|
50
|
+
s(), setTimeout(() => {
|
|
51
|
+
h("select"), T(null);
|
|
229
52
|
}, 300);
|
|
230
53
|
};
|
|
231
54
|
return useEffect(() => {
|
|
232
|
-
|
|
233
|
-
}, [
|
|
234
|
-
|
|
235
|
-
}, [
|
|
55
|
+
o && v.length === 0 && A();
|
|
56
|
+
}, [o]), useEffect(() => {
|
|
57
|
+
D.length > 0 && C(D[0].symbol);
|
|
58
|
+
}, [D]), o ? /* @__PURE__ */ jsx("div", {
|
|
236
59
|
className: "_cppay-overlay",
|
|
237
|
-
onClick: (
|
|
238
|
-
children: /* @__PURE__ */
|
|
60
|
+
onClick: (t) => t.target === t.currentTarget && P(),
|
|
61
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
239
62
|
className: "_cppay-dialog",
|
|
240
|
-
children: [/* @__PURE__ */
|
|
63
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
241
64
|
className: "_cppay-header",
|
|
242
|
-
children: [/* @__PURE__ */
|
|
65
|
+
children: [/* @__PURE__ */ jsx("h2", {
|
|
243
66
|
className: "_cppay-title",
|
|
244
|
-
children:
|
|
245
|
-
}), /* @__PURE__ */
|
|
246
|
-
onClick:
|
|
247
|
-
disabled:
|
|
67
|
+
children: m === "select" ? "选择支付方式" : "完成支付"
|
|
68
|
+
}), /* @__PURE__ */ jsx("button", {
|
|
69
|
+
onClick: P,
|
|
70
|
+
disabled: g,
|
|
248
71
|
className: "_cppay-close-btn",
|
|
249
|
-
children: /* @__PURE__ */
|
|
72
|
+
children: /* @__PURE__ */ jsx("svg", {
|
|
250
73
|
fill: "none",
|
|
251
74
|
stroke: "currentColor",
|
|
252
75
|
viewBox: "0 0 24 24",
|
|
253
|
-
children: /* @__PURE__ */
|
|
76
|
+
children: /* @__PURE__ */ jsx("path", {
|
|
254
77
|
strokeLinecap: "round",
|
|
255
78
|
strokeLinejoin: "round",
|
|
256
79
|
strokeWidth: 2,
|
|
@@ -258,117 +81,117 @@ var __commonJSMin = (e, t) => () => (t || e((t = { exports: {} }).exports, t), t
|
|
|
258
81
|
})
|
|
259
82
|
})
|
|
260
83
|
})]
|
|
261
|
-
}), /* @__PURE__ */
|
|
84
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
262
85
|
className: "_cppay-content",
|
|
263
|
-
children:
|
|
264
|
-
/* @__PURE__ */
|
|
86
|
+
children: m === "select" ? /* @__PURE__ */ jsxs("div", { children: [
|
|
87
|
+
/* @__PURE__ */ jsxs("div", {
|
|
265
88
|
className: "_cppay-section",
|
|
266
|
-
children: [/* @__PURE__ */
|
|
89
|
+
children: [/* @__PURE__ */ jsx("label", {
|
|
267
90
|
className: "_cppay-label",
|
|
268
91
|
children: "支付网络"
|
|
269
|
-
}), /* @__PURE__ */
|
|
92
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
270
93
|
className: "_cppay-grid",
|
|
271
|
-
children:
|
|
272
|
-
onClick: () =>
|
|
273
|
-
className: `_cppay-select-btn ${
|
|
274
|
-
children: [
|
|
275
|
-
src:
|
|
276
|
-
alt:
|
|
277
|
-
}), /* @__PURE__ */
|
|
278
|
-
},
|
|
94
|
+
children: v.map((t) => /* @__PURE__ */ jsxs("button", {
|
|
95
|
+
onClick: () => x(t.chain),
|
|
96
|
+
className: `_cppay-select-btn ${b === t.chain ? "_cppay-selected" : ""}`,
|
|
97
|
+
children: [t.icon && /* @__PURE__ */ jsx("img", {
|
|
98
|
+
src: t.icon,
|
|
99
|
+
alt: t.chain
|
|
100
|
+
}), /* @__PURE__ */ jsx("span", { children: t.chain })]
|
|
101
|
+
}, t.chain))
|
|
279
102
|
})]
|
|
280
103
|
}),
|
|
281
|
-
/* @__PURE__ */
|
|
104
|
+
/* @__PURE__ */ jsxs("div", {
|
|
282
105
|
className: "_cppay-section",
|
|
283
|
-
children: [/* @__PURE__ */
|
|
106
|
+
children: [/* @__PURE__ */ jsx("label", {
|
|
284
107
|
className: "_cppay-label",
|
|
285
108
|
children: "支付代币"
|
|
286
|
-
}), /* @__PURE__ */
|
|
109
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
287
110
|
className: "_cppay-grid",
|
|
288
|
-
children:
|
|
289
|
-
onClick: () =>
|
|
290
|
-
className: `_cppay-select-btn ${
|
|
291
|
-
children: [
|
|
292
|
-
src:
|
|
293
|
-
alt:
|
|
294
|
-
}), /* @__PURE__ */
|
|
295
|
-
},
|
|
111
|
+
children: D.map((t) => /* @__PURE__ */ jsxs("button", {
|
|
112
|
+
onClick: () => C(t.symbol),
|
|
113
|
+
className: `_cppay-select-btn ${S === t.symbol ? "_cppay-selected" : ""}`,
|
|
114
|
+
children: [t.icon && /* @__PURE__ */ jsx("img", {
|
|
115
|
+
src: t.icon,
|
|
116
|
+
alt: t.symbol
|
|
117
|
+
}), /* @__PURE__ */ jsx("span", { children: t.symbol })]
|
|
118
|
+
}, t.symbol))
|
|
296
119
|
})]
|
|
297
120
|
}),
|
|
298
|
-
/* @__PURE__ */
|
|
121
|
+
/* @__PURE__ */ jsx("div", {
|
|
299
122
|
className: "_cppay-section",
|
|
300
|
-
children: /* @__PURE__ */
|
|
123
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
301
124
|
className: "_cppay-price-box",
|
|
302
|
-
children: /* @__PURE__ */
|
|
125
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
303
126
|
className: "_cppay-price-row",
|
|
304
|
-
children: [/* @__PURE__ */
|
|
127
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
305
128
|
className: "_cppay-price-label",
|
|
306
129
|
children: "支付金额"
|
|
307
|
-
}), /* @__PURE__ */
|
|
130
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
308
131
|
className: "_cppay-price-amount",
|
|
309
|
-
children: [/* @__PURE__ */
|
|
132
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
310
133
|
className: "_cppay-price-main",
|
|
311
134
|
children: [
|
|
312
|
-
|
|
135
|
+
k,
|
|
313
136
|
" ",
|
|
314
|
-
|
|
137
|
+
S
|
|
315
138
|
]
|
|
316
|
-
}), /* @__PURE__ */
|
|
139
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
317
140
|
className: "_cppay-price-sub",
|
|
318
|
-
children: ["≈ $",
|
|
141
|
+
children: ["≈ $", u]
|
|
319
142
|
})]
|
|
320
143
|
})]
|
|
321
144
|
})
|
|
322
145
|
})
|
|
323
146
|
}),
|
|
324
|
-
/* @__PURE__ */
|
|
147
|
+
/* @__PURE__ */ jsx("div", {
|
|
325
148
|
className: "_cppay-section",
|
|
326
|
-
children: /* @__PURE__ */
|
|
327
|
-
onClick:
|
|
328
|
-
disabled: !
|
|
149
|
+
children: /* @__PURE__ */ jsx("button", {
|
|
150
|
+
onClick: j,
|
|
151
|
+
disabled: !b || !S || g,
|
|
329
152
|
className: "_cppay-btn _cppay-btn-primary",
|
|
330
|
-
children:
|
|
153
|
+
children: g ? "处理中..." : "继续支付"
|
|
331
154
|
})
|
|
332
155
|
})
|
|
333
|
-
] }) :
|
|
334
|
-
/* @__PURE__ */
|
|
156
|
+
] }) : w && /* @__PURE__ */ jsxs("div", { children: [
|
|
157
|
+
/* @__PURE__ */ jsx("div", {
|
|
335
158
|
className: "_cppay-qr-container",
|
|
336
|
-
children: /* @__PURE__ */
|
|
159
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
337
160
|
className: "_cppay-qr-placeholder",
|
|
338
|
-
children: /* @__PURE__ */
|
|
161
|
+
children: /* @__PURE__ */ jsx("span", { children: "扫码支付" })
|
|
339
162
|
})
|
|
340
163
|
}),
|
|
341
|
-
/* @__PURE__ */
|
|
164
|
+
/* @__PURE__ */ jsxs("div", {
|
|
342
165
|
className: "_cppay-section",
|
|
343
|
-
children: [/* @__PURE__ */
|
|
166
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
344
167
|
className: "_cppay-info-box",
|
|
345
|
-
children: [/* @__PURE__ */
|
|
168
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
346
169
|
className: "_cppay-info-label",
|
|
347
170
|
children: "支付金额"
|
|
348
|
-
}), /* @__PURE__ */
|
|
171
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
349
172
|
className: "_cppay-info-value",
|
|
350
173
|
children: [
|
|
351
|
-
|
|
174
|
+
w.paymentAmount,
|
|
352
175
|
" ",
|
|
353
|
-
|
|
176
|
+
S
|
|
354
177
|
]
|
|
355
178
|
})]
|
|
356
|
-
}), /* @__PURE__ */
|
|
179
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
357
180
|
className: "_cppay-info-box",
|
|
358
|
-
children: [/* @__PURE__ */
|
|
181
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
359
182
|
className: "_cppay-info-label",
|
|
360
183
|
children: "支付地址"
|
|
361
|
-
}), /* @__PURE__ */
|
|
184
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
362
185
|
className: "_cppay-address-row",
|
|
363
|
-
children: [/* @__PURE__ */
|
|
364
|
-
onClick:
|
|
186
|
+
children: [/* @__PURE__ */ jsx("code", { children: w.receiveAddress }), /* @__PURE__ */ jsx("button", {
|
|
187
|
+
onClick: N,
|
|
365
188
|
className: "_cppay-copy-btn",
|
|
366
189
|
title: "复制地址",
|
|
367
|
-
children: /* @__PURE__ */
|
|
190
|
+
children: /* @__PURE__ */ jsx("svg", {
|
|
368
191
|
fill: "none",
|
|
369
192
|
stroke: "currentColor",
|
|
370
193
|
viewBox: "0 0 24 24",
|
|
371
|
-
children: /* @__PURE__ */
|
|
194
|
+
children: /* @__PURE__ */ jsx("path", {
|
|
372
195
|
strokeLinecap: "round",
|
|
373
196
|
strokeLinejoin: "round",
|
|
374
197
|
strokeWidth: 2,
|
|
@@ -379,20 +202,20 @@ var __commonJSMin = (e, t) => () => (t || e((t = { exports: {} }).exports, t), t
|
|
|
379
202
|
})]
|
|
380
203
|
})]
|
|
381
204
|
}),
|
|
382
|
-
/* @__PURE__ */
|
|
205
|
+
/* @__PURE__ */ jsx("div", {
|
|
383
206
|
className: "_cppay-section",
|
|
384
|
-
children: /* @__PURE__ */
|
|
385
|
-
onClick:
|
|
386
|
-
disabled:
|
|
207
|
+
children: /* @__PURE__ */ jsx("button", {
|
|
208
|
+
onClick: M,
|
|
209
|
+
disabled: g,
|
|
387
210
|
className: "_cppay-btn _cppay-btn-primary",
|
|
388
|
-
children:
|
|
211
|
+
children: g ? "检查支付状态..." : "我已完成支付"
|
|
389
212
|
})
|
|
390
213
|
}),
|
|
391
|
-
/* @__PURE__ */
|
|
214
|
+
/* @__PURE__ */ jsx("div", {
|
|
392
215
|
className: "_cppay-section",
|
|
393
|
-
children: /* @__PURE__ */
|
|
394
|
-
onClick: () =>
|
|
395
|
-
disabled:
|
|
216
|
+
children: /* @__PURE__ */ jsx("button", {
|
|
217
|
+
onClick: () => h("select"),
|
|
218
|
+
disabled: g,
|
|
396
219
|
className: "_cppay-btn _cppay-btn-secondary",
|
|
397
220
|
children: "更改支付方式"
|
|
398
221
|
})
|
|
@@ -402,4 +225,5 @@ var __commonJSMin = (e, t) => () => (t || e((t = { exports: {} }).exports, t), t
|
|
|
402
225
|
})
|
|
403
226
|
}) : null;
|
|
404
227
|
});
|
|
228
|
+
injectStyle(payment_dialog_default);
|
|
405
229
|
export { PaymentDialog_default as PaymentDialog };
|
package/dist/vue.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require(`./cppay-
|
|
1
|
+
const e=require(`./cppay-Bvf-Bb7R.cjs`),t=require(`./inject-style-Dz7JsQxo.cjs`),n=require(`./react.cjs`);let r=require(`vue`);var i={class:`_cppay-dialog`},a={class:`_cppay-header`},o={class:`_cppay-title`},s=[`disabled`],c={class:`_cppay-content`},l={key:0},u={class:`_cppay-section`},d={class:`_cppay-grid`},f=[`onClick`],p=[`src`,`alt`],m={class:`_cppay-section`},h={class:`_cppay-grid`},g=[`onClick`],_=[`src`,`alt`],v={class:`_cppay-section`},y={class:`_cppay-price-box`},b={class:`_cppay-price-row`},x={class:`_cppay-price-amount`},S={class:`_cppay-price-main`},C={class:`_cppay-price-sub`},w={class:`_cppay-section`},T=[`disabled`],E={key:1},D={class:`_cppay-section`},O={class:`_cppay-info-box`},k={class:`_cppay-info-value`},A={class:`_cppay-info-box`},j={class:`_cppay-address-row`},M={class:`_cppay-section`},ee=[`disabled`],N={class:`_cppay-section`},P=[`disabled`],F=(0,r.defineComponent)({__name:`PaymentDialog`,props:{modelValue:{type:Boolean},apiKey:{},orderId:{},amount:{}},emits:[`update:modelValue`,`success`,`error`],setup(t,{emit:n}){let F=t,I=n,L=new e.t(F.apiKey),R=(0,r.ref)(`select`),z=(0,r.ref)(!1),B=(0,r.ref)([]),V=(0,r.ref)(``),H=(0,r.ref)(``),U=(0,r.ref)(null),W=(0,r.computed)(()=>B.value.find(e=>e.chain===V.value)),G=(0,r.computed)(()=>W.value?.tokens||[]),K=(0,r.computed)(()=>G.value.find(e=>e.symbol===H.value)),q=(0,r.ref)(1),J=(0,r.computed)(()=>H.value?(parseFloat(F.amount)/q.value).toFixed(6):`0`),Y=()=>{I(`update:modelValue`,!1),setTimeout(()=>{R.value=`select`,U.value=null},300)},X=async()=>{try{z.value=!0,B.value=await L.getSupportedChains(),B.value.length>0&&(V.value=B.value[0].chain)}catch(e){I(`error`,e)}finally{z.value=!1}},Z=async()=>{if(!(!V.value||!H.value))try{z.value=!0;let e=await L.createPayment({paymentChain:V.value,paymentToken:H.value,orderId:F.orderId,amount:J.value});U.value={paymentId:e.paymentId,paymentAmount:e.paymentAmount,receiveAddress:K.value?.receiveAddresses[0]||``},R.value=`payment`}catch(e){I(`error`,e)}finally{z.value=!1}},Q=async()=>{if(U.value)try{z.value=!0,await L.checkPaymentStatus(U.value.paymentId,1e3),I(`success`,U.value.paymentId),Y()}catch(e){I(`error`,e)}finally{z.value=!1}},$=async()=>{U.value?.receiveAddress&&await navigator.clipboard.writeText(U.value.receiveAddress)};return(0,r.watch)(()=>F.modelValue,e=>{e&&B.value.length===0&&X()}),(0,r.watch)(V,()=>{G.value.length>0&&(H.value=G.value[0].symbol)}),(e,n)=>((0,r.openBlock)(),(0,r.createBlock)(r.Teleport,{to:`body`},[(0,r.createVNode)(r.Transition,{name:`_cppay-fade`},{default:(0,r.withCtx)(()=>[t.modelValue?((0,r.openBlock)(),(0,r.createElementBlock)(`div`,{key:0,class:`_cppay-overlay`,onClick:(0,r.withModifiers)(Y,[`self`])},[(0,r.createElementVNode)(`div`,i,[(0,r.createElementVNode)(`div`,a,[(0,r.createElementVNode)(`h2`,o,(0,r.toDisplayString)(R.value===`select`?`选择支付方式`:`完成支付`),1),(0,r.createElementVNode)(`button`,{onClick:Y,class:`_cppay-close-btn`,disabled:z.value},[...n[1]||=[(0,r.createElementVNode)(`svg`,{fill:`none`,stroke:`currentColor`,viewBox:`0 0 24 24`},[(0,r.createElementVNode)(`path`,{"stroke-linecap":`round`,"stroke-linejoin":`round`,"stroke-width":`2`,d:`M6 18L18 6M6 6l12 12`})],-1)]],8,s)]),(0,r.createElementVNode)(`div`,c,[R.value===`select`?((0,r.openBlock)(),(0,r.createElementBlock)(`div`,l,[(0,r.createElementVNode)(`div`,u,[n[2]||=(0,r.createElementVNode)(`label`,{class:`_cppay-label`},`支付网络`,-1),(0,r.createElementVNode)(`div`,d,[((0,r.openBlock)(!0),(0,r.createElementBlock)(r.Fragment,null,(0,r.renderList)(B.value,e=>((0,r.openBlock)(),(0,r.createElementBlock)(`button`,{key:e.chain,onClick:t=>V.value=e.chain,class:(0,r.normalizeClass)([`_cppay-select-btn`,V.value===e.chain?`_cppay-selected`:``])},[e.icon?((0,r.openBlock)(),(0,r.createElementBlock)(`img`,{key:0,src:e.icon,alt:e.chain},null,8,p)):(0,r.createCommentVNode)(``,!0),(0,r.createElementVNode)(`span`,null,(0,r.toDisplayString)(e.chain),1)],10,f))),128))])]),(0,r.createElementVNode)(`div`,m,[n[3]||=(0,r.createElementVNode)(`label`,{class:`_cppay-label`},`支付代币`,-1),(0,r.createElementVNode)(`div`,h,[((0,r.openBlock)(!0),(0,r.createElementBlock)(r.Fragment,null,(0,r.renderList)(G.value,e=>((0,r.openBlock)(),(0,r.createElementBlock)(`button`,{key:e.symbol,onClick:t=>H.value=e.symbol,class:(0,r.normalizeClass)([`_cppay-select-btn`,H.value===e.symbol?`_cppay-selected`:``])},[e.icon?((0,r.openBlock)(),(0,r.createElementBlock)(`img`,{key:0,src:e.icon,alt:e.symbol},null,8,_)):(0,r.createCommentVNode)(``,!0),(0,r.createElementVNode)(`span`,null,(0,r.toDisplayString)(e.symbol),1)],10,g))),128))])]),(0,r.createElementVNode)(`div`,v,[(0,r.createElementVNode)(`div`,y,[(0,r.createElementVNode)(`div`,b,[n[4]||=(0,r.createElementVNode)(`span`,{class:`_cppay-price-label`},`支付金额`,-1),(0,r.createElementVNode)(`div`,x,[(0,r.createElementVNode)(`div`,S,(0,r.toDisplayString)(J.value)+` `+(0,r.toDisplayString)(H.value),1),(0,r.createElementVNode)(`div`,C,`≈ $`+(0,r.toDisplayString)(t.amount),1)])])])]),(0,r.createElementVNode)(`div`,w,[(0,r.createElementVNode)(`button`,{onClick:Z,disabled:!V.value||!H.value||z.value,class:`_cppay-btn _cppay-btn-primary`},(0,r.toDisplayString)(z.value?`处理中...`:`继续支付`),9,T)])])):R.value===`payment`&&U.value?((0,r.openBlock)(),(0,r.createElementBlock)(`div`,E,[n[8]||=(0,r.createElementVNode)(`div`,{class:`_cppay-qr-container`},[(0,r.createElementVNode)(`div`,{class:`_cppay-qr-placeholder`},[(0,r.createElementVNode)(`span`,null,`扫码支付`)])],-1),(0,r.createElementVNode)(`div`,D,[(0,r.createElementVNode)(`div`,O,[n[5]||=(0,r.createElementVNode)(`div`,{class:`_cppay-info-label`},`支付金额`,-1),(0,r.createElementVNode)(`div`,k,(0,r.toDisplayString)(U.value.paymentAmount)+` `+(0,r.toDisplayString)(H.value),1)]),(0,r.createElementVNode)(`div`,A,[n[7]||=(0,r.createElementVNode)(`div`,{class:`_cppay-info-label`},`支付地址`,-1),(0,r.createElementVNode)(`div`,j,[(0,r.createElementVNode)(`code`,null,(0,r.toDisplayString)(U.value.receiveAddress),1),(0,r.createElementVNode)(`button`,{onClick:$,class:`_cppay-copy-btn`,title:`复制地址`},[...n[6]||=[(0,r.createElementVNode)(`svg`,{fill:`none`,stroke:`currentColor`,viewBox:`0 0 24 24`},[(0,r.createElementVNode)(`path`,{"stroke-linecap":`round`,"stroke-linejoin":`round`,"stroke-width":`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`})],-1)]])])])]),(0,r.createElementVNode)(`div`,M,[(0,r.createElementVNode)(`button`,{onClick:Q,disabled:z.value,class:`_cppay-btn _cppay-btn-primary`},(0,r.toDisplayString)(z.value?`检查支付状态...`:`我已完成支付`),9,ee)]),(0,r.createElementVNode)(`div`,N,[(0,r.createElementVNode)(`button`,{onClick:n[0]||=e=>R.value=`select`,disabled:z.value,class:`_cppay-btn _cppay-btn-secondary`},` 更改支付方式 `,8,P)])])):(0,r.createCommentVNode)(``,!0)])])])):(0,r.createCommentVNode)(``,!0)]),_:1})]))}}),I=(e,t)=>{let n=e.__vccOpts||e;for(let[e,r]of t)n[e]=r;return n},L=I(F,[[`__scopeId`,`data-v-a66fc55b`]]);t.t(t.n),exports.PaymentDialog=L;
|
package/dist/vue.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { t as cppay_default } from "./cppay-
|
|
2
|
-
|
|
1
|
+
import { t as cppay_default } from "./cppay-Bz0NCjpC.js";
|
|
2
|
+
import { n as payment_dialog_default, t as injectStyle } from "./inject-style-qX_0AjjE.js";
|
|
3
3
|
import { Fragment, Teleport, Transition, computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createVNode, defineComponent, normalizeClass, openBlock, ref, renderList, toDisplayString, watch, withCtx, withModifiers } from "vue";
|
|
4
|
-
var _hoisted_1 = { class: "_cppay-dialog" }, _hoisted_2 = { class: "_cppay-header" }, _hoisted_3 = { class: "_cppay-title" }, _hoisted_4 = ["disabled"], _hoisted_5 = { class: "_cppay-content" }, _hoisted_6 = { key: 0 }, _hoisted_7 = { class: "_cppay-section" }, _hoisted_8 = { class: "_cppay-grid" }, _hoisted_9 = ["onClick"], _hoisted_10 = ["src", "alt"], _hoisted_11 = { class: "_cppay-section" }, _hoisted_12 = { class: "_cppay-grid" }, _hoisted_13 = ["onClick"], _hoisted_14 = ["src", "alt"], _hoisted_15 = { class: "_cppay-section" }, _hoisted_16 = { class: "_cppay-price-box" }, _hoisted_17 = { class: "_cppay-price-row" }, _hoisted_18 = { class: "_cppay-price-amount" }, _hoisted_19 = { class: "_cppay-price-main" }, _hoisted_20 = { class: "_cppay-price-sub" }, _hoisted_21 = { class: "_cppay-section" }, _hoisted_22 = ["disabled"], _hoisted_23 = { key: 1 }, _hoisted_24 = { class: "_cppay-section" }, _hoisted_25 = { class: "_cppay-info-box" }, _hoisted_26 = { class: "_cppay-info-value" }, _hoisted_27 = { class: "_cppay-info-box" }, _hoisted_28 = { class: "_cppay-address-row" }, _hoisted_29 = { class: "_cppay-section" }, _hoisted_30 = ["disabled"], _hoisted_31 = { class: "_cppay-section" }, _hoisted_32 = ["disabled"], PaymentDialog_default = /* @__PURE__ */ ((
|
|
5
|
-
let
|
|
6
|
-
for (let [
|
|
7
|
-
return
|
|
4
|
+
var _hoisted_1 = { class: "_cppay-dialog" }, _hoisted_2 = { class: "_cppay-header" }, _hoisted_3 = { class: "_cppay-title" }, _hoisted_4 = ["disabled"], _hoisted_5 = { class: "_cppay-content" }, _hoisted_6 = { key: 0 }, _hoisted_7 = { class: "_cppay-section" }, _hoisted_8 = { class: "_cppay-grid" }, _hoisted_9 = ["onClick"], _hoisted_10 = ["src", "alt"], _hoisted_11 = { class: "_cppay-section" }, _hoisted_12 = { class: "_cppay-grid" }, _hoisted_13 = ["onClick"], _hoisted_14 = ["src", "alt"], _hoisted_15 = { class: "_cppay-section" }, _hoisted_16 = { class: "_cppay-price-box" }, _hoisted_17 = { class: "_cppay-price-row" }, _hoisted_18 = { class: "_cppay-price-amount" }, _hoisted_19 = { class: "_cppay-price-main" }, _hoisted_20 = { class: "_cppay-price-sub" }, _hoisted_21 = { class: "_cppay-section" }, _hoisted_22 = ["disabled"], _hoisted_23 = { key: 1 }, _hoisted_24 = { class: "_cppay-section" }, _hoisted_25 = { class: "_cppay-info-box" }, _hoisted_26 = { class: "_cppay-info-value" }, _hoisted_27 = { class: "_cppay-info-box" }, _hoisted_28 = { class: "_cppay-address-row" }, _hoisted_29 = { class: "_cppay-section" }, _hoisted_30 = ["disabled"], _hoisted_31 = { class: "_cppay-section" }, _hoisted_32 = ["disabled"], PaymentDialog_default = /* @__PURE__ */ ((r, M) => {
|
|
5
|
+
let N = r.__vccOpts || r;
|
|
6
|
+
for (let [r, P] of M) N[r] = P;
|
|
7
|
+
return N;
|
|
8
8
|
})(/* @__PURE__ */ defineComponent({
|
|
9
9
|
__name: "PaymentDialog",
|
|
10
10
|
props: {
|
|
@@ -18,55 +18,55 @@ var _hoisted_1 = { class: "_cppay-dialog" }, _hoisted_2 = { class: "_cppay-heade
|
|
|
18
18
|
"success",
|
|
19
19
|
"error"
|
|
20
20
|
],
|
|
21
|
-
setup(
|
|
22
|
-
let F =
|
|
21
|
+
setup(M, { emit: N }) {
|
|
22
|
+
let F = M, I = N, L = new cppay_default(F.apiKey), R = ref("select"), z = ref(!1), B = ref([]), V = ref(""), H = ref(""), U = ref(null), W = computed(() => B.value.find((r) => r.chain === V.value)), G = computed(() => W.value?.tokens || []), K = computed(() => G.value.find((r) => r.symbol === H.value)), q = ref(1), J = computed(() => H.value ? (parseFloat(F.amount) / q.value).toFixed(6) : "0"), Y = () => {
|
|
23
23
|
I("update:modelValue", !1), setTimeout(() => {
|
|
24
24
|
R.value = "select", U.value = null;
|
|
25
25
|
}, 300);
|
|
26
26
|
}, X = async () => {
|
|
27
27
|
try {
|
|
28
28
|
z.value = !0, B.value = await L.getSupportedChains(), B.value.length > 0 && (V.value = B.value[0].chain);
|
|
29
|
-
} catch (
|
|
30
|
-
I("error",
|
|
29
|
+
} catch (r) {
|
|
30
|
+
I("error", r);
|
|
31
31
|
} finally {
|
|
32
32
|
z.value = !1;
|
|
33
33
|
}
|
|
34
34
|
}, Z = async () => {
|
|
35
35
|
if (!(!V.value || !H.value)) try {
|
|
36
36
|
z.value = !0;
|
|
37
|
-
let
|
|
37
|
+
let r = await L.createPayment({
|
|
38
38
|
paymentChain: V.value,
|
|
39
39
|
paymentToken: H.value,
|
|
40
40
|
orderId: F.orderId,
|
|
41
41
|
amount: J.value
|
|
42
42
|
});
|
|
43
43
|
U.value = {
|
|
44
|
-
paymentId:
|
|
45
|
-
paymentAmount:
|
|
44
|
+
paymentId: r.paymentId,
|
|
45
|
+
paymentAmount: r.paymentAmount,
|
|
46
46
|
receiveAddress: K.value?.receiveAddresses[0] || ""
|
|
47
47
|
}, R.value = "payment";
|
|
48
|
-
} catch (
|
|
49
|
-
I("error",
|
|
48
|
+
} catch (r) {
|
|
49
|
+
I("error", r);
|
|
50
50
|
} finally {
|
|
51
51
|
z.value = !1;
|
|
52
52
|
}
|
|
53
53
|
}, Q = async () => {
|
|
54
54
|
if (U.value) try {
|
|
55
55
|
z.value = !0, await L.checkPaymentStatus(U.value.paymentId, 1e3), I("success", U.value.paymentId), Y();
|
|
56
|
-
} catch (
|
|
57
|
-
I("error",
|
|
56
|
+
} catch (r) {
|
|
57
|
+
I("error", r);
|
|
58
58
|
} finally {
|
|
59
59
|
z.value = !1;
|
|
60
60
|
}
|
|
61
61
|
}, $ = async () => {
|
|
62
62
|
U.value?.receiveAddress && await navigator.clipboard.writeText(U.value.receiveAddress);
|
|
63
63
|
};
|
|
64
|
-
return watch(() => F.modelValue, (
|
|
65
|
-
|
|
64
|
+
return watch(() => F.modelValue, (r) => {
|
|
65
|
+
r && B.value.length === 0 && X();
|
|
66
66
|
}), watch(V, () => {
|
|
67
67
|
G.value.length > 0 && (H.value = G.value[0].symbol);
|
|
68
|
-
}), (
|
|
69
|
-
default: withCtx(() => [
|
|
68
|
+
}), (r, N) => (openBlock(), createBlock(Teleport, { to: "body" }, [createVNode(Transition, { name: "_cppay-fade" }, {
|
|
69
|
+
default: withCtx(() => [M.modelValue ? (openBlock(), createElementBlock("div", {
|
|
70
70
|
key: 0,
|
|
71
71
|
class: "_cppay-overlay",
|
|
72
72
|
onClick: withModifiers(Y, ["self"])
|
|
@@ -74,7 +74,7 @@ var _hoisted_1 = { class: "_cppay-dialog" }, _hoisted_2 = { class: "_cppay-heade
|
|
|
74
74
|
onClick: Y,
|
|
75
75
|
class: "_cppay-close-btn",
|
|
76
76
|
disabled: z.value
|
|
77
|
-
}, [...
|
|
77
|
+
}, [...N[1] ||= [createElementVNode("svg", {
|
|
78
78
|
fill: "none",
|
|
79
79
|
stroke: "currentColor",
|
|
80
80
|
viewBox: "0 0 24 24"
|
|
@@ -84,37 +84,37 @@ var _hoisted_1 = { class: "_cppay-dialog" }, _hoisted_2 = { class: "_cppay-heade
|
|
|
84
84
|
"stroke-width": "2",
|
|
85
85
|
d: "M6 18L18 6M6 6l12 12"
|
|
86
86
|
})], -1)]], 8, _hoisted_4)]), createElementVNode("div", _hoisted_5, [R.value === "select" ? (openBlock(), createElementBlock("div", _hoisted_6, [
|
|
87
|
-
createElementVNode("div", _hoisted_7, [
|
|
88
|
-
key:
|
|
89
|
-
onClick: (
|
|
90
|
-
class: normalizeClass(["_cppay-select-btn", V.value ===
|
|
91
|
-
}, [
|
|
87
|
+
createElementVNode("div", _hoisted_7, [N[2] ||= createElementVNode("label", { class: "_cppay-label" }, "支付网络", -1), createElementVNode("div", _hoisted_8, [(openBlock(!0), createElementBlock(Fragment, null, renderList(B.value, (r) => (openBlock(), createElementBlock("button", {
|
|
88
|
+
key: r.chain,
|
|
89
|
+
onClick: (M) => V.value = r.chain,
|
|
90
|
+
class: normalizeClass(["_cppay-select-btn", V.value === r.chain ? "_cppay-selected" : ""])
|
|
91
|
+
}, [r.icon ? (openBlock(), createElementBlock("img", {
|
|
92
92
|
key: 0,
|
|
93
|
-
src:
|
|
94
|
-
alt:
|
|
95
|
-
}, null, 8, _hoisted_10)) : createCommentVNode("", !0), createElementVNode("span", null, toDisplayString(
|
|
96
|
-
createElementVNode("div", _hoisted_11, [
|
|
97
|
-
key:
|
|
98
|
-
onClick: (
|
|
99
|
-
class: normalizeClass(["_cppay-select-btn", H.value ===
|
|
100
|
-
}, [
|
|
93
|
+
src: r.icon,
|
|
94
|
+
alt: r.chain
|
|
95
|
+
}, null, 8, _hoisted_10)) : createCommentVNode("", !0), createElementVNode("span", null, toDisplayString(r.chain), 1)], 10, _hoisted_9))), 128))])]),
|
|
96
|
+
createElementVNode("div", _hoisted_11, [N[3] ||= createElementVNode("label", { class: "_cppay-label" }, "支付代币", -1), createElementVNode("div", _hoisted_12, [(openBlock(!0), createElementBlock(Fragment, null, renderList(G.value, (r) => (openBlock(), createElementBlock("button", {
|
|
97
|
+
key: r.symbol,
|
|
98
|
+
onClick: (M) => H.value = r.symbol,
|
|
99
|
+
class: normalizeClass(["_cppay-select-btn", H.value === r.symbol ? "_cppay-selected" : ""])
|
|
100
|
+
}, [r.icon ? (openBlock(), createElementBlock("img", {
|
|
101
101
|
key: 0,
|
|
102
|
-
src:
|
|
103
|
-
alt:
|
|
104
|
-
}, null, 8, _hoisted_14)) : createCommentVNode("", !0), createElementVNode("span", null, toDisplayString(
|
|
105
|
-
createElementVNode("div", _hoisted_15, [createElementVNode("div", _hoisted_16, [createElementVNode("div", _hoisted_17, [
|
|
102
|
+
src: r.icon,
|
|
103
|
+
alt: r.symbol
|
|
104
|
+
}, null, 8, _hoisted_14)) : createCommentVNode("", !0), createElementVNode("span", null, toDisplayString(r.symbol), 1)], 10, _hoisted_13))), 128))])]),
|
|
105
|
+
createElementVNode("div", _hoisted_15, [createElementVNode("div", _hoisted_16, [createElementVNode("div", _hoisted_17, [N[4] ||= createElementVNode("span", { class: "_cppay-price-label" }, "支付金额", -1), createElementVNode("div", _hoisted_18, [createElementVNode("div", _hoisted_19, toDisplayString(J.value) + " " + toDisplayString(H.value), 1), createElementVNode("div", _hoisted_20, "≈ $" + toDisplayString(M.amount), 1)])])])]),
|
|
106
106
|
createElementVNode("div", _hoisted_21, [createElementVNode("button", {
|
|
107
107
|
onClick: Z,
|
|
108
108
|
disabled: !V.value || !H.value || z.value,
|
|
109
109
|
class: "_cppay-btn _cppay-btn-primary"
|
|
110
110
|
}, toDisplayString(z.value ? "处理中..." : "继续支付"), 9, _hoisted_22)])
|
|
111
111
|
])) : R.value === "payment" && U.value ? (openBlock(), createElementBlock("div", _hoisted_23, [
|
|
112
|
-
|
|
113
|
-
createElementVNode("div", _hoisted_24, [createElementVNode("div", _hoisted_25, [
|
|
112
|
+
N[8] ||= createElementVNode("div", { class: "_cppay-qr-container" }, [createElementVNode("div", { class: "_cppay-qr-placeholder" }, [createElementVNode("span", null, "扫码支付")])], -1),
|
|
113
|
+
createElementVNode("div", _hoisted_24, [createElementVNode("div", _hoisted_25, [N[5] ||= createElementVNode("div", { class: "_cppay-info-label" }, "支付金额", -1), createElementVNode("div", _hoisted_26, toDisplayString(U.value.paymentAmount) + " " + toDisplayString(H.value), 1)]), createElementVNode("div", _hoisted_27, [N[7] ||= createElementVNode("div", { class: "_cppay-info-label" }, "支付地址", -1), createElementVNode("div", _hoisted_28, [createElementVNode("code", null, toDisplayString(U.value.receiveAddress), 1), createElementVNode("button", {
|
|
114
114
|
onClick: $,
|
|
115
115
|
class: "_cppay-copy-btn",
|
|
116
116
|
title: "复制地址"
|
|
117
|
-
}, [...
|
|
117
|
+
}, [...N[6] ||= [createElementVNode("svg", {
|
|
118
118
|
fill: "none",
|
|
119
119
|
stroke: "currentColor",
|
|
120
120
|
viewBox: "0 0 24 24"
|
|
@@ -130,7 +130,7 @@ var _hoisted_1 = { class: "_cppay-dialog" }, _hoisted_2 = { class: "_cppay-heade
|
|
|
130
130
|
class: "_cppay-btn _cppay-btn-primary"
|
|
131
131
|
}, toDisplayString(z.value ? "检查支付状态..." : "我已完成支付"), 9, _hoisted_30)]),
|
|
132
132
|
createElementVNode("div", _hoisted_31, [createElementVNode("button", {
|
|
133
|
-
onClick:
|
|
133
|
+
onClick: N[0] ||= (r) => R.value = "select",
|
|
134
134
|
disabled: z.value,
|
|
135
135
|
class: "_cppay-btn _cppay-btn-secondary"
|
|
136
136
|
}, " 更改支付方式 ", 8, _hoisted_32)])
|
|
@@ -138,5 +138,6 @@ var _hoisted_1 = { class: "_cppay-dialog" }, _hoisted_2 = { class: "_cppay-heade
|
|
|
138
138
|
_: 1
|
|
139
139
|
})]));
|
|
140
140
|
}
|
|
141
|
-
}), [["__scopeId", "data-v-
|
|
141
|
+
}), [["__scopeId", "data-v-a66fc55b"]]);
|
|
142
|
+
injectStyle(payment_dialog_default);
|
|
142
143
|
export { PaymentDialog_default as PaymentDialog };
|