@ton-pay/ui-react 0.1.2 → 0.2.0-beta.1
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 +126 -98
- package/dist/index.css +594 -0
- package/dist/index.css.map +1 -0
- package/dist/index.d.mts +257 -28
- package/dist/index.d.ts +257 -28
- package/dist/index.js +3209 -321
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +3145 -257
- package/dist/index.mjs.map +1 -1
- package/package.json +28 -14
package/README.md
CHANGED
|
@@ -1,145 +1,173 @@
|
|
|
1
1
|
# @ton-pay/ui-react
|
|
2
2
|
|
|
3
|
-
React components and hooks for TON
|
|
4
|
-
|
|
5
|
-
## Documentation
|
|
6
|
-
|
|
7
|
-
Full documentation: https://docs.tonpay.tech
|
|
3
|
+
Professional React components and hooks for integrating TON blockchain payments into your application.
|
|
8
4
|
|
|
9
5
|
## Installation
|
|
10
6
|
|
|
11
7
|
```bash
|
|
12
|
-
npm install @ton-pay/ui-react @tonconnect/ui-react
|
|
8
|
+
npm install @ton-pay/ui-react @ton-pay/api @tonconnect/ui-react
|
|
13
9
|
```
|
|
14
10
|
|
|
15
11
|
## Quick Start
|
|
16
12
|
|
|
17
|
-
### Basic Usage
|
|
18
|
-
|
|
19
13
|
```tsx
|
|
20
|
-
import {
|
|
14
|
+
import { TonConnectUIProvider } from "@tonconnect/ui-react";
|
|
15
|
+
import { TonPayButton, useTonPay } from "@ton-pay/ui-react";
|
|
21
16
|
import { createTonPayTransfer, TON } from "@ton-pay/api";
|
|
22
|
-
|
|
17
|
+
|
|
18
|
+
function App() {
|
|
19
|
+
return (
|
|
20
|
+
<TonConnectUIProvider manifestUrl="https://your-app.com/tonconnect-manifest.json">
|
|
21
|
+
<PaymentForm />
|
|
22
|
+
</TonConnectUIProvider>
|
|
23
|
+
);
|
|
24
|
+
}
|
|
23
25
|
|
|
24
26
|
function PaymentForm() {
|
|
25
|
-
const
|
|
27
|
+
const { pay } = useTonPay();
|
|
26
28
|
|
|
27
29
|
const handlePay = async () => {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
30
|
+
await pay(async (senderAddr) => {
|
|
31
|
+
return createTonPayTransfer(
|
|
32
|
+
{
|
|
33
|
+
amount: 10.5,
|
|
34
|
+
asset: TON,
|
|
35
|
+
recipientAddr: "EQC...",
|
|
36
|
+
senderAddr,
|
|
37
|
+
commentToSender: "Payment for order #123",
|
|
38
|
+
},
|
|
39
|
+
{ chain: "mainnet", apiKey: "your-api-key" }
|
|
40
|
+
);
|
|
41
|
+
});
|
|
40
42
|
};
|
|
41
43
|
|
|
42
44
|
return <TonPayButton handlePay={handlePay} />;
|
|
43
45
|
}
|
|
44
46
|
```
|
|
45
47
|
|
|
46
|
-
|
|
48
|
+
## Components
|
|
47
49
|
|
|
48
|
-
|
|
49
|
-
<TonPayButton preset="gradient" variant="long" handlePay={handlePay} />
|
|
50
|
-
```
|
|
50
|
+
### TonPayButton
|
|
51
51
|
|
|
52
|
-
|
|
52
|
+
Complete payment button with wallet connection, loading states, and error handling.
|
|
53
53
|
|
|
54
54
|
```tsx
|
|
55
55
|
<TonPayButton
|
|
56
|
-
bgColor="#000000"
|
|
57
|
-
textColor="#FFFFFF"
|
|
58
|
-
borderRadius={99}
|
|
59
|
-
variant="short"
|
|
60
56
|
handlePay={handlePay}
|
|
57
|
+
variant="long"
|
|
58
|
+
preset="gradient"
|
|
59
|
+
amount={10.5}
|
|
60
|
+
currency="TON"
|
|
61
61
|
/>
|
|
62
62
|
```
|
|
63
63
|
|
|
64
|
-
|
|
64
|
+
#### Props
|
|
65
|
+
|
|
66
|
+
| Prop | Type | Default | Description |
|
|
67
|
+
|------|------|---------|-------------|
|
|
68
|
+
| `handlePay` | `() => Promise<void>` | **required** | Payment handler |
|
|
69
|
+
| `isLoading` | `boolean` | `false` | Loading state |
|
|
70
|
+
| `variant` | `"long" \| "short"` | `"long"` | Button text variant |
|
|
71
|
+
| `preset` | `"default" \| "gradient"` | - | Theme preset |
|
|
72
|
+
| `bgColor` | `string` | `"#0098EA"` | Background color |
|
|
73
|
+
| `textColor` | `string` | `"#FFFFFF"` | Text color |
|
|
74
|
+
| `borderRadius` | `number \| string` | `8` | Border radius |
|
|
75
|
+
| `width` | `number \| string` | `300` | Button width |
|
|
76
|
+
| `height` | `number \| string` | `44` | Button height |
|
|
77
|
+
| `disabled` | `boolean` | `false` | Disabled state |
|
|
78
|
+
| `amount` | `number \| string` | - | Payment amount |
|
|
79
|
+
| `currency` | `string` | `"TON"` | Currency code |
|
|
80
|
+
| `apiKey` | `string` | - | API key for on-ramp |
|
|
81
|
+
| `onError` | `(error: unknown) => void` | - | Error callback |
|
|
82
|
+
| `showErrorNotification` | `boolean` | `true` | Show error toast |
|
|
83
|
+
|
|
84
|
+
## Hooks
|
|
85
|
+
|
|
86
|
+
### useTonPay
|
|
87
|
+
|
|
88
|
+
Core hook for TON wallet integration and payments.
|
|
65
89
|
|
|
66
90
|
```tsx
|
|
67
|
-
|
|
68
|
-
|
|
91
|
+
const { pay, address } = useTonPay();
|
|
92
|
+
|
|
93
|
+
const handlePayment = async () => {
|
|
94
|
+
const result = await pay(async (senderAddr) => {
|
|
95
|
+
return createTonPayTransfer({
|
|
96
|
+
amount: 10.5,
|
|
97
|
+
asset: TON,
|
|
98
|
+
recipientAddr: "EQC...",
|
|
99
|
+
senderAddr,
|
|
100
|
+
}, { chain: "mainnet", apiKey: "your-api-key" });
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
console.log("Transaction:", result.txResult);
|
|
104
|
+
};
|
|
105
|
+
```
|
|
69
106
|
|
|
70
|
-
|
|
71
|
-
const { pay, address } = useTonPay();
|
|
107
|
+
### useMoonPayIframe
|
|
72
108
|
|
|
73
|
-
|
|
74
|
-
const result = await pay(async (senderAddr) => {
|
|
75
|
-
const transfer = await createTonPayTransfer(
|
|
76
|
-
{
|
|
77
|
-
amount: 10.5,
|
|
78
|
-
asset: TON,
|
|
79
|
-
recipientAddr: "EQC...", // Optional if API key is provided
|
|
80
|
-
senderAddr,
|
|
81
|
-
commentToSender: "Payment for order #123",
|
|
82
|
-
},
|
|
83
|
-
{ chain: "mainnet", apiKey: "your-api-key" }
|
|
84
|
-
);
|
|
109
|
+
Hook for MoonPay on-ramp integration.
|
|
85
110
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
111
|
+
```tsx
|
|
112
|
+
const {
|
|
113
|
+
checkAvailability,
|
|
114
|
+
fetchOnRampLink,
|
|
115
|
+
loading
|
|
116
|
+
} = useMoonPayIframe({
|
|
117
|
+
apiKey: "your-api-key",
|
|
118
|
+
chain: "mainnet",
|
|
119
|
+
});
|
|
120
|
+
```
|
|
89
121
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
122
|
+
## Styling
|
|
123
|
+
|
|
124
|
+
### Presets
|
|
125
|
+
|
|
126
|
+
Built-in theme presets:
|
|
127
|
+
|
|
128
|
+
```tsx
|
|
129
|
+
<TonPayButton preset="default" /> // Blue solid
|
|
130
|
+
<TonPayButton preset="gradient" /> // Blue gradient
|
|
97
131
|
```
|
|
98
132
|
|
|
99
|
-
|
|
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:
|
|
133
|
+
### Custom Styling
|
|
132
134
|
|
|
133
|
-
```
|
|
134
|
-
|
|
135
|
+
```tsx
|
|
136
|
+
<TonPayButton
|
|
137
|
+
bgColor="#000000"
|
|
138
|
+
textColor="#FFFFFF"
|
|
139
|
+
borderRadius={99}
|
|
140
|
+
fontFamily="'SF Pro Display', sans-serif"
|
|
141
|
+
width={280}
|
|
142
|
+
height={48}
|
|
143
|
+
/>
|
|
135
144
|
```
|
|
136
145
|
|
|
137
|
-
|
|
146
|
+
### CSS Variables
|
|
138
147
|
|
|
139
|
-
|
|
148
|
+
The button uses CSS variables for theming:
|
|
149
|
+
|
|
150
|
+
```css
|
|
151
|
+
--tp-bg: #0098EA;
|
|
152
|
+
--tp-text: #FFFFFF;
|
|
153
|
+
--tp-radius: 8px;
|
|
154
|
+
--tp-font: inherit;
|
|
155
|
+
--tp-width: 300px;
|
|
156
|
+
--tp-height: 44px;
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
## TypeScript
|
|
140
160
|
|
|
141
|
-
|
|
142
|
-
|
|
161
|
+
Full TypeScript support with exported types:
|
|
162
|
+
|
|
163
|
+
```tsx
|
|
164
|
+
import type {
|
|
165
|
+
TonPayButtonProps,
|
|
166
|
+
PayInfo,
|
|
167
|
+
GetMessageFn,
|
|
168
|
+
TonPayMessage,
|
|
169
|
+
} from "@ton-pay/ui-react";
|
|
170
|
+
```
|
|
143
171
|
|
|
144
172
|
## License
|
|
145
173
|
|