@ic-pay/icpay-widget 0.1.76

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/README.md ADDED
@@ -0,0 +1,31 @@
1
+ ## ICPay Widget (Web Components)
2
+
3
+ Embeddable, framework-agnostic payment widgets powered by `@ic-pay/icpay-sdk`.
4
+
5
+ ### Installation
6
+
7
+ Using pnpm:
8
+ ```bash
9
+ pnpm add @ic-pay/icpay-widget @ic-pay/icpay-sdk
10
+ ```
11
+
12
+ Using yarn:
13
+ ```bash
14
+ yarn add @ic-pay/icpay-widget @ic-pay/icpay-sdk
15
+ ```
16
+
17
+ Using npm:
18
+ ```bash
19
+ npm install @ic-pay/icpay-widget @ic-pay/icpay-sdk
20
+ ```
21
+
22
+ ### Documentation
23
+
24
+ For full usage, component list, configuration, theming, and examples, see the ICPay documentation: [ICPay Docs](https://docs.icpay.org).
25
+
26
+ ### Basic Info
27
+
28
+ - Framework-agnostic Web Components (works with vanilla JS, React, Next.js, etc.)
29
+ - Requires and integrates with `@ic-pay/icpay-sdk`
30
+ - TypeScript types included
31
+ - Theming via CSS variables
@@ -0,0 +1,510 @@
1
+ import * as lit from 'lit';
2
+ import { LitElement } from 'lit';
3
+ import { Icpay, PriceCalculationResult } from '@ic-pay/icpay-sdk';
4
+
5
+ type ThemeConfig = {
6
+ primaryColor?: string;
7
+ secondaryColor?: string;
8
+ accentColor?: string;
9
+ textColor?: string;
10
+ mutedTextColor?: string;
11
+ surfaceColor?: string;
12
+ surfaceAltColor?: string;
13
+ borderColor?: string;
14
+ fontFamily?: string;
15
+ };
16
+ type PlugNPlayConfig = {
17
+ enabled?: boolean;
18
+ providers?: {
19
+ internetIdentity?: boolean;
20
+ oisy?: boolean;
21
+ plug?: boolean;
22
+ };
23
+ theme?: {
24
+ modalBackground?: string;
25
+ modalBorderRadius?: string;
26
+ buttonBackground?: string;
27
+ buttonHoverBackground?: string;
28
+ textColor?: string;
29
+ primaryColor?: string;
30
+ };
31
+ };
32
+ type ProgressBarConfig = {
33
+ enabled?: boolean;
34
+ mode?: 'modal' | 'horizontal' | 'vertical' | 'inline';
35
+ };
36
+ type CommonConfig = {
37
+ publishableKey: string;
38
+ apiUrl?: string;
39
+ icHost?: string;
40
+ actorProvider?: (canisterId: string, idl: any) => any;
41
+ connectedWallet?: any;
42
+ useOwnWallet?: boolean;
43
+ plugNPlay?: PlugNPlayConfig;
44
+ theme?: ThemeConfig;
45
+ debug?: boolean;
46
+ progressBar?: ProgressBarConfig;
47
+ disablePaymentButton?: boolean;
48
+ disableAfterSuccess?: boolean;
49
+ showLedgerDropdown?: 'buttons' | 'dropdown' | 'none';
50
+ };
51
+ type CryptoOption = {
52
+ symbol: string;
53
+ label: string;
54
+ canisterId?: string;
55
+ };
56
+ type PremiumContentConfig = CommonConfig & {
57
+ priceUsd: number;
58
+ cryptoOptions?: CryptoOption[];
59
+ imageUrl?: string;
60
+ buttonLabel?: string;
61
+ defaultSymbol?: string;
62
+ onSuccess?: (tx: {
63
+ id: number;
64
+ status: string;
65
+ }) => void;
66
+ };
67
+ type TipJarConfig = CommonConfig & {
68
+ amountsUsd?: number[];
69
+ defaultAmountUsd?: number;
70
+ cryptoOptions?: CryptoOption[];
71
+ defaultSymbol?: string;
72
+ showLedgerDropdown?: boolean;
73
+ buttonLabel?: string;
74
+ onSuccess?: (tx: {
75
+ id: number;
76
+ status: string;
77
+ total?: number;
78
+ }) => void;
79
+ };
80
+ type ArticlePaywallConfig = CommonConfig & {
81
+ priceUsd: number;
82
+ cryptoOptions?: CryptoOption[];
83
+ title?: string;
84
+ preview?: string;
85
+ lockedContent?: string;
86
+ buttonLabel?: string;
87
+ defaultSymbol?: string;
88
+ onSuccess?: (tx: {
89
+ id: number;
90
+ status: string;
91
+ }) => void;
92
+ };
93
+ type CoffeeShopConfig = CommonConfig & {
94
+ items: Array<{
95
+ name: string;
96
+ priceUsd: number;
97
+ }>;
98
+ defaultItemIndex?: number;
99
+ cryptoOptions?: CryptoOption[];
100
+ buttonLabel?: string;
101
+ defaultSymbol?: string;
102
+ onSuccess?: (tx: {
103
+ id: number;
104
+ status: string;
105
+ item: string;
106
+ }) => void;
107
+ };
108
+ type DonationThermometerConfig = CommonConfig & {
109
+ goalUsd: number;
110
+ defaultAmountUsd?: number;
111
+ amountsUsd?: number[];
112
+ cryptoOptions?: CryptoOption[];
113
+ buttonLabel?: string;
114
+ defaultSymbol?: string;
115
+ onSuccess?: (tx: {
116
+ id: number;
117
+ status: string;
118
+ raised: number;
119
+ }) => void;
120
+ };
121
+ type PayButtonConfig = CommonConfig & {
122
+ amountUsd?: number;
123
+ cryptoOptions?: CryptoOption[];
124
+ showLedgerDropdown?: boolean;
125
+ defaultSymbol?: string;
126
+ buttonLabel?: string;
127
+ onSuccess?: (tx: {
128
+ id: number;
129
+ status: string;
130
+ }) => void;
131
+ };
132
+ type AmountInputConfig = CommonConfig & {
133
+ placeholder?: string;
134
+ defaultAmountUsd?: number;
135
+ cryptoOptions?: CryptoOption[];
136
+ showLedgerDropdown?: boolean;
137
+ defaultSymbol?: string;
138
+ minUsd?: number;
139
+ maxUsd?: number;
140
+ stepUsd?: number;
141
+ buttonLabel?: string;
142
+ onSuccess?: (tx: {
143
+ id: number;
144
+ status: string;
145
+ amountUsd: number;
146
+ }) => void;
147
+ };
148
+
149
+ declare const baseStyles: lit.CSSResult;
150
+ declare function applyThemeVars(host: HTMLElement, theme?: ThemeConfig | null): void;
151
+
152
+ type WidgetSdk = {
153
+ client: InstanceType<typeof Icpay>;
154
+ quoteUsd(usdAmount: number, ledgerCanisterId: string): Promise<PriceCalculationResult>;
155
+ sendUsd(usdAmount: number, ledgerCanisterId: string, metadata?: Record<string, any>): Promise<any>;
156
+ };
157
+ declare function createSdk(config: CommonConfig): WidgetSdk;
158
+
159
+ type StepStatus = 'pending' | 'loading' | 'completed' | 'error';
160
+ type Step = {
161
+ key: string;
162
+ label: string;
163
+ tooltip: string;
164
+ status: StepStatus;
165
+ timestamp?: string;
166
+ errorMessage?: string;
167
+ };
168
+ declare class ICPayProgressBar extends LitElement {
169
+ static styles: lit.CSSResult;
170
+ open: boolean;
171
+ steps: Step[];
172
+ amount: number;
173
+ currency: string;
174
+ ledgerSymbol: string;
175
+ private activeIndex;
176
+ private completed;
177
+ private failed;
178
+ private errorMessage;
179
+ private showSuccess;
180
+ private showConfetti;
181
+ private currentSteps;
182
+ private currentAmount;
183
+ private currentCurrency;
184
+ private currentLedgerSymbol;
185
+ private progressionTimer;
186
+ theme?: {
187
+ primaryColor?: string;
188
+ secondaryColor?: string;
189
+ };
190
+ connectedCallback(): void;
191
+ disconnectedCallback(): void;
192
+ protected updated(changed: Map<string, unknown>): void;
193
+ private attachSDKEventListeners;
194
+ private detachSDKEventListeners;
195
+ private onMethodStart;
196
+ private startAutomaticProgression;
197
+ private stopAutomaticProgression;
198
+ private onMethodSuccess;
199
+ private onTransactionCreated;
200
+ private onTransactionUpdated;
201
+ private onTransactionCompleted;
202
+ private onTransactionFailed;
203
+ private onMethodError;
204
+ private onSDKError;
205
+ private onWalletConnected;
206
+ private onWalletDisconnected;
207
+ private onBalanceCheck;
208
+ private onLedgerVerified;
209
+ private onWidgetPayment;
210
+ private onWidgetError;
211
+ private onWidgetUnlock;
212
+ private onWidgetTip;
213
+ private onWidgetDonation;
214
+ private onWidgetCoffee;
215
+ private updateStepStatus;
216
+ private getCurrentTime;
217
+ private progressPercent;
218
+ private verticalPercent;
219
+ private getStepIcon;
220
+ private transformErrorMessage;
221
+ private renderConfetti;
222
+ private renderSuccessState;
223
+ private renderErrorState;
224
+ private renderProgressContent;
225
+ private retryTransaction;
226
+ private closeProgress;
227
+ private renderStep;
228
+ render(): lit.TemplateResult<1>;
229
+ }
230
+ declare global {
231
+ interface HTMLElementTagNameMap {
232
+ 'icpay-progress-bar': ICPayProgressBar;
233
+ }
234
+ }
235
+
236
+ declare class ICPayTokenSelector extends LitElement {
237
+ static styles: lit.CSSResult;
238
+ options: CryptoOption[];
239
+ value: string | null;
240
+ defaultSymbol: string;
241
+ mode: 'buttons' | 'dropdown' | 'none';
242
+ theme?: {
243
+ primaryColor?: string;
244
+ secondaryColor?: string;
245
+ };
246
+ connectedCallback(): void;
247
+ updated(changed: Map<string, unknown>): void;
248
+ private get effectiveSymbol();
249
+ private onSelect;
250
+ render(): lit.TemplateResult<1>;
251
+ }
252
+ declare global {
253
+ interface HTMLElementTagNameMap {
254
+ 'icpay-token-selector': ICPayTokenSelector;
255
+ }
256
+ }
257
+
258
+ declare class ICPayPremiumContent extends LitElement {
259
+ static styles: lit.CSSResult[];
260
+ config: PremiumContentConfig;
261
+ private selectedSymbol;
262
+ private unlocked;
263
+ private succeeded;
264
+ private processing;
265
+ private availableLedgers;
266
+ private errorMessage;
267
+ private errorSeverity;
268
+ private errorAction;
269
+ private walletConnected;
270
+ private pendingAction;
271
+ private showWalletModal;
272
+ private pnp;
273
+ private tryAutoConnectPNP;
274
+ private get cryptoOptions();
275
+ connectedCallback(): void;
276
+ protected updated(changed: Map<string, unknown>): void;
277
+ private loadVerifiedLedgers;
278
+ private onPay;
279
+ private select;
280
+ private getWalletId;
281
+ private getWalletLabel;
282
+ private getWalletIcon;
283
+ private connectWithWallet;
284
+ render(): lit.TemplateResult<1>;
285
+ }
286
+ declare global {
287
+ interface HTMLElementTagNameMap {
288
+ 'icpay-premium-content': ICPayPremiumContent;
289
+ }
290
+ }
291
+
292
+ declare class ICPayTipJar extends LitElement {
293
+ static styles: lit.CSSResult[];
294
+ config: TipJarConfig;
295
+ private selectedAmount;
296
+ private selectedSymbol;
297
+ private total;
298
+ private processing;
299
+ private succeeded;
300
+ private availableLedgers;
301
+ private errorMessage;
302
+ private errorSeverity;
303
+ private errorAction;
304
+ private walletConnected;
305
+ private pendingAction;
306
+ private showWalletModal;
307
+ private pnp;
308
+ private tryAutoConnectPNP;
309
+ private get amounts();
310
+ private get cryptoOptions();
311
+ connectedCallback(): void;
312
+ protected updated(changed: Map<string, unknown>): void;
313
+ private loadVerifiedLedgers;
314
+ private selectAmount;
315
+ private selectSymbol;
316
+ private get fillPercentage();
317
+ private tip;
318
+ private getWalletId;
319
+ private getWalletLabel;
320
+ private getWalletIcon;
321
+ private connectWithWallet;
322
+ render(): lit.TemplateResult<1>;
323
+ }
324
+ declare global {
325
+ interface HTMLElementTagNameMap {
326
+ 'icpay-tip-jar': ICPayTipJar;
327
+ }
328
+ }
329
+
330
+ declare class ICPayArticlePaywall extends LitElement {
331
+ static styles: lit.CSSResult[];
332
+ config: ArticlePaywallConfig;
333
+ title: string;
334
+ preview: string;
335
+ lockedContent: string;
336
+ private selectedSymbol;
337
+ private unlocked;
338
+ private succeeded;
339
+ private processing;
340
+ private availableLedgers;
341
+ private errorMessage;
342
+ private errorSeverity;
343
+ private errorAction;
344
+ private walletConnected;
345
+ private pendingAction;
346
+ private showWalletModal;
347
+ private pnp;
348
+ private tryAutoConnectPNP;
349
+ private get cryptoOptions();
350
+ connectedCallback(): void;
351
+ protected updated(changed: Map<string, unknown>): void;
352
+ private loadVerifiedLedgers;
353
+ private selectSymbol;
354
+ private unlock;
355
+ private getWalletId;
356
+ private getWalletLabel;
357
+ private getWalletIcon;
358
+ private connectWithWallet;
359
+ render(): lit.TemplateResult<1>;
360
+ }
361
+ declare global {
362
+ interface HTMLElementTagNameMap {
363
+ 'icpay-article-paywall': ICPayArticlePaywall;
364
+ }
365
+ }
366
+
367
+ declare class ICPayCoffeeShop extends LitElement {
368
+ static styles: lit.CSSResult[];
369
+ config: CoffeeShopConfig;
370
+ private selectedIndex;
371
+ private selectedSymbol;
372
+ private processing;
373
+ private availableLedgers;
374
+ private errorMessage;
375
+ private errorSeverity;
376
+ private errorAction;
377
+ private walletConnected;
378
+ private pendingAction;
379
+ private showWalletModal;
380
+ private pnp;
381
+ private get cryptoOptions();
382
+ connectedCallback(): void;
383
+ protected updated(changed: Map<string, unknown>): void;
384
+ private loadVerifiedLedgers;
385
+ private selectItem;
386
+ private selectSymbol;
387
+ private get selectedItem();
388
+ private order;
389
+ private getWalletId;
390
+ private getWalletLabel;
391
+ private getWalletIcon;
392
+ private connectWithWallet;
393
+ render(): lit.TemplateResult<1>;
394
+ }
395
+ declare global {
396
+ interface HTMLElementTagNameMap {
397
+ 'icpay-coffee-shop': ICPayCoffeeShop;
398
+ }
399
+ }
400
+
401
+ declare class ICPayDonationThermometer extends LitElement {
402
+ static styles: lit.CSSResult[];
403
+ config: DonationThermometerConfig;
404
+ private selectedAmount;
405
+ private selectedSymbol;
406
+ private raised;
407
+ private processing;
408
+ private succeeded;
409
+ private availableLedgers;
410
+ private errorMessage;
411
+ private errorSeverity;
412
+ private errorAction;
413
+ private walletConnected;
414
+ private pendingAction;
415
+ private showWalletModal;
416
+ private pnp;
417
+ private tryAutoConnectPNP;
418
+ private get amounts();
419
+ private get cryptoOptions();
420
+ connectedCallback(): void;
421
+ protected updated(changed: Map<string, unknown>): void;
422
+ private loadVerifiedLedgers;
423
+ private selectAmount;
424
+ private selectSymbol;
425
+ private get fillPercentage();
426
+ private donate;
427
+ private getWalletId;
428
+ private getWalletLabel;
429
+ private getWalletIcon;
430
+ private connectWithWallet;
431
+ render(): lit.TemplateResult<1>;
432
+ }
433
+ declare global {
434
+ interface HTMLElementTagNameMap {
435
+ 'icpay-donation-thermometer': ICPayDonationThermometer;
436
+ }
437
+ }
438
+
439
+ declare class ICPayPayButton extends LitElement {
440
+ static styles: lit.CSSResult[];
441
+ config: PayButtonConfig;
442
+ private selectedSymbol;
443
+ private processing;
444
+ private succeeded;
445
+ private availableLedgers;
446
+ private errorMessage;
447
+ private errorSeverity;
448
+ private errorAction;
449
+ private walletConnected;
450
+ private pendingAction;
451
+ private showWalletModal;
452
+ private pnp;
453
+ private get cryptoOptions();
454
+ connectedCallback(): void;
455
+ protected updated(changed: Map<string, unknown>): void;
456
+ private loadVerifiedLedgers;
457
+ private selectSymbol;
458
+ private ensureWallet;
459
+ private getWalletId;
460
+ private getWalletLabel;
461
+ private getWalletIcon;
462
+ private connectWithWallet;
463
+ private renderWalletModal;
464
+ private pay;
465
+ render(): lit.TemplateResult<1>;
466
+ }
467
+ declare global {
468
+ interface HTMLElementTagNameMap {
469
+ 'icpay-pay-button': ICPayPayButton;
470
+ }
471
+ }
472
+
473
+ declare class ICPayAmountInput extends LitElement {
474
+ static styles: lit.CSSResult[];
475
+ config: AmountInputConfig;
476
+ private amountUsd;
477
+ private hasUserAmount;
478
+ private selectedSymbol;
479
+ private processing;
480
+ private succeeded;
481
+ private availableLedgers;
482
+ private errorMessage;
483
+ private errorSeverity;
484
+ private errorAction;
485
+ private walletConnected;
486
+ private pendingAction;
487
+ private showWalletModal;
488
+ private pnp;
489
+ private get cryptoOptions();
490
+ connectedCallback(): void;
491
+ protected updated(changed: Map<string, unknown>): void;
492
+ private loadVerifiedLedgers;
493
+ private onInputChange;
494
+ private selectSymbol;
495
+ private isValidAmount;
496
+ private ensureWallet;
497
+ private getWalletId;
498
+ private getWalletLabel;
499
+ private getWalletIcon;
500
+ private connectWithWallet;
501
+ private pay;
502
+ render(): lit.TemplateResult<1>;
503
+ }
504
+ declare global {
505
+ interface HTMLElementTagNameMap {
506
+ 'icpay-amount-input': ICPayAmountInput;
507
+ }
508
+ }
509
+
510
+ export { type AmountInputConfig, type ArticlePaywallConfig, type CoffeeShopConfig, type CommonConfig, type CryptoOption, type DonationThermometerConfig, ICPayAmountInput, ICPayArticlePaywall, ICPayCoffeeShop, ICPayDonationThermometer, ICPayPayButton, ICPayPremiumContent, ICPayTipJar, type PayButtonConfig, type PlugNPlayConfig, type PremiumContentConfig, type ProgressBarConfig, type ThemeConfig, type TipJarConfig, type WidgetSdk, applyThemeVars, baseStyles, createSdk };