@t402/vue 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.cjs +746 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/index.d.cts +600 -0
- package/dist/esm/index.d.ts +600 -0
- package/dist/esm/index.js +720 -0
- package/dist/esm/index.js.map +1 -0
- package/package.json +73 -0
|
@@ -0,0 +1,720 @@
|
|
|
1
|
+
import { defineComponent, h, ref, computed } from 'vue';
|
|
2
|
+
|
|
3
|
+
// src/components/Spinner.ts
|
|
4
|
+
var sizeConfig = {
|
|
5
|
+
sm: { width: "16px", height: "16px", borderWidth: "2px" },
|
|
6
|
+
md: { width: "24px", height: "24px", borderWidth: "3px" },
|
|
7
|
+
lg: { width: "32px", height: "32px", borderWidth: "4px" }
|
|
8
|
+
};
|
|
9
|
+
var Spinner = defineComponent({
|
|
10
|
+
name: "T402Spinner",
|
|
11
|
+
props: {
|
|
12
|
+
size: {
|
|
13
|
+
type: String,
|
|
14
|
+
default: "md"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
setup(props) {
|
|
18
|
+
return () => {
|
|
19
|
+
const config = sizeConfig[props.size];
|
|
20
|
+
return h("span", {
|
|
21
|
+
role: "status",
|
|
22
|
+
"aria-label": "Loading",
|
|
23
|
+
style: {
|
|
24
|
+
width: config.width,
|
|
25
|
+
height: config.height,
|
|
26
|
+
borderWidth: config.borderWidth,
|
|
27
|
+
borderStyle: "solid",
|
|
28
|
+
borderColor: "#e5e7eb",
|
|
29
|
+
borderTopColor: "#3b82f6",
|
|
30
|
+
borderRadius: "50%",
|
|
31
|
+
animation: "t402-spin 0.8s linear infinite",
|
|
32
|
+
display: "inline-block"
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
var spinnerStyles = `
|
|
39
|
+
@keyframes t402-spin {
|
|
40
|
+
to { transform: rotate(360deg); }
|
|
41
|
+
}
|
|
42
|
+
`;
|
|
43
|
+
var baseStyles = {
|
|
44
|
+
display: "inline-flex",
|
|
45
|
+
alignItems: "center",
|
|
46
|
+
justifyContent: "center",
|
|
47
|
+
gap: "8px",
|
|
48
|
+
fontWeight: "600",
|
|
49
|
+
borderRadius: "8px",
|
|
50
|
+
cursor: "pointer",
|
|
51
|
+
transition: "all 0.15s ease",
|
|
52
|
+
border: "none",
|
|
53
|
+
fontFamily: "inherit"
|
|
54
|
+
};
|
|
55
|
+
var variantStyles = {
|
|
56
|
+
primary: {
|
|
57
|
+
backgroundColor: "#2563eb",
|
|
58
|
+
color: "#ffffff"
|
|
59
|
+
},
|
|
60
|
+
secondary: {
|
|
61
|
+
backgroundColor: "#6b7280",
|
|
62
|
+
color: "#ffffff"
|
|
63
|
+
},
|
|
64
|
+
outline: {
|
|
65
|
+
backgroundColor: "transparent",
|
|
66
|
+
color: "#2563eb",
|
|
67
|
+
border: "2px solid #2563eb"
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
var sizeStyles = {
|
|
71
|
+
sm: {
|
|
72
|
+
padding: "8px 16px",
|
|
73
|
+
fontSize: "14px"
|
|
74
|
+
},
|
|
75
|
+
md: {
|
|
76
|
+
padding: "12px 24px",
|
|
77
|
+
fontSize: "16px"
|
|
78
|
+
},
|
|
79
|
+
lg: {
|
|
80
|
+
padding: "16px 32px",
|
|
81
|
+
fontSize: "18px"
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
var PaymentButton = defineComponent({
|
|
85
|
+
name: "T402PaymentButton",
|
|
86
|
+
props: {
|
|
87
|
+
disabled: {
|
|
88
|
+
type: Boolean,
|
|
89
|
+
default: false
|
|
90
|
+
},
|
|
91
|
+
loading: {
|
|
92
|
+
type: Boolean,
|
|
93
|
+
default: false
|
|
94
|
+
},
|
|
95
|
+
variant: {
|
|
96
|
+
type: String,
|
|
97
|
+
default: "primary"
|
|
98
|
+
},
|
|
99
|
+
size: {
|
|
100
|
+
type: String,
|
|
101
|
+
default: "md"
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
emits: ["click"],
|
|
105
|
+
setup(props, { emit, slots }) {
|
|
106
|
+
const isHovered = ref(false);
|
|
107
|
+
const isDisabled = computed(() => props.disabled || props.loading);
|
|
108
|
+
const buttonStyle = computed(() => ({
|
|
109
|
+
...baseStyles,
|
|
110
|
+
...variantStyles[props.variant],
|
|
111
|
+
...sizeStyles[props.size],
|
|
112
|
+
...isDisabled.value ? { opacity: "0.6", cursor: "not-allowed" } : {},
|
|
113
|
+
...isHovered.value && !isDisabled.value ? { filter: "brightness(1.1)", transform: "translateY(-1px)" } : {}
|
|
114
|
+
}));
|
|
115
|
+
const handleClick = () => {
|
|
116
|
+
if (!isDisabled.value) {
|
|
117
|
+
emit("click");
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
return () => h(
|
|
121
|
+
"button",
|
|
122
|
+
{
|
|
123
|
+
type: "button",
|
|
124
|
+
disabled: isDisabled.value,
|
|
125
|
+
style: buttonStyle.value,
|
|
126
|
+
onClick: handleClick,
|
|
127
|
+
onMouseenter: () => isHovered.value = true,
|
|
128
|
+
onMouseleave: () => isHovered.value = false
|
|
129
|
+
},
|
|
130
|
+
[
|
|
131
|
+
props.loading ? h(Spinner, { size: "sm" }) : null,
|
|
132
|
+
slots.default ? slots.default() : "Pay Now"
|
|
133
|
+
]
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
var statusStyles = {
|
|
138
|
+
idle: {
|
|
139
|
+
backgroundColor: "#f3f4f6",
|
|
140
|
+
color: "#374151",
|
|
141
|
+
borderColor: "#d1d5db"
|
|
142
|
+
},
|
|
143
|
+
loading: {
|
|
144
|
+
backgroundColor: "#eff6ff",
|
|
145
|
+
color: "#1d4ed8",
|
|
146
|
+
borderColor: "#93c5fd"
|
|
147
|
+
},
|
|
148
|
+
success: {
|
|
149
|
+
backgroundColor: "#f0fdf4",
|
|
150
|
+
color: "#166534",
|
|
151
|
+
borderColor: "#86efac"
|
|
152
|
+
},
|
|
153
|
+
error: {
|
|
154
|
+
backgroundColor: "#fef2f2",
|
|
155
|
+
color: "#dc2626",
|
|
156
|
+
borderColor: "#fca5a5"
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
var baseStyles2 = {
|
|
160
|
+
display: "flex",
|
|
161
|
+
alignItems: "center",
|
|
162
|
+
gap: "8px",
|
|
163
|
+
padding: "12px 16px",
|
|
164
|
+
borderRadius: "8px",
|
|
165
|
+
borderWidth: "1px",
|
|
166
|
+
borderStyle: "solid",
|
|
167
|
+
fontSize: "14px",
|
|
168
|
+
fontWeight: "500"
|
|
169
|
+
};
|
|
170
|
+
var icons = {
|
|
171
|
+
idle: "\u25CB",
|
|
172
|
+
loading: "",
|
|
173
|
+
success: "\u2713",
|
|
174
|
+
error: "\u2715"
|
|
175
|
+
};
|
|
176
|
+
var defaultMessages = {
|
|
177
|
+
idle: "Ready to pay",
|
|
178
|
+
loading: "Processing...",
|
|
179
|
+
success: "Payment successful",
|
|
180
|
+
error: "Payment failed"
|
|
181
|
+
};
|
|
182
|
+
var PaymentStatusDisplay = defineComponent({
|
|
183
|
+
name: "T402PaymentStatusDisplay",
|
|
184
|
+
props: {
|
|
185
|
+
status: {
|
|
186
|
+
type: String,
|
|
187
|
+
required: true
|
|
188
|
+
},
|
|
189
|
+
message: {
|
|
190
|
+
type: String,
|
|
191
|
+
default: void 0
|
|
192
|
+
}
|
|
193
|
+
},
|
|
194
|
+
setup(props) {
|
|
195
|
+
const combinedStyle = computed(() => ({
|
|
196
|
+
...baseStyles2,
|
|
197
|
+
...statusStyles[props.status]
|
|
198
|
+
}));
|
|
199
|
+
const displayMessage = computed(() => props.message || defaultMessages[props.status]);
|
|
200
|
+
return () => h(
|
|
201
|
+
"div",
|
|
202
|
+
{
|
|
203
|
+
role: "status",
|
|
204
|
+
"aria-live": "polite",
|
|
205
|
+
style: combinedStyle.value
|
|
206
|
+
},
|
|
207
|
+
[
|
|
208
|
+
props.status === "loading" ? h(Spinner, { size: "sm" }) : h("span", { style: { fontSize: "16px" } }, icons[props.status]),
|
|
209
|
+
h("span", displayMessage.value)
|
|
210
|
+
]
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
// src/utils/index.ts
|
|
216
|
+
var EVM_CHAIN_IDS = {
|
|
217
|
+
ETHEREUM_MAINNET: "1",
|
|
218
|
+
BASE_MAINNET: "8453",
|
|
219
|
+
BASE_SEPOLIA: "84532",
|
|
220
|
+
ARBITRUM_MAINNET: "42161",
|
|
221
|
+
ARBITRUM_SEPOLIA: "421614"
|
|
222
|
+
};
|
|
223
|
+
var SOLANA_NETWORK_REFS = {
|
|
224
|
+
MAINNET: "5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",
|
|
225
|
+
DEVNET: "EtWTRABZaYq6iMfeYKouRu166VU2xqa1"
|
|
226
|
+
};
|
|
227
|
+
var TON_NETWORK_REFS = {
|
|
228
|
+
MAINNET: "-239",
|
|
229
|
+
TESTNET: "-3"
|
|
230
|
+
};
|
|
231
|
+
var TRON_NETWORK_REFS = {
|
|
232
|
+
MAINNET: "mainnet",
|
|
233
|
+
NILE: "nile",
|
|
234
|
+
SHASTA: "shasta"
|
|
235
|
+
};
|
|
236
|
+
function normalizePaymentRequirements(paymentRequirements) {
|
|
237
|
+
if (Array.isArray(paymentRequirements)) {
|
|
238
|
+
return paymentRequirements;
|
|
239
|
+
}
|
|
240
|
+
return [paymentRequirements];
|
|
241
|
+
}
|
|
242
|
+
function getPreferredNetworks(testnet) {
|
|
243
|
+
if (testnet) {
|
|
244
|
+
return [
|
|
245
|
+
`eip155:${EVM_CHAIN_IDS.BASE_SEPOLIA}`,
|
|
246
|
+
`eip155:${EVM_CHAIN_IDS.ARBITRUM_SEPOLIA}`,
|
|
247
|
+
`solana:${SOLANA_NETWORK_REFS.DEVNET}`
|
|
248
|
+
];
|
|
249
|
+
}
|
|
250
|
+
return [
|
|
251
|
+
`eip155:${EVM_CHAIN_IDS.BASE_MAINNET}`,
|
|
252
|
+
`eip155:${EVM_CHAIN_IDS.ARBITRUM_MAINNET}`,
|
|
253
|
+
`solana:${SOLANA_NETWORK_REFS.MAINNET}`
|
|
254
|
+
];
|
|
255
|
+
}
|
|
256
|
+
function choosePaymentRequirement(paymentRequirements, testnet) {
|
|
257
|
+
const normalized = normalizePaymentRequirements(paymentRequirements);
|
|
258
|
+
const preferredNetworks = getPreferredNetworks(testnet);
|
|
259
|
+
for (const preferredNetwork of preferredNetworks) {
|
|
260
|
+
const match = normalized.find((req) => req.network === preferredNetwork);
|
|
261
|
+
if (match) {
|
|
262
|
+
return match;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
return normalized[0];
|
|
266
|
+
}
|
|
267
|
+
function isEvmNetwork(network) {
|
|
268
|
+
return network.startsWith("eip155:");
|
|
269
|
+
}
|
|
270
|
+
function isSvmNetwork(network) {
|
|
271
|
+
return network.startsWith("solana:");
|
|
272
|
+
}
|
|
273
|
+
function isTonNetwork(network) {
|
|
274
|
+
return network.startsWith("ton:");
|
|
275
|
+
}
|
|
276
|
+
function isTronNetwork(network) {
|
|
277
|
+
return network.startsWith("tron:");
|
|
278
|
+
}
|
|
279
|
+
var EVM_CHAIN_NAMES = {
|
|
280
|
+
"1": "Ethereum",
|
|
281
|
+
"10": "Optimism",
|
|
282
|
+
"137": "Polygon",
|
|
283
|
+
"8453": "Base",
|
|
284
|
+
"42161": "Arbitrum One",
|
|
285
|
+
"84532": "Base Sepolia",
|
|
286
|
+
"421614": "Arbitrum Sepolia",
|
|
287
|
+
"11155111": "Sepolia"
|
|
288
|
+
};
|
|
289
|
+
function getNetworkDisplayName(network) {
|
|
290
|
+
if (network.startsWith("eip155:")) {
|
|
291
|
+
const chainId = network.split(":")[1];
|
|
292
|
+
return EVM_CHAIN_NAMES[chainId] ?? `Chain ${chainId}`;
|
|
293
|
+
}
|
|
294
|
+
if (network.startsWith("solana:")) {
|
|
295
|
+
const ref6 = network.split(":")[1];
|
|
296
|
+
return ref6 === SOLANA_NETWORK_REFS.DEVNET ? "Solana Devnet" : "Solana";
|
|
297
|
+
}
|
|
298
|
+
if (network.startsWith("ton:")) {
|
|
299
|
+
const ref6 = network.split(":")[1];
|
|
300
|
+
return ref6 === TON_NETWORK_REFS.TESTNET ? "TON Testnet" : "TON";
|
|
301
|
+
}
|
|
302
|
+
if (network.startsWith("tron:")) {
|
|
303
|
+
const ref6 = network.split(":")[1];
|
|
304
|
+
if (ref6 === TRON_NETWORK_REFS.NILE) return "TRON Nile";
|
|
305
|
+
if (ref6 === TRON_NETWORK_REFS.SHASTA) return "TRON Shasta";
|
|
306
|
+
return "TRON";
|
|
307
|
+
}
|
|
308
|
+
return network;
|
|
309
|
+
}
|
|
310
|
+
var TESTNET_CHAIN_IDS = /* @__PURE__ */ new Set(["84532", "421614", "11155111", "80001", "97"]);
|
|
311
|
+
function isTestnetNetwork(network) {
|
|
312
|
+
if (network.startsWith("eip155:")) {
|
|
313
|
+
const chainId = network.split(":")[1];
|
|
314
|
+
return TESTNET_CHAIN_IDS.has(chainId);
|
|
315
|
+
}
|
|
316
|
+
if (network.startsWith("solana:")) {
|
|
317
|
+
const ref6 = network.split(":")[1];
|
|
318
|
+
return ref6 === SOLANA_NETWORK_REFS.DEVNET;
|
|
319
|
+
}
|
|
320
|
+
if (network.startsWith("ton:")) {
|
|
321
|
+
const ref6 = network.split(":")[1];
|
|
322
|
+
return ref6 === TON_NETWORK_REFS.TESTNET;
|
|
323
|
+
}
|
|
324
|
+
if (network.startsWith("tron:")) {
|
|
325
|
+
const ref6 = network.split(":")[1];
|
|
326
|
+
return ref6 === TRON_NETWORK_REFS.NILE || ref6 === TRON_NETWORK_REFS.SHASTA;
|
|
327
|
+
}
|
|
328
|
+
return false;
|
|
329
|
+
}
|
|
330
|
+
function truncateAddress(address, startChars = 6, endChars = 4) {
|
|
331
|
+
if (address.length <= startChars + endChars + 3) {
|
|
332
|
+
return address;
|
|
333
|
+
}
|
|
334
|
+
return `${address.slice(0, startChars)}...${address.slice(-endChars)}`;
|
|
335
|
+
}
|
|
336
|
+
function formatTokenAmount(amount, decimals = 6, maxDecimals = 2) {
|
|
337
|
+
const value = BigInt(amount);
|
|
338
|
+
const divisor = BigInt(10 ** decimals);
|
|
339
|
+
const integerPart = value / divisor;
|
|
340
|
+
const fractionalPart = value % divisor;
|
|
341
|
+
if (fractionalPart === 0n) {
|
|
342
|
+
return integerPart.toString();
|
|
343
|
+
}
|
|
344
|
+
const fractionalStr = fractionalPart.toString().padStart(decimals, "0");
|
|
345
|
+
const trimmed = fractionalStr.slice(0, maxDecimals).replace(/0+$/, "");
|
|
346
|
+
if (trimmed === "") {
|
|
347
|
+
return integerPart.toString();
|
|
348
|
+
}
|
|
349
|
+
return `${integerPart}.${trimmed}`;
|
|
350
|
+
}
|
|
351
|
+
function getAssetDisplayName(asset) {
|
|
352
|
+
const assetLower = asset.toLowerCase();
|
|
353
|
+
switch (assetLower) {
|
|
354
|
+
case "usdt":
|
|
355
|
+
return "USDT";
|
|
356
|
+
case "usdt0":
|
|
357
|
+
return "USDT0";
|
|
358
|
+
case "usdc":
|
|
359
|
+
return "USDC";
|
|
360
|
+
default:
|
|
361
|
+
return asset.toUpperCase();
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
// src/components/PaymentDetails.ts
|
|
366
|
+
var containerStyles = {
|
|
367
|
+
backgroundColor: "#f9fafb",
|
|
368
|
+
borderRadius: "12px",
|
|
369
|
+
padding: "16px",
|
|
370
|
+
borderWidth: "1px",
|
|
371
|
+
borderStyle: "solid",
|
|
372
|
+
borderColor: "#e5e7eb"
|
|
373
|
+
};
|
|
374
|
+
var rowStyles = {
|
|
375
|
+
display: "flex",
|
|
376
|
+
justifyContent: "space-between",
|
|
377
|
+
alignItems: "center",
|
|
378
|
+
padding: "8px 0",
|
|
379
|
+
borderBottomWidth: "1px",
|
|
380
|
+
borderBottomStyle: "solid",
|
|
381
|
+
borderBottomColor: "#e5e7eb"
|
|
382
|
+
};
|
|
383
|
+
var lastRowStyles = {
|
|
384
|
+
...rowStyles,
|
|
385
|
+
borderBottomWidth: "0"
|
|
386
|
+
};
|
|
387
|
+
var labelStyles = {
|
|
388
|
+
color: "#6b7280",
|
|
389
|
+
fontSize: "14px"
|
|
390
|
+
};
|
|
391
|
+
var valueStyles = {
|
|
392
|
+
color: "#111827",
|
|
393
|
+
fontSize: "14px",
|
|
394
|
+
fontWeight: "500"
|
|
395
|
+
};
|
|
396
|
+
var amountStyles = {
|
|
397
|
+
color: "#111827",
|
|
398
|
+
fontSize: "20px",
|
|
399
|
+
fontWeight: "700"
|
|
400
|
+
};
|
|
401
|
+
var PaymentDetails = defineComponent({
|
|
402
|
+
name: "T402PaymentDetails",
|
|
403
|
+
props: {
|
|
404
|
+
requirement: {
|
|
405
|
+
type: Object,
|
|
406
|
+
required: true
|
|
407
|
+
},
|
|
408
|
+
showNetwork: {
|
|
409
|
+
type: Boolean,
|
|
410
|
+
default: true
|
|
411
|
+
},
|
|
412
|
+
showAsset: {
|
|
413
|
+
type: Boolean,
|
|
414
|
+
default: true
|
|
415
|
+
},
|
|
416
|
+
showRecipient: {
|
|
417
|
+
type: Boolean,
|
|
418
|
+
default: false
|
|
419
|
+
}
|
|
420
|
+
},
|
|
421
|
+
setup(props) {
|
|
422
|
+
const formattedAmount = computed(() => formatTokenAmount(props.requirement.amount));
|
|
423
|
+
const assetName = computed(() => getAssetDisplayName(props.requirement.asset));
|
|
424
|
+
const networkName = computed(() => getNetworkDisplayName(props.requirement.network));
|
|
425
|
+
const truncatedAddress = computed(() => truncateAddress(props.requirement.payTo));
|
|
426
|
+
return () => {
|
|
427
|
+
const rows = [];
|
|
428
|
+
rows.push(
|
|
429
|
+
h("div", { style: rowStyles }, [
|
|
430
|
+
h("span", { style: labelStyles }, "Amount"),
|
|
431
|
+
h("span", { style: amountStyles }, `${formattedAmount.value} ${assetName.value}`)
|
|
432
|
+
])
|
|
433
|
+
);
|
|
434
|
+
if (props.showNetwork) {
|
|
435
|
+
rows.push(
|
|
436
|
+
h("div", { style: rowStyles }, [
|
|
437
|
+
h("span", { style: labelStyles }, "Network"),
|
|
438
|
+
h("span", { style: valueStyles }, networkName.value)
|
|
439
|
+
])
|
|
440
|
+
);
|
|
441
|
+
}
|
|
442
|
+
if (props.showAsset) {
|
|
443
|
+
rows.push(
|
|
444
|
+
h("div", { style: rowStyles }, [
|
|
445
|
+
h("span", { style: labelStyles }, "Asset"),
|
|
446
|
+
h("span", { style: valueStyles }, assetName.value)
|
|
447
|
+
])
|
|
448
|
+
);
|
|
449
|
+
}
|
|
450
|
+
if (props.showRecipient) {
|
|
451
|
+
rows.push(
|
|
452
|
+
h("div", { style: lastRowStyles }, [
|
|
453
|
+
h("span", { style: labelStyles }, "Recipient"),
|
|
454
|
+
h(
|
|
455
|
+
"span",
|
|
456
|
+
{
|
|
457
|
+
style: { ...valueStyles, fontFamily: "monospace" },
|
|
458
|
+
title: props.requirement.payTo
|
|
459
|
+
},
|
|
460
|
+
truncatedAddress.value
|
|
461
|
+
)
|
|
462
|
+
])
|
|
463
|
+
);
|
|
464
|
+
}
|
|
465
|
+
return h("div", { style: containerStyles }, rows);
|
|
466
|
+
};
|
|
467
|
+
}
|
|
468
|
+
});
|
|
469
|
+
var containerStyles2 = {
|
|
470
|
+
display: "inline-flex",
|
|
471
|
+
alignItems: "center",
|
|
472
|
+
gap: "8px",
|
|
473
|
+
fontFamily: "monospace",
|
|
474
|
+
fontSize: "14px"
|
|
475
|
+
};
|
|
476
|
+
var addressStyles = {
|
|
477
|
+
color: "#374151"
|
|
478
|
+
};
|
|
479
|
+
var buttonStyles = {
|
|
480
|
+
background: "none",
|
|
481
|
+
border: "none",
|
|
482
|
+
cursor: "pointer",
|
|
483
|
+
padding: "4px",
|
|
484
|
+
borderRadius: "4px",
|
|
485
|
+
color: "#6b7280",
|
|
486
|
+
transition: "all 0.15s ease",
|
|
487
|
+
display: "inline-flex",
|
|
488
|
+
alignItems: "center",
|
|
489
|
+
justifyContent: "center"
|
|
490
|
+
};
|
|
491
|
+
var copiedButtonStyles = {
|
|
492
|
+
...buttonStyles,
|
|
493
|
+
color: "#22c55e"
|
|
494
|
+
};
|
|
495
|
+
var AddressDisplay = defineComponent({
|
|
496
|
+
name: "T402AddressDisplay",
|
|
497
|
+
props: {
|
|
498
|
+
address: {
|
|
499
|
+
type: String,
|
|
500
|
+
required: true
|
|
501
|
+
},
|
|
502
|
+
startChars: {
|
|
503
|
+
type: Number,
|
|
504
|
+
default: 6
|
|
505
|
+
},
|
|
506
|
+
endChars: {
|
|
507
|
+
type: Number,
|
|
508
|
+
default: 4
|
|
509
|
+
},
|
|
510
|
+
copyable: {
|
|
511
|
+
type: Boolean,
|
|
512
|
+
default: false
|
|
513
|
+
}
|
|
514
|
+
},
|
|
515
|
+
setup(props) {
|
|
516
|
+
const copied = ref(false);
|
|
517
|
+
const displayAddress = computed(
|
|
518
|
+
() => truncateAddress(props.address, props.startChars, props.endChars)
|
|
519
|
+
);
|
|
520
|
+
const handleCopy = async () => {
|
|
521
|
+
try {
|
|
522
|
+
await navigator.clipboard.writeText(props.address);
|
|
523
|
+
copied.value = true;
|
|
524
|
+
setTimeout(() => copied.value = false, 2e3);
|
|
525
|
+
} catch {
|
|
526
|
+
const textArea = document.createElement("textarea");
|
|
527
|
+
textArea.value = props.address;
|
|
528
|
+
document.body.appendChild(textArea);
|
|
529
|
+
textArea.select();
|
|
530
|
+
document.execCommand("copy");
|
|
531
|
+
document.body.removeChild(textArea);
|
|
532
|
+
copied.value = true;
|
|
533
|
+
setTimeout(() => copied.value = false, 2e3);
|
|
534
|
+
}
|
|
535
|
+
};
|
|
536
|
+
const copyIcon = () => h(
|
|
537
|
+
"svg",
|
|
538
|
+
{
|
|
539
|
+
width: "16",
|
|
540
|
+
height: "16",
|
|
541
|
+
viewBox: "0 0 24 24",
|
|
542
|
+
fill: "none",
|
|
543
|
+
stroke: "currentColor",
|
|
544
|
+
"stroke-width": "2"
|
|
545
|
+
},
|
|
546
|
+
[
|
|
547
|
+
h("rect", { x: "9", y: "9", width: "13", height: "13", rx: "2", ry: "2" }),
|
|
548
|
+
h("path", { d: "M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1" })
|
|
549
|
+
]
|
|
550
|
+
);
|
|
551
|
+
const checkIcon = () => h(
|
|
552
|
+
"svg",
|
|
553
|
+
{
|
|
554
|
+
width: "16",
|
|
555
|
+
height: "16",
|
|
556
|
+
viewBox: "0 0 24 24",
|
|
557
|
+
fill: "none",
|
|
558
|
+
stroke: "currentColor",
|
|
559
|
+
"stroke-width": "2"
|
|
560
|
+
},
|
|
561
|
+
[h("polyline", { points: "20 6 9 17 4 12" })]
|
|
562
|
+
);
|
|
563
|
+
return () => h("span", { style: containerStyles2, title: props.address }, [
|
|
564
|
+
h("span", { style: addressStyles }, displayAddress.value),
|
|
565
|
+
props.copyable ? h(
|
|
566
|
+
"button",
|
|
567
|
+
{
|
|
568
|
+
type: "button",
|
|
569
|
+
onClick: handleCopy,
|
|
570
|
+
style: copied.value ? copiedButtonStyles : buttonStyles,
|
|
571
|
+
"aria-label": copied.value ? "Copied" : "Copy address"
|
|
572
|
+
},
|
|
573
|
+
[copied.value ? checkIcon() : copyIcon()]
|
|
574
|
+
) : null
|
|
575
|
+
]);
|
|
576
|
+
}
|
|
577
|
+
});
|
|
578
|
+
function usePaymentRequired(options = {}) {
|
|
579
|
+
const { onSuccess, onError } = options;
|
|
580
|
+
const paymentRequired = ref(null);
|
|
581
|
+
const status = ref("idle");
|
|
582
|
+
const error = ref(null);
|
|
583
|
+
const fetchResource = async (url, fetchOptions) => {
|
|
584
|
+
status.value = "loading";
|
|
585
|
+
error.value = null;
|
|
586
|
+
paymentRequired.value = null;
|
|
587
|
+
try {
|
|
588
|
+
const response = await fetch(url, fetchOptions);
|
|
589
|
+
if (response.status === 402) {
|
|
590
|
+
const data = await response.json();
|
|
591
|
+
paymentRequired.value = data;
|
|
592
|
+
status.value = "idle";
|
|
593
|
+
return null;
|
|
594
|
+
}
|
|
595
|
+
if (response.ok) {
|
|
596
|
+
status.value = "success";
|
|
597
|
+
onSuccess?.(response);
|
|
598
|
+
return response;
|
|
599
|
+
}
|
|
600
|
+
throw new Error(`Request failed with status ${response.status}`);
|
|
601
|
+
} catch (err) {
|
|
602
|
+
const errorMessage = err instanceof Error ? err.message : "Unknown error";
|
|
603
|
+
error.value = errorMessage;
|
|
604
|
+
status.value = "error";
|
|
605
|
+
onError?.(err instanceof Error ? err : new Error(errorMessage));
|
|
606
|
+
return null;
|
|
607
|
+
}
|
|
608
|
+
};
|
|
609
|
+
const reset = () => {
|
|
610
|
+
paymentRequired.value = null;
|
|
611
|
+
status.value = "idle";
|
|
612
|
+
error.value = null;
|
|
613
|
+
};
|
|
614
|
+
return {
|
|
615
|
+
paymentRequired,
|
|
616
|
+
status,
|
|
617
|
+
error,
|
|
618
|
+
fetchResource,
|
|
619
|
+
reset
|
|
620
|
+
};
|
|
621
|
+
}
|
|
622
|
+
function usePaymentStatus() {
|
|
623
|
+
const status = ref("idle");
|
|
624
|
+
const message = ref(null);
|
|
625
|
+
const scheduleMessageClear = (timeout) => {
|
|
626
|
+
if (timeout && timeout > 0) {
|
|
627
|
+
setTimeout(() => {
|
|
628
|
+
message.value = null;
|
|
629
|
+
}, timeout);
|
|
630
|
+
}
|
|
631
|
+
};
|
|
632
|
+
const setStatus = (newStatus, messageText) => {
|
|
633
|
+
status.value = newStatus;
|
|
634
|
+
if (messageText) {
|
|
635
|
+
const type = newStatus === "error" ? "error" : newStatus === "success" ? "success" : "info";
|
|
636
|
+
message.value = { text: messageText, type };
|
|
637
|
+
}
|
|
638
|
+
};
|
|
639
|
+
const setSuccess = (text, timeout) => {
|
|
640
|
+
status.value = "success";
|
|
641
|
+
message.value = { text, type: "success", timeout };
|
|
642
|
+
scheduleMessageClear(timeout);
|
|
643
|
+
};
|
|
644
|
+
const setError = (text) => {
|
|
645
|
+
status.value = "error";
|
|
646
|
+
message.value = { text, type: "error" };
|
|
647
|
+
};
|
|
648
|
+
const setInfo = (text, timeout) => {
|
|
649
|
+
message.value = { text, type: "info", timeout };
|
|
650
|
+
scheduleMessageClear(timeout);
|
|
651
|
+
};
|
|
652
|
+
const setWarning = (text, timeout) => {
|
|
653
|
+
message.value = { text, type: "warning", timeout };
|
|
654
|
+
scheduleMessageClear(timeout);
|
|
655
|
+
};
|
|
656
|
+
const clearMessage = () => {
|
|
657
|
+
message.value = null;
|
|
658
|
+
};
|
|
659
|
+
const reset = () => {
|
|
660
|
+
status.value = "idle";
|
|
661
|
+
message.value = null;
|
|
662
|
+
};
|
|
663
|
+
return {
|
|
664
|
+
status,
|
|
665
|
+
message,
|
|
666
|
+
setStatus,
|
|
667
|
+
setSuccess,
|
|
668
|
+
setError,
|
|
669
|
+
setInfo,
|
|
670
|
+
setWarning,
|
|
671
|
+
clearMessage,
|
|
672
|
+
reset
|
|
673
|
+
};
|
|
674
|
+
}
|
|
675
|
+
function useAsyncPayment(options) {
|
|
676
|
+
const { paymentFn, onSuccess, onError, onStart } = options;
|
|
677
|
+
const status = ref("idle");
|
|
678
|
+
const result = ref(null);
|
|
679
|
+
const error = ref(null);
|
|
680
|
+
const isLoading = computed(() => status.value === "loading");
|
|
681
|
+
const isSuccess = computed(() => status.value === "success");
|
|
682
|
+
const isError = computed(() => status.value === "error");
|
|
683
|
+
const execute = async () => {
|
|
684
|
+
status.value = "loading";
|
|
685
|
+
error.value = null;
|
|
686
|
+
onStart?.();
|
|
687
|
+
try {
|
|
688
|
+
const paymentResult = await paymentFn();
|
|
689
|
+
result.value = paymentResult;
|
|
690
|
+
status.value = "success";
|
|
691
|
+
onSuccess?.(paymentResult);
|
|
692
|
+
return paymentResult;
|
|
693
|
+
} catch (err) {
|
|
694
|
+
const errorMessage = err instanceof Error ? err.message : "Payment failed";
|
|
695
|
+
error.value = errorMessage;
|
|
696
|
+
status.value = "error";
|
|
697
|
+
onError?.(err instanceof Error ? err : new Error(errorMessage));
|
|
698
|
+
return null;
|
|
699
|
+
}
|
|
700
|
+
};
|
|
701
|
+
const reset = () => {
|
|
702
|
+
status.value = "idle";
|
|
703
|
+
result.value = null;
|
|
704
|
+
error.value = null;
|
|
705
|
+
};
|
|
706
|
+
return {
|
|
707
|
+
execute,
|
|
708
|
+
status,
|
|
709
|
+
result,
|
|
710
|
+
error,
|
|
711
|
+
isLoading,
|
|
712
|
+
isSuccess,
|
|
713
|
+
isError,
|
|
714
|
+
reset
|
|
715
|
+
};
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
export { AddressDisplay, EVM_CHAIN_IDS, PaymentButton, PaymentDetails, PaymentStatusDisplay, SOLANA_NETWORK_REFS, Spinner, TON_NETWORK_REFS, TRON_NETWORK_REFS, choosePaymentRequirement, formatTokenAmount, getAssetDisplayName, getNetworkDisplayName, getPreferredNetworks, isEvmNetwork, isSvmNetwork, isTestnetNetwork, isTonNetwork, isTronNetwork, normalizePaymentRequirements, spinnerStyles, truncateAddress, useAsyncPayment, usePaymentRequired, usePaymentStatus };
|
|
719
|
+
//# sourceMappingURL=index.js.map
|
|
720
|
+
//# sourceMappingURL=index.js.map
|