@swype-org/react-sdk 0.1.229 → 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 CHANGED
@@ -158,304 +158,6 @@ 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, {
@@ -639,180 +341,478 @@ async function signTransfer(apiBaseUrl, token, transferId, signedUserOp, authori
639
341
  if (!res.ok) await throwApiError(res);
640
342
  return await res.json();
641
343
  }
642
- async function fetchAuthorizationSession(apiBaseUrl, sessionId) {
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) {
441
+ const res = await fetch(`${apiBaseUrl}/v1/transfers/${transferId}`, {
442
+ method: "PATCH",
443
+ headers: {
444
+ "Content-Type": "application/json",
445
+ "x-guest-session-token": guestSessionToken
446
+ },
447
+ body: JSON.stringify({ originTxHash })
448
+ });
449
+ if (!res.ok) await throwApiError(res);
450
+ return await res.json();
451
+ }
452
+ async function getGuestTransfer(apiBaseUrl, transferId, guestSessionToken) {
453
+ const res = await fetch(`${apiBaseUrl}/v1/transfers/${transferId}`, {
454
+ headers: {
455
+ "x-guest-session-token": guestSessionToken
456
+ }
457
+ });
458
+ if (!res.ok) await throwApiError(res);
459
+ return await res.json();
460
+ }
461
+ async function fetchGuestTransferBalances(apiBaseUrl, transferId, guestSessionToken, walletAddress) {
462
+ const params = new URLSearchParams({ walletAddress });
643
463
  const res = await fetch(
644
- `${apiBaseUrl}/v1/authorization-sessions/${sessionId}`
464
+ `${apiBaseUrl}/v1/transfers/${transferId}/balances?${params.toString()}`,
465
+ {
466
+ headers: {
467
+ "x-guest-session-token": guestSessionToken
468
+ }
469
+ }
645
470
  );
646
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);
647
480
  return await res.json();
648
481
  }
649
- async function registerPasskey(apiBaseUrl, token, credentialId, publicKey) {
650
- const res = await fetch(`${apiBaseUrl}/v1/users/config/passkey`, {
482
+ async function createGuestAccount(apiBaseUrl, guestSessionToken, providerId, name) {
483
+ const res = await fetch(`${apiBaseUrl}/v1/accounts`, {
651
484
  method: "POST",
652
485
  headers: {
653
486
  "Content-Type": "application/json",
654
- Authorization: `Bearer ${token}`
487
+ "x-guest-session-token": guestSessionToken
655
488
  },
656
- body: JSON.stringify({ credentialId, publicKey })
489
+ body: JSON.stringify({ providerId, name })
657
490
  });
658
491
  if (!res.ok) await throwApiError(res);
492
+ return await res.json();
659
493
  }
660
- async function reportPasskeyActivity(apiBaseUrl, token, credentialId) {
661
- const res = await fetch(`${apiBaseUrl}/v1/users/config/passkey`, {
662
- method: "PATCH",
494
+ async function setAccountOwner(apiBaseUrl, accessToken, accountId, guestSessionToken, body) {
495
+ const res = await fetch(`${apiBaseUrl}/v1/accounts/${accountId}/owner`, {
496
+ method: "PUT",
663
497
  headers: {
664
498
  "Content-Type": "application/json",
665
- Authorization: `Bearer ${token}`
499
+ "Authorization": `Bearer ${accessToken}`,
500
+ "x-guest-session-token": guestSessionToken
666
501
  },
667
- body: JSON.stringify({ credentialId })
502
+ body: JSON.stringify(body)
668
503
  });
669
504
  if (!res.ok) await throwApiError(res);
505
+ return await res.json();
670
506
  }
671
- async function fetchUserConfig(apiBaseUrl, token) {
672
- const res = await fetch(`${apiBaseUrl}/v1/users/config`, {
673
- headers: { Authorization: `Bearer ${token}` }
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 })
674
720
  });
675
- if (!res.ok) await throwApiError(res);
676
- return await res.json();
677
721
  }
678
- async function updateUserConfig(apiBaseUrl, token, config) {
679
- const res = await fetch(`${apiBaseUrl}/v1/users`, {
680
- method: "PATCH",
681
- headers: {
682
- "Content-Type": "application/json",
683
- Authorization: `Bearer ${token}`
684
- },
685
- body: JSON.stringify({ config })
686
- });
687
- if (!res.ok) await throwApiError(res);
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
+ }
688
785
  }
689
- async function updateUserConfigBySession(apiBaseUrl, sessionId, config) {
690
- const res = await fetch(
691
- `${apiBaseUrl}/v1/authorization-sessions/${sessionId}/user-config`,
692
- {
693
- method: "PATCH",
694
- headers: { "Content-Type": "application/json" },
695
- body: JSON.stringify({ config })
696
- }
697
- );
698
- 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);
699
789
  }
700
- async function createGuestTransfer(apiBaseUrl, params) {
701
- const body = {
702
- id: params.id ?? crypto.randomUUID(),
703
- type: "guest",
704
- merchantAuthorization: params.merchantAuthorization,
705
- destinations: params.destinations,
706
- amount: {
707
- amount: params.amount,
708
- currency: params.currency ?? "USD"
709
- },
710
- providerId: params.providerId
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
711
815
  };
712
- const res = await fetch(`${apiBaseUrl}/v1/transfers`, {
713
- method: "POST",
714
- headers: { "Content-Type": "application/json" },
715
- body: JSON.stringify(body)
716
- });
717
- if (!res.ok) await throwApiError(res);
718
- return await res.json();
719
- }
720
- async function getTransferByGuestToken(apiBaseUrl, guestToken) {
721
- const params = new URLSearchParams({ guestToken });
722
- const res = await fetch(`${apiBaseUrl}/v1/transfers?${params.toString()}`);
723
- if (!res.ok) await throwApiError(res);
724
- return await res.json();
725
- }
726
- async function setTransferSender(apiBaseUrl, transferId, guestSessionToken, senderAddress, sourceChainId, sourceToken) {
727
- const res = await fetch(`${apiBaseUrl}/v1/transfers/${transferId}/sender`, {
728
- method: "PUT",
729
- headers: {
730
- "Content-Type": "application/json",
731
- "x-guest-session-token": guestSessionToken
732
- },
733
- body: JSON.stringify({ senderAddress, sourceChainId, sourceToken })
734
- });
735
- if (!res.ok) await throwApiError(res);
736
- return await res.json();
737
- }
738
- async function signGuestTransfer(apiBaseUrl, transferId, guestSessionToken, originTxHash) {
739
- const res = await fetch(`${apiBaseUrl}/v1/transfers/${transferId}`, {
740
- method: "PATCH",
741
- headers: {
742
- "Content-Type": "application/json",
743
- "x-guest-session-token": guestSessionToken
744
- },
745
- body: JSON.stringify({ originTxHash })
746
- });
747
- if (!res.ok) await throwApiError(res);
748
- return await res.json();
749
- }
750
- async function getGuestTransfer(apiBaseUrl, transferId, guestSessionToken) {
751
- const res = await fetch(`${apiBaseUrl}/v1/transfers/${transferId}`, {
752
- headers: {
753
- "x-guest-session-token": guestSessionToken
754
- }
755
- });
756
- if (!res.ok) await throwApiError(res);
757
- return await res.json();
758
- }
759
- async function fetchGuestTransferBalances(apiBaseUrl, transferId, guestSessionToken, walletAddress) {
760
- const params = new URLSearchParams({ walletAddress });
761
- const res = await fetch(
762
- `${apiBaseUrl}/v1/transfers/${transferId}/balances?${params.toString()}`,
763
- {
764
- headers: {
765
- "x-guest-session-token": guestSessionToken
766
- }
767
- }
768
- );
769
- if (!res.ok) await throwApiError(res);
770
- const data = await res.json();
771
- return data.items;
772
- }
773
- async function fetchGuestAccount(apiBaseUrl, guestToken) {
774
- const params = new URLSearchParams({ guestToken });
775
- const res = await fetch(`${apiBaseUrl}/v1/accounts?${params.toString()}`);
776
- if (res.status === 404) return null;
777
- if (!res.ok) await throwApiError(res);
778
- return await res.json();
779
- }
780
- async function createGuestAccount(apiBaseUrl, guestSessionToken, providerId, name) {
781
- const res = await fetch(`${apiBaseUrl}/v1/accounts`, {
782
- method: "POST",
783
- headers: {
784
- "Content-Type": "application/json",
785
- "x-guest-session-token": guestSessionToken
786
- },
787
- body: JSON.stringify({ providerId, name })
788
- });
789
- if (!res.ok) await throwApiError(res);
790
- return await res.json();
791
- }
792
- async function setAccountOwner(apiBaseUrl, accessToken, accountId, guestSessionToken, body) {
793
- const res = await fetch(`${apiBaseUrl}/v1/accounts/${accountId}/owner`, {
794
- method: "PUT",
795
- headers: {
796
- "Content-Type": "application/json",
797
- "Authorization": `Bearer ${accessToken}`,
798
- "x-guest-session-token": guestSessionToken
799
- },
800
- body: JSON.stringify(body)
801
- });
802
- if (!res.ok) await throwApiError(res);
803
- return await res.json();
804
- }
805
- async function reportActionCompletion(apiBaseUrl, actionId, result) {
806
- const res = await fetch(
807
- `${apiBaseUrl}/v1/authorization-actions/${actionId}`,
808
- {
809
- method: "PATCH",
810
- headers: { "Content-Type": "application/json" },
811
- body: JSON.stringify({ status: "COMPLETED", result })
812
- }
813
- );
814
- if (!res.ok) await throwApiError(res);
815
- return await res.json();
816
816
  }
817
817
 
818
818
  // src/passkeyRpId.ts
@@ -8259,40 +8259,21 @@ function usePaymentEffects(deps) {
8259
8259
  if (state.guestPreauthAccountId) return;
8260
8260
  if (!state.transfer || state.transfer.status !== "COMPLETED") return;
8261
8261
  let cancelled = false;
8262
- const ensureGuestAccount = async () => {
8262
+ const checkGuestAccount = async () => {
8263
8263
  try {
8264
- let result = await fetchGuestAccount(apiBaseUrl, state.guestSessionToken);
8264
+ const result = await fetchGuestAccount(apiBaseUrl, state.guestSessionToken);
8265
8265
  if (cancelled) return;
8266
- if (!result && state.selectedProviderId) {
8267
- const providerName = state.providers.find((p) => p.id === state.selectedProviderId)?.name ?? "Wallet";
8268
- const created = await createGuestAccount(
8269
- apiBaseUrl,
8270
- state.guestSessionToken,
8271
- state.selectedProviderId,
8272
- providerName
8273
- );
8274
- if (cancelled) return;
8275
- result = { accountId: created.accountId, hasPasskey: false, walletAddress: null };
8276
- }
8277
8266
  if (result && !result.hasPasskey) {
8278
8267
  dispatch({ type: "GUEST_PREAUTH_DETECTED", accountId: result.accountId });
8279
8268
  }
8280
8269
  } catch {
8281
8270
  }
8282
8271
  };
8283
- ensureGuestAccount();
8272
+ checkGuestAccount();
8284
8273
  return () => {
8285
8274
  cancelled = true;
8286
8275
  };
8287
- }, [
8288
- state.transfer,
8289
- state.guestSessionToken,
8290
- state.guestPreauthAccountId,
8291
- state.selectedProviderId,
8292
- state.providers,
8293
- apiBaseUrl,
8294
- dispatch
8295
- ]);
8276
+ }, [state.transfer, state.guestSessionToken, state.guestPreauthAccountId, apiBaseUrl, dispatch]);
8296
8277
  const settingOwnerRef = react.useRef(false);
8297
8278
  react.useEffect(() => {
8298
8279
  if (!state.guestPreauthAccountId) return;
@@ -8584,7 +8565,29 @@ function BlinkPaymentInner({
8584
8565
  onAuthorizeToken: provider.handleAuthorizeToken,
8585
8566
  onSelectGuestToken: guestTransfer.handleSelectGuestToken,
8586
8567
  onLogin: () => dispatch({ type: "REQUEST_LOGIN" }),
8587
- onPreauthorize: () => dispatch({ type: "REQUEST_LOGIN" })
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
+ }
8588
8591
  }), [
8589
8592
  auth,
8590
8593
  passkey,
@@ -8595,7 +8598,12 @@ function BlinkPaymentInner({
8595
8598
  oneTapSetup,
8596
8599
  guestTransfer,
8597
8600
  handleLogout,
8598
- handleNewPayment
8601
+ handleNewPayment,
8602
+ state.guestPreauthAccountId,
8603
+ state.guestSessionToken,
8604
+ state.selectedProviderId,
8605
+ state.providers,
8606
+ apiBaseUrl
8599
8607
  ]);
8600
8608
  return /* @__PURE__ */ jsxRuntime.jsx(
8601
8609
  StepRenderer,