@oobit/react-native-sdk 2.0.0 → 2.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/dist/WidgetSDK.d.ts.map +1 -1
- package/dist/WidgetSDK.js +13 -57
- package/dist/WidgetSDK.js.map +1 -1
- package/dist/config.d.ts +12 -7
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +36 -7
- package/dist/config.js.map +1 -1
- package/dist/index.d.ts +1 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -13
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +1 -35
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +1 -1
- package/src/WidgetSDK.tsx +14 -70
- package/src/config.ts +36 -10
- package/src/index.ts +0 -33
- package/src/types.ts +2 -37
package/dist/WidgetSDK.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WidgetSDK.d.ts","sourceRoot":"","sources":["../src/WidgetSDK.tsx"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAON,MAAM,OAAO,CAAC;AAWf,OAAO,EAAyC,eAAe,EAAE,MAAM,SAAS,CAAC;AAIjF,MAAM,WAAW,YAAY;IAC3B,sCAAsC;IACtC,YAAY,EAAE,MAAM,IAAI,CAAC;IACzB,wBAAwB;IACxB,MAAM,EAAE,MAAM,IAAI,CAAC;CACpB;AAED,eAAO,MAAM,SAAS,
|
|
1
|
+
{"version":3,"file":"WidgetSDK.d.ts","sourceRoot":"","sources":["../src/WidgetSDK.tsx"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAON,MAAM,OAAO,CAAC;AAWf,OAAO,EAAyC,eAAe,EAAE,MAAM,SAAS,CAAC;AAIjF,MAAM,WAAW,YAAY;IAC3B,sCAAsC;IACtC,YAAY,EAAE,MAAM,IAAI,CAAC;IACzB,wBAAwB;IACxB,MAAM,EAAE,MAAM,IAAI,CAAC;CACpB;AAED,eAAO,MAAM,SAAS,sFAqPrB,CAAC"}
|
package/dist/WidgetSDK.js
CHANGED
|
@@ -44,17 +44,7 @@ const react_native_webview_1 = require("react-native-webview");
|
|
|
44
44
|
const config_1 = require("./config");
|
|
45
45
|
const walletUtils_1 = require("./walletUtils");
|
|
46
46
|
const Clipboard = __importStar(require("expo-clipboard"));
|
|
47
|
-
exports.WidgetSDK = (0, react_1.forwardRef)(({ accessToken, userWalletAddress,
|
|
48
|
-
// Debug logger - only logs when debug is enabled
|
|
49
|
-
const log = debug
|
|
50
|
-
? (...args) => console.log("[WidgetSDK]", ...args)
|
|
51
|
-
: () => { };
|
|
52
|
-
const logError = debug
|
|
53
|
-
? (...args) => console.error("[WidgetSDK]", ...args)
|
|
54
|
-
: () => { };
|
|
55
|
-
const logWarn = debug
|
|
56
|
-
? (...args) => console.warn("[WidgetSDK]", ...args)
|
|
57
|
-
: () => { };
|
|
47
|
+
exports.WidgetSDK = (0, react_1.forwardRef)(({ accessToken, userWalletAddress, onError, onClose, onTransactionRequested, }, ref) => {
|
|
58
48
|
const webViewRef = (0, react_1.useRef)(null);
|
|
59
49
|
const [walletAvailable, setWalletAvailable] = (0, react_1.useState)(false);
|
|
60
50
|
const [isLoading, setIsLoading] = (0, react_1.useState)(true);
|
|
@@ -85,16 +75,11 @@ exports.WidgetSDK = (0, react_1.forwardRef)(({ accessToken, userWalletAddress, e
|
|
|
85
75
|
});
|
|
86
76
|
},
|
|
87
77
|
reload: () => {
|
|
88
|
-
log("Reloading widget");
|
|
89
78
|
setIsLoading(true);
|
|
90
79
|
hasLoadedOnce.current = false;
|
|
91
80
|
webViewRef.current?.reload();
|
|
92
81
|
},
|
|
93
82
|
}));
|
|
94
|
-
// Notify parent of loading state changes
|
|
95
|
-
(0, react_1.useEffect)(() => {
|
|
96
|
-
onLoadingChange?.(isLoading);
|
|
97
|
-
}, [isLoading, onLoadingChange]);
|
|
98
83
|
const checkWalletAvailability = async () => {
|
|
99
84
|
const available = await (0, walletUtils_1.isWalletAvailable)();
|
|
100
85
|
setWalletAvailable(available);
|
|
@@ -105,7 +90,6 @@ exports.WidgetSDK = (0, react_1.forwardRef)(({ accessToken, userWalletAddress, e
|
|
|
105
90
|
const handleMessage = (event) => {
|
|
106
91
|
try {
|
|
107
92
|
const message = JSON.parse(event.nativeEvent.data);
|
|
108
|
-
log("Received message:", message.type);
|
|
109
93
|
switch (message.type) {
|
|
110
94
|
case "widget:ready":
|
|
111
95
|
handleReady();
|
|
@@ -117,30 +101,24 @@ exports.WidgetSDK = (0, react_1.forwardRef)(({ accessToken, userWalletAddress, e
|
|
|
117
101
|
handleError(message);
|
|
118
102
|
break;
|
|
119
103
|
case "widget:close":
|
|
120
|
-
|
|
104
|
+
onClose?.();
|
|
121
105
|
break;
|
|
122
106
|
case "widget:transaction-requested":
|
|
123
107
|
handleTransactionRequested(message);
|
|
124
108
|
break;
|
|
125
109
|
case "widget:token-expired":
|
|
126
|
-
logError("Access token expired");
|
|
127
110
|
onError?.("TOKEN_EXPIRED", "Access token has expired");
|
|
128
111
|
break;
|
|
129
112
|
case "widget:copy-to-clipboard":
|
|
130
113
|
handleCopyToClipboard(message);
|
|
131
114
|
break;
|
|
132
|
-
default:
|
|
133
|
-
logWarn("Unknown message type:", message);
|
|
134
115
|
}
|
|
135
116
|
}
|
|
136
|
-
catch
|
|
137
|
-
logError("Failed to parse message:", error);
|
|
117
|
+
catch {
|
|
138
118
|
onError?.("PARSE_ERROR", "Failed to parse widget message");
|
|
139
119
|
}
|
|
140
120
|
};
|
|
141
121
|
const handleReady = () => {
|
|
142
|
-
log("Widget ready");
|
|
143
|
-
onReady?.();
|
|
144
122
|
// Send platform info to widget
|
|
145
123
|
sendMessageToWidget({
|
|
146
124
|
type: "native:platform-info",
|
|
@@ -151,7 +129,6 @@ exports.WidgetSDK = (0, react_1.forwardRef)(({ accessToken, userWalletAddress, e
|
|
|
151
129
|
});
|
|
152
130
|
};
|
|
153
131
|
const handleOpenWallet = async () => {
|
|
154
|
-
log("Opening native wallet...");
|
|
155
132
|
const success = await (0, walletUtils_1.openNativeWallet)();
|
|
156
133
|
// Notify widget of result
|
|
157
134
|
sendMessageToWidget({
|
|
@@ -163,32 +140,19 @@ exports.WidgetSDK = (0, react_1.forwardRef)(({ accessToken, userWalletAddress, e
|
|
|
163
140
|
if (message.type !== "widget:error")
|
|
164
141
|
return;
|
|
165
142
|
const { code, message: errorMessage } = message.payload;
|
|
166
|
-
logError("Widget error:", code, errorMessage);
|
|
167
143
|
onError?.(code, errorMessage);
|
|
168
144
|
};
|
|
169
|
-
const handleClose = () => {
|
|
170
|
-
log("Widget closed");
|
|
171
|
-
onClose?.();
|
|
172
|
-
};
|
|
173
145
|
const handleTransactionRequested = (message) => {
|
|
174
146
|
if (message.type !== "widget:transaction-requested")
|
|
175
147
|
return;
|
|
176
148
|
const { token, cryptoAmount, depositAddress, depositAddressTag } = message.payload;
|
|
177
|
-
|
|
178
|
-
token: token.symbol,
|
|
179
|
-
cryptoAmount,
|
|
180
|
-
depositAddress,
|
|
181
|
-
});
|
|
182
|
-
onTransactionRequested?.(token, cryptoAmount, depositAddress, depositAddressTag);
|
|
149
|
+
onTransactionRequested(token, cryptoAmount, depositAddress, depositAddressTag);
|
|
183
150
|
};
|
|
184
151
|
/**
|
|
185
152
|
* Handle clipboard copy request from widget
|
|
186
|
-
* Copies text to device clipboard and sends result back to widget
|
|
187
153
|
*/
|
|
188
154
|
const handleCopyToClipboard = async (message) => {
|
|
189
155
|
const { text, label } = message.payload;
|
|
190
|
-
// Log only the label, never the actual text content (security)
|
|
191
|
-
log("Copy to clipboard requested:", label || "unlabeled");
|
|
192
156
|
try {
|
|
193
157
|
await Clipboard.setStringAsync(text);
|
|
194
158
|
sendMessageToWidget({
|
|
@@ -196,8 +160,7 @@ exports.WidgetSDK = (0, react_1.forwardRef)(({ accessToken, userWalletAddress, e
|
|
|
196
160
|
payload: { success: true, label },
|
|
197
161
|
});
|
|
198
162
|
}
|
|
199
|
-
catch
|
|
200
|
-
logError("Clipboard copy failed:", error);
|
|
163
|
+
catch {
|
|
201
164
|
sendMessageToWidget({
|
|
202
165
|
type: "native:clipboard-result",
|
|
203
166
|
payload: {
|
|
@@ -222,29 +185,25 @@ exports.WidgetSDK = (0, react_1.forwardRef)(({ accessToken, userWalletAddress, e
|
|
|
222
185
|
* Build the widget URL with query parameters
|
|
223
186
|
*/
|
|
224
187
|
const finalWidgetUrl = (0, react_1.useMemo)(() => {
|
|
225
|
-
const baseUrl = (0, config_1.getWidgetUrl)(
|
|
188
|
+
const baseUrl = (0, config_1.getWidgetUrl)(accessToken);
|
|
226
189
|
const params = new URLSearchParams({
|
|
227
|
-
token: accessToken,
|
|
190
|
+
token: (0, config_1.stripTokenPrefix)(accessToken),
|
|
228
191
|
platform: react_native_1.Platform.OS,
|
|
229
192
|
userWalletAddress: userWalletAddress,
|
|
230
193
|
});
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
return url;
|
|
234
|
-
}, [accessToken, userWalletAddress, environment]);
|
|
194
|
+
return `${baseUrl}?${params.toString()}`;
|
|
195
|
+
}, [accessToken, userWalletAddress]);
|
|
235
196
|
return (<react_native_1.View style={styles.container}>
|
|
236
197
|
<react_native_webview_1.WebView ref={webViewRef} style={styles.webview} source={{ uri: finalWidgetUrl }} onMessage={handleMessage} onLoadEnd={() => {
|
|
237
198
|
if (!hasLoadedOnce.current) {
|
|
238
199
|
hasLoadedOnce.current = true;
|
|
239
200
|
setIsLoading(false);
|
|
240
201
|
}
|
|
241
|
-
}} onError={(
|
|
242
|
-
const { nativeEvent } = syntheticEvent;
|
|
243
|
-
logError("WebView error:", nativeEvent);
|
|
202
|
+
}} onError={() => {
|
|
244
203
|
setIsLoading(false);
|
|
245
204
|
onError?.("WEBVIEW_ERROR", "Failed to load widget");
|
|
246
205
|
}}
|
|
247
|
-
//
|
|
206
|
+
// Allow external URLs to open in native apps
|
|
248
207
|
onShouldStartLoadWithRequest={(request) => {
|
|
249
208
|
const { url } = request;
|
|
250
209
|
// Allow wallet URLs to open in native apps
|
|
@@ -252,10 +211,7 @@ exports.WidgetSDK = (0, react_1.forwardRef)(({ accessToken, userWalletAddress, e
|
|
|
252
211
|
url.includes("pay.google.com") || // Google Wallet
|
|
253
212
|
url.includes("wallet.google.com") ||
|
|
254
213
|
url.includes("wallet.apple.com")) {
|
|
255
|
-
|
|
256
|
-
react_native_1.Linking.openURL(url).catch((err) => {
|
|
257
|
-
logError("Failed to open URL:", err);
|
|
258
|
-
});
|
|
214
|
+
react_native_1.Linking.openURL(url).catch(() => { });
|
|
259
215
|
return false; // Don't load in WebView
|
|
260
216
|
}
|
|
261
217
|
// Allow normal widget navigation
|
|
@@ -268,7 +224,7 @@ exports.WidgetSDK = (0, react_1.forwardRef)(({ accessToken, userWalletAddress, e
|
|
|
268
224
|
// Android specific
|
|
269
225
|
mixedContentMode="always"/>
|
|
270
226
|
{isLoading && (<react_native_1.View style={styles.loadingOverlay}>
|
|
271
|
-
<react_native_1.ActivityIndicator size="large" color=
|
|
227
|
+
<react_native_1.ActivityIndicator size="large" color="#007AFF"/>
|
|
272
228
|
</react_native_1.View>)}
|
|
273
229
|
</react_native_1.View>);
|
|
274
230
|
});
|
package/dist/WidgetSDK.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WidgetSDK.js","sourceRoot":"","sources":["../src/WidgetSDK.tsx"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,+CAOe;AACf,+CAOsB;AACtB,+DAAoE;AACpE,
|
|
1
|
+
{"version":3,"file":"WidgetSDK.js","sourceRoot":"","sources":["../src/WidgetSDK.tsx"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,+CAOe;AACf,+CAOsB;AACtB,+DAAoE;AACpE,qCAA0D;AAE1D,+CAAoE;AACpE,0DAA4C;AAS/B,QAAA,SAA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CAAC,OAAO,CAAC,KAAK,CAAC,SAAS,EACjD;UAAA,EAAE,mBAAI,CAAC,CACR,CACH;MAAA,EAAE,mBAAI,CAAC,CACR,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,MAAM,MAAM,GAAG,yBAAU,CAAC,MAAM,CAAC;IAC/B,SAAS,EAAE;QACT,IAAI,EAAE,CAAC;KACR;IACD,OAAO,EAAE;QACP,IAAI,EAAE,CAAC;KACR;IACD,cAAc,EAAE;QACd,GAAG,yBAAU,CAAC,kBAAkB;QAChC,eAAe,EAAE,0BAA0B;QAC3C,cAAc,EAAE,QAAQ;QACxB,UAAU,EAAE,QAAQ;KACrB;CACF,CAAC,CAAC"}
|
package/dist/config.d.ts
CHANGED
|
@@ -1,19 +1,24 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Widget SDK Configuration
|
|
3
|
-
* Environment
|
|
3
|
+
* Environment detection based on access token prefix
|
|
4
4
|
*/
|
|
5
|
-
import { WidgetEnvironment } from "./types";
|
|
6
5
|
/**
|
|
7
6
|
* Widget URLs by environment
|
|
8
7
|
*/
|
|
9
8
|
export declare const WIDGET_URLS: {
|
|
10
|
-
readonly
|
|
9
|
+
readonly sandbox: "https://oobit-widget-dev.web.app";
|
|
11
10
|
readonly production: "https://oobit-widget.web.app";
|
|
12
11
|
};
|
|
13
12
|
/**
|
|
14
|
-
* Get the widget URL
|
|
15
|
-
* @param
|
|
16
|
-
* @returns The widget URL for the
|
|
13
|
+
* Get the widget URL based on the access token prefix
|
|
14
|
+
* @param accessToken - The access token (prefixed with sbx_ or prod_)
|
|
15
|
+
* @returns The widget URL for the corresponding environment
|
|
17
16
|
*/
|
|
18
|
-
export declare function getWidgetUrl(
|
|
17
|
+
export declare function getWidgetUrl(accessToken: string): string;
|
|
18
|
+
/**
|
|
19
|
+
* Strip the environment prefix from an access token
|
|
20
|
+
* @param accessToken - The access token (prefixed with sbx_ or prod_)
|
|
21
|
+
* @returns The token without the environment prefix
|
|
22
|
+
*/
|
|
23
|
+
export declare function stripTokenPrefix(accessToken: string): string;
|
|
19
24
|
//# sourceMappingURL=config.d.ts.map
|
package/dist/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAUH;;GAEG;AACH,eAAO,MAAM,WAAW;;;CAGd,CAAC;AAEX;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CASxD;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAQ5D"}
|
package/dist/config.js
CHANGED
|
@@ -1,24 +1,53 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
3
|
* Widget SDK Configuration
|
|
4
|
-
* Environment
|
|
4
|
+
* Environment detection based on access token prefix
|
|
5
5
|
*/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
exports.WIDGET_URLS = void 0;
|
|
8
8
|
exports.getWidgetUrl = getWidgetUrl;
|
|
9
|
+
exports.stripTokenPrefix = stripTokenPrefix;
|
|
10
|
+
/**
|
|
11
|
+
* Token prefixes that determine the environment
|
|
12
|
+
*/
|
|
13
|
+
const TOKEN_PREFIX = {
|
|
14
|
+
SANDBOX: "sbx_",
|
|
15
|
+
PRODUCTION: "prod_",
|
|
16
|
+
};
|
|
9
17
|
/**
|
|
10
18
|
* Widget URLs by environment
|
|
11
19
|
*/
|
|
12
20
|
exports.WIDGET_URLS = {
|
|
13
|
-
|
|
21
|
+
sandbox: "https://oobit-widget-dev.web.app",
|
|
14
22
|
production: "https://oobit-widget.web.app",
|
|
15
23
|
};
|
|
16
24
|
/**
|
|
17
|
-
* Get the widget URL
|
|
18
|
-
* @param
|
|
19
|
-
* @returns The widget URL for the
|
|
25
|
+
* Get the widget URL based on the access token prefix
|
|
26
|
+
* @param accessToken - The access token (prefixed with sbx_ or prod_)
|
|
27
|
+
* @returns The widget URL for the corresponding environment
|
|
28
|
+
*/
|
|
29
|
+
function getWidgetUrl(accessToken) {
|
|
30
|
+
if (accessToken.startsWith(TOKEN_PREFIX.SANDBOX)) {
|
|
31
|
+
return exports.WIDGET_URLS.sandbox;
|
|
32
|
+
}
|
|
33
|
+
if (accessToken.startsWith(TOKEN_PREFIX.PRODUCTION)) {
|
|
34
|
+
return exports.WIDGET_URLS.production;
|
|
35
|
+
}
|
|
36
|
+
// Default to production for backwards compatibility
|
|
37
|
+
return exports.WIDGET_URLS.production;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Strip the environment prefix from an access token
|
|
41
|
+
* @param accessToken - The access token (prefixed with sbx_ or prod_)
|
|
42
|
+
* @returns The token without the environment prefix
|
|
20
43
|
*/
|
|
21
|
-
function
|
|
22
|
-
|
|
44
|
+
function stripTokenPrefix(accessToken) {
|
|
45
|
+
if (accessToken.startsWith(TOKEN_PREFIX.SANDBOX)) {
|
|
46
|
+
return accessToken.slice(TOKEN_PREFIX.SANDBOX.length);
|
|
47
|
+
}
|
|
48
|
+
if (accessToken.startsWith(TOKEN_PREFIX.PRODUCTION)) {
|
|
49
|
+
return accessToken.slice(TOKEN_PREFIX.PRODUCTION.length);
|
|
50
|
+
}
|
|
51
|
+
return accessToken;
|
|
23
52
|
}
|
|
24
53
|
//# sourceMappingURL=config.js.map
|
package/dist/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAuBH,oCASC;AAOD,4CAQC;AA7CD;;GAEG;AACH,MAAM,YAAY,GAAG;IACnB,OAAO,EAAE,MAAM;IACf,UAAU,EAAE,OAAO;CACX,CAAC;AAEX;;GAEG;AACU,QAAA,WAAW,GAAG;IACzB,OAAO,EAAE,kCAAkC;IAC3C,UAAU,EAAE,8BAA8B;CAClC,CAAC;AAEX;;;;GAIG;AACH,SAAgB,YAAY,CAAC,WAAmB;IAC9C,IAAI,WAAW,CAAC,UAAU,CAAC,YAAY,CAAC,OAAO,CAAC,EAAE,CAAC;QACjD,OAAO,mBAAW,CAAC,OAAO,CAAC;IAC7B,CAAC;IACD,IAAI,WAAW,CAAC,UAAU,CAAC,YAAY,CAAC,UAAU,CAAC,EAAE,CAAC;QACpD,OAAO,mBAAW,CAAC,UAAU,CAAC;IAChC,CAAC;IACD,oDAAoD;IACpD,OAAO,mBAAW,CAAC,UAAU,CAAC;AAChC,CAAC;AAED;;;;GAIG;AACH,SAAgB,gBAAgB,CAAC,WAAmB;IAClD,IAAI,WAAW,CAAC,UAAU,CAAC,YAAY,CAAC,OAAO,CAAC,EAAE,CAAC;QACjD,OAAO,WAAW,CAAC,KAAK,CAAC,YAAY,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IACxD,CAAC;IACD,IAAI,WAAW,CAAC,UAAU,CAAC,YAAY,CAAC,UAAU,CAAC,EAAE,CAAC;QACpD,OAAO,WAAW,CAAC,KAAK,CAAC,YAAY,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;IAC3D,CAAC;IACD,OAAO,WAAW,CAAC;AACrB,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Widget SDK - Public API
|
|
3
|
-
* Export all public components, types, and utilities
|
|
4
3
|
*/
|
|
5
4
|
export { WidgetSDK } from "./WidgetSDK";
|
|
6
5
|
export type { WidgetSDKRef } from "./WidgetSDK";
|
|
7
|
-
export type {
|
|
8
|
-
export { getWidgetUrl, WIDGET_URLS } from "./config";
|
|
9
|
-
export { MessageTypes, WALLET_URLS } from "./types";
|
|
10
|
-
export { isWalletAvailable, openNativeWallet } from "./walletUtils";
|
|
6
|
+
export type { DepositToken, SDKErrorCode, WidgetSDKConfig, } from "./types";
|
|
11
7
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,YAAY,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD,YAAY,EACV,YAAY,EACZ,YAAY,EACZ,eAAe,GAChB,MAAM,SAAS,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,21 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
3
|
* Widget SDK - Public API
|
|
4
|
-
* Export all public components, types, and utilities
|
|
5
4
|
*/
|
|
6
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.
|
|
6
|
+
exports.WidgetSDK = void 0;
|
|
8
7
|
var WidgetSDK_1 = require("./WidgetSDK");
|
|
9
8
|
Object.defineProperty(exports, "WidgetSDK", { enumerable: true, get: function () { return WidgetSDK_1.WidgetSDK; } });
|
|
10
|
-
// Export constants
|
|
11
|
-
var config_1 = require("./config");
|
|
12
|
-
Object.defineProperty(exports, "getWidgetUrl", { enumerable: true, get: function () { return config_1.getWidgetUrl; } });
|
|
13
|
-
Object.defineProperty(exports, "WIDGET_URLS", { enumerable: true, get: function () { return config_1.WIDGET_URLS; } });
|
|
14
|
-
var types_1 = require("./types");
|
|
15
|
-
Object.defineProperty(exports, "MessageTypes", { enumerable: true, get: function () { return types_1.MessageTypes; } });
|
|
16
|
-
Object.defineProperty(exports, "WALLET_URLS", { enumerable: true, get: function () { return types_1.WALLET_URLS; } });
|
|
17
|
-
// Export wallet utilities
|
|
18
|
-
var walletUtils_1 = require("./walletUtils");
|
|
19
|
-
Object.defineProperty(exports, "isWalletAvailable", { enumerable: true, get: function () { return walletUtils_1.isWalletAvailable; } });
|
|
20
|
-
Object.defineProperty(exports, "openNativeWallet", { enumerable: true, get: function () { return walletUtils_1.openNativeWallet; } });
|
|
21
9
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,yCAAwC;AAA/B,sGAAA,SAAS,OAAA"}
|
package/dist/types.d.ts
CHANGED
|
@@ -114,12 +114,6 @@ export interface CopyToClipboardMessage extends BaseWidgetMessage {
|
|
|
114
114
|
};
|
|
115
115
|
}
|
|
116
116
|
export type WidgetMessage = WidgetReadyMessage | OpenWalletMessage | WidgetErrorMessage | WidgetCloseMessage | TransactionRequestedMessage | TokenExpiredMessage | RequestCardDetailsSessionMessage | CopyToClipboardMessage;
|
|
117
|
-
/**
|
|
118
|
-
* Widget environment configuration
|
|
119
|
-
* - 'development': Uses development/staging widget URL
|
|
120
|
-
* - 'production': Uses production widget URL
|
|
121
|
-
*/
|
|
122
|
-
export type WidgetEnvironment = "development" | "production";
|
|
123
117
|
/**
|
|
124
118
|
* Known SDK error codes
|
|
125
119
|
* - TOKEN_EXPIRED: The access token has expired
|
|
@@ -133,21 +127,8 @@ export type SDKErrorCode = "TOKEN_EXPIRED" | "PARSE_ERROR" | "WEBVIEW_ERROR";
|
|
|
133
127
|
export interface WidgetSDKConfig {
|
|
134
128
|
accessToken: string;
|
|
135
129
|
userWalletAddress: string;
|
|
136
|
-
/**
|
|
137
|
-
* Widget environment to use.
|
|
138
|
-
* - 'development': Uses https://oobit-widget-dev.web.app
|
|
139
|
-
* - 'production': Uses https://widget.oobit.com
|
|
140
|
-
* @default 'production'
|
|
141
|
-
*/
|
|
142
|
-
environment?: WidgetEnvironment;
|
|
143
|
-
/**
|
|
144
|
-
* Called when the widget is ready and loaded
|
|
145
|
-
*/
|
|
146
|
-
onReady?: () => void;
|
|
147
130
|
/**
|
|
148
131
|
* Called when an error occurs
|
|
149
|
-
* @param code - Error code (SDKErrorCode or custom widget error code)
|
|
150
|
-
* @param message - Human-readable error message
|
|
151
132
|
*/
|
|
152
133
|
onError?: (code: SDKErrorCode | string, message: string) => void;
|
|
153
134
|
/**
|
|
@@ -157,22 +138,7 @@ export interface WidgetSDKConfig {
|
|
|
157
138
|
/**
|
|
158
139
|
* Called when a crypto transaction is requested
|
|
159
140
|
*/
|
|
160
|
-
onTransactionRequested
|
|
161
|
-
/**
|
|
162
|
-
* Called when the loading state changes
|
|
163
|
-
* @param isLoading - Whether the widget is currently loading
|
|
164
|
-
*/
|
|
165
|
-
onLoadingChange?: (isLoading: boolean) => void;
|
|
166
|
-
/**
|
|
167
|
-
* Enable debug logging to console
|
|
168
|
-
* @default false
|
|
169
|
-
*/
|
|
170
|
-
debug?: boolean;
|
|
171
|
-
/**
|
|
172
|
-
* Custom color for the loading indicator
|
|
173
|
-
* @default "#007AFF"
|
|
174
|
-
*/
|
|
175
|
-
loadingIndicatorColor?: string;
|
|
141
|
+
onTransactionRequested: (token: DepositToken, cryptoAmount: string, depositAddress: string, depositAddressTag: string | null) => void;
|
|
176
142
|
}
|
|
177
143
|
/**
|
|
178
144
|
* Platform-specific wallet URLs
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAA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;AACH,MAAM,WAAW,eAAe;IAC9B,WAAW,EAAE,MAAM,CAAC;IACpB,iBAAiB,EAAE,MAAM,CAAC;IAC1B;;OAEG;IACH,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,YAAY,GAAG,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IACjE;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB;;OAEG;IACH,sBAAsB,EAAE,CACtB,KAAK,EAAE,YAAY,EACnB,YAAY,EAAE,MAAM,EACpB,cAAc,EAAE,MAAM,EACtB,iBAAiB,EAAE,MAAM,GAAG,IAAI,KAC7B,IAAI,CAAC;CACX;AAED;;GAEG;AACH,eAAO,MAAM,WAAW;;;;;;;;;CASd,CAAC;AAEX;;;;;;GAMG;AACH,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;CAkBf,CAAC"}
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAsMH;;GAEG;AACU,QAAA,WAAW,GAAG;IACzB,GAAG,EAAE;QACH,OAAO,EAAE,YAAY,EAAE,yBAAyB;QAChD,QAAQ,EAAE,0BAA0B;KACrC;IACD,OAAO,EAAE;QACP,SAAS,EAAE,yCAAyC;QACpD,QAAQ,EAAE,2BAA2B;KACtC;CACO,CAAC;AAEX;;;;;;GAMG;AACU,QAAA,YAAY,GAAG;IAC1B,kBAAkB;IAClB,KAAK,EAAE,cAAc;IACrB,WAAW,EAAE,oBAAoB;IACjC,KAAK,EAAE,cAAc;IACrB,KAAK,EAAE,cAAc;IACrB,qBAAqB,EAAE,8BAA8B;IACrD,aAAa,EAAE,sBAAsB;IACrC,4BAA4B,EAAE,qCAAqC;IACnE,iBAAiB,EAAE,0BAA0B;IAC7C,kBAAkB;IAClB,aAAa,EAAE,sBAAsB;IACrC,aAAa,EAAE,sBAAsB;IACrC,YAAY,EAAE,qBAAqB;IACnC,aAAa,EAAE,sBAAsB;IACrC,oBAAoB,EAAE,6BAA6B;IACnD,gBAAgB,EAAE,yBAAyB;IAC3C,gBAAgB,EAAE,yBAAyB;CACnC,CAAC"}
|
package/package.json
CHANGED
package/src/WidgetSDK.tsx
CHANGED
|
@@ -20,7 +20,7 @@ import {
|
|
|
20
20
|
View,
|
|
21
21
|
} from "react-native";
|
|
22
22
|
import { WebView, WebViewMessageEvent } from "react-native-webview";
|
|
23
|
-
import { getWidgetUrl } from "./config";
|
|
23
|
+
import { getWidgetUrl, stripTokenPrefix } from "./config";
|
|
24
24
|
import { CopyToClipboardMessage, WidgetMessage, WidgetSDKConfig } from "./types";
|
|
25
25
|
import { isWalletAvailable, openNativeWallet } from "./walletUtils";
|
|
26
26
|
import * as Clipboard from "expo-clipboard";
|
|
@@ -37,27 +37,12 @@ export const WidgetSDK = forwardRef<WidgetSDKRef, WidgetSDKConfig>(
|
|
|
37
37
|
{
|
|
38
38
|
accessToken,
|
|
39
39
|
userWalletAddress,
|
|
40
|
-
environment,
|
|
41
|
-
onReady,
|
|
42
40
|
onError,
|
|
43
41
|
onClose,
|
|
44
42
|
onTransactionRequested,
|
|
45
|
-
onLoadingChange,
|
|
46
|
-
debug = false,
|
|
47
|
-
loadingIndicatorColor = "#007AFF",
|
|
48
43
|
},
|
|
49
44
|
ref
|
|
50
45
|
) => {
|
|
51
|
-
// Debug logger - only logs when debug is enabled
|
|
52
|
-
const log = debug
|
|
53
|
-
? (...args: unknown[]) => console.log("[WidgetSDK]", ...args)
|
|
54
|
-
: () => {};
|
|
55
|
-
const logError = debug
|
|
56
|
-
? (...args: unknown[]) => console.error("[WidgetSDK]", ...args)
|
|
57
|
-
: () => {};
|
|
58
|
-
const logWarn = debug
|
|
59
|
-
? (...args: unknown[]) => console.warn("[WidgetSDK]", ...args)
|
|
60
|
-
: () => {};
|
|
61
46
|
const webViewRef = useRef<WebView>(null);
|
|
62
47
|
const [walletAvailable, setWalletAvailable] = useState(false);
|
|
63
48
|
const [isLoading, setIsLoading] = useState(true);
|
|
@@ -95,18 +80,12 @@ export const WidgetSDK = forwardRef<WidgetSDKRef, WidgetSDKConfig>(
|
|
|
95
80
|
});
|
|
96
81
|
},
|
|
97
82
|
reload: () => {
|
|
98
|
-
log("Reloading widget");
|
|
99
83
|
setIsLoading(true);
|
|
100
84
|
hasLoadedOnce.current = false;
|
|
101
85
|
webViewRef.current?.reload();
|
|
102
86
|
},
|
|
103
87
|
}));
|
|
104
88
|
|
|
105
|
-
// Notify parent of loading state changes
|
|
106
|
-
useEffect(() => {
|
|
107
|
-
onLoadingChange?.(isLoading);
|
|
108
|
-
}, [isLoading, onLoadingChange]);
|
|
109
|
-
|
|
110
89
|
const checkWalletAvailability = async () => {
|
|
111
90
|
const available = await isWalletAvailable();
|
|
112
91
|
setWalletAvailable(available);
|
|
@@ -119,8 +98,6 @@ export const WidgetSDK = forwardRef<WidgetSDKRef, WidgetSDKConfig>(
|
|
|
119
98
|
try {
|
|
120
99
|
const message: WidgetMessage = JSON.parse(event.nativeEvent.data);
|
|
121
100
|
|
|
122
|
-
log("Received message:", message.type);
|
|
123
|
-
|
|
124
101
|
switch (message.type) {
|
|
125
102
|
case "widget:ready":
|
|
126
103
|
handleReady();
|
|
@@ -135,7 +112,7 @@ export const WidgetSDK = forwardRef<WidgetSDKRef, WidgetSDKConfig>(
|
|
|
135
112
|
break;
|
|
136
113
|
|
|
137
114
|
case "widget:close":
|
|
138
|
-
|
|
115
|
+
onClose?.();
|
|
139
116
|
break;
|
|
140
117
|
|
|
141
118
|
case "widget:transaction-requested":
|
|
@@ -143,27 +120,19 @@ export const WidgetSDK = forwardRef<WidgetSDKRef, WidgetSDKConfig>(
|
|
|
143
120
|
break;
|
|
144
121
|
|
|
145
122
|
case "widget:token-expired":
|
|
146
|
-
logError("Access token expired");
|
|
147
123
|
onError?.("TOKEN_EXPIRED", "Access token has expired");
|
|
148
124
|
break;
|
|
149
125
|
|
|
150
126
|
case "widget:copy-to-clipboard":
|
|
151
127
|
handleCopyToClipboard(message as CopyToClipboardMessage);
|
|
152
128
|
break;
|
|
153
|
-
|
|
154
|
-
default:
|
|
155
|
-
logWarn("Unknown message type:", message);
|
|
156
129
|
}
|
|
157
|
-
} catch
|
|
158
|
-
logError("Failed to parse message:", error);
|
|
130
|
+
} catch {
|
|
159
131
|
onError?.("PARSE_ERROR", "Failed to parse widget message");
|
|
160
132
|
}
|
|
161
133
|
};
|
|
162
134
|
|
|
163
135
|
const handleReady = () => {
|
|
164
|
-
log("Widget ready");
|
|
165
|
-
onReady?.();
|
|
166
|
-
|
|
167
136
|
// Send platform info to widget
|
|
168
137
|
sendMessageToWidget({
|
|
169
138
|
type: "native:platform-info",
|
|
@@ -175,8 +144,6 @@ export const WidgetSDK = forwardRef<WidgetSDKRef, WidgetSDKConfig>(
|
|
|
175
144
|
};
|
|
176
145
|
|
|
177
146
|
const handleOpenWallet = async () => {
|
|
178
|
-
log("Opening native wallet...");
|
|
179
|
-
|
|
180
147
|
const success = await openNativeWallet();
|
|
181
148
|
|
|
182
149
|
// Notify widget of result
|
|
@@ -190,28 +157,16 @@ export const WidgetSDK = forwardRef<WidgetSDKRef, WidgetSDKConfig>(
|
|
|
190
157
|
if (message.type !== "widget:error") return;
|
|
191
158
|
|
|
192
159
|
const { code, message: errorMessage } = message.payload;
|
|
193
|
-
logError("Widget error:", code, errorMessage);
|
|
194
|
-
|
|
195
160
|
onError?.(code, errorMessage);
|
|
196
161
|
};
|
|
197
162
|
|
|
198
|
-
const handleClose = () => {
|
|
199
|
-
log("Widget closed");
|
|
200
|
-
onClose?.();
|
|
201
|
-
};
|
|
202
|
-
|
|
203
163
|
const handleTransactionRequested = (message: WidgetMessage) => {
|
|
204
164
|
if (message.type !== "widget:transaction-requested") return;
|
|
205
165
|
|
|
206
166
|
const { token, cryptoAmount, depositAddress, depositAddressTag } =
|
|
207
167
|
message.payload;
|
|
208
|
-
log("Transaction requested:", {
|
|
209
|
-
token: token.symbol,
|
|
210
|
-
cryptoAmount,
|
|
211
|
-
depositAddress,
|
|
212
|
-
});
|
|
213
168
|
|
|
214
|
-
onTransactionRequested
|
|
169
|
+
onTransactionRequested(
|
|
215
170
|
token,
|
|
216
171
|
cryptoAmount,
|
|
217
172
|
depositAddress,
|
|
@@ -221,12 +176,9 @@ export const WidgetSDK = forwardRef<WidgetSDKRef, WidgetSDKConfig>(
|
|
|
221
176
|
|
|
222
177
|
/**
|
|
223
178
|
* Handle clipboard copy request from widget
|
|
224
|
-
* Copies text to device clipboard and sends result back to widget
|
|
225
179
|
*/
|
|
226
180
|
const handleCopyToClipboard = async (message: CopyToClipboardMessage) => {
|
|
227
181
|
const { text, label } = message.payload;
|
|
228
|
-
// Log only the label, never the actual text content (security)
|
|
229
|
-
log("Copy to clipboard requested:", label || "unlabeled");
|
|
230
182
|
|
|
231
183
|
try {
|
|
232
184
|
await Clipboard.setStringAsync(text);
|
|
@@ -234,8 +186,7 @@ export const WidgetSDK = forwardRef<WidgetSDKRef, WidgetSDKConfig>(
|
|
|
234
186
|
type: "native:clipboard-result",
|
|
235
187
|
payload: { success: true, label },
|
|
236
188
|
});
|
|
237
|
-
} catch
|
|
238
|
-
logError("Clipboard copy failed:", error);
|
|
189
|
+
} catch {
|
|
239
190
|
sendMessageToWidget({
|
|
240
191
|
type: "native:clipboard-result",
|
|
241
192
|
payload: {
|
|
@@ -250,7 +201,7 @@ export const WidgetSDK = forwardRef<WidgetSDKRef, WidgetSDKConfig>(
|
|
|
250
201
|
/**
|
|
251
202
|
* Send message to the web widget
|
|
252
203
|
*/
|
|
253
|
-
const sendMessageToWidget = (message:
|
|
204
|
+
const sendMessageToWidget = (message: unknown) => {
|
|
254
205
|
const js = `
|
|
255
206
|
window.postMessage(${JSON.stringify(message)}, '*');
|
|
256
207
|
true;
|
|
@@ -263,17 +214,15 @@ export const WidgetSDK = forwardRef<WidgetSDKRef, WidgetSDKConfig>(
|
|
|
263
214
|
* Build the widget URL with query parameters
|
|
264
215
|
*/
|
|
265
216
|
const finalWidgetUrl = useMemo(() => {
|
|
266
|
-
const baseUrl = getWidgetUrl(
|
|
217
|
+
const baseUrl = getWidgetUrl(accessToken);
|
|
267
218
|
const params = new URLSearchParams({
|
|
268
|
-
token: accessToken,
|
|
219
|
+
token: stripTokenPrefix(accessToken),
|
|
269
220
|
platform: Platform.OS,
|
|
270
221
|
userWalletAddress: userWalletAddress,
|
|
271
222
|
});
|
|
272
223
|
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
return url;
|
|
276
|
-
}, [accessToken, userWalletAddress, environment]);
|
|
224
|
+
return `${baseUrl}?${params.toString()}`;
|
|
225
|
+
}, [accessToken, userWalletAddress]);
|
|
277
226
|
|
|
278
227
|
return (
|
|
279
228
|
<View style={styles.container}>
|
|
@@ -288,13 +237,11 @@ export const WidgetSDK = forwardRef<WidgetSDKRef, WidgetSDKConfig>(
|
|
|
288
237
|
setIsLoading(false);
|
|
289
238
|
}
|
|
290
239
|
}}
|
|
291
|
-
onError={(
|
|
292
|
-
const { nativeEvent } = syntheticEvent;
|
|
293
|
-
logError("WebView error:", nativeEvent);
|
|
240
|
+
onError={() => {
|
|
294
241
|
setIsLoading(false);
|
|
295
242
|
onError?.("WEBVIEW_ERROR", "Failed to load widget");
|
|
296
243
|
}}
|
|
297
|
-
//
|
|
244
|
+
// Allow external URLs to open in native apps
|
|
298
245
|
onShouldStartLoadWithRequest={(request) => {
|
|
299
246
|
const { url } = request;
|
|
300
247
|
|
|
@@ -305,10 +252,7 @@ export const WidgetSDK = forwardRef<WidgetSDKRef, WidgetSDKConfig>(
|
|
|
305
252
|
url.includes("wallet.google.com") ||
|
|
306
253
|
url.includes("wallet.apple.com")
|
|
307
254
|
) {
|
|
308
|
-
|
|
309
|
-
Linking.openURL(url).catch((err) => {
|
|
310
|
-
logError("Failed to open URL:", err);
|
|
311
|
-
});
|
|
255
|
+
Linking.openURL(url).catch(() => {});
|
|
312
256
|
return false; // Don't load in WebView
|
|
313
257
|
}
|
|
314
258
|
|
|
@@ -327,7 +271,7 @@ export const WidgetSDK = forwardRef<WidgetSDKRef, WidgetSDKConfig>(
|
|
|
327
271
|
/>
|
|
328
272
|
{isLoading && (
|
|
329
273
|
<View style={styles.loadingOverlay}>
|
|
330
|
-
<ActivityIndicator size="large" color=
|
|
274
|
+
<ActivityIndicator size="large" color="#007AFF" />
|
|
331
275
|
</View>
|
|
332
276
|
)}
|
|
333
277
|
</View>
|
package/src/config.ts
CHANGED
|
@@ -1,25 +1,51 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Widget SDK Configuration
|
|
3
|
-
* Environment
|
|
3
|
+
* Environment detection based on access token prefix
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Token prefixes that determine the environment
|
|
8
|
+
*/
|
|
9
|
+
const TOKEN_PREFIX = {
|
|
10
|
+
SANDBOX: "sbx_",
|
|
11
|
+
PRODUCTION: "prod_",
|
|
12
|
+
} as const;
|
|
7
13
|
|
|
8
14
|
/**
|
|
9
15
|
* Widget URLs by environment
|
|
10
16
|
*/
|
|
11
17
|
export const WIDGET_URLS = {
|
|
12
|
-
|
|
18
|
+
sandbox: "https://oobit-widget-dev.web.app",
|
|
13
19
|
production: "https://oobit-widget.web.app",
|
|
14
20
|
} as const;
|
|
15
21
|
|
|
16
22
|
/**
|
|
17
|
-
* Get the widget URL
|
|
18
|
-
* @param
|
|
19
|
-
* @returns The widget URL for the
|
|
23
|
+
* Get the widget URL based on the access token prefix
|
|
24
|
+
* @param accessToken - The access token (prefixed with sbx_ or prod_)
|
|
25
|
+
* @returns The widget URL for the corresponding environment
|
|
26
|
+
*/
|
|
27
|
+
export function getWidgetUrl(accessToken: string): string {
|
|
28
|
+
if (accessToken.startsWith(TOKEN_PREFIX.SANDBOX)) {
|
|
29
|
+
return WIDGET_URLS.sandbox;
|
|
30
|
+
}
|
|
31
|
+
if (accessToken.startsWith(TOKEN_PREFIX.PRODUCTION)) {
|
|
32
|
+
return WIDGET_URLS.production;
|
|
33
|
+
}
|
|
34
|
+
// Default to production for backwards compatibility
|
|
35
|
+
return WIDGET_URLS.production;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Strip the environment prefix from an access token
|
|
40
|
+
* @param accessToken - The access token (prefixed with sbx_ or prod_)
|
|
41
|
+
* @returns The token without the environment prefix
|
|
20
42
|
*/
|
|
21
|
-
export function
|
|
22
|
-
|
|
23
|
-
)
|
|
24
|
-
|
|
43
|
+
export function stripTokenPrefix(accessToken: string): string {
|
|
44
|
+
if (accessToken.startsWith(TOKEN_PREFIX.SANDBOX)) {
|
|
45
|
+
return accessToken.slice(TOKEN_PREFIX.SANDBOX.length);
|
|
46
|
+
}
|
|
47
|
+
if (accessToken.startsWith(TOKEN_PREFIX.PRODUCTION)) {
|
|
48
|
+
return accessToken.slice(TOKEN_PREFIX.PRODUCTION.length);
|
|
49
|
+
}
|
|
50
|
+
return accessToken;
|
|
25
51
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,45 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Widget SDK - Public API
|
|
3
|
-
* Export all public components, types, and utilities
|
|
4
3
|
*/
|
|
5
4
|
|
|
6
5
|
export { WidgetSDK } from "./WidgetSDK";
|
|
7
6
|
export type { WidgetSDKRef } from "./WidgetSDK";
|
|
8
7
|
|
|
9
|
-
// Export all message types for clients to use
|
|
10
8
|
export type {
|
|
11
|
-
BaseWidgetMessage,
|
|
12
|
-
CopyToClipboardMessage,
|
|
13
9
|
DepositToken,
|
|
14
|
-
NativeBackPressedMessage,
|
|
15
|
-
NativeBiometricFailedMessage,
|
|
16
|
-
NativeCardDetailsSessionMessage,
|
|
17
|
-
NativeMessage,
|
|
18
|
-
// Native → Widget message types
|
|
19
|
-
NativeMessageType,
|
|
20
|
-
NativeNavigateBackMessage,
|
|
21
|
-
NativePlatformInfoMessage,
|
|
22
|
-
NativeWalletOpenedMessage,
|
|
23
|
-
OpenWalletMessage,
|
|
24
|
-
RequestCardDetailsSessionMessage,
|
|
25
|
-
// Error codes
|
|
26
10
|
SDKErrorCode,
|
|
27
|
-
TokenExpiredMessage,
|
|
28
|
-
TransactionRequestedMessage,
|
|
29
|
-
WidgetCloseMessage,
|
|
30
|
-
WidgetEnvironment,
|
|
31
|
-
WidgetErrorMessage,
|
|
32
|
-
WidgetMessage,
|
|
33
|
-
// Widget → Native message types
|
|
34
|
-
WidgetMessageType,
|
|
35
|
-
WidgetReadyMessage,
|
|
36
|
-
// Configuration
|
|
37
11
|
WidgetSDKConfig,
|
|
38
12
|
} from "./types";
|
|
39
|
-
|
|
40
|
-
// Export constants
|
|
41
|
-
export { getWidgetUrl, WIDGET_URLS } from "./config";
|
|
42
|
-
export { MessageTypes, WALLET_URLS } from "./types";
|
|
43
|
-
|
|
44
|
-
// Export wallet utilities
|
|
45
|
-
export { isWalletAvailable, openNativeWallet } from "./walletUtils";
|
package/src/types.ts
CHANGED
|
@@ -166,13 +166,6 @@ export type WidgetMessage =
|
|
|
166
166
|
| RequestCardDetailsSessionMessage
|
|
167
167
|
| CopyToClipboardMessage;
|
|
168
168
|
|
|
169
|
-
/**
|
|
170
|
-
* Widget environment configuration
|
|
171
|
-
* - 'development': Uses development/staging widget URL
|
|
172
|
-
* - 'production': Uses production widget URL
|
|
173
|
-
*/
|
|
174
|
-
export type WidgetEnvironment = "development" | "production";
|
|
175
|
-
|
|
176
169
|
/**
|
|
177
170
|
* Known SDK error codes
|
|
178
171
|
* - TOKEN_EXPIRED: The access token has expired
|
|
@@ -185,23 +178,10 @@ export type SDKErrorCode = "TOKEN_EXPIRED" | "PARSE_ERROR" | "WEBVIEW_ERROR";
|
|
|
185
178
|
* SDK Configuration
|
|
186
179
|
*/
|
|
187
180
|
export interface WidgetSDKConfig {
|
|
188
|
-
accessToken: string; // Required: Access token from backend
|
|
181
|
+
accessToken: string; // Required: Access token from backend (prefixed with sbx_ or prod_)
|
|
189
182
|
userWalletAddress: string; // Required: User's external wallet address for crypto deposits
|
|
190
|
-
/**
|
|
191
|
-
* Widget environment to use.
|
|
192
|
-
* - 'development': Uses https://oobit-widget-dev.web.app
|
|
193
|
-
* - 'production': Uses https://widget.oobit.com
|
|
194
|
-
* @default 'production'
|
|
195
|
-
*/
|
|
196
|
-
environment?: WidgetEnvironment;
|
|
197
|
-
/**
|
|
198
|
-
* Called when the widget is ready and loaded
|
|
199
|
-
*/
|
|
200
|
-
onReady?: () => void;
|
|
201
183
|
/**
|
|
202
184
|
* Called when an error occurs
|
|
203
|
-
* @param code - Error code (SDKErrorCode or custom widget error code)
|
|
204
|
-
* @param message - Human-readable error message
|
|
205
185
|
*/
|
|
206
186
|
onError?: (code: SDKErrorCode | string, message: string) => void;
|
|
207
187
|
/**
|
|
@@ -211,27 +191,12 @@ export interface WidgetSDKConfig {
|
|
|
211
191
|
/**
|
|
212
192
|
* Called when a crypto transaction is requested
|
|
213
193
|
*/
|
|
214
|
-
onTransactionRequested
|
|
194
|
+
onTransactionRequested: (
|
|
215
195
|
token: DepositToken,
|
|
216
196
|
cryptoAmount: string,
|
|
217
197
|
depositAddress: string,
|
|
218
198
|
depositAddressTag: string | null
|
|
219
199
|
) => void;
|
|
220
|
-
/**
|
|
221
|
-
* Called when the loading state changes
|
|
222
|
-
* @param isLoading - Whether the widget is currently loading
|
|
223
|
-
*/
|
|
224
|
-
onLoadingChange?: (isLoading: boolean) => void;
|
|
225
|
-
/**
|
|
226
|
-
* Enable debug logging to console
|
|
227
|
-
* @default false
|
|
228
|
-
*/
|
|
229
|
-
debug?: boolean;
|
|
230
|
-
/**
|
|
231
|
-
* Custom color for the loading indicator
|
|
232
|
-
* @default "#007AFF"
|
|
233
|
-
*/
|
|
234
|
-
loadingIndicatorColor?: string;
|
|
235
200
|
}
|
|
236
201
|
|
|
237
202
|
/**
|