@ton-pay/ui-react 0.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/README.md ADDED
@@ -0,0 +1,146 @@
1
+ # @ton-pay/ui-react
2
+
3
+ React components and hooks for TonPay SDK.
4
+
5
+ ## Documentation
6
+
7
+ Full documentation: https://docs.tonpay.tech
8
+
9
+ ## Installation
10
+
11
+ ```bash
12
+ npm install @ton-pay/ui @tonconnect/ui-react
13
+ ```
14
+
15
+ ## Quick Start
16
+
17
+ ### Basic Usage
18
+
19
+ ```tsx
20
+ import { TonPayButton } from "@ton-pay/ui-react";
21
+ import { createTonPayTransfer, TON } from "@ton-pay/api";
22
+ import { useTonAddress } from "@tonconnect/ui-react";
23
+
24
+ function PaymentForm() {
25
+ const senderAddr = useTonAddress();
26
+
27
+ const handlePay = async () => {
28
+ const transfer = await createTonPayTransfer(
29
+ {
30
+ amount: 10.5,
31
+ asset: TON,
32
+ recipientAddr: "EQC...",
33
+ senderAddr,
34
+ commentToSender: "Payment for order #123",
35
+ },
36
+ { chain: "mainnet", apiKey: "your-api-key" }
37
+ );
38
+
39
+ return transfer;
40
+ };
41
+
42
+ return <TonPayButton handlePay={handlePay} />;
43
+ }
44
+ ```
45
+
46
+ ### With Presets
47
+
48
+ ```tsx
49
+ <TonPayButton preset="gradient" variant="long" handlePay={handlePay} />
50
+ ```
51
+
52
+ ### Custom Styling
53
+
54
+ ```tsx
55
+ <TonPayButton
56
+ bgColor="#000000"
57
+ textColor="#FFFFFF"
58
+ borderRadius={99}
59
+ variant="short"
60
+ handlePay={handlePay}
61
+ />
62
+ ```
63
+
64
+ ### useTonPay Hook
65
+
66
+ ```tsx
67
+ import { useTonPay } from "@ton-pay/ui-react";
68
+ import { createTonPayTransfer, TON } from "@ton-pay/api";
69
+
70
+ function PaymentComponent() {
71
+ const { pay, address } = useTonPay();
72
+
73
+ const handlePayment = async () => {
74
+ const result = await pay(async (senderAddr) => {
75
+ const transfer = await createTonPayTransfer(
76
+ {
77
+ amount: 10.5,
78
+ asset: TON,
79
+ recipientAddr: "EQC...",
80
+ senderAddr,
81
+ commentToSender: "Payment for order #123",
82
+ },
83
+ { chain: "mainnet", apiKey: "your-api-key" }
84
+ );
85
+
86
+ return transfer;
87
+ });
88
+ };
89
+
90
+ return (
91
+ <div>
92
+ {address ? `Connected: ${address}` : "Not connected"}
93
+ <button onClick={handlePayment}>Pay</button>
94
+ </div>
95
+ );
96
+ }
97
+ ```
98
+
99
+ ## Features
100
+
101
+ - **Highly Customizable** - Background color, text color, border radius, font family
102
+ - **Presets** - Built-in themes (default, gradient) matching Figma designs
103
+ - **Variants** - Long ("Pay with TON Pay") and Short ("TON Pay") text options
104
+ - **Loading States** - Built-in spinner and loading text
105
+ - **Wallet Integration** - Connect, disconnect, copy address via dropdown menu
106
+ - **Responsive** - Flexible width and height
107
+ - **Zero Config** - Works out of the box with sensible defaults
108
+
109
+ ## Props
110
+
111
+ | Prop | Type | Default | Description |
112
+ | -------------- | ------------------------- | ----------------- | ---------------------------- |
113
+ | `handlePay` | `() => Promise<void>` | **required** | Payment handler function |
114
+ | `isLoading` | `boolean` | `false` | Loading state |
115
+ | `variant` | `"long" \| "short"` | `"long"` | Button text variant |
116
+ | `preset` | `"default" \| "gradient"` | - | Predefined theme preset |
117
+ | `bgColor` | `string` | `"#0098EA"` | Background (hex or gradient) |
118
+ | `textColor` | `string` | `"#FFFFFF"` | Text color |
119
+ | `borderRadius` | `number \| string` | `8` | Border radius |
120
+ | `fontFamily` | `string` | `"inherit"` | Font family |
121
+ | `width` | `number \| string` | `300` | Button width |
122
+ | `height` | `number \| string` | `44` | Button height |
123
+ | `loadingText` | `string` | `"Processing..."` | Loading state text |
124
+ | `showMenu` | `boolean` | `false` | Show dropdown menu |
125
+ | `disabled` | `boolean` | `false` | Disabled state |
126
+ | `style` | `Record<string, any>` | - | Additional styles |
127
+ | `className` | `string` | - | Additional CSS class |
128
+
129
+ ## Visual Showcase
130
+
131
+ Run the interactive button showcase to see all variants and styling options:
132
+
133
+ ```bash
134
+ bun test:button-react
135
+ ```
136
+
137
+ This will start a local dev server with a visual gallery of all button configurations.
138
+
139
+ ## Components
140
+
141
+ - **TonPayButton**: Complete payment button with wallet connection and customizable styling
142
+ - **useTonPay**: Hook for TON wallet integration
143
+
144
+ ## License
145
+
146
+ Apache License 2.0
@@ -0,0 +1,60 @@
1
+ import { SendTransactionRequest, SendTransactionResponse } from '@tonconnect/sdk';
2
+
3
+ type TonPayPreset = "default" | "gradient";
4
+ type TonPayButtonProps = {
5
+ handlePay: () => Promise<void>;
6
+ isLoading?: boolean;
7
+ variant?: "long" | "short";
8
+ preset?: TonPayPreset;
9
+ bgColor?: string;
10
+ textColor?: string;
11
+ borderRadius?: number | string;
12
+ fontFamily?: string;
13
+ width?: number | string;
14
+ height?: number | string;
15
+ text?: string;
16
+ loadingText?: string;
17
+ style?: Record<string, any>;
18
+ className?: string;
19
+ showMenu?: boolean;
20
+ disabled?: boolean;
21
+ };
22
+ declare const TonPayButton: ({ handlePay, isLoading, variant, preset, bgColor, textColor, borderRadius, fontFamily, width, height, text, loadingText, style, className, showMenu, disabled, }: TonPayButtonProps) => JSX.Element;
23
+
24
+ type NotificationProps = {
25
+ title: string;
26
+ text?: string;
27
+ icon?: React.ReactNode;
28
+ className?: string;
29
+ style?: React.CSSProperties;
30
+ };
31
+ declare const NotificationCard: React.FC<NotificationProps>;
32
+ declare const NotificationRoot: React.FC<{
33
+ children?: React.ReactNode;
34
+ }>;
35
+ declare const ErrorDotIcon: React.FC<{
36
+ color?: string;
37
+ }>;
38
+
39
+ declare const ErrorTransactionNotification: React.FC<{
40
+ text?: string;
41
+ className?: string;
42
+ style?: React.CSSProperties;
43
+ }>;
44
+
45
+ type TonPayMessage = SendTransactionRequest["messages"][number] & {
46
+ payload: string;
47
+ };
48
+ type GetMessageFn<T extends object = object> = (senderAddr: string) => Promise<{
49
+ message: TonPayMessage;
50
+ } & T>;
51
+ type PayInfo<T extends object = object> = {
52
+ message: TonPayMessage;
53
+ txResult: SendTransactionResponse;
54
+ } & T;
55
+ declare const useTonPay: () => {
56
+ pay: any;
57
+ address: string | null;
58
+ };
59
+
60
+ export { ErrorDotIcon, ErrorTransactionNotification, type GetMessageFn, NotificationCard, type NotificationProps, NotificationRoot, type PayInfo, TonPayButton, type TonPayMessage, useTonPay };
@@ -0,0 +1,60 @@
1
+ import { SendTransactionRequest, SendTransactionResponse } from '@tonconnect/sdk';
2
+
3
+ type TonPayPreset = "default" | "gradient";
4
+ type TonPayButtonProps = {
5
+ handlePay: () => Promise<void>;
6
+ isLoading?: boolean;
7
+ variant?: "long" | "short";
8
+ preset?: TonPayPreset;
9
+ bgColor?: string;
10
+ textColor?: string;
11
+ borderRadius?: number | string;
12
+ fontFamily?: string;
13
+ width?: number | string;
14
+ height?: number | string;
15
+ text?: string;
16
+ loadingText?: string;
17
+ style?: Record<string, any>;
18
+ className?: string;
19
+ showMenu?: boolean;
20
+ disabled?: boolean;
21
+ };
22
+ declare const TonPayButton: ({ handlePay, isLoading, variant, preset, bgColor, textColor, borderRadius, fontFamily, width, height, text, loadingText, style, className, showMenu, disabled, }: TonPayButtonProps) => JSX.Element;
23
+
24
+ type NotificationProps = {
25
+ title: string;
26
+ text?: string;
27
+ icon?: React.ReactNode;
28
+ className?: string;
29
+ style?: React.CSSProperties;
30
+ };
31
+ declare const NotificationCard: React.FC<NotificationProps>;
32
+ declare const NotificationRoot: React.FC<{
33
+ children?: React.ReactNode;
34
+ }>;
35
+ declare const ErrorDotIcon: React.FC<{
36
+ color?: string;
37
+ }>;
38
+
39
+ declare const ErrorTransactionNotification: React.FC<{
40
+ text?: string;
41
+ className?: string;
42
+ style?: React.CSSProperties;
43
+ }>;
44
+
45
+ type TonPayMessage = SendTransactionRequest["messages"][number] & {
46
+ payload: string;
47
+ };
48
+ type GetMessageFn<T extends object = object> = (senderAddr: string) => Promise<{
49
+ message: TonPayMessage;
50
+ } & T>;
51
+ type PayInfo<T extends object = object> = {
52
+ message: TonPayMessage;
53
+ txResult: SendTransactionResponse;
54
+ } & T;
55
+ declare const useTonPay: () => {
56
+ pay: any;
57
+ address: string | null;
58
+ };
59
+
60
+ export { ErrorDotIcon, ErrorTransactionNotification, type GetMessageFn, NotificationCard, type NotificationProps, NotificationRoot, type PayInfo, TonPayButton, type TonPayMessage, useTonPay };