@oasisprotocol/privana-sdk 0.2.1 → 0.4.0
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 +137 -17
- package/dist/chunk-RDMJGMI3.cjs +1757 -0
- package/dist/chunk-RDMJGMI3.cjs.map +1 -0
- package/dist/chunk-ZVNC4FTJ.js +1704 -0
- package/dist/chunk-ZVNC4FTJ.js.map +1 -0
- package/dist/index.cjs +322 -1516
- package/dist/index.cjs.map +1 -1
- package/dist/index.css +1 -1
- package/dist/index.css.map +1 -1
- package/dist/index.d.cts +98 -61
- package/dist/index.d.ts +98 -61
- package/dist/index.js +52 -1377
- package/dist/index.js.map +1 -1
- package/dist/on-ramp-DIAOtdeU.d.cts +115 -0
- package/dist/on-ramp-DIAOtdeU.d.ts +115 -0
- package/dist/on-ramp.cjs +861 -0
- package/dist/on-ramp.cjs.map +1 -0
- package/dist/on-ramp.d.cts +137 -0
- package/dist/on-ramp.d.ts +137 -0
- package/dist/on-ramp.js +858 -0
- package/dist/on-ramp.js.map +1 -0
- package/package.json +12 -1
package/dist/index.cjs
CHANGED
|
@@ -1,20 +1,14 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
|
+
var chunkRDMJGMI3_cjs = require('./chunk-RDMJGMI3.cjs');
|
|
4
5
|
var react = require('react');
|
|
5
|
-
var viem = require('viem');
|
|
6
|
-
var jsxRuntime = require('react/jsx-runtime');
|
|
7
6
|
var reactQuery = require('@tanstack/react-query');
|
|
8
|
-
var clsx = require('clsx');
|
|
9
|
-
var tailwindMerge = require('tailwind-merge');
|
|
10
|
-
var siwe = require('viem/siwe');
|
|
11
7
|
var wagmi = require('wagmi');
|
|
12
|
-
var
|
|
13
|
-
var actions$1 = require('viem/actions');
|
|
14
|
-
var reactSlot = require('@radix-ui/react-slot');
|
|
15
|
-
var classVarianceAuthority = require('class-variance-authority');
|
|
8
|
+
var viem = require('viem');
|
|
16
9
|
var DialogPrimitive = require('@radix-ui/react-dialog');
|
|
17
10
|
var lucideReact = require('lucide-react');
|
|
11
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
18
12
|
var sonner = require('sonner');
|
|
19
13
|
|
|
20
14
|
function _interopNamespace(e) {
|
|
@@ -37,565 +31,6 @@ function _interopNamespace(e) {
|
|
|
37
31
|
|
|
38
32
|
var DialogPrimitive__namespace = /*#__PURE__*/_interopNamespace(DialogPrimitive);
|
|
39
33
|
|
|
40
|
-
// ../../shared/config.json
|
|
41
|
-
var config_default = {
|
|
42
|
-
chains: [
|
|
43
|
-
{
|
|
44
|
-
id: 84532,
|
|
45
|
-
name: "Base Sepolia",
|
|
46
|
-
explorerUrl: "https://sepolia.basescan.org"
|
|
47
|
-
}
|
|
48
|
-
],
|
|
49
|
-
networks: {
|
|
50
|
-
testnet: {
|
|
51
|
-
chainId: 23295,
|
|
52
|
-
name: "Sapphire Testnet",
|
|
53
|
-
accountingContract: "0xaF8e5de153A584528B57DD4B9B0195956BBDF571",
|
|
54
|
-
apiUrl: "https://testnet.privana.finance"
|
|
55
|
-
},
|
|
56
|
-
mainnet: {
|
|
57
|
-
chainId: 23294,
|
|
58
|
-
name: "Sapphire Mainnet",
|
|
59
|
-
accountingContract: "0x0000000000000000000000000000000000000000",
|
|
60
|
-
apiUrl: ""
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
// src/sdk/types/common.ts
|
|
66
|
-
var NETWORK_CONFIG = {
|
|
67
|
-
testnet: {
|
|
68
|
-
...config_default.networks.testnet,
|
|
69
|
-
accountingContract: config_default.networks.testnet.accountingContract
|
|
70
|
-
},
|
|
71
|
-
mainnet: {
|
|
72
|
-
...config_default.networks.mainnet,
|
|
73
|
-
accountingContract: config_default.networks.mainnet.accountingContract
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
function getChainId(network) {
|
|
77
|
-
return NETWORK_CONFIG[network].chainId;
|
|
78
|
-
}
|
|
79
|
-
function getAccountingContract(network) {
|
|
80
|
-
return NETWORK_CONFIG[network].accountingContract;
|
|
81
|
-
}
|
|
82
|
-
function getApiUrl(network) {
|
|
83
|
-
return NETWORK_CONFIG[network].apiUrl;
|
|
84
|
-
}
|
|
85
|
-
function normalizeHex(value) {
|
|
86
|
-
const normalized = value.trim().toLowerCase();
|
|
87
|
-
return normalized.startsWith("0x") ? normalized : `0x${normalized}`;
|
|
88
|
-
}
|
|
89
|
-
function normalizeAddress(value) {
|
|
90
|
-
return normalizeHex(value);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
// src/sdk/types/chains.ts
|
|
94
|
-
var SUPPORTED_CHAINS = config_default.chains.map((chain) => ({
|
|
95
|
-
id: chain.id,
|
|
96
|
-
name: chain.name,
|
|
97
|
-
explorerUrl: chain.explorerUrl
|
|
98
|
-
}));
|
|
99
|
-
function getChainById(chainId) {
|
|
100
|
-
return SUPPORTED_CHAINS.find((c) => c.id === chainId);
|
|
101
|
-
}
|
|
102
|
-
function getExplorerAddressUrl(chainId, address) {
|
|
103
|
-
const chain = getChainById(chainId);
|
|
104
|
-
if (!chain) return void 0;
|
|
105
|
-
return `${chain.explorerUrl}/address/${address}#tokentxns`;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
// src/sdk/auth/hosted-auth.ts
|
|
109
|
-
var HOSTED_AUTH_CLOCK_SKEW_MS = 3e4;
|
|
110
|
-
var PKCE_CHARSET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~";
|
|
111
|
-
var DEFAULT_RANDOM_LENGTH = 64;
|
|
112
|
-
var HOSTED_AUTH_CALLBACK_QUERY_KEYS = ["code", "error", "error_description", "state"];
|
|
113
|
-
function randomString(length) {
|
|
114
|
-
const values = new Uint8Array(length);
|
|
115
|
-
crypto.getRandomValues(values);
|
|
116
|
-
let output = "";
|
|
117
|
-
for (const value of values) {
|
|
118
|
-
output += PKCE_CHARSET[value % PKCE_CHARSET.length];
|
|
119
|
-
}
|
|
120
|
-
return output;
|
|
121
|
-
}
|
|
122
|
-
function toBase64Url(bytes) {
|
|
123
|
-
let binary = "";
|
|
124
|
-
bytes.forEach((byte) => {
|
|
125
|
-
binary += String.fromCharCode(byte);
|
|
126
|
-
});
|
|
127
|
-
return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/g, "");
|
|
128
|
-
}
|
|
129
|
-
function createPkceVerifier(length = DEFAULT_RANDOM_LENGTH) {
|
|
130
|
-
return randomString(length);
|
|
131
|
-
}
|
|
132
|
-
async function createPkceChallenge(verifier) {
|
|
133
|
-
const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(verifier));
|
|
134
|
-
return toBase64Url(new Uint8Array(digest));
|
|
135
|
-
}
|
|
136
|
-
function createHostedAuthState(length = DEFAULT_RANDOM_LENGTH) {
|
|
137
|
-
return randomString(length);
|
|
138
|
-
}
|
|
139
|
-
function createHostedAuthStorageKey(apiUrl, config) {
|
|
140
|
-
const normalizedApiUrl = apiUrl.replace(/\/$/, "");
|
|
141
|
-
return [
|
|
142
|
-
"privana",
|
|
143
|
-
"hosted-auth",
|
|
144
|
-
normalizedApiUrl,
|
|
145
|
-
config.clientId.trim(),
|
|
146
|
-
config.redirectUri.trim()
|
|
147
|
-
].join(":");
|
|
148
|
-
}
|
|
149
|
-
function createHostedAuthPendingStorageKey(apiUrl, config) {
|
|
150
|
-
return `${createHostedAuthStorageKey(apiUrl, config)}:pending`;
|
|
151
|
-
}
|
|
152
|
-
function persistHostedAuthPendingTransaction(storage, key, transaction) {
|
|
153
|
-
storage.setItem(key, JSON.stringify(transaction));
|
|
154
|
-
}
|
|
155
|
-
function readHostedAuthPendingTransaction(storage, key) {
|
|
156
|
-
const raw = storage.getItem(key);
|
|
157
|
-
if (!raw) return null;
|
|
158
|
-
try {
|
|
159
|
-
const parsed = JSON.parse(raw);
|
|
160
|
-
if (typeof parsed.codeVerifier !== "string" || typeof parsed.state !== "string") {
|
|
161
|
-
return null;
|
|
162
|
-
}
|
|
163
|
-
return {
|
|
164
|
-
codeVerifier: parsed.codeVerifier,
|
|
165
|
-
state: parsed.state
|
|
166
|
-
};
|
|
167
|
-
} catch {
|
|
168
|
-
return null;
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
function clearHostedAuthPendingTransaction(storage, key) {
|
|
172
|
-
storage.removeItem(key);
|
|
173
|
-
}
|
|
174
|
-
function parseHostedAuthCallback(url, redirectUri) {
|
|
175
|
-
const expectedUrl = new URL(redirectUri);
|
|
176
|
-
if (url.origin !== expectedUrl.origin || url.pathname !== expectedUrl.pathname) {
|
|
177
|
-
return null;
|
|
178
|
-
}
|
|
179
|
-
const code = url.searchParams.get("code");
|
|
180
|
-
if (code) {
|
|
181
|
-
return {
|
|
182
|
-
code,
|
|
183
|
-
state: url.searchParams.get("state")
|
|
184
|
-
};
|
|
185
|
-
}
|
|
186
|
-
const error = url.searchParams.get("error");
|
|
187
|
-
if (error) {
|
|
188
|
-
return {
|
|
189
|
-
error,
|
|
190
|
-
errorDescription: url.searchParams.get("error_description") ?? void 0,
|
|
191
|
-
state: url.searchParams.get("state")
|
|
192
|
-
};
|
|
193
|
-
}
|
|
194
|
-
return null;
|
|
195
|
-
}
|
|
196
|
-
function stripHostedAuthCallbackParams(url) {
|
|
197
|
-
const nextUrl = new URL(url.toString());
|
|
198
|
-
HOSTED_AUTH_CALLBACK_QUERY_KEYS.forEach((key) => {
|
|
199
|
-
nextUrl.searchParams.delete(key);
|
|
200
|
-
});
|
|
201
|
-
return `${nextUrl.pathname}${nextUrl.search}${nextUrl.hash}`;
|
|
202
|
-
}
|
|
203
|
-
function buildHostedAuthSession(response, config, now = Date.now()) {
|
|
204
|
-
return {
|
|
205
|
-
accessToken: response.access_token,
|
|
206
|
-
refreshToken: response.refresh_token,
|
|
207
|
-
idToken: response.id_token,
|
|
208
|
-
tokenType: response.token_type,
|
|
209
|
-
address: response.address,
|
|
210
|
-
clientId: config.clientId,
|
|
211
|
-
redirectUri: config.redirectUri,
|
|
212
|
-
expiresAt: now + response.expires_in * 1e3,
|
|
213
|
-
refreshExpiresAt: now + response.refresh_expires_in * 1e3
|
|
214
|
-
};
|
|
215
|
-
}
|
|
216
|
-
function applyRefreshResponse(session, response, now = Date.now()) {
|
|
217
|
-
return {
|
|
218
|
-
...session,
|
|
219
|
-
accessToken: response.token,
|
|
220
|
-
refreshToken: response.refresh_token,
|
|
221
|
-
expiresAt: now + response.expires_in * 1e3,
|
|
222
|
-
refreshExpiresAt: now + response.refresh_expires_in * 1e3
|
|
223
|
-
};
|
|
224
|
-
}
|
|
225
|
-
function isHostedAuthSessionActive(session, now = Date.now(), skewMs = HOSTED_AUTH_CLOCK_SKEW_MS) {
|
|
226
|
-
return session.expiresAt > now + skewMs;
|
|
227
|
-
}
|
|
228
|
-
function isHostedAuthRefreshActive(session, now = Date.now(), skewMs = HOSTED_AUTH_CLOCK_SKEW_MS) {
|
|
229
|
-
return session.refreshExpiresAt > now + skewMs;
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
// src/sdk/client/errors.ts
|
|
233
|
-
var AccountingApiError = class _AccountingApiError extends Error {
|
|
234
|
-
constructor(message, statusCode, detail) {
|
|
235
|
-
super(message);
|
|
236
|
-
this.statusCode = statusCode;
|
|
237
|
-
this.detail = detail;
|
|
238
|
-
this.name = "AccountingApiError";
|
|
239
|
-
Object.setPrototypeOf(this, _AccountingApiError.prototype);
|
|
240
|
-
}
|
|
241
|
-
};
|
|
242
|
-
var NetworkError = class _NetworkError extends Error {
|
|
243
|
-
constructor(message, cause) {
|
|
244
|
-
super(message);
|
|
245
|
-
this.cause = cause;
|
|
246
|
-
this.name = "NetworkError";
|
|
247
|
-
Object.setPrototypeOf(this, _NetworkError.prototype);
|
|
248
|
-
}
|
|
249
|
-
};
|
|
250
|
-
var ValidationError = class _ValidationError extends Error {
|
|
251
|
-
constructor(message, field) {
|
|
252
|
-
super(message);
|
|
253
|
-
this.field = field;
|
|
254
|
-
this.name = "ValidationError";
|
|
255
|
-
Object.setPrototypeOf(this, _ValidationError.prototype);
|
|
256
|
-
}
|
|
257
|
-
};
|
|
258
|
-
var HostedAuthError = class _HostedAuthError extends Error {
|
|
259
|
-
constructor(message) {
|
|
260
|
-
super(message);
|
|
261
|
-
this.name = "HostedAuthError";
|
|
262
|
-
Object.setPrototypeOf(this, _HostedAuthError.prototype);
|
|
263
|
-
}
|
|
264
|
-
};
|
|
265
|
-
var HostedAuthRequiredError = class _HostedAuthRequiredError extends HostedAuthError {
|
|
266
|
-
constructor(message = "Hosted redirect authentication is required. Start login with useHostedRedirectAuth().") {
|
|
267
|
-
super(message);
|
|
268
|
-
this.name = "HostedAuthRequiredError";
|
|
269
|
-
Object.setPrototypeOf(this, _HostedAuthRequiredError.prototype);
|
|
270
|
-
}
|
|
271
|
-
};
|
|
272
|
-
var HostedAuthStateMismatchError = class _HostedAuthStateMismatchError extends HostedAuthError {
|
|
273
|
-
constructor(message = "Hosted authentication returned an invalid state value.") {
|
|
274
|
-
super(message);
|
|
275
|
-
this.name = "HostedAuthStateMismatchError";
|
|
276
|
-
Object.setPrototypeOf(this, _HostedAuthStateMismatchError.prototype);
|
|
277
|
-
}
|
|
278
|
-
};
|
|
279
|
-
|
|
280
|
-
// src/sdk/client/http-client.ts
|
|
281
|
-
var HttpClient = class {
|
|
282
|
-
constructor(config) {
|
|
283
|
-
this.baseUrl = config.baseUrl.replace(/\/$/, "");
|
|
284
|
-
this.timeout = config.timeout ?? 3e4;
|
|
285
|
-
this.headers = {
|
|
286
|
-
"Content-Type": "application/json",
|
|
287
|
-
...config.headers
|
|
288
|
-
};
|
|
289
|
-
}
|
|
290
|
-
async get(path) {
|
|
291
|
-
return this.request("GET", path);
|
|
292
|
-
}
|
|
293
|
-
async post(path, body) {
|
|
294
|
-
return this.request("POST", path, body);
|
|
295
|
-
}
|
|
296
|
-
getBaseUrl() {
|
|
297
|
-
return this.baseUrl;
|
|
298
|
-
}
|
|
299
|
-
setHeader(name, value) {
|
|
300
|
-
this.headers[name] = value;
|
|
301
|
-
}
|
|
302
|
-
removeHeader(name) {
|
|
303
|
-
delete this.headers[name];
|
|
304
|
-
}
|
|
305
|
-
getHeader(name) {
|
|
306
|
-
return this.headers[name];
|
|
307
|
-
}
|
|
308
|
-
async request(method, path, body) {
|
|
309
|
-
const url = `${this.baseUrl}${path}`;
|
|
310
|
-
const controller = new AbortController();
|
|
311
|
-
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
312
|
-
try {
|
|
313
|
-
const response = await fetch(url, {
|
|
314
|
-
method,
|
|
315
|
-
headers: this.headers,
|
|
316
|
-
body: body ? JSON.stringify(body) : void 0,
|
|
317
|
-
signal: controller.signal
|
|
318
|
-
});
|
|
319
|
-
clearTimeout(timeoutId);
|
|
320
|
-
if (!response.ok) {
|
|
321
|
-
let detail;
|
|
322
|
-
try {
|
|
323
|
-
const errorBody = await response.json();
|
|
324
|
-
detail = errorBody.detail || errorBody.error_description || errorBody.message;
|
|
325
|
-
} catch {
|
|
326
|
-
detail = await response.text().catch(() => void 0);
|
|
327
|
-
}
|
|
328
|
-
throw new AccountingApiError(
|
|
329
|
-
`API request failed: ${response.status} ${response.statusText}`,
|
|
330
|
-
response.status,
|
|
331
|
-
detail
|
|
332
|
-
);
|
|
333
|
-
}
|
|
334
|
-
return response.json();
|
|
335
|
-
} catch (error) {
|
|
336
|
-
clearTimeout(timeoutId);
|
|
337
|
-
if (error instanceof AccountingApiError) {
|
|
338
|
-
throw error;
|
|
339
|
-
}
|
|
340
|
-
if (error instanceof Error) {
|
|
341
|
-
if (error.name === "AbortError") {
|
|
342
|
-
throw new NetworkError(`Request timeout after ${this.timeout}ms`);
|
|
343
|
-
}
|
|
344
|
-
throw new NetworkError(`Network request failed: ${error.message}`, error);
|
|
345
|
-
}
|
|
346
|
-
throw new NetworkError("Unknown network error occurred");
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
};
|
|
350
|
-
|
|
351
|
-
// src/sdk/client/privana-client.ts
|
|
352
|
-
var PRIVATE_READ_TOKEN_HEADER = "X-SIWE-Token";
|
|
353
|
-
var MAX_BATCH_BALANCE_TOKEN_IDS = 100;
|
|
354
|
-
var MAX_HISTORY_PAGE_SIZE = 100;
|
|
355
|
-
var PrivanaClient = class {
|
|
356
|
-
constructor(config) {
|
|
357
|
-
this.http = new HttpClient(config);
|
|
358
|
-
}
|
|
359
|
-
getBaseUrl() {
|
|
360
|
-
return this.http.getBaseUrl();
|
|
361
|
-
}
|
|
362
|
-
async getDepositAddress(request = {}) {
|
|
363
|
-
return this.http.post("/v1/accounting/deposits/address", {
|
|
364
|
-
chain_type: request.chain_type ?? "evm",
|
|
365
|
-
version: request.version ?? 0
|
|
366
|
-
});
|
|
367
|
-
}
|
|
368
|
-
async checkDeposit(request) {
|
|
369
|
-
return this.http.post("/v1/accounting/deposits/check", {
|
|
370
|
-
chain_type: request.chain_type ?? "evm",
|
|
371
|
-
chain_id: request.chain_id,
|
|
372
|
-
tx_hash: normalizeHex(request.tx_hash),
|
|
373
|
-
amount: String(request.amount),
|
|
374
|
-
log_index: request.log_index ?? 0,
|
|
375
|
-
version: request.version ?? 0
|
|
376
|
-
});
|
|
377
|
-
}
|
|
378
|
-
async getDepositStatus(depositId) {
|
|
379
|
-
return this.http.get(`/v1/accounting/deposits/status/${depositId}`);
|
|
380
|
-
}
|
|
381
|
-
async getBalance(tokenId) {
|
|
382
|
-
const token = normalizeHex(tokenId);
|
|
383
|
-
return this.http.get(`/v1/accounting/balances/${token}`);
|
|
384
|
-
}
|
|
385
|
-
async getBatchBalances(request) {
|
|
386
|
-
if (request.token_ids.length > MAX_BATCH_BALANCE_TOKEN_IDS) {
|
|
387
|
-
throw new Error(
|
|
388
|
-
`Batch balance requests support at most ${MAX_BATCH_BALANCE_TOKEN_IDS} token IDs`
|
|
389
|
-
);
|
|
390
|
-
}
|
|
391
|
-
return this.http.post("/v1/accounting/balances/batch", {
|
|
392
|
-
token_ids: request.token_ids.map((id) => normalizeHex(id))
|
|
393
|
-
});
|
|
394
|
-
}
|
|
395
|
-
async getHistory(request = {}) {
|
|
396
|
-
const offset = request.offset ?? -1;
|
|
397
|
-
const limit = request.limit ?? 50;
|
|
398
|
-
if (!Number.isSafeInteger(offset)) {
|
|
399
|
-
throw new Error("History offset must be an integer");
|
|
400
|
-
}
|
|
401
|
-
if (!Number.isSafeInteger(limit)) {
|
|
402
|
-
throw new Error("History limit must be an integer");
|
|
403
|
-
}
|
|
404
|
-
if (limit < 0 || limit > MAX_HISTORY_PAGE_SIZE) {
|
|
405
|
-
throw new Error(`History requests support between 0 and ${MAX_HISTORY_PAGE_SIZE} entries`);
|
|
406
|
-
}
|
|
407
|
-
const params = new URLSearchParams({
|
|
408
|
-
offset: String(offset),
|
|
409
|
-
limit: String(limit)
|
|
410
|
-
});
|
|
411
|
-
return this.http.get(`/v1/accounting/history?${params.toString()}`);
|
|
412
|
-
}
|
|
413
|
-
async listTokens() {
|
|
414
|
-
return this.http.get("/v1/accounting/tokens");
|
|
415
|
-
}
|
|
416
|
-
async getTokenInfo(tokenId) {
|
|
417
|
-
const token = normalizeHex(tokenId);
|
|
418
|
-
return this.http.get(`/v1/accounting/tokens/${token}`);
|
|
419
|
-
}
|
|
420
|
-
async lockFunds(request) {
|
|
421
|
-
return this.http.post("/v1/accounting/funds/lock", {
|
|
422
|
-
service_address: normalizeAddress(request.service_address),
|
|
423
|
-
token_id: normalizeHex(request.token_id),
|
|
424
|
-
amount: String(request.amount),
|
|
425
|
-
expiry: String(request.expiry),
|
|
426
|
-
nonce: String(request.nonce),
|
|
427
|
-
signature: normalizeHex(request.signature)
|
|
428
|
-
});
|
|
429
|
-
}
|
|
430
|
-
async modifyLock(request) {
|
|
431
|
-
return this.http.post("/v1/accounting/funds/modify-lock", {
|
|
432
|
-
lock_id: request.lock_id,
|
|
433
|
-
amount: String(request.amount),
|
|
434
|
-
new_expiry: String(request.new_expiry),
|
|
435
|
-
nonce: String(request.nonce),
|
|
436
|
-
signature: normalizeHex(request.signature)
|
|
437
|
-
});
|
|
438
|
-
}
|
|
439
|
-
async unlockFunds(request) {
|
|
440
|
-
return this.http.post("/v1/accounting/funds/unlock", {
|
|
441
|
-
user_address: normalizeAddress(request.user_address),
|
|
442
|
-
lock_id: request.lock_id
|
|
443
|
-
});
|
|
444
|
-
}
|
|
445
|
-
async unlockAllExpired(request) {
|
|
446
|
-
return this.http.post(
|
|
447
|
-
"/v1/accounting/funds/unlock-all-expired",
|
|
448
|
-
{
|
|
449
|
-
user_address: normalizeAddress(request.user_address)
|
|
450
|
-
}
|
|
451
|
-
);
|
|
452
|
-
}
|
|
453
|
-
async getLockedFunds(serviceAddress) {
|
|
454
|
-
const queryParams = serviceAddress ? `?service_address=${normalizeAddress(serviceAddress)}` : "";
|
|
455
|
-
return this.http.get(`/v1/accounting/funds/locked${queryParams}`);
|
|
456
|
-
}
|
|
457
|
-
async getTotalLockedBalance(tokenId) {
|
|
458
|
-
const token = normalizeHex(tokenId);
|
|
459
|
-
return this.http.get(`/v1/accounting/funds/locked/total/${token}`);
|
|
460
|
-
}
|
|
461
|
-
async getExpiredLocks() {
|
|
462
|
-
return this.http.get("/v1/accounting/funds/expired");
|
|
463
|
-
}
|
|
464
|
-
async transferFunds(request) {
|
|
465
|
-
return this.http.post("/v1/accounting/funds/transfer", {
|
|
466
|
-
to_address: normalizeAddress(request.to_address),
|
|
467
|
-
token_id: normalizeHex(request.token_id),
|
|
468
|
-
amount: String(request.amount),
|
|
469
|
-
nonce: String(request.nonce),
|
|
470
|
-
signature: normalizeHex(request.signature)
|
|
471
|
-
});
|
|
472
|
-
}
|
|
473
|
-
async getTransferNonce(userAddress) {
|
|
474
|
-
const user = normalizeAddress(userAddress);
|
|
475
|
-
return this.http.get(`/v1/accounting/funds/transfer/nonce/${user}`);
|
|
476
|
-
}
|
|
477
|
-
async getLockNonce(userAddress) {
|
|
478
|
-
const user = normalizeAddress(userAddress);
|
|
479
|
-
return this.http.get(`/v1/accounting/funds/lock/nonce/${user}`);
|
|
480
|
-
}
|
|
481
|
-
async getModifyLockNonce(userAddress) {
|
|
482
|
-
const user = normalizeAddress(userAddress);
|
|
483
|
-
return this.http.get(`/v1/accounting/funds/modify-lock/nonce/${user}`);
|
|
484
|
-
}
|
|
485
|
-
async transferLockedFunds(request) {
|
|
486
|
-
return this.http.post("/v1/accounting/funds/transfer-locked", {
|
|
487
|
-
user_address: normalizeAddress(request.user_address),
|
|
488
|
-
lock_id: request.lock_id,
|
|
489
|
-
to_address: normalizeAddress(request.to_address),
|
|
490
|
-
amount: String(request.amount),
|
|
491
|
-
service_address: normalizeAddress(request.service_address),
|
|
492
|
-
nonce: String(request.nonce),
|
|
493
|
-
signature: normalizeHex(request.signature)
|
|
494
|
-
});
|
|
495
|
-
}
|
|
496
|
-
async withdrawFromLock(request) {
|
|
497
|
-
return this.http.post(
|
|
498
|
-
"/v1/accounting/funds/withdraw-from-lock",
|
|
499
|
-
{
|
|
500
|
-
to_address: normalizeAddress(request.to_address),
|
|
501
|
-
lock_id: request.lock_id,
|
|
502
|
-
amount: String(request.amount),
|
|
503
|
-
nonce: String(request.nonce),
|
|
504
|
-
signature: normalizeHex(request.signature)
|
|
505
|
-
}
|
|
506
|
-
);
|
|
507
|
-
}
|
|
508
|
-
async requestWithdrawal(request) {
|
|
509
|
-
return this.http.post("/v1/accounting/withdraw", {
|
|
510
|
-
token_id: normalizeHex(request.token_id),
|
|
511
|
-
amount: String(request.amount),
|
|
512
|
-
nonce: String(request.nonce),
|
|
513
|
-
signature: normalizeHex(request.signature)
|
|
514
|
-
});
|
|
515
|
-
}
|
|
516
|
-
async getWithdrawalNonce(userAddress) {
|
|
517
|
-
const user = normalizeAddress(userAddress);
|
|
518
|
-
return this.http.get(`/v1/accounting/withdraw/nonce/${user}`);
|
|
519
|
-
}
|
|
520
|
-
async getTransferLockedNonce(serviceAddress) {
|
|
521
|
-
const service = normalizeAddress(serviceAddress);
|
|
522
|
-
return this.http.get(
|
|
523
|
-
`/v1/accounting/funds/transfer-locked/nonce/${service}`
|
|
524
|
-
);
|
|
525
|
-
}
|
|
526
|
-
async getPendingWithdrawals(userAddress) {
|
|
527
|
-
const user = normalizeAddress(userAddress);
|
|
528
|
-
return this.http.get(`/v1/accounting/withdraw/pending/${user}`);
|
|
529
|
-
}
|
|
530
|
-
async getWithdrawalInfo(index) {
|
|
531
|
-
return this.http.get(`/v1/accounting/withdraw/${index}`);
|
|
532
|
-
}
|
|
533
|
-
async getSiweDomain() {
|
|
534
|
-
return this.http.get("/v1/accounting/auth/domain");
|
|
535
|
-
}
|
|
536
|
-
async getSiweNonce(userAddress) {
|
|
537
|
-
const user = normalizeAddress(userAddress);
|
|
538
|
-
return this.http.get(`/v1/accounting/auth/nonce?address=${user}`);
|
|
539
|
-
}
|
|
540
|
-
async loginWithSiwe(request) {
|
|
541
|
-
return this.http.post("/v1/accounting/auth/login", {
|
|
542
|
-
siwe_message: request.siwe_message,
|
|
543
|
-
signature: normalizeHex(request.signature)
|
|
544
|
-
});
|
|
545
|
-
}
|
|
546
|
-
getHostedAuthAuthorizeUrl(request) {
|
|
547
|
-
const url = new URL(
|
|
548
|
-
"v1/accounting/auth/authorize",
|
|
549
|
-
`${this.http.getBaseUrl().replace(/\/$/, "")}/`
|
|
550
|
-
);
|
|
551
|
-
url.searchParams.set("client_id", request.client_id);
|
|
552
|
-
url.searchParams.set("redirect_uri", request.redirect_uri);
|
|
553
|
-
url.searchParams.set("code_challenge", request.code_challenge);
|
|
554
|
-
url.searchParams.set("state", request.state);
|
|
555
|
-
url.searchParams.set("chain_id", String(request.chain_id));
|
|
556
|
-
url.searchParams.set("response_mode", request.response_mode ?? "redirect");
|
|
557
|
-
url.searchParams.set("code_challenge_method", request.code_challenge_method ?? "S256");
|
|
558
|
-
return url.toString();
|
|
559
|
-
}
|
|
560
|
-
async exchangeHostedAuthCode(request) {
|
|
561
|
-
return this.http.post("/v1/accounting/auth/token", {
|
|
562
|
-
grant_type: request.grant_type ?? "authorization_code",
|
|
563
|
-
code: request.code,
|
|
564
|
-
code_verifier: request.code_verifier,
|
|
565
|
-
client_id: request.client_id,
|
|
566
|
-
redirect_uri: request.redirect_uri
|
|
567
|
-
});
|
|
568
|
-
}
|
|
569
|
-
async refreshJwtSession(request) {
|
|
570
|
-
return this.http.post("/v1/accounting/auth/jwt/refresh", {
|
|
571
|
-
refresh_token: request.refresh_token
|
|
572
|
-
});
|
|
573
|
-
}
|
|
574
|
-
async logoutJwtSession(request = {}) {
|
|
575
|
-
return this.http.post("/v1/accounting/auth/jwt/logout", {
|
|
576
|
-
refresh_token: request.refresh_token,
|
|
577
|
-
revoke_all: request.revoke_all ?? false
|
|
578
|
-
});
|
|
579
|
-
}
|
|
580
|
-
setPrivateReadToken(token) {
|
|
581
|
-
this.http.removeHeader("Authorization");
|
|
582
|
-
this.http.setHeader(PRIVATE_READ_TOKEN_HEADER, token);
|
|
583
|
-
}
|
|
584
|
-
getPrivateReadToken() {
|
|
585
|
-
return this.http.getHeader(PRIVATE_READ_TOKEN_HEADER);
|
|
586
|
-
}
|
|
587
|
-
clearPrivateReadToken() {
|
|
588
|
-
this.http.removeHeader(PRIVATE_READ_TOKEN_HEADER);
|
|
589
|
-
}
|
|
590
|
-
setBearerToken(token) {
|
|
591
|
-
this.http.removeHeader(PRIVATE_READ_TOKEN_HEADER);
|
|
592
|
-
this.http.setHeader("Authorization", `Bearer ${token}`);
|
|
593
|
-
}
|
|
594
|
-
clearBearerToken() {
|
|
595
|
-
this.http.removeHeader("Authorization");
|
|
596
|
-
}
|
|
597
|
-
};
|
|
598
|
-
|
|
599
34
|
// src/sdk/signatures/eip712-types.ts
|
|
600
35
|
function createDomain(chainId, verifyingContract) {
|
|
601
36
|
return {
|
|
@@ -791,309 +226,21 @@ async function signWithdrawFromLockMessage({
|
|
|
791
226
|
});
|
|
792
227
|
return signature;
|
|
793
228
|
}
|
|
794
|
-
var PrivanaContext = react.createContext(null);
|
|
795
|
-
function readStoredHostedAuthSession(storage, hostedAuthStorageKey, now = Date.now()) {
|
|
796
|
-
const raw = storage.getItem(hostedAuthStorageKey);
|
|
797
|
-
if (!raw) {
|
|
798
|
-
return null;
|
|
799
|
-
}
|
|
800
|
-
try {
|
|
801
|
-
const parsed = JSON.parse(raw);
|
|
802
|
-
if (!isHostedAuthRefreshActive(parsed, now, 0)) {
|
|
803
|
-
storage.removeItem(hostedAuthStorageKey);
|
|
804
|
-
return null;
|
|
805
|
-
}
|
|
806
|
-
return parsed;
|
|
807
|
-
} catch {
|
|
808
|
-
storage.removeItem(hostedAuthStorageKey);
|
|
809
|
-
return null;
|
|
810
|
-
}
|
|
811
|
-
}
|
|
812
|
-
function syncHostedAuthSessionToClient(client, hostedAuthConfig, hostedAuthSession) {
|
|
813
|
-
if (!hostedAuthConfig) {
|
|
814
|
-
client.clearBearerToken();
|
|
815
|
-
client.clearPrivateReadToken();
|
|
816
|
-
return;
|
|
817
|
-
}
|
|
818
|
-
if (hostedAuthSession && isHostedAuthSessionActive(hostedAuthSession)) {
|
|
819
|
-
client.setBearerToken(hostedAuthSession.accessToken);
|
|
820
|
-
client.clearPrivateReadToken();
|
|
821
|
-
return;
|
|
822
|
-
}
|
|
823
|
-
client.clearBearerToken();
|
|
824
|
-
client.clearPrivateReadToken();
|
|
825
|
-
}
|
|
826
|
-
var DEFAULT_NETWORK_CONFIG = NETWORK_CONFIG.testnet;
|
|
827
|
-
function PrivanaProvider({
|
|
828
|
-
children,
|
|
829
|
-
networkConfig: networkConfigOverride,
|
|
830
|
-
tokens,
|
|
831
|
-
chains,
|
|
832
|
-
pollingInterval = 1e4,
|
|
833
|
-
serviceAddress,
|
|
834
|
-
hostedAuth
|
|
835
|
-
}) {
|
|
836
|
-
const networkConfig = react.useMemo(() => {
|
|
837
|
-
const config = {
|
|
838
|
-
...DEFAULT_NETWORK_CONFIG,
|
|
839
|
-
...networkConfigOverride
|
|
840
|
-
};
|
|
841
|
-
if (!config.chainId || config.chainId <= 0) {
|
|
842
|
-
throw new Error("PrivanaProvider: networkConfig.chainId must be a positive number");
|
|
843
|
-
}
|
|
844
|
-
if (!config.accountingContract || !config.accountingContract.startsWith("0x")) {
|
|
845
|
-
throw new Error("PrivanaProvider: networkConfig.accountingContract must be a valid address");
|
|
846
|
-
}
|
|
847
|
-
if (!config.apiUrl) {
|
|
848
|
-
throw new Error("PrivanaProvider: networkConfig.apiUrl must be provided");
|
|
849
|
-
}
|
|
850
|
-
return config;
|
|
851
|
-
}, [
|
|
852
|
-
networkConfigOverride?.chainId,
|
|
853
|
-
networkConfigOverride?.name,
|
|
854
|
-
networkConfigOverride?.accountingContract,
|
|
855
|
-
networkConfigOverride?.apiUrl
|
|
856
|
-
]);
|
|
857
|
-
const resolvedChains = react.useMemo(() => {
|
|
858
|
-
if (chains && chains.length > 0) return chains;
|
|
859
|
-
return SUPPORTED_CHAINS;
|
|
860
|
-
}, [chains]);
|
|
861
|
-
const client = react.useMemo(
|
|
862
|
-
() => new PrivanaClient({ baseUrl: networkConfig.apiUrl }),
|
|
863
|
-
[networkConfig.apiUrl]
|
|
864
|
-
);
|
|
865
|
-
const [allTokens, setAllTokens] = react.useState([]);
|
|
866
|
-
const [tokensStatus, setTokensStatus] = react.useState("loading");
|
|
867
|
-
const [tokensError, setTokensError] = react.useState();
|
|
868
|
-
react.useEffect(() => {
|
|
869
|
-
setTokensStatus("loading");
|
|
870
|
-
setTokensError(void 0);
|
|
871
|
-
client.listTokens().then(({ tokens: list }) => {
|
|
872
|
-
setAllTokens(
|
|
873
|
-
list.map((t) => ({
|
|
874
|
-
id: t.token_id,
|
|
875
|
-
symbol: t.symbol,
|
|
876
|
-
decimals: t.decimals,
|
|
877
|
-
contract: t.token_address ?? viem.zeroAddress,
|
|
878
|
-
name: t.name,
|
|
879
|
-
chainId: t.chain_id
|
|
880
|
-
}))
|
|
881
|
-
);
|
|
882
|
-
setTokensStatus("ready");
|
|
883
|
-
}).catch((err) => {
|
|
884
|
-
setTokensError(err instanceof Error ? err : new Error(String(err)));
|
|
885
|
-
setTokensStatus("error");
|
|
886
|
-
});
|
|
887
|
-
}, [client]);
|
|
888
|
-
const enabledTokens = react.useMemo(() => {
|
|
889
|
-
if (tokens && tokens.length > 0) {
|
|
890
|
-
const allowed = new Set(tokens.map((id) => id.toLowerCase()));
|
|
891
|
-
return allTokens.filter((t) => allowed.has(t.id.toLowerCase()));
|
|
892
|
-
}
|
|
893
|
-
return allTokens;
|
|
894
|
-
}, [allTokens, tokens]);
|
|
895
|
-
const tokenById = react.useMemo(
|
|
896
|
-
() => Object.fromEntries(enabledTokens.map((t) => [t.id.toLowerCase(), t])),
|
|
897
|
-
[enabledTokens]
|
|
898
|
-
);
|
|
899
|
-
const getTokenById = react.useMemo(() => (id) => tokenById[id.toLowerCase()], [tokenById]);
|
|
900
|
-
const chainById = react.useMemo(
|
|
901
|
-
() => Object.fromEntries(resolvedChains.map((c) => [c.id, c])),
|
|
902
|
-
[resolvedChains]
|
|
903
|
-
);
|
|
904
|
-
const getChainById2 = react.useMemo(() => (id) => chainById[id], [chainById]);
|
|
905
|
-
const hostedAuthConfig = react.useMemo(() => {
|
|
906
|
-
if (!hostedAuth) return null;
|
|
907
|
-
const clientId = hostedAuth.clientId.trim();
|
|
908
|
-
const redirectUri = hostedAuth.redirectUri.trim();
|
|
909
|
-
if (!clientId) {
|
|
910
|
-
throw new Error(
|
|
911
|
-
"PrivanaProvider: hostedAuth.clientId must be provided when hostedAuth is enabled"
|
|
912
|
-
);
|
|
913
|
-
}
|
|
914
|
-
if (!redirectUri) {
|
|
915
|
-
throw new Error(
|
|
916
|
-
"PrivanaProvider: hostedAuth.redirectUri must be provided when hostedAuth is enabled"
|
|
917
|
-
);
|
|
918
|
-
}
|
|
919
|
-
return {
|
|
920
|
-
clientId,
|
|
921
|
-
redirectUri
|
|
922
|
-
};
|
|
923
|
-
}, [hostedAuth]);
|
|
924
|
-
const hostedAuthStorageKey = react.useMemo(
|
|
925
|
-
() => hostedAuthConfig ? createHostedAuthStorageKey(networkConfig.apiUrl, hostedAuthConfig) : null,
|
|
926
|
-
[hostedAuthConfig, networkConfig.apiUrl]
|
|
927
|
-
);
|
|
928
|
-
const [hostedAuthSession, setHostedAuthSessionState] = react.useState(null);
|
|
929
|
-
const hostedAuthSessionRef = react.useRef(null);
|
|
930
|
-
const hostedAuthStateVersionRef = react.useRef(0);
|
|
931
|
-
const hostedAuthRefreshInflight = react.useRef(null);
|
|
932
|
-
const clearHostedAuthSession = react.useCallback(() => {
|
|
933
|
-
hostedAuthStateVersionRef.current += 1;
|
|
934
|
-
hostedAuthSessionRef.current = null;
|
|
935
|
-
hostedAuthRefreshInflight.current = null;
|
|
936
|
-
setHostedAuthSessionState(null);
|
|
937
|
-
client.clearBearerToken();
|
|
938
|
-
client.clearPrivateReadToken();
|
|
939
|
-
if (hostedAuthStorageKey && typeof window !== "undefined") {
|
|
940
|
-
window.sessionStorage.removeItem(hostedAuthStorageKey);
|
|
941
|
-
}
|
|
942
|
-
}, [client, hostedAuthStorageKey]);
|
|
943
|
-
const setHostedAuthSession = react.useCallback(
|
|
944
|
-
(session) => {
|
|
945
|
-
if (!session) {
|
|
946
|
-
clearHostedAuthSession();
|
|
947
|
-
return;
|
|
948
|
-
}
|
|
949
|
-
hostedAuthStateVersionRef.current += 1;
|
|
950
|
-
hostedAuthSessionRef.current = session;
|
|
951
|
-
setHostedAuthSessionState(session);
|
|
952
|
-
if (isHostedAuthSessionActive(session)) {
|
|
953
|
-
client.setBearerToken(session.accessToken);
|
|
954
|
-
} else {
|
|
955
|
-
client.clearBearerToken();
|
|
956
|
-
}
|
|
957
|
-
client.clearPrivateReadToken();
|
|
958
|
-
if (hostedAuthStorageKey && typeof window !== "undefined") {
|
|
959
|
-
window.sessionStorage.setItem(hostedAuthStorageKey, JSON.stringify(session));
|
|
960
|
-
}
|
|
961
|
-
},
|
|
962
|
-
[clearHostedAuthSession, client, hostedAuthStorageKey]
|
|
963
|
-
);
|
|
964
|
-
const refreshHostedAuthSession = react.useCallback(async () => {
|
|
965
|
-
if (!hostedAuthConfig) {
|
|
966
|
-
throw new HostedAuthRequiredError(
|
|
967
|
-
"Hosted redirect authentication is not configured for this provider."
|
|
968
|
-
);
|
|
969
|
-
}
|
|
970
|
-
const currentSession = hostedAuthSessionRef.current;
|
|
971
|
-
if (!currentSession) {
|
|
972
|
-
throw new HostedAuthRequiredError();
|
|
973
|
-
}
|
|
974
|
-
if (!isHostedAuthRefreshActive(currentSession)) {
|
|
975
|
-
clearHostedAuthSession();
|
|
976
|
-
throw new HostedAuthRequiredError(
|
|
977
|
-
"Hosted redirect authentication has expired. Start login again."
|
|
978
|
-
);
|
|
979
|
-
}
|
|
980
|
-
if (hostedAuthRefreshInflight.current) {
|
|
981
|
-
return hostedAuthRefreshInflight.current;
|
|
982
|
-
}
|
|
983
|
-
const refreshPromise = (async () => {
|
|
984
|
-
const refreshVersion = hostedAuthStateVersionRef.current;
|
|
985
|
-
try {
|
|
986
|
-
const response = await client.refreshJwtSession({
|
|
987
|
-
refresh_token: currentSession.refreshToken
|
|
988
|
-
});
|
|
989
|
-
if (refreshVersion !== hostedAuthStateVersionRef.current) {
|
|
990
|
-
const latestSession = hostedAuthSessionRef.current;
|
|
991
|
-
if (latestSession) {
|
|
992
|
-
return latestSession;
|
|
993
|
-
}
|
|
994
|
-
throw new HostedAuthRequiredError(
|
|
995
|
-
"Hosted redirect authentication has changed. Start login again."
|
|
996
|
-
);
|
|
997
|
-
}
|
|
998
|
-
const nextSession = applyRefreshResponse(currentSession, response);
|
|
999
|
-
setHostedAuthSession(nextSession);
|
|
1000
|
-
return nextSession;
|
|
1001
|
-
} catch (error) {
|
|
1002
|
-
if (refreshVersion === hostedAuthStateVersionRef.current) {
|
|
1003
|
-
clearHostedAuthSession();
|
|
1004
|
-
}
|
|
1005
|
-
throw error;
|
|
1006
|
-
} finally {
|
|
1007
|
-
hostedAuthRefreshInflight.current = null;
|
|
1008
|
-
}
|
|
1009
|
-
})();
|
|
1010
|
-
hostedAuthRefreshInflight.current = refreshPromise;
|
|
1011
|
-
return refreshPromise;
|
|
1012
|
-
}, [clearHostedAuthSession, client, hostedAuthConfig, setHostedAuthSession]);
|
|
1013
|
-
react.useEffect(() => {
|
|
1014
|
-
hostedAuthSessionRef.current = hostedAuthSession;
|
|
1015
|
-
}, [hostedAuthSession]);
|
|
1016
|
-
react.useEffect(() => {
|
|
1017
|
-
if (!hostedAuthStorageKey || typeof window === "undefined") {
|
|
1018
|
-
hostedAuthStateVersionRef.current += 1;
|
|
1019
|
-
hostedAuthSessionRef.current = null;
|
|
1020
|
-
hostedAuthRefreshInflight.current = null;
|
|
1021
|
-
setHostedAuthSessionState(null);
|
|
1022
|
-
return;
|
|
1023
|
-
}
|
|
1024
|
-
const restoredSession = readStoredHostedAuthSession(window.sessionStorage, hostedAuthStorageKey);
|
|
1025
|
-
hostedAuthStateVersionRef.current += 1;
|
|
1026
|
-
hostedAuthSessionRef.current = restoredSession;
|
|
1027
|
-
hostedAuthRefreshInflight.current = null;
|
|
1028
|
-
setHostedAuthSessionState(restoredSession);
|
|
1029
|
-
}, [hostedAuthStorageKey]);
|
|
1030
|
-
react.useEffect(() => {
|
|
1031
|
-
syncHostedAuthSessionToClient(client, hostedAuthConfig, hostedAuthSession);
|
|
1032
|
-
}, [client, hostedAuthConfig, hostedAuthSession]);
|
|
1033
|
-
const value = react.useMemo(
|
|
1034
|
-
() => ({
|
|
1035
|
-
client,
|
|
1036
|
-
networkConfig,
|
|
1037
|
-
enabledTokens,
|
|
1038
|
-
defaultToken: enabledTokens[0],
|
|
1039
|
-
getTokenById,
|
|
1040
|
-
getChainById: getChainById2,
|
|
1041
|
-
chains: resolvedChains,
|
|
1042
|
-
tokensStatus,
|
|
1043
|
-
tokensError,
|
|
1044
|
-
pollingInterval,
|
|
1045
|
-
serviceAddress,
|
|
1046
|
-
hostedAuthConfig,
|
|
1047
|
-
hostedAuthSession,
|
|
1048
|
-
setHostedAuthSession,
|
|
1049
|
-
clearHostedAuthSession,
|
|
1050
|
-
refreshHostedAuthSession
|
|
1051
|
-
}),
|
|
1052
|
-
[
|
|
1053
|
-
client,
|
|
1054
|
-
networkConfig,
|
|
1055
|
-
enabledTokens,
|
|
1056
|
-
getTokenById,
|
|
1057
|
-
getChainById2,
|
|
1058
|
-
resolvedChains,
|
|
1059
|
-
tokensStatus,
|
|
1060
|
-
tokensError,
|
|
1061
|
-
pollingInterval,
|
|
1062
|
-
serviceAddress,
|
|
1063
|
-
hostedAuthConfig,
|
|
1064
|
-
hostedAuthSession,
|
|
1065
|
-
setHostedAuthSession,
|
|
1066
|
-
clearHostedAuthSession,
|
|
1067
|
-
refreshHostedAuthSession
|
|
1068
|
-
]
|
|
1069
|
-
);
|
|
1070
|
-
return /* @__PURE__ */ jsxRuntime.jsx(PrivanaContext.Provider, { value, children });
|
|
1071
|
-
}
|
|
1072
|
-
function usePrivanaContext() {
|
|
1073
|
-
const context = react.useContext(PrivanaContext);
|
|
1074
|
-
if (!context) {
|
|
1075
|
-
throw new Error("usePrivanaContext must be used within a PrivanaProvider");
|
|
1076
|
-
}
|
|
1077
|
-
return context;
|
|
1078
|
-
}
|
|
1079
|
-
function useSafePrivanaContext() {
|
|
1080
|
-
return react.useContext(PrivanaContext);
|
|
1081
|
-
}
|
|
1082
229
|
|
|
1083
230
|
// src/sdk/hooks/use-privana-client.ts
|
|
1084
231
|
function usePrivanaClient() {
|
|
1085
|
-
const { client } = usePrivanaContext();
|
|
232
|
+
const { client } = chunkRDMJGMI3_cjs.usePrivanaContext();
|
|
1086
233
|
return client;
|
|
1087
234
|
}
|
|
1088
235
|
var hostedAuthExchangeInflight = /* @__PURE__ */ new Map();
|
|
1089
236
|
function normalizeHostedAuthError(error) {
|
|
1090
|
-
if (error instanceof AccountingApiError && error.detail) {
|
|
1091
|
-
return new HostedAuthError(error.detail);
|
|
237
|
+
if (error instanceof chunkRDMJGMI3_cjs.AccountingApiError && error.detail) {
|
|
238
|
+
return new chunkRDMJGMI3_cjs.HostedAuthError(error.detail);
|
|
1092
239
|
}
|
|
1093
240
|
if (error instanceof Error) {
|
|
1094
241
|
return error;
|
|
1095
242
|
}
|
|
1096
|
-
return new HostedAuthError("Hosted authentication failed.");
|
|
243
|
+
return new chunkRDMJGMI3_cjs.HostedAuthError("Hosted authentication failed.");
|
|
1097
244
|
}
|
|
1098
245
|
function useHostedRedirectAuth() {
|
|
1099
246
|
const {
|
|
@@ -1104,30 +251,30 @@ function useHostedRedirectAuth() {
|
|
|
1104
251
|
setHostedAuthSession,
|
|
1105
252
|
clearHostedAuthSession,
|
|
1106
253
|
refreshHostedAuthSession
|
|
1107
|
-
} = usePrivanaContext();
|
|
254
|
+
} = chunkRDMJGMI3_cjs.usePrivanaContext();
|
|
1108
255
|
const [error, setError] = react.useState(null);
|
|
1109
256
|
const [isLoading, setIsLoading] = react.useState(false);
|
|
1110
257
|
const loginInflight = react.useRef(null);
|
|
1111
258
|
const completionInflight = react.useRef(null);
|
|
1112
259
|
const pendingStorageKey = react.useMemo(
|
|
1113
|
-
() => hostedAuthConfig ? createHostedAuthPendingStorageKey(client.getBaseUrl(), hostedAuthConfig) : null,
|
|
260
|
+
() => hostedAuthConfig ? chunkRDMJGMI3_cjs.createHostedAuthPendingStorageKey(client.getBaseUrl(), hostedAuthConfig) : null,
|
|
1114
261
|
[client, hostedAuthConfig]
|
|
1115
262
|
);
|
|
1116
263
|
const clearPendingLogin = react.useCallback(() => {
|
|
1117
264
|
if (!pendingStorageKey || typeof window === "undefined") return;
|
|
1118
|
-
clearHostedAuthPendingTransaction(window.sessionStorage, pendingStorageKey);
|
|
265
|
+
chunkRDMJGMI3_cjs.clearHostedAuthPendingTransaction(window.sessionStorage, pendingStorageKey);
|
|
1119
266
|
}, [pendingStorageKey]);
|
|
1120
267
|
const login = react.useCallback(async () => {
|
|
1121
268
|
if (!hostedAuthConfig) {
|
|
1122
|
-
throw new HostedAuthRequiredError(
|
|
269
|
+
throw new chunkRDMJGMI3_cjs.HostedAuthRequiredError(
|
|
1123
270
|
"Hosted redirect authentication is not configured for this provider."
|
|
1124
271
|
);
|
|
1125
272
|
}
|
|
1126
273
|
if (typeof window === "undefined") {
|
|
1127
|
-
throw new HostedAuthError("Hosted redirect authentication requires a browser environment.");
|
|
274
|
+
throw new chunkRDMJGMI3_cjs.HostedAuthError("Hosted redirect authentication requires a browser environment.");
|
|
1128
275
|
}
|
|
1129
276
|
if (!pendingStorageKey) {
|
|
1130
|
-
throw new HostedAuthError("Hosted redirect authentication storage is not configured.");
|
|
277
|
+
throw new chunkRDMJGMI3_cjs.HostedAuthError("Hosted redirect authentication storage is not configured.");
|
|
1131
278
|
}
|
|
1132
279
|
if (loginInflight.current) {
|
|
1133
280
|
return loginInflight.current;
|
|
@@ -1136,10 +283,10 @@ function useHostedRedirectAuth() {
|
|
|
1136
283
|
setIsLoading(true);
|
|
1137
284
|
setError(null);
|
|
1138
285
|
try {
|
|
1139
|
-
const verifier = createPkceVerifier();
|
|
1140
|
-
const codeChallenge = await createPkceChallenge(verifier);
|
|
1141
|
-
const state = createHostedAuthState();
|
|
1142
|
-
persistHostedAuthPendingTransaction(window.sessionStorage, pendingStorageKey, {
|
|
286
|
+
const verifier = chunkRDMJGMI3_cjs.createPkceVerifier();
|
|
287
|
+
const codeChallenge = await chunkRDMJGMI3_cjs.createPkceChallenge(verifier);
|
|
288
|
+
const state = chunkRDMJGMI3_cjs.createHostedAuthState();
|
|
289
|
+
chunkRDMJGMI3_cjs.persistHostedAuthPendingTransaction(window.sessionStorage, pendingStorageKey, {
|
|
1143
290
|
codeVerifier: verifier,
|
|
1144
291
|
state
|
|
1145
292
|
});
|
|
@@ -1168,15 +315,15 @@ function useHostedRedirectAuth() {
|
|
|
1168
315
|
}, [clearPendingLogin, client, hostedAuthConfig, networkConfig.chainId, pendingStorageKey]);
|
|
1169
316
|
const completeLogin = react.useCallback(async () => {
|
|
1170
317
|
if (!hostedAuthConfig) {
|
|
1171
|
-
throw new HostedAuthRequiredError(
|
|
318
|
+
throw new chunkRDMJGMI3_cjs.HostedAuthRequiredError(
|
|
1172
319
|
"Hosted redirect authentication is not configured for this provider."
|
|
1173
320
|
);
|
|
1174
321
|
}
|
|
1175
322
|
if (typeof window === "undefined") {
|
|
1176
|
-
throw new HostedAuthError("Hosted redirect authentication requires a browser environment.");
|
|
323
|
+
throw new chunkRDMJGMI3_cjs.HostedAuthError("Hosted redirect authentication requires a browser environment.");
|
|
1177
324
|
}
|
|
1178
325
|
if (!pendingStorageKey) {
|
|
1179
|
-
throw new HostedAuthError("Hosted redirect authentication storage is not configured.");
|
|
326
|
+
throw new chunkRDMJGMI3_cjs.HostedAuthError("Hosted redirect authentication storage is not configured.");
|
|
1180
327
|
}
|
|
1181
328
|
if (completionInflight.current) {
|
|
1182
329
|
return completionInflight.current;
|
|
@@ -1186,30 +333,30 @@ function useHostedRedirectAuth() {
|
|
|
1186
333
|
setError(null);
|
|
1187
334
|
const callbackUrl = new URL(window.location.href);
|
|
1188
335
|
const cleanupCallbackUrl = () => {
|
|
1189
|
-
window.history.replaceState(null, "", stripHostedAuthCallbackParams(callbackUrl));
|
|
336
|
+
window.history.replaceState(null, "", chunkRDMJGMI3_cjs.stripHostedAuthCallbackParams(callbackUrl));
|
|
1190
337
|
};
|
|
1191
338
|
try {
|
|
1192
|
-
const callback = parseHostedAuthCallback(callbackUrl, hostedAuthConfig.redirectUri);
|
|
339
|
+
const callback = chunkRDMJGMI3_cjs.parseHostedAuthCallback(callbackUrl, hostedAuthConfig.redirectUri);
|
|
1193
340
|
if (!callback) {
|
|
1194
341
|
return null;
|
|
1195
342
|
}
|
|
1196
|
-
const pending = readHostedAuthPendingTransaction(window.sessionStorage, pendingStorageKey);
|
|
343
|
+
const pending = chunkRDMJGMI3_cjs.readHostedAuthPendingTransaction(window.sessionStorage, pendingStorageKey);
|
|
1197
344
|
if (!pending) {
|
|
1198
345
|
clearPendingLogin();
|
|
1199
346
|
cleanupCallbackUrl();
|
|
1200
|
-
throw new HostedAuthError(
|
|
347
|
+
throw new chunkRDMJGMI3_cjs.HostedAuthError(
|
|
1201
348
|
"Hosted authentication response could not be matched to a pending login request."
|
|
1202
349
|
);
|
|
1203
350
|
}
|
|
1204
351
|
if (!callback.state || callback.state !== pending.state) {
|
|
1205
352
|
clearPendingLogin();
|
|
1206
353
|
cleanupCallbackUrl();
|
|
1207
|
-
throw new HostedAuthStateMismatchError();
|
|
354
|
+
throw new chunkRDMJGMI3_cjs.HostedAuthStateMismatchError();
|
|
1208
355
|
}
|
|
1209
356
|
if ("error" in callback) {
|
|
1210
357
|
clearPendingLogin();
|
|
1211
358
|
cleanupCallbackUrl();
|
|
1212
|
-
throw new HostedAuthError(
|
|
359
|
+
throw new chunkRDMJGMI3_cjs.HostedAuthError(
|
|
1213
360
|
callback.errorDescription || callback.error || "Hosted authentication failed."
|
|
1214
361
|
);
|
|
1215
362
|
}
|
|
@@ -1224,7 +371,7 @@ function useHostedRedirectAuth() {
|
|
|
1224
371
|
client_id: hostedAuthConfig.clientId,
|
|
1225
372
|
redirect_uri: hostedAuthConfig.redirectUri
|
|
1226
373
|
});
|
|
1227
|
-
const session = buildHostedAuthSession(response, hostedAuthConfig);
|
|
374
|
+
const session = chunkRDMJGMI3_cjs.buildHostedAuthSession(response, hostedAuthConfig);
|
|
1228
375
|
setHostedAuthSession(session);
|
|
1229
376
|
clearPendingLogin();
|
|
1230
377
|
cleanupCallbackUrl();
|
|
@@ -1269,7 +416,7 @@ function useHostedRedirectAuth() {
|
|
|
1269
416
|
try {
|
|
1270
417
|
return await refreshHostedAuthSession();
|
|
1271
418
|
} catch (refreshError) {
|
|
1272
|
-
const normalizedError = refreshError instanceof Error ? refreshError : new HostedAuthError("Hosted authentication refresh failed.");
|
|
419
|
+
const normalizedError = refreshError instanceof Error ? refreshError : new chunkRDMJGMI3_cjs.HostedAuthError("Hosted authentication refresh failed.");
|
|
1273
420
|
setError(normalizedError);
|
|
1274
421
|
throw normalizedError;
|
|
1275
422
|
} finally {
|
|
@@ -1287,288 +434,14 @@ function useHostedRedirectAuth() {
|
|
|
1287
434
|
refresh
|
|
1288
435
|
};
|
|
1289
436
|
}
|
|
1290
|
-
function cn(...inputs) {
|
|
1291
|
-
return tailwindMerge.twMerge(clsx.clsx(inputs));
|
|
1292
|
-
}
|
|
1293
|
-
function formatTokenAmount(amount, decimals = 18) {
|
|
1294
|
-
const value = typeof amount === "string" ? BigInt(amount) : amount;
|
|
1295
|
-
const divisor = BigInt(10 ** decimals);
|
|
1296
|
-
const integerPart = value / divisor;
|
|
1297
|
-
const fractionalPart = value % divisor;
|
|
1298
|
-
const fractionalStr = fractionalPart.toString().padStart(decimals, "0");
|
|
1299
|
-
const twoDecimals = fractionalStr.slice(0, 2).padEnd(2, "0");
|
|
1300
|
-
const integerWithSpaces = integerPart.toString().replace(/\B(?=(\d{3})+(?!\d))/g, "\u2009");
|
|
1301
|
-
return `${integerWithSpaces}.${twoDecimals}`;
|
|
1302
|
-
}
|
|
1303
|
-
function parseTokenAmount(amount, decimals = 18) {
|
|
1304
|
-
const sanitized = amount.replace(/[\s\u2009]/g, "").replace(/,/g, ".");
|
|
1305
|
-
const lastDot = sanitized.lastIndexOf(".");
|
|
1306
|
-
const integerPart = lastDot === -1 ? sanitized : sanitized.slice(0, lastDot).replace(/\./g, "");
|
|
1307
|
-
const fractionalPart = lastDot === -1 ? "" : sanitized.slice(lastDot + 1);
|
|
1308
|
-
const paddedFractional = fractionalPart.padEnd(decimals, "0").slice(0, decimals);
|
|
1309
|
-
return BigInt(integerPart + paddedFractional);
|
|
1310
|
-
}
|
|
1311
|
-
function shortenAddress(address, chars = 4) {
|
|
1312
|
-
if (!address || address.length < chars * 2 + 2) return address;
|
|
1313
|
-
return `${address.slice(0, chars + 2)}...${address.slice(-chars)}`;
|
|
1314
|
-
}
|
|
1315
|
-
function formatTimeRemaining(expiryTimestamp) {
|
|
1316
|
-
const now = Math.floor(Date.now() / 1e3);
|
|
1317
|
-
const diff = expiryTimestamp - now;
|
|
1318
|
-
if (diff <= 0) return "Expired";
|
|
1319
|
-
const days = Math.floor(diff / 86400);
|
|
1320
|
-
const hours = Math.floor(diff % 86400 / 3600);
|
|
1321
|
-
const minutes = Math.floor(diff % 3600 / 60);
|
|
1322
|
-
if (days > 0) {
|
|
1323
|
-
return hours > 0 ? `${days}d ${hours}h left` : `${days}d left`;
|
|
1324
|
-
}
|
|
1325
|
-
if (hours > 0) {
|
|
1326
|
-
return minutes > 0 ? `${hours}h ${minutes}m left` : `${hours}h left`;
|
|
1327
|
-
}
|
|
1328
|
-
return `${minutes}m left`;
|
|
1329
|
-
}
|
|
1330
|
-
var defaultResult = {
|
|
1331
|
-
address: void 0,
|
|
1332
|
-
isConnected: false
|
|
1333
|
-
};
|
|
1334
|
-
function useSafeAccount() {
|
|
1335
|
-
const context = react.useContext(wagmi.WagmiContext);
|
|
1336
|
-
const cacheRef = react.useRef(defaultResult);
|
|
1337
|
-
const subscribe = react.useCallback(
|
|
1338
|
-
(onChange) => {
|
|
1339
|
-
if (!context) return () => {
|
|
1340
|
-
};
|
|
1341
|
-
return actions.watchAccount(context, { onChange });
|
|
1342
|
-
},
|
|
1343
|
-
[context]
|
|
1344
|
-
);
|
|
1345
|
-
const getSnapshot = react.useCallback(() => {
|
|
1346
|
-
if (!context) return defaultResult;
|
|
1347
|
-
const account = actions.getAccount(context);
|
|
1348
|
-
if (cacheRef.current.address !== account.address || cacheRef.current.isConnected !== account.isConnected) {
|
|
1349
|
-
cacheRef.current = { address: account.address, isConnected: account.isConnected };
|
|
1350
|
-
}
|
|
1351
|
-
return cacheRef.current;
|
|
1352
|
-
}, [context]);
|
|
1353
|
-
const getServerSnapshot = react.useCallback(() => defaultResult, []);
|
|
1354
|
-
return react.useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
|
|
1355
|
-
}
|
|
1356
|
-
|
|
1357
|
-
// src/sdk/hooks/use-private-read-request.ts
|
|
1358
|
-
var AUTH_CLOCK_SKEW_MS = 3e4;
|
|
1359
|
-
var INITIAL_AUTH_BACKOFF_MS = 5e3;
|
|
1360
|
-
var MAX_AUTH_BACKOFF_MS = 6e4;
|
|
1361
|
-
var DEFAULT_SIWE_AUTH_VALIDITY_MS = 24 * 60 * 60 * 1e3;
|
|
1362
|
-
var PRIVATE_READ_STATEMENT = "Sign in to Privana to access private account data.";
|
|
1363
|
-
var privateReadTokenCache = /* @__PURE__ */ new Map();
|
|
1364
|
-
var privateReadFailureCache = /* @__PURE__ */ new Map();
|
|
1365
|
-
var privateReadInflight = /* @__PURE__ */ new Map();
|
|
1366
|
-
async function executeHostedAuthPrivateReadRequest({
|
|
1367
|
-
client,
|
|
1368
|
-
hostedAuthSession,
|
|
1369
|
-
refreshHostedAuthSession,
|
|
1370
|
-
request
|
|
1371
|
-
}) {
|
|
1372
|
-
const ensureHostedAuth = async (forceRefresh) => {
|
|
1373
|
-
if (!hostedAuthSession) {
|
|
1374
|
-
throw new HostedAuthRequiredError();
|
|
1375
|
-
}
|
|
1376
|
-
if (!forceRefresh && isHostedAuthSessionActive(hostedAuthSession)) {
|
|
1377
|
-
client.clearPrivateReadToken();
|
|
1378
|
-
client.setBearerToken(hostedAuthSession.accessToken);
|
|
1379
|
-
return hostedAuthSession.accessToken;
|
|
1380
|
-
}
|
|
1381
|
-
const refreshed = await refreshHostedAuthSession();
|
|
1382
|
-
client.clearPrivateReadToken();
|
|
1383
|
-
client.setBearerToken(refreshed.accessToken);
|
|
1384
|
-
return refreshed.accessToken;
|
|
1385
|
-
};
|
|
1386
|
-
await ensureHostedAuth(false);
|
|
1387
|
-
try {
|
|
1388
|
-
return await request();
|
|
1389
|
-
} catch (error) {
|
|
1390
|
-
if (!(error instanceof AccountingApiError) || error.statusCode !== 401) {
|
|
1391
|
-
throw error;
|
|
1392
|
-
}
|
|
1393
|
-
await ensureHostedAuth(true);
|
|
1394
|
-
return request();
|
|
1395
|
-
}
|
|
1396
|
-
}
|
|
1397
|
-
function createScopeKey(apiUrl, deploymentChainId, address) {
|
|
1398
|
-
return `${apiUrl.replace(/\/$/, "")}:${deploymentChainId}:${address.toLowerCase()}`;
|
|
1399
|
-
}
|
|
1400
|
-
function getCachedPrivateReadToken(scopeKey) {
|
|
1401
|
-
const cached = privateReadTokenCache.get(scopeKey);
|
|
1402
|
-
if (!cached) return null;
|
|
1403
|
-
if (cached.expiresAt <= Date.now() + AUTH_CLOCK_SKEW_MS) {
|
|
1404
|
-
privateReadTokenCache.delete(scopeKey);
|
|
1405
|
-
return null;
|
|
1406
|
-
}
|
|
1407
|
-
return cached.token;
|
|
1408
|
-
}
|
|
1409
|
-
function clearPrivateReadScope(scopeKey, client) {
|
|
1410
|
-
privateReadTokenCache.delete(scopeKey);
|
|
1411
|
-
privateReadFailureCache.delete(scopeKey);
|
|
1412
|
-
client.clearPrivateReadToken();
|
|
1413
|
-
}
|
|
1414
|
-
function recordPrivateReadFailure(scopeKey) {
|
|
1415
|
-
const previous = privateReadFailureCache.get(scopeKey);
|
|
1416
|
-
const backoffMs = Math.min(
|
|
1417
|
-
previous ? previous.backoffMs * 2 : INITIAL_AUTH_BACKOFF_MS,
|
|
1418
|
-
MAX_AUTH_BACKOFF_MS
|
|
1419
|
-
);
|
|
1420
|
-
privateReadFailureCache.set(scopeKey, {
|
|
1421
|
-
backoffMs,
|
|
1422
|
-
retryAt: Date.now() + backoffMs
|
|
1423
|
-
});
|
|
1424
|
-
}
|
|
1425
|
-
function ensureFailureBackoff(scopeKey) {
|
|
1426
|
-
const failure = privateReadFailureCache.get(scopeKey);
|
|
1427
|
-
if (!failure) return;
|
|
1428
|
-
if (failure.retryAt <= Date.now()) {
|
|
1429
|
-
privateReadFailureCache.delete(scopeKey);
|
|
1430
|
-
return;
|
|
1431
|
-
}
|
|
1432
|
-
throw new Error(
|
|
1433
|
-
`Private-read authentication is temporarily paused after a recent failure. Retry in ${Math.ceil(
|
|
1434
|
-
(failure.retryAt - Date.now()) / 1e3
|
|
1435
|
-
)}s.`
|
|
1436
|
-
);
|
|
1437
|
-
}
|
|
1438
|
-
function usePrivateReadRequest() {
|
|
1439
|
-
const wagmiContext = react.useContext(wagmi.WagmiContext);
|
|
1440
|
-
const { client, networkConfig, hostedAuthConfig, hostedAuthSession, refreshHostedAuthSession } = usePrivanaContext();
|
|
1441
|
-
const { address: walletAddress } = useSafeAccount();
|
|
1442
|
-
const privateReadAddress = hostedAuthConfig ? hostedAuthSession?.address ?? null : walletAddress ?? null;
|
|
1443
|
-
const privateReadReady = hostedAuthConfig ? !!hostedAuthSession : !!walletAddress;
|
|
1444
|
-
const executePrivateRead = react.useCallback(
|
|
1445
|
-
async (request) => {
|
|
1446
|
-
if (hostedAuthConfig) {
|
|
1447
|
-
return executeHostedAuthPrivateReadRequest({
|
|
1448
|
-
client,
|
|
1449
|
-
hostedAuthSession,
|
|
1450
|
-
refreshHostedAuthSession,
|
|
1451
|
-
request
|
|
1452
|
-
});
|
|
1453
|
-
}
|
|
1454
|
-
if (!wagmiContext) {
|
|
1455
|
-
throw new Error("WagmiProvider is required for authenticated private reads");
|
|
1456
|
-
}
|
|
1457
|
-
if (!walletAddress) {
|
|
1458
|
-
throw new Error("No wallet connected");
|
|
1459
|
-
}
|
|
1460
|
-
const walletClient = await actions.getWalletClient(wagmiContext);
|
|
1461
|
-
if (!walletClient) {
|
|
1462
|
-
throw new Error("No wallet client available");
|
|
1463
|
-
}
|
|
1464
|
-
const apiUrl = networkConfig.apiUrl;
|
|
1465
|
-
const scopeKey = createScopeKey(apiUrl, networkConfig.chainId, walletAddress);
|
|
1466
|
-
const getToken = async (forceRefresh) => {
|
|
1467
|
-
const inflight = privateReadInflight.get(scopeKey);
|
|
1468
|
-
if (inflight) {
|
|
1469
|
-
const token = await inflight;
|
|
1470
|
-
client.setPrivateReadToken(token);
|
|
1471
|
-
return token;
|
|
1472
|
-
}
|
|
1473
|
-
if (!forceRefresh) {
|
|
1474
|
-
const cached = getCachedPrivateReadToken(scopeKey);
|
|
1475
|
-
if (cached) {
|
|
1476
|
-
client.setPrivateReadToken(cached);
|
|
1477
|
-
return cached;
|
|
1478
|
-
}
|
|
1479
|
-
}
|
|
1480
|
-
ensureFailureBackoff(scopeKey);
|
|
1481
|
-
const authPromise = (async () => {
|
|
1482
|
-
try {
|
|
1483
|
-
const [{ domain }, nonceResponse] = await Promise.all([
|
|
1484
|
-
client.getSiweDomain(),
|
|
1485
|
-
client.getSiweNonce(walletAddress)
|
|
1486
|
-
]);
|
|
1487
|
-
const issuedAt = /* @__PURE__ */ new Date();
|
|
1488
|
-
const expirationTime = new Date(issuedAt.getTime() + DEFAULT_SIWE_AUTH_VALIDITY_MS);
|
|
1489
|
-
const uri = typeof window !== "undefined" && window.location.origin ? window.location.origin : apiUrl;
|
|
1490
|
-
const message = siwe.createSiweMessage({
|
|
1491
|
-
address: walletAddress,
|
|
1492
|
-
chainId: walletClient.chain?.id ?? networkConfig.chainId,
|
|
1493
|
-
domain,
|
|
1494
|
-
expirationTime,
|
|
1495
|
-
issuedAt,
|
|
1496
|
-
nonce: nonceResponse.nonce,
|
|
1497
|
-
statement: PRIVATE_READ_STATEMENT,
|
|
1498
|
-
uri,
|
|
1499
|
-
version: "1"
|
|
1500
|
-
});
|
|
1501
|
-
const signature = await walletClient.signMessage({
|
|
1502
|
-
account: walletClient.account ?? walletAddress,
|
|
1503
|
-
message
|
|
1504
|
-
});
|
|
1505
|
-
const login = await client.loginWithSiwe({
|
|
1506
|
-
siwe_message: message,
|
|
1507
|
-
signature
|
|
1508
|
-
});
|
|
1509
|
-
privateReadTokenCache.set(scopeKey, {
|
|
1510
|
-
token: login.siwe_token,
|
|
1511
|
-
expiresAt: expirationTime.getTime()
|
|
1512
|
-
});
|
|
1513
|
-
privateReadFailureCache.delete(scopeKey);
|
|
1514
|
-
client.setPrivateReadToken(login.siwe_token);
|
|
1515
|
-
return login.siwe_token;
|
|
1516
|
-
} catch (error) {
|
|
1517
|
-
const authError = error instanceof Error ? error : new Error("Failed to authenticate private reads");
|
|
1518
|
-
clearPrivateReadScope(scopeKey, client);
|
|
1519
|
-
recordPrivateReadFailure(scopeKey);
|
|
1520
|
-
throw authError;
|
|
1521
|
-
} finally {
|
|
1522
|
-
privateReadInflight.delete(scopeKey);
|
|
1523
|
-
}
|
|
1524
|
-
})();
|
|
1525
|
-
privateReadInflight.set(scopeKey, authPromise);
|
|
1526
|
-
return authPromise;
|
|
1527
|
-
};
|
|
1528
|
-
await getToken(false);
|
|
1529
|
-
try {
|
|
1530
|
-
return await request();
|
|
1531
|
-
} catch (error) {
|
|
1532
|
-
if (!(error instanceof AccountingApiError) || error.statusCode !== 401) {
|
|
1533
|
-
throw error;
|
|
1534
|
-
}
|
|
1535
|
-
clearPrivateReadScope(scopeKey, client);
|
|
1536
|
-
await getToken(true);
|
|
1537
|
-
return request();
|
|
1538
|
-
}
|
|
1539
|
-
},
|
|
1540
|
-
[
|
|
1541
|
-
client,
|
|
1542
|
-
hostedAuthConfig,
|
|
1543
|
-
hostedAuthSession,
|
|
1544
|
-
networkConfig.apiUrl,
|
|
1545
|
-
networkConfig.chainId,
|
|
1546
|
-
refreshHostedAuthSession,
|
|
1547
|
-
walletAddress,
|
|
1548
|
-
wagmiContext
|
|
1549
|
-
]
|
|
1550
|
-
);
|
|
1551
|
-
const privateReadQueryScope = react.useMemo(
|
|
1552
|
-
() => [networkConfig.apiUrl, networkConfig.chainId, privateReadAddress],
|
|
1553
|
-
[networkConfig.apiUrl, networkConfig.chainId, privateReadAddress]
|
|
1554
|
-
);
|
|
1555
|
-
return {
|
|
1556
|
-
executePrivateRead,
|
|
1557
|
-
privateReadAddress,
|
|
1558
|
-
privateReadReady,
|
|
1559
|
-
privateReadQueryScope
|
|
1560
|
-
};
|
|
1561
|
-
}
|
|
1562
|
-
|
|
1563
|
-
// src/sdk/hooks/use-balance.ts
|
|
1564
437
|
function useBalance(options = {}) {
|
|
1565
438
|
const queryClient = react.useContext(reactQuery.QueryClientContext);
|
|
1566
|
-
const accountingContext = useSafePrivanaContext();
|
|
439
|
+
const accountingContext = chunkRDMJGMI3_cjs.useSafePrivanaContext();
|
|
1567
440
|
const hasProviders = !!queryClient && !!accountingContext;
|
|
1568
441
|
const client = accountingContext?.client;
|
|
1569
442
|
const defaultToken = accountingContext?.defaultToken;
|
|
1570
443
|
const pollingInterval = accountingContext?.pollingInterval ?? 1e4;
|
|
1571
|
-
const { executePrivateRead, privateReadAddress, privateReadQueryScope, privateReadReady } = usePrivateReadRequest();
|
|
444
|
+
const { executePrivateRead, privateReadAddress, privateReadQueryScope, privateReadReady } = chunkRDMJGMI3_cjs.usePrivateReadRequest();
|
|
1572
445
|
const tokenId = options.tokenId ?? defaultToken?.id;
|
|
1573
446
|
const query = reactQuery.useQuery({
|
|
1574
447
|
queryKey: ["accounting-balance", ...privateReadQueryScope, tokenId],
|
|
@@ -1585,7 +458,7 @@ function useBalance(options = {}) {
|
|
|
1585
458
|
return {
|
|
1586
459
|
balance: balanceWei,
|
|
1587
460
|
balanceWei,
|
|
1588
|
-
balanceFormatted: formatTokenAmount(balanceWei),
|
|
461
|
+
balanceFormatted: chunkRDMJGMI3_cjs.formatTokenAmount(balanceWei),
|
|
1589
462
|
tokenSymbol: query.data?.token_symbol ?? "",
|
|
1590
463
|
chainId: query.data?.chain_id ?? "",
|
|
1591
464
|
isLoading: query.isPending || query.isLoading,
|
|
@@ -1595,8 +468,8 @@ function useBalance(options = {}) {
|
|
|
1595
468
|
};
|
|
1596
469
|
}
|
|
1597
470
|
function useBatchBalances(options) {
|
|
1598
|
-
const { client, pollingInterval } = usePrivanaContext();
|
|
1599
|
-
const { executePrivateRead, privateReadAddress, privateReadQueryScope, privateReadReady } = usePrivateReadRequest();
|
|
471
|
+
const { client, pollingInterval } = chunkRDMJGMI3_cjs.usePrivanaContext();
|
|
472
|
+
const { executePrivateRead, privateReadAddress, privateReadQueryScope, privateReadReady } = chunkRDMJGMI3_cjs.usePrivateReadRequest();
|
|
1600
473
|
const query = reactQuery.useQuery({
|
|
1601
474
|
queryKey: ["accounting-batch-balances", ...privateReadQueryScope, options.tokenIds],
|
|
1602
475
|
queryFn: async () => {
|
|
@@ -1614,55 +487,6 @@ function useBatchBalances(options) {
|
|
|
1614
487
|
refetch: query.refetch
|
|
1615
488
|
};
|
|
1616
489
|
}
|
|
1617
|
-
|
|
1618
|
-
// ../../node_modules/@wagmi/core/dist/esm/utils/getAction.js
|
|
1619
|
-
function getAction(client, actionFn, name) {
|
|
1620
|
-
const action_implicit = client[actionFn.name];
|
|
1621
|
-
if (typeof action_implicit === "function")
|
|
1622
|
-
return action_implicit;
|
|
1623
|
-
const action_explicit = client[name];
|
|
1624
|
-
if (typeof action_explicit === "function")
|
|
1625
|
-
return action_explicit;
|
|
1626
|
-
return (params) => actionFn(client, params);
|
|
1627
|
-
}
|
|
1628
|
-
|
|
1629
|
-
// ../../node_modules/@wagmi/core/dist/esm/actions/getChainId.js
|
|
1630
|
-
function getChainId2(config) {
|
|
1631
|
-
return config.state.chainId;
|
|
1632
|
-
}
|
|
1633
|
-
async function getTransactionReceipt(config, parameters) {
|
|
1634
|
-
const { chainId, ...rest } = parameters;
|
|
1635
|
-
const client = config.getClient({ chainId });
|
|
1636
|
-
const action = getAction(client, actions$1.getTransactionReceipt, "getTransactionReceipt");
|
|
1637
|
-
return action(rest);
|
|
1638
|
-
}
|
|
1639
|
-
async function waitForTransactionReceipt(config, parameters) {
|
|
1640
|
-
const { chainId, timeout = 0, ...rest } = parameters;
|
|
1641
|
-
const client = config.getClient({ chainId });
|
|
1642
|
-
const action = getAction(client, actions$1.waitForTransactionReceipt, "waitForTransactionReceipt");
|
|
1643
|
-
const receipt = await action({ ...rest, timeout });
|
|
1644
|
-
if (receipt.status === "reverted") {
|
|
1645
|
-
const action_getTransaction = getAction(client, actions$1.getTransaction, "getTransaction");
|
|
1646
|
-
const { from: account, ...txn } = await action_getTransaction({
|
|
1647
|
-
hash: receipt.transactionHash
|
|
1648
|
-
});
|
|
1649
|
-
const action_call = getAction(client, actions$1.call, "call");
|
|
1650
|
-
const code = await action_call({
|
|
1651
|
-
...txn,
|
|
1652
|
-
account,
|
|
1653
|
-
data: txn.input,
|
|
1654
|
-
gasPrice: txn.type !== "eip1559" ? txn.gasPrice : void 0,
|
|
1655
|
-
maxFeePerGas: txn.type === "eip1559" ? txn.maxFeePerGas : void 0,
|
|
1656
|
-
maxPriorityFeePerGas: txn.type === "eip1559" ? txn.maxPriorityFeePerGas : void 0
|
|
1657
|
-
});
|
|
1658
|
-
const reason = code?.data ? viem.hexToString(`0x${code.data.substring(138)}`) : "unknown reason";
|
|
1659
|
-
throw new Error(reason);
|
|
1660
|
-
}
|
|
1661
|
-
return {
|
|
1662
|
-
...receipt,
|
|
1663
|
-
chainId: client.chain.id
|
|
1664
|
-
};
|
|
1665
|
-
}
|
|
1666
490
|
function useEnsureCorrectChain() {
|
|
1667
491
|
const config = wagmi.useConfig();
|
|
1668
492
|
const chainId = wagmi.useChainId();
|
|
@@ -1671,7 +495,7 @@ function useEnsureCorrectChain() {
|
|
|
1671
495
|
async (expectedChainId, timeoutMs, pollIntervalMs = 250) => {
|
|
1672
496
|
const startedAt = Date.now();
|
|
1673
497
|
while (Date.now() - startedAt < timeoutMs) {
|
|
1674
|
-
const currentChainId = getChainId2(config);
|
|
498
|
+
const currentChainId = chunkRDMJGMI3_cjs.getChainId2(config);
|
|
1675
499
|
if (currentChainId === expectedChainId) return true;
|
|
1676
500
|
await new Promise((resolve) => setTimeout(resolve, pollIntervalMs));
|
|
1677
501
|
}
|
|
@@ -1681,7 +505,7 @@ function useEnsureCorrectChain() {
|
|
|
1681
505
|
);
|
|
1682
506
|
const ensureCorrectChain = react.useCallback(
|
|
1683
507
|
async (targetChainId) => {
|
|
1684
|
-
const currentChainId = getChainId2(config);
|
|
508
|
+
const currentChainId = chunkRDMJGMI3_cjs.getChainId2(config);
|
|
1685
509
|
if (currentChainId === targetChainId) return false;
|
|
1686
510
|
let switchErrorMessage;
|
|
1687
511
|
try {
|
|
@@ -1748,24 +572,19 @@ function clearPendingDeposit(address) {
|
|
|
1748
572
|
}
|
|
1749
573
|
function useDeposit(options = {}) {
|
|
1750
574
|
const { address } = wagmi.useAccount();
|
|
1751
|
-
const { client, enabledTokens, getChainById: getChainById2 } = usePrivanaContext();
|
|
575
|
+
const { client, enabledTokens, getChainById: getChainById2 } = chunkRDMJGMI3_cjs.usePrivanaContext();
|
|
1752
576
|
const { data: walletClient } = wagmi.useWalletClient();
|
|
1753
577
|
const queryClient = reactQuery.useQueryClient();
|
|
1754
578
|
const config = wagmi.useConfig();
|
|
1755
|
-
const { executePrivateRead } = usePrivateReadRequest();
|
|
1756
|
-
const pollInterval = options.pollInterval ?? 5e3;
|
|
1757
|
-
const pollTimeout = options.pollTimeout ?? 18e4;
|
|
579
|
+
const { executePrivateRead } = chunkRDMJGMI3_cjs.usePrivateReadRequest();
|
|
1758
580
|
const confirmations = options.confirmations ?? 15;
|
|
1759
581
|
const [depositAddress, setDepositAddress] = react.useState(null);
|
|
1760
582
|
const [txHash, setTxHash] = react.useState();
|
|
1761
583
|
const [isSwitchingChain, setIsSwitchingChain] = react.useState(false);
|
|
1762
584
|
const [isWaitingForConfirmation, setIsWaitingForConfirmation] = react.useState(false);
|
|
1763
|
-
const [
|
|
1764
|
-
const [didTimeout, setDidTimeout] = react.useState(false);
|
|
1765
|
-
const [verificationFailed, setVerificationFailed] = react.useState(false);
|
|
585
|
+
const [receiptFailed, setReceiptFailed] = react.useState(false);
|
|
1766
586
|
const [depositError, setDepositError] = react.useState(null);
|
|
1767
587
|
const generationRef = react.useRef(0);
|
|
1768
|
-
const pollIntervalRef = react.useRef(null);
|
|
1769
588
|
const verificationContextRef = react.useRef(null);
|
|
1770
589
|
const onDepositAddressReceivedRef = react.useRef(options.onDepositAddressReceived);
|
|
1771
590
|
const onDepositSuccessRef = react.useRef(options.onDepositSuccess);
|
|
@@ -1785,6 +604,28 @@ function useDeposit(options = {}) {
|
|
|
1785
604
|
options.onCheckTimeout,
|
|
1786
605
|
options.onError
|
|
1787
606
|
]);
|
|
607
|
+
const {
|
|
608
|
+
isVerifying,
|
|
609
|
+
didTimeout,
|
|
610
|
+
verificationFailed: innerVerificationFailed,
|
|
611
|
+
error: verificationError,
|
|
612
|
+
verify,
|
|
613
|
+
reset: resetVerification
|
|
614
|
+
} = chunkRDMJGMI3_cjs.useDepositVerification({
|
|
615
|
+
pollInterval: options.pollInterval,
|
|
616
|
+
pollTimeout: options.pollTimeout,
|
|
617
|
+
onCredited: (hash, response) => {
|
|
618
|
+
verificationContextRef.current = null;
|
|
619
|
+
if (address) clearPendingDeposit(address);
|
|
620
|
+
onCreditedRef.current?.(hash, response);
|
|
621
|
+
},
|
|
622
|
+
onCheckTimeout: (hash) => {
|
|
623
|
+
onCheckTimeoutRef.current?.(hash);
|
|
624
|
+
},
|
|
625
|
+
onError: (err) => {
|
|
626
|
+
onErrorRef.current?.(err);
|
|
627
|
+
}
|
|
628
|
+
});
|
|
1788
629
|
const addressMutation = reactQuery.useMutation({
|
|
1789
630
|
mutationFn: async () => {
|
|
1790
631
|
if (!address) throw new Error("No wallet connected");
|
|
@@ -1819,149 +660,24 @@ function useDeposit(options = {}) {
|
|
|
1819
660
|
react.useEffect(() => {
|
|
1820
661
|
return () => {
|
|
1821
662
|
invalidateGeneration();
|
|
1822
|
-
if (pollIntervalRef.current) {
|
|
1823
|
-
clearTimeout(pollIntervalRef.current);
|
|
1824
|
-
pollIntervalRef.current = null;
|
|
1825
|
-
}
|
|
1826
663
|
};
|
|
1827
664
|
}, [invalidateGeneration]);
|
|
1828
665
|
const resumedAddressRef = react.useRef(void 0);
|
|
1829
|
-
const stopPolling = react.useCallback(() => {
|
|
1830
|
-
if (pollIntervalRef.current) {
|
|
1831
|
-
clearTimeout(pollIntervalRef.current);
|
|
1832
|
-
pollIntervalRef.current = null;
|
|
1833
|
-
}
|
|
1834
|
-
}, []);
|
|
1835
666
|
const reset = react.useCallback(() => {
|
|
1836
667
|
generationRef.current++;
|
|
1837
|
-
|
|
668
|
+
resetVerification();
|
|
1838
669
|
if (address) clearPendingDeposit(address);
|
|
1839
670
|
verificationContextRef.current = null;
|
|
1840
671
|
setDepositAddress(null);
|
|
1841
672
|
setTxHash(void 0);
|
|
1842
673
|
setIsSwitchingChain(false);
|
|
1843
674
|
setIsWaitingForConfirmation(false);
|
|
1844
|
-
|
|
1845
|
-
setDidTimeout(false);
|
|
1846
|
-
setVerificationFailed(false);
|
|
675
|
+
setReceiptFailed(false);
|
|
1847
676
|
setDepositError(null);
|
|
1848
677
|
addressMutation.reset();
|
|
1849
678
|
resetWriteContract();
|
|
1850
679
|
resetSendTransaction();
|
|
1851
|
-
}, [address, addressMutation, resetWriteContract, resetSendTransaction,
|
|
1852
|
-
const runVerification = react.useCallback(
|
|
1853
|
-
async (ctx, generation) => {
|
|
1854
|
-
const isStale = () => generation !== generationRef.current;
|
|
1855
|
-
const { hash, chainId, amount } = ctx;
|
|
1856
|
-
setVerificationFailed(false);
|
|
1857
|
-
setDepositError(null);
|
|
1858
|
-
setDidTimeout(false);
|
|
1859
|
-
setIsWaitingForProcessing(true);
|
|
1860
|
-
const pollStartTime = Date.now();
|
|
1861
|
-
const markVerificationFailed = (err) => {
|
|
1862
|
-
setIsWaitingForProcessing(false);
|
|
1863
|
-
setDepositError(err);
|
|
1864
|
-
setVerificationFailed(true);
|
|
1865
|
-
onErrorRef.current?.(err);
|
|
1866
|
-
};
|
|
1867
|
-
try {
|
|
1868
|
-
const triggerResult = await executePrivateRead(
|
|
1869
|
-
() => client.checkDeposit({
|
|
1870
|
-
chain_id: chainId,
|
|
1871
|
-
tx_hash: hash,
|
|
1872
|
-
amount: amount.toString()
|
|
1873
|
-
})
|
|
1874
|
-
);
|
|
1875
|
-
if (isStale()) return;
|
|
1876
|
-
if (triggerResult.status === "credited") {
|
|
1877
|
-
setIsWaitingForProcessing(false);
|
|
1878
|
-
verificationContextRef.current = null;
|
|
1879
|
-
if (address) clearPendingDeposit(address);
|
|
1880
|
-
queryClient.invalidateQueries({ queryKey: ["accounting-balance"] });
|
|
1881
|
-
queryClient.invalidateQueries({ queryKey: ["accounting-history"] });
|
|
1882
|
-
onCreditedRef.current?.(hash, triggerResult);
|
|
1883
|
-
return;
|
|
1884
|
-
}
|
|
1885
|
-
if (triggerResult.status === "error") {
|
|
1886
|
-
markVerificationFailed(new Error(triggerResult.detail ?? "Deposit verification failed"));
|
|
1887
|
-
return;
|
|
1888
|
-
}
|
|
1889
|
-
const depositId = triggerResult.deposit_id;
|
|
1890
|
-
if (!depositId) {
|
|
1891
|
-
markVerificationFailed(new Error("Deposit check did not return a deposit id"));
|
|
1892
|
-
return;
|
|
1893
|
-
}
|
|
1894
|
-
let consecutiveFailures = 0;
|
|
1895
|
-
const checkStatus = async () => {
|
|
1896
|
-
if (isStale()) return true;
|
|
1897
|
-
if (Date.now() - pollStartTime > pollTimeout) {
|
|
1898
|
-
stopPolling();
|
|
1899
|
-
setIsWaitingForProcessing(false);
|
|
1900
|
-
setDidTimeout(true);
|
|
1901
|
-
onCheckTimeoutRef.current?.(hash);
|
|
1902
|
-
queryClient.invalidateQueries({ queryKey: ["accounting-balance"] });
|
|
1903
|
-
return true;
|
|
1904
|
-
}
|
|
1905
|
-
try {
|
|
1906
|
-
const result = await executePrivateRead(() => client.getDepositStatus(depositId));
|
|
1907
|
-
if (isStale()) return true;
|
|
1908
|
-
consecutiveFailures = 0;
|
|
1909
|
-
if (result.status === "credited") {
|
|
1910
|
-
stopPolling();
|
|
1911
|
-
setIsWaitingForProcessing(false);
|
|
1912
|
-
verificationContextRef.current = null;
|
|
1913
|
-
if (address) clearPendingDeposit(address);
|
|
1914
|
-
queryClient.invalidateQueries({ queryKey: ["accounting-balance"] });
|
|
1915
|
-
queryClient.invalidateQueries({ queryKey: ["accounting-history"] });
|
|
1916
|
-
onCreditedRef.current?.(hash, result);
|
|
1917
|
-
return true;
|
|
1918
|
-
}
|
|
1919
|
-
if (result.status === "error") {
|
|
1920
|
-
stopPolling();
|
|
1921
|
-
markVerificationFailed(new Error(result.detail ?? "Deposit verification failed"));
|
|
1922
|
-
return true;
|
|
1923
|
-
}
|
|
1924
|
-
} catch (err) {
|
|
1925
|
-
if (isStale()) return true;
|
|
1926
|
-
consecutiveFailures++;
|
|
1927
|
-
console.warn("Error polling deposit status:", err);
|
|
1928
|
-
if (consecutiveFailures >= 3) {
|
|
1929
|
-
stopPolling();
|
|
1930
|
-
markVerificationFailed(
|
|
1931
|
-
err instanceof Error ? err : new Error("Deposit status polling failed")
|
|
1932
|
-
);
|
|
1933
|
-
return true;
|
|
1934
|
-
}
|
|
1935
|
-
}
|
|
1936
|
-
return false;
|
|
1937
|
-
};
|
|
1938
|
-
const pollLoop = async () => {
|
|
1939
|
-
const done = await checkStatus();
|
|
1940
|
-
if (!done && !isStale() && pollIntervalRef.current !== null) {
|
|
1941
|
-
pollIntervalRef.current = setTimeout(pollLoop, pollInterval);
|
|
1942
|
-
}
|
|
1943
|
-
};
|
|
1944
|
-
pollIntervalRef.current = setTimeout(pollLoop, pollInterval);
|
|
1945
|
-
} catch (err) {
|
|
1946
|
-
if (isStale()) return;
|
|
1947
|
-
stopPolling();
|
|
1948
|
-
markVerificationFailed(
|
|
1949
|
-
err instanceof Error ? err : new Error("Deposit verification failed")
|
|
1950
|
-
);
|
|
1951
|
-
}
|
|
1952
|
-
},
|
|
1953
|
-
[address, client, executePrivateRead, pollInterval, pollTimeout, queryClient, stopPolling]
|
|
1954
|
-
);
|
|
1955
|
-
const retryVerification = react.useCallback(async () => {
|
|
1956
|
-
const ctx = verificationContextRef.current;
|
|
1957
|
-
if (!ctx) {
|
|
1958
|
-
throw new Error("No pending deposit to verify");
|
|
1959
|
-
}
|
|
1960
|
-
generationRef.current++;
|
|
1961
|
-
stopPolling();
|
|
1962
|
-
const generation = generationRef.current;
|
|
1963
|
-
await runVerification(ctx, generation);
|
|
1964
|
-
}, [runVerification, stopPolling]);
|
|
680
|
+
}, [address, addressMutation, resetWriteContract, resetSendTransaction, resetVerification]);
|
|
1965
681
|
react.useEffect(() => {
|
|
1966
682
|
if (!address || resumedAddressRef.current === address) return;
|
|
1967
683
|
const persisted = loadPendingDeposit(address);
|
|
@@ -1983,12 +699,12 @@ function useDeposit(options = {}) {
|
|
|
1983
699
|
try {
|
|
1984
700
|
let confirmed = false;
|
|
1985
701
|
try {
|
|
1986
|
-
await getTransactionReceipt(config, { hash, chainId: persisted.chainId });
|
|
702
|
+
await chunkRDMJGMI3_cjs.getTransactionReceipt(config, { hash, chainId: persisted.chainId });
|
|
1987
703
|
confirmed = true;
|
|
1988
704
|
} catch {
|
|
1989
705
|
}
|
|
1990
706
|
if (!confirmed) {
|
|
1991
|
-
await waitForTransactionReceipt(config, {
|
|
707
|
+
await chunkRDMJGMI3_cjs.waitForTransactionReceipt(config, {
|
|
1992
708
|
hash,
|
|
1993
709
|
chainId: persisted.chainId,
|
|
1994
710
|
confirmations
|
|
@@ -1998,19 +714,17 @@ function useDeposit(options = {}) {
|
|
|
1998
714
|
setIsWaitingForConfirmation(false);
|
|
1999
715
|
onDepositSuccessRef.current?.(hash);
|
|
2000
716
|
queryClient.invalidateQueries({ queryKey: ["readContract"] });
|
|
2001
|
-
await
|
|
717
|
+
await verify(ctx);
|
|
2002
718
|
} catch (err) {
|
|
2003
719
|
if (isStale()) return;
|
|
2004
720
|
setIsWaitingForConfirmation(false);
|
|
2005
|
-
stopPolling();
|
|
2006
721
|
const error2 = err instanceof Error ? err : new Error("Deposit verification failed");
|
|
2007
|
-
setIsWaitingForProcessing(false);
|
|
2008
722
|
setDepositError(error2);
|
|
2009
|
-
|
|
723
|
+
setReceiptFailed(true);
|
|
2010
724
|
onErrorRef.current?.(error2);
|
|
2011
725
|
}
|
|
2012
726
|
})();
|
|
2013
|
-
}, [address, config, confirmations, queryClient,
|
|
727
|
+
}, [address, config, confirmations, queryClient, verify]);
|
|
2014
728
|
const deposit = react.useCallback(
|
|
2015
729
|
async (params) => {
|
|
2016
730
|
if (verificationContextRef.current) {
|
|
@@ -2077,7 +791,7 @@ function useDeposit(options = {}) {
|
|
|
2077
791
|
try {
|
|
2078
792
|
setIsWaitingForConfirmation(true);
|
|
2079
793
|
try {
|
|
2080
|
-
await waitForTransactionReceipt(config, {
|
|
794
|
+
await chunkRDMJGMI3_cjs.waitForTransactionReceipt(config, {
|
|
2081
795
|
hash,
|
|
2082
796
|
chainId: sourceChain.id,
|
|
2083
797
|
confirmations
|
|
@@ -2088,15 +802,13 @@ function useDeposit(options = {}) {
|
|
|
2088
802
|
if (isStale()) return;
|
|
2089
803
|
onDepositSuccessRef.current?.(hash);
|
|
2090
804
|
queryClient.invalidateQueries({ queryKey: ["readContract"] });
|
|
2091
|
-
await
|
|
805
|
+
await verify(ctx);
|
|
2092
806
|
} catch (err) {
|
|
2093
807
|
if (isStale()) return;
|
|
2094
808
|
setIsWaitingForConfirmation(false);
|
|
2095
|
-
stopPolling();
|
|
2096
809
|
const error2 = err instanceof Error ? err : new Error("Deposit verification failed");
|
|
2097
|
-
setIsWaitingForProcessing(false);
|
|
2098
810
|
setDepositError(error2);
|
|
2099
|
-
|
|
811
|
+
setReceiptFailed(true);
|
|
2100
812
|
onErrorRef.current?.(error2);
|
|
2101
813
|
}
|
|
2102
814
|
} catch (err) {
|
|
@@ -2118,13 +830,21 @@ function useDeposit(options = {}) {
|
|
|
2118
830
|
queryClient,
|
|
2119
831
|
writeContractAsync,
|
|
2120
832
|
sendTransactionAsync,
|
|
2121
|
-
stopPolling,
|
|
2122
833
|
reset,
|
|
2123
|
-
|
|
834
|
+
verify
|
|
2124
835
|
]
|
|
2125
836
|
);
|
|
2126
|
-
const
|
|
2127
|
-
|
|
837
|
+
const retryVerification = react.useCallback(async () => {
|
|
838
|
+
const ctx = verificationContextRef.current;
|
|
839
|
+
if (!ctx) {
|
|
840
|
+
throw new Error("No pending deposit to verify");
|
|
841
|
+
}
|
|
842
|
+
setReceiptFailed(false);
|
|
843
|
+
setDepositError(null);
|
|
844
|
+
await verify(ctx);
|
|
845
|
+
}, [verify]);
|
|
846
|
+
const isPending = addressMutation.isPending || isSwitchingChain || isSendingTx || isWaitingForConfirmation || isVerifying;
|
|
847
|
+
const error = addressMutation.error || sendError || depositError || verificationError;
|
|
2128
848
|
return {
|
|
2129
849
|
depositAddress,
|
|
2130
850
|
txHash,
|
|
@@ -2132,9 +852,9 @@ function useDeposit(options = {}) {
|
|
|
2132
852
|
isSwitchingChain,
|
|
2133
853
|
isSendingTransaction: isSendingTx,
|
|
2134
854
|
isWaitingForConfirmation,
|
|
2135
|
-
isWaitingForProcessing,
|
|
855
|
+
isWaitingForProcessing: isVerifying,
|
|
2136
856
|
didTimeout,
|
|
2137
|
-
verificationFailed,
|
|
857
|
+
verificationFailed: innerVerificationFailed || receiptFailed,
|
|
2138
858
|
isPending,
|
|
2139
859
|
error,
|
|
2140
860
|
deposit,
|
|
@@ -2145,7 +865,7 @@ function useDeposit(options = {}) {
|
|
|
2145
865
|
function useWithdraw(options = {}) {
|
|
2146
866
|
const { address } = wagmi.useAccount();
|
|
2147
867
|
const { data: walletClient } = wagmi.useWalletClient();
|
|
2148
|
-
const { client, networkConfig } = usePrivanaContext();
|
|
868
|
+
const { client, networkConfig } = chunkRDMJGMI3_cjs.usePrivanaContext();
|
|
2149
869
|
const queryClient = reactQuery.useQueryClient();
|
|
2150
870
|
const { chainId, ensureCorrectChain } = useEnsureCorrectChain();
|
|
2151
871
|
const pollInterval = options.pollInterval ?? 3e3;
|
|
@@ -2344,7 +1064,7 @@ function useWithdraw(options = {}) {
|
|
|
2344
1064
|
function useLockFunds(options = {}) {
|
|
2345
1065
|
const { address } = wagmi.useAccount();
|
|
2346
1066
|
const { data: walletClient } = wagmi.useWalletClient();
|
|
2347
|
-
const { client, networkConfig, serviceAddress } = usePrivanaContext();
|
|
1067
|
+
const { client, networkConfig, serviceAddress } = chunkRDMJGMI3_cjs.usePrivanaContext();
|
|
2348
1068
|
const queryClient = reactQuery.useQueryClient();
|
|
2349
1069
|
const mutation = reactQuery.useMutation({
|
|
2350
1070
|
mutationFn: async (params) => {
|
|
@@ -2403,7 +1123,7 @@ function useLockFunds(options = {}) {
|
|
|
2403
1123
|
}
|
|
2404
1124
|
function useUnlockFunds(options = {}) {
|
|
2405
1125
|
const { address } = wagmi.useAccount();
|
|
2406
|
-
const { client } = usePrivanaContext();
|
|
1126
|
+
const { client } = chunkRDMJGMI3_cjs.usePrivanaContext();
|
|
2407
1127
|
const queryClient = reactQuery.useQueryClient();
|
|
2408
1128
|
const unlockMutation = reactQuery.useMutation({
|
|
2409
1129
|
mutationFn: async (params) => {
|
|
@@ -2471,7 +1191,7 @@ function useUnlockFunds(options = {}) {
|
|
|
2471
1191
|
function useTransfer(options = {}) {
|
|
2472
1192
|
const { address } = wagmi.useAccount();
|
|
2473
1193
|
const { data: walletClient } = wagmi.useWalletClient();
|
|
2474
|
-
const { client, networkConfig, serviceAddress } = usePrivanaContext();
|
|
1194
|
+
const { client, networkConfig, serviceAddress } = chunkRDMJGMI3_cjs.usePrivanaContext();
|
|
2475
1195
|
const queryClient = reactQuery.useQueryClient();
|
|
2476
1196
|
const transferMutation = reactQuery.useMutation({
|
|
2477
1197
|
mutationFn: async (params) => {
|
|
@@ -2576,8 +1296,8 @@ function useTransfer(options = {}) {
|
|
|
2576
1296
|
};
|
|
2577
1297
|
}
|
|
2578
1298
|
function useLockedFunds(options = {}) {
|
|
2579
|
-
const { client, pollingInterval, serviceAddress } = usePrivanaContext();
|
|
2580
|
-
const { executePrivateRead, privateReadAddress, privateReadQueryScope, privateReadReady } = usePrivateReadRequest();
|
|
1299
|
+
const { client, pollingInterval, serviceAddress } = chunkRDMJGMI3_cjs.usePrivanaContext();
|
|
1300
|
+
const { executePrivateRead, privateReadAddress, privateReadQueryScope, privateReadReady } = chunkRDMJGMI3_cjs.usePrivateReadRequest();
|
|
2581
1301
|
const query = reactQuery.useQuery({
|
|
2582
1302
|
queryKey: ["accounting-locked-funds", ...privateReadQueryScope, serviceAddress ?? null],
|
|
2583
1303
|
queryFn: async () => {
|
|
@@ -2599,8 +1319,8 @@ function useLockedFunds(options = {}) {
|
|
|
2599
1319
|
};
|
|
2600
1320
|
}
|
|
2601
1321
|
function useTotalLockedBalance(options = {}) {
|
|
2602
|
-
const { client, pollingInterval, defaultToken } = usePrivanaContext();
|
|
2603
|
-
const { executePrivateRead, privateReadAddress, privateReadQueryScope, privateReadReady } = usePrivateReadRequest();
|
|
1322
|
+
const { client, pollingInterval, defaultToken } = chunkRDMJGMI3_cjs.usePrivanaContext();
|
|
1323
|
+
const { executePrivateRead, privateReadAddress, privateReadQueryScope, privateReadReady } = chunkRDMJGMI3_cjs.usePrivateReadRequest();
|
|
2604
1324
|
const tokenId = options.tokenId ?? defaultToken?.id;
|
|
2605
1325
|
const query = reactQuery.useQuery({
|
|
2606
1326
|
queryKey: ["accounting-total-locked-balance", ...privateReadQueryScope, tokenId],
|
|
@@ -2621,8 +1341,8 @@ function useTotalLockedBalance(options = {}) {
|
|
|
2621
1341
|
};
|
|
2622
1342
|
}
|
|
2623
1343
|
function useExpiredLocks(options = {}) {
|
|
2624
|
-
const { client, pollingInterval } = usePrivanaContext();
|
|
2625
|
-
const { executePrivateRead, privateReadAddress, privateReadQueryScope, privateReadReady } = usePrivateReadRequest();
|
|
1344
|
+
const { client, pollingInterval } = chunkRDMJGMI3_cjs.usePrivanaContext();
|
|
1345
|
+
const { executePrivateRead, privateReadAddress, privateReadQueryScope, privateReadReady } = chunkRDMJGMI3_cjs.usePrivateReadRequest();
|
|
2626
1346
|
const query = reactQuery.useQuery({
|
|
2627
1347
|
queryKey: ["accounting-expired-locks", ...privateReadQueryScope],
|
|
2628
1348
|
queryFn: async () => {
|
|
@@ -2644,7 +1364,7 @@ function useExpiredLocks(options = {}) {
|
|
|
2644
1364
|
}
|
|
2645
1365
|
function usePendingWithdrawals(options = {}) {
|
|
2646
1366
|
const { address, isConnected } = wagmi.useAccount();
|
|
2647
|
-
const { client, pollingInterval } = usePrivanaContext();
|
|
1367
|
+
const { client, pollingInterval } = chunkRDMJGMI3_cjs.usePrivanaContext();
|
|
2648
1368
|
const query = reactQuery.useQuery({
|
|
2649
1369
|
queryKey: ["accounting-pending-withdrawals", address],
|
|
2650
1370
|
queryFn: async () => {
|
|
@@ -2680,8 +1400,8 @@ function usePendingWithdrawals(options = {}) {
|
|
|
2680
1400
|
};
|
|
2681
1401
|
}
|
|
2682
1402
|
function useHistory(options = {}) {
|
|
2683
|
-
const { client, pollingInterval } = usePrivanaContext();
|
|
2684
|
-
const { executePrivateRead, privateReadAddress, privateReadQueryScope, privateReadReady } = usePrivateReadRequest();
|
|
1403
|
+
const { client, pollingInterval } = chunkRDMJGMI3_cjs.usePrivanaContext();
|
|
1404
|
+
const { executePrivateRead, privateReadAddress, privateReadQueryScope, privateReadReady } = chunkRDMJGMI3_cjs.usePrivateReadRequest();
|
|
2685
1405
|
const offset = options.offset ?? -1;
|
|
2686
1406
|
const limit = options.limit ?? 50;
|
|
2687
1407
|
const query = reactQuery.useQuery({
|
|
@@ -2705,7 +1425,7 @@ function useHistory(options = {}) {
|
|
|
2705
1425
|
};
|
|
2706
1426
|
}
|
|
2707
1427
|
function useTokenInfo(options = {}) {
|
|
2708
|
-
const { client } = usePrivanaContext();
|
|
1428
|
+
const { client } = chunkRDMJGMI3_cjs.usePrivanaContext();
|
|
2709
1429
|
const { tokenId } = options;
|
|
2710
1430
|
const query = reactQuery.useQuery({
|
|
2711
1431
|
queryKey: ["accounting-token-info", tokenId],
|
|
@@ -2725,7 +1445,7 @@ function useTokenInfo(options = {}) {
|
|
|
2725
1445
|
};
|
|
2726
1446
|
}
|
|
2727
1447
|
function useTokenList(options = {}) {
|
|
2728
|
-
const { client } = usePrivanaContext();
|
|
1448
|
+
const { client } = chunkRDMJGMI3_cjs.usePrivanaContext();
|
|
2729
1449
|
const query = reactQuery.useQuery({
|
|
2730
1450
|
queryKey: ["accounting-token-list"],
|
|
2731
1451
|
queryFn: () => client.listTokens(),
|
|
@@ -2743,7 +1463,7 @@ function useTokenList(options = {}) {
|
|
|
2743
1463
|
function useModifyLock(options = {}) {
|
|
2744
1464
|
const { address } = wagmi.useAccount();
|
|
2745
1465
|
const { data: walletClient } = wagmi.useWalletClient();
|
|
2746
|
-
const { client, networkConfig } = usePrivanaContext();
|
|
1466
|
+
const { client, networkConfig } = chunkRDMJGMI3_cjs.usePrivanaContext();
|
|
2747
1467
|
const queryClient = reactQuery.useQueryClient();
|
|
2748
1468
|
const mutation = reactQuery.useMutation({
|
|
2749
1469
|
mutationFn: async (params) => {
|
|
@@ -2794,52 +1514,6 @@ function useModifyLock(options = {}) {
|
|
|
2794
1514
|
reset: mutation.reset
|
|
2795
1515
|
};
|
|
2796
1516
|
}
|
|
2797
|
-
var buttonVariants = classVarianceAuthority.cva(
|
|
2798
|
-
"inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-all disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",
|
|
2799
|
-
{
|
|
2800
|
-
variants: {
|
|
2801
|
-
variant: {
|
|
2802
|
-
default: "bg-primary text-primary-foreground hover:bg-primary/90",
|
|
2803
|
-
destructive: "bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",
|
|
2804
|
-
outline: "border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:bg-input/30 dark:border-input dark:hover:bg-input/50",
|
|
2805
|
-
secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/80",
|
|
2806
|
-
ghost: "hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",
|
|
2807
|
-
link: "text-primary underline-offset-4 hover:underline"
|
|
2808
|
-
},
|
|
2809
|
-
size: {
|
|
2810
|
-
default: "h-9 px-4 py-2 has-[>svg]:px-3",
|
|
2811
|
-
sm: "h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5",
|
|
2812
|
-
lg: "h-10 rounded-md px-6 has-[>svg]:px-4",
|
|
2813
|
-
icon: "size-9",
|
|
2814
|
-
"icon-sm": "size-8",
|
|
2815
|
-
"icon-lg": "size-10"
|
|
2816
|
-
}
|
|
2817
|
-
},
|
|
2818
|
-
defaultVariants: {
|
|
2819
|
-
variant: "default",
|
|
2820
|
-
size: "default"
|
|
2821
|
-
}
|
|
2822
|
-
}
|
|
2823
|
-
);
|
|
2824
|
-
function Button({
|
|
2825
|
-
className,
|
|
2826
|
-
variant = "default",
|
|
2827
|
-
size = "default",
|
|
2828
|
-
asChild = false,
|
|
2829
|
-
...props
|
|
2830
|
-
}) {
|
|
2831
|
-
const Comp = asChild ? reactSlot.Slot : "button";
|
|
2832
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
2833
|
-
Comp,
|
|
2834
|
-
{
|
|
2835
|
-
"data-slot": "button",
|
|
2836
|
-
"data-variant": variant,
|
|
2837
|
-
"data-size": size,
|
|
2838
|
-
className: cn(buttonVariants({ variant, size, className })),
|
|
2839
|
-
...props
|
|
2840
|
-
}
|
|
2841
|
-
);
|
|
2842
|
-
}
|
|
2843
1517
|
function Dialog({ ...props }) {
|
|
2844
1518
|
return /* @__PURE__ */ jsxRuntime.jsx(DialogPrimitive__namespace.Root, { "data-slot": "dialog", ...props });
|
|
2845
1519
|
}
|
|
@@ -2855,7 +1529,7 @@ function DialogOverlay({
|
|
|
2855
1529
|
{
|
|
2856
1530
|
"data-slot": "dialog-overlay",
|
|
2857
1531
|
"data-privana": true,
|
|
2858
|
-
className: cn(
|
|
1532
|
+
className: chunkRDMJGMI3_cjs.cn(
|
|
2859
1533
|
"data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/50",
|
|
2860
1534
|
className
|
|
2861
1535
|
),
|
|
@@ -2877,7 +1551,7 @@ function DialogContent({
|
|
|
2877
1551
|
{
|
|
2878
1552
|
"data-slot": "dialog-content",
|
|
2879
1553
|
"data-privana": true,
|
|
2880
|
-
className: cn(
|
|
1554
|
+
className: chunkRDMJGMI3_cjs.cn(
|
|
2881
1555
|
"bg-background data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border p-6 shadow-lg duration-200 outline-none sm:max-w-lg",
|
|
2882
1556
|
className
|
|
2883
1557
|
),
|
|
@@ -2905,7 +1579,7 @@ function DialogHeader({ className, ...props }) {
|
|
|
2905
1579
|
"div",
|
|
2906
1580
|
{
|
|
2907
1581
|
"data-slot": "dialog-header",
|
|
2908
|
-
className: cn("flex flex-col gap-2 text-center sm:text-left", className),
|
|
1582
|
+
className: chunkRDMJGMI3_cjs.cn("flex flex-col gap-2 text-center sm:text-left", className),
|
|
2909
1583
|
...props
|
|
2910
1584
|
}
|
|
2911
1585
|
);
|
|
@@ -2915,7 +1589,7 @@ function DialogTitle({ className, ...props }) {
|
|
|
2915
1589
|
DialogPrimitive__namespace.Title,
|
|
2916
1590
|
{
|
|
2917
1591
|
"data-slot": "dialog-title",
|
|
2918
|
-
className: cn("text-lg leading-none font-semibold", className),
|
|
1592
|
+
className: chunkRDMJGMI3_cjs.cn("text-lg leading-none font-semibold", className),
|
|
2919
1593
|
...props
|
|
2920
1594
|
}
|
|
2921
1595
|
);
|
|
@@ -2928,7 +1602,7 @@ function DialogDescription({
|
|
|
2928
1602
|
DialogPrimitive__namespace.Description,
|
|
2929
1603
|
{
|
|
2930
1604
|
"data-slot": "dialog-description",
|
|
2931
|
-
className: cn("text-muted-foreground text-sm", className),
|
|
1605
|
+
className: chunkRDMJGMI3_cjs.cn("text-muted-foreground text-sm", className),
|
|
2932
1606
|
...props
|
|
2933
1607
|
}
|
|
2934
1608
|
);
|
|
@@ -3283,7 +1957,7 @@ function DepositForm({
|
|
|
3283
1957
|
onSuccess
|
|
3284
1958
|
}) {
|
|
3285
1959
|
const { isConnected, address } = wagmi.useAccount();
|
|
3286
|
-
const { chains, getChainById: getChainById2 } = usePrivanaContext();
|
|
1960
|
+
const { chains, getChainById: getChainById2 } = chunkRDMJGMI3_cjs.usePrivanaContext();
|
|
3287
1961
|
const [amount, setAmount] = react.useState("");
|
|
3288
1962
|
const [showSuccess, setShowSuccess] = react.useState(false);
|
|
3289
1963
|
const [showTimeout, setShowTimeout] = react.useState(false);
|
|
@@ -3308,7 +1982,7 @@ function DepositForm({
|
|
|
3308
1982
|
}
|
|
3309
1983
|
});
|
|
3310
1984
|
const walletBalance = isNative ? nativeBalanceData?.value : erc20Balance;
|
|
3311
|
-
const formattedWalletBalance = walletBalance ? formatTokenAmount(walletBalance.toString(), selectedToken.decimals) : "0.00";
|
|
1985
|
+
const formattedWalletBalance = walletBalance ? chunkRDMJGMI3_cjs.formatTokenAmount(walletBalance.toString(), selectedToken.decimals) : "0.00";
|
|
3312
1986
|
const handleMaxClick = () => {
|
|
3313
1987
|
if (formattedWalletBalance && parseFloat(formattedWalletBalance) > 0) {
|
|
3314
1988
|
setAmount(formattedWalletBalance.replace(/[\s\u2009]/g, ""));
|
|
@@ -3316,7 +1990,7 @@ function DepositForm({
|
|
|
3316
1990
|
};
|
|
3317
1991
|
const hasValidAmount = amount && parseFloat(amount) > 0;
|
|
3318
1992
|
const tooManyDecimals = hasValidAmount && amount.includes(".") && amount.split(".")[1].length > selectedToken.decimals;
|
|
3319
|
-
const exceedsBalance = hasValidAmount && !tooManyDecimals && walletBalance != null && parseTokenAmount(amount, selectedToken.decimals) > walletBalance;
|
|
1993
|
+
const exceedsBalance = hasValidAmount && !tooManyDecimals && walletBalance != null && chunkRDMJGMI3_cjs.parseTokenAmount(amount, selectedToken.decimals) > walletBalance;
|
|
3320
1994
|
const {
|
|
3321
1995
|
txHash,
|
|
3322
1996
|
isGettingAddress,
|
|
@@ -3401,7 +2075,7 @@ function DepositForm({
|
|
|
3401
2075
|
const handleSubmit = async () => {
|
|
3402
2076
|
if (!amount || !selectedToken || exceedsBalance) return;
|
|
3403
2077
|
setCancelled(false);
|
|
3404
|
-
const amountInWei = parseTokenAmount(amount, selectedToken.decimals);
|
|
2078
|
+
const amountInWei = chunkRDMJGMI3_cjs.parseTokenAmount(amount, selectedToken.decimals);
|
|
3405
2079
|
await deposit({
|
|
3406
2080
|
tokenId: selectedToken.id,
|
|
3407
2081
|
amount: amountInWei
|
|
@@ -3504,7 +2178,7 @@ function DepositForm({
|
|
|
3504
2178
|
setAmount(value);
|
|
3505
2179
|
}
|
|
3506
2180
|
},
|
|
3507
|
-
className: cn(
|
|
2181
|
+
className: chunkRDMJGMI3_cjs.cn(
|
|
3508
2182
|
"text-foreground flex-1 bg-transparent text-sm outline-none",
|
|
3509
2183
|
"placeholder:text-muted-foreground/50"
|
|
3510
2184
|
)
|
|
@@ -3531,7 +2205,7 @@ function DepositForm({
|
|
|
3531
2205
|
{
|
|
3532
2206
|
onClick: handleSubmit,
|
|
3533
2207
|
disabled: !isConnected || !hasValidAmount || tooManyDecimals || !!exceedsBalance || isPending,
|
|
3534
|
-
className: cn(
|
|
2208
|
+
className: chunkRDMJGMI3_cjs.cn(
|
|
3535
2209
|
"flex h-10 w-full cursor-pointer items-center justify-center rounded-[10px] px-3 py-2 text-sm font-medium transition-colors",
|
|
3536
2210
|
"bg-primary text-primary-foreground hover:bg-primary/90",
|
|
3537
2211
|
"disabled:cursor-not-allowed disabled:opacity-50"
|
|
@@ -3548,7 +2222,7 @@ function WithdrawForm({
|
|
|
3548
2222
|
onUnsafeToCloseChange
|
|
3549
2223
|
}) {
|
|
3550
2224
|
const { isConnected, address } = wagmi.useAccount();
|
|
3551
|
-
const { chains, getChainById: getChainById2 } = usePrivanaContext();
|
|
2225
|
+
const { chains, getChainById: getChainById2 } = chunkRDMJGMI3_cjs.usePrivanaContext();
|
|
3552
2226
|
const [amount, setAmount] = react.useState("");
|
|
3553
2227
|
const [showSuccess, setShowSuccess] = react.useState(false);
|
|
3554
2228
|
const [showTimeout, setShowTimeout] = react.useState(false);
|
|
@@ -3561,7 +2235,7 @@ function WithdrawForm({
|
|
|
3561
2235
|
} = useBalance({
|
|
3562
2236
|
tokenId: selectedToken.id
|
|
3563
2237
|
});
|
|
3564
|
-
const formattedBalance = formatTokenAmount(balanceWei, selectedToken.decimals);
|
|
2238
|
+
const formattedBalance = chunkRDMJGMI3_cjs.formatTokenAmount(balanceWei, selectedToken.decimals);
|
|
3565
2239
|
const { withdraw, isPending, currentStep, error, reset } = useWithdraw({
|
|
3566
2240
|
onProcessingSuccess: () => {
|
|
3567
2241
|
setAmount("");
|
|
@@ -3572,7 +2246,7 @@ function WithdrawForm({
|
|
|
3572
2246
|
setShowTimeout(true);
|
|
3573
2247
|
}
|
|
3574
2248
|
});
|
|
3575
|
-
const explorerUrl = address && targetChain ? getExplorerAddressUrl(targetChain.id, address) : void 0;
|
|
2249
|
+
const explorerUrl = address && targetChain ? chunkRDMJGMI3_cjs.getExplorerAddressUrl(targetChain.id, address) : void 0;
|
|
3576
2250
|
const getStepStatus = (step, after) => {
|
|
3577
2251
|
if (currentStep === step) return "active";
|
|
3578
2252
|
if (after.includes(currentStep)) return "completed";
|
|
@@ -3616,7 +2290,7 @@ function WithdrawForm({
|
|
|
3616
2290
|
const handleWithdraw = async () => {
|
|
3617
2291
|
if (!amount || !selectedToken || exceedsBalance) return;
|
|
3618
2292
|
setCancelled(false);
|
|
3619
|
-
const amountInWei = parseTokenAmount(amount, selectedToken.decimals);
|
|
2293
|
+
const amountInWei = chunkRDMJGMI3_cjs.parseTokenAmount(amount, selectedToken.decimals);
|
|
3620
2294
|
await withdraw({
|
|
3621
2295
|
tokenId: selectedToken.id,
|
|
3622
2296
|
amount: amountInWei
|
|
@@ -3629,7 +2303,7 @@ function WithdrawForm({
|
|
|
3629
2303
|
};
|
|
3630
2304
|
const hasValidAmount = amount && parseFloat(amount) > 0;
|
|
3631
2305
|
const tooManyDecimals = hasValidAmount && amount.includes(".") && amount.split(".")[1].length > selectedToken.decimals;
|
|
3632
|
-
const exceedsBalance = hasValidAmount && !tooManyDecimals && !isBalanceLoading && !isBalanceError && parseTokenAmount(amount, selectedToken.decimals) > BigInt(balanceWei);
|
|
2306
|
+
const exceedsBalance = hasValidAmount && !tooManyDecimals && !isBalanceLoading && !isBalanceError && chunkRDMJGMI3_cjs.parseTokenAmount(amount, selectedToken.decimals) > BigInt(balanceWei);
|
|
3633
2307
|
const getButtonText = () => {
|
|
3634
2308
|
if (!isConnected) return "Connect Wallet";
|
|
3635
2309
|
return "Withdraw";
|
|
@@ -3712,7 +2386,7 @@ function WithdrawForm({
|
|
|
3712
2386
|
setAmount(value);
|
|
3713
2387
|
}
|
|
3714
2388
|
},
|
|
3715
|
-
className: cn(
|
|
2389
|
+
className: chunkRDMJGMI3_cjs.cn(
|
|
3716
2390
|
"text-foreground flex-1 bg-transparent text-sm outline-none",
|
|
3717
2391
|
"placeholder:text-muted-foreground/50"
|
|
3718
2392
|
)
|
|
@@ -3739,7 +2413,7 @@ function WithdrawForm({
|
|
|
3739
2413
|
{
|
|
3740
2414
|
onClick: handleWithdraw,
|
|
3741
2415
|
disabled: !isConnected || !hasValidAmount || tooManyDecimals || !!exceedsBalance || isPending,
|
|
3742
|
-
className: cn(
|
|
2416
|
+
className: chunkRDMJGMI3_cjs.cn(
|
|
3743
2417
|
"flex h-10 w-full cursor-pointer items-center justify-center rounded-[10px] px-3 py-2 text-sm font-medium transition-colors",
|
|
3744
2418
|
"bg-primary text-primary-foreground hover:bg-primary/90",
|
|
3745
2419
|
"disabled:cursor-not-allowed disabled:opacity-50"
|
|
@@ -3794,7 +2468,7 @@ function ChevronDown({ collapsed }) {
|
|
|
3794
2468
|
width: "12",
|
|
3795
2469
|
height: "6",
|
|
3796
2470
|
viewBox: "0 0 12 6",
|
|
3797
|
-
className: cn("transition-transform", collapsed && "-rotate-90"),
|
|
2471
|
+
className: chunkRDMJGMI3_cjs.cn("transition-transform", collapsed && "-rotate-90"),
|
|
3798
2472
|
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
3799
2473
|
"path",
|
|
3800
2474
|
{
|
|
@@ -3820,15 +2494,15 @@ function BalanceCards({
|
|
|
3820
2494
|
tokenId: selectedToken.id
|
|
3821
2495
|
});
|
|
3822
2496
|
const { totalLocked, isLoading: lockedLoading } = useLockedFunds({ enabled: showLockedFunds });
|
|
3823
|
-
const formattedBalance = formatTokenAmount(balanceWei, selectedToken.decimals);
|
|
3824
|
-
const formattedLocked = showLockedFunds ? formatTokenAmount(String(totalLocked), selectedToken.decimals) : "0.00";
|
|
3825
|
-
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cn("flex gap-2", disabled && "opacity-50"), children: [
|
|
2497
|
+
const formattedBalance = chunkRDMJGMI3_cjs.formatTokenAmount(balanceWei, selectedToken.decimals);
|
|
2498
|
+
const formattedLocked = showLockedFunds ? chunkRDMJGMI3_cjs.formatTokenAmount(String(totalLocked), selectedToken.decimals) : "0.00";
|
|
2499
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: chunkRDMJGMI3_cjs.cn("flex gap-2", disabled && "opacity-50"), children: [
|
|
3826
2500
|
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
3827
2501
|
"button",
|
|
3828
2502
|
{
|
|
3829
2503
|
onClick: onBalanceClick,
|
|
3830
2504
|
disabled,
|
|
3831
|
-
className: cn(
|
|
2505
|
+
className: chunkRDMJGMI3_cjs.cn(
|
|
3832
2506
|
"bg-muted flex flex-1 flex-col gap-2 rounded-[10px] p-5 text-left transition-colors",
|
|
3833
2507
|
disabled ? "cursor-not-allowed" : "hover:bg-muted/80 cursor-pointer"
|
|
3834
2508
|
),
|
|
@@ -3849,7 +2523,7 @@ function BalanceCards({
|
|
|
3849
2523
|
{
|
|
3850
2524
|
onClick: onLockedFundsClick,
|
|
3851
2525
|
disabled,
|
|
3852
|
-
className: cn(
|
|
2526
|
+
className: chunkRDMJGMI3_cjs.cn(
|
|
3853
2527
|
"bg-muted flex flex-1 flex-col gap-2 rounded-[10px] p-5 text-left transition-colors",
|
|
3854
2528
|
disabled ? "cursor-not-allowed" : "hover:bg-muted/80 cursor-pointer"
|
|
3855
2529
|
),
|
|
@@ -3875,7 +2549,7 @@ function Tabs({
|
|
|
3875
2549
|
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
3876
2550
|
"div",
|
|
3877
2551
|
{
|
|
3878
|
-
className: cn(
|
|
2552
|
+
className: chunkRDMJGMI3_cjs.cn(
|
|
3879
2553
|
"bg-muted relative flex gap-2 overflow-hidden rounded-[10px] p-1",
|
|
3880
2554
|
disabled && "opacity-50"
|
|
3881
2555
|
),
|
|
@@ -3883,7 +2557,7 @@ function Tabs({
|
|
|
3883
2557
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3884
2558
|
"div",
|
|
3885
2559
|
{
|
|
3886
|
-
className: cn(
|
|
2560
|
+
className: chunkRDMJGMI3_cjs.cn(
|
|
3887
2561
|
"bg-input absolute top-1 bottom-1 left-1 w-[calc(50%-8px)] rounded-md transition-transform duration-200",
|
|
3888
2562
|
activeTab === "withdraw" && "translate-x-[calc(100%+8px)]"
|
|
3889
2563
|
)
|
|
@@ -3894,7 +2568,7 @@ function Tabs({
|
|
|
3894
2568
|
{
|
|
3895
2569
|
onClick: () => !disabled && onTabChange("deposit"),
|
|
3896
2570
|
disabled,
|
|
3897
|
-
className: cn(
|
|
2571
|
+
className: chunkRDMJGMI3_cjs.cn(
|
|
3898
2572
|
"relative z-10 flex-1 rounded-md px-3 py-[9px] text-sm transition-colors",
|
|
3899
2573
|
activeTab === "deposit" ? "text-foreground" : "text-muted-foreground",
|
|
3900
2574
|
disabled ? "cursor-not-allowed" : "cursor-pointer"
|
|
@@ -3907,7 +2581,7 @@ function Tabs({
|
|
|
3907
2581
|
{
|
|
3908
2582
|
onClick: () => !disabled && onTabChange("withdraw"),
|
|
3909
2583
|
disabled,
|
|
3910
|
-
className: cn(
|
|
2584
|
+
className: chunkRDMJGMI3_cjs.cn(
|
|
3911
2585
|
"relative z-10 flex-1 rounded-md px-3 py-[9px] text-sm transition-colors",
|
|
3912
2586
|
activeTab === "withdraw" ? "text-foreground" : "text-muted-foreground",
|
|
3913
2587
|
disabled ? "cursor-not-allowed" : "cursor-pointer"
|
|
@@ -3920,14 +2594,14 @@ function Tabs({
|
|
|
3920
2594
|
);
|
|
3921
2595
|
}
|
|
3922
2596
|
function LockedFundsView({ onBack }) {
|
|
3923
|
-
const { getTokenById } = usePrivanaContext();
|
|
2597
|
+
const { getTokenById } = chunkRDMJGMI3_cjs.usePrivanaContext();
|
|
3924
2598
|
const { locks, isLoading } = useLockedFunds();
|
|
3925
2599
|
const { unlockFunds, unlockAllExpired, isPending } = useUnlockFunds();
|
|
3926
2600
|
const [collapsedSections, setCollapsedSections] = react.useState({});
|
|
3927
2601
|
const sections = react.useMemo(() => {
|
|
3928
2602
|
const sectionMap = {};
|
|
3929
2603
|
locks.forEach((lock) => {
|
|
3930
|
-
const serviceName = shortenAddress(lock.service_address);
|
|
2604
|
+
const serviceName = chunkRDMJGMI3_cjs.shortenAddress(lock.service_address);
|
|
3931
2605
|
if (!sectionMap[lock.service_address]) {
|
|
3932
2606
|
sectionMap[lock.service_address] = {
|
|
3933
2607
|
title: `Service ${serviceName}`,
|
|
@@ -3936,9 +2610,9 @@ function LockedFundsView({ onBack }) {
|
|
|
3936
2610
|
}
|
|
3937
2611
|
sectionMap[lock.service_address].items.push({
|
|
3938
2612
|
lockId: lock.lock_id,
|
|
3939
|
-
amount: formatTokenAmount(String(lock.amount), getTokenById(lock.token_id)?.decimals ?? 18),
|
|
2613
|
+
amount: chunkRDMJGMI3_cjs.formatTokenAmount(String(lock.amount), getTokenById(lock.token_id)?.decimals ?? 18),
|
|
3940
2614
|
serviceAddress: lock.service_address,
|
|
3941
|
-
time: lock.is_expired ? "Click to unlock" : formatTimeRemaining(lock.expiry),
|
|
2615
|
+
time: lock.is_expired ? "Click to unlock" : chunkRDMJGMI3_cjs.formatTimeRemaining(lock.expiry),
|
|
3942
2616
|
isExpired: lock.is_expired
|
|
3943
2617
|
});
|
|
3944
2618
|
});
|
|
@@ -3985,7 +2659,7 @@ function LockedFundsView({ onBack }) {
|
|
|
3985
2659
|
!collapsedSections[section.title] && section.items.map((item) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
3986
2660
|
"div",
|
|
3987
2661
|
{
|
|
3988
|
-
className: cn(
|
|
2662
|
+
className: chunkRDMJGMI3_cjs.cn(
|
|
3989
2663
|
"flex items-center justify-between gap-3 rounded-lg p-3",
|
|
3990
2664
|
item.isExpired && "bg-secondary"
|
|
3991
2665
|
),
|
|
@@ -3999,7 +2673,7 @@ function LockedFundsView({ onBack }) {
|
|
|
3999
2673
|
] }),
|
|
4000
2674
|
/* @__PURE__ */ jsxRuntime.jsxs("span", { className: "text-muted-foreground text-xs", children: [
|
|
4001
2675
|
"Service: ",
|
|
4002
|
-
shortenAddress(item.serviceAddress)
|
|
2676
|
+
chunkRDMJGMI3_cjs.shortenAddress(item.serviceAddress)
|
|
4003
2677
|
] })
|
|
4004
2678
|
] })
|
|
4005
2679
|
] }),
|
|
@@ -4040,7 +2714,7 @@ function BalanceTokenRow({ token }) {
|
|
|
4040
2714
|
const { balanceWei, isLoading } = useBalance({
|
|
4041
2715
|
tokenId: token.id
|
|
4042
2716
|
});
|
|
4043
|
-
const formattedBalance = formatTokenAmount(balanceWei, token.decimals);
|
|
2717
|
+
const formattedBalance = chunkRDMJGMI3_cjs.formatTokenAmount(balanceWei, token.decimals);
|
|
4044
2718
|
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full items-center gap-2 rounded-lg px-3 py-2.5", children: [
|
|
4045
2719
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "h-[18px] w-[18px] overflow-hidden rounded-full", children: getTokenIcon(token.symbol, 18) }),
|
|
4046
2720
|
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-foreground flex-1 text-sm", children: token.symbol }),
|
|
@@ -4048,7 +2722,7 @@ function BalanceTokenRow({ token }) {
|
|
|
4048
2722
|
] });
|
|
4049
2723
|
}
|
|
4050
2724
|
function BalanceDetailsView({ onBack }) {
|
|
4051
|
-
const { enabledTokens, chains } = usePrivanaContext();
|
|
2725
|
+
const { enabledTokens, chains } = chunkRDMJGMI3_cjs.usePrivanaContext();
|
|
4052
2726
|
const [selectedChainId, setSelectedChainId] = react.useState(chains[0]?.id ?? 84532);
|
|
4053
2727
|
const chainTokens = react.useMemo(() => {
|
|
4054
2728
|
return enabledTokens.filter((t) => t.chainId === selectedChainId);
|
|
@@ -4074,7 +2748,7 @@ function BalanceDetailsView({ onBack }) {
|
|
|
4074
2748
|
"button",
|
|
4075
2749
|
{
|
|
4076
2750
|
onClick: () => setSelectedChainId(chain.id),
|
|
4077
|
-
className: cn(
|
|
2751
|
+
className: chunkRDMJGMI3_cjs.cn(
|
|
4078
2752
|
"hover:bg-secondary flex w-full cursor-pointer items-center gap-2 rounded-lg px-3 py-2.5 text-left transition-colors",
|
|
4079
2753
|
isSelected && "bg-secondary"
|
|
4080
2754
|
),
|
|
@@ -4115,12 +2789,12 @@ function TokenRow({
|
|
|
4115
2789
|
query: { enabled: !!address && !isNative }
|
|
4116
2790
|
});
|
|
4117
2791
|
const walletBalance = isNative ? nativeBalanceData?.value : erc20Balance;
|
|
4118
|
-
const formattedBalance = walletBalance ? formatTokenAmount(walletBalance.toString(), token.decimals) : "0.00";
|
|
2792
|
+
const formattedBalance = walletBalance ? chunkRDMJGMI3_cjs.formatTokenAmount(walletBalance.toString(), token.decimals) : "0.00";
|
|
4119
2793
|
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
4120
2794
|
"button",
|
|
4121
2795
|
{
|
|
4122
2796
|
onClick,
|
|
4123
|
-
className: cn(
|
|
2797
|
+
className: chunkRDMJGMI3_cjs.cn(
|
|
4124
2798
|
"hover:bg-secondary flex w-full cursor-pointer items-center gap-2 rounded-lg px-3 py-2.5 text-left transition-colors",
|
|
4125
2799
|
isSelected && "bg-secondary"
|
|
4126
2800
|
),
|
|
@@ -4137,7 +2811,7 @@ function TokenSelectorView({
|
|
|
4137
2811
|
onSelect,
|
|
4138
2812
|
selectedTokenId
|
|
4139
2813
|
}) {
|
|
4140
|
-
const { enabledTokens, chains } = usePrivanaContext();
|
|
2814
|
+
const { enabledTokens, chains } = chunkRDMJGMI3_cjs.usePrivanaContext();
|
|
4141
2815
|
const [selectedChainId, setSelectedChainId] = react.useState(chains[0]?.id ?? 84532);
|
|
4142
2816
|
const chainTokens = react.useMemo(() => {
|
|
4143
2817
|
return enabledTokens.filter((t) => t.chainId === selectedChainId);
|
|
@@ -4167,7 +2841,7 @@ function TokenSelectorView({
|
|
|
4167
2841
|
"button",
|
|
4168
2842
|
{
|
|
4169
2843
|
onClick: () => setSelectedChainId(chain.id),
|
|
4170
|
-
className: cn(
|
|
2844
|
+
className: chunkRDMJGMI3_cjs.cn(
|
|
4171
2845
|
"hover:bg-secondary flex w-full cursor-pointer items-center gap-2 rounded-lg px-3 py-2.5 text-left transition-colors",
|
|
4172
2846
|
isSelected && "bg-secondary"
|
|
4173
2847
|
),
|
|
@@ -4202,7 +2876,7 @@ function ModalBody({
|
|
|
4202
2876
|
defaultTab = "deposit",
|
|
4203
2877
|
onDepositSuccess
|
|
4204
2878
|
}) {
|
|
4205
|
-
const { defaultToken, tokensStatus } = usePrivanaContext();
|
|
2879
|
+
const { defaultToken, tokensStatus } = chunkRDMJGMI3_cjs.usePrivanaContext();
|
|
4206
2880
|
const [selectedToken, setSelectedToken] = react.useState(defaultToken);
|
|
4207
2881
|
const [activeTab, setActiveTab] = react.useState(defaultTab);
|
|
4208
2882
|
const [currentView, setCurrentView] = react.useState("main");
|
|
@@ -4260,7 +2934,7 @@ function ModalBody({
|
|
|
4260
2934
|
);
|
|
4261
2935
|
}
|
|
4262
2936
|
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-2 pb-4", children: [
|
|
4263
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: cn(isInteractionPending && "pointer-events-none"), children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
2937
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: chunkRDMJGMI3_cjs.cn(isInteractionPending && "pointer-events-none"), children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
4264
2938
|
BalanceCards,
|
|
4265
2939
|
{
|
|
4266
2940
|
selectedToken,
|
|
@@ -4270,7 +2944,7 @@ function ModalBody({
|
|
|
4270
2944
|
disabled: isInteractionPending
|
|
4271
2945
|
}
|
|
4272
2946
|
) }),
|
|
4273
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: cn(isInteractionPending && "pointer-events-none"), children: /* @__PURE__ */ jsxRuntime.jsx(Tabs, { activeTab, onTabChange: setActiveTab, disabled: isInteractionPending }) }),
|
|
2947
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: chunkRDMJGMI3_cjs.cn(isInteractionPending && "pointer-events-none"), children: /* @__PURE__ */ jsxRuntime.jsx(Tabs, { activeTab, onTabChange: setActiveTab, disabled: isInteractionPending }) }),
|
|
4274
2948
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "bg-muted rounded-[10px] p-5", children: activeTab === "deposit" ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
4275
2949
|
DepositForm,
|
|
4276
2950
|
{
|
|
@@ -4331,7 +3005,7 @@ function PrivanaModal({
|
|
|
4331
3005
|
onClick: handleClose,
|
|
4332
3006
|
disabled: isCloseBlocked,
|
|
4333
3007
|
"aria-label": "Close",
|
|
4334
|
-
className: cn(
|
|
3008
|
+
className: chunkRDMJGMI3_cjs.cn(
|
|
4335
3009
|
"absolute top-6 right-5 z-20 flex h-6 w-6 items-center justify-center transition-colors",
|
|
4336
3010
|
isCloseBlocked ? "text-muted-foreground/40 cursor-not-allowed" : "text-muted-foreground hover:text-foreground cursor-pointer"
|
|
4337
3011
|
),
|
|
@@ -4387,7 +3061,7 @@ function PrivanaInlineModal({
|
|
|
4387
3061
|
"div",
|
|
4388
3062
|
{
|
|
4389
3063
|
"data-privana": true,
|
|
4390
|
-
className: cn(
|
|
3064
|
+
className: chunkRDMJGMI3_cjs.cn(
|
|
4391
3065
|
"bg-card flex w-[560px] max-w-full flex-col gap-2 overflow-hidden rounded-2xl p-2 shadow-lg",
|
|
4392
3066
|
className
|
|
4393
3067
|
),
|
|
@@ -4422,12 +3096,12 @@ function PrivanaButton({
|
|
|
4422
3096
|
}
|
|
4423
3097
|
const handleClick = () => setModalOpen(true);
|
|
4424
3098
|
const buttonElement = renderButton ? renderButton({ onClick: handleClick, isOpen: modalOpen }) : /* @__PURE__ */ jsxRuntime.jsx(
|
|
4425
|
-
Button,
|
|
3099
|
+
chunkRDMJGMI3_cjs.Button,
|
|
4426
3100
|
{
|
|
4427
3101
|
variant,
|
|
4428
3102
|
size,
|
|
4429
3103
|
asChild,
|
|
4430
|
-
className: cn(className),
|
|
3104
|
+
className: chunkRDMJGMI3_cjs.cn(className),
|
|
4431
3105
|
onClick: handleClick,
|
|
4432
3106
|
disabled: !isConnected,
|
|
4433
3107
|
...buttonProps,
|
|
@@ -4453,69 +3127,204 @@ function Skeleton({ className, ...props }) {
|
|
|
4453
3127
|
"div",
|
|
4454
3128
|
{
|
|
4455
3129
|
"data-slot": "skeleton",
|
|
4456
|
-
className: cn("bg-accent animate-pulse rounded-md", className),
|
|
3130
|
+
className: chunkRDMJGMI3_cjs.cn("bg-accent animate-pulse rounded-md", className),
|
|
4457
3131
|
...props
|
|
4458
3132
|
}
|
|
4459
3133
|
);
|
|
4460
3134
|
}
|
|
4461
3135
|
|
|
4462
|
-
exports
|
|
4463
|
-
|
|
4464
|
-
|
|
4465
|
-
|
|
4466
|
-
exports
|
|
4467
|
-
|
|
4468
|
-
|
|
3136
|
+
Object.defineProperty(exports, "AccountingApiError", {
|
|
3137
|
+
enumerable: true,
|
|
3138
|
+
get: function () { return chunkRDMJGMI3_cjs.AccountingApiError; }
|
|
3139
|
+
});
|
|
3140
|
+
Object.defineProperty(exports, "Button", {
|
|
3141
|
+
enumerable: true,
|
|
3142
|
+
get: function () { return chunkRDMJGMI3_cjs.Button; }
|
|
3143
|
+
});
|
|
3144
|
+
Object.defineProperty(exports, "HOSTED_AUTH_CLOCK_SKEW_MS", {
|
|
3145
|
+
enumerable: true,
|
|
3146
|
+
get: function () { return chunkRDMJGMI3_cjs.HOSTED_AUTH_CLOCK_SKEW_MS; }
|
|
3147
|
+
});
|
|
3148
|
+
Object.defineProperty(exports, "HostedAuthError", {
|
|
3149
|
+
enumerable: true,
|
|
3150
|
+
get: function () { return chunkRDMJGMI3_cjs.HostedAuthError; }
|
|
3151
|
+
});
|
|
3152
|
+
Object.defineProperty(exports, "HostedAuthRequiredError", {
|
|
3153
|
+
enumerable: true,
|
|
3154
|
+
get: function () { return chunkRDMJGMI3_cjs.HostedAuthRequiredError; }
|
|
3155
|
+
});
|
|
3156
|
+
Object.defineProperty(exports, "HostedAuthStateMismatchError", {
|
|
3157
|
+
enumerable: true,
|
|
3158
|
+
get: function () { return chunkRDMJGMI3_cjs.HostedAuthStateMismatchError; }
|
|
3159
|
+
});
|
|
3160
|
+
Object.defineProperty(exports, "HttpClient", {
|
|
3161
|
+
enumerable: true,
|
|
3162
|
+
get: function () { return chunkRDMJGMI3_cjs.HttpClient; }
|
|
3163
|
+
});
|
|
3164
|
+
Object.defineProperty(exports, "NETWORK_CONFIG", {
|
|
3165
|
+
enumerable: true,
|
|
3166
|
+
get: function () { return chunkRDMJGMI3_cjs.NETWORK_CONFIG; }
|
|
3167
|
+
});
|
|
3168
|
+
Object.defineProperty(exports, "NetworkError", {
|
|
3169
|
+
enumerable: true,
|
|
3170
|
+
get: function () { return chunkRDMJGMI3_cjs.NetworkError; }
|
|
3171
|
+
});
|
|
3172
|
+
Object.defineProperty(exports, "PrivanaClient", {
|
|
3173
|
+
enumerable: true,
|
|
3174
|
+
get: function () { return chunkRDMJGMI3_cjs.PrivanaClient; }
|
|
3175
|
+
});
|
|
3176
|
+
Object.defineProperty(exports, "PrivanaProvider", {
|
|
3177
|
+
enumerable: true,
|
|
3178
|
+
get: function () { return chunkRDMJGMI3_cjs.PrivanaProvider; }
|
|
3179
|
+
});
|
|
3180
|
+
Object.defineProperty(exports, "SUPPORTED_CHAINS", {
|
|
3181
|
+
enumerable: true,
|
|
3182
|
+
get: function () { return chunkRDMJGMI3_cjs.SUPPORTED_CHAINS; }
|
|
3183
|
+
});
|
|
3184
|
+
Object.defineProperty(exports, "SiweAuthProvider", {
|
|
3185
|
+
enumerable: true,
|
|
3186
|
+
get: function () { return chunkRDMJGMI3_cjs.SiweAuthProvider; }
|
|
3187
|
+
});
|
|
3188
|
+
Object.defineProperty(exports, "ValidationError", {
|
|
3189
|
+
enumerable: true,
|
|
3190
|
+
get: function () { return chunkRDMJGMI3_cjs.ValidationError; }
|
|
3191
|
+
});
|
|
3192
|
+
Object.defineProperty(exports, "applyRefreshResponse", {
|
|
3193
|
+
enumerable: true,
|
|
3194
|
+
get: function () { return chunkRDMJGMI3_cjs.applyRefreshResponse; }
|
|
3195
|
+
});
|
|
3196
|
+
Object.defineProperty(exports, "buildHostedAuthSession", {
|
|
3197
|
+
enumerable: true,
|
|
3198
|
+
get: function () { return chunkRDMJGMI3_cjs.buildHostedAuthSession; }
|
|
3199
|
+
});
|
|
3200
|
+
Object.defineProperty(exports, "buttonVariants", {
|
|
3201
|
+
enumerable: true,
|
|
3202
|
+
get: function () { return chunkRDMJGMI3_cjs.buttonVariants; }
|
|
3203
|
+
});
|
|
3204
|
+
Object.defineProperty(exports, "clearHostedAuthPendingTransaction", {
|
|
3205
|
+
enumerable: true,
|
|
3206
|
+
get: function () { return chunkRDMJGMI3_cjs.clearHostedAuthPendingTransaction; }
|
|
3207
|
+
});
|
|
3208
|
+
Object.defineProperty(exports, "createHostedAuthPendingStorageKey", {
|
|
3209
|
+
enumerable: true,
|
|
3210
|
+
get: function () { return chunkRDMJGMI3_cjs.createHostedAuthPendingStorageKey; }
|
|
3211
|
+
});
|
|
3212
|
+
Object.defineProperty(exports, "createHostedAuthState", {
|
|
3213
|
+
enumerable: true,
|
|
3214
|
+
get: function () { return chunkRDMJGMI3_cjs.createHostedAuthState; }
|
|
3215
|
+
});
|
|
3216
|
+
Object.defineProperty(exports, "createHostedAuthStorageKey", {
|
|
3217
|
+
enumerable: true,
|
|
3218
|
+
get: function () { return chunkRDMJGMI3_cjs.createHostedAuthStorageKey; }
|
|
3219
|
+
});
|
|
3220
|
+
Object.defineProperty(exports, "createPkceChallenge", {
|
|
3221
|
+
enumerable: true,
|
|
3222
|
+
get: function () { return chunkRDMJGMI3_cjs.createPkceChallenge; }
|
|
3223
|
+
});
|
|
3224
|
+
Object.defineProperty(exports, "createPkceVerifier", {
|
|
3225
|
+
enumerable: true,
|
|
3226
|
+
get: function () { return chunkRDMJGMI3_cjs.createPkceVerifier; }
|
|
3227
|
+
});
|
|
3228
|
+
Object.defineProperty(exports, "getAccountingContract", {
|
|
3229
|
+
enumerable: true,
|
|
3230
|
+
get: function () { return chunkRDMJGMI3_cjs.getAccountingContract; }
|
|
3231
|
+
});
|
|
3232
|
+
Object.defineProperty(exports, "getApiUrl", {
|
|
3233
|
+
enumerable: true,
|
|
3234
|
+
get: function () { return chunkRDMJGMI3_cjs.getApiUrl; }
|
|
3235
|
+
});
|
|
3236
|
+
Object.defineProperty(exports, "getChainById", {
|
|
3237
|
+
enumerable: true,
|
|
3238
|
+
get: function () { return chunkRDMJGMI3_cjs.getChainById; }
|
|
3239
|
+
});
|
|
3240
|
+
Object.defineProperty(exports, "getChainId", {
|
|
3241
|
+
enumerable: true,
|
|
3242
|
+
get: function () { return chunkRDMJGMI3_cjs.getChainId; }
|
|
3243
|
+
});
|
|
3244
|
+
Object.defineProperty(exports, "getExplorerAddressUrl", {
|
|
3245
|
+
enumerable: true,
|
|
3246
|
+
get: function () { return chunkRDMJGMI3_cjs.getExplorerAddressUrl; }
|
|
3247
|
+
});
|
|
3248
|
+
Object.defineProperty(exports, "isHostedAuthRefreshActive", {
|
|
3249
|
+
enumerable: true,
|
|
3250
|
+
get: function () { return chunkRDMJGMI3_cjs.isHostedAuthRefreshActive; }
|
|
3251
|
+
});
|
|
3252
|
+
Object.defineProperty(exports, "isHostedAuthSessionActive", {
|
|
3253
|
+
enumerable: true,
|
|
3254
|
+
get: function () { return chunkRDMJGMI3_cjs.isHostedAuthSessionActive; }
|
|
3255
|
+
});
|
|
3256
|
+
Object.defineProperty(exports, "normalizeAddress", {
|
|
3257
|
+
enumerable: true,
|
|
3258
|
+
get: function () { return chunkRDMJGMI3_cjs.normalizeAddress; }
|
|
3259
|
+
});
|
|
3260
|
+
Object.defineProperty(exports, "normalizeHex", {
|
|
3261
|
+
enumerable: true,
|
|
3262
|
+
get: function () { return chunkRDMJGMI3_cjs.normalizeHex; }
|
|
3263
|
+
});
|
|
3264
|
+
Object.defineProperty(exports, "parseHostedAuthCallback", {
|
|
3265
|
+
enumerable: true,
|
|
3266
|
+
get: function () { return chunkRDMJGMI3_cjs.parseHostedAuthCallback; }
|
|
3267
|
+
});
|
|
3268
|
+
Object.defineProperty(exports, "persistHostedAuthPendingTransaction", {
|
|
3269
|
+
enumerable: true,
|
|
3270
|
+
get: function () { return chunkRDMJGMI3_cjs.persistHostedAuthPendingTransaction; }
|
|
3271
|
+
});
|
|
3272
|
+
Object.defineProperty(exports, "readHostedAuthPendingTransaction", {
|
|
3273
|
+
enumerable: true,
|
|
3274
|
+
get: function () { return chunkRDMJGMI3_cjs.readHostedAuthPendingTransaction; }
|
|
3275
|
+
});
|
|
3276
|
+
Object.defineProperty(exports, "readStoredHostedAuthSession", {
|
|
3277
|
+
enumerable: true,
|
|
3278
|
+
get: function () { return chunkRDMJGMI3_cjs.readStoredHostedAuthSession; }
|
|
3279
|
+
});
|
|
3280
|
+
Object.defineProperty(exports, "stripHostedAuthCallbackParams", {
|
|
3281
|
+
enumerable: true,
|
|
3282
|
+
get: function () { return chunkRDMJGMI3_cjs.stripHostedAuthCallbackParams; }
|
|
3283
|
+
});
|
|
3284
|
+
Object.defineProperty(exports, "syncHostedAuthSessionToClient", {
|
|
3285
|
+
enumerable: true,
|
|
3286
|
+
get: function () { return chunkRDMJGMI3_cjs.syncHostedAuthSessionToClient; }
|
|
3287
|
+
});
|
|
3288
|
+
Object.defineProperty(exports, "useDepositVerification", {
|
|
3289
|
+
enumerable: true,
|
|
3290
|
+
get: function () { return chunkRDMJGMI3_cjs.useDepositVerification; }
|
|
3291
|
+
});
|
|
3292
|
+
Object.defineProperty(exports, "usePrivanaContext", {
|
|
3293
|
+
enumerable: true,
|
|
3294
|
+
get: function () { return chunkRDMJGMI3_cjs.usePrivanaContext; }
|
|
3295
|
+
});
|
|
3296
|
+
Object.defineProperty(exports, "useSafeAccount", {
|
|
3297
|
+
enumerable: true,
|
|
3298
|
+
get: function () { return chunkRDMJGMI3_cjs.useSafeAccount; }
|
|
3299
|
+
});
|
|
3300
|
+
Object.defineProperty(exports, "useSafePrivanaContext", {
|
|
3301
|
+
enumerable: true,
|
|
3302
|
+
get: function () { return chunkRDMJGMI3_cjs.useSafePrivanaContext; }
|
|
3303
|
+
});
|
|
3304
|
+
Object.defineProperty(exports, "useSiweAuth", {
|
|
3305
|
+
enumerable: true,
|
|
3306
|
+
get: function () { return chunkRDMJGMI3_cjs.useSiweAuth; }
|
|
3307
|
+
});
|
|
4469
3308
|
exports.LOCK_TYPES = LOCK_TYPES;
|
|
4470
3309
|
exports.MODIFY_LOCK_TYPES = MODIFY_LOCK_TYPES;
|
|
4471
|
-
exports.NETWORK_CONFIG = NETWORK_CONFIG;
|
|
4472
|
-
exports.NetworkError = NetworkError;
|
|
4473
3310
|
exports.PrivanaButton = PrivanaButton;
|
|
4474
|
-
exports.PrivanaClient = PrivanaClient;
|
|
4475
3311
|
exports.PrivanaInlineModal = PrivanaInlineModal;
|
|
4476
3312
|
exports.PrivanaModal = PrivanaModal;
|
|
4477
|
-
exports.PrivanaProvider = PrivanaProvider;
|
|
4478
|
-
exports.SUPPORTED_CHAINS = SUPPORTED_CHAINS;
|
|
4479
3313
|
exports.Skeleton = Skeleton;
|
|
4480
3314
|
exports.TRANSFER_LOCKED_TYPES = TRANSFER_LOCKED_TYPES;
|
|
4481
3315
|
exports.TRANSFER_TYPES = TRANSFER_TYPES;
|
|
4482
|
-
exports.ValidationError = ValidationError;
|
|
4483
3316
|
exports.WITHDRAW_FROM_LOCK_TYPES = WITHDRAW_FROM_LOCK_TYPES;
|
|
4484
3317
|
exports.WITHDRAW_TYPES = WITHDRAW_TYPES;
|
|
4485
|
-
exports.applyRefreshResponse = applyRefreshResponse;
|
|
4486
|
-
exports.buildHostedAuthSession = buildHostedAuthSession;
|
|
4487
|
-
exports.buttonVariants = buttonVariants;
|
|
4488
|
-
exports.clearHostedAuthPendingTransaction = clearHostedAuthPendingTransaction;
|
|
4489
3318
|
exports.createDomain = createDomain;
|
|
4490
|
-
exports.createHostedAuthPendingStorageKey = createHostedAuthPendingStorageKey;
|
|
4491
|
-
exports.createHostedAuthState = createHostedAuthState;
|
|
4492
|
-
exports.createHostedAuthStorageKey = createHostedAuthStorageKey;
|
|
4493
3319
|
exports.createLockExpiry = createLockExpiry;
|
|
4494
|
-
exports.createPkceChallenge = createPkceChallenge;
|
|
4495
|
-
exports.createPkceVerifier = createPkceVerifier;
|
|
4496
|
-
exports.getAccountingContract = getAccountingContract;
|
|
4497
|
-
exports.getApiUrl = getApiUrl;
|
|
4498
|
-
exports.getChainById = getChainById;
|
|
4499
3320
|
exports.getChainIcon = getChainIcon;
|
|
4500
|
-
exports.getChainId = getChainId;
|
|
4501
|
-
exports.getExplorerAddressUrl = getExplorerAddressUrl;
|
|
4502
3321
|
exports.getTokenIcon = getTokenIcon;
|
|
4503
|
-
exports.isHostedAuthRefreshActive = isHostedAuthRefreshActive;
|
|
4504
|
-
exports.isHostedAuthSessionActive = isHostedAuthSessionActive;
|
|
4505
|
-
exports.normalizeAddress = normalizeAddress;
|
|
4506
|
-
exports.normalizeHex = normalizeHex;
|
|
4507
|
-
exports.parseHostedAuthCallback = parseHostedAuthCallback;
|
|
4508
|
-
exports.persistHostedAuthPendingTransaction = persistHostedAuthPendingTransaction;
|
|
4509
|
-
exports.readHostedAuthPendingTransaction = readHostedAuthPendingTransaction;
|
|
4510
|
-
exports.readStoredHostedAuthSession = readStoredHostedAuthSession;
|
|
4511
3322
|
exports.signLockMessage = signLockMessage;
|
|
4512
3323
|
exports.signModifyLockMessage = signModifyLockMessage;
|
|
4513
3324
|
exports.signTransferLockedMessage = signTransferLockedMessage;
|
|
4514
3325
|
exports.signTransferMessage = signTransferMessage;
|
|
4515
3326
|
exports.signWithdrawFromLockMessage = signWithdrawFromLockMessage;
|
|
4516
3327
|
exports.signWithdrawMessage = signWithdrawMessage;
|
|
4517
|
-
exports.stripHostedAuthCallbackParams = stripHostedAuthCallbackParams;
|
|
4518
|
-
exports.syncHostedAuthSessionToClient = syncHostedAuthSessionToClient;
|
|
4519
3328
|
exports.useBalance = useBalance;
|
|
4520
3329
|
exports.useBatchBalances = useBatchBalances;
|
|
4521
3330
|
exports.useDeposit = useDeposit;
|
|
@@ -4527,9 +3336,6 @@ exports.useLockedFunds = useLockedFunds;
|
|
|
4527
3336
|
exports.useModifyLock = useModifyLock;
|
|
4528
3337
|
exports.usePendingWithdrawals = usePendingWithdrawals;
|
|
4529
3338
|
exports.usePrivanaClient = usePrivanaClient;
|
|
4530
|
-
exports.usePrivanaContext = usePrivanaContext;
|
|
4531
|
-
exports.useSafeAccount = useSafeAccount;
|
|
4532
|
-
exports.useSafePrivanaContext = useSafePrivanaContext;
|
|
4533
3339
|
exports.useTokenInfo = useTokenInfo;
|
|
4534
3340
|
exports.useTokenList = useTokenList;
|
|
4535
3341
|
exports.useTotalLockedBalance = useTotalLockedBalance;
|