@unifold/ui-web 0.1.49 → 0.1.51

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) {
@@ -48903,11 +48906,13 @@ function useUserIp2() {
48903
48906
  queryKey: ["unifold", "userIpInfo"],
48904
48907
  queryFn: async () => {
48905
48908
  const data = await getIpAddress();
48909
+ const subdivision = (data.subdivision_code || data.state || "").toLowerCase() || null;
48906
48910
  return {
48907
48911
  alpha2: data.alpha2.toLowerCase(),
48908
48912
  alpha3: data.alpha3?.toLowerCase(),
48909
48913
  country: data.country,
48910
- state: data.state?.toLowerCase() ?? null,
48914
+ state: subdivision,
48915
+ subdivisionCode: subdivision,
48911
48916
  ipAddress: data.ip_address
48912
48917
  };
48913
48918
  },
@@ -50213,7 +50218,7 @@ function BuyWithCard({
50213
50218
  const response = await getDefaultOnrampToken(
50214
50219
  {
50215
50220
  country_code: userIpInfo?.alpha2?.toUpperCase() || "US",
50216
- subdivision_code: userIpInfo?.state || void 0,
50221
+ subdivision_code: userIpInfo?.subdivisionCode || void 0,
50217
50222
  token_address: destinationTokenAddress,
50218
50223
  chain_id: destinationChainId,
50219
50224
  chain_type: destinationChainType
@@ -50296,7 +50301,7 @@ function BuyWithCard({
50296
50301
  source_currency: currency.toLowerCase(),
50297
50302
  destination_currency: defaultToken.destination_currency,
50298
50303
  destination_network: defaultToken.destination_network,
50299
- subdivision_code: userIpInfo?.state || void 0
50304
+ subdivision_code: userIpInfo?.subdivisionCode || void 0
50300
50305
  };
50301
50306
  const response = await getOnrampQuotes(request, publishableKey);
50302
50307
  setQuotes(response.data);
@@ -50308,31 +50313,29 @@ function BuyWithCard({
50308
50313
  );
50309
50314
  if (manualProviderStillExists) {
50310
50315
  setSelectedProvider(manualProviderStillExists);
50311
- const bestProvider = response.data.reduce(
50312
- (best, current) => current.destination_amount > best.destination_amount ? current : best
50313
- );
50316
+ const firstProvider = response.data[0];
50314
50317
  if (!autoSelectedProvider) {
50315
- setAutoSelectedProvider(bestProvider.service_provider);
50318
+ setAutoSelectedProvider(firstProvider.service_provider);
50316
50319
  }
50317
50320
  setIsAutoSelected(
50318
50321
  manualProviderStillExists.service_provider === autoSelectedProvider
50319
50322
  );
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);
50323
+ } else if (response.data.length > 0) {
50324
+ const firstProvider = response.data[0];
50325
+ setSelectedProvider(firstProvider);
50326
+ setAutoSelectedProvider(firstProvider.service_provider);
50326
50327
  setIsAutoSelected(true);
50327
50328
  setHasManualSelection(false);
50329
+ } else {
50330
+ setSelectedProvider(null);
50331
+ setIsAutoSelected(false);
50332
+ setHasManualSelection(false);
50328
50333
  }
50329
50334
  } else {
50330
50335
  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);
50336
+ const firstProvider = response.data[0];
50337
+ setSelectedProvider(firstProvider);
50338
+ setAutoSelectedProvider(firstProvider.service_provider);
50336
50339
  setIsAutoSelected(true);
50337
50340
  }
50338
50341
  }
@@ -50405,7 +50408,7 @@ function BuyWithCard({
50405
50408
  destination_currency: selectedProvider.destination_currency,
50406
50409
  destination_network: selectedProvider.destination_network,
50407
50410
  wallet_address: wallet.address,
50408
- subdivision_code: userIpInfo?.state || void 0,
50411
+ subdivision_code: userIpInfo?.subdivisionCode || void 0,
50409
50412
  external_id: externalId
50410
50413
  };
50411
50414
  const sessionStartUrl = getOnrampSessionStartUrl(
@@ -50428,9 +50431,7 @@ function BuyWithCard({
50428
50431
  window.open(sessionStartUrl, "_blank");
50429
50432
  handleViewChange("onramp");
50430
50433
  };
50431
- const sortedQuotes = [...quotes].sort(
50432
- (a, b) => b.destination_amount - a.destination_amount
50433
- );
50434
+ const sortedQuotes = quotes;
50434
50435
  const currencySymbol = getCurrencySymbol(currency);
50435
50436
  return /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)(
50436
50437
  "div",
@@ -54422,16 +54423,27 @@ function useAllowedCountry(publishableKey) {
54422
54423
  let isAllowed = null;
54423
54424
  if (ipData && configData) {
54424
54425
  const blockedCodes = configData.blocked_country_codes || [];
54426
+ const blockedSubdivisions = configData.blocked_country_subdivisions || [];
54425
54427
  const userCountryUpper = ipData.alpha2.toUpperCase();
54426
- isAllowed = !blockedCodes.some(
54428
+ const userSubdivision = ipData.subdivision_code || ipData.state || "";
54429
+ const userSubdivisionUpper = userSubdivision.toUpperCase();
54430
+ const isCountryBlocked = blockedCodes.some(
54427
54431
  (code) => code.toUpperCase() === userCountryUpper
54428
54432
  );
54433
+ const isSubdivisionBlocked = blockedSubdivisions.some((entry) => {
54434
+ if (entry.country_code.toUpperCase() !== userCountryUpper) return false;
54435
+ return entry.subdivision_codes.some(
54436
+ (code) => code.toUpperCase() === userSubdivisionUpper
54437
+ );
54438
+ });
54439
+ isAllowed = !isCountryBlocked && !isSubdivisionBlocked;
54429
54440
  }
54441
+ const subdivisionCode = (ipData?.subdivision_code || ipData?.state || "").toLowerCase() || null;
54430
54442
  return {
54431
54443
  isAllowed,
54432
- // Return lowercase for consistency with useUserIp hook
54433
54444
  alpha2: ipData?.alpha2?.toLowerCase() ?? null,
54434
54445
  country: ipData?.country ?? null,
54446
+ subdivisionCode,
54435
54447
  isLoading,
54436
54448
  error
54437
54449
  };
@@ -59750,19 +59762,30 @@ function DepositModal({
59750
59762
  }
59751
59763
  ) });
59752
59764
  }
59765
+ var TERMINAL_STATUSES = /* @__PURE__ */ new Set([
59766
+ "succeeded",
59767
+ "expired",
59768
+ "refunded",
59769
+ "canceled"
59770
+ ]);
59753
59771
  function usePaymentIntent(params) {
59754
59772
  const {
59755
59773
  clientSecret,
59756
59774
  publishableKey,
59757
59775
  enabled = true,
59758
- pollingInterval = 5e3
59776
+ pollingInterval = 3e3
59759
59777
  } = params;
59760
59778
  return useQuery({
59761
59779
  queryKey: ["unifold", "paymentIntent", clientSecret, publishableKey],
59762
59780
  queryFn: () => retrievePaymentIntent(clientSecret, publishableKey),
59763
59781
  enabled: enabled && !!clientSecret && !!publishableKey,
59764
59782
  staleTime: 0,
59765
- refetchInterval: pollingInterval || false,
59783
+ refetchInterval: (query) => {
59784
+ if (!pollingInterval) return false;
59785
+ const status = query.state.data?.status;
59786
+ if (status && TERMINAL_STATUSES.has(status)) return false;
59787
+ return pollingInterval;
59788
+ },
59766
59789
  refetchOnWindowFocus: true,
59767
59790
  retry: 3,
59768
59791
  retryDelay: (attempt) => Math.min(1e3 * 2 ** attempt, 1e4)
@@ -59886,7 +59909,7 @@ function CheckoutModal({
59886
59909
  clientSecret,
59887
59910
  publishableKey,
59888
59911
  enabled: open && !!clientSecret,
59889
- pollingInterval: 5e3
59912
+ pollingInterval: 3e3
59890
59913
  });
59891
59914
  const { projectConfig } = useProjectConfig({
59892
59915
  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) {
@@ -48890,11 +48893,13 @@ function useUserIp2() {
48890
48893
  queryKey: ["unifold", "userIpInfo"],
48891
48894
  queryFn: async () => {
48892
48895
  const data = await getIpAddress();
48896
+ const subdivision = (data.subdivision_code || data.state || "").toLowerCase() || null;
48893
48897
  return {
48894
48898
  alpha2: data.alpha2.toLowerCase(),
48895
48899
  alpha3: data.alpha3?.toLowerCase(),
48896
48900
  country: data.country,
48897
- state: data.state?.toLowerCase() ?? null,
48901
+ state: subdivision,
48902
+ subdivisionCode: subdivision,
48898
48903
  ipAddress: data.ip_address
48899
48904
  };
48900
48905
  },
@@ -50200,7 +50205,7 @@ function BuyWithCard({
50200
50205
  const response = await getDefaultOnrampToken(
50201
50206
  {
50202
50207
  country_code: userIpInfo?.alpha2?.toUpperCase() || "US",
50203
- subdivision_code: userIpInfo?.state || void 0,
50208
+ subdivision_code: userIpInfo?.subdivisionCode || void 0,
50204
50209
  token_address: destinationTokenAddress,
50205
50210
  chain_id: destinationChainId,
50206
50211
  chain_type: destinationChainType
@@ -50283,7 +50288,7 @@ function BuyWithCard({
50283
50288
  source_currency: currency.toLowerCase(),
50284
50289
  destination_currency: defaultToken.destination_currency,
50285
50290
  destination_network: defaultToken.destination_network,
50286
- subdivision_code: userIpInfo?.state || void 0
50291
+ subdivision_code: userIpInfo?.subdivisionCode || void 0
50287
50292
  };
50288
50293
  const response = await getOnrampQuotes(request, publishableKey);
50289
50294
  setQuotes(response.data);
@@ -50295,31 +50300,29 @@ function BuyWithCard({
50295
50300
  );
50296
50301
  if (manualProviderStillExists) {
50297
50302
  setSelectedProvider(manualProviderStillExists);
50298
- const bestProvider = response.data.reduce(
50299
- (best, current) => current.destination_amount > best.destination_amount ? current : best
50300
- );
50303
+ const firstProvider = response.data[0];
50301
50304
  if (!autoSelectedProvider) {
50302
- setAutoSelectedProvider(bestProvider.service_provider);
50305
+ setAutoSelectedProvider(firstProvider.service_provider);
50303
50306
  }
50304
50307
  setIsAutoSelected(
50305
50308
  manualProviderStillExists.service_provider === autoSelectedProvider
50306
50309
  );
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);
50310
+ } else if (response.data.length > 0) {
50311
+ const firstProvider = response.data[0];
50312
+ setSelectedProvider(firstProvider);
50313
+ setAutoSelectedProvider(firstProvider.service_provider);
50313
50314
  setIsAutoSelected(true);
50314
50315
  setHasManualSelection(false);
50316
+ } else {
50317
+ setSelectedProvider(null);
50318
+ setIsAutoSelected(false);
50319
+ setHasManualSelection(false);
50315
50320
  }
50316
50321
  } else {
50317
50322
  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);
50323
+ const firstProvider = response.data[0];
50324
+ setSelectedProvider(firstProvider);
50325
+ setAutoSelectedProvider(firstProvider.service_provider);
50323
50326
  setIsAutoSelected(true);
50324
50327
  }
50325
50328
  }
@@ -50392,7 +50395,7 @@ function BuyWithCard({
50392
50395
  destination_currency: selectedProvider.destination_currency,
50393
50396
  destination_network: selectedProvider.destination_network,
50394
50397
  wallet_address: wallet.address,
50395
- subdivision_code: userIpInfo?.state || void 0,
50398
+ subdivision_code: userIpInfo?.subdivisionCode || void 0,
50396
50399
  external_id: externalId
50397
50400
  };
50398
50401
  const sessionStartUrl = getOnrampSessionStartUrl(
@@ -50415,9 +50418,7 @@ function BuyWithCard({
50415
50418
  window.open(sessionStartUrl, "_blank");
50416
50419
  handleViewChange("onramp");
50417
50420
  };
50418
- const sortedQuotes = [...quotes].sort(
50419
- (a, b) => b.destination_amount - a.destination_amount
50420
- );
50421
+ const sortedQuotes = quotes;
50421
50422
  const currencySymbol = getCurrencySymbol(currency);
50422
50423
  return /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)(
50423
50424
  "div",
@@ -54409,16 +54410,27 @@ function useAllowedCountry(publishableKey) {
54409
54410
  let isAllowed = null;
54410
54411
  if (ipData && configData) {
54411
54412
  const blockedCodes = configData.blocked_country_codes || [];
54413
+ const blockedSubdivisions = configData.blocked_country_subdivisions || [];
54412
54414
  const userCountryUpper = ipData.alpha2.toUpperCase();
54413
- isAllowed = !blockedCodes.some(
54415
+ const userSubdivision = ipData.subdivision_code || ipData.state || "";
54416
+ const userSubdivisionUpper = userSubdivision.toUpperCase();
54417
+ const isCountryBlocked = blockedCodes.some(
54414
54418
  (code) => code.toUpperCase() === userCountryUpper
54415
54419
  );
54420
+ const isSubdivisionBlocked = blockedSubdivisions.some((entry) => {
54421
+ if (entry.country_code.toUpperCase() !== userCountryUpper) return false;
54422
+ return entry.subdivision_codes.some(
54423
+ (code) => code.toUpperCase() === userSubdivisionUpper
54424
+ );
54425
+ });
54426
+ isAllowed = !isCountryBlocked && !isSubdivisionBlocked;
54416
54427
  }
54428
+ const subdivisionCode = (ipData?.subdivision_code || ipData?.state || "").toLowerCase() || null;
54417
54429
  return {
54418
54430
  isAllowed,
54419
- // Return lowercase for consistency with useUserIp hook
54420
54431
  alpha2: ipData?.alpha2?.toLowerCase() ?? null,
54421
54432
  country: ipData?.country ?? null,
54433
+ subdivisionCode,
54422
54434
  isLoading,
54423
54435
  error
54424
54436
  };
@@ -59737,19 +59749,30 @@ function DepositModal({
59737
59749
  }
59738
59750
  ) });
59739
59751
  }
59752
+ var TERMINAL_STATUSES = /* @__PURE__ */ new Set([
59753
+ "succeeded",
59754
+ "expired",
59755
+ "refunded",
59756
+ "canceled"
59757
+ ]);
59740
59758
  function usePaymentIntent(params) {
59741
59759
  const {
59742
59760
  clientSecret,
59743
59761
  publishableKey,
59744
59762
  enabled = true,
59745
- pollingInterval = 5e3
59763
+ pollingInterval = 3e3
59746
59764
  } = params;
59747
59765
  return useQuery({
59748
59766
  queryKey: ["unifold", "paymentIntent", clientSecret, publishableKey],
59749
59767
  queryFn: () => retrievePaymentIntent(clientSecret, publishableKey),
59750
59768
  enabled: enabled && !!clientSecret && !!publishableKey,
59751
59769
  staleTime: 0,
59752
- refetchInterval: pollingInterval || false,
59770
+ refetchInterval: (query) => {
59771
+ if (!pollingInterval) return false;
59772
+ const status = query.state.data?.status;
59773
+ if (status && TERMINAL_STATUSES.has(status)) return false;
59774
+ return pollingInterval;
59775
+ },
59753
59776
  refetchOnWindowFocus: true,
59754
59777
  retry: 3,
59755
59778
  retryDelay: (attempt) => Math.min(1e3 * 2 ** attempt, 1e4)
@@ -59873,7 +59896,7 @@ function CheckoutModal({
59873
59896
  clientSecret,
59874
59897
  publishableKey,
59875
59898
  enabled: open && !!clientSecret,
59876
- pollingInterval: 5e3
59899
+ pollingInterval: 3e3
59877
59900
  });
59878
59901
  const { projectConfig } = useProjectConfig({
59879
59902
  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.51",
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.51",
34
+ "@unifold/core": "0.1.51",
35
+ "@unifold/ui-react": "0.1.51",
36
+ "@unifold/react-provider": "0.1.51"
37
37
  },
38
38
  "keywords": [
39
39
  "unifold",