cppay-sdk 0.0.2-beta.4 → 0.0.2-beta.5

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.
@@ -0,0 +1,102 @@
1
+ const CHAIN_ICONS = {
2
+ Ethereum: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/info/logo.png",
3
+ BSC: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/binance/info/logo.png",
4
+ "bsc-testnet": "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/binance/info/logo.png",
5
+ Tron: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/tron/info/logo.png",
6
+ Polygon: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/polygon/info/logo.png",
7
+ Solana: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/solana/info/logo.png"
8
+ }, TOKEN_ICONS = {
9
+ USDT: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0xdAC17F958D2ee523a2206206994597C13D831ec7/logo.png",
10
+ USDC: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48/logo.png",
11
+ ETH: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/info/logo.png",
12
+ BNB: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/binance/info/logo.png",
13
+ tBNB: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/binance/info/logo.png",
14
+ TRX: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/tron/info/logo.png",
15
+ SOL: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/solana/info/logo.png"
16
+ };
17
+ var BASE_URL = "http://192.168.0.162:8000", request = async (e, n, i) => {
18
+ let a = Object.assign({ timeout: 15e3 }, i), o = new AbortController(), s = setTimeout(() => o.abort(), a.timeout);
19
+ try {
20
+ let i = await fetch(new URL(e, BASE_URL), {
21
+ signal: o.signal,
22
+ ...n
23
+ });
24
+ clearTimeout(s);
25
+ let a = i.headers.get("Content-Type") ?? "";
26
+ if (a.includes("json")) return await i.json();
27
+ try {
28
+ return await i.json();
29
+ } catch {
30
+ throw Error(`URL: ${e}, Unsupport Content Type: ${a}`);
31
+ }
32
+ } catch (n) {
33
+ throw clearTimeout(s), n instanceof DOMException && n.name === "AbortError" ? Error(`URL: ${e}, Request timeout after ${a.timeout}ms`) : n;
34
+ }
35
+ }, SUCCESS_CODE = 0;
36
+ const cppayRequest = async (e, n) => {
37
+ let r = await request(n.url, {
38
+ method: n.method ?? "get",
39
+ headers: {
40
+ Authorization: e,
41
+ ...n.headers
42
+ },
43
+ body: JSON.stringify(n.data)
44
+ });
45
+ if (r.code !== SUCCESS_CODE) throw Error(`Request ${n.url} Failed. ${r.message}`);
46
+ return r.data;
47
+ }, sleep = (e = 1e3) => new Promise((n) => setTimeout(n, e));
48
+ var cppay_default = class {
49
+ apikey;
50
+ constructor(e) {
51
+ this.apikey = e;
52
+ }
53
+ async getSupportedChains() {
54
+ let r = (await cppayRequest(this.apikey, { url: "/api/payment/token" })).reduce((r, i) => {
55
+ let a = r[i.chain] ?? {
56
+ chain: i.chain,
57
+ tokens: [],
58
+ icon: CHAIN_ICONS[i.chain]
59
+ };
60
+ return a.tokens.push({
61
+ symbol: i.token_symbol,
62
+ decimals: i.token_decimals,
63
+ address: i.token_address,
64
+ receiveAddresses: i.receive_addresses,
65
+ icon: TOKEN_ICONS[i.token_symbol]
66
+ }), r[i.chain] = a, r;
67
+ }, {});
68
+ return Object.values(r);
69
+ }
70
+ async createPayment(e) {
71
+ let n = {
72
+ chain: e.paymentChain,
73
+ token: e.paymentToken,
74
+ order_no: e.orderId,
75
+ amount: e.amount
76
+ }, r = await cppayRequest(this.apikey, {
77
+ url: "/api/payment/create",
78
+ method: "post",
79
+ data: n
80
+ });
81
+ return {
82
+ orderId: e.orderId,
83
+ paymentId: r.payment_id,
84
+ paymentAmount: r.pay_amount,
85
+ paymentChain: e.paymentChain,
86
+ paymentToken: e.paymentToken
87
+ };
88
+ }
89
+ async checkPaymentStatus(e, n = 1e3) {
90
+ let r = 15;
91
+ for (; r--;) {
92
+ let r = { payment_id: e };
93
+ if ((await cppayRequest(this.apikey, {
94
+ url: "/api/payment/query",
95
+ data: r
96
+ })).status === "success") return;
97
+ await sleep(n);
98
+ }
99
+ throw Error(`Check Payment Status Timeout, PaymentId: ${e}`);
100
+ }
101
+ };
102
+ export { CHAIN_ICONS as n, TOKEN_ICONS as r, cppay_default as t };
@@ -0,0 +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,{method:t.method??`get`,headers:{Authorization:e,...t.headers},body:JSON.stringify(t.data)});if(n.code!==i)throw Error(`Request ${t.url} Failed. ${n.message}`);return n.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`,data: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}});
@@ -0,0 +1,2 @@
1
+ ._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}}._cppay-fade-enter-active[data-v-b7958c41],._cppay-fade-leave-active[data-v-b7958c41]{transition:opacity .3s}._cppay-fade-enter-from[data-v-b7958c41],._cppay-fade-leave-to[data-v-b7958c41]{opacity:0}._cppay-fade-enter-active ._cppay-dialog[data-v-b7958c41]{animation:.3s _cppay-slideUp}
2
+ /*$vite$:1*/
package/dist/index.cjs CHANGED
@@ -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`,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,{method:t.method??`get`,headers:{Authorization:e,...t.headers},body:JSON.stringify(t.data)});if(n.code!==i)throw Error(`Request ${t.url} Failed. ${n.message}`);return n.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`,data:n})).status===`success`)return;await o(t)}throw Error(`Check Payment Status Timeout, PaymentId: ${e}`)}},c=s;exports.CHAIN_ICONS=e,exports.Cppay=c,exports.TOKEN_ICONS=t;
1
+ const e=require(`./cppay-rxbtyzyZ.cjs`);exports.CHAIN_ICONS=e.n,exports.Cppay=e.t,exports.TOKEN_ICONS=e.r;
package/dist/index.js CHANGED
@@ -1,101 +1,2 @@
1
- const CHAIN_ICONS = {
2
- Ethereum: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/info/logo.png",
3
- BSC: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/binance/info/logo.png",
4
- Tron: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/tron/info/logo.png",
5
- Polygon: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/polygon/info/logo.png",
6
- Solana: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/solana/info/logo.png"
7
- }, TOKEN_ICONS = {
8
- USDT: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0xdAC17F958D2ee523a2206206994597C13D831ec7/logo.png",
9
- USDC: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48/logo.png",
10
- ETH: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/info/logo.png",
11
- BNB: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/binance/info/logo.png",
12
- tBNB: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/binance/info/logo.png",
13
- TRX: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/tron/info/logo.png",
14
- SOL: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/solana/info/logo.png"
15
- };
16
- var BASE_URL = "http://192.168.0.162:8000", request = async (e, n, i) => {
17
- let a = Object.assign({ timeout: 15e3 }, i), o = new AbortController(), s = setTimeout(() => o.abort(), a.timeout);
18
- try {
19
- let i = await fetch(new URL(e, BASE_URL), {
20
- signal: o.signal,
21
- ...n
22
- });
23
- clearTimeout(s);
24
- let a = i.headers.get("Content-Type") ?? "";
25
- if (a.includes("json")) return await i.json();
26
- try {
27
- return await i.json();
28
- } catch {
29
- throw Error(`URL: ${e}, Unsupport Content Type: ${a}`);
30
- }
31
- } catch (n) {
32
- throw clearTimeout(s), n instanceof DOMException && n.name === "AbortError" ? Error(`URL: ${e}, Request timeout after ${a.timeout}ms`) : n;
33
- }
34
- }, SUCCESS_CODE = 0;
35
- const cppayRequest = async (e, n) => {
36
- let r = await request(n.url, {
37
- method: n.method ?? "get",
38
- headers: {
39
- Authorization: e,
40
- ...n.headers
41
- },
42
- body: JSON.stringify(n.data)
43
- });
44
- if (r.code !== SUCCESS_CODE) throw Error(`Request ${n.url} Failed. ${r.message}`);
45
- return r.data;
46
- }, sleep = (e = 1e3) => new Promise((n) => setTimeout(n, e));
47
- var cppay_default = class {
48
- apikey;
49
- constructor(e) {
50
- this.apikey = e;
51
- }
52
- async getSupportedChains() {
53
- let r = (await cppayRequest(this.apikey, { url: "/api/payment/token" })).reduce((r, i) => {
54
- let a = r[i.chain] ?? {
55
- chain: i.chain,
56
- tokens: [],
57
- icon: CHAIN_ICONS[i.chain]
58
- };
59
- return a.tokens.push({
60
- symbol: i.token_symbol,
61
- decimals: i.token_decimals,
62
- address: i.token_address,
63
- receiveAddresses: i.receive_addresses,
64
- icon: TOKEN_ICONS[i.token_symbol]
65
- }), r[i.chain] = a, r;
66
- }, {});
67
- return Object.values(r);
68
- }
69
- async createPayment(e) {
70
- let n = {
71
- chain: e.paymentChain,
72
- token: e.paymentToken,
73
- order_no: e.orderId,
74
- amount: e.amount
75
- }, r = await cppayRequest(this.apikey, {
76
- url: "/api/payment/create",
77
- method: "post",
78
- data: n
79
- });
80
- return {
81
- orderId: e.orderId,
82
- paymentId: r.payment_id,
83
- paymentAmount: r.pay_amount,
84
- paymentChain: e.paymentChain,
85
- paymentToken: e.paymentToken
86
- };
87
- }
88
- async checkPaymentStatus(e, n = 1e3) {
89
- let r = 15;
90
- for (; r--;) {
91
- let r = { payment_id: e };
92
- if ((await cppayRequest(this.apikey, {
93
- url: "/api/payment/query",
94
- data: r
95
- })).status === "success") return;
96
- await sleep(n);
97
- }
98
- throw Error(`Check Payment Status Timeout, PaymentId: ${e}`);
99
- }
100
- };
1
+ import { n as CHAIN_ICONS, r as TOKEN_ICONS, t as cppay_default } from "./cppay-gIC4-2qD.js";
101
2
  export { CHAIN_ICONS, cppay_default as Cppay, TOKEN_ICONS };
package/dist/react.cjs CHANGED
@@ -1 +1,6 @@
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));let c=require(`react`);c=s(c);var l=()=>null,u=c.default.memo(l);exports.PaymentDialog=u;
1
+ var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),s=(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},c=(n,r,a)=>(a=n==null?{}:e(i(n)),s(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));const l=require(`./cppay-rxbtyzyZ.cjs`);;/* empty css */let u=require(`react`);u=c(u);var d=o((e=>{var t=Symbol.for(`react.transitional.element`);function n(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.jsx=n,e.jsxs=n})),f=o((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)}})()})),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;
package/dist/react.d.ts CHANGED
@@ -1,5 +1,15 @@
1
1
  import { default as default_2 } from 'react';
2
2
 
3
- export declare const PaymentDialog: default_2.MemoExoticComponent<() => null>;
3
+ export declare const PaymentDialog: default_2.NamedExoticComponent<PaymentDialogProps>;
4
+
5
+ declare interface PaymentDialogProps {
6
+ open: boolean;
7
+ onClose: () => void;
8
+ apiKey: string;
9
+ orderId: string;
10
+ amount: string;
11
+ onSuccess?: (paymentId: string) => void;
12
+ onError?: (error: Error) => void;
13
+ }
4
14
 
5
15
  export { }
package/dist/react.js CHANGED
@@ -1,3 +1,405 @@
1
- import React from "react";
2
- var PaymentDialog_default = React.memo(() => null);
1
+ import { t as cppay_default } from "./cppay-gIC4-2qD.js";
2
+ /* empty css */
3
+ import React, { useEffect, useMemo, useState } from "react";
4
+ var __commonJSMin = (e, t) => () => (t || e((t = { exports: {} }).exports, t), t.exports), __require = /* @__PURE__ */ ((e) => typeof require < "u" ? require : typeof Proxy < "u" ? new Proxy(e, { get: (e, t) => (typeof require < "u" ? require : e)[t] }) : e)(function(e) {
5
+ if (typeof require < "u") return require.apply(this, arguments);
6
+ throw Error("Calling `require` for \"" + e + "\" in an environment that doesn't expose the `require` function.");
7
+ }), require_react_jsx_runtime_production = /* @__PURE__ */ __commonJSMin(((e) => {
8
+ var t = Symbol.for("react.transitional.element");
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,
186
+ 1
187
+ ]), k = async () => {
188
+ try {
189
+ g(!0);
190
+ let e = await f.getSupportedChains();
191
+ v(e), e.length > 0 && b(e[0].chain);
192
+ } catch (e) {
193
+ d?.(e);
194
+ } finally {
195
+ g(!1);
196
+ }
197
+ }, A = async () => {
198
+ if (!(!y || !x)) try {
199
+ g(!0);
200
+ let e = await f.createPayment({
201
+ paymentChain: y,
202
+ paymentToken: x,
203
+ orderId: s,
204
+ amount: O
205
+ });
206
+ w({
207
+ paymentId: e.paymentId,
208
+ paymentAmount: e.paymentAmount,
209
+ receiveAddress: D?.receiveAddresses[0] || ""
210
+ }), m("payment");
211
+ } catch (e) {
212
+ d?.(e);
213
+ } finally {
214
+ g(!1);
215
+ }
216
+ }, j = async () => {
217
+ if (C) try {
218
+ g(!0), await f.checkPaymentStatus(C.paymentId, 1e3), u?.(C.paymentId), N();
219
+ } catch (e) {
220
+ d?.(e);
221
+ } finally {
222
+ g(!1);
223
+ }
224
+ }, M = async () => {
225
+ C?.receiveAddress && await navigator.clipboard.writeText(C.receiveAddress);
226
+ }, N = () => {
227
+ a(), setTimeout(() => {
228
+ m("select"), w(null);
229
+ }, 300);
230
+ };
231
+ return useEffect(() => {
232
+ t && _.length === 0 && k();
233
+ }, [t]), useEffect(() => {
234
+ E.length > 0 && S(E[0].symbol);
235
+ }, [E]), t ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
236
+ className: "_cppay-overlay",
237
+ onClick: (e) => e.target === e.currentTarget && N(),
238
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
239
+ className: "_cppay-dialog",
240
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
241
+ className: "_cppay-header",
242
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("h2", {
243
+ className: "_cppay-title",
244
+ children: p === "select" ? "选择支付方式" : "完成支付"
245
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", {
246
+ onClick: N,
247
+ disabled: h,
248
+ className: "_cppay-close-btn",
249
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("svg", {
250
+ fill: "none",
251
+ stroke: "currentColor",
252
+ viewBox: "0 0 24 24",
253
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", {
254
+ strokeLinecap: "round",
255
+ strokeLinejoin: "round",
256
+ strokeWidth: 2,
257
+ d: "M6 18L18 6M6 6l12 12"
258
+ })
259
+ })
260
+ })]
261
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
262
+ className: "_cppay-content",
263
+ children: p === "select" ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { children: [
264
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
265
+ className: "_cppay-section",
266
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("label", {
267
+ className: "_cppay-label",
268
+ children: "支付网络"
269
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
270
+ className: "_cppay-grid",
271
+ children: _.map((e) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("button", {
272
+ onClick: () => b(e.chain),
273
+ className: `_cppay-select-btn ${y === e.chain ? "_cppay-selected" : ""}`,
274
+ children: [e.icon && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("img", {
275
+ src: e.icon,
276
+ alt: e.chain
277
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: e.chain })]
278
+ }, e.chain))
279
+ })]
280
+ }),
281
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
282
+ className: "_cppay-section",
283
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("label", {
284
+ className: "_cppay-label",
285
+ children: "支付代币"
286
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
287
+ className: "_cppay-grid",
288
+ children: E.map((e) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("button", {
289
+ onClick: () => S(e.symbol),
290
+ className: `_cppay-select-btn ${x === e.symbol ? "_cppay-selected" : ""}`,
291
+ children: [e.icon && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("img", {
292
+ src: e.icon,
293
+ alt: e.symbol
294
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: e.symbol })]
295
+ }, e.symbol))
296
+ })]
297
+ }),
298
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
299
+ className: "_cppay-section",
300
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
301
+ className: "_cppay-price-box",
302
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
303
+ className: "_cppay-price-row",
304
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
305
+ className: "_cppay-price-label",
306
+ children: "支付金额"
307
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
308
+ className: "_cppay-price-amount",
309
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
310
+ className: "_cppay-price-main",
311
+ children: [
312
+ O,
313
+ " ",
314
+ x
315
+ ]
316
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
317
+ className: "_cppay-price-sub",
318
+ children: ["≈ $", c]
319
+ })]
320
+ })]
321
+ })
322
+ })
323
+ }),
324
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
325
+ className: "_cppay-section",
326
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", {
327
+ onClick: A,
328
+ disabled: !y || !x || h,
329
+ className: "_cppay-btn _cppay-btn-primary",
330
+ children: h ? "处理中..." : "继续支付"
331
+ })
332
+ })
333
+ ] }) : C && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { children: [
334
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
335
+ className: "_cppay-qr-container",
336
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
337
+ className: "_cppay-qr-placeholder",
338
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: "扫码支付" })
339
+ })
340
+ }),
341
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
342
+ className: "_cppay-section",
343
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
344
+ className: "_cppay-info-box",
345
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
346
+ className: "_cppay-info-label",
347
+ children: "支付金额"
348
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
349
+ className: "_cppay-info-value",
350
+ children: [
351
+ C.paymentAmount,
352
+ " ",
353
+ x
354
+ ]
355
+ })]
356
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
357
+ className: "_cppay-info-box",
358
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
359
+ className: "_cppay-info-label",
360
+ children: "支付地址"
361
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
362
+ className: "_cppay-address-row",
363
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("code", { children: C.receiveAddress }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", {
364
+ onClick: M,
365
+ className: "_cppay-copy-btn",
366
+ title: "复制地址",
367
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("svg", {
368
+ fill: "none",
369
+ stroke: "currentColor",
370
+ viewBox: "0 0 24 24",
371
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", {
372
+ strokeLinecap: "round",
373
+ strokeLinejoin: "round",
374
+ strokeWidth: 2,
375
+ 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"
376
+ })
377
+ })
378
+ })]
379
+ })]
380
+ })]
381
+ }),
382
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
383
+ className: "_cppay-section",
384
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", {
385
+ onClick: j,
386
+ disabled: h,
387
+ className: "_cppay-btn _cppay-btn-primary",
388
+ children: h ? "检查支付状态..." : "我已完成支付"
389
+ })
390
+ }),
391
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
392
+ className: "_cppay-section",
393
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", {
394
+ onClick: () => m("select"),
395
+ disabled: h,
396
+ className: "_cppay-btn _cppay-btn-secondary",
397
+ children: "更改支付方式"
398
+ })
399
+ })
400
+ ] })
401
+ })]
402
+ })
403
+ }) : null;
404
+ });
3
405
  export { PaymentDialog_default as PaymentDialog };
package/dist/vue.cjs CHANGED
@@ -1 +1 @@
1
- var e=(e,t)=>{let n=e.__vccOpts||e;for(let[e,r]of t)n[e]=r;return n},t={};function n(e,t){return null}var r=e(t,[[`render`,n]]);exports.PaymentDialog=r;
1
+ const e=require(`./cppay-rxbtyzyZ.cjs`);;/* empty css */const t=require(`./react.cjs`);let n=require(`vue`);var r={class:`_cppay-dialog`},i={class:`_cppay-header`},a={class:`_cppay-title`},o=[`disabled`],s={class:`_cppay-content`},c={key:0},l={class:`_cppay-section`},u={class:`_cppay-grid`},d=[`onClick`],f=[`src`,`alt`],p={class:`_cppay-section`},m={class:`_cppay-grid`},h=[`onClick`],g=[`src`,`alt`],_={class:`_cppay-section`},v={class:`_cppay-price-box`},y={class:`_cppay-price-row`},b={class:`_cppay-price-amount`},x={class:`_cppay-price-main`},S={class:`_cppay-price-sub`},C={class:`_cppay-section`},w=[`disabled`],T={key:1},E={class:`_cppay-section`},D={class:`_cppay-info-box`},O={class:`_cppay-info-value`},k={class:`_cppay-info-box`},A={class:`_cppay-address-row`},j={class:`_cppay-section`},M=[`disabled`],N={class:`_cppay-section`},ee=[`disabled`],P=(0,n.defineComponent)({__name:`PaymentDialog`,props:{modelValue:{type:Boolean},apiKey:{},orderId:{},amount:{}},emits:[`update:modelValue`,`success`,`error`],setup(t,{emit:P}){let F=t,I=P,L=new e.t(F.apiKey),R=(0,n.ref)(`select`),z=(0,n.ref)(!1),B=(0,n.ref)([]),V=(0,n.ref)(``),H=(0,n.ref)(``),U=(0,n.ref)(null),W=(0,n.computed)(()=>B.value.find(e=>e.chain===V.value)),G=(0,n.computed)(()=>W.value?.tokens||[]),K=(0,n.computed)(()=>G.value.find(e=>e.symbol===H.value)),q=(0,n.ref)(1),J=(0,n.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,n.watch)(()=>F.modelValue,e=>{e&&B.value.length===0&&X()}),(0,n.watch)(V,()=>{G.value.length>0&&(H.value=G.value[0].symbol)}),(e,P)=>((0,n.openBlock)(),(0,n.createBlock)(n.Teleport,{to:`body`},[(0,n.createVNode)(n.Transition,{name:`_cppay-fade`},{default:(0,n.withCtx)(()=>[t.modelValue?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,{key:0,class:`_cppay-overlay`,onClick:(0,n.withModifiers)(Y,[`self`])},[(0,n.createElementVNode)(`div`,r,[(0,n.createElementVNode)(`div`,i,[(0,n.createElementVNode)(`h2`,a,(0,n.toDisplayString)(R.value===`select`?`选择支付方式`:`完成支付`),1),(0,n.createElementVNode)(`button`,{onClick:Y,class:`_cppay-close-btn`,disabled:z.value},[...P[1]||=[(0,n.createElementVNode)(`svg`,{fill:`none`,stroke:`currentColor`,viewBox:`0 0 24 24`},[(0,n.createElementVNode)(`path`,{"stroke-linecap":`round`,"stroke-linejoin":`round`,"stroke-width":`2`,d:`M6 18L18 6M6 6l12 12`})],-1)]],8,o)]),(0,n.createElementVNode)(`div`,s,[R.value===`select`?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,c,[(0,n.createElementVNode)(`div`,l,[P[2]||=(0,n.createElementVNode)(`label`,{class:`_cppay-label`},`支付网络`,-1),(0,n.createElementVNode)(`div`,u,[((0,n.openBlock)(!0),(0,n.createElementBlock)(n.Fragment,null,(0,n.renderList)(B.value,e=>((0,n.openBlock)(),(0,n.createElementBlock)(`button`,{key:e.chain,onClick:t=>V.value=e.chain,class:(0,n.normalizeClass)([`_cppay-select-btn`,V.value===e.chain?`_cppay-selected`:``])},[e.icon?((0,n.openBlock)(),(0,n.createElementBlock)(`img`,{key:0,src:e.icon,alt:e.chain},null,8,f)):(0,n.createCommentVNode)(``,!0),(0,n.createElementVNode)(`span`,null,(0,n.toDisplayString)(e.chain),1)],10,d))),128))])]),(0,n.createElementVNode)(`div`,p,[P[3]||=(0,n.createElementVNode)(`label`,{class:`_cppay-label`},`支付代币`,-1),(0,n.createElementVNode)(`div`,m,[((0,n.openBlock)(!0),(0,n.createElementBlock)(n.Fragment,null,(0,n.renderList)(G.value,e=>((0,n.openBlock)(),(0,n.createElementBlock)(`button`,{key:e.symbol,onClick:t=>H.value=e.symbol,class:(0,n.normalizeClass)([`_cppay-select-btn`,H.value===e.symbol?`_cppay-selected`:``])},[e.icon?((0,n.openBlock)(),(0,n.createElementBlock)(`img`,{key:0,src:e.icon,alt:e.symbol},null,8,g)):(0,n.createCommentVNode)(``,!0),(0,n.createElementVNode)(`span`,null,(0,n.toDisplayString)(e.symbol),1)],10,h))),128))])]),(0,n.createElementVNode)(`div`,_,[(0,n.createElementVNode)(`div`,v,[(0,n.createElementVNode)(`div`,y,[P[4]||=(0,n.createElementVNode)(`span`,{class:`_cppay-price-label`},`支付金额`,-1),(0,n.createElementVNode)(`div`,b,[(0,n.createElementVNode)(`div`,x,(0,n.toDisplayString)(J.value)+` `+(0,n.toDisplayString)(H.value),1),(0,n.createElementVNode)(`div`,S,`≈ $`+(0,n.toDisplayString)(t.amount),1)])])])]),(0,n.createElementVNode)(`div`,C,[(0,n.createElementVNode)(`button`,{onClick:Z,disabled:!V.value||!H.value||z.value,class:`_cppay-btn _cppay-btn-primary`},(0,n.toDisplayString)(z.value?`处理中...`:`继续支付`),9,w)])])):R.value===`payment`&&U.value?((0,n.openBlock)(),(0,n.createElementBlock)(`div`,T,[P[8]||=(0,n.createElementVNode)(`div`,{class:`_cppay-qr-container`},[(0,n.createElementVNode)(`div`,{class:`_cppay-qr-placeholder`},[(0,n.createElementVNode)(`span`,null,`扫码支付`)])],-1),(0,n.createElementVNode)(`div`,E,[(0,n.createElementVNode)(`div`,D,[P[5]||=(0,n.createElementVNode)(`div`,{class:`_cppay-info-label`},`支付金额`,-1),(0,n.createElementVNode)(`div`,O,(0,n.toDisplayString)(U.value.paymentAmount)+` `+(0,n.toDisplayString)(H.value),1)]),(0,n.createElementVNode)(`div`,k,[P[7]||=(0,n.createElementVNode)(`div`,{class:`_cppay-info-label`},`支付地址`,-1),(0,n.createElementVNode)(`div`,A,[(0,n.createElementVNode)(`code`,null,(0,n.toDisplayString)(U.value.receiveAddress),1),(0,n.createElementVNode)(`button`,{onClick:$,class:`_cppay-copy-btn`,title:`复制地址`},[...P[6]||=[(0,n.createElementVNode)(`svg`,{fill:`none`,stroke:`currentColor`,viewBox:`0 0 24 24`},[(0,n.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,n.createElementVNode)(`div`,j,[(0,n.createElementVNode)(`button`,{onClick:Q,disabled:z.value,class:`_cppay-btn _cppay-btn-primary`},(0,n.toDisplayString)(z.value?`检查支付状态...`:`我已完成支付`),9,M)]),(0,n.createElementVNode)(`div`,N,[(0,n.createElementVNode)(`button`,{onClick:P[0]||=e=>R.value=`select`,disabled:z.value,class:`_cppay-btn _cppay-btn-secondary`},` 更改支付方式 `,8,ee)])])):(0,n.createCommentVNode)(``,!0)])])])):(0,n.createCommentVNode)(``,!0)]),_:1})]))}}),F=(e,t)=>{let n=e.__vccOpts||e;for(let[e,r]of t)n[e]=r;return n},I=F(P,[[`__scopeId`,`data-v-b7958c41`]]);exports.PaymentDialog=I;
package/dist/vue.d.ts CHANGED
@@ -3,6 +3,21 @@ import { ComponentProvideOptions } from 'vue';
3
3
  import { DefineComponent } from 'vue';
4
4
  import { PublicProps } from 'vue';
5
5
 
6
- export declare const PaymentDialog: DefineComponent< {}, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, ComponentProvideOptions, true, {}, any>;
6
+ export declare const PaymentDialog: DefineComponent<Props, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {} & {
7
+ error: (error: Error) => any;
8
+ success: (paymentId: string) => any;
9
+ "update:modelValue": (value: boolean) => any;
10
+ }, string, PublicProps, Readonly<Props> & Readonly<{
11
+ onError?: ((error: Error) => any) | undefined;
12
+ onSuccess?: ((paymentId: string) => any) | undefined;
13
+ "onUpdate:modelValue"?: ((value: boolean) => any) | undefined;
14
+ }>, {}, {}, {}, {}, string, ComponentProvideOptions, false, {}, any>;
15
+
16
+ declare interface Props {
17
+ modelValue: boolean;
18
+ apiKey: string;
19
+ orderId: string;
20
+ amount: string;
21
+ }
7
22
 
8
23
  export { }
package/dist/vue.js CHANGED
@@ -1,10 +1,142 @@
1
- var __plugin_vue_export_helper_default = (e, t) => {
2
- let n = e.__vccOpts || e;
3
- for (let [e, r] of t) n[e] = r;
4
- return n;
5
- }, _sfc_main = {};
6
- function _sfc_render(e, t) {
7
- return null;
8
- }
9
- var PaymentDialog_default = /* @__PURE__ */ __plugin_vue_export_helper_default(_sfc_main, [["render", _sfc_render]]);
1
+ import { t as cppay_default } from "./cppay-gIC4-2qD.js";
2
+ /* empty css */
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__ */ ((e, k) => {
5
+ let A = e.__vccOpts || e;
6
+ for (let [e, j] of k) A[e] = j;
7
+ return A;
8
+ })(/* @__PURE__ */ defineComponent({
9
+ __name: "PaymentDialog",
10
+ props: {
11
+ modelValue: { type: Boolean },
12
+ apiKey: {},
13
+ orderId: {},
14
+ amount: {}
15
+ },
16
+ emits: [
17
+ "update:modelValue",
18
+ "success",
19
+ "error"
20
+ ],
21
+ setup(N, { emit: P }) {
22
+ let F = N, I = P, 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((e) => e.chain === V.value)), G = computed(() => W.value?.tokens || []), K = computed(() => G.value.find((e) => e.symbol === H.value)), q = ref(1), J = computed(() => H.value ? (parseFloat(F.amount) / q.value).toFixed(6) : "0"), Y = () => {
23
+ I("update:modelValue", !1), setTimeout(() => {
24
+ R.value = "select", U.value = null;
25
+ }, 300);
26
+ }, X = async () => {
27
+ try {
28
+ z.value = !0, B.value = await L.getSupportedChains(), B.value.length > 0 && (V.value = B.value[0].chain);
29
+ } catch (e) {
30
+ I("error", e);
31
+ } finally {
32
+ z.value = !1;
33
+ }
34
+ }, Z = async () => {
35
+ if (!(!V.value || !H.value)) try {
36
+ z.value = !0;
37
+ let e = await L.createPayment({
38
+ paymentChain: V.value,
39
+ paymentToken: H.value,
40
+ orderId: F.orderId,
41
+ amount: J.value
42
+ });
43
+ U.value = {
44
+ paymentId: e.paymentId,
45
+ paymentAmount: e.paymentAmount,
46
+ receiveAddress: K.value?.receiveAddresses[0] || ""
47
+ }, R.value = "payment";
48
+ } catch (e) {
49
+ I("error", e);
50
+ } finally {
51
+ z.value = !1;
52
+ }
53
+ }, Q = async () => {
54
+ if (U.value) try {
55
+ z.value = !0, await L.checkPaymentStatus(U.value.paymentId, 1e3), I("success", U.value.paymentId), Y();
56
+ } catch (e) {
57
+ I("error", e);
58
+ } finally {
59
+ z.value = !1;
60
+ }
61
+ }, $ = async () => {
62
+ U.value?.receiveAddress && await navigator.clipboard.writeText(U.value.receiveAddress);
63
+ };
64
+ return watch(() => F.modelValue, (e) => {
65
+ e && B.value.length === 0 && X();
66
+ }), watch(V, () => {
67
+ G.value.length > 0 && (H.value = G.value[0].symbol);
68
+ }), (e, M) => (openBlock(), createBlock(Teleport, { to: "body" }, [createVNode(Transition, { name: "_cppay-fade" }, {
69
+ default: withCtx(() => [N.modelValue ? (openBlock(), createElementBlock("div", {
70
+ key: 0,
71
+ class: "_cppay-overlay",
72
+ onClick: withModifiers(Y, ["self"])
73
+ }, [createElementVNode("div", _hoisted_1, [createElementVNode("div", _hoisted_2, [createElementVNode("h2", _hoisted_3, toDisplayString(R.value === "select" ? "选择支付方式" : "完成支付"), 1), createElementVNode("button", {
74
+ onClick: Y,
75
+ class: "_cppay-close-btn",
76
+ disabled: z.value
77
+ }, [...M[1] ||= [createElementVNode("svg", {
78
+ fill: "none",
79
+ stroke: "currentColor",
80
+ viewBox: "0 0 24 24"
81
+ }, [createElementVNode("path", {
82
+ "stroke-linecap": "round",
83
+ "stroke-linejoin": "round",
84
+ "stroke-width": "2",
85
+ d: "M6 18L18 6M6 6l12 12"
86
+ })], -1)]], 8, _hoisted_4)]), createElementVNode("div", _hoisted_5, [R.value === "select" ? (openBlock(), createElementBlock("div", _hoisted_6, [
87
+ createElementVNode("div", _hoisted_7, [M[2] ||= createElementVNode("label", { class: "_cppay-label" }, "支付网络", -1), createElementVNode("div", _hoisted_8, [(openBlock(!0), createElementBlock(Fragment, null, renderList(B.value, (e) => (openBlock(), createElementBlock("button", {
88
+ key: e.chain,
89
+ onClick: (k) => V.value = e.chain,
90
+ class: normalizeClass(["_cppay-select-btn", V.value === e.chain ? "_cppay-selected" : ""])
91
+ }, [e.icon ? (openBlock(), createElementBlock("img", {
92
+ key: 0,
93
+ src: e.icon,
94
+ alt: e.chain
95
+ }, null, 8, _hoisted_10)) : createCommentVNode("", !0), createElementVNode("span", null, toDisplayString(e.chain), 1)], 10, _hoisted_9))), 128))])]),
96
+ createElementVNode("div", _hoisted_11, [M[3] ||= createElementVNode("label", { class: "_cppay-label" }, "支付代币", -1), createElementVNode("div", _hoisted_12, [(openBlock(!0), createElementBlock(Fragment, null, renderList(G.value, (e) => (openBlock(), createElementBlock("button", {
97
+ key: e.symbol,
98
+ onClick: (k) => H.value = e.symbol,
99
+ class: normalizeClass(["_cppay-select-btn", H.value === e.symbol ? "_cppay-selected" : ""])
100
+ }, [e.icon ? (openBlock(), createElementBlock("img", {
101
+ key: 0,
102
+ src: e.icon,
103
+ alt: e.symbol
104
+ }, null, 8, _hoisted_14)) : createCommentVNode("", !0), createElementVNode("span", null, toDisplayString(e.symbol), 1)], 10, _hoisted_13))), 128))])]),
105
+ createElementVNode("div", _hoisted_15, [createElementVNode("div", _hoisted_16, [createElementVNode("div", _hoisted_17, [M[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(N.amount), 1)])])])]),
106
+ createElementVNode("div", _hoisted_21, [createElementVNode("button", {
107
+ onClick: Z,
108
+ disabled: !V.value || !H.value || z.value,
109
+ class: "_cppay-btn _cppay-btn-primary"
110
+ }, toDisplayString(z.value ? "处理中..." : "继续支付"), 9, _hoisted_22)])
111
+ ])) : R.value === "payment" && U.value ? (openBlock(), createElementBlock("div", _hoisted_23, [
112
+ M[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, [M[5] ||= createElementVNode("div", { class: "_cppay-info-label" }, "支付金额", -1), createElementVNode("div", _hoisted_26, toDisplayString(U.value.paymentAmount) + " " + toDisplayString(H.value), 1)]), createElementVNode("div", _hoisted_27, [M[7] ||= createElementVNode("div", { class: "_cppay-info-label" }, "支付地址", -1), createElementVNode("div", _hoisted_28, [createElementVNode("code", null, toDisplayString(U.value.receiveAddress), 1), createElementVNode("button", {
114
+ onClick: $,
115
+ class: "_cppay-copy-btn",
116
+ title: "复制地址"
117
+ }, [...M[6] ||= [createElementVNode("svg", {
118
+ fill: "none",
119
+ stroke: "currentColor",
120
+ viewBox: "0 0 24 24"
121
+ }, [createElementVNode("path", {
122
+ "stroke-linecap": "round",
123
+ "stroke-linejoin": "round",
124
+ "stroke-width": "2",
125
+ 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"
126
+ })], -1)]])])])]),
127
+ createElementVNode("div", _hoisted_29, [createElementVNode("button", {
128
+ onClick: Q,
129
+ disabled: z.value,
130
+ class: "_cppay-btn _cppay-btn-primary"
131
+ }, toDisplayString(z.value ? "检查支付状态..." : "我已完成支付"), 9, _hoisted_30)]),
132
+ createElementVNode("div", _hoisted_31, [createElementVNode("button", {
133
+ onClick: M[0] ||= (e) => R.value = "select",
134
+ disabled: z.value,
135
+ class: "_cppay-btn _cppay-btn-secondary"
136
+ }, " 更改支付方式 ", 8, _hoisted_32)])
137
+ ])) : createCommentVNode("", !0)])])])) : createCommentVNode("", !0)]),
138
+ _: 1
139
+ })]));
140
+ }
141
+ }), [["__scopeId", "data-v-b7958c41"]]);
10
142
  export { PaymentDialog_default as PaymentDialog };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cppay-sdk",
3
- "version": "0.0.2-beta.4",
3
+ "version": "0.0.2-beta.5",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "dev": "vite",