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

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 @@
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,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-rxbtyzyZ.cjs`);;/* empty css */let l=require(`react`);l=s(l);let u=require(`react/jsx-runtime`);var d=({open:e,onClose:t,apiKey:n,orderId:r,amount:i,onSuccess:a,onError:o})=>{let s=(0,l.useMemo)(()=>new c.t(n),[n]),[d,f]=(0,l.useState)(`select`),[p,m]=(0,l.useState)(!1),[h,g]=(0,l.useState)([]),[_,v]=(0,l.useState)(``),[y,b]=(0,l.useState)(``),[x,S]=(0,l.useState)(null),C=(0,l.useMemo)(()=>h.find(e=>e.chain===_),[h,_]),w=(0,l.useMemo)(()=>C?.tokens||[],[C]),T=(0,l.useMemo)(()=>w.find(e=>e.symbol===y),[w,y]),E=(0,l.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,l.useEffect)(()=>{e&&h.length===0&&D()},[e]),(0,l.useEffect)(()=>{w.length>0&&b(w[0].symbol)},[w]),e?(0,u.jsx)(`div`,{className:`_cppay-overlay`,onClick:e=>e.target===e.currentTarget&&j(),children:(0,u.jsxs)(`div`,{className:`_cppay-dialog`,children:[(0,u.jsxs)(`div`,{className:`_cppay-header`,children:[(0,u.jsx)(`h2`,{className:`_cppay-title`,children:d===`select`?`选择支付方式`:`完成支付`}),(0,u.jsx)(`button`,{onClick:j,disabled:p,className:`_cppay-close-btn`,children:(0,u.jsx)(`svg`,{fill:`none`,stroke:`currentColor`,viewBox:`0 0 24 24`,children:(0,u.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M6 18L18 6M6 6l12 12`})})})]}),(0,u.jsx)(`div`,{className:`_cppay-content`,children:d===`select`?(0,u.jsxs)(`div`,{children:[(0,u.jsxs)(`div`,{className:`_cppay-section`,children:[(0,u.jsx)(`label`,{className:`_cppay-label`,children:`支付网络`}),(0,u.jsx)(`div`,{className:`_cppay-grid`,children:h.map(e=>(0,u.jsxs)(`button`,{onClick:()=>v(e.chain),className:`_cppay-select-btn ${_===e.chain?`_cppay-selected`:``}`,children:[e.icon&&(0,u.jsx)(`img`,{src:e.icon,alt:e.chain}),(0,u.jsx)(`span`,{children:e.chain})]},e.chain))})]}),(0,u.jsxs)(`div`,{className:`_cppay-section`,children:[(0,u.jsx)(`label`,{className:`_cppay-label`,children:`支付代币`}),(0,u.jsx)(`div`,{className:`_cppay-grid`,children:w.map(e=>(0,u.jsxs)(`button`,{onClick:()=>b(e.symbol),className:`_cppay-select-btn ${y===e.symbol?`_cppay-selected`:``}`,children:[e.icon&&(0,u.jsx)(`img`,{src:e.icon,alt:e.symbol}),(0,u.jsx)(`span`,{children:e.symbol})]},e.symbol))})]}),(0,u.jsx)(`div`,{className:`_cppay-section`,children:(0,u.jsx)(`div`,{className:`_cppay-price-box`,children:(0,u.jsxs)(`div`,{className:`_cppay-price-row`,children:[(0,u.jsx)(`span`,{className:`_cppay-price-label`,children:`支付金额`}),(0,u.jsxs)(`div`,{className:`_cppay-price-amount`,children:[(0,u.jsxs)(`div`,{className:`_cppay-price-main`,children:[E,` `,y]}),(0,u.jsxs)(`div`,{className:`_cppay-price-sub`,children:[`≈ $`,i]})]})]})})}),(0,u.jsx)(`div`,{className:`_cppay-section`,children:(0,u.jsx)(`button`,{onClick:O,disabled:!_||!y||p,className:`_cppay-btn _cppay-btn-primary`,children:p?`处理中...`:`继续支付`})})]}):x&&(0,u.jsxs)(`div`,{children:[(0,u.jsx)(`div`,{className:`_cppay-qr-container`,children:(0,u.jsx)(`div`,{className:`_cppay-qr-placeholder`,children:(0,u.jsx)(`span`,{children:`扫码支付`})})}),(0,u.jsxs)(`div`,{className:`_cppay-section`,children:[(0,u.jsxs)(`div`,{className:`_cppay-info-box`,children:[(0,u.jsx)(`div`,{className:`_cppay-info-label`,children:`支付金额`}),(0,u.jsxs)(`div`,{className:`_cppay-info-value`,children:[x.paymentAmount,` `,y]})]}),(0,u.jsxs)(`div`,{className:`_cppay-info-box`,children:[(0,u.jsx)(`div`,{className:`_cppay-info-label`,children:`支付地址`}),(0,u.jsxs)(`div`,{className:`_cppay-address-row`,children:[(0,u.jsx)(`code`,{children:x.receiveAddress}),(0,u.jsx)(`button`,{onClick:A,className:`_cppay-copy-btn`,title:`复制地址`,children:(0,u.jsx)(`svg`,{fill:`none`,stroke:`currentColor`,viewBox:`0 0 24 24`,children:(0,u.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z`})})})]})]})]}),(0,u.jsx)(`div`,{className:`_cppay-section`,children:(0,u.jsx)(`button`,{onClick:k,disabled:p,className:`_cppay-btn _cppay-btn-primary`,children:p?`检查支付状态...`:`我已完成支付`})}),(0,u.jsx)(`div`,{className:`_cppay-section`,children:(0,u.jsx)(`button`,{onClick:()=>f(`select`),disabled:p,className:`_cppay-btn _cppay-btn-secondary`,children:`更改支付方式`})})]})})]})}):null},f=l.default.memo(d);exports.PaymentDialog=f,exports.t=s;
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,228 @@
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
+ 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,
9
+ 1
10
+ ]), A = async () => {
11
+ try {
12
+ _(!0);
13
+ let t = await p.getSupportedChains();
14
+ y(t), t.length > 0 && x(t[0].chain);
15
+ } catch (t) {
16
+ f?.(t);
17
+ } finally {
18
+ _(!1);
19
+ }
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
28
+ });
29
+ T({
30
+ paymentId: t.paymentId,
31
+ paymentAmount: t.paymentAmount,
32
+ receiveAddress: O?.receiveAddresses[0] || ""
33
+ }), h("payment");
34
+ } catch (t) {
35
+ f?.(t);
36
+ } finally {
37
+ _(!1);
38
+ }
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);
44
+ } finally {
45
+ _(!1);
46
+ }
47
+ }, N = async () => {
48
+ w?.receiveAddress && await navigator.clipboard.writeText(w.receiveAddress);
49
+ }, P = () => {
50
+ s(), setTimeout(() => {
51
+ h("select"), T(null);
52
+ }, 300);
53
+ };
54
+ return useEffect(() => {
55
+ o && v.length === 0 && A();
56
+ }, [o]), useEffect(() => {
57
+ D.length > 0 && C(D[0].symbol);
58
+ }, [D]), o ? /* @__PURE__ */ jsx("div", {
59
+ className: "_cppay-overlay",
60
+ onClick: (t) => t.target === t.currentTarget && P(),
61
+ children: /* @__PURE__ */ jsxs("div", {
62
+ className: "_cppay-dialog",
63
+ children: [/* @__PURE__ */ jsxs("div", {
64
+ className: "_cppay-header",
65
+ children: [/* @__PURE__ */ jsx("h2", {
66
+ className: "_cppay-title",
67
+ children: m === "select" ? "选择支付方式" : "完成支付"
68
+ }), /* @__PURE__ */ jsx("button", {
69
+ onClick: P,
70
+ disabled: g,
71
+ className: "_cppay-close-btn",
72
+ children: /* @__PURE__ */ jsx("svg", {
73
+ fill: "none",
74
+ stroke: "currentColor",
75
+ viewBox: "0 0 24 24",
76
+ children: /* @__PURE__ */ jsx("path", {
77
+ strokeLinecap: "round",
78
+ strokeLinejoin: "round",
79
+ strokeWidth: 2,
80
+ d: "M6 18L18 6M6 6l12 12"
81
+ })
82
+ })
83
+ })]
84
+ }), /* @__PURE__ */ jsx("div", {
85
+ className: "_cppay-content",
86
+ children: m === "select" ? /* @__PURE__ */ jsxs("div", { children: [
87
+ /* @__PURE__ */ jsxs("div", {
88
+ className: "_cppay-section",
89
+ children: [/* @__PURE__ */ jsx("label", {
90
+ className: "_cppay-label",
91
+ children: "支付网络"
92
+ }), /* @__PURE__ */ jsx("div", {
93
+ className: "_cppay-grid",
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))
102
+ })]
103
+ }),
104
+ /* @__PURE__ */ jsxs("div", {
105
+ className: "_cppay-section",
106
+ children: [/* @__PURE__ */ jsx("label", {
107
+ className: "_cppay-label",
108
+ children: "支付代币"
109
+ }), /* @__PURE__ */ jsx("div", {
110
+ className: "_cppay-grid",
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))
119
+ })]
120
+ }),
121
+ /* @__PURE__ */ jsx("div", {
122
+ className: "_cppay-section",
123
+ children: /* @__PURE__ */ jsx("div", {
124
+ className: "_cppay-price-box",
125
+ children: /* @__PURE__ */ jsxs("div", {
126
+ className: "_cppay-price-row",
127
+ children: [/* @__PURE__ */ jsx("span", {
128
+ className: "_cppay-price-label",
129
+ children: "支付金额"
130
+ }), /* @__PURE__ */ jsxs("div", {
131
+ className: "_cppay-price-amount",
132
+ children: [/* @__PURE__ */ jsxs("div", {
133
+ className: "_cppay-price-main",
134
+ children: [
135
+ k,
136
+ " ",
137
+ S
138
+ ]
139
+ }), /* @__PURE__ */ jsxs("div", {
140
+ className: "_cppay-price-sub",
141
+ children: ["≈ $", u]
142
+ })]
143
+ })]
144
+ })
145
+ })
146
+ }),
147
+ /* @__PURE__ */ jsx("div", {
148
+ className: "_cppay-section",
149
+ children: /* @__PURE__ */ jsx("button", {
150
+ onClick: j,
151
+ disabled: !b || !S || g,
152
+ className: "_cppay-btn _cppay-btn-primary",
153
+ children: g ? "处理中..." : "继续支付"
154
+ })
155
+ })
156
+ ] }) : w && /* @__PURE__ */ jsxs("div", { children: [
157
+ /* @__PURE__ */ jsx("div", {
158
+ className: "_cppay-qr-container",
159
+ children: /* @__PURE__ */ jsx("div", {
160
+ className: "_cppay-qr-placeholder",
161
+ children: /* @__PURE__ */ jsx("span", { children: "扫码支付" })
162
+ })
163
+ }),
164
+ /* @__PURE__ */ jsxs("div", {
165
+ className: "_cppay-section",
166
+ children: [/* @__PURE__ */ jsxs("div", {
167
+ className: "_cppay-info-box",
168
+ children: [/* @__PURE__ */ jsx("div", {
169
+ className: "_cppay-info-label",
170
+ children: "支付金额"
171
+ }), /* @__PURE__ */ jsxs("div", {
172
+ className: "_cppay-info-value",
173
+ children: [
174
+ w.paymentAmount,
175
+ " ",
176
+ S
177
+ ]
178
+ })]
179
+ }), /* @__PURE__ */ jsxs("div", {
180
+ className: "_cppay-info-box",
181
+ children: [/* @__PURE__ */ jsx("div", {
182
+ className: "_cppay-info-label",
183
+ children: "支付地址"
184
+ }), /* @__PURE__ */ jsxs("div", {
185
+ className: "_cppay-address-row",
186
+ children: [/* @__PURE__ */ jsx("code", { children: w.receiveAddress }), /* @__PURE__ */ jsx("button", {
187
+ onClick: N,
188
+ className: "_cppay-copy-btn",
189
+ title: "复制地址",
190
+ children: /* @__PURE__ */ jsx("svg", {
191
+ fill: "none",
192
+ stroke: "currentColor",
193
+ viewBox: "0 0 24 24",
194
+ children: /* @__PURE__ */ jsx("path", {
195
+ strokeLinecap: "round",
196
+ strokeLinejoin: "round",
197
+ strokeWidth: 2,
198
+ 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"
199
+ })
200
+ })
201
+ })]
202
+ })]
203
+ })]
204
+ }),
205
+ /* @__PURE__ */ jsx("div", {
206
+ className: "_cppay-section",
207
+ children: /* @__PURE__ */ jsx("button", {
208
+ onClick: M,
209
+ disabled: g,
210
+ className: "_cppay-btn _cppay-btn-primary",
211
+ children: g ? "检查支付状态..." : "我已完成支付"
212
+ })
213
+ }),
214
+ /* @__PURE__ */ jsx("div", {
215
+ className: "_cppay-section",
216
+ children: /* @__PURE__ */ jsx("button", {
217
+ onClick: () => h("select"),
218
+ disabled: g,
219
+ className: "_cppay-btn _cppay-btn-secondary",
220
+ children: "更改支付方式"
221
+ })
222
+ })
223
+ ] })
224
+ })]
225
+ })
226
+ }) : null;
227
+ });
3
228
  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.6",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "dev": "vite",