@trustware/sdk-staging 1.0.17-staging.14 → 1.0.17-staging.17
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 +200 -251
- package/dist/constants.cjs +1 -1
- package/dist/constants.mjs +1 -1
- package/dist/core-DRDMS5t3.d.ts +435 -0
- package/dist/core-DXxIIFgy.d.cts +435 -0
- package/dist/core.cjs +3107 -0
- package/dist/core.cjs.map +1 -0
- package/dist/core.d.cts +3 -0
- package/dist/core.d.ts +3 -0
- package/dist/core.mjs +3087 -0
- package/dist/core.mjs.map +1 -0
- package/dist/detect-BI5qLt5s.d.cts +34 -0
- package/dist/detect-GUvqS-mr.d.ts +34 -0
- package/dist/index.cjs +5509 -5571
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -844
- package/dist/index.d.ts +9 -844
- package/dist/index.mjs +5478 -5554
- package/dist/index.mjs.map +1 -1
- package/dist/manager-CgpuAzqn.d.cts +306 -0
- package/dist/manager-CgpuAzqn.d.ts +306 -0
- package/dist/types-BrVfNxND.d.cts +14 -0
- package/dist/types-BrVfNxND.d.ts +14 -0
- package/dist/wallet.cjs +2161 -0
- package/dist/wallet.cjs.map +1 -0
- package/dist/wallet.d.cts +37 -0
- package/dist/wallet.d.ts +37 -0
- package/dist/wallet.mjs +2117 -0
- package/dist/wallet.mjs.map +1 -0
- package/dist/widget.cjs +13388 -0
- package/dist/widget.cjs.map +1 -0
- package/dist/widget.d.cts +66 -0
- package/dist/widget.d.ts +66 -0
- package/dist/widget.mjs +13377 -0
- package/dist/widget.mjs.map +1 -0
- package/package.json +3 -1
package/README.md
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
# Trustware SDK
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Trustware SDK gives you three integration styles on top of the same routing and wallet infrastructure:
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
- a prebuilt React widget for the full deposit flow
|
|
6
|
+
- a provider + host wallet bridge for apps that already manage wallet state
|
|
7
|
+
- a headless core API for custom UIs
|
|
8
|
+
|
|
9
|
+
The current widget flow is:
|
|
10
|
+
|
|
11
|
+
`Home -> Select Token -> Confirm Deposit -> Processing -> Success/Error`
|
|
12
|
+
|
|
13
|
+
The refactored widget keeps the same behavior, but the configuration surface is now documented around the actual `TrustwareConfigOptions` shape and the current widget step model.
|
|
6
14
|
|
|
7
15
|
## Installation
|
|
8
16
|
|
|
@@ -12,79 +20,117 @@ npm install @trustware/sdk
|
|
|
12
20
|
pnpm add @trustware/sdk
|
|
13
21
|
```
|
|
14
22
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
## Core Concepts
|
|
23
|
+
## Main Exports
|
|
18
24
|
|
|
19
|
-
-
|
|
20
|
-
-
|
|
21
|
-
-
|
|
22
|
-
-
|
|
25
|
+
- `TrustwareProvider`
|
|
26
|
+
- `TrustwareWidget`
|
|
27
|
+
- `Trustware`
|
|
28
|
+
- `useTrustware`
|
|
23
29
|
|
|
24
|
-
##
|
|
30
|
+
## Quick Start
|
|
25
31
|
|
|
26
|
-
|
|
32
|
+
```tsx
|
|
33
|
+
import {
|
|
34
|
+
TrustwareProvider,
|
|
35
|
+
TrustwareWidget,
|
|
36
|
+
type TrustwareConfigOptions,
|
|
37
|
+
} from "@trustware/sdk";
|
|
27
38
|
|
|
28
|
-
```ts
|
|
29
39
|
const trustwareConfig = {
|
|
30
40
|
apiKey: process.env.NEXT_PUBLIC_TRUSTWARE_API_KEY!,
|
|
31
41
|
routes: {
|
|
32
|
-
toChain: "8453",
|
|
33
|
-
toToken: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
|
|
42
|
+
toChain: "8453",
|
|
43
|
+
toToken: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
|
|
34
44
|
defaultSlippage: 1,
|
|
35
|
-
// Optional defaults:
|
|
36
|
-
// fromAddress: "0x...", // User's wallet address
|
|
37
|
-
// toAddress: "0x...", // Destination; can be set later via Trustware.setDestinationAddress
|
|
38
45
|
options: {
|
|
39
|
-
|
|
40
|
-
// minAmountOut: "1.00", // USD minimum
|
|
41
|
-
// maxAmountOut: "100.00", // USD maximum
|
|
42
|
-
// routeRefreshMs: 15000, // auto-refresh route quotes
|
|
46
|
+
routeRefreshMs: 15000,
|
|
43
47
|
},
|
|
44
48
|
},
|
|
45
|
-
autoDetectProvider: true,
|
|
46
|
-
theme: {
|
|
47
|
-
primaryColor: "#FCB514",
|
|
48
|
-
secondaryColor: "#FFFFFF",
|
|
49
|
-
backgroundColor: "#000000",
|
|
50
|
-
borderColor: "#FCB514",
|
|
51
|
-
textColor: "#FFFFFF",
|
|
52
|
-
radius: 16,
|
|
53
|
-
},
|
|
49
|
+
autoDetectProvider: true,
|
|
54
50
|
messages: {
|
|
55
|
-
title: "
|
|
56
|
-
description: "
|
|
57
|
-
},
|
|
58
|
-
onError: (error) => {
|
|
59
|
-
console.error("Trustware error:", error);
|
|
60
|
-
},
|
|
61
|
-
onSuccess: (tx) => {
|
|
62
|
-
console.log("Trustware success:", tx);
|
|
63
|
-
},
|
|
64
|
-
onEvent: (event) => {
|
|
65
|
-
// Optional: listen to all SDK events
|
|
66
|
-
console.log("Trustware event:", event);
|
|
51
|
+
title: "Deposit",
|
|
52
|
+
description: "Move funds into the destination asset and chain.",
|
|
67
53
|
},
|
|
68
54
|
} satisfies TrustwareConfigOptions;
|
|
55
|
+
|
|
56
|
+
export function App() {
|
|
57
|
+
return (
|
|
58
|
+
<TrustwareProvider config={trustwareConfig}>
|
|
59
|
+
<TrustwareWidget />
|
|
60
|
+
</TrustwareProvider>
|
|
61
|
+
);
|
|
62
|
+
}
|
|
69
63
|
```
|
|
70
64
|
|
|
71
|
-
|
|
65
|
+
## Config Reference
|
|
66
|
+
|
|
67
|
+
`TrustwareConfigOptions` is the single source of truth. The current supported shape is:
|
|
72
68
|
|
|
73
69
|
```ts
|
|
74
|
-
|
|
75
|
-
|
|
70
|
+
type TrustwareConfigOptions = {
|
|
71
|
+
apiKey: string;
|
|
72
|
+
routes: {
|
|
73
|
+
toChain: string;
|
|
74
|
+
toToken: string;
|
|
75
|
+
fromToken?: string;
|
|
76
|
+
fromAddress?: string;
|
|
77
|
+
toAddress?: string;
|
|
78
|
+
defaultSlippage?: number;
|
|
79
|
+
routeType?: string;
|
|
80
|
+
options?: {
|
|
81
|
+
routeRefreshMs?: number;
|
|
82
|
+
fixedFromAmount?: string | number;
|
|
83
|
+
minAmountOut?: string | number;
|
|
84
|
+
maxAmountOut?: string | number;
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
autoDetectProvider?: boolean;
|
|
88
|
+
theme?: TrustwareWidgetTheme;
|
|
89
|
+
messages?: Partial<TrustwareWidgetMessages>;
|
|
90
|
+
retry?: RetryConfig;
|
|
91
|
+
walletConnect?: WalletConnectConfig;
|
|
92
|
+
onError?: (error: TrustwareError) => void;
|
|
93
|
+
onSuccess?: (transaction: Transaction) => void;
|
|
94
|
+
onEvent?: (event: TrustwareEvent) => void;
|
|
95
|
+
};
|
|
76
96
|
```
|
|
77
97
|
|
|
78
|
-
|
|
98
|
+
### Route Fields
|
|
99
|
+
|
|
100
|
+
- `routes.toChain`: destination chain key or chain id string.
|
|
101
|
+
- `routes.toToken`: destination token address or registry token identifier.
|
|
102
|
+
- `routes.fromToken`: optional source token preference.
|
|
103
|
+
- `routes.fromAddress`: optional source wallet override.
|
|
104
|
+
- `routes.toAddress`: optional destination address override.
|
|
105
|
+
- `routes.defaultSlippage`: optional slippage percentage. Defaults to `1`.
|
|
106
|
+
- `routes.routeType`: optional route flavor. Defaults to `"swap"`.
|
|
107
|
+
|
|
108
|
+
### Route Options
|
|
109
|
+
|
|
110
|
+
- `routes.options.routeRefreshMs`: auto-refresh cadence for route previews.
|
|
111
|
+
- `routes.options.fixedFromAmount`: locks the widget amount input to a fixed USD amount.
|
|
112
|
+
- `routes.options.minAmountOut`: minimum allowed USD amount.
|
|
113
|
+
- `routes.options.maxAmountOut`: maximum allowed USD amount.
|
|
114
|
+
|
|
115
|
+
### Other Config Groups
|
|
116
|
+
|
|
117
|
+
- `autoDetectProvider`: enables Trustware-managed wallet discovery.
|
|
118
|
+
- `theme`: widget color and radius customization.
|
|
119
|
+
- `messages`: top-level copy overrides.
|
|
120
|
+
- `retry`: API retry and rate-limit behavior.
|
|
121
|
+
- `walletConnect`: WalletConnect overrides.
|
|
122
|
+
- `onError`, `onSuccess`, `onEvent`: lifecycle callbacks.
|
|
79
123
|
|
|
80
|
-
|
|
124
|
+
## Widget Usage Patterns
|
|
81
125
|
|
|
82
|
-
|
|
126
|
+
### 1. Drop-In Widget With Trustware-Managed Wallet Detection
|
|
127
|
+
|
|
128
|
+
Use this when your app does not already manage a connected wallet.
|
|
83
129
|
|
|
84
130
|
```tsx
|
|
85
131
|
import { TrustwareProvider, TrustwareWidget } from "@trustware/sdk";
|
|
86
132
|
|
|
87
|
-
export function
|
|
133
|
+
export function DepositPanel() {
|
|
88
134
|
return (
|
|
89
135
|
<TrustwareProvider config={trustwareConfig}>
|
|
90
136
|
<TrustwareWidget />
|
|
@@ -93,272 +139,175 @@ export function App() {
|
|
|
93
139
|
}
|
|
94
140
|
```
|
|
95
141
|
|
|
96
|
-
|
|
97
|
-
- Call `Trustware.setDestinationAddress(address)` dynamically if the `toAddress` is determined at runtime (e.g., after smart wallet generation).
|
|
142
|
+
Use this mode when:
|
|
98
143
|
|
|
99
|
-
|
|
144
|
+
- you want the built-in wallet selection flow
|
|
145
|
+
- you want the full hosted deposit UX
|
|
146
|
+
- `autoDetectProvider` should stay enabled
|
|
100
147
|
|
|
101
|
-
|
|
148
|
+
### 2. Widget With a Host-Managed Wallet
|
|
149
|
+
|
|
150
|
+
Use this when your app already controls wallet connection through Wagmi, Viem, or another adapter.
|
|
102
151
|
|
|
103
152
|
```tsx
|
|
104
|
-
import {
|
|
153
|
+
import { useMemo } from "react";
|
|
105
154
|
import { useWalletClient } from "wagmi";
|
|
106
|
-
import { TrustwareProvider, TrustwareWidget
|
|
107
|
-
import { useWagmi } from "@trustware/sdk/wallet";
|
|
155
|
+
import { TrustwareProvider, TrustwareWidget } from "@trustware/sdk";
|
|
156
|
+
import { useWagmi } from "@trustware/sdk/wallet";
|
|
108
157
|
|
|
109
|
-
export function
|
|
110
|
-
const { data:
|
|
158
|
+
export function DepositPanel() {
|
|
159
|
+
const { data: walletClient } = useWalletClient();
|
|
111
160
|
const wallet = useMemo(
|
|
112
|
-
() => (
|
|
113
|
-
[
|
|
161
|
+
() => (walletClient ? useWagmi(walletClient) : undefined),
|
|
162
|
+
[walletClient]
|
|
114
163
|
);
|
|
115
164
|
|
|
116
|
-
useEffect(() => {
|
|
117
|
-
if (!wallet) return;
|
|
118
|
-
Trustware.setDestinationAddress("0xDestination...");
|
|
119
|
-
}, [wallet]);
|
|
120
|
-
|
|
121
165
|
return (
|
|
122
166
|
<TrustwareProvider
|
|
123
167
|
config={trustwareConfig}
|
|
124
168
|
wallet={wallet}
|
|
125
|
-
autoDetect={false}
|
|
169
|
+
autoDetect={false}
|
|
126
170
|
>
|
|
127
|
-
<TrustwareWidget />
|
|
171
|
+
<TrustwareWidget />
|
|
128
172
|
</TrustwareProvider>
|
|
129
173
|
);
|
|
130
174
|
}
|
|
131
175
|
```
|
|
132
176
|
|
|
133
|
-
|
|
134
|
-
- Attach imperatively post-mount: `Trustware.useWallet(wallet)`.
|
|
135
|
-
- Bridge example for Wagmi:
|
|
136
|
-
|
|
137
|
-
```ts
|
|
138
|
-
import { useEffect } from "react";
|
|
139
|
-
import { useWalletClient } from "wagmi";
|
|
140
|
-
import { useWagmi } from "@trustware/sdk/wallet";
|
|
141
|
-
import { Trustware } from "@trustware/sdk";
|
|
142
|
-
|
|
143
|
-
export function useTrustwareWalletBridge() {
|
|
144
|
-
const { data } = useWalletClient();
|
|
145
|
-
|
|
146
|
-
useEffect(() => {
|
|
147
|
-
if (!data) return;
|
|
148
|
-
const wallet = useWagmi(data);
|
|
149
|
-
Trustware.useWallet(wallet);
|
|
150
|
-
}, [data]);
|
|
151
|
-
}
|
|
152
|
-
```
|
|
177
|
+
Use this mode when:
|
|
153
178
|
|
|
154
|
-
|
|
179
|
+
- your app already owns wallet state
|
|
180
|
+
- you do not want the SDK to pick another provider
|
|
181
|
+
- you want the widget UX but not the widget’s wallet discovery responsibilities
|
|
155
182
|
|
|
156
|
-
|
|
183
|
+
### 3. Controlled Widget Shell
|
|
157
184
|
|
|
158
|
-
|
|
159
|
-
- For dynamic `toAddress`: Call `Trustware.setDestinationAddress` before render.
|
|
185
|
+
`TrustwareWidget` also supports basic shell control through props and a ref.
|
|
160
186
|
|
|
161
|
-
|
|
187
|
+
```tsx
|
|
188
|
+
import { useRef } from "react";
|
|
189
|
+
import {
|
|
190
|
+
TrustwareProvider,
|
|
191
|
+
TrustwareWidget,
|
|
192
|
+
type TrustwareWidgetRef,
|
|
193
|
+
} from "@trustware/sdk";
|
|
162
194
|
|
|
163
|
-
|
|
195
|
+
export function ControlledWidget() {
|
|
196
|
+
const widgetRef = useRef<TrustwareWidgetRef>(null);
|
|
164
197
|
|
|
165
|
-
|
|
166
|
-
|
|
198
|
+
return (
|
|
199
|
+
<TrustwareProvider config={trustwareConfig}>
|
|
200
|
+
<button onClick={() => widgetRef.current?.open()}>Open</button>
|
|
201
|
+
<TrustwareWidget
|
|
202
|
+
ref={widgetRef}
|
|
203
|
+
defaultOpen={false}
|
|
204
|
+
initialStep="home"
|
|
205
|
+
showThemeToggle={false}
|
|
206
|
+
onOpen={() => console.log("opened")}
|
|
207
|
+
onClose={() => console.log("closed")}
|
|
208
|
+
/>
|
|
209
|
+
</TrustwareProvider>
|
|
210
|
+
);
|
|
211
|
+
}
|
|
167
212
|
```
|
|
168
213
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
### Wallet Detection and Management
|
|
214
|
+
Current widget props:
|
|
172
215
|
|
|
173
|
-
- `
|
|
174
|
-
- `
|
|
175
|
-
- `
|
|
216
|
+
- `theme?: "light" | "dark" | "system"`
|
|
217
|
+
- `initialStep?: "home" | "select-token" | "crypto-pay" | "processing" | "success" | "error"`
|
|
218
|
+
- `defaultOpen?: boolean`
|
|
219
|
+
- `onOpen?: () => void`
|
|
220
|
+
- `onClose?: () => void`
|
|
221
|
+
- `showThemeToggle?: boolean`
|
|
176
222
|
|
|
177
|
-
###
|
|
223
|
+
### 4. Headless Core API
|
|
178
224
|
|
|
179
|
-
|
|
225
|
+
Use this when you want Trustware’s routing and wallet plumbing without the widget UI.
|
|
180
226
|
|
|
181
227
|
```ts
|
|
182
|
-
|
|
183
|
-
const fromAddress = await Trustware.getAddress();
|
|
228
|
+
import { Trustware } from "@trustware/sdk";
|
|
184
229
|
|
|
185
230
|
const route = await Trustware.buildRoute({
|
|
186
|
-
amount: "0.1",
|
|
187
|
-
fromAddress,
|
|
188
|
-
toAddress: cfg.routes.toAddress ?? fromAddress, // Fallbacks applied
|
|
231
|
+
amount: "0.1",
|
|
232
|
+
fromAddress: await Trustware.getAddress(),
|
|
189
233
|
});
|
|
190
234
|
|
|
191
235
|
const quote = await Trustware.getQuote(route);
|
|
192
|
-
console.log(quote.expectedAmountOut);
|
|
193
|
-
```
|
|
194
|
-
|
|
195
|
-
- `amount`: Denominated in `fromToken` (defaults to native).
|
|
196
|
-
- Fallbacks: `fromAddress` → connected wallet; `toAddress` → config → `fromAddress`.
|
|
197
|
-
|
|
198
|
-
### Running a Top-up
|
|
199
236
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
const result = await Trustware.runTopUp({
|
|
205
|
-
amount: "0.25",
|
|
206
|
-
fromAddress: await Trustware.getAddress(),
|
|
207
|
-
toAddress: "0xDestination...", // Optional; uses config fallbacks
|
|
208
|
-
});
|
|
209
|
-
|
|
210
|
-
console.log("Top-up confirmed", result.txHash);
|
|
211
|
-
} catch (err) {
|
|
212
|
-
console.error("Top-up failed", err);
|
|
213
|
-
}
|
|
237
|
+
const result = await Trustware.runTopUp({
|
|
238
|
+
amount: "0.1",
|
|
239
|
+
fromAddress: await Trustware.getAddress(),
|
|
240
|
+
});
|
|
214
241
|
```
|
|
215
242
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
### Lifecycle Events
|
|
243
|
+
## Common Config Examples
|
|
219
244
|
|
|
220
|
-
|
|
245
|
+
### Fixed Amount Deposit
|
|
221
246
|
|
|
222
247
|
```ts
|
|
223
|
-
const
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
248
|
+
const fixedAmountConfig = {
|
|
249
|
+
...trustwareConfig,
|
|
250
|
+
routes: {
|
|
251
|
+
...trustwareConfig.routes,
|
|
252
|
+
options: {
|
|
253
|
+
fixedFromAmount: "25",
|
|
254
|
+
},
|
|
255
|
+
},
|
|
256
|
+
} satisfies TrustwareConfigOptions;
|
|
229
257
|
```
|
|
230
258
|
|
|
231
|
-
|
|
232
|
-
- `status`: High-level updates.
|
|
233
|
-
- `quote`: Latest quote.
|
|
234
|
-
- `error`: Thrown errors (e.g., approval/bridge failures).
|
|
235
|
-
|
|
236
|
-
## Additional Utilities
|
|
237
|
-
|
|
238
|
-
- `Trustware.setDestinationAddress(address)`: Updates runtime `toAddress`.
|
|
239
|
-
- `Trustware.getConfig()`: Resolved config.
|
|
240
|
-
- Hooks: `useTrustware()`, `useTrustwareRoute()` for advanced React flows.
|
|
241
|
-
- Explore `src/core` for types on balances, tokens, chain metadata.
|
|
242
|
-
|
|
243
|
-
## Error Handling Tips
|
|
244
|
-
|
|
245
|
-
- Surface actionable errors from `runTopUp` or `error` events (e.g., network/approval issues).
|
|
246
|
-
- Add retry logic for transients.
|
|
247
|
-
- Guard calls: Ensure provider mounted and wallet connected.
|
|
248
|
-
|
|
249
|
-
## Rate Limiting
|
|
250
|
-
|
|
251
|
-
The SDK automatically handles API rate limits with retry logic. The backend enforces per-API-key limits and returns standard rate limit headers.
|
|
252
|
-
|
|
253
|
-
### Default Behavior
|
|
254
|
-
|
|
255
|
-
Rate limiting is **enabled by default**. When a 429 (Too Many Requests) response is received:
|
|
256
|
-
1. The SDK waits for the time specified in the `Retry-After` header
|
|
257
|
-
2. Automatically retries the request (up to 3 times by default)
|
|
258
|
-
3. Uses exponential backoff if `Retry-After` is not provided
|
|
259
|
-
|
|
260
|
-
### Configuration
|
|
261
|
-
|
|
262
|
-
Customize rate limit handling in your config:
|
|
259
|
+
### Min / Max Guardrails
|
|
263
260
|
|
|
264
261
|
```ts
|
|
265
|
-
const
|
|
266
|
-
|
|
267
|
-
routes: {
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
baseDelayMs: 1000, // Base delay for exponential backoff (default: 1000)
|
|
274
|
-
approachingThreshold: 5, // Trigger warning when remaining < threshold (default: 5)
|
|
275
|
-
|
|
276
|
-
// Callbacks for monitoring
|
|
277
|
-
onRateLimitInfo: (info) => {
|
|
278
|
-
console.log(`${info.remaining}/${info.limit} requests remaining`);
|
|
279
|
-
},
|
|
280
|
-
onRateLimited: (info, retryCount) => {
|
|
281
|
-
console.warn(`Rate limited! Retry ${retryCount}, waiting ${info.retryAfter}s`);
|
|
282
|
-
},
|
|
283
|
-
onRateLimitApproaching: (info, threshold) => {
|
|
284
|
-
console.warn(`Approaching limit: ${info.remaining} remaining`);
|
|
262
|
+
const guardedConfig = {
|
|
263
|
+
...trustwareConfig,
|
|
264
|
+
routes: {
|
|
265
|
+
...trustwareConfig.routes,
|
|
266
|
+
options: {
|
|
267
|
+
minAmountOut: "10",
|
|
268
|
+
maxAmountOut: "250",
|
|
269
|
+
routeRefreshMs: 10000,
|
|
285
270
|
},
|
|
286
271
|
},
|
|
287
|
-
};
|
|
272
|
+
} satisfies TrustwareConfigOptions;
|
|
288
273
|
```
|
|
289
274
|
|
|
290
|
-
###
|
|
291
|
-
|
|
292
|
-
The `RateLimitInfo` object contains:
|
|
275
|
+
### Runtime Destination Address
|
|
293
276
|
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
| `limit` | number | Maximum requests allowed in the window |
|
|
297
|
-
| `remaining` | number | Requests remaining in current window |
|
|
298
|
-
| `reset` | number | Unix timestamp when window resets |
|
|
299
|
-
| `retryAfter` | number? | Seconds to wait (only on 429) |
|
|
277
|
+
```ts
|
|
278
|
+
import { Trustware } from "@trustware/sdk";
|
|
300
279
|
|
|
301
|
-
|
|
280
|
+
Trustware.setDestinationAddress("0xDestination...");
|
|
281
|
+
```
|
|
302
282
|
|
|
303
|
-
|
|
283
|
+
## Headless / Core Notes
|
|
304
284
|
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
await Trustware.buildRoute({ ... });
|
|
310
|
-
} catch (err) {
|
|
311
|
-
if (err instanceof RateLimitError) {
|
|
312
|
-
console.error(`Rate limited: ${err.message}`);
|
|
313
|
-
console.log(`Try again in ${err.rateLimitInfo.retryAfter}s`);
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
```
|
|
285
|
+
- `Trustware.getConfig()` returns the resolved config.
|
|
286
|
+
- `Trustware.getWallet()` and `Trustware.getAddress()` expose the active wallet.
|
|
287
|
+
- `Trustware.useWallet(wallet)` attaches a wallet imperatively.
|
|
288
|
+
- `Trustware.autoDetect()` can still be used if you want SDK-managed discovery outside the widget.
|
|
317
289
|
|
|
318
|
-
|
|
290
|
+
## Rate Limiting
|
|
319
291
|
|
|
320
|
-
|
|
292
|
+
Client retry behavior is configured through `retry`.
|
|
321
293
|
|
|
322
294
|
```ts
|
|
323
295
|
const config = {
|
|
324
|
-
|
|
296
|
+
...trustwareConfig,
|
|
325
297
|
retry: {
|
|
326
|
-
autoRetry:
|
|
327
|
-
|
|
298
|
+
autoRetry: true,
|
|
299
|
+
maxRetries: 3,
|
|
300
|
+
baseDelayMs: 1000,
|
|
301
|
+
approachingThreshold: 5,
|
|
328
302
|
},
|
|
329
|
-
};
|
|
303
|
+
} satisfies TrustwareConfigOptions;
|
|
330
304
|
```
|
|
331
305
|
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
The SDK is optimized for minimal bundle impact:
|
|
335
|
-
|
|
336
|
-
| Bundle | Gzipped Size |
|
|
337
|
-
|--------|--------------|
|
|
338
|
-
| Full SDK (ESM) | ~49 KB |
|
|
339
|
-
| CSS Styles | ~5 KB |
|
|
340
|
-
| **Total** | **~54 KB** |
|
|
341
|
-
|
|
342
|
-
*Sizes exclude React peer dependency*
|
|
343
|
-
|
|
344
|
-
Key optimizations:
|
|
345
|
-
- Tree-shaking enabled via ES modules
|
|
346
|
-
- ConfettiEffect lazy-loaded (only imported on success page)
|
|
347
|
-
- Minimal Radix UI usage (only react-dialog)
|
|
348
|
-
- CSS scoped with `tw-` prefix to avoid conflicts
|
|
349
|
-
|
|
350
|
-
Run `npm run size` to check current bundle sizes.
|
|
351
|
-
|
|
352
|
-
## Troubleshooting
|
|
353
|
-
|
|
354
|
-
- Mount `TrustwareProvider` once at app root.
|
|
355
|
-
- For host wallets: Inject only after connection.
|
|
356
|
-
- SSR/Next.js: Use `"use client";` for SDK-touching components.
|
|
357
|
-
- No wallet? Enable `autoDetectProvider` or inject manually.
|
|
306
|
+
If retries are exhausted, the SDK throws `RateLimitError`.
|
|
358
307
|
|
|
359
|
-
##
|
|
308
|
+
## Docs
|
|
360
309
|
|
|
361
|
-
-
|
|
362
|
-
- Source: Explore `sdk/src` for implementation details.
|
|
310
|
+
- [Integration Guide](docs/intergrationGuide.md)
|
|
363
311
|
- [Core Guide](docs/coreGuide.md)
|
|
364
|
-
- [
|
|
312
|
+
- [Widget Architecture Boundaries](docs/widget-architecture-boundaries.md)
|
|
313
|
+
- [Widget Refactor Baseline](docs/widget-refactor-baseline.md)
|
package/dist/constants.cjs
CHANGED
|
@@ -29,7 +29,7 @@ __export(constants_exports, {
|
|
|
29
29
|
});
|
|
30
30
|
module.exports = __toCommonJS(constants_exports);
|
|
31
31
|
var SDK_NAME = "@trustware/sdk";
|
|
32
|
-
var SDK_VERSION = "1.0.17-staging.
|
|
32
|
+
var SDK_VERSION = "1.0.17-staging.17";
|
|
33
33
|
var API_ROOT = "https://bv-staging-api.trustware.io";
|
|
34
34
|
var API_PREFIX = "/api";
|
|
35
35
|
var ASSETS_BASE_URL = "https://app.trustware.io";
|
package/dist/constants.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/constants.ts
|
|
2
2
|
var SDK_NAME = "@trustware/sdk";
|
|
3
|
-
var SDK_VERSION = "1.0.17-staging.
|
|
3
|
+
var SDK_VERSION = "1.0.17-staging.17";
|
|
4
4
|
var API_ROOT = "https://bv-staging-api.trustware.io";
|
|
5
5
|
var API_PREFIX = "/api";
|
|
6
6
|
var ASSETS_BASE_URL = "https://app.trustware.io";
|