@oobit/react-native-sdk 3.0.0 → 3.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 +19 -341
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @oobit/react-native-sdk
|
|
2
2
|
|
|
3
|
-
A React Native SDK that enables wallet apps to integrate Oobit's crypto payment services.
|
|
3
|
+
A React Native SDK that enables wallet apps to integrate Oobit's crypto-to-card payment services.
|
|
4
4
|
|
|
5
5
|
[](https://www.npmjs.com/package/@oobit/react-native-sdk)
|
|
6
6
|
[](https://github.com/oobit-tech/react-native-SDK/blob/main/LICENSE)
|
|
@@ -8,361 +8,39 @@ A React Native SDK that enables wallet apps to integrate Oobit's crypto payment
|
|
|
8
8
|
## Installation
|
|
9
9
|
|
|
10
10
|
```bash
|
|
11
|
-
npm install @oobit/react-native-sdk
|
|
12
|
-
# or
|
|
13
|
-
yarn add @oobit/react-native-sdk
|
|
14
|
-
```
|
|
15
|
-
|
|
16
|
-
### Peer Dependencies
|
|
17
|
-
|
|
18
|
-
Make sure you have these installed:
|
|
19
|
-
|
|
20
|
-
```bash
|
|
21
|
-
npm install react-native-webview expo-linking expo-clipboard expo-intent-launcher expo-local-authentication
|
|
22
|
-
# or
|
|
23
|
-
yarn add react-native-webview expo-linking expo-clipboard expo-intent-launcher expo-local-authentication
|
|
11
|
+
npm install @oobit/react-native-sdk react-native-webview
|
|
24
12
|
```
|
|
25
13
|
|
|
26
14
|
## Quick Start
|
|
27
15
|
|
|
28
|
-
```
|
|
29
|
-
import { WidgetSDK } from
|
|
30
|
-
import { View, Alert } from 'react-native';
|
|
31
|
-
|
|
32
|
-
function MyApp() {
|
|
33
|
-
return (
|
|
34
|
-
<View style={{ flex: 1 }}>
|
|
35
|
-
<WidgetSDK
|
|
36
|
-
accessToken="your-jwt-token-from-backend"
|
|
37
|
-
userWalletAddress="0x1234...abcd"
|
|
38
|
-
environment="production"
|
|
39
|
-
onReady={() => {
|
|
40
|
-
console.log('Widget loaded successfully');
|
|
41
|
-
}}
|
|
42
|
-
onError={(code, message) => {
|
|
43
|
-
Alert.alert('Error', message);
|
|
44
|
-
}}
|
|
45
|
-
onClose={() => {
|
|
46
|
-
console.log('User closed the widget');
|
|
47
|
-
}}
|
|
48
|
-
onTransactionRequested={(token, amount, address, tag) => {
|
|
49
|
-
console.log(`Send ${amount} ${token.symbol} to ${address}`);
|
|
50
|
-
}}
|
|
51
|
-
/>
|
|
52
|
-
</View>
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
## Props
|
|
58
|
-
|
|
59
|
-
### Required Props
|
|
60
|
-
|
|
61
|
-
#### `accessToken: string`
|
|
62
|
-
JWT access token from your backend for authentication.
|
|
63
|
-
|
|
64
|
-
```typescript
|
|
65
|
-
<WidgetSDK accessToken="eyJhbGciOiJIUzI1NiIs..." />
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
#### `userWalletAddress: string`
|
|
69
|
-
The user's external wallet address for crypto deposits.
|
|
70
|
-
|
|
71
|
-
```typescript
|
|
72
|
-
<WidgetSDK userWalletAddress="0x1234567890abcdef..." />
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
### Optional Props
|
|
76
|
-
|
|
77
|
-
#### `environment?: 'development' | 'production'`
|
|
78
|
-
The environment to use. Defaults to `'production'`.
|
|
79
|
-
|
|
80
|
-
```typescript
|
|
81
|
-
<WidgetSDK environment="development" />
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
#### `debug?: boolean`
|
|
85
|
-
Enable debug logging to console. Defaults to `false`.
|
|
86
|
-
|
|
87
|
-
```typescript
|
|
88
|
-
<WidgetSDK debug={true} />
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
#### `loadingIndicatorColor?: string`
|
|
92
|
-
Custom color for the loading indicator. Defaults to `'#007AFF'`.
|
|
93
|
-
|
|
94
|
-
```typescript
|
|
95
|
-
<WidgetSDK loadingIndicatorColor="#6200EE" />
|
|
96
|
-
```
|
|
97
|
-
|
|
98
|
-
### Callback Props
|
|
99
|
-
|
|
100
|
-
#### `onReady?: () => void`
|
|
101
|
-
Called when the widget has finished loading and is ready for interaction.
|
|
102
|
-
|
|
103
|
-
```typescript
|
|
104
|
-
<WidgetSDK
|
|
105
|
-
onReady={() => {
|
|
106
|
-
console.log('Widget is ready!');
|
|
107
|
-
setIsLoading(false);
|
|
108
|
-
}}
|
|
109
|
-
/>
|
|
110
|
-
```
|
|
111
|
-
|
|
112
|
-
#### `onError?: (code: SDKErrorCode | string, message: string) => void`
|
|
113
|
-
Called when an error occurs in the widget.
|
|
114
|
-
|
|
115
|
-
**Error Codes:**
|
|
116
|
-
- `TOKEN_EXPIRED` - The access token has expired
|
|
117
|
-
- `PARSE_ERROR` - Failed to parse a message from the widget
|
|
118
|
-
- `WEBVIEW_ERROR` - The WebView failed to load
|
|
119
|
-
|
|
120
|
-
```typescript
|
|
121
|
-
<WidgetSDK
|
|
122
|
-
onError={(code, message) => {
|
|
123
|
-
console.error(`Widget error [${code}]: ${message}`);
|
|
124
|
-
|
|
125
|
-
if (code === 'TOKEN_EXPIRED') {
|
|
126
|
-
// Refresh token and reload
|
|
127
|
-
refreshAuth();
|
|
128
|
-
}
|
|
129
|
-
}}
|
|
130
|
-
/>
|
|
131
|
-
```
|
|
132
|
-
|
|
133
|
-
#### `onClose?: () => void`
|
|
134
|
-
Called when the user requests to close the widget.
|
|
135
|
-
|
|
136
|
-
```typescript
|
|
137
|
-
<WidgetSDK
|
|
138
|
-
onClose={() => {
|
|
139
|
-
navigation.goBack();
|
|
140
|
-
}}
|
|
141
|
-
/>
|
|
142
|
-
```
|
|
143
|
-
|
|
144
|
-
#### `onTransactionRequested?: (token, cryptoAmount, depositAddress, depositAddressTag) => void`
|
|
145
|
-
Called when a crypto transaction is requested.
|
|
146
|
-
|
|
147
|
-
```typescript
|
|
148
|
-
<WidgetSDK
|
|
149
|
-
onTransactionRequested={(token, cryptoAmount, depositAddress, depositAddressTag) => {
|
|
150
|
-
console.log(`Send ${cryptoAmount} ${token.symbol} to ${depositAddress}`);
|
|
151
|
-
// Navigate to your send crypto screen
|
|
152
|
-
navigation.navigate('SendCrypto', {
|
|
153
|
-
token,
|
|
154
|
-
amount: cryptoAmount,
|
|
155
|
-
address: depositAddress,
|
|
156
|
-
tag: depositAddressTag,
|
|
157
|
-
});
|
|
158
|
-
}}
|
|
159
|
-
/>
|
|
160
|
-
```
|
|
161
|
-
|
|
162
|
-
#### `onLoadingChange?: (isLoading: boolean) => void`
|
|
163
|
-
Called when the loading state changes.
|
|
164
|
-
|
|
165
|
-
```typescript
|
|
166
|
-
<WidgetSDK
|
|
167
|
-
onLoadingChange={(isLoading) => {
|
|
168
|
-
setShowCustomLoader(isLoading);
|
|
169
|
-
}}
|
|
170
|
-
/>
|
|
171
|
-
```
|
|
172
|
-
|
|
173
|
-
## Ref Methods
|
|
174
|
-
|
|
175
|
-
You can control the widget programmatically using a ref:
|
|
176
|
-
|
|
177
|
-
```typescript
|
|
178
|
-
import { useRef } from 'react';
|
|
179
|
-
import { WidgetSDK, WidgetSDKRef } from '@oobit/react-native-sdk';
|
|
180
|
-
|
|
181
|
-
function MyScreen() {
|
|
182
|
-
const widgetRef = useRef<WidgetSDKRef>(null);
|
|
183
|
-
|
|
184
|
-
const handleBackPress = () => {
|
|
185
|
-
widgetRef.current?.navigateBack();
|
|
186
|
-
};
|
|
187
|
-
|
|
188
|
-
const handleRetry = () => {
|
|
189
|
-
widgetRef.current?.reload();
|
|
190
|
-
};
|
|
16
|
+
```tsx
|
|
17
|
+
import { WidgetSDK } from "@oobit/react-native-sdk";
|
|
191
18
|
|
|
19
|
+
function PaymentScreen() {
|
|
192
20
|
return (
|
|
193
21
|
<WidgetSDK
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
22
|
+
accessToken="prod_your-jwt-token"
|
|
23
|
+
userWalletAddress="0x1234..."
|
|
24
|
+
onTransactionRequested={(transaction) => {
|
|
25
|
+
// Navigate to your transaction confirmation screen
|
|
26
|
+
navigation.navigate("ConfirmTransaction", { transaction });
|
|
27
|
+
}}
|
|
28
|
+
onClose={() => navigation.goBack()}
|
|
197
29
|
/>
|
|
198
30
|
);
|
|
199
31
|
}
|
|
200
32
|
```
|
|
201
33
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
| Method | Description |
|
|
205
|
-
|--------|-------------|
|
|
206
|
-
| `navigateBack()` | Navigate back within the widget |
|
|
207
|
-
| `reload()` | Reload the widget |
|
|
208
|
-
|
|
209
|
-
## TypeScript Support
|
|
210
|
-
|
|
211
|
-
The SDK is fully typed. Import types as needed:
|
|
212
|
-
|
|
213
|
-
```typescript
|
|
214
|
-
import type {
|
|
215
|
-
WidgetSDKConfig,
|
|
216
|
-
WidgetSDKRef,
|
|
217
|
-
SDKErrorCode,
|
|
218
|
-
DepositToken,
|
|
219
|
-
} from '@oobit/react-native-sdk';
|
|
220
|
-
```
|
|
221
|
-
|
|
222
|
-
### Message Type Constants
|
|
223
|
-
|
|
224
|
-
For advanced use cases where you need to handle messages directly:
|
|
225
|
-
|
|
226
|
-
```typescript
|
|
227
|
-
import { MessageTypes } from '@oobit/react-native-sdk';
|
|
228
|
-
|
|
229
|
-
// Use constants instead of strings
|
|
230
|
-
if (message.type === MessageTypes.ERROR) {
|
|
231
|
-
// Handle error
|
|
232
|
-
}
|
|
233
|
-
```
|
|
234
|
-
|
|
235
|
-
## Native Wallet Integration
|
|
236
|
-
|
|
237
|
-
The SDK automatically handles adding cards to Apple Wallet (iOS) and Google Pay (Android).
|
|
238
|
-
|
|
239
|
-
You can also manually open the wallet from your React Native app:
|
|
240
|
-
|
|
241
|
-
```typescript
|
|
242
|
-
import { openNativeWallet, isWalletAvailable } from '@oobit/react-native-sdk';
|
|
243
|
-
|
|
244
|
-
// Check if wallet is available
|
|
245
|
-
const available = await isWalletAvailable();
|
|
246
|
-
|
|
247
|
-
if (available) {
|
|
248
|
-
// Open native wallet
|
|
249
|
-
await openNativeWallet();
|
|
250
|
-
}
|
|
251
|
-
```
|
|
252
|
-
|
|
253
|
-
## Platform Support
|
|
254
|
-
|
|
255
|
-
| Platform | Supported | Notes |
|
|
256
|
-
|----------|-----------|-------|
|
|
257
|
-
| iOS | ✅ | Includes Apple Wallet integration |
|
|
258
|
-
| Android | ✅ | Includes Google Pay integration |
|
|
259
|
-
| Web | ❌ | React Native only |
|
|
260
|
-
|
|
261
|
-
## Complete Example
|
|
262
|
-
|
|
263
|
-
```typescript
|
|
264
|
-
import React, { useState, useRef } from 'react';
|
|
265
|
-
import { View, Button, StyleSheet, Alert } from 'react-native';
|
|
266
|
-
import { WidgetSDK, WidgetSDKRef } from '@oobit/react-native-sdk';
|
|
267
|
-
|
|
268
|
-
export default function PaymentScreen() {
|
|
269
|
-
const [showWidget, setShowWidget] = useState(false);
|
|
270
|
-
const widgetRef = useRef<WidgetSDKRef>(null);
|
|
271
|
-
|
|
272
|
-
if (showWidget) {
|
|
273
|
-
return (
|
|
274
|
-
<View style={styles.container}>
|
|
275
|
-
<WidgetSDK
|
|
276
|
-
ref={widgetRef}
|
|
277
|
-
accessToken="your-jwt-token"
|
|
278
|
-
userWalletAddress="0x1234..."
|
|
279
|
-
environment="production"
|
|
280
|
-
debug={__DEV__}
|
|
281
|
-
onReady={() => {
|
|
282
|
-
console.log('Widget ready');
|
|
283
|
-
}}
|
|
284
|
-
onError={(code, message) => {
|
|
285
|
-
Alert.alert('Error', `${code}: ${message}`);
|
|
286
|
-
if (code === 'WEBVIEW_ERROR') {
|
|
287
|
-
// Offer retry option
|
|
288
|
-
Alert.alert('Error', 'Failed to load. Retry?', [
|
|
289
|
-
{ text: 'Cancel', onPress: () => setShowWidget(false) },
|
|
290
|
-
{ text: 'Retry', onPress: () => widgetRef.current?.reload() },
|
|
291
|
-
]);
|
|
292
|
-
}
|
|
293
|
-
}}
|
|
294
|
-
onClose={() => {
|
|
295
|
-
setShowWidget(false);
|
|
296
|
-
}}
|
|
297
|
-
onTransactionRequested={(token, amount, address, tag) => {
|
|
298
|
-
Alert.alert(
|
|
299
|
-
'Transaction Requested',
|
|
300
|
-
`Send ${amount} ${token.symbol} to ${address}`,
|
|
301
|
-
);
|
|
302
|
-
}}
|
|
303
|
-
onLoadingChange={(isLoading) => {
|
|
304
|
-
console.log('Loading:', isLoading);
|
|
305
|
-
}}
|
|
306
|
-
/>
|
|
307
|
-
</View>
|
|
308
|
-
);
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
return (
|
|
312
|
-
<View style={styles.container}>
|
|
313
|
-
<Button
|
|
314
|
-
title="Open Payment Widget"
|
|
315
|
-
onPress={() => setShowWidget(true)}
|
|
316
|
-
/>
|
|
317
|
-
</View>
|
|
318
|
-
);
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
const styles = StyleSheet.create({
|
|
322
|
-
container: {
|
|
323
|
-
flex: 1,
|
|
324
|
-
},
|
|
325
|
-
});
|
|
326
|
-
```
|
|
327
|
-
|
|
328
|
-
## Dependencies
|
|
329
|
-
|
|
330
|
-
### Required Peer Dependencies
|
|
331
|
-
|
|
332
|
-
```json
|
|
333
|
-
{
|
|
334
|
-
"react": ">=18.0.0",
|
|
335
|
-
"react-native": ">=0.70.0",
|
|
336
|
-
"react-native-webview": ">=13.0.0",
|
|
337
|
-
"expo-linking": ">=6.0.0",
|
|
338
|
-
"expo-clipboard": ">=5.0.0",
|
|
339
|
-
"expo-intent-launcher": ">=6.0.0",
|
|
340
|
-
"expo-local-authentication": ">=14.0.0"
|
|
341
|
-
}
|
|
342
|
-
```
|
|
343
|
-
|
|
344
|
-
## Troubleshooting
|
|
345
|
-
|
|
346
|
-
### Widget Not Loading
|
|
347
|
-
|
|
348
|
-
1. Verify `accessToken` is valid and not expired
|
|
349
|
-
2. Check that `userWalletAddress` is a valid address
|
|
350
|
-
3. Enable `debug={true}` to see console logs
|
|
351
|
-
4. Verify all peer dependencies are installed
|
|
352
|
-
|
|
353
|
-
### Callbacks Not Firing
|
|
354
|
-
|
|
355
|
-
1. Enable debug mode to see message logs
|
|
356
|
-
2. Check that your widget is sending proper postMessage events
|
|
357
|
-
3. Verify message format matches expected structure
|
|
358
|
-
|
|
359
|
-
### Error: TOKEN_EXPIRED
|
|
34
|
+
## Documentation
|
|
360
35
|
|
|
361
|
-
|
|
36
|
+
For complete documentation, guides, and API reference, visit:
|
|
362
37
|
|
|
363
|
-
|
|
38
|
+
**[Oobit Developer Docs](https://docs.oobit.com/docs/getting-started)**
|
|
364
39
|
|
|
365
|
-
|
|
40
|
+
- [Getting Started](https://docs.oobit.com/docs/getting-started) - Installation and setup
|
|
41
|
+
- [Component Reference](https://docs.oobit.com/docs/component) - Props and methods
|
|
42
|
+
- [Handling Transactions](https://docs.oobit.com/docs/transactions) - Transaction flow guide
|
|
43
|
+
- [TypeScript Types](https://docs.oobit.com/docs/types) - Type definitions
|
|
366
44
|
|
|
367
45
|
## License
|
|
368
46
|
|