@trustware/sdk-staging 1.0.17-staging.15 → 1.1.3-staging.20
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 +203 -251
- package/dist/constants.cjs +1 -1
- package/dist/constants.mjs +1 -1
- package/dist/{core-DXxIIFgy.d.cts → core-B0-MyOv6.d.cts} +44 -8
- package/dist/{core-DRDMS5t3.d.ts → core-qSEzIBWs.d.ts} +44 -8
- package/dist/core.cjs +610 -138
- package/dist/core.cjs.map +1 -1
- package/dist/core.d.cts +2 -2
- package/dist/core.d.ts +2 -2
- package/dist/core.mjs +611 -139
- package/dist/core.mjs.map +1 -1
- package/dist/{detect-GUvqS-mr.d.ts → detect-BS03Cycm.d.ts} +1 -1
- package/dist/{detect-BI5qLt5s.d.cts → detect-DxT7Xlae.d.cts} +1 -1
- package/dist/index.cjs +1159 -494
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.mjs +973 -309
- package/dist/index.mjs.map +1 -1
- package/dist/{manager-CgpuAzqn.d.cts → manager-BPgytsNL.d.cts} +20 -2
- package/dist/{manager-CgpuAzqn.d.ts → manager-BPgytsNL.d.ts} +20 -2
- package/dist/wallet.cjs +386 -10
- package/dist/wallet.cjs.map +1 -1
- package/dist/wallet.d.cts +3 -3
- package/dist/wallet.d.ts +3 -3
- package/dist/wallet.mjs +387 -11
- package/dist/wallet.mjs.map +1 -1
- package/dist/widget.cjs +1157 -494
- package/dist/widget.cjs.map +1 -1
- package/dist/widget.mjs +972 -309
- package/dist/widget.mjs.map +1 -1
- package/package.json +7 -3
package/README.md
CHANGED
|
@@ -1,90 +1,138 @@
|
|
|
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
|
|
|
17
|
+
Supports React `18.2+` and `19`.
|
|
18
|
+
|
|
9
19
|
```bash
|
|
10
20
|
npm install @trustware/sdk
|
|
11
21
|
# or
|
|
12
22
|
pnpm add @trustware/sdk
|
|
13
23
|
```
|
|
14
24
|
|
|
15
|
-
|
|
25
|
+
## Main Exports
|
|
16
26
|
|
|
17
|
-
|
|
27
|
+
- `TrustwareProvider`
|
|
28
|
+
- `TrustwareWidget`
|
|
29
|
+
- `Trustware`
|
|
30
|
+
- `useTrustware`
|
|
18
31
|
|
|
19
|
-
|
|
20
|
-
- **`TrustwareWidget`** – A prebuilt React component that renders a UI for quoting, wallet selection, top-up submission, and asset settlement.
|
|
21
|
-
- **`Trustware core`** – An imperative singleton with helpers like `Trustware.runTopUp`, `Trustware.buildRoute`, and wallet utilities. Import once the provider is mounted.
|
|
22
|
-
- **Config** – `TrustwareConfigOptions` defines your API key, default routes (e.g., toChain, toToken), slippage, theme, messages, and wallet detection behavior.
|
|
32
|
+
## Quick Start
|
|
23
33
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
34
|
+
```tsx
|
|
35
|
+
import {
|
|
36
|
+
TrustwareProvider,
|
|
37
|
+
TrustwareWidget,
|
|
38
|
+
type TrustwareConfigOptions,
|
|
39
|
+
} from "@trustware/sdk";
|
|
27
40
|
|
|
28
|
-
```ts
|
|
29
41
|
const trustwareConfig = {
|
|
30
42
|
apiKey: process.env.NEXT_PUBLIC_TRUSTWARE_API_KEY!,
|
|
31
43
|
routes: {
|
|
32
|
-
toChain: "8453",
|
|
33
|
-
toToken: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
|
|
44
|
+
toChain: "8453",
|
|
45
|
+
toToken: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
|
|
34
46
|
defaultSlippage: 1,
|
|
35
|
-
// Optional defaults:
|
|
36
|
-
// fromAddress: "0x...", // User's wallet address
|
|
37
|
-
// toAddress: "0x...", // Destination; can be set later via Trustware.setDestinationAddress
|
|
38
47
|
options: {
|
|
39
|
-
|
|
40
|
-
// minAmountOut: "1.00", // USD minimum
|
|
41
|
-
// maxAmountOut: "100.00", // USD maximum
|
|
42
|
-
// routeRefreshMs: 15000, // auto-refresh route quotes
|
|
48
|
+
routeRefreshMs: 15000,
|
|
43
49
|
},
|
|
44
50
|
},
|
|
45
|
-
autoDetectProvider: true,
|
|
46
|
-
theme: {
|
|
47
|
-
primaryColor: "#FCB514",
|
|
48
|
-
secondaryColor: "#FFFFFF",
|
|
49
|
-
backgroundColor: "#000000",
|
|
50
|
-
borderColor: "#FCB514",
|
|
51
|
-
textColor: "#FFFFFF",
|
|
52
|
-
radius: 16,
|
|
53
|
-
},
|
|
51
|
+
autoDetectProvider: true,
|
|
54
52
|
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);
|
|
53
|
+
title: "Deposit",
|
|
54
|
+
description: "Move funds into the destination asset and chain.",
|
|
67
55
|
},
|
|
68
56
|
} satisfies TrustwareConfigOptions;
|
|
57
|
+
|
|
58
|
+
export function App() {
|
|
59
|
+
return (
|
|
60
|
+
<TrustwareProvider config={trustwareConfig}>
|
|
61
|
+
<TrustwareWidget />
|
|
62
|
+
</TrustwareProvider>
|
|
63
|
+
);
|
|
64
|
+
}
|
|
69
65
|
```
|
|
70
66
|
|
|
71
|
-
|
|
67
|
+
## Config Reference
|
|
68
|
+
|
|
69
|
+
`TrustwareConfigOptions` is the single source of truth. The current supported shape is:
|
|
72
70
|
|
|
73
71
|
```ts
|
|
74
|
-
|
|
75
|
-
|
|
72
|
+
type TrustwareConfigOptions = {
|
|
73
|
+
apiKey: string;
|
|
74
|
+
routes: {
|
|
75
|
+
toChain: string;
|
|
76
|
+
toToken: string;
|
|
77
|
+
fromToken?: string;
|
|
78
|
+
fromAddress?: string;
|
|
79
|
+
toAddress?: string;
|
|
80
|
+
defaultSlippage?: number;
|
|
81
|
+
routeType?: string;
|
|
82
|
+
options?: {
|
|
83
|
+
routeRefreshMs?: number;
|
|
84
|
+
fixedFromAmount?: string | number;
|
|
85
|
+
minAmountOut?: string | number;
|
|
86
|
+
maxAmountOut?: string | number;
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
autoDetectProvider?: boolean;
|
|
90
|
+
theme?: TrustwareWidgetTheme;
|
|
91
|
+
messages?: Partial<TrustwareWidgetMessages>;
|
|
92
|
+
retry?: RetryConfig;
|
|
93
|
+
walletConnect?: WalletConnectConfig;
|
|
94
|
+
onError?: (error: TrustwareError) => void;
|
|
95
|
+
onSuccess?: (transaction: Transaction) => void;
|
|
96
|
+
onEvent?: (event: TrustwareEvent) => void;
|
|
97
|
+
};
|
|
76
98
|
```
|
|
77
99
|
|
|
78
|
-
|
|
100
|
+
### Route Fields
|
|
101
|
+
|
|
102
|
+
- `routes.toChain`: destination chain key or chain id string.
|
|
103
|
+
- `routes.toToken`: destination token address or registry token identifier.
|
|
104
|
+
- `routes.fromToken`: optional source token preference.
|
|
105
|
+
- `routes.fromAddress`: optional source wallet override.
|
|
106
|
+
- `routes.toAddress`: optional destination address override.
|
|
107
|
+
- `routes.defaultSlippage`: optional slippage percentage. Defaults to `1`.
|
|
108
|
+
- `routes.routeType`: optional route flavor. Defaults to `"swap"`.
|
|
109
|
+
|
|
110
|
+
### Route Options
|
|
111
|
+
|
|
112
|
+
- `routes.options.routeRefreshMs`: auto-refresh cadence for route previews.
|
|
113
|
+
- `routes.options.fixedFromAmount`: locks the widget amount input to a fixed USD amount.
|
|
114
|
+
- `routes.options.minAmountOut`: minimum allowed USD amount.
|
|
115
|
+
- `routes.options.maxAmountOut`: maximum allowed USD amount.
|
|
116
|
+
|
|
117
|
+
### Other Config Groups
|
|
118
|
+
|
|
119
|
+
- `autoDetectProvider`: enables Trustware-managed wallet discovery.
|
|
120
|
+
- `theme`: widget color and radius customization.
|
|
121
|
+
- `messages`: top-level copy overrides.
|
|
122
|
+
- `retry`: API retry and rate-limit behavior.
|
|
123
|
+
- `walletConnect`: WalletConnect overrides.
|
|
124
|
+
- `onError`, `onSuccess`, `onEvent`: lifecycle callbacks.
|
|
79
125
|
|
|
80
|
-
|
|
126
|
+
## Widget Usage Patterns
|
|
81
127
|
|
|
82
|
-
|
|
128
|
+
### 1. Drop-In Widget With Trustware-Managed Wallet Detection
|
|
129
|
+
|
|
130
|
+
Use this when your app does not already manage a connected wallet.
|
|
83
131
|
|
|
84
132
|
```tsx
|
|
85
133
|
import { TrustwareProvider, TrustwareWidget } from "@trustware/sdk";
|
|
86
134
|
|
|
87
|
-
export function
|
|
135
|
+
export function DepositPanel() {
|
|
88
136
|
return (
|
|
89
137
|
<TrustwareProvider config={trustwareConfig}>
|
|
90
138
|
<TrustwareWidget />
|
|
@@ -93,272 +141,176 @@ export function App() {
|
|
|
93
141
|
}
|
|
94
142
|
```
|
|
95
143
|
|
|
96
|
-
|
|
97
|
-
- Call `Trustware.setDestinationAddress(address)` dynamically if the `toAddress` is determined at runtime (e.g., after smart wallet generation).
|
|
144
|
+
Use this mode when:
|
|
98
145
|
|
|
99
|
-
|
|
146
|
+
- you want the built-in wallet selection flow
|
|
147
|
+
- you want the full hosted deposit UX
|
|
148
|
+
- `autoDetectProvider` should stay enabled
|
|
100
149
|
|
|
101
|
-
|
|
150
|
+
### 2. Widget With a Host-Managed Wallet
|
|
151
|
+
|
|
152
|
+
Use this when your app already controls wallet connection through Wagmi, Viem, or another adapter.
|
|
102
153
|
|
|
103
154
|
```tsx
|
|
104
|
-
import {
|
|
155
|
+
import { useMemo } from "react";
|
|
105
156
|
import { useWalletClient } from "wagmi";
|
|
106
|
-
import { TrustwareProvider, TrustwareWidget
|
|
107
|
-
import { useWagmi } from "@trustware/sdk/wallet";
|
|
157
|
+
import { TrustwareProvider, TrustwareWidget } from "@trustware/sdk";
|
|
158
|
+
import { useWagmi } from "@trustware/sdk/wallet";
|
|
108
159
|
|
|
109
|
-
export function
|
|
110
|
-
const { data:
|
|
160
|
+
export function DepositPanel() {
|
|
161
|
+
const { data: walletClient } = useWalletClient();
|
|
111
162
|
const wallet = useMemo(
|
|
112
|
-
() => (
|
|
113
|
-
[
|
|
163
|
+
() => (walletClient ? useWagmi(walletClient) : undefined),
|
|
164
|
+
[walletClient]
|
|
114
165
|
);
|
|
115
166
|
|
|
116
|
-
useEffect(() => {
|
|
117
|
-
if (!wallet) return;
|
|
118
|
-
Trustware.setDestinationAddress("0xDestination...");
|
|
119
|
-
}, [wallet]);
|
|
120
|
-
|
|
121
167
|
return (
|
|
122
168
|
<TrustwareProvider
|
|
123
169
|
config={trustwareConfig}
|
|
124
170
|
wallet={wallet}
|
|
125
|
-
autoDetect={false}
|
|
171
|
+
autoDetect={false}
|
|
126
172
|
>
|
|
127
|
-
<TrustwareWidget />
|
|
173
|
+
<TrustwareWidget />
|
|
128
174
|
</TrustwareProvider>
|
|
129
175
|
);
|
|
130
176
|
}
|
|
131
177
|
```
|
|
132
178
|
|
|
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
|
-
```
|
|
179
|
+
Use this mode when:
|
|
153
180
|
|
|
154
|
-
|
|
181
|
+
- your app already owns wallet state
|
|
182
|
+
- you do not want the SDK to pick another provider
|
|
183
|
+
- you want the widget UX but not the widget’s wallet discovery responsibilities
|
|
155
184
|
|
|
156
|
-
|
|
185
|
+
### 3. Controlled Widget Shell
|
|
157
186
|
|
|
158
|
-
|
|
159
|
-
- For dynamic `toAddress`: Call `Trustware.setDestinationAddress` before render.
|
|
187
|
+
`TrustwareWidget` also supports basic shell control through props and a ref.
|
|
160
188
|
|
|
161
|
-
|
|
189
|
+
```tsx
|
|
190
|
+
import { useRef } from "react";
|
|
191
|
+
import {
|
|
192
|
+
TrustwareProvider,
|
|
193
|
+
TrustwareWidget,
|
|
194
|
+
type TrustwareWidgetRef,
|
|
195
|
+
} from "@trustware/sdk";
|
|
162
196
|
|
|
163
|
-
|
|
197
|
+
export function ControlledWidget() {
|
|
198
|
+
const widgetRef = useRef<TrustwareWidgetRef>(null);
|
|
164
199
|
|
|
165
|
-
|
|
166
|
-
|
|
200
|
+
return (
|
|
201
|
+
<TrustwareProvider config={trustwareConfig}>
|
|
202
|
+
<button onClick={() => widgetRef.current?.open()}>Open</button>
|
|
203
|
+
<TrustwareWidget
|
|
204
|
+
ref={widgetRef}
|
|
205
|
+
defaultOpen={false}
|
|
206
|
+
initialStep="home"
|
|
207
|
+
showThemeToggle={false}
|
|
208
|
+
onOpen={() => console.log("opened")}
|
|
209
|
+
onClose={() => console.log("closed")}
|
|
210
|
+
/>
|
|
211
|
+
</TrustwareProvider>
|
|
212
|
+
);
|
|
213
|
+
}
|
|
167
214
|
```
|
|
168
215
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
### Wallet Detection and Management
|
|
216
|
+
Current widget props:
|
|
172
217
|
|
|
173
|
-
- `
|
|
174
|
-
- `
|
|
175
|
-
- `
|
|
218
|
+
- `theme?: "light" | "dark" | "system"`
|
|
219
|
+
- `initialStep?: "home" | "select-token" | "crypto-pay" | "processing" | "success" | "error"`
|
|
220
|
+
- `defaultOpen?: boolean`
|
|
221
|
+
- `onOpen?: () => void`
|
|
222
|
+
- `onClose?: () => void`
|
|
223
|
+
- `showThemeToggle?: boolean`
|
|
176
224
|
|
|
177
|
-
###
|
|
225
|
+
### 4. Headless Core API
|
|
178
226
|
|
|
179
|
-
|
|
227
|
+
Use this when you want Trustware’s routing and wallet plumbing without the widget UI.
|
|
180
228
|
|
|
181
229
|
```ts
|
|
182
|
-
|
|
183
|
-
const fromAddress = await Trustware.getAddress();
|
|
230
|
+
import { Trustware } from "@trustware/sdk";
|
|
184
231
|
|
|
185
232
|
const route = await Trustware.buildRoute({
|
|
186
|
-
amount: "0.1",
|
|
187
|
-
fromAddress,
|
|
188
|
-
toAddress: cfg.routes.toAddress ?? fromAddress, // Fallbacks applied
|
|
233
|
+
amount: "0.1",
|
|
234
|
+
fromAddress: await Trustware.getAddress(),
|
|
189
235
|
});
|
|
190
236
|
|
|
191
237
|
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
238
|
|
|
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
|
-
}
|
|
239
|
+
const result = await Trustware.runTopUp({
|
|
240
|
+
amount: "0.1",
|
|
241
|
+
fromAddress: await Trustware.getAddress(),
|
|
242
|
+
});
|
|
214
243
|
```
|
|
215
244
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
### Lifecycle Events
|
|
245
|
+
## Common Config Examples
|
|
219
246
|
|
|
220
|
-
|
|
247
|
+
### Fixed Amount Deposit
|
|
221
248
|
|
|
222
249
|
```ts
|
|
223
|
-
const
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
250
|
+
const fixedAmountConfig = {
|
|
251
|
+
...trustwareConfig,
|
|
252
|
+
routes: {
|
|
253
|
+
...trustwareConfig.routes,
|
|
254
|
+
options: {
|
|
255
|
+
fixedFromAmount: "25",
|
|
256
|
+
},
|
|
257
|
+
},
|
|
258
|
+
} satisfies TrustwareConfigOptions;
|
|
229
259
|
```
|
|
230
260
|
|
|
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:
|
|
261
|
+
### Min / Max Guardrails
|
|
263
262
|
|
|
264
263
|
```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`);
|
|
264
|
+
const guardedConfig = {
|
|
265
|
+
...trustwareConfig,
|
|
266
|
+
routes: {
|
|
267
|
+
...trustwareConfig.routes,
|
|
268
|
+
options: {
|
|
269
|
+
minAmountOut: "10",
|
|
270
|
+
maxAmountOut: "250",
|
|
271
|
+
routeRefreshMs: 10000,
|
|
285
272
|
},
|
|
286
273
|
},
|
|
287
|
-
};
|
|
274
|
+
} satisfies TrustwareConfigOptions;
|
|
288
275
|
```
|
|
289
276
|
|
|
290
|
-
###
|
|
291
|
-
|
|
292
|
-
The `RateLimitInfo` object contains:
|
|
277
|
+
### Runtime Destination Address
|
|
293
278
|
|
|
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) |
|
|
279
|
+
```ts
|
|
280
|
+
import { Trustware } from "@trustware/sdk";
|
|
300
281
|
|
|
301
|
-
|
|
282
|
+
Trustware.setDestinationAddress("0xDestination...");
|
|
283
|
+
```
|
|
302
284
|
|
|
303
|
-
|
|
285
|
+
## Headless / Core Notes
|
|
304
286
|
|
|
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
|
-
```
|
|
287
|
+
- `Trustware.getConfig()` returns the resolved config.
|
|
288
|
+
- `Trustware.getWallet()` and `Trustware.getAddress()` expose the active wallet.
|
|
289
|
+
- `Trustware.useWallet(wallet)` attaches a wallet imperatively.
|
|
290
|
+
- `Trustware.autoDetect()` can still be used if you want SDK-managed discovery outside the widget.
|
|
317
291
|
|
|
318
|
-
|
|
292
|
+
## Rate Limiting
|
|
319
293
|
|
|
320
|
-
|
|
294
|
+
Client retry behavior is configured through `retry`.
|
|
321
295
|
|
|
322
296
|
```ts
|
|
323
297
|
const config = {
|
|
324
|
-
|
|
298
|
+
...trustwareConfig,
|
|
325
299
|
retry: {
|
|
326
|
-
autoRetry:
|
|
327
|
-
|
|
300
|
+
autoRetry: true,
|
|
301
|
+
maxRetries: 3,
|
|
302
|
+
baseDelayMs: 1000,
|
|
303
|
+
approachingThreshold: 5,
|
|
328
304
|
},
|
|
329
|
-
};
|
|
305
|
+
} satisfies TrustwareConfigOptions;
|
|
330
306
|
```
|
|
331
307
|
|
|
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.
|
|
308
|
+
If retries are exhausted, the SDK throws `RateLimitError`.
|
|
358
309
|
|
|
359
|
-
##
|
|
310
|
+
## Docs
|
|
360
311
|
|
|
361
|
-
-
|
|
362
|
-
- Source: Explore `sdk/src` for implementation details.
|
|
312
|
+
- [Integration Guide](docs/intergrationGuide.md)
|
|
363
313
|
- [Core Guide](docs/coreGuide.md)
|
|
364
|
-
- [
|
|
314
|
+
- [Backend RPC Offload PDR](docs/backend-rpc-offload-pdr.md)
|
|
315
|
+
- [Widget Architecture Boundaries](docs/widget-architecture-boundaries.md)
|
|
316
|
+
- [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.
|
|
32
|
+
var SDK_VERSION = "1.1.3-staging.20";
|
|
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.
|
|
3
|
+
var SDK_VERSION = "1.1.3-staging.20";
|
|
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";
|