@w3payments/common 1.1.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/index.d.ts +641 -0
- package/dist/index.js +630 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +630 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +78 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,630 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
class PaymentMethodService {
|
|
4
|
+
static instance;
|
|
5
|
+
paymentMethods = /* @__PURE__ */ new Map();
|
|
6
|
+
constructor() {
|
|
7
|
+
}
|
|
8
|
+
static getInstance() {
|
|
9
|
+
if (!PaymentMethodService.instance) {
|
|
10
|
+
PaymentMethodService.instance = new PaymentMethodService();
|
|
11
|
+
}
|
|
12
|
+
return PaymentMethodService.instance;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Register a new payment method
|
|
16
|
+
*/
|
|
17
|
+
register(method) {
|
|
18
|
+
this.paymentMethods.set(method.id, method);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Register multiple payment methods
|
|
22
|
+
*/
|
|
23
|
+
registerMany(methods) {
|
|
24
|
+
methods.forEach((method) => this.register(method));
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Get payment method by ID
|
|
28
|
+
*/
|
|
29
|
+
getPaymentMethod(id) {
|
|
30
|
+
return this.paymentMethods.get(id);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Get all registered payment methods
|
|
34
|
+
*/
|
|
35
|
+
getAllPaymentMethods() {
|
|
36
|
+
return Array.from(this.paymentMethods.values());
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Check if payment method exists
|
|
40
|
+
*/
|
|
41
|
+
hasPaymentMethod(id) {
|
|
42
|
+
return this.paymentMethods.has(id);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Get payment methods by vendor
|
|
46
|
+
*/
|
|
47
|
+
getByVendor(vendorId) {
|
|
48
|
+
return this.getAllPaymentMethods().filter(
|
|
49
|
+
(method) => method.vendorId === vendorId
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Get payment methods by method type (ach, wallet, exchange)
|
|
54
|
+
*/
|
|
55
|
+
getByMethod(methodType) {
|
|
56
|
+
return this.getAllPaymentMethods().filter(
|
|
57
|
+
(method) => method.method === methodType
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Get payment methods by type (fiat or crypto)
|
|
62
|
+
*/
|
|
63
|
+
getByType(type) {
|
|
64
|
+
return this.getAllPaymentMethods().filter((method) => method.type === type);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Get fiat payment methods only
|
|
68
|
+
*/
|
|
69
|
+
getFiatPaymentMethods() {
|
|
70
|
+
return this.getAllPaymentMethods().filter(
|
|
71
|
+
(method) => method.type === "fiat"
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Get crypto payment methods only
|
|
76
|
+
*/
|
|
77
|
+
getCryptoPaymentMethods() {
|
|
78
|
+
return this.getAllPaymentMethods().filter(
|
|
79
|
+
(method) => method.type === "crypto"
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Get payment methods by currency
|
|
84
|
+
*/
|
|
85
|
+
getByCurrency(currencyCode) {
|
|
86
|
+
return this.getAllPaymentMethods().filter(
|
|
87
|
+
(method) => method.supportedCurrencies.includes(currencyCode)
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Get crypto payment methods by network
|
|
92
|
+
*/
|
|
93
|
+
getByNetwork(networkId) {
|
|
94
|
+
return this.getCryptoPaymentMethods().filter(
|
|
95
|
+
(method) => method.network === networkId
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Get crypto payment methods by network and currency combination
|
|
100
|
+
*/
|
|
101
|
+
getByNetworkAndCurrency(networkId, currencyCode) {
|
|
102
|
+
return this.getCryptoPaymentMethods().filter(
|
|
103
|
+
(method) => method.network === networkId && method.currency === currencyCode
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Get payment methods by region
|
|
108
|
+
*/
|
|
109
|
+
getByRegion(region) {
|
|
110
|
+
return this.getAllPaymentMethods().filter(
|
|
111
|
+
(method) => !method.regions || method.regions.length === 0 || method.regions.includes(region)
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Get active payment methods only
|
|
116
|
+
*/
|
|
117
|
+
getActive() {
|
|
118
|
+
return this.getAllPaymentMethods().filter((method) => method.isActive);
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Get available payment methods for currency and region
|
|
122
|
+
*/
|
|
123
|
+
getAvailableFor(currencyCode, region) {
|
|
124
|
+
const methods = this.getByCurrency(currencyCode).filter(
|
|
125
|
+
(method) => method.isActive
|
|
126
|
+
);
|
|
127
|
+
if (region) {
|
|
128
|
+
return methods.filter(
|
|
129
|
+
(method) => !method.regions || method.regions.length === 0 || method.regions.includes(region)
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
return methods;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Search payment methods by name or description
|
|
136
|
+
*/
|
|
137
|
+
searchPaymentMethods(query) {
|
|
138
|
+
const lowerQuery = query.toLowerCase();
|
|
139
|
+
return this.getAllPaymentMethods().filter(
|
|
140
|
+
(method) => method.name.toLowerCase().includes(lowerQuery) || method.description?.toLowerCase().includes(lowerQuery)
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Get wallet payment methods with optional currency and target filters
|
|
145
|
+
*/
|
|
146
|
+
getWalletMethods(filters) {
|
|
147
|
+
const walletMethods = this.getCryptoPaymentMethods().filter(
|
|
148
|
+
(method) => method.method === "wallet"
|
|
149
|
+
);
|
|
150
|
+
console.log("getWalletMethods: All wallet methods:", walletMethods.length);
|
|
151
|
+
console.log("getWalletMethods: Filters:", filters);
|
|
152
|
+
if (!filters) return walletMethods;
|
|
153
|
+
const filtered = walletMethods.filter((method) => {
|
|
154
|
+
const currencyMatches = !filters.currencies?.length || filters.currencies.some(
|
|
155
|
+
(curr) => method.currency.toLowerCase() === curr.toLowerCase()
|
|
156
|
+
);
|
|
157
|
+
const targetMatches = (!filters.targetCurrency || method.currency.toLowerCase() === filters.targetCurrency.toLowerCase()) && (!filters.targetNetwork || method.network.toLowerCase() === filters.targetNetwork.toLowerCase());
|
|
158
|
+
const matches = currencyMatches && targetMatches;
|
|
159
|
+
console.log(
|
|
160
|
+
`getWalletMethods: Method ${method.currency}/${method.network} - currencyMatches: ${currencyMatches}, targetMatches: ${targetMatches}, overall: ${matches}`
|
|
161
|
+
);
|
|
162
|
+
return matches;
|
|
163
|
+
});
|
|
164
|
+
console.log("getWalletMethods: Filtered result:", filtered.length);
|
|
165
|
+
return filtered;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Get exchange payment methods with optional exchange and target filters
|
|
169
|
+
*/
|
|
170
|
+
getExchangeMethods(filters) {
|
|
171
|
+
const exchangeMethods = this.getCryptoPaymentMethods().filter(
|
|
172
|
+
(method) => method.method === "exchange"
|
|
173
|
+
);
|
|
174
|
+
if (!filters) return exchangeMethods;
|
|
175
|
+
return exchangeMethods.filter((method) => {
|
|
176
|
+
const exchangeMatches = !filters.exchanges?.length || filters.exchanges.some(
|
|
177
|
+
(exchange) => method.name.toLowerCase().includes(exchange.toLowerCase())
|
|
178
|
+
);
|
|
179
|
+
const targetMatches = !filters.targetCurrency || method.currency.toLowerCase() === filters.targetCurrency.toLowerCase();
|
|
180
|
+
return exchangeMatches && targetMatches;
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Get fiat payment methods with optional method type filter
|
|
185
|
+
*/
|
|
186
|
+
getFiatMethods(filters) {
|
|
187
|
+
const fiatMethods = this.getFiatPaymentMethods();
|
|
188
|
+
if (!filters?.methods?.length) return fiatMethods;
|
|
189
|
+
return fiatMethods.filter(
|
|
190
|
+
(method) => filters.methods.some(
|
|
191
|
+
(fiat) => method.method.toLowerCase() === fiat.toLowerCase()
|
|
192
|
+
)
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Get simple display options from filter values
|
|
197
|
+
*/
|
|
198
|
+
getDisplayOptions(filters) {
|
|
199
|
+
const result = [];
|
|
200
|
+
console.log(
|
|
201
|
+
"getDisplayOptions: Processing walletFilter:",
|
|
202
|
+
filters?.walletFilter
|
|
203
|
+
);
|
|
204
|
+
filters?.walletFilter?.forEach((currency) => {
|
|
205
|
+
console.log(`getDisplayOptions: Processing wallet currency: ${currency}`);
|
|
206
|
+
const walletMethods = this.getWalletMethods({
|
|
207
|
+
currencies: [currency],
|
|
208
|
+
targetCurrency: filters.targetCurrency,
|
|
209
|
+
targetNetwork: filters.targetNetwork
|
|
210
|
+
});
|
|
211
|
+
console.log(
|
|
212
|
+
`getDisplayOptions: Found ${walletMethods.length} wallet methods for ${currency}`
|
|
213
|
+
);
|
|
214
|
+
if (walletMethods.length > 0) {
|
|
215
|
+
result.push({
|
|
216
|
+
id: `wallet-${currency.toLowerCase()}`,
|
|
217
|
+
displayName: currency,
|
|
218
|
+
method: "wallet"
|
|
219
|
+
});
|
|
220
|
+
console.log(`getDisplayOptions: Added wallet option for ${currency}`);
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
filters?.exchangeFilter?.forEach((exchange) => {
|
|
224
|
+
const exchangeMethods = this.getExchangeMethods({
|
|
225
|
+
exchanges: [exchange],
|
|
226
|
+
targetCurrency: filters.targetCurrency
|
|
227
|
+
});
|
|
228
|
+
if (exchangeMethods.length > 0) {
|
|
229
|
+
result.push({
|
|
230
|
+
id: `exchange-${exchange.toLowerCase()}`,
|
|
231
|
+
displayName: exchange,
|
|
232
|
+
method: "exchange"
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
filters?.fiatFilter?.forEach((fiatMethod) => {
|
|
237
|
+
const fiatMethods = this.getFiatMethods({
|
|
238
|
+
methods: [fiatMethod]
|
|
239
|
+
});
|
|
240
|
+
if (fiatMethods.length > 0) {
|
|
241
|
+
result.push({
|
|
242
|
+
id: `fiat-${fiatMethod.toLowerCase()}`,
|
|
243
|
+
displayName: fiatMethod,
|
|
244
|
+
method: "fiat"
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
return result;
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Clear all payment methods (useful for testing)
|
|
252
|
+
*/
|
|
253
|
+
clear() {
|
|
254
|
+
this.paymentMethods.clear();
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
const paymentMethodService = PaymentMethodService.getInstance();
|
|
258
|
+
class CurrencyService {
|
|
259
|
+
static instance;
|
|
260
|
+
currencies = /* @__PURE__ */ new Map();
|
|
261
|
+
supportedCurrencies = {
|
|
262
|
+
sandbox: /* @__PURE__ */ new Set(),
|
|
263
|
+
production: /* @__PURE__ */ new Set()
|
|
264
|
+
};
|
|
265
|
+
constructor() {
|
|
266
|
+
}
|
|
267
|
+
static getInstance() {
|
|
268
|
+
if (!CurrencyService.instance) {
|
|
269
|
+
CurrencyService.instance = new CurrencyService();
|
|
270
|
+
}
|
|
271
|
+
return CurrencyService.instance;
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Register a new currency
|
|
275
|
+
*/
|
|
276
|
+
register(currency) {
|
|
277
|
+
this.currencies.set(currency.code, currency);
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Register multiple currencies
|
|
281
|
+
*/
|
|
282
|
+
registerMany(currencies) {
|
|
283
|
+
currencies.forEach((currency) => this.register(currency));
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Get currency by code
|
|
287
|
+
*/
|
|
288
|
+
getCurrency(code) {
|
|
289
|
+
return this.currencies.get(code);
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Get all registered currencies
|
|
293
|
+
*/
|
|
294
|
+
getAllCurrencies() {
|
|
295
|
+
return Array.from(this.currencies.values());
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Check if currency exists
|
|
299
|
+
*/
|
|
300
|
+
hasCurrency(code) {
|
|
301
|
+
return this.currencies.has(code);
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Get currency icon URL
|
|
305
|
+
*/
|
|
306
|
+
getCurrencyIcon(code) {
|
|
307
|
+
const currency = this.getCurrency(code);
|
|
308
|
+
return currency?.iconUrl || "";
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* Get cryptocurrencies only
|
|
312
|
+
*/
|
|
313
|
+
getCryptoCurrencies() {
|
|
314
|
+
return this.getAllCurrencies().filter(
|
|
315
|
+
(currency) => currency.type === "crypto"
|
|
316
|
+
);
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Get fiat currencies only
|
|
320
|
+
*/
|
|
321
|
+
getFiatCurrencies() {
|
|
322
|
+
return this.getAllCurrencies().filter(
|
|
323
|
+
(currency) => currency.type === "fiat"
|
|
324
|
+
);
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* Get stablecoins only
|
|
328
|
+
*/
|
|
329
|
+
getStablecoins() {
|
|
330
|
+
return this.getCryptoCurrencies().filter((currency) => currency.isStablecoin);
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* Get currencies by network
|
|
334
|
+
*/
|
|
335
|
+
getCurrenciesByNetwork(networkId) {
|
|
336
|
+
return this.getCryptoCurrencies().filter(
|
|
337
|
+
(currency) => currency.network === networkId
|
|
338
|
+
);
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* Search currencies by code or name
|
|
342
|
+
*/
|
|
343
|
+
searchCurrencies(query) {
|
|
344
|
+
const lowerQuery = query.toLowerCase();
|
|
345
|
+
return this.getAllCurrencies().filter(
|
|
346
|
+
(currency) => currency.code.toLowerCase().includes(lowerQuery) || currency.name.toLowerCase().includes(lowerQuery)
|
|
347
|
+
);
|
|
348
|
+
}
|
|
349
|
+
/**
|
|
350
|
+
* Add currency to supported list for environment
|
|
351
|
+
*/
|
|
352
|
+
addSupportedCurrency(code, environment) {
|
|
353
|
+
this.supportedCurrencies[environment].add(code);
|
|
354
|
+
}
|
|
355
|
+
/**
|
|
356
|
+
* Get supported currencies for environment
|
|
357
|
+
*/
|
|
358
|
+
getSupportedCurrencies(environment) {
|
|
359
|
+
return Array.from(this.supportedCurrencies[environment]);
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* Check if currency is supported in environment
|
|
363
|
+
*/
|
|
364
|
+
isCurrencySupported(code, environment) {
|
|
365
|
+
return this.supportedCurrencies[environment].has(code);
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* Clear all currencies (useful for testing)
|
|
369
|
+
*/
|
|
370
|
+
clear() {
|
|
371
|
+
this.currencies.clear();
|
|
372
|
+
this.supportedCurrencies.sandbox.clear();
|
|
373
|
+
this.supportedCurrencies.production.clear();
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
const currencyService = CurrencyService.getInstance();
|
|
377
|
+
class NetworkService {
|
|
378
|
+
static instance;
|
|
379
|
+
networks = /* @__PURE__ */ new Map();
|
|
380
|
+
constructor() {
|
|
381
|
+
}
|
|
382
|
+
static getInstance() {
|
|
383
|
+
if (!NetworkService.instance) {
|
|
384
|
+
NetworkService.instance = new NetworkService();
|
|
385
|
+
}
|
|
386
|
+
return NetworkService.instance;
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* Register a new network
|
|
390
|
+
*/
|
|
391
|
+
register(network) {
|
|
392
|
+
this.networks.set(network.id, network);
|
|
393
|
+
}
|
|
394
|
+
/**
|
|
395
|
+
* Register multiple networks
|
|
396
|
+
*/
|
|
397
|
+
registerMany(networks) {
|
|
398
|
+
networks.forEach((network) => this.register(network));
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* Get network by ID
|
|
402
|
+
*/
|
|
403
|
+
getNetwork(id) {
|
|
404
|
+
return this.networks.get(id);
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* Get all registered networks
|
|
408
|
+
*/
|
|
409
|
+
getAllNetworks() {
|
|
410
|
+
return Array.from(this.networks.values());
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
413
|
+
* Check if network exists
|
|
414
|
+
*/
|
|
415
|
+
hasNetwork(id) {
|
|
416
|
+
return this.networks.has(id);
|
|
417
|
+
}
|
|
418
|
+
/**
|
|
419
|
+
* Get mainnet networks only
|
|
420
|
+
*/
|
|
421
|
+
getMainnetNetworks() {
|
|
422
|
+
return this.getAllNetworks().filter((network) => !network.isTestnet);
|
|
423
|
+
}
|
|
424
|
+
/**
|
|
425
|
+
* Get testnet networks only
|
|
426
|
+
*/
|
|
427
|
+
getTestnetNetworks() {
|
|
428
|
+
return this.getAllNetworks().filter((network) => network.isTestnet);
|
|
429
|
+
}
|
|
430
|
+
/**
|
|
431
|
+
* Clear all networks (useful for testing)
|
|
432
|
+
*/
|
|
433
|
+
clear() {
|
|
434
|
+
this.networks.clear();
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
const networkService = NetworkService.getInstance();
|
|
438
|
+
function camelToKebab(str) {
|
|
439
|
+
return str.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);
|
|
440
|
+
}
|
|
441
|
+
function getDefaultVariables() {
|
|
442
|
+
return {
|
|
443
|
+
colorPrimary: "#6366f1",
|
|
444
|
+
colorPrimaryHover: "#4f46e5",
|
|
445
|
+
colorPrimaryLight: "#e0e7ff",
|
|
446
|
+
colorBackground: "#ffffff",
|
|
447
|
+
colorText: "#1f2937",
|
|
448
|
+
colorTextMuted: "#6b7280",
|
|
449
|
+
colorBorder: "#e5e7eb",
|
|
450
|
+
colorBorderLight: "#f3f4f6",
|
|
451
|
+
colorDanger: "#ef4444",
|
|
452
|
+
colorSuccess: "#10b981",
|
|
453
|
+
fontFamily: "system-ui, -apple-system, sans-serif",
|
|
454
|
+
fontSize: "1rem",
|
|
455
|
+
borderRadius: "0.5rem",
|
|
456
|
+
spacing: "1rem"
|
|
457
|
+
};
|
|
458
|
+
}
|
|
459
|
+
function getThemePreset(themeName) {
|
|
460
|
+
const defaults = getDefaultVariables();
|
|
461
|
+
switch (themeName) {
|
|
462
|
+
case "dark":
|
|
463
|
+
return {
|
|
464
|
+
...defaults,
|
|
465
|
+
colorPrimary: "#6366f1",
|
|
466
|
+
colorPrimaryHover: "#7c3aed",
|
|
467
|
+
colorPrimaryLight: "#1e1b4b",
|
|
468
|
+
colorBackground: "#111827",
|
|
469
|
+
colorText: "#f9fafb",
|
|
470
|
+
colorTextMuted: "#9ca3af",
|
|
471
|
+
colorBorder: "#374151",
|
|
472
|
+
colorBorderLight: "#4b5563"
|
|
473
|
+
};
|
|
474
|
+
case "light":
|
|
475
|
+
default:
|
|
476
|
+
return defaults;
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
function applyTheme(themeInput, container) {
|
|
480
|
+
const theme = typeof themeInput === "string" ? { theme: themeInput } : themeInput;
|
|
481
|
+
const baseVariables = getThemePreset(theme.theme ?? "light");
|
|
482
|
+
const finalVariables = { ...baseVariables, ...theme.variables };
|
|
483
|
+
Object.entries(finalVariables).forEach(([key, value]) => {
|
|
484
|
+
if (value !== void 0) {
|
|
485
|
+
const cssVar = `--${camelToKebab(key)}`;
|
|
486
|
+
container.style.setProperty(cssVar, value);
|
|
487
|
+
}
|
|
488
|
+
});
|
|
489
|
+
if (theme.theme) {
|
|
490
|
+
container.setAttribute("data-theme", theme.theme);
|
|
491
|
+
}
|
|
492
|
+
if (theme.rules) {
|
|
493
|
+
applyComponentRules(theme.rules);
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
function applyComponentRules(rules) {
|
|
497
|
+
const styleId = "w3-theme-rules";
|
|
498
|
+
let styleElement = document.getElementById(styleId);
|
|
499
|
+
if (!styleElement) {
|
|
500
|
+
styleElement = document.createElement("style");
|
|
501
|
+
styleElement.id = styleId;
|
|
502
|
+
document.head.appendChild(styleElement);
|
|
503
|
+
}
|
|
504
|
+
const css = Object.entries(rules).map(([selector, styles]) => {
|
|
505
|
+
const cssProperties = Object.entries(styles).map(([prop, value]) => `${camelToKebab(prop)}: ${value};`).join(" ");
|
|
506
|
+
return `.w3-widget ${selector} { ${cssProperties} }`;
|
|
507
|
+
}).join("\n");
|
|
508
|
+
styleElement.textContent = css;
|
|
509
|
+
}
|
|
510
|
+
const CURRENCIES = {
|
|
511
|
+
USD: {
|
|
512
|
+
code: "USD",
|
|
513
|
+
name: "US Dollar",
|
|
514
|
+
symbol: "$",
|
|
515
|
+
decimals: 2,
|
|
516
|
+
type: "fiat",
|
|
517
|
+
countryCode: "US",
|
|
518
|
+
iconUrl: "https://cdn.jsdelivr.net/gh/atomiclabs/cryptocurrency-icons@1a63530be6e374711a8554f31b17e4cb92c25fa5/svg/icon/usd.svg"
|
|
519
|
+
},
|
|
520
|
+
BTC: {
|
|
521
|
+
code: "BTC",
|
|
522
|
+
name: "Bitcoin",
|
|
523
|
+
symbol: "₿",
|
|
524
|
+
decimals: 8,
|
|
525
|
+
type: "crypto",
|
|
526
|
+
network: "bitcoin",
|
|
527
|
+
isStablecoin: false,
|
|
528
|
+
iconUrl: "https://cdn.jsdelivr.net/gh/atomiclabs/cryptocurrency-icons@1a63530be6e374711a8554f31b17e4cb92c25fa5/svg/icon/btc.svg"
|
|
529
|
+
},
|
|
530
|
+
ETH: {
|
|
531
|
+
code: "ETH",
|
|
532
|
+
name: "Ethereum",
|
|
533
|
+
symbol: "Ξ",
|
|
534
|
+
decimals: 18,
|
|
535
|
+
type: "crypto",
|
|
536
|
+
network: "ethereum",
|
|
537
|
+
isStablecoin: false,
|
|
538
|
+
iconUrl: "https://cdn.jsdelivr.net/gh/atomiclabs/cryptocurrency-icons@1a63530be6e374711a8554f31b17e4cb92c25fa5/svg/icon/eth.svg"
|
|
539
|
+
}
|
|
540
|
+
};
|
|
541
|
+
const NETWORKS = {
|
|
542
|
+
bitcoin: {
|
|
543
|
+
id: "bitcoin",
|
|
544
|
+
name: "Bitcoin",
|
|
545
|
+
symbol: "BTC"
|
|
546
|
+
},
|
|
547
|
+
ethereum: {
|
|
548
|
+
id: "ethereum",
|
|
549
|
+
name: "Ethereum",
|
|
550
|
+
symbol: "ETH",
|
|
551
|
+
chainId: 1
|
|
552
|
+
}
|
|
553
|
+
};
|
|
554
|
+
const currencyIcons = {
|
|
555
|
+
// Major Cryptocurrencies
|
|
556
|
+
BTC: "https://cryptologos.cc/logos/bitcoin-btc-logo.svg",
|
|
557
|
+
ETH: "https://cryptologos.cc/logos/ethereum-eth-logo.svg",
|
|
558
|
+
USDC: "https://cryptologos.cc/logos/usd-coin-usdc-logo.svg",
|
|
559
|
+
USDT: "https://cryptologos.cc/logos/tether-usdt-logo.svg",
|
|
560
|
+
DAI: "https://cryptologos.cc/logos/multi-collateral-dai-dai-logo.svg",
|
|
561
|
+
// Layer 1 Networks
|
|
562
|
+
SOL: "https://cryptologos.cc/logos/solana-sol-logo.svg",
|
|
563
|
+
AVAX: "https://cryptologos.cc/logos/avalanche-avax-logo.svg",
|
|
564
|
+
MATIC: "https://cryptologos.cc/logos/polygon-matic-logo.svg",
|
|
565
|
+
BNB: "https://cryptologos.cc/logos/bnb-bnb-logo.svg",
|
|
566
|
+
// DeFi Tokens
|
|
567
|
+
UNI: "https://cryptologos.cc/logos/uniswap-uni-logo.svg",
|
|
568
|
+
LINK: "https://cryptologos.cc/logos/chainlink-link-logo.svg",
|
|
569
|
+
AAVE: "https://cryptologos.cc/logos/aave-aave-logo.svg",
|
|
570
|
+
// Layer 2
|
|
571
|
+
ARB: "https://cryptologos.cc/logos/arbitrum-arb-logo.svg",
|
|
572
|
+
OP: "https://cryptologos.cc/logos/optimism-ethereum-op-logo.svg",
|
|
573
|
+
// Other Popular
|
|
574
|
+
DOGE: "https://cryptologos.cc/logos/dogecoin-doge-logo.svg",
|
|
575
|
+
XRP: "https://cryptologos.cc/logos/xrp-xrp-logo.svg",
|
|
576
|
+
ADA: "https://cryptologos.cc/logos/cardano-ada-logo.svg",
|
|
577
|
+
DOT: "https://cryptologos.cc/logos/polkadot-new-dot-logo.svg"
|
|
578
|
+
};
|
|
579
|
+
function getCurrencyIcon(code) {
|
|
580
|
+
return currencyIcons[code.toUpperCase()];
|
|
581
|
+
}
|
|
582
|
+
const exchangeIcons = {
|
|
583
|
+
// Major Exchanges
|
|
584
|
+
coinbase: "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjQiIGhlaWdodD0iMjQiIHZpZXdCb3g9IjAgMCAyNCAyNCIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPGNpcmNsZSBjeD0iMTIiIGN5PSIxMiIgcj0iMTAiIGZpbGw9IiMwMDUyRkYiLz4KPHJlY3QgeD0iOSIgeT0iOSIgd2lkdGg9IjYiIGhlaWdodD0iNiIgcng9IjEiIGZpbGw9IndoaXRlIi8+Cjwvc3ZnPg==",
|
|
585
|
+
kraken: "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjQiIGhlaWdodD0iMjQiIHZpZXdCb3g9IjAgMCAyNCAyNCIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPGNpcmNsZSBjeD0iMTIiIGN5PSIxMiIgcj0iMTAiIGZpbGw9IiM1NzQxOUEiLz4KPHBhdGggZD0iTTggN0wxNiA5VjE3TDggMTVWN1oiIGZpbGw9IndoaXRlIi8+Cjwvc3ZnPg==",
|
|
586
|
+
binance: "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjQiIGhlaWdodD0iMjQiIHZpZXdCb3g9IjAgMCAyNCAyNCIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPGNpcmNsZSBjeD0iMTIiIGN5PSIxMiIgcj0iMTAiIGZpbGw9IiNGM0JBMkYiLz4KPHBhdGggZD0iTTEyIDZMMTUgOVYxNUwxMiAxOEw5IDE1VjlMMTIgNloiIGZpbGw9IndoaXRlIi8+Cjwvc3ZnPg==",
|
|
587
|
+
// Other Exchanges
|
|
588
|
+
gemini: "https://assets.coincap.io/assets/icons/256/gemini.png",
|
|
589
|
+
kucoin: "https://assets.coincap.io/assets/icons/256/kucoin.png",
|
|
590
|
+
huobi: "https://assets.coincap.io/assets/icons/256/huobi.png",
|
|
591
|
+
okx: "https://assets.coincap.io/assets/icons/256/okx.png",
|
|
592
|
+
gate: "https://assets.coincap.io/assets/icons/256/gate.png",
|
|
593
|
+
bitfinex: "https://assets.coincap.io/assets/icons/256/bitfinex.png",
|
|
594
|
+
// Alternative sources if needed
|
|
595
|
+
"coinbase-pro": "https://assets.coincap.io/assets/icons/256/coinbase.png",
|
|
596
|
+
"binance-us": "https://assets.coincap.io/assets/icons/256/binance.png"
|
|
597
|
+
};
|
|
598
|
+
function getExchangeIcon(exchange) {
|
|
599
|
+
return exchangeIcons[exchange.toLowerCase()];
|
|
600
|
+
}
|
|
601
|
+
const fiatIcons = {
|
|
602
|
+
// Bank Transfer Methods
|
|
603
|
+
ach: "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjQiIGhlaWdodD0iMjQiIHZpZXdCb3g9IjAgMCAyNCAyNCIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHBhdGggZD0iTTMgN1YxN0gyMVY3SDNaTTQgOEgyMFYxNkg0VjhaTTYgMTBWMTRIOVYxMEg2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S4xMSAyMiAxOFY2QzIyIDQuODkgMjEuMTEgNCAyMCA0Wk0yMCA2VjhINFY2SDIwWk0yMCAxOEg0VjEwSDIwVjE4WiIgZmlsbD0iY3VycmVudENvbG9yIi8+Cjwvc3ZnPg==",
|
|
608
|
+
debit: "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjQiIGhlaWdodD0iMjQiIHZpZXdCb3g9IjAgMCAyNCAyNCIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHBhdGggZD0iTTIwIDRINEMyLjg5IDQgMiA0Ljg5IDIgNlYxOEMyIDE5LjExIDIuODkgMjAgNCAyMEgyMEMyMS4xMSAyMCAyMiAxOS4xMSAyMiAxOFY2QzIyIDQuODkgMjEuMTEgNCAyMCA0Wk0yMCA2VjhINFY2SDIwWk0yMCAxOEg0VjEwSDIwVjE4WiIgZmlsbD0iY3VycmVudENvbG9yIi8+Cjwvc3ZnPg==",
|
|
609
|
+
// Digital Wallets
|
|
610
|
+
paypal: "https://cdn.jsdelivr.net/gh/devicons/devicon/icons/paypal/paypal-original.svg",
|
|
611
|
+
applepay: "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjQiIGhlaWdodD0iMjQiIHZpZXdCb3g9IjAgMCAyNCAyNCIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHBhdGggZD0iTTE4Ljc0IDguNDNDMTguNzQgMTEuNTQgMTUuNzQgMTMgMTIuNzQgMTNIMTBWMjBINlYzSDEyLjc0QzE1Ljc0IDMgMTguNzQgNC40NiAxOC43NCA4LjQzWk0xNC41IDguNDNDMTQuNSA2LjY3IDEzLjU5IDUuNzUgMTEuOTggNS43NUgxMFYxMS4yNUgxMS45OEMxMy41OSAxMS4yNSAxNC41IDEwLjMzIDE0LjUgOC40M1oiIGZpbGw9ImN1cnJlbnRDb2xvciIvPgo8L3N2Zz4K",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MTAgMTIgMTBaTTEyIDE2QzEwLjkgMTYgMTAgMTYuOSAxMCAxOFMxMC45IDIwIDEyIDIwUzE0IDE5LjEgMTQgMThTMTMuMSAxNiAxMiAxNloiIGZpbGw9ImN1cnJlbnRDb2xvciIvPgo8L3N2Zz4K"
|
|
616
|
+
};
|
|
617
|
+
function getFiatIcon(method) {
|
|
618
|
+
return fiatIcons[method.toLowerCase()];
|
|
619
|
+
}
|
|
620
|
+
exports.CURRENCIES = CURRENCIES;
|
|
621
|
+
exports.NETWORKS = NETWORKS;
|
|
622
|
+
exports.PaymentMethodService = PaymentMethodService;
|
|
623
|
+
exports.applyTheme = applyTheme;
|
|
624
|
+
exports.currencyService = currencyService;
|
|
625
|
+
exports.getCurrencyIcon = getCurrencyIcon;
|
|
626
|
+
exports.getExchangeIcon = getExchangeIcon;
|
|
627
|
+
exports.getFiatIcon = getFiatIcon;
|
|
628
|
+
exports.networkService = networkService;
|
|
629
|
+
exports.paymentMethodService = paymentMethodService;
|
|
630
|
+
//# sourceMappingURL=index.js.map
|