one-ewallet-otc-ui 0.0.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 ADDED
@@ -0,0 +1,253 @@
1
+ # One E-Wallet OTC UI Component Library
2
+
3
+ A React + TypeScript + Vite component library for OTC (Over-The-Counter) trading, providing OTC trading and withdrawal functionality components.
4
+
5
+ ## 📦 Installation
6
+
7
+ ```bash
8
+ npm install one-ewallet-otc-ui
9
+ # or
10
+ yarn add one-ewallet-otc-ui
11
+ # or
12
+ pnpm add one-ewallet-otc-ui
13
+ ```
14
+
15
+ ## 🔧 Dependencies
16
+
17
+ This component library requires the following peer dependencies. Please ensure they are installed in your project:
18
+
19
+ - `react` >= 18.2.0
20
+ - `react-dom` >= 18.2.0
21
+
22
+ Additionally, the component library uses the following dependencies internally. If your project also uses these libraries, it's recommended to use the same versions to avoid conflicts:
23
+
24
+ - `@onelabs/dapp-kit` ^0.15.5
25
+ - `@tanstack/react-query` ^5.83.0
26
+ - `antd` ^5.12.5
27
+ - `axios` ^1.13.2
28
+
29
+ ## 🚀 Quick Start
30
+
31
+ ### 1. Setup SuiClientProvider (Required)
32
+
33
+ Since the components use `@onelabs/dapp-kit`, you need to set up `SuiClientProvider` and `QueryClientProvider` at the top level of your application:
34
+
35
+ ```tsx
36
+ import { SuiClientProvider, createNetworkConfig } from '@onelabs/dapp-kit'
37
+ import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
38
+ import { OtcModal, Withdraw } from 'one-ewallet-otc-ui'
39
+
40
+ // Create Sui network configuration
41
+ const { networkConfig } = createNetworkConfig({
42
+ mainnet: { url: 'https://fullnode.mainnet.sui.io:443' },
43
+ testnet: { url: 'https://fullnode.testnet.sui.io:443' },
44
+ devnet: { url: 'https://fullnode.devnet.sui.io:443' },
45
+ })
46
+
47
+ // Create React Query client
48
+ const queryClient = new QueryClient()
49
+
50
+ function App() {
51
+ return (
52
+ <QueryClientProvider client={queryClient}>
53
+ <SuiClientProvider networks={networkConfig} defaultNetwork="mainnet">
54
+ {/* Your app content */}
55
+ </SuiClientProvider>
56
+ </QueryClientProvider>
57
+ )
58
+ }
59
+ ```
60
+
61
+ ### 2. Using OtcModal Component
62
+
63
+ `OtcModal` is an OTC trading modal component:
64
+
65
+ ```tsx
66
+ import { OtcModal } from 'one-ewallet-otc-ui'
67
+
68
+ function MyComponent() {
69
+ return (
70
+ <OtcModal
71
+ baseUrl="/api" // API base URL
72
+ authToken="your-auth-token" // User authentication token
73
+ userAddress="user-sui-address" // User Sui address
74
+ lang="EN" // Language: 'ZH' | 'EN', default is 'EN'
75
+ >
76
+ <button>Open OTC Trading</button>
77
+ </OtcModal>
78
+ )
79
+ }
80
+ ```
81
+
82
+ #### OtcModal Props
83
+
84
+ | Property | Type | Required | Default | Description |
85
+ |----------|------|----------|----------|-------------|
86
+ | `children` | `React.ReactNode` | ✅ | - | Element that triggers the modal to open |
87
+ | `baseUrl` | `string` | ✅ | - | API base URL |
88
+ | `authToken` | `string` | ✅ | - | User authentication token |
89
+ | `userAddress` | `string` | ✅ | - | User Sui wallet address |
90
+ | `lang` | `'ZH' \| 'EN'` | ❌ | `'EN'` | Interface language |
91
+
92
+ ### 3. Using Withdraw Component
93
+
94
+ `Withdraw` is a withdrawal component that requires SuiClient support:
95
+
96
+ ```tsx
97
+ import { Withdraw } from 'one-ewallet-otc-ui'
98
+ import { useSuiClient } from '@onelabs/dapp-kit'
99
+
100
+ function MyComponent() {
101
+ const suiClient = useSuiClient()
102
+
103
+ const handleWithdraw = (withdrawData: any, callback: () => void) => {
104
+ // Handle withdrawal logic
105
+ console.log('Withdrawal data:', withdrawData)
106
+ // Execute withdrawal operation...
107
+ // Call callback when done
108
+ callback()
109
+ }
110
+
111
+ return (
112
+ <Withdraw
113
+ baseUrl="/api"
114
+ authToken="your-auth-token"
115
+ userAddress="user-sui-address"
116
+ suiClient={suiClient}
117
+ USDH_COIN_TYPE="0x72eba41c73c4c2ce2bcfc6ec1dc0896ba1b5c17bfe7ae7c6c779943f84912b41::usdh::USDH"
118
+ USDH_DECIMALS={9}
119
+ onSubmit={handleWithdraw}
120
+ lang="EN"
121
+ >
122
+ <button>Open Withdrawal</button>
123
+ </Withdraw>
124
+ )
125
+ }
126
+ ```
127
+
128
+ #### Withdraw Props
129
+
130
+ | Property | Type | Required | Default | Description |
131
+ |----------|------|----------|----------|-------------|
132
+ | `children` | `React.ReactNode` | ✅ | - | Element that triggers the withdrawal modal to open |
133
+ | `baseUrl` | `string` | ✅ | - | API base URL |
134
+ | `authToken` | `string` | ✅ | - | User authentication token |
135
+ | `userAddress` | `string` | ✅ | - | User Sui wallet address |
136
+ | `suiClient` | `ReturnType<typeof useSuiClient>` | ✅ | - | SuiClient instance (obtained via `useSuiClient()` hook) |
137
+ | `USDH_COIN_TYPE` | `string` | ✅ | - | USDH token Coin Type |
138
+ | `USDH_DECIMALS` | `number` | ✅ | - | USDH token decimal places |
139
+ | `onSubmit` | `(withdrawData: any, callback: () => void) => void` | ✅ | - | Withdrawal submit callback function |
140
+ | `lang` | `'ZH' \| 'EN'` | ❌ | `'EN'` | Interface language |
141
+
142
+ ## 📝 Complete Example
143
+
144
+ ```tsx
145
+ import React from 'react'
146
+ import { createRoot } from 'react-dom/client'
147
+ import { SuiClientProvider, createNetworkConfig, useSuiClient } from '@onelabs/dapp-kit'
148
+ import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
149
+ import { OtcModal, Withdraw } from 'one-ewallet-otc-ui'
150
+
151
+ // Create Sui network configuration
152
+ const { networkConfig } = createNetworkConfig({
153
+ mainnet: { url: 'https://fullnode.mainnet.sui.io:443' },
154
+ testnet: { url: 'https://fullnode.testnet.sui.io:443' },
155
+ devnet: { url: 'https://fullnode.devnet.sui.io:443' },
156
+ })
157
+
158
+ const queryClient = new QueryClient()
159
+
160
+ // Inner component: use hook inside Provider
161
+ const AppContent = () => {
162
+ const suiClient = useSuiClient()
163
+
164
+ const handleWithdraw = (withdrawData: any, callback: () => void) => {
165
+ console.log('Withdrawal data:', withdrawData)
166
+ // Execute withdrawal logic...
167
+ callback()
168
+ }
169
+
170
+ return (
171
+ <div>
172
+ <h1>My Application</h1>
173
+
174
+ <OtcModal
175
+ baseUrl="/api"
176
+ authToken="your-auth-token"
177
+ userAddress="0x..."
178
+ lang="EN"
179
+ >
180
+ <button>OTC Trading</button>
181
+ </OtcModal>
182
+
183
+ <Withdraw
184
+ baseUrl="/api"
185
+ authToken="your-auth-token"
186
+ userAddress="0x..."
187
+ suiClient={suiClient}
188
+ USDH_COIN_TYPE="0x72eba41c73c4c2ce2bcfc6ec1dc0896ba1b5c17bfe7ae7c6c779943f84912b41::usdh::USDH"
189
+ USDH_DECIMALS={9}
190
+ onSubmit={handleWithdraw}
191
+ lang="EN"
192
+ >
193
+ <button>Withdraw</button>
194
+ </Withdraw>
195
+ </div>
196
+ )
197
+ }
198
+
199
+ // Root component
200
+ const App = () => {
201
+ return (
202
+ <QueryClientProvider client={queryClient}>
203
+ <SuiClientProvider networks={networkConfig} defaultNetwork="mainnet">
204
+ <AppContent />
205
+ </SuiClientProvider>
206
+ </QueryClientProvider>
207
+ )
208
+ }
209
+
210
+ createRoot(document.getElementById('root')!).render(<App />)
211
+ ```
212
+
213
+ ## 🎨 Styling
214
+
215
+ The component library includes built-in styles, so no additional CSS imports are needed. Styles are written in SCSS and are automatically bundled.
216
+
217
+ ## 🔌 API Endpoints
218
+
219
+ The components require the following API endpoints:
220
+
221
+ ### OtcModal Required Endpoints
222
+
223
+ - `POST {baseUrl}/ext/ewallet/getOtcAddress` - Get OTC address
224
+ - Other OTC related endpoints...
225
+
226
+ ### Withdraw Required Endpoints
227
+
228
+ - `POST {baseUrl}/ext/ewallet/getWithdrawAddress` - Get withdrawal address
229
+ - Other withdrawal related endpoints...
230
+
231
+ ## 🛠️ Development
232
+
233
+ ```bash
234
+ # Install dependencies
235
+ npm install
236
+
237
+ # Start development server
238
+ npm run dev
239
+
240
+ # Build
241
+ npm run build
242
+
243
+ # Preview build
244
+ npm run preview
245
+ ```
246
+
247
+ ## 📄 License
248
+
249
+ MIT
250
+
251
+ ## 🤝 Contributing
252
+
253
+ Issues and Pull Requests are welcome!