@volr/react 0.1.92 → 0.1.93

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
@@ -19620,6 +19620,87 @@ async function uploadBlobViaPresign(params) {
19620
19620
  }
19621
19621
  return { s3Key };
19622
19622
  }
19623
+ var POLL_INTERVAL_MS = 2e3;
19624
+ var MAX_POLL_ATTEMPTS = 180;
19625
+ function useVolrPay() {
19626
+ const { client } = useInternalAuth();
19627
+ const [isLoading, setIsLoading] = react.useState(false);
19628
+ const createPayment = react.useCallback(
19629
+ async (options) => {
19630
+ setIsLoading(true);
19631
+ try {
19632
+ const response = await client.post("/payments", {
19633
+ amount: options.amount,
19634
+ item: options.item,
19635
+ referenceId: options.referenceId,
19636
+ metadata: options.metadata,
19637
+ idempotencyKey: options.idempotencyKey,
19638
+ expiresInSec: options.expiresInSec
19639
+ });
19640
+ return response;
19641
+ } finally {
19642
+ setIsLoading(false);
19643
+ }
19644
+ },
19645
+ [client]
19646
+ );
19647
+ const checkPayment = react.useCallback(
19648
+ async (paymentId) => {
19649
+ return client.get(`/payments/${paymentId}`);
19650
+ },
19651
+ [client]
19652
+ );
19653
+ const getPaymentHistory = react.useCallback(
19654
+ async (options = {}) => {
19655
+ const params = new URLSearchParams();
19656
+ if (options.take) params.append("take", String(options.take));
19657
+ if (options.skip) params.append("skip", String(options.skip));
19658
+ if (options.status) params.append("status", options.status);
19659
+ const queryString = params.toString();
19660
+ const url = queryString ? `/payments?${queryString}` : "/payments";
19661
+ return client.get(url);
19662
+ },
19663
+ [client]
19664
+ );
19665
+ const updatePaymentToProcessing = react.useCallback(
19666
+ async (paymentId, transactionId) => {
19667
+ return client.post(`/payments/${paymentId}/processing`, {
19668
+ transactionId
19669
+ });
19670
+ },
19671
+ [client]
19672
+ );
19673
+ const cancelPayment = react.useCallback(
19674
+ async (paymentId) => {
19675
+ return client.post(`/payments/${paymentId}/cancel`, {});
19676
+ },
19677
+ [client]
19678
+ );
19679
+ const pollPaymentStatus = react.useCallback(
19680
+ async (paymentId) => {
19681
+ let attempts = 0;
19682
+ while (attempts < MAX_POLL_ATTEMPTS) {
19683
+ const payment = await checkPayment(paymentId);
19684
+ if (payment.status === "CONFIRMED" || payment.status === "FAILED" || payment.status === "CANCELLED" || payment.status === "EXPIRED") {
19685
+ return payment;
19686
+ }
19687
+ await new Promise((resolve) => setTimeout(resolve, POLL_INTERVAL_MS));
19688
+ attempts++;
19689
+ }
19690
+ throw new Error("Payment polling timeout");
19691
+ },
19692
+ [checkPayment]
19693
+ );
19694
+ return {
19695
+ createPayment,
19696
+ checkPayment,
19697
+ getPaymentHistory,
19698
+ updatePaymentToProcessing,
19699
+ cancelPayment,
19700
+ pollPaymentStatus,
19701
+ isLoading
19702
+ };
19703
+ }
19623
19704
 
19624
19705
  // src/utils/contract-analysis.ts
19625
19706
  var EIP7702_PREFIX = "0xef0100";
@@ -20295,5 +20376,6 @@ exports.useVolr = useVolr;
20295
20376
  exports.useVolrAuthCallback = useVolrAuthCallback;
20296
20377
  exports.useVolrContext = useVolrContext;
20297
20378
  exports.useVolrLogin = useVolrLogin;
20379
+ exports.useVolrPay = useVolrPay;
20298
20380
  //# sourceMappingURL=index.cjs.map
20299
20381
  //# sourceMappingURL=index.cjs.map