@swype-org/react-sdk 0.1.228 → 0.1.230
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +502 -461
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -3
- package/dist/index.d.ts +9 -3
- package/dist/index.js +502 -461
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -158,316 +158,19 @@ function useBlinkDepositAmount() {
|
|
|
158
158
|
};
|
|
159
159
|
}
|
|
160
160
|
|
|
161
|
-
// node_modules/@wagmi/core/dist/esm/utils/getAction.js
|
|
162
|
-
function getAction(client, actionFn, name) {
|
|
163
|
-
const action_implicit = client[actionFn.name];
|
|
164
|
-
if (typeof action_implicit === "function")
|
|
165
|
-
return action_implicit;
|
|
166
|
-
const action_explicit = client[name];
|
|
167
|
-
if (typeof action_explicit === "function")
|
|
168
|
-
return action_explicit;
|
|
169
|
-
return (params) => actionFn(client, params);
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
// node_modules/@wagmi/core/dist/esm/version.js
|
|
173
|
-
var version = "2.22.1";
|
|
174
|
-
|
|
175
|
-
// node_modules/@wagmi/core/dist/esm/utils/getVersion.js
|
|
176
|
-
var getVersion = () => `@wagmi/core@${version}`;
|
|
177
|
-
|
|
178
|
-
// node_modules/@wagmi/core/dist/esm/errors/base.js
|
|
179
|
-
var __classPrivateFieldGet = function(receiver, state, kind, f) {
|
|
180
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
181
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
182
|
-
};
|
|
183
|
-
var _BaseError_instances;
|
|
184
|
-
var _BaseError_walk;
|
|
185
|
-
var BaseError = class _BaseError extends Error {
|
|
186
|
-
get docsBaseUrl() {
|
|
187
|
-
return "https://wagmi.sh/core";
|
|
188
|
-
}
|
|
189
|
-
get version() {
|
|
190
|
-
return getVersion();
|
|
191
|
-
}
|
|
192
|
-
constructor(shortMessage, options = {}) {
|
|
193
|
-
super();
|
|
194
|
-
_BaseError_instances.add(this);
|
|
195
|
-
Object.defineProperty(this, "details", {
|
|
196
|
-
enumerable: true,
|
|
197
|
-
configurable: true,
|
|
198
|
-
writable: true,
|
|
199
|
-
value: void 0
|
|
200
|
-
});
|
|
201
|
-
Object.defineProperty(this, "docsPath", {
|
|
202
|
-
enumerable: true,
|
|
203
|
-
configurable: true,
|
|
204
|
-
writable: true,
|
|
205
|
-
value: void 0
|
|
206
|
-
});
|
|
207
|
-
Object.defineProperty(this, "metaMessages", {
|
|
208
|
-
enumerable: true,
|
|
209
|
-
configurable: true,
|
|
210
|
-
writable: true,
|
|
211
|
-
value: void 0
|
|
212
|
-
});
|
|
213
|
-
Object.defineProperty(this, "shortMessage", {
|
|
214
|
-
enumerable: true,
|
|
215
|
-
configurable: true,
|
|
216
|
-
writable: true,
|
|
217
|
-
value: void 0
|
|
218
|
-
});
|
|
219
|
-
Object.defineProperty(this, "name", {
|
|
220
|
-
enumerable: true,
|
|
221
|
-
configurable: true,
|
|
222
|
-
writable: true,
|
|
223
|
-
value: "WagmiCoreError"
|
|
224
|
-
});
|
|
225
|
-
const details = options.cause instanceof _BaseError ? options.cause.details : options.cause?.message ? options.cause.message : options.details;
|
|
226
|
-
const docsPath = options.cause instanceof _BaseError ? options.cause.docsPath || options.docsPath : options.docsPath;
|
|
227
|
-
this.message = [
|
|
228
|
-
shortMessage || "An error occurred.",
|
|
229
|
-
"",
|
|
230
|
-
...options.metaMessages ? [...options.metaMessages, ""] : [],
|
|
231
|
-
...docsPath ? [
|
|
232
|
-
`Docs: ${this.docsBaseUrl}${docsPath}.html${options.docsSlug ? `#${options.docsSlug}` : ""}`
|
|
233
|
-
] : [],
|
|
234
|
-
...details ? [`Details: ${details}`] : [],
|
|
235
|
-
`Version: ${this.version}`
|
|
236
|
-
].join("\n");
|
|
237
|
-
if (options.cause)
|
|
238
|
-
this.cause = options.cause;
|
|
239
|
-
this.details = details;
|
|
240
|
-
this.docsPath = docsPath;
|
|
241
|
-
this.metaMessages = options.metaMessages;
|
|
242
|
-
this.shortMessage = shortMessage;
|
|
243
|
-
}
|
|
244
|
-
walk(fn) {
|
|
245
|
-
return __classPrivateFieldGet(this, _BaseError_instances, "m", _BaseError_walk).call(this, this, fn);
|
|
246
|
-
}
|
|
247
|
-
};
|
|
248
|
-
_BaseError_instances = /* @__PURE__ */ new WeakSet(), _BaseError_walk = function _BaseError_walk2(err, fn) {
|
|
249
|
-
if (fn?.(err))
|
|
250
|
-
return err;
|
|
251
|
-
if (err.cause)
|
|
252
|
-
return __classPrivateFieldGet(this, _BaseError_instances, "m", _BaseError_walk2).call(this, err.cause, fn);
|
|
253
|
-
return err;
|
|
254
|
-
};
|
|
255
|
-
|
|
256
|
-
// node_modules/@wagmi/core/dist/esm/errors/config.js
|
|
257
|
-
var ConnectorNotConnectedError = class extends BaseError {
|
|
258
|
-
constructor() {
|
|
259
|
-
super("Connector not connected.");
|
|
260
|
-
Object.defineProperty(this, "name", {
|
|
261
|
-
enumerable: true,
|
|
262
|
-
configurable: true,
|
|
263
|
-
writable: true,
|
|
264
|
-
value: "ConnectorNotConnectedError"
|
|
265
|
-
});
|
|
266
|
-
}
|
|
267
|
-
};
|
|
268
|
-
var ConnectorAccountNotFoundError = class extends BaseError {
|
|
269
|
-
constructor({ address, connector }) {
|
|
270
|
-
super(`Account "${address}" not found for connector "${connector.name}".`);
|
|
271
|
-
Object.defineProperty(this, "name", {
|
|
272
|
-
enumerable: true,
|
|
273
|
-
configurable: true,
|
|
274
|
-
writable: true,
|
|
275
|
-
value: "ConnectorAccountNotFoundError"
|
|
276
|
-
});
|
|
277
|
-
}
|
|
278
|
-
};
|
|
279
|
-
var ConnectorChainMismatchError = class extends BaseError {
|
|
280
|
-
constructor({ connectionChainId, connectorChainId }) {
|
|
281
|
-
super(`The current chain of the connector (id: ${connectorChainId}) does not match the connection's chain (id: ${connectionChainId}).`, {
|
|
282
|
-
metaMessages: [
|
|
283
|
-
`Current Chain ID: ${connectorChainId}`,
|
|
284
|
-
`Expected Chain ID: ${connectionChainId}`
|
|
285
|
-
]
|
|
286
|
-
});
|
|
287
|
-
Object.defineProperty(this, "name", {
|
|
288
|
-
enumerable: true,
|
|
289
|
-
configurable: true,
|
|
290
|
-
writable: true,
|
|
291
|
-
value: "ConnectorChainMismatchError"
|
|
292
|
-
});
|
|
293
|
-
}
|
|
294
|
-
};
|
|
295
|
-
var ConnectorUnavailableReconnectingError = class extends BaseError {
|
|
296
|
-
constructor({ connector }) {
|
|
297
|
-
super(`Connector "${connector.name}" unavailable while reconnecting.`, {
|
|
298
|
-
details: [
|
|
299
|
-
"During the reconnection step, the only connector methods guaranteed to be available are: `id`, `name`, `type`, `uid`.",
|
|
300
|
-
"All other methods are not guaranteed to be available until reconnection completes and connectors are fully restored.",
|
|
301
|
-
"This error commonly occurs for connectors that asynchronously inject after reconnection has already started."
|
|
302
|
-
].join(" ")
|
|
303
|
-
});
|
|
304
|
-
Object.defineProperty(this, "name", {
|
|
305
|
-
enumerable: true,
|
|
306
|
-
configurable: true,
|
|
307
|
-
writable: true,
|
|
308
|
-
value: "ConnectorUnavailableReconnectingError"
|
|
309
|
-
});
|
|
310
|
-
}
|
|
311
|
-
};
|
|
312
|
-
async function getConnectorClient(config, parameters = {}) {
|
|
313
|
-
const { assertChainId = true } = parameters;
|
|
314
|
-
let connection;
|
|
315
|
-
if (parameters.connector) {
|
|
316
|
-
const { connector: connector2 } = parameters;
|
|
317
|
-
if (config.state.status === "reconnecting" && !connector2.getAccounts && !connector2.getChainId)
|
|
318
|
-
throw new ConnectorUnavailableReconnectingError({ connector: connector2 });
|
|
319
|
-
const [accounts, chainId2] = await Promise.all([
|
|
320
|
-
connector2.getAccounts().catch((e) => {
|
|
321
|
-
if (parameters.account === null)
|
|
322
|
-
return [];
|
|
323
|
-
throw e;
|
|
324
|
-
}),
|
|
325
|
-
connector2.getChainId()
|
|
326
|
-
]);
|
|
327
|
-
connection = {
|
|
328
|
-
accounts,
|
|
329
|
-
chainId: chainId2,
|
|
330
|
-
connector: connector2
|
|
331
|
-
};
|
|
332
|
-
} else
|
|
333
|
-
connection = config.state.connections.get(config.state.current);
|
|
334
|
-
if (!connection)
|
|
335
|
-
throw new ConnectorNotConnectedError();
|
|
336
|
-
const chainId = parameters.chainId ?? connection.chainId;
|
|
337
|
-
const connectorChainId = await connection.connector.getChainId();
|
|
338
|
-
if (assertChainId && connectorChainId !== chainId)
|
|
339
|
-
throw new ConnectorChainMismatchError({
|
|
340
|
-
connectionChainId: chainId,
|
|
341
|
-
connectorChainId
|
|
342
|
-
});
|
|
343
|
-
const connector = connection.connector;
|
|
344
|
-
if (connector.getClient)
|
|
345
|
-
return connector.getClient({ chainId });
|
|
346
|
-
const account = utils.parseAccount(parameters.account ?? connection.accounts[0]);
|
|
347
|
-
if (account)
|
|
348
|
-
account.address = utils.getAddress(account.address);
|
|
349
|
-
if (parameters.account && !connection.accounts.some((x) => x.toLowerCase() === account.address.toLowerCase()))
|
|
350
|
-
throw new ConnectorAccountNotFoundError({
|
|
351
|
-
address: account.address,
|
|
352
|
-
connector
|
|
353
|
-
});
|
|
354
|
-
const chain = config.chains.find((chain2) => chain2.id === chainId);
|
|
355
|
-
const provider = await connection.connector.getProvider({ chainId });
|
|
356
|
-
return viem.createClient({
|
|
357
|
-
account,
|
|
358
|
-
chain,
|
|
359
|
-
name: "Connector Client",
|
|
360
|
-
transport: (opts) => viem.custom(provider)({ ...opts, retryCount: 0 })
|
|
361
|
-
});
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
// node_modules/@wagmi/core/dist/esm/actions/getAccount.js
|
|
365
|
-
function getAccount(config) {
|
|
366
|
-
const uid = config.state.current;
|
|
367
|
-
const connection = config.state.connections.get(uid);
|
|
368
|
-
const addresses = connection?.accounts;
|
|
369
|
-
const address = addresses?.[0];
|
|
370
|
-
const chain = config.chains.find((chain2) => chain2.id === connection?.chainId);
|
|
371
|
-
const status = config.state.status;
|
|
372
|
-
switch (status) {
|
|
373
|
-
case "connected":
|
|
374
|
-
return {
|
|
375
|
-
address,
|
|
376
|
-
addresses,
|
|
377
|
-
chain,
|
|
378
|
-
chainId: connection?.chainId,
|
|
379
|
-
connector: connection?.connector,
|
|
380
|
-
isConnected: true,
|
|
381
|
-
isConnecting: false,
|
|
382
|
-
isDisconnected: false,
|
|
383
|
-
isReconnecting: false,
|
|
384
|
-
status
|
|
385
|
-
};
|
|
386
|
-
case "reconnecting":
|
|
387
|
-
return {
|
|
388
|
-
address,
|
|
389
|
-
addresses,
|
|
390
|
-
chain,
|
|
391
|
-
chainId: connection?.chainId,
|
|
392
|
-
connector: connection?.connector,
|
|
393
|
-
isConnected: !!address,
|
|
394
|
-
isConnecting: false,
|
|
395
|
-
isDisconnected: false,
|
|
396
|
-
isReconnecting: true,
|
|
397
|
-
status
|
|
398
|
-
};
|
|
399
|
-
case "connecting":
|
|
400
|
-
return {
|
|
401
|
-
address,
|
|
402
|
-
addresses,
|
|
403
|
-
chain,
|
|
404
|
-
chainId: connection?.chainId,
|
|
405
|
-
connector: connection?.connector,
|
|
406
|
-
isConnected: false,
|
|
407
|
-
isConnecting: true,
|
|
408
|
-
isDisconnected: false,
|
|
409
|
-
isReconnecting: false,
|
|
410
|
-
status
|
|
411
|
-
};
|
|
412
|
-
case "disconnected":
|
|
413
|
-
return {
|
|
414
|
-
address: void 0,
|
|
415
|
-
addresses: void 0,
|
|
416
|
-
chain: void 0,
|
|
417
|
-
chainId: void 0,
|
|
418
|
-
connector: void 0,
|
|
419
|
-
isConnected: false,
|
|
420
|
-
isConnecting: false,
|
|
421
|
-
isDisconnected: true,
|
|
422
|
-
isReconnecting: false,
|
|
423
|
-
status
|
|
424
|
-
};
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
async function getWalletClient(config, parameters = {}) {
|
|
428
|
-
const client = await getConnectorClient(config, parameters);
|
|
429
|
-
return client.extend(viem.walletActions);
|
|
430
|
-
}
|
|
431
|
-
async function waitForTransactionReceipt(config, parameters) {
|
|
432
|
-
const { chainId, timeout = 0, ...rest } = parameters;
|
|
433
|
-
const client = config.getClient({ chainId });
|
|
434
|
-
const action = getAction(client, actions.waitForTransactionReceipt, "waitForTransactionReceipt");
|
|
435
|
-
const receipt = await action({ ...rest, timeout });
|
|
436
|
-
if (receipt.status === "reverted") {
|
|
437
|
-
const action_getTransaction = getAction(client, actions.getTransaction, "getTransaction");
|
|
438
|
-
const { from: account, ...txn } = await action_getTransaction({
|
|
439
|
-
hash: receipt.transactionHash
|
|
440
|
-
});
|
|
441
|
-
const action_call = getAction(client, actions.call, "call");
|
|
442
|
-
const code = await action_call({
|
|
443
|
-
...txn,
|
|
444
|
-
account,
|
|
445
|
-
data: txn.input,
|
|
446
|
-
gasPrice: txn.type !== "eip1559" ? txn.gasPrice : void 0,
|
|
447
|
-
maxFeePerGas: txn.type === "eip1559" ? txn.maxFeePerGas : void 0,
|
|
448
|
-
maxPriorityFeePerGas: txn.type === "eip1559" ? txn.maxPriorityFeePerGas : void 0
|
|
449
|
-
});
|
|
450
|
-
const reason = code?.data ? viem.hexToString(`0x${code.data.substring(138)}`) : "unknown reason";
|
|
451
|
-
throw new Error(reason);
|
|
452
|
-
}
|
|
453
|
-
return {
|
|
454
|
-
...receipt,
|
|
455
|
-
chainId: client.chain.id
|
|
456
|
-
};
|
|
457
|
-
}
|
|
458
|
-
|
|
459
161
|
// src/api.ts
|
|
460
162
|
var api_exports = {};
|
|
461
163
|
__export(api_exports, {
|
|
462
164
|
createAccount: () => createAccount,
|
|
463
165
|
createAccountAuthorizationSession: () => createAccountAuthorizationSession,
|
|
166
|
+
createGuestAccount: () => createGuestAccount,
|
|
464
167
|
createGuestTransfer: () => createGuestTransfer,
|
|
465
168
|
createTransfer: () => createTransfer,
|
|
466
169
|
fetchAccount: () => fetchAccount,
|
|
467
170
|
fetchAccounts: () => fetchAccounts,
|
|
468
171
|
fetchAuthorizationSession: () => fetchAuthorizationSession,
|
|
469
172
|
fetchChains: () => fetchChains,
|
|
470
|
-
|
|
173
|
+
fetchGuestAccount: () => fetchGuestAccount,
|
|
471
174
|
fetchGuestTransferBalances: () => fetchGuestTransferBalances,
|
|
472
175
|
fetchMerchantPublicKey: () => fetchMerchantPublicKey,
|
|
473
176
|
fetchProviders: () => fetchProviders,
|
|
@@ -609,197 +312,507 @@ async function fetchMerchantPublicKey(apiBaseUrl, merchantId) {
|
|
|
609
312
|
if (!res.ok) await throwApiError(res);
|
|
610
313
|
return await res.json();
|
|
611
314
|
}
|
|
612
|
-
async function fetchTransfer(apiBaseUrl, token, transferId, authorizationSessionToken) {
|
|
613
|
-
if (!token && !authorizationSessionToken) {
|
|
614
|
-
throw new Error("Missing auth credentials for transfer fetch.");
|
|
615
|
-
}
|
|
315
|
+
async function fetchTransfer(apiBaseUrl, token, transferId, authorizationSessionToken) {
|
|
316
|
+
if (!token && !authorizationSessionToken) {
|
|
317
|
+
throw new Error("Missing auth credentials for transfer fetch.");
|
|
318
|
+
}
|
|
319
|
+
const res = await fetch(`${apiBaseUrl}/v1/transfers/${transferId}`, {
|
|
320
|
+
headers: {
|
|
321
|
+
...token ? { Authorization: `Bearer ${token}` } : {},
|
|
322
|
+
...authorizationSessionToken ? { "x-authorization-session-token": authorizationSessionToken } : {}
|
|
323
|
+
}
|
|
324
|
+
});
|
|
325
|
+
if (!res.ok) await throwApiError(res);
|
|
326
|
+
return await res.json();
|
|
327
|
+
}
|
|
328
|
+
async function signTransfer(apiBaseUrl, token, transferId, signedUserOp, authorizationSessionToken) {
|
|
329
|
+
if (!token && !authorizationSessionToken) {
|
|
330
|
+
throw new Error("Missing auth credentials for transfer signing.");
|
|
331
|
+
}
|
|
332
|
+
const res = await fetch(`${apiBaseUrl}/v1/transfers/${transferId}`, {
|
|
333
|
+
method: "PATCH",
|
|
334
|
+
headers: {
|
|
335
|
+
"Content-Type": "application/json",
|
|
336
|
+
...token ? { Authorization: `Bearer ${token}` } : {},
|
|
337
|
+
...authorizationSessionToken ? { "x-authorization-session-token": authorizationSessionToken } : {}
|
|
338
|
+
},
|
|
339
|
+
body: JSON.stringify({ signedUserOp })
|
|
340
|
+
});
|
|
341
|
+
if (!res.ok) await throwApiError(res);
|
|
342
|
+
return await res.json();
|
|
343
|
+
}
|
|
344
|
+
async function fetchAuthorizationSession(apiBaseUrl, sessionId) {
|
|
345
|
+
const res = await fetch(
|
|
346
|
+
`${apiBaseUrl}/v1/authorization-sessions/${sessionId}`
|
|
347
|
+
);
|
|
348
|
+
if (!res.ok) await throwApiError(res);
|
|
349
|
+
return await res.json();
|
|
350
|
+
}
|
|
351
|
+
async function registerPasskey(apiBaseUrl, token, credentialId, publicKey) {
|
|
352
|
+
const res = await fetch(`${apiBaseUrl}/v1/users/config/passkey`, {
|
|
353
|
+
method: "POST",
|
|
354
|
+
headers: {
|
|
355
|
+
"Content-Type": "application/json",
|
|
356
|
+
Authorization: `Bearer ${token}`
|
|
357
|
+
},
|
|
358
|
+
body: JSON.stringify({ credentialId, publicKey })
|
|
359
|
+
});
|
|
360
|
+
if (!res.ok) await throwApiError(res);
|
|
361
|
+
}
|
|
362
|
+
async function reportPasskeyActivity(apiBaseUrl, token, credentialId) {
|
|
363
|
+
const res = await fetch(`${apiBaseUrl}/v1/users/config/passkey`, {
|
|
364
|
+
method: "PATCH",
|
|
365
|
+
headers: {
|
|
366
|
+
"Content-Type": "application/json",
|
|
367
|
+
Authorization: `Bearer ${token}`
|
|
368
|
+
},
|
|
369
|
+
body: JSON.stringify({ credentialId })
|
|
370
|
+
});
|
|
371
|
+
if (!res.ok) await throwApiError(res);
|
|
372
|
+
}
|
|
373
|
+
async function fetchUserConfig(apiBaseUrl, token) {
|
|
374
|
+
const res = await fetch(`${apiBaseUrl}/v1/users/config`, {
|
|
375
|
+
headers: { Authorization: `Bearer ${token}` }
|
|
376
|
+
});
|
|
377
|
+
if (!res.ok) await throwApiError(res);
|
|
378
|
+
return await res.json();
|
|
379
|
+
}
|
|
380
|
+
async function updateUserConfig(apiBaseUrl, token, config) {
|
|
381
|
+
const res = await fetch(`${apiBaseUrl}/v1/users`, {
|
|
382
|
+
method: "PATCH",
|
|
383
|
+
headers: {
|
|
384
|
+
"Content-Type": "application/json",
|
|
385
|
+
Authorization: `Bearer ${token}`
|
|
386
|
+
},
|
|
387
|
+
body: JSON.stringify({ config })
|
|
388
|
+
});
|
|
389
|
+
if (!res.ok) await throwApiError(res);
|
|
390
|
+
}
|
|
391
|
+
async function updateUserConfigBySession(apiBaseUrl, sessionId, config) {
|
|
392
|
+
const res = await fetch(
|
|
393
|
+
`${apiBaseUrl}/v1/authorization-sessions/${sessionId}/user-config`,
|
|
394
|
+
{
|
|
395
|
+
method: "PATCH",
|
|
396
|
+
headers: { "Content-Type": "application/json" },
|
|
397
|
+
body: JSON.stringify({ config })
|
|
398
|
+
}
|
|
399
|
+
);
|
|
400
|
+
if (!res.ok) await throwApiError(res);
|
|
401
|
+
}
|
|
402
|
+
async function createGuestTransfer(apiBaseUrl, params) {
|
|
403
|
+
const body = {
|
|
404
|
+
id: params.id ?? crypto.randomUUID(),
|
|
405
|
+
type: "guest",
|
|
406
|
+
merchantAuthorization: params.merchantAuthorization,
|
|
407
|
+
destinations: params.destinations,
|
|
408
|
+
amount: {
|
|
409
|
+
amount: params.amount,
|
|
410
|
+
currency: params.currency ?? "USD"
|
|
411
|
+
},
|
|
412
|
+
providerId: params.providerId
|
|
413
|
+
};
|
|
414
|
+
const res = await fetch(`${apiBaseUrl}/v1/transfers`, {
|
|
415
|
+
method: "POST",
|
|
416
|
+
headers: { "Content-Type": "application/json" },
|
|
417
|
+
body: JSON.stringify(body)
|
|
418
|
+
});
|
|
419
|
+
if (!res.ok) await throwApiError(res);
|
|
420
|
+
return await res.json();
|
|
421
|
+
}
|
|
422
|
+
async function getTransferByGuestToken(apiBaseUrl, guestToken) {
|
|
423
|
+
const params = new URLSearchParams({ guestToken });
|
|
424
|
+
const res = await fetch(`${apiBaseUrl}/v1/transfers?${params.toString()}`);
|
|
425
|
+
if (!res.ok) await throwApiError(res);
|
|
426
|
+
return await res.json();
|
|
427
|
+
}
|
|
428
|
+
async function setTransferSender(apiBaseUrl, transferId, guestSessionToken, senderAddress, sourceChainId, sourceToken) {
|
|
429
|
+
const res = await fetch(`${apiBaseUrl}/v1/transfers/${transferId}/sender`, {
|
|
430
|
+
method: "PUT",
|
|
431
|
+
headers: {
|
|
432
|
+
"Content-Type": "application/json",
|
|
433
|
+
"x-guest-session-token": guestSessionToken
|
|
434
|
+
},
|
|
435
|
+
body: JSON.stringify({ senderAddress, sourceChainId, sourceToken })
|
|
436
|
+
});
|
|
437
|
+
if (!res.ok) await throwApiError(res);
|
|
438
|
+
return await res.json();
|
|
439
|
+
}
|
|
440
|
+
async function signGuestTransfer(apiBaseUrl, transferId, guestSessionToken, originTxHash) {
|
|
616
441
|
const res = await fetch(`${apiBaseUrl}/v1/transfers/${transferId}`, {
|
|
442
|
+
method: "PATCH",
|
|
617
443
|
headers: {
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
}
|
|
444
|
+
"Content-Type": "application/json",
|
|
445
|
+
"x-guest-session-token": guestSessionToken
|
|
446
|
+
},
|
|
447
|
+
body: JSON.stringify({ originTxHash })
|
|
621
448
|
});
|
|
622
449
|
if (!res.ok) await throwApiError(res);
|
|
623
450
|
return await res.json();
|
|
624
451
|
}
|
|
625
|
-
async function
|
|
626
|
-
if (!token && !authorizationSessionToken) {
|
|
627
|
-
throw new Error("Missing auth credentials for transfer signing.");
|
|
628
|
-
}
|
|
452
|
+
async function getGuestTransfer(apiBaseUrl, transferId, guestSessionToken) {
|
|
629
453
|
const res = await fetch(`${apiBaseUrl}/v1/transfers/${transferId}`, {
|
|
630
|
-
method: "PATCH",
|
|
631
454
|
headers: {
|
|
632
|
-
"
|
|
633
|
-
|
|
634
|
-
...authorizationSessionToken ? { "x-authorization-session-token": authorizationSessionToken } : {}
|
|
635
|
-
},
|
|
636
|
-
body: JSON.stringify({ signedUserOp })
|
|
455
|
+
"x-guest-session-token": guestSessionToken
|
|
456
|
+
}
|
|
637
457
|
});
|
|
638
458
|
if (!res.ok) await throwApiError(res);
|
|
639
459
|
return await res.json();
|
|
640
460
|
}
|
|
641
|
-
async function
|
|
461
|
+
async function fetchGuestTransferBalances(apiBaseUrl, transferId, guestSessionToken, walletAddress) {
|
|
462
|
+
const params = new URLSearchParams({ walletAddress });
|
|
642
463
|
const res = await fetch(
|
|
643
|
-
`${apiBaseUrl}/v1/
|
|
464
|
+
`${apiBaseUrl}/v1/transfers/${transferId}/balances?${params.toString()}`,
|
|
465
|
+
{
|
|
466
|
+
headers: {
|
|
467
|
+
"x-guest-session-token": guestSessionToken
|
|
468
|
+
}
|
|
469
|
+
}
|
|
644
470
|
);
|
|
645
471
|
if (!res.ok) await throwApiError(res);
|
|
472
|
+
const data = await res.json();
|
|
473
|
+
return data.items;
|
|
474
|
+
}
|
|
475
|
+
async function fetchGuestAccount(apiBaseUrl, guestToken) {
|
|
476
|
+
const params = new URLSearchParams({ guestToken });
|
|
477
|
+
const res = await fetch(`${apiBaseUrl}/v1/accounts?${params.toString()}`);
|
|
478
|
+
if (res.status === 404) return null;
|
|
479
|
+
if (!res.ok) await throwApiError(res);
|
|
646
480
|
return await res.json();
|
|
647
481
|
}
|
|
648
|
-
async function
|
|
649
|
-
const res = await fetch(`${apiBaseUrl}/v1/
|
|
482
|
+
async function createGuestAccount(apiBaseUrl, guestSessionToken, providerId, name) {
|
|
483
|
+
const res = await fetch(`${apiBaseUrl}/v1/accounts`, {
|
|
650
484
|
method: "POST",
|
|
651
485
|
headers: {
|
|
652
486
|
"Content-Type": "application/json",
|
|
653
|
-
|
|
487
|
+
"x-guest-session-token": guestSessionToken
|
|
654
488
|
},
|
|
655
|
-
body: JSON.stringify({
|
|
489
|
+
body: JSON.stringify({ providerId, name })
|
|
656
490
|
});
|
|
657
491
|
if (!res.ok) await throwApiError(res);
|
|
492
|
+
return await res.json();
|
|
658
493
|
}
|
|
659
|
-
async function
|
|
660
|
-
const res = await fetch(`${apiBaseUrl}/v1/
|
|
661
|
-
method: "
|
|
494
|
+
async function setAccountOwner(apiBaseUrl, accessToken, accountId, guestSessionToken, body) {
|
|
495
|
+
const res = await fetch(`${apiBaseUrl}/v1/accounts/${accountId}/owner`, {
|
|
496
|
+
method: "PUT",
|
|
662
497
|
headers: {
|
|
663
498
|
"Content-Type": "application/json",
|
|
664
|
-
Authorization: `Bearer ${
|
|
499
|
+
"Authorization": `Bearer ${accessToken}`,
|
|
500
|
+
"x-guest-session-token": guestSessionToken
|
|
665
501
|
},
|
|
666
|
-
body: JSON.stringify(
|
|
502
|
+
body: JSON.stringify(body)
|
|
667
503
|
});
|
|
668
504
|
if (!res.ok) await throwApiError(res);
|
|
505
|
+
return await res.json();
|
|
669
506
|
}
|
|
670
|
-
async function
|
|
671
|
-
const res = await fetch(
|
|
672
|
-
|
|
507
|
+
async function reportActionCompletion(apiBaseUrl, actionId, result) {
|
|
508
|
+
const res = await fetch(
|
|
509
|
+
`${apiBaseUrl}/v1/authorization-actions/${actionId}`,
|
|
510
|
+
{
|
|
511
|
+
method: "PATCH",
|
|
512
|
+
headers: { "Content-Type": "application/json" },
|
|
513
|
+
body: JSON.stringify({ status: "COMPLETED", result })
|
|
514
|
+
}
|
|
515
|
+
);
|
|
516
|
+
if (!res.ok) await throwApiError(res);
|
|
517
|
+
return await res.json();
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
// node_modules/@wagmi/core/dist/esm/utils/getAction.js
|
|
521
|
+
function getAction(client, actionFn, name) {
|
|
522
|
+
const action_implicit = client[actionFn.name];
|
|
523
|
+
if (typeof action_implicit === "function")
|
|
524
|
+
return action_implicit;
|
|
525
|
+
const action_explicit = client[name];
|
|
526
|
+
if (typeof action_explicit === "function")
|
|
527
|
+
return action_explicit;
|
|
528
|
+
return (params) => actionFn(client, params);
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
// node_modules/@wagmi/core/dist/esm/version.js
|
|
532
|
+
var version = "2.22.1";
|
|
533
|
+
|
|
534
|
+
// node_modules/@wagmi/core/dist/esm/utils/getVersion.js
|
|
535
|
+
var getVersion = () => `@wagmi/core@${version}`;
|
|
536
|
+
|
|
537
|
+
// node_modules/@wagmi/core/dist/esm/errors/base.js
|
|
538
|
+
var __classPrivateFieldGet = function(receiver, state, kind, f) {
|
|
539
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
540
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
541
|
+
};
|
|
542
|
+
var _BaseError_instances;
|
|
543
|
+
var _BaseError_walk;
|
|
544
|
+
var BaseError = class _BaseError extends Error {
|
|
545
|
+
get docsBaseUrl() {
|
|
546
|
+
return "https://wagmi.sh/core";
|
|
547
|
+
}
|
|
548
|
+
get version() {
|
|
549
|
+
return getVersion();
|
|
550
|
+
}
|
|
551
|
+
constructor(shortMessage, options = {}) {
|
|
552
|
+
super();
|
|
553
|
+
_BaseError_instances.add(this);
|
|
554
|
+
Object.defineProperty(this, "details", {
|
|
555
|
+
enumerable: true,
|
|
556
|
+
configurable: true,
|
|
557
|
+
writable: true,
|
|
558
|
+
value: void 0
|
|
559
|
+
});
|
|
560
|
+
Object.defineProperty(this, "docsPath", {
|
|
561
|
+
enumerable: true,
|
|
562
|
+
configurable: true,
|
|
563
|
+
writable: true,
|
|
564
|
+
value: void 0
|
|
565
|
+
});
|
|
566
|
+
Object.defineProperty(this, "metaMessages", {
|
|
567
|
+
enumerable: true,
|
|
568
|
+
configurable: true,
|
|
569
|
+
writable: true,
|
|
570
|
+
value: void 0
|
|
571
|
+
});
|
|
572
|
+
Object.defineProperty(this, "shortMessage", {
|
|
573
|
+
enumerable: true,
|
|
574
|
+
configurable: true,
|
|
575
|
+
writable: true,
|
|
576
|
+
value: void 0
|
|
577
|
+
});
|
|
578
|
+
Object.defineProperty(this, "name", {
|
|
579
|
+
enumerable: true,
|
|
580
|
+
configurable: true,
|
|
581
|
+
writable: true,
|
|
582
|
+
value: "WagmiCoreError"
|
|
583
|
+
});
|
|
584
|
+
const details = options.cause instanceof _BaseError ? options.cause.details : options.cause?.message ? options.cause.message : options.details;
|
|
585
|
+
const docsPath = options.cause instanceof _BaseError ? options.cause.docsPath || options.docsPath : options.docsPath;
|
|
586
|
+
this.message = [
|
|
587
|
+
shortMessage || "An error occurred.",
|
|
588
|
+
"",
|
|
589
|
+
...options.metaMessages ? [...options.metaMessages, ""] : [],
|
|
590
|
+
...docsPath ? [
|
|
591
|
+
`Docs: ${this.docsBaseUrl}${docsPath}.html${options.docsSlug ? `#${options.docsSlug}` : ""}`
|
|
592
|
+
] : [],
|
|
593
|
+
...details ? [`Details: ${details}`] : [],
|
|
594
|
+
`Version: ${this.version}`
|
|
595
|
+
].join("\n");
|
|
596
|
+
if (options.cause)
|
|
597
|
+
this.cause = options.cause;
|
|
598
|
+
this.details = details;
|
|
599
|
+
this.docsPath = docsPath;
|
|
600
|
+
this.metaMessages = options.metaMessages;
|
|
601
|
+
this.shortMessage = shortMessage;
|
|
602
|
+
}
|
|
603
|
+
walk(fn) {
|
|
604
|
+
return __classPrivateFieldGet(this, _BaseError_instances, "m", _BaseError_walk).call(this, this, fn);
|
|
605
|
+
}
|
|
606
|
+
};
|
|
607
|
+
_BaseError_instances = /* @__PURE__ */ new WeakSet(), _BaseError_walk = function _BaseError_walk2(err, fn) {
|
|
608
|
+
if (fn?.(err))
|
|
609
|
+
return err;
|
|
610
|
+
if (err.cause)
|
|
611
|
+
return __classPrivateFieldGet(this, _BaseError_instances, "m", _BaseError_walk2).call(this, err.cause, fn);
|
|
612
|
+
return err;
|
|
613
|
+
};
|
|
614
|
+
|
|
615
|
+
// node_modules/@wagmi/core/dist/esm/errors/config.js
|
|
616
|
+
var ConnectorNotConnectedError = class extends BaseError {
|
|
617
|
+
constructor() {
|
|
618
|
+
super("Connector not connected.");
|
|
619
|
+
Object.defineProperty(this, "name", {
|
|
620
|
+
enumerable: true,
|
|
621
|
+
configurable: true,
|
|
622
|
+
writable: true,
|
|
623
|
+
value: "ConnectorNotConnectedError"
|
|
624
|
+
});
|
|
625
|
+
}
|
|
626
|
+
};
|
|
627
|
+
var ConnectorAccountNotFoundError = class extends BaseError {
|
|
628
|
+
constructor({ address, connector }) {
|
|
629
|
+
super(`Account "${address}" not found for connector "${connector.name}".`);
|
|
630
|
+
Object.defineProperty(this, "name", {
|
|
631
|
+
enumerable: true,
|
|
632
|
+
configurable: true,
|
|
633
|
+
writable: true,
|
|
634
|
+
value: "ConnectorAccountNotFoundError"
|
|
635
|
+
});
|
|
636
|
+
}
|
|
637
|
+
};
|
|
638
|
+
var ConnectorChainMismatchError = class extends BaseError {
|
|
639
|
+
constructor({ connectionChainId, connectorChainId }) {
|
|
640
|
+
super(`The current chain of the connector (id: ${connectorChainId}) does not match the connection's chain (id: ${connectionChainId}).`, {
|
|
641
|
+
metaMessages: [
|
|
642
|
+
`Current Chain ID: ${connectorChainId}`,
|
|
643
|
+
`Expected Chain ID: ${connectionChainId}`
|
|
644
|
+
]
|
|
645
|
+
});
|
|
646
|
+
Object.defineProperty(this, "name", {
|
|
647
|
+
enumerable: true,
|
|
648
|
+
configurable: true,
|
|
649
|
+
writable: true,
|
|
650
|
+
value: "ConnectorChainMismatchError"
|
|
651
|
+
});
|
|
652
|
+
}
|
|
653
|
+
};
|
|
654
|
+
var ConnectorUnavailableReconnectingError = class extends BaseError {
|
|
655
|
+
constructor({ connector }) {
|
|
656
|
+
super(`Connector "${connector.name}" unavailable while reconnecting.`, {
|
|
657
|
+
details: [
|
|
658
|
+
"During the reconnection step, the only connector methods guaranteed to be available are: `id`, `name`, `type`, `uid`.",
|
|
659
|
+
"All other methods are not guaranteed to be available until reconnection completes and connectors are fully restored.",
|
|
660
|
+
"This error commonly occurs for connectors that asynchronously inject after reconnection has already started."
|
|
661
|
+
].join(" ")
|
|
662
|
+
});
|
|
663
|
+
Object.defineProperty(this, "name", {
|
|
664
|
+
enumerable: true,
|
|
665
|
+
configurable: true,
|
|
666
|
+
writable: true,
|
|
667
|
+
value: "ConnectorUnavailableReconnectingError"
|
|
668
|
+
});
|
|
669
|
+
}
|
|
670
|
+
};
|
|
671
|
+
async function getConnectorClient(config, parameters = {}) {
|
|
672
|
+
const { assertChainId = true } = parameters;
|
|
673
|
+
let connection;
|
|
674
|
+
if (parameters.connector) {
|
|
675
|
+
const { connector: connector2 } = parameters;
|
|
676
|
+
if (config.state.status === "reconnecting" && !connector2.getAccounts && !connector2.getChainId)
|
|
677
|
+
throw new ConnectorUnavailableReconnectingError({ connector: connector2 });
|
|
678
|
+
const [accounts, chainId2] = await Promise.all([
|
|
679
|
+
connector2.getAccounts().catch((e) => {
|
|
680
|
+
if (parameters.account === null)
|
|
681
|
+
return [];
|
|
682
|
+
throw e;
|
|
683
|
+
}),
|
|
684
|
+
connector2.getChainId()
|
|
685
|
+
]);
|
|
686
|
+
connection = {
|
|
687
|
+
accounts,
|
|
688
|
+
chainId: chainId2,
|
|
689
|
+
connector: connector2
|
|
690
|
+
};
|
|
691
|
+
} else
|
|
692
|
+
connection = config.state.connections.get(config.state.current);
|
|
693
|
+
if (!connection)
|
|
694
|
+
throw new ConnectorNotConnectedError();
|
|
695
|
+
const chainId = parameters.chainId ?? connection.chainId;
|
|
696
|
+
const connectorChainId = await connection.connector.getChainId();
|
|
697
|
+
if (assertChainId && connectorChainId !== chainId)
|
|
698
|
+
throw new ConnectorChainMismatchError({
|
|
699
|
+
connectionChainId: chainId,
|
|
700
|
+
connectorChainId
|
|
701
|
+
});
|
|
702
|
+
const connector = connection.connector;
|
|
703
|
+
if (connector.getClient)
|
|
704
|
+
return connector.getClient({ chainId });
|
|
705
|
+
const account = utils.parseAccount(parameters.account ?? connection.accounts[0]);
|
|
706
|
+
if (account)
|
|
707
|
+
account.address = utils.getAddress(account.address);
|
|
708
|
+
if (parameters.account && !connection.accounts.some((x) => x.toLowerCase() === account.address.toLowerCase()))
|
|
709
|
+
throw new ConnectorAccountNotFoundError({
|
|
710
|
+
address: account.address,
|
|
711
|
+
connector
|
|
712
|
+
});
|
|
713
|
+
const chain = config.chains.find((chain2) => chain2.id === chainId);
|
|
714
|
+
const provider = await connection.connector.getProvider({ chainId });
|
|
715
|
+
return viem.createClient({
|
|
716
|
+
account,
|
|
717
|
+
chain,
|
|
718
|
+
name: "Connector Client",
|
|
719
|
+
transport: (opts) => viem.custom(provider)({ ...opts, retryCount: 0 })
|
|
673
720
|
});
|
|
674
|
-
if (!res.ok) await throwApiError(res);
|
|
675
|
-
return await res.json();
|
|
676
721
|
}
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
722
|
+
|
|
723
|
+
// node_modules/@wagmi/core/dist/esm/actions/getAccount.js
|
|
724
|
+
function getAccount(config) {
|
|
725
|
+
const uid = config.state.current;
|
|
726
|
+
const connection = config.state.connections.get(uid);
|
|
727
|
+
const addresses = connection?.accounts;
|
|
728
|
+
const address = addresses?.[0];
|
|
729
|
+
const chain = config.chains.find((chain2) => chain2.id === connection?.chainId);
|
|
730
|
+
const status = config.state.status;
|
|
731
|
+
switch (status) {
|
|
732
|
+
case "connected":
|
|
733
|
+
return {
|
|
734
|
+
address,
|
|
735
|
+
addresses,
|
|
736
|
+
chain,
|
|
737
|
+
chainId: connection?.chainId,
|
|
738
|
+
connector: connection?.connector,
|
|
739
|
+
isConnected: true,
|
|
740
|
+
isConnecting: false,
|
|
741
|
+
isDisconnected: false,
|
|
742
|
+
isReconnecting: false,
|
|
743
|
+
status
|
|
744
|
+
};
|
|
745
|
+
case "reconnecting":
|
|
746
|
+
return {
|
|
747
|
+
address,
|
|
748
|
+
addresses,
|
|
749
|
+
chain,
|
|
750
|
+
chainId: connection?.chainId,
|
|
751
|
+
connector: connection?.connector,
|
|
752
|
+
isConnected: !!address,
|
|
753
|
+
isConnecting: false,
|
|
754
|
+
isDisconnected: false,
|
|
755
|
+
isReconnecting: true,
|
|
756
|
+
status
|
|
757
|
+
};
|
|
758
|
+
case "connecting":
|
|
759
|
+
return {
|
|
760
|
+
address,
|
|
761
|
+
addresses,
|
|
762
|
+
chain,
|
|
763
|
+
chainId: connection?.chainId,
|
|
764
|
+
connector: connection?.connector,
|
|
765
|
+
isConnected: false,
|
|
766
|
+
isConnecting: true,
|
|
767
|
+
isDisconnected: false,
|
|
768
|
+
isReconnecting: false,
|
|
769
|
+
status
|
|
770
|
+
};
|
|
771
|
+
case "disconnected":
|
|
772
|
+
return {
|
|
773
|
+
address: void 0,
|
|
774
|
+
addresses: void 0,
|
|
775
|
+
chain: void 0,
|
|
776
|
+
chainId: void 0,
|
|
777
|
+
connector: void 0,
|
|
778
|
+
isConnected: false,
|
|
779
|
+
isConnecting: false,
|
|
780
|
+
isDisconnected: true,
|
|
781
|
+
isReconnecting: false,
|
|
782
|
+
status
|
|
783
|
+
};
|
|
784
|
+
}
|
|
687
785
|
}
|
|
688
|
-
async function
|
|
689
|
-
const
|
|
690
|
-
|
|
691
|
-
{
|
|
692
|
-
method: "PATCH",
|
|
693
|
-
headers: { "Content-Type": "application/json" },
|
|
694
|
-
body: JSON.stringify({ config })
|
|
695
|
-
}
|
|
696
|
-
);
|
|
697
|
-
if (!res.ok) await throwApiError(res);
|
|
786
|
+
async function getWalletClient(config, parameters = {}) {
|
|
787
|
+
const client = await getConnectorClient(config, parameters);
|
|
788
|
+
return client.extend(viem.walletActions);
|
|
698
789
|
}
|
|
699
|
-
async function
|
|
700
|
-
const
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
}
|
|
709
|
-
|
|
790
|
+
async function waitForTransactionReceipt(config, parameters) {
|
|
791
|
+
const { chainId, timeout = 0, ...rest } = parameters;
|
|
792
|
+
const client = config.getClient({ chainId });
|
|
793
|
+
const action = getAction(client, actions.waitForTransactionReceipt, "waitForTransactionReceipt");
|
|
794
|
+
const receipt = await action({ ...rest, timeout });
|
|
795
|
+
if (receipt.status === "reverted") {
|
|
796
|
+
const action_getTransaction = getAction(client, actions.getTransaction, "getTransaction");
|
|
797
|
+
const { from: account, ...txn } = await action_getTransaction({
|
|
798
|
+
hash: receipt.transactionHash
|
|
799
|
+
});
|
|
800
|
+
const action_call = getAction(client, actions.call, "call");
|
|
801
|
+
const code = await action_call({
|
|
802
|
+
...txn,
|
|
803
|
+
account,
|
|
804
|
+
data: txn.input,
|
|
805
|
+
gasPrice: txn.type !== "eip1559" ? txn.gasPrice : void 0,
|
|
806
|
+
maxFeePerGas: txn.type === "eip1559" ? txn.maxFeePerGas : void 0,
|
|
807
|
+
maxPriorityFeePerGas: txn.type === "eip1559" ? txn.maxPriorityFeePerGas : void 0
|
|
808
|
+
});
|
|
809
|
+
const reason = code?.data ? viem.hexToString(`0x${code.data.substring(138)}`) : "unknown reason";
|
|
810
|
+
throw new Error(reason);
|
|
811
|
+
}
|
|
812
|
+
return {
|
|
813
|
+
...receipt,
|
|
814
|
+
chainId: client.chain.id
|
|
710
815
|
};
|
|
711
|
-
const res = await fetch(`${apiBaseUrl}/v1/transfers`, {
|
|
712
|
-
method: "POST",
|
|
713
|
-
headers: { "Content-Type": "application/json" },
|
|
714
|
-
body: JSON.stringify(body)
|
|
715
|
-
});
|
|
716
|
-
if (!res.ok) await throwApiError(res);
|
|
717
|
-
return await res.json();
|
|
718
|
-
}
|
|
719
|
-
async function getTransferByGuestToken(apiBaseUrl, guestToken) {
|
|
720
|
-
const params = new URLSearchParams({ guestToken });
|
|
721
|
-
const res = await fetch(`${apiBaseUrl}/v1/transfers?${params.toString()}`);
|
|
722
|
-
if (!res.ok) await throwApiError(res);
|
|
723
|
-
return await res.json();
|
|
724
|
-
}
|
|
725
|
-
async function setTransferSender(apiBaseUrl, transferId, guestSessionToken, senderAddress, sourceChainId, sourceToken) {
|
|
726
|
-
const res = await fetch(`${apiBaseUrl}/v1/transfers/${transferId}/sender`, {
|
|
727
|
-
method: "PUT",
|
|
728
|
-
headers: {
|
|
729
|
-
"Content-Type": "application/json",
|
|
730
|
-
"x-guest-session-token": guestSessionToken
|
|
731
|
-
},
|
|
732
|
-
body: JSON.stringify({ senderAddress, sourceChainId, sourceToken })
|
|
733
|
-
});
|
|
734
|
-
if (!res.ok) await throwApiError(res);
|
|
735
|
-
return await res.json();
|
|
736
|
-
}
|
|
737
|
-
async function signGuestTransfer(apiBaseUrl, transferId, guestSessionToken, originTxHash) {
|
|
738
|
-
const res = await fetch(`${apiBaseUrl}/v1/transfers/${transferId}`, {
|
|
739
|
-
method: "PATCH",
|
|
740
|
-
headers: {
|
|
741
|
-
"Content-Type": "application/json",
|
|
742
|
-
"x-guest-session-token": guestSessionToken
|
|
743
|
-
},
|
|
744
|
-
body: JSON.stringify({ originTxHash })
|
|
745
|
-
});
|
|
746
|
-
if (!res.ok) await throwApiError(res);
|
|
747
|
-
return await res.json();
|
|
748
|
-
}
|
|
749
|
-
async function getGuestTransfer(apiBaseUrl, transferId, guestSessionToken) {
|
|
750
|
-
const res = await fetch(`${apiBaseUrl}/v1/transfers/${transferId}`, {
|
|
751
|
-
headers: {
|
|
752
|
-
"x-guest-session-token": guestSessionToken
|
|
753
|
-
}
|
|
754
|
-
});
|
|
755
|
-
if (!res.ok) await throwApiError(res);
|
|
756
|
-
return await res.json();
|
|
757
|
-
}
|
|
758
|
-
async function fetchGuestTransferBalances(apiBaseUrl, transferId, guestSessionToken, walletAddress) {
|
|
759
|
-
const params = new URLSearchParams({ walletAddress });
|
|
760
|
-
const res = await fetch(
|
|
761
|
-
`${apiBaseUrl}/v1/transfers/${transferId}/balances?${params.toString()}`,
|
|
762
|
-
{
|
|
763
|
-
headers: {
|
|
764
|
-
"x-guest-session-token": guestSessionToken
|
|
765
|
-
}
|
|
766
|
-
}
|
|
767
|
-
);
|
|
768
|
-
if (!res.ok) await throwApiError(res);
|
|
769
|
-
const data = await res.json();
|
|
770
|
-
return data.items;
|
|
771
|
-
}
|
|
772
|
-
async function fetchGuestPreauthAccount(apiBaseUrl, guestToken) {
|
|
773
|
-
const params = new URLSearchParams({ guestToken });
|
|
774
|
-
const res = await fetch(`${apiBaseUrl}/v1/guest-preauth?${params.toString()}`);
|
|
775
|
-
if (res.status === 404) return null;
|
|
776
|
-
if (!res.ok) await throwApiError(res);
|
|
777
|
-
return await res.json();
|
|
778
|
-
}
|
|
779
|
-
async function setAccountOwner(apiBaseUrl, accessToken, accountId, guestSessionToken, body) {
|
|
780
|
-
const res = await fetch(`${apiBaseUrl}/v1/accounts/${accountId}/owner`, {
|
|
781
|
-
method: "PUT",
|
|
782
|
-
headers: {
|
|
783
|
-
"Content-Type": "application/json",
|
|
784
|
-
"Authorization": `Bearer ${accessToken}`,
|
|
785
|
-
"x-guest-session-token": guestSessionToken
|
|
786
|
-
},
|
|
787
|
-
body: JSON.stringify(body)
|
|
788
|
-
});
|
|
789
|
-
if (!res.ok) await throwApiError(res);
|
|
790
|
-
return await res.json();
|
|
791
|
-
}
|
|
792
|
-
async function reportActionCompletion(apiBaseUrl, actionId, result) {
|
|
793
|
-
const res = await fetch(
|
|
794
|
-
`${apiBaseUrl}/v1/authorization-actions/${actionId}`,
|
|
795
|
-
{
|
|
796
|
-
method: "PATCH",
|
|
797
|
-
headers: { "Content-Type": "application/json" },
|
|
798
|
-
body: JSON.stringify({ status: "COMPLETED", result })
|
|
799
|
-
}
|
|
800
|
-
);
|
|
801
|
-
if (!res.ok) await throwApiError(res);
|
|
802
|
-
return await res.json();
|
|
803
816
|
}
|
|
804
817
|
|
|
805
818
|
// src/passkeyRpId.ts
|
|
@@ -2213,7 +2226,8 @@ function paymentReducer(state, action) {
|
|
|
2213
2226
|
...state,
|
|
2214
2227
|
guestPreauthAccountId: null,
|
|
2215
2228
|
activePublicKey: null,
|
|
2216
|
-
error: null
|
|
2229
|
+
error: null,
|
|
2230
|
+
userIntent: "configure-one-tap"
|
|
2217
2231
|
};
|
|
2218
2232
|
// ── User intent & error ──────────────────────────────────────
|
|
2219
2233
|
case "SET_USER_INTENT":
|
|
@@ -8245,9 +8259,9 @@ function usePaymentEffects(deps) {
|
|
|
8245
8259
|
if (state.guestPreauthAccountId) return;
|
|
8246
8260
|
if (!state.transfer || state.transfer.status !== "COMPLETED") return;
|
|
8247
8261
|
let cancelled = false;
|
|
8248
|
-
const
|
|
8262
|
+
const checkGuestAccount = async () => {
|
|
8249
8263
|
try {
|
|
8250
|
-
const result = await
|
|
8264
|
+
const result = await fetchGuestAccount(apiBaseUrl, state.guestSessionToken);
|
|
8251
8265
|
if (cancelled) return;
|
|
8252
8266
|
if (result && !result.hasPasskey) {
|
|
8253
8267
|
dispatch({ type: "GUEST_PREAUTH_DETECTED", accountId: result.accountId });
|
|
@@ -8255,7 +8269,7 @@ function usePaymentEffects(deps) {
|
|
|
8255
8269
|
} catch {
|
|
8256
8270
|
}
|
|
8257
8271
|
};
|
|
8258
|
-
|
|
8272
|
+
checkGuestAccount();
|
|
8259
8273
|
return () => {
|
|
8260
8274
|
cancelled = true;
|
|
8261
8275
|
};
|
|
@@ -8551,7 +8565,29 @@ function BlinkPaymentInner({
|
|
|
8551
8565
|
onAuthorizeToken: provider.handleAuthorizeToken,
|
|
8552
8566
|
onSelectGuestToken: guestTransfer.handleSelectGuestToken,
|
|
8553
8567
|
onLogin: () => dispatch({ type: "REQUEST_LOGIN" }),
|
|
8554
|
-
onPreauthorize: () =>
|
|
8568
|
+
onPreauthorize: async () => {
|
|
8569
|
+
if (state.guestPreauthAccountId) {
|
|
8570
|
+
dispatch({ type: "REQUEST_LOGIN" });
|
|
8571
|
+
return;
|
|
8572
|
+
}
|
|
8573
|
+
if (!state.guestSessionToken || !state.selectedProviderId) {
|
|
8574
|
+
dispatch({ type: "REQUEST_LOGIN" });
|
|
8575
|
+
return;
|
|
8576
|
+
}
|
|
8577
|
+
try {
|
|
8578
|
+
const providerName = state.providers.find((p) => p.id === state.selectedProviderId)?.name ?? "Wallet";
|
|
8579
|
+
const created = await createGuestAccount(
|
|
8580
|
+
apiBaseUrl,
|
|
8581
|
+
state.guestSessionToken,
|
|
8582
|
+
state.selectedProviderId,
|
|
8583
|
+
providerName
|
|
8584
|
+
);
|
|
8585
|
+
dispatch({ type: "GUEST_PREAUTH_DETECTED", accountId: created.accountId });
|
|
8586
|
+
dispatch({ type: "REQUEST_LOGIN" });
|
|
8587
|
+
} catch {
|
|
8588
|
+
dispatch({ type: "REQUEST_LOGIN" });
|
|
8589
|
+
}
|
|
8590
|
+
}
|
|
8555
8591
|
}), [
|
|
8556
8592
|
auth,
|
|
8557
8593
|
passkey,
|
|
@@ -8562,7 +8598,12 @@ function BlinkPaymentInner({
|
|
|
8562
8598
|
oneTapSetup,
|
|
8563
8599
|
guestTransfer,
|
|
8564
8600
|
handleLogout,
|
|
8565
|
-
handleNewPayment
|
|
8601
|
+
handleNewPayment,
|
|
8602
|
+
state.guestPreauthAccountId,
|
|
8603
|
+
state.guestSessionToken,
|
|
8604
|
+
state.selectedProviderId,
|
|
8605
|
+
state.providers,
|
|
8606
|
+
apiBaseUrl
|
|
8566
8607
|
]);
|
|
8567
8608
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
8568
8609
|
StepRenderer,
|