@coinlist-co/react 0.12.2-rc.31c2f50 → 0.12.2-rc.5f2ca48

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.
Files changed (32) hide show
  1. package/dist/{chunk-4IZ2F732.js → chunk-6NCNF5GF.js} +2 -2
  2. package/dist/{chunk-UJYSXXJF.js → chunk-VUIDJYHY.js} +6 -156
  3. package/dist/chunk-VUIDJYHY.js.map +1 -0
  4. package/dist/{chunk-NBO5E2RO.js → chunk-XCRU3YE2.js} +599 -409
  5. package/dist/chunk-XCRU3YE2.js.map +1 -0
  6. package/dist/client/index.cjs +458 -111
  7. package/dist/client/index.cjs.map +1 -1
  8. package/dist/client/index.d.cts +184 -5
  9. package/dist/client/index.d.ts +184 -5
  10. package/dist/client/index.js +222 -9
  11. package/dist/client/index.js.map +1 -1
  12. package/dist/server/index.cjs +151 -26
  13. package/dist/server/index.cjs.map +1 -1
  14. package/dist/server/index.d.cts +10 -2
  15. package/dist/server/index.d.ts +10 -2
  16. package/dist/server/index.js +4 -2
  17. package/dist/server/index.js.map +1 -1
  18. package/dist/{time-DvgN98Q9.d.ts → time-CTuVDTx6.d.ts} +1 -1
  19. package/dist/{time-CFocgYyl.d.cts → time-Dv1dejVB.d.cts} +1 -1
  20. package/dist/{token-registry-snapshot-Cc_eA5zM.d.cts → token-registry-snapshot-CX5YiSHp.d.cts} +1 -1
  21. package/dist/{token-registry-snapshot-BsAfBL_b.d.ts → token-registry-snapshot-CzJd2VYU.d.ts} +1 -1
  22. package/dist/{tokens-namespace-D_XSpiS-.d.cts → tokens-namespace-CcvHrw-k.d.cts} +361 -2
  23. package/dist/{tokens-namespace-D_XSpiS-.d.ts → tokens-namespace-CcvHrw-k.d.ts} +361 -2
  24. package/dist/universal/index.cjs +528 -472
  25. package/dist/universal/index.cjs.map +1 -1
  26. package/dist/universal/index.d.cts +18 -321
  27. package/dist/universal/index.d.ts +18 -321
  28. package/dist/universal/index.js +11 -7
  29. package/package.json +1 -1
  30. package/dist/chunk-NBO5E2RO.js.map +0 -1
  31. package/dist/chunk-UJYSXXJF.js.map +0 -1
  32. /package/dist/{chunk-4IZ2F732.js.map → chunk-6NCNF5GF.js.map} +0 -0
@@ -7,9 +7,10 @@ import {
7
7
  notifySessionExpired,
8
8
  publicClients,
9
9
  systemDelay
10
- } from "../chunk-4IZ2F732.js";
10
+ } from "../chunk-6NCNF5GF.js";
11
11
  import {
12
12
  AuthorizationCode,
13
+ CENTRIFUGE_POLL_INTERVAL_MS,
13
14
  CodeVerifier,
14
15
  DEFAULT_AMOUNT_TO_COMPUTE_PRICE,
15
16
  DEFAULT_ONDO_AMOUNT_TO_COMPUTE_PRICE,
@@ -42,7 +43,7 @@ import {
42
43
  ondoQuoteOfferDeadline,
43
44
  superstateSwapContractAddress,
44
45
  swapSpender
45
- } from "../chunk-UJYSXXJF.js";
46
+ } from "../chunk-VUIDJYHY.js";
46
47
  import {
47
48
  API_VERSION,
48
49
  AssetDecimals,
@@ -52,6 +53,7 @@ import {
52
53
  Blockchain,
53
54
  BlockchainAmount,
54
55
  COINLIST_BASE_URL,
56
+ CentrifugeNamespaceImpl,
55
57
  CoinListTokenSaleNamespaceImpl,
56
58
  DecimalString,
57
59
  ERC20_ABI,
@@ -95,7 +97,7 @@ import {
95
97
  shortenAddress,
96
98
  txExplorerUrl,
97
99
  usdAmount
98
- } from "../chunk-NBO5E2RO.js";
100
+ } from "../chunk-XCRU3YE2.js";
99
101
 
100
102
  // src/client/CoinListProvider.tsx
101
103
  import {
@@ -1164,6 +1166,7 @@ var CoinListClientImpl = class {
1164
1166
  this.wallets
1165
1167
  );
1166
1168
  this.ondo = new ClientOndoNamespaceImpl(ctx, this.erc20);
1169
+ this.centrifuge = new CentrifugeNamespaceImpl(ctx);
1167
1170
  this.tokens = new TokensNamespaceImpl(
1168
1171
  config.tokensBaseUrl ?? NABU_BASE_URL,
1169
1172
  logger
@@ -12585,17 +12588,220 @@ function useCompleteOAuth(options) {
12585
12588
  }, [coinlist, log]);
12586
12589
  }
12587
12590
 
12591
+ // src/client/hooks/checkout/centrifuge/shared/centrifuge-order-reason.ts
12592
+ var CENTRIFUGE_VAULT_ORDER_REASON_MESSAGES = {
12593
+ vault_unlinked: "This vault is no longer available on this network.",
12594
+ vault_halted: "Investing in this vault is paused.",
12595
+ proxy_not_permissioned: "This vault cannot accept investments right now.",
12596
+ price_unavailable: "A price is not available for this vault right now.",
12597
+ below_minimum: "Enter at least the minimum amount to invest."
12598
+ };
12599
+ var ORDER_REASON_SEVERITY = {
12600
+ vault_unlinked: 0,
12601
+ vault_halted: 1,
12602
+ proxy_not_permissioned: 2,
12603
+ price_unavailable: 3,
12604
+ below_minimum: 4
12605
+ };
12606
+ function centrifugeVaultOrderReasonMessage(reason) {
12607
+ return CENTRIFUGE_VAULT_ORDER_REASON_MESSAGES[reason];
12608
+ }
12609
+ function primaryCentrifugeVaultOrderReason(reasons) {
12610
+ if (reasons.length === 0) return null;
12611
+ return reasons.reduce(
12612
+ (best, reason) => ORDER_REASON_SEVERITY[reason] < ORDER_REASON_SEVERITY[best] ? reason : best
12613
+ );
12614
+ }
12615
+ function centrifugeVaultOrderingMessage(orderability) {
12616
+ if (orderability.type === "orderable") return null;
12617
+ const reason = primaryCentrifugeVaultOrderReason(orderability.reasons);
12618
+ return reason === null ? null : centrifugeVaultOrderReasonMessage(reason);
12619
+ }
12620
+
12621
+ // src/client/hooks/checkout/centrifuge/shared/data/centrifuge-load-error.ts
12622
+ function centrifugeLoadErrorReason(error) {
12623
+ return error instanceof NotAuthenticatedError ? "not-authenticated" : "generic-error";
12624
+ }
12625
+
12626
+ // src/client/hooks/checkout/centrifuge/shared/data/useCentrifugeQuote.ts
12627
+ import { useEffect as useEffect32, useRef as useRef19, useState as useState33 } from "react";
12628
+ var LOADING3 = { type: "LOADING" };
12629
+ function useCentrifugeQuote(options) {
12630
+ const {
12631
+ symbol,
12632
+ chain,
12633
+ amount,
12634
+ pollIntervalMs = CENTRIFUGE_POLL_INTERVAL_MS,
12635
+ data,
12636
+ enabled
12637
+ } = options;
12638
+ const { coinlist, isReady } = useCoinList();
12639
+ const log = useLogger("useCentrifugeQuote");
12640
+ const [state, setState] = useState33(
12641
+ () => data === void 0 ? LOADING3 : { type: "CONTENT", quote: data, isRefreshing: false }
12642
+ );
12643
+ const fetchIdRef = useRef19(0);
12644
+ const isFetchingRef = useRef19(false);
12645
+ const hasQuoteRef = useRef19(data !== void 0);
12646
+ useEffect32(() => {
12647
+ if (!isReady || !enabled) return;
12648
+ const currentFetchId = ++fetchIdRef.current;
12649
+ isFetchingRef.current = false;
12650
+ const load = async () => {
12651
+ if (isFetchingRef.current) return;
12652
+ isFetchingRef.current = true;
12653
+ setState(
12654
+ (previous) => previous.type === "CONTENT" ? { ...previous, isRefreshing: true } : previous
12655
+ );
12656
+ try {
12657
+ const quote = await coinlist.centrifuge.getQuote({
12658
+ symbol,
12659
+ chain,
12660
+ // Rebuilt from primitives the effect depends on, so an inline
12661
+ // `amount` from the checkout viewmodel does not restart the poll.
12662
+ amount: BlockchainAmount({
12663
+ raw: amount.raw,
12664
+ decimals: amount.decimals
12665
+ })
12666
+ });
12667
+ if (currentFetchId !== fetchIdRef.current) return;
12668
+ log.debug(() => ({
12669
+ msg: "settled",
12670
+ fields: { state: "CONTENT" }
12671
+ }));
12672
+ hasQuoteRef.current = true;
12673
+ setState({ type: "CONTENT", quote, isRefreshing: false });
12674
+ } catch (error) {
12675
+ if (currentFetchId !== fetchIdRef.current) return;
12676
+ const reason = centrifugeLoadErrorReason(error);
12677
+ if (hasQuoteRef.current) {
12678
+ log.warning(
12679
+ () => ({
12680
+ msg: "poll failed; keeping the last quote",
12681
+ fields: { reason }
12682
+ }),
12683
+ error
12684
+ );
12685
+ } else {
12686
+ log.failure(
12687
+ () => ({ msg: "settled", fields: { state: "ERROR", reason } }),
12688
+ error
12689
+ );
12690
+ }
12691
+ setState(
12692
+ (previous) => previous.type === "CONTENT" ? { ...previous, isRefreshing: false } : { type: "ERROR", reason }
12693
+ );
12694
+ } finally {
12695
+ if (currentFetchId === fetchIdRef.current) {
12696
+ isFetchingRef.current = false;
12697
+ }
12698
+ }
12699
+ };
12700
+ load();
12701
+ const interval = setInterval(load, pollIntervalMs);
12702
+ return () => {
12703
+ clearInterval(interval);
12704
+ ++fetchIdRef.current;
12705
+ };
12706
+ }, [
12707
+ coinlist,
12708
+ isReady,
12709
+ enabled,
12710
+ symbol,
12711
+ chain,
12712
+ amount.raw,
12713
+ amount.decimals,
12714
+ pollIntervalMs,
12715
+ log
12716
+ ]);
12717
+ return { state };
12718
+ }
12719
+
12720
+ // src/client/hooks/checkout/centrifuge/shared/data/useCentrifugeVaultStatus.ts
12721
+ import { useEffect as useEffect33, useRef as useRef20, useState as useState34 } from "react";
12722
+ var LOADING4 = { type: "LOADING" };
12723
+ function useCentrifugeVaultStatus(options) {
12724
+ const {
12725
+ symbol,
12726
+ chain,
12727
+ pollIntervalMs = CENTRIFUGE_POLL_INTERVAL_MS,
12728
+ data,
12729
+ enabled
12730
+ } = options;
12731
+ const { coinlist, isReady } = useCoinList();
12732
+ const log = useLogger("useCentrifugeVaultStatus");
12733
+ const [state, setState] = useState34(
12734
+ () => data === void 0 ? LOADING4 : { type: "CONTENT", status: data }
12735
+ );
12736
+ const fetchIdRef = useRef20(0);
12737
+ const isFetchingRef = useRef20(false);
12738
+ const hasStatusRef = useRef20(data !== void 0);
12739
+ useEffect33(() => {
12740
+ if (!isReady || !enabled) return;
12741
+ const currentFetchId = ++fetchIdRef.current;
12742
+ isFetchingRef.current = false;
12743
+ const load = async () => {
12744
+ if (isFetchingRef.current) return;
12745
+ isFetchingRef.current = true;
12746
+ try {
12747
+ const status = await coinlist.centrifuge.getVaultStatus({
12748
+ symbol,
12749
+ chain
12750
+ });
12751
+ if (currentFetchId !== fetchIdRef.current) return;
12752
+ log.debug(() => ({
12753
+ msg: "settled",
12754
+ fields: { state: "CONTENT", orderability: status.orderability.type }
12755
+ }));
12756
+ hasStatusRef.current = true;
12757
+ setState({ type: "CONTENT", status });
12758
+ } catch (error) {
12759
+ if (currentFetchId !== fetchIdRef.current) return;
12760
+ const reason = centrifugeLoadErrorReason(error);
12761
+ if (hasStatusRef.current) {
12762
+ log.warning(
12763
+ () => ({
12764
+ msg: "poll failed; keeping the last status",
12765
+ fields: { reason }
12766
+ }),
12767
+ error
12768
+ );
12769
+ } else {
12770
+ log.failure(
12771
+ () => ({ msg: "settled", fields: { state: "ERROR", reason } }),
12772
+ error
12773
+ );
12774
+ }
12775
+ setState(
12776
+ (previous) => previous.type === "CONTENT" ? previous : { type: "ERROR", reason }
12777
+ );
12778
+ } finally {
12779
+ if (currentFetchId === fetchIdRef.current) {
12780
+ isFetchingRef.current = false;
12781
+ }
12782
+ }
12783
+ };
12784
+ load();
12785
+ const interval = setInterval(load, pollIntervalMs);
12786
+ return () => {
12787
+ clearInterval(interval);
12788
+ ++fetchIdRef.current;
12789
+ };
12790
+ }, [coinlist, isReady, enabled, symbol, chain, pollIntervalMs, log]);
12791
+ return { state };
12792
+ }
12793
+
12588
12794
  // src/client/hooks/checkout/coin-list/token-sale/data/useParticipations.ts
12589
- import { useEffect as useEffect32, useState as useState33 } from "react";
12795
+ import { useEffect as useEffect34, useState as useState35 } from "react";
12590
12796
  var LOADING_STATE9 = { type: "LOADING" };
12591
12797
  function useParticipations(offerId, options = {}) {
12592
12798
  const { coinlist, isReady } = useCoinList();
12593
12799
  const log = useLogger("useParticipations");
12594
12800
  const { data, enabled = true } = options;
12595
- const [participationsState, setParticipationsState] = useState33(
12801
+ const [participationsState, setParticipationsState] = useState35(
12596
12802
  data !== void 0 ? { type: "CONTENT", participations: data } : LOADING_STATE9
12597
12803
  );
12598
- useEffect32(() => {
12804
+ useEffect34(() => {
12599
12805
  let isCancelled = false;
12600
12806
  if (!enabled) {
12601
12807
  return () => {
@@ -12642,16 +12848,16 @@ function useParticipations(offerId, options = {}) {
12642
12848
  }
12643
12849
 
12644
12850
  // src/client/hooks/offers/data/useOfferDetails.ts
12645
- import { useEffect as useEffect33, useState as useState34 } from "react";
12851
+ import { useEffect as useEffect35, useState as useState36 } from "react";
12646
12852
  var LOADING_STATE10 = { type: "LOADING" };
12647
12853
  function useOfferDetails(offerId, options = {}) {
12648
12854
  const { coinlist, isReady } = useCoinList();
12649
12855
  const log = useLogger("useOfferDetails");
12650
12856
  const { data, enabled = true } = options;
12651
- const [offerDetailsState, setOfferDetailsState] = useState34(
12857
+ const [offerDetailsState, setOfferDetailsState] = useState36(
12652
12858
  data !== void 0 ? { type: "CONTENT", offerDetail: data } : LOADING_STATE10
12653
12859
  );
12654
- useEffect33(() => {
12860
+ useEffect35(() => {
12655
12861
  let isCancelled = false;
12656
12862
  if (!enabled) {
12657
12863
  return () => {
@@ -12728,6 +12934,7 @@ function formatMonthYear(date, locale) {
12728
12934
  }).format(date);
12729
12935
  }
12730
12936
  export {
12937
+ CENTRIFUGE_VAULT_ORDER_REASON_MESSAGES,
12731
12938
  ChecklistStatus,
12732
12939
  CheckoutAssetUi,
12733
12940
  CheckoutContainer,
@@ -12798,6 +13005,9 @@ export {
12798
13005
  USDT_ICON_URL,
12799
13006
  VerificationOverlay,
12800
13007
  authorizeWallet,
13008
+ centrifugeLoadErrorReason,
13009
+ centrifugeVaultOrderReasonMessage,
13010
+ centrifugeVaultOrderingMessage,
12801
13011
  classifyWalletError,
12802
13012
  connectExternalWalletFlow,
12803
13013
  createCoinListClient,
@@ -12817,6 +13027,7 @@ export {
12817
13027
  pinoClientLogger,
12818
13028
  prepareOndoBuy,
12819
13029
  prepareOndoSell,
13030
+ primaryCentrifugeVaultOrderReason,
12820
13031
  quoteIsStale,
12821
13032
  quoteOverAsks,
12822
13033
  stablecoinIconUrl,
@@ -12824,6 +13035,8 @@ export {
12824
13035
  tokenLogoSrcSet,
12825
13036
  tokenLogoUrl,
12826
13037
  tokenMetadataOf,
13038
+ useCentrifugeQuote,
13039
+ useCentrifugeVaultStatus,
12827
13040
  useCheckoutOfferTokenMetadata,
12828
13041
  useCoinList,
12829
13042
  useCoinListSignInCardViewModel,