@zerohash-sdk/fund-react 1.2.0 → 1.3.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 +45 -36
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
# @zerohash-sdk/
|
|
1
|
+
# @zerohash-sdk/fund-react
|
|
2
2
|
|
|
3
|
-
A React SDK that enables frontend React applications to seamlessly integrate with the Connect
|
|
3
|
+
A React SDK that enables frontend React applications to seamlessly integrate with the Connect Fund product.
|
|
4
4
|
|
|
5
|
-
Connect
|
|
5
|
+
Connect Fund provides a secure, customizable flow for funding accounts via crypto deposits directly within your application.
|
|
6
6
|
|
|
7
7
|
## Requirements
|
|
8
8
|
|
|
@@ -12,27 +12,27 @@ Connect Crypto Sell provides a secure, customizable flow for selling crypto asse
|
|
|
12
12
|
## Installation
|
|
13
13
|
|
|
14
14
|
```bash
|
|
15
|
-
npm install @zerohash-sdk/
|
|
15
|
+
npm install @zerohash-sdk/fund-react
|
|
16
16
|
```
|
|
17
17
|
|
|
18
18
|
## Getting Started
|
|
19
19
|
|
|
20
|
-
Follow these simple steps to integrate Connect
|
|
20
|
+
Follow these simple steps to integrate Connect Fund into your React application:
|
|
21
21
|
|
|
22
|
-
### 1. Import the
|
|
22
|
+
### 1. Import the Fund Component
|
|
23
23
|
|
|
24
24
|
```tsx
|
|
25
|
-
import {
|
|
25
|
+
import { Fund } from '@zerohash-sdk/fund-react';
|
|
26
26
|
```
|
|
27
27
|
|
|
28
|
-
### 2. Add the
|
|
28
|
+
### 2. Add the Fund Component to Your App
|
|
29
29
|
|
|
30
30
|
```tsx
|
|
31
31
|
function App() {
|
|
32
32
|
const jwt = 'your-jwt-token'; // Obtain this from your backend
|
|
33
33
|
|
|
34
34
|
return (
|
|
35
|
-
<
|
|
35
|
+
<Fund
|
|
36
36
|
jwt={jwt}
|
|
37
37
|
env="prod" // or "cert" for testing
|
|
38
38
|
theme="auto" // 'auto' (default), 'light', or 'dark'
|
|
@@ -43,34 +43,34 @@ function App() {
|
|
|
43
43
|
|
|
44
44
|
### 3. Configure Event Callbacks (Optional)
|
|
45
45
|
|
|
46
|
-
Listen to events from the
|
|
46
|
+
Listen to events from the Fund SDK to handle user interactions:
|
|
47
47
|
|
|
48
48
|
```tsx
|
|
49
49
|
function App() {
|
|
50
50
|
const jwt = 'your-jwt-token';
|
|
51
51
|
|
|
52
|
-
const handleCompleted = ({
|
|
53
|
-
console.log('
|
|
52
|
+
const handleCompleted = ({ assetSymbol, amount, network, depositAddress }) => {
|
|
53
|
+
console.log('Fund completed:', amount, assetSymbol, network, depositAddress);
|
|
54
54
|
};
|
|
55
55
|
|
|
56
56
|
const handleError = ({ errorCode, reason }) => {
|
|
57
|
-
console.log('
|
|
57
|
+
console.log('Fund error:', errorCode, 'Reason:', reason);
|
|
58
58
|
};
|
|
59
59
|
|
|
60
60
|
const handleClose = () => {
|
|
61
|
-
console.log('
|
|
61
|
+
console.log('Fund widget closed');
|
|
62
62
|
};
|
|
63
63
|
|
|
64
64
|
const handleEvent = ({ type, data }) => {
|
|
65
|
-
console.log('
|
|
65
|
+
console.log('Fund event:', type, 'Data:', data);
|
|
66
66
|
};
|
|
67
67
|
|
|
68
68
|
const handleLoaded = () => {
|
|
69
|
-
console.log('
|
|
69
|
+
console.log('Fund widget loaded and ready');
|
|
70
70
|
};
|
|
71
71
|
|
|
72
72
|
return (
|
|
73
|
-
<
|
|
73
|
+
<Fund
|
|
74
74
|
jwt={jwt}
|
|
75
75
|
env="prod"
|
|
76
76
|
theme="auto"
|
|
@@ -86,11 +86,11 @@ function App() {
|
|
|
86
86
|
|
|
87
87
|
## Complete Example
|
|
88
88
|
|
|
89
|
-
Here's a full example of integrating Connect
|
|
89
|
+
Here's a full example of integrating Connect Fund into your React application:
|
|
90
90
|
|
|
91
91
|
```tsx
|
|
92
92
|
import React from 'react';
|
|
93
|
-
import {
|
|
93
|
+
import { Fund } from '@zerohash-sdk/fund-react';
|
|
94
94
|
|
|
95
95
|
function App() {
|
|
96
96
|
// JWT token should be obtained from your backend
|
|
@@ -100,24 +100,25 @@ function App() {
|
|
|
100
100
|
<div className="App">
|
|
101
101
|
<h1>My Crypto App</h1>
|
|
102
102
|
|
|
103
|
-
<
|
|
103
|
+
<Fund
|
|
104
104
|
jwt={jwt}
|
|
105
105
|
env="prod" // 'prod' (default), 'cert', 'dev', or 'local'
|
|
106
106
|
theme="auto" // 'auto' (default), 'light', or 'dark'
|
|
107
|
-
onCompleted={({
|
|
108
|
-
console.log('
|
|
107
|
+
onCompleted={({ assetSymbol, amount, network, depositAddress }) => {
|
|
108
|
+
console.log('Funded:', amount, assetSymbol, 'on', network);
|
|
109
|
+
console.log('Deposit address:', depositAddress);
|
|
109
110
|
}}
|
|
110
111
|
onError={({ errorCode, reason }) => {
|
|
111
112
|
console.log('Error:', errorCode, 'Reason:', reason);
|
|
112
113
|
}}
|
|
113
114
|
onClose={() => {
|
|
114
|
-
console.log('
|
|
115
|
+
console.log('Fund widget closed');
|
|
115
116
|
}}
|
|
116
117
|
onEvent={({ type, data }) => {
|
|
117
118
|
console.log('Event type:', type, 'Event data:', data);
|
|
118
119
|
}}
|
|
119
120
|
onLoaded={() => {
|
|
120
|
-
console.log('
|
|
121
|
+
console.log('Fund widget loaded and ready');
|
|
121
122
|
}}
|
|
122
123
|
/>
|
|
123
124
|
</div>
|
|
@@ -129,18 +130,26 @@ export default App;
|
|
|
129
130
|
|
|
130
131
|
## API Reference
|
|
131
132
|
|
|
132
|
-
###
|
|
133
|
-
|
|
134
|
-
| Prop | Type
|
|
135
|
-
| ------------- |
|
|
136
|
-
| `jwt` | `string`
|
|
137
|
-
| `env` | `"prod" \| "cert" \| "dev" \| "local"`
|
|
138
|
-
| `theme` | `"auto" \| "light" \| "dark"`
|
|
139
|
-
| `
|
|
140
|
-
| `
|
|
141
|
-
| `
|
|
142
|
-
| `
|
|
143
|
-
| `
|
|
133
|
+
### Fund Component Props
|
|
134
|
+
|
|
135
|
+
| Prop | Type | Required | Default | Description |
|
|
136
|
+
| ------------- | ------------------------------------------------------------ | -------- | -------- | -------------------------------------------------- |
|
|
137
|
+
| `jwt` | `string` | Yes | - | JWT token for authentication with Connect |
|
|
138
|
+
| `env` | `"prod" \| "cert" \| "dev" \| "local"` | No | `"prod"` | Target environment |
|
|
139
|
+
| `theme` | `"auto" \| "light" \| "dark"` | No | `"auto"` | Theme mode for the interface |
|
|
140
|
+
| `isPay` | `boolean` | No | `false` | Run the SDK in Pay mode (see notes below) |
|
|
141
|
+
| `onCompleted` | `({ assetSymbol, amount, network, depositAddress }) => void` | No | - | Callback when the fund flow completes successfully |
|
|
142
|
+
| `onError` | `({ errorCode, reason }) => void` | No | - | Callback for error events |
|
|
143
|
+
| `onClose` | `() => void` | No | - | Callback when the widget is closed |
|
|
144
|
+
| `onEvent` | `({ type, data }) => void` | No | - | Callback for general events |
|
|
145
|
+
| `onLoaded` | `() => void` | No | - | Callback when the widget is loaded and ready |
|
|
146
|
+
|
|
147
|
+
### Pay mode (`isPay`)
|
|
148
|
+
|
|
149
|
+
When `isPay` is `true`, the Fund SDK runs in Pay mode:
|
|
150
|
+
|
|
151
|
+
- Uses the `pay-sdk` app id and the `app:internal:pay` scope when calling trade-api.
|
|
152
|
+
- Signs the `account_funding_pay` terms agreement.
|
|
144
153
|
|
|
145
154
|
## More Information & Support
|
|
146
155
|
|