@unifold/ui-web 0.1.49 → 0.1.50

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.js CHANGED
@@ -43354,6 +43354,9 @@ function getOnrampSessionStartUrl(request, publishableKey) {
43354
43354
  if (request.external_id) {
43355
43355
  params.append("external_id", request.external_id);
43356
43356
  }
43357
+ if (request.email) {
43358
+ params.append("email", request.email);
43359
+ }
43357
43360
  return `${API_BASE_URL}/v1/public/onramps/sessions/start?${params.toString()}`;
43358
43361
  }
43359
43362
  async function getDefaultOnrampToken(params, publishableKey) {
@@ -50308,31 +50311,29 @@ function BuyWithCard({
50308
50311
  );
50309
50312
  if (manualProviderStillExists) {
50310
50313
  setSelectedProvider(manualProviderStillExists);
50311
- const bestProvider = response.data.reduce(
50312
- (best, current) => current.destination_amount > best.destination_amount ? current : best
50313
- );
50314
+ const firstProvider = response.data[0];
50314
50315
  if (!autoSelectedProvider) {
50315
- setAutoSelectedProvider(bestProvider.service_provider);
50316
+ setAutoSelectedProvider(firstProvider.service_provider);
50316
50317
  }
50317
50318
  setIsAutoSelected(
50318
50319
  manualProviderStillExists.service_provider === autoSelectedProvider
50319
50320
  );
50320
- } else {
50321
- const bestProvider = response.data.reduce(
50322
- (best, current) => current.destination_amount > best.destination_amount ? current : best
50323
- );
50324
- setSelectedProvider(bestProvider);
50325
- setAutoSelectedProvider(bestProvider.service_provider);
50321
+ } else if (response.data.length > 0) {
50322
+ const firstProvider = response.data[0];
50323
+ setSelectedProvider(firstProvider);
50324
+ setAutoSelectedProvider(firstProvider.service_provider);
50326
50325
  setIsAutoSelected(true);
50327
50326
  setHasManualSelection(false);
50327
+ } else {
50328
+ setSelectedProvider(null);
50329
+ setIsAutoSelected(false);
50330
+ setHasManualSelection(false);
50328
50331
  }
50329
50332
  } else {
50330
50333
  if (response.data.length > 0) {
50331
- const bestProvider = response.data.reduce(
50332
- (best, current) => current.destination_amount > best.destination_amount ? current : best
50333
- );
50334
- setSelectedProvider(bestProvider);
50335
- setAutoSelectedProvider(bestProvider.service_provider);
50334
+ const firstProvider = response.data[0];
50335
+ setSelectedProvider(firstProvider);
50336
+ setAutoSelectedProvider(firstProvider.service_provider);
50336
50337
  setIsAutoSelected(true);
50337
50338
  }
50338
50339
  }
@@ -50428,9 +50429,7 @@ function BuyWithCard({
50428
50429
  window.open(sessionStartUrl, "_blank");
50429
50430
  handleViewChange("onramp");
50430
50431
  };
50431
- const sortedQuotes = [...quotes].sort(
50432
- (a, b) => b.destination_amount - a.destination_amount
50433
- );
50432
+ const sortedQuotes = quotes;
50434
50433
  const currencySymbol = getCurrencySymbol(currency);
50435
50434
  return /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)(
50436
50435
  "div",
@@ -54422,14 +54421,23 @@ function useAllowedCountry(publishableKey) {
54422
54421
  let isAllowed = null;
54423
54422
  if (ipData && configData) {
54424
54423
  const blockedCodes = configData.blocked_country_codes || [];
54424
+ const blockedSubdivisions = configData.blocked_country_subdivisions || [];
54425
54425
  const userCountryUpper = ipData.alpha2.toUpperCase();
54426
- isAllowed = !blockedCodes.some(
54426
+ const userSubdivision = ipData.subdivision_code || ipData.state || "";
54427
+ const userSubdivisionUpper = userSubdivision.toUpperCase();
54428
+ const isCountryBlocked = blockedCodes.some(
54427
54429
  (code) => code.toUpperCase() === userCountryUpper
54428
54430
  );
54431
+ const isSubdivisionBlocked = blockedSubdivisions.some((entry) => {
54432
+ if (entry.country_code.toUpperCase() !== userCountryUpper) return false;
54433
+ return entry.subdivision_codes.some(
54434
+ (code) => code.toUpperCase() === userSubdivisionUpper
54435
+ );
54436
+ });
54437
+ isAllowed = !isCountryBlocked && !isSubdivisionBlocked;
54429
54438
  }
54430
54439
  return {
54431
54440
  isAllowed,
54432
- // Return lowercase for consistency with useUserIp hook
54433
54441
  alpha2: ipData?.alpha2?.toLowerCase() ?? null,
54434
54442
  country: ipData?.country ?? null,
54435
54443
  isLoading,
@@ -59750,19 +59758,30 @@ function DepositModal({
59750
59758
  }
59751
59759
  ) });
59752
59760
  }
59761
+ var TERMINAL_STATUSES = /* @__PURE__ */ new Set([
59762
+ "succeeded",
59763
+ "expired",
59764
+ "refunded",
59765
+ "canceled"
59766
+ ]);
59753
59767
  function usePaymentIntent(params) {
59754
59768
  const {
59755
59769
  clientSecret,
59756
59770
  publishableKey,
59757
59771
  enabled = true,
59758
- pollingInterval = 5e3
59772
+ pollingInterval = 3e3
59759
59773
  } = params;
59760
59774
  return useQuery({
59761
59775
  queryKey: ["unifold", "paymentIntent", clientSecret, publishableKey],
59762
59776
  queryFn: () => retrievePaymentIntent(clientSecret, publishableKey),
59763
59777
  enabled: enabled && !!clientSecret && !!publishableKey,
59764
59778
  staleTime: 0,
59765
- refetchInterval: pollingInterval || false,
59779
+ refetchInterval: (query) => {
59780
+ if (!pollingInterval) return false;
59781
+ const status = query.state.data?.status;
59782
+ if (status && TERMINAL_STATUSES.has(status)) return false;
59783
+ return pollingInterval;
59784
+ },
59766
59785
  refetchOnWindowFocus: true,
59767
59786
  retry: 3,
59768
59787
  retryDelay: (attempt) => Math.min(1e3 * 2 ** attempt, 1e4)
@@ -59886,7 +59905,7 @@ function CheckoutModal({
59886
59905
  clientSecret,
59887
59906
  publishableKey,
59888
59907
  enabled: open && !!clientSecret,
59889
- pollingInterval: 5e3
59908
+ pollingInterval: 3e3
59890
59909
  });
59891
59910
  const { projectConfig } = useProjectConfig({
59892
59911
  publishableKey,
package/dist/index.mjs CHANGED
@@ -43341,6 +43341,9 @@ function getOnrampSessionStartUrl(request, publishableKey) {
43341
43341
  if (request.external_id) {
43342
43342
  params.append("external_id", request.external_id);
43343
43343
  }
43344
+ if (request.email) {
43345
+ params.append("email", request.email);
43346
+ }
43344
43347
  return `${API_BASE_URL}/v1/public/onramps/sessions/start?${params.toString()}`;
43345
43348
  }
43346
43349
  async function getDefaultOnrampToken(params, publishableKey) {
@@ -50295,31 +50298,29 @@ function BuyWithCard({
50295
50298
  );
50296
50299
  if (manualProviderStillExists) {
50297
50300
  setSelectedProvider(manualProviderStillExists);
50298
- const bestProvider = response.data.reduce(
50299
- (best, current) => current.destination_amount > best.destination_amount ? current : best
50300
- );
50301
+ const firstProvider = response.data[0];
50301
50302
  if (!autoSelectedProvider) {
50302
- setAutoSelectedProvider(bestProvider.service_provider);
50303
+ setAutoSelectedProvider(firstProvider.service_provider);
50303
50304
  }
50304
50305
  setIsAutoSelected(
50305
50306
  manualProviderStillExists.service_provider === autoSelectedProvider
50306
50307
  );
50307
- } else {
50308
- const bestProvider = response.data.reduce(
50309
- (best, current) => current.destination_amount > best.destination_amount ? current : best
50310
- );
50311
- setSelectedProvider(bestProvider);
50312
- setAutoSelectedProvider(bestProvider.service_provider);
50308
+ } else if (response.data.length > 0) {
50309
+ const firstProvider = response.data[0];
50310
+ setSelectedProvider(firstProvider);
50311
+ setAutoSelectedProvider(firstProvider.service_provider);
50313
50312
  setIsAutoSelected(true);
50314
50313
  setHasManualSelection(false);
50314
+ } else {
50315
+ setSelectedProvider(null);
50316
+ setIsAutoSelected(false);
50317
+ setHasManualSelection(false);
50315
50318
  }
50316
50319
  } else {
50317
50320
  if (response.data.length > 0) {
50318
- const bestProvider = response.data.reduce(
50319
- (best, current) => current.destination_amount > best.destination_amount ? current : best
50320
- );
50321
- setSelectedProvider(bestProvider);
50322
- setAutoSelectedProvider(bestProvider.service_provider);
50321
+ const firstProvider = response.data[0];
50322
+ setSelectedProvider(firstProvider);
50323
+ setAutoSelectedProvider(firstProvider.service_provider);
50323
50324
  setIsAutoSelected(true);
50324
50325
  }
50325
50326
  }
@@ -50415,9 +50416,7 @@ function BuyWithCard({
50415
50416
  window.open(sessionStartUrl, "_blank");
50416
50417
  handleViewChange("onramp");
50417
50418
  };
50418
- const sortedQuotes = [...quotes].sort(
50419
- (a, b) => b.destination_amount - a.destination_amount
50420
- );
50419
+ const sortedQuotes = quotes;
50421
50420
  const currencySymbol = getCurrencySymbol(currency);
50422
50421
  return /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)(
50423
50422
  "div",
@@ -54409,14 +54408,23 @@ function useAllowedCountry(publishableKey) {
54409
54408
  let isAllowed = null;
54410
54409
  if (ipData && configData) {
54411
54410
  const blockedCodes = configData.blocked_country_codes || [];
54411
+ const blockedSubdivisions = configData.blocked_country_subdivisions || [];
54412
54412
  const userCountryUpper = ipData.alpha2.toUpperCase();
54413
- isAllowed = !blockedCodes.some(
54413
+ const userSubdivision = ipData.subdivision_code || ipData.state || "";
54414
+ const userSubdivisionUpper = userSubdivision.toUpperCase();
54415
+ const isCountryBlocked = blockedCodes.some(
54414
54416
  (code) => code.toUpperCase() === userCountryUpper
54415
54417
  );
54418
+ const isSubdivisionBlocked = blockedSubdivisions.some((entry) => {
54419
+ if (entry.country_code.toUpperCase() !== userCountryUpper) return false;
54420
+ return entry.subdivision_codes.some(
54421
+ (code) => code.toUpperCase() === userSubdivisionUpper
54422
+ );
54423
+ });
54424
+ isAllowed = !isCountryBlocked && !isSubdivisionBlocked;
54416
54425
  }
54417
54426
  return {
54418
54427
  isAllowed,
54419
- // Return lowercase for consistency with useUserIp hook
54420
54428
  alpha2: ipData?.alpha2?.toLowerCase() ?? null,
54421
54429
  country: ipData?.country ?? null,
54422
54430
  isLoading,
@@ -59737,19 +59745,30 @@ function DepositModal({
59737
59745
  }
59738
59746
  ) });
59739
59747
  }
59748
+ var TERMINAL_STATUSES = /* @__PURE__ */ new Set([
59749
+ "succeeded",
59750
+ "expired",
59751
+ "refunded",
59752
+ "canceled"
59753
+ ]);
59740
59754
  function usePaymentIntent(params) {
59741
59755
  const {
59742
59756
  clientSecret,
59743
59757
  publishableKey,
59744
59758
  enabled = true,
59745
- pollingInterval = 5e3
59759
+ pollingInterval = 3e3
59746
59760
  } = params;
59747
59761
  return useQuery({
59748
59762
  queryKey: ["unifold", "paymentIntent", clientSecret, publishableKey],
59749
59763
  queryFn: () => retrievePaymentIntent(clientSecret, publishableKey),
59750
59764
  enabled: enabled && !!clientSecret && !!publishableKey,
59751
59765
  staleTime: 0,
59752
- refetchInterval: pollingInterval || false,
59766
+ refetchInterval: (query) => {
59767
+ if (!pollingInterval) return false;
59768
+ const status = query.state.data?.status;
59769
+ if (status && TERMINAL_STATUSES.has(status)) return false;
59770
+ return pollingInterval;
59771
+ },
59753
59772
  refetchOnWindowFocus: true,
59754
59773
  retry: 3,
59755
59774
  retryDelay: (attempt) => Math.min(1e3 * 2 ** attempt, 1e4)
@@ -59873,7 +59892,7 @@ function CheckoutModal({
59873
59892
  clientSecret,
59874
59893
  publishableKey,
59875
59894
  enabled: open && !!clientSecret,
59876
- pollingInterval: 5e3
59895
+ pollingInterval: 3e3
59877
59896
  });
59878
59897
  const { projectConfig } = useProjectConfig({
59879
59898
  publishableKey,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unifold/ui-web",
3
- "version": "0.1.49",
3
+ "version": "0.1.50",
4
4
  "description": "Unifold UI Web - Framework-agnostic deposit widget",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -30,10 +30,10 @@
30
30
  "@types/react-dom": "^19.0.0",
31
31
  "tsup": "^8.0.0",
32
32
  "typescript": "^5.0.0",
33
- "@unifold/connect-react": "0.1.49",
34
- "@unifold/core": "0.1.49",
35
- "@unifold/react-provider": "0.1.49",
36
- "@unifold/ui-react": "0.1.49"
33
+ "@unifold/connect-react": "0.1.50",
34
+ "@unifold/ui-react": "0.1.50",
35
+ "@unifold/react-provider": "0.1.50",
36
+ "@unifold/core": "0.1.50"
37
37
  },
38
38
  "keywords": [
39
39
  "unifold",