@ultrade/react-sdk 1.0.0 → 1.0.2
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 +78 -81
- package/dist/index.d.ts +2 -2
- package/package.json +7 -6
package/README.md
CHANGED
|
@@ -4,10 +4,11 @@ Redux Toolkit Query adaptor for @ultrade/ultrade-js-sdk. Provides RTK Query endp
|
|
|
4
4
|
|
|
5
5
|
**Repository:** [https://github.com/ultrade-org/ultrade-react-sdk](https://github.com/ultrade-org/ultrade-react-sdk)
|
|
6
6
|
|
|
7
|
+
**SDK Repository:** [https://github.com/ultrade-org/ultrade-js-sdk](https://github.com/ultrade-org/ultrade-js-sdk)
|
|
8
|
+
|
|
7
9
|
## Package Info
|
|
8
10
|
|
|
9
11
|
- **Name:** `@ultrade/react-sdk`
|
|
10
|
-
- **Purpose:** Bridge between Redux Toolkit Query and Ultrade SDK
|
|
11
12
|
- **Main Entry:** `./dist/index.js`
|
|
12
13
|
- **Types:** `./dist/index.d.ts`
|
|
13
14
|
|
|
@@ -27,37 +28,6 @@ yarn add @ultrade/react-sdk
|
|
|
27
28
|
pnpm add @ultrade/react-sdk
|
|
28
29
|
```
|
|
29
30
|
|
|
30
|
-
## TypeScript Configuration
|
|
31
|
-
|
|
32
|
-
For proper type resolution and convenient development, you need to configure your `tsconfig.json` correctly.
|
|
33
|
-
|
|
34
|
-
### Recommended Configuration
|
|
35
|
-
|
|
36
|
-
The configuration should be able to resolve types that account for the `exports` field in `package.json`:
|
|
37
|
-
|
|
38
|
-
```json
|
|
39
|
-
{
|
|
40
|
-
"compilerOptions": {
|
|
41
|
-
"moduleResolution": "nodenext"
|
|
42
|
-
// Alternative options: "node16" or "bundler"
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
### Alternative: Manual Path Configuration
|
|
48
|
-
|
|
49
|
-
If you cannot change your TypeScript settings, you can explicitly specify paths:
|
|
50
|
-
|
|
51
|
-
```json
|
|
52
|
-
{
|
|
53
|
-
"compilerOptions": {
|
|
54
|
-
"paths": {
|
|
55
|
-
"@ultrade/shared/browser/*": ["../shared/dist/browser/*"]
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
```
|
|
60
|
-
|
|
61
31
|
## Structure
|
|
62
32
|
|
|
63
33
|
```
|
|
@@ -120,65 +90,92 @@ Defined in `tsconfig.alias.json`:
|
|
|
120
90
|
| `@interfaces` | `./src/interfaces/index.ts` | TypeScript interfaces |
|
|
121
91
|
| `@utils` | `./src/utils/index.ts` | Utility functions |
|
|
122
92
|
|
|
123
|
-
|
|
93
|
+
### Creating RTK SDK Client
|
|
124
94
|
|
|
125
95
|
```typescript
|
|
126
|
-
import
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
}
|
|
96
|
+
import RTKSDKAdaptor from '@ultrade/react-sdk';
|
|
97
|
+
import algosdk from 'algosdk';
|
|
98
|
+
|
|
99
|
+
// Create Algorand SDK client
|
|
100
|
+
const rtkAlgodClient = new algosdk.Algodv2(
|
|
101
|
+
'', // token
|
|
102
|
+
'https://testnet-api.algonode.cloud', // server
|
|
103
|
+
'' // port
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
// Initialize RTK SDK client (extends Client from @ultrade/ultrade-js-sdk)
|
|
107
|
+
const rtkSdkClient = new RTKSDKAdaptor({
|
|
108
|
+
network: 'testnet', // or 'mainnet'
|
|
109
|
+
apiUrl: 'https://api.testnet.ultrade.org',
|
|
110
|
+
algoSdkClient: rtkAlgodClient,
|
|
111
|
+
websocketUrl: 'wss://ws.testnet.ultrade.org',
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
// Set signer (same as base SDK)
|
|
115
|
+
rtkSdkClient.setSigner({
|
|
116
|
+
signMessage,
|
|
117
|
+
signMessageByToken
|
|
118
|
+
});
|
|
143
119
|
```
|
|
144
120
|
|
|
145
|
-
|
|
121
|
+
### Redux Store Setup
|
|
146
122
|
|
|
147
|
-
|
|
123
|
+
```typescript
|
|
124
|
+
import { SDKReducers, SDKMiddlewares } from '@ultrade/react-sdk';
|
|
148
125
|
|
|
149
|
-
|
|
150
|
-
|
|
126
|
+
export const store = configureStore({
|
|
127
|
+
reducer: {
|
|
128
|
+
// ... your other reducers
|
|
129
|
+
...SDKReducers
|
|
130
|
+
},
|
|
131
|
+
middleware: (getDefaultMiddleware) =>
|
|
132
|
+
getDefaultMiddleware().concat(SDKMiddlewares)
|
|
133
|
+
});
|
|
151
134
|
|
|
152
|
-
|
|
135
|
+
```
|
|
153
136
|
|
|
154
|
-
|
|
155
|
-
2. **Cache Management** - Automatic cache invalidation with tags
|
|
156
|
-
3. **WebSocket Integration** - Real-time updates through WebSocket handlers
|
|
157
|
-
4. **Error Handling** - Centralized error handling with `withErrorHandling`
|
|
158
|
-
5. **SDK Client Singleton** - Single SDK client instance via `getSdkClient()`
|
|
137
|
+
### Using RTK Query Hooks
|
|
159
138
|
|
|
160
|
-
|
|
139
|
+
```typescript
|
|
140
|
+
import { useAppSelector } from './hooks';
|
|
141
|
+
import { useEffect } from 'react';
|
|
142
|
+
|
|
143
|
+
function Component() {
|
|
144
|
+
//...
|
|
145
|
+
|
|
146
|
+
const { useLazyGetSettingsQuery, useLazyGetPairListQuery } = rtkSdkClient.markets();
|
|
147
|
+
const { useGetTradingKeysQuery, useAddTradingKeyMutation } = rtkSdkClient.walletApi();
|
|
148
|
+
|
|
149
|
+
// Lazy query for settings
|
|
150
|
+
const [getSettings, { data: settings, isLoading: isLoadingSettings }] = useLazyGetSettingsQuery();
|
|
151
|
+
|
|
152
|
+
// Query for trading pairs
|
|
153
|
+
const [getPairList, { data: pairs, isLoading: isLoadingPairs }] = useLazyGetPairListQuery();
|
|
154
|
+
|
|
155
|
+
// Query for trading keys
|
|
156
|
+
const { data: tradingKeys, isLoading: isLoadingKeys } = useGetTradingKeysQuery();
|
|
157
|
+
|
|
158
|
+
// Mutation for creating trading key
|
|
159
|
+
const [addTradingKey, { isLoading: isCreatingKey }] = useAddTradingKeyMutation();
|
|
160
|
+
|
|
161
|
+
return <></>
|
|
162
|
+
}
|
|
163
|
+
```
|
|
161
164
|
|
|
162
|
-
|
|
165
|
+
## Redux integration
|
|
163
166
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
- `markets_history` - Historical candles
|
|
168
|
-
- `markets_orders` - User orders
|
|
169
|
-
- `markets_pair_list` - Trading pairs
|
|
170
|
-
- `markets_last_trades` - Recent trades
|
|
171
|
-
- `wallet_transactions` - Wallet transactions
|
|
172
|
-
- `wallet_transfers` - Transfer history
|
|
173
|
-
- `wallet_whitelist` - Withdrawal whitelist
|
|
174
|
-
- `wallet_trading_keys` - Trading keys
|
|
175
|
-
- `wallet_pending_transactions` - Pending transactions
|
|
176
|
-
- `withdrawal_wallets` - Withdrawal wallets
|
|
167
|
+
```typescript
|
|
168
|
+
import { Provider } from 'react-redux';
|
|
169
|
+
import { store } from './store';
|
|
177
170
|
|
|
178
|
-
|
|
171
|
+
function App() {
|
|
172
|
+
|
|
173
|
+
//component logic
|
|
179
174
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
175
|
+
return (
|
|
176
|
+
<Provider store={store}>
|
|
177
|
+
<YourApp />
|
|
178
|
+
</Provider>
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
```
|
package/dist/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ultrade/react-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -12,11 +12,15 @@
|
|
|
12
12
|
},
|
|
13
13
|
"author": "",
|
|
14
14
|
"files": [
|
|
15
|
-
"dist"
|
|
16
|
-
"README.md"
|
|
15
|
+
"dist"
|
|
17
16
|
],
|
|
17
|
+
"publishConfig": {
|
|
18
|
+
"registry": "https://registry.npmjs.org/",
|
|
19
|
+
"access": "public"
|
|
20
|
+
},
|
|
18
21
|
"peerDependencies": {
|
|
19
22
|
"@reduxjs/toolkit": "^1.9.7",
|
|
23
|
+
"@ultrade/ultrade-js-sdk": "^2.0.2",
|
|
20
24
|
"bignumber.js": "^9.1.2",
|
|
21
25
|
"react": "^18.0.0",
|
|
22
26
|
"react-redux": "^8.0.0"
|
|
@@ -31,8 +35,5 @@
|
|
|
31
35
|
"esbuild-plugin-d.ts": "^1.3.1",
|
|
32
36
|
"ts-node": "^10.9.2",
|
|
33
37
|
"typescript": "^5.6.3"
|
|
34
|
-
},
|
|
35
|
-
"dependencies": {
|
|
36
|
-
"@ultrade/ultrade-js-sdk": "^2.0.2"
|
|
37
38
|
}
|
|
38
39
|
}
|