@microcosmmoney/auth-react 1.5.0 → 2.0.0

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 (62) hide show
  1. package/dist/hooks/use-api-query.d.ts +3 -2
  2. package/dist/hooks/use-api-query.js +18 -9
  3. package/dist/hooks/use-auction-bid.js +3 -6
  4. package/dist/hooks/use-auction-cancel.js +3 -6
  5. package/dist/hooks/use-auction-end.js +3 -4
  6. package/dist/hooks/use-auction-history.js +3 -4
  7. package/dist/hooks/use-auction-refund.js +3 -4
  8. package/dist/hooks/use-buyback-action.js +3 -6
  9. package/dist/hooks/use-buyback-flow.js +4 -6
  10. package/dist/hooks/use-buyback-history.js +1 -0
  11. package/dist/hooks/use-buyback-quote.js +3 -4
  12. package/dist/hooks/use-create-auction.js +3 -4
  13. package/dist/hooks/use-cycle-history.js +3 -4
  14. package/dist/hooks/use-dashboard-summary.js +3 -4
  15. package/dist/hooks/use-fragment-action.js +3 -6
  16. package/dist/hooks/use-fragment-holdings.d.ts +1 -1
  17. package/dist/hooks/use-fragment-holdings.js +1 -0
  18. package/dist/hooks/use-fragment-vaults.js +1 -0
  19. package/dist/hooks/use-lending-action.js +3 -6
  20. package/dist/hooks/use-lending-loans.d.ts +1 -1
  21. package/dist/hooks/use-lending-loans.js +1 -0
  22. package/dist/hooks/use-mcc-history.js +6 -5
  23. package/dist/hooks/use-mcc-locks.js +1 -0
  24. package/dist/hooks/use-mcc.js +6 -5
  25. package/dist/hooks/use-mcd-rewards.js +1 -0
  26. package/dist/hooks/use-mcd-transactions.js +1 -0
  27. package/dist/hooks/use-mcd.js +6 -5
  28. package/dist/hooks/use-mining-action.js +4 -10
  29. package/dist/hooks/use-mining-config.js +3 -4
  30. package/dist/hooks/use-mining-flow.js +4 -6
  31. package/dist/hooks/use-mining-history.js +6 -5
  32. package/dist/hooks/use-multi-wallet-balance.js +6 -5
  33. package/dist/hooks/use-notification-action.js +4 -6
  34. package/dist/hooks/use-price-history.js +1 -0
  35. package/dist/hooks/use-profile.js +20 -21
  36. package/dist/hooks/use-proposal-settle.js +3 -4
  37. package/dist/hooks/use-public-mining.js +4 -6
  38. package/dist/hooks/use-reincarnation-config.js +3 -4
  39. package/dist/hooks/use-station-join.js +3 -4
  40. package/dist/hooks/use-station-leave.js +3 -4
  41. package/dist/hooks/use-tech-tree-action.js +4 -6
  42. package/dist/hooks/use-territory-distribution-plan.js +3 -4
  43. package/dist/hooks/use-territory-image.js +3 -4
  44. package/dist/hooks/use-territory-income.js +6 -5
  45. package/dist/hooks/use-territory-join.js +3 -4
  46. package/dist/hooks/use-territory-kpi.js +6 -5
  47. package/dist/hooks/use-territory-leave.js +3 -4
  48. package/dist/hooks/use-territory-nft-action.js +4 -6
  49. package/dist/hooks/use-territory-nft-mint.js +3 -4
  50. package/dist/hooks/use-territory-nfts.d.ts +1 -1
  51. package/dist/hooks/use-territory-nfts.js +1 -0
  52. package/dist/hooks/use-territory-ranking.js +6 -5
  53. package/dist/hooks/use-territory-update.js +4 -10
  54. package/dist/hooks/use-vote-action.js +4 -10
  55. package/dist/hooks/use-wallets.js +1 -0
  56. package/dist/index.d.ts +3 -1
  57. package/dist/index.js +8 -3
  58. package/dist/microcosm-context.d.ts +18 -0
  59. package/dist/microcosm-context.js +70 -0
  60. package/dist/provider.d.ts +1 -0
  61. package/dist/provider.js +7 -2
  62. package/package.json +2 -2
@@ -1,8 +1,9 @@
1
- interface UseApiQueryOptions {
1
+ interface UseApiQueryOptions<T = any> {
2
2
  path: string;
3
3
  requireAuth?: boolean;
4
4
  refetchInterval?: number;
5
5
  skip?: boolean;
6
+ select?: (raw: any) => T;
6
7
  }
7
8
  export interface UseApiQueryResult<T> {
8
9
  data: T | null;
@@ -10,5 +11,5 @@ export interface UseApiQueryResult<T> {
10
11
  error: Error | null;
11
12
  refresh: () => Promise<void>;
12
13
  }
13
- export declare function useApiQuery<T = any>(options: UseApiQueryOptions): UseApiQueryResult<T>;
14
+ export declare function useApiQuery<T = any>(options: UseApiQueryOptions<T>): UseApiQueryResult<T>;
14
15
  export {};
@@ -3,26 +3,35 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useApiQuery = useApiQuery;
4
4
  // AI-generated · AI-managed · AI-maintained
5
5
  const react_1 = require("react");
6
- const provider_1 = require("../provider");
6
+ const microcosm_context_1 = require("../microcosm-context");
7
7
  function useApiQuery(options) {
8
- const { client, isAuthenticated } = (0, provider_1.useAuth)();
8
+ const api = (0, microcosm_context_1.useMicrocosmApi)();
9
+ const { getAccessToken } = (0, microcosm_context_1.useMicrocosmContext)();
9
10
  const [data, setData] = (0, react_1.useState)(null);
10
11
  const [loading, setLoading] = (0, react_1.useState)(true);
11
12
  const [error, setError] = (0, react_1.useState)(null);
12
13
  const mountedRef = (0, react_1.useRef)(true);
13
- const shouldSkip = options.skip || (options.requireAuth && !isAuthenticated);
14
+ const skipRef = (0, react_1.useRef)(options.skip);
15
+ skipRef.current = options.skip;
14
16
  const fetchData = (0, react_1.useCallback)(async () => {
15
- if (shouldSkip) {
17
+ if (skipRef.current) {
16
18
  setData(null);
17
19
  setLoading(false);
18
20
  return;
19
21
  }
20
- const api = client.getApiClient();
22
+ if (options.requireAuth) {
23
+ const token = await getAccessToken();
24
+ if (!token) {
25
+ setData(null);
26
+ setLoading(false);
27
+ return;
28
+ }
29
+ }
21
30
  try {
22
31
  setLoading(true);
23
32
  const res = await api.get(options.path);
24
33
  if (mountedRef.current) {
25
- setData(res.data);
34
+ setData(options.select ? options.select(res.data) : res.data);
26
35
  setError(null);
27
36
  }
28
37
  }
@@ -35,16 +44,16 @@ function useApiQuery(options) {
35
44
  if (mountedRef.current)
36
45
  setLoading(false);
37
46
  }
38
- }, [client, options.path, shouldSkip]);
47
+ }, [api, options.path, options.requireAuth, getAccessToken]);
39
48
  (0, react_1.useEffect)(() => {
40
49
  mountedRef.current = true;
41
50
  fetchData();
42
51
  const interval = options.refetchInterval;
43
- if (interval && interval > 0 && !shouldSkip) {
52
+ if (interval && interval > 0 && !options.skip) {
44
53
  const timer = setInterval(fetchData, interval);
45
54
  return () => { mountedRef.current = false; clearInterval(timer); };
46
55
  }
47
56
  return () => { mountedRef.current = false; };
48
- }, [fetchData, options.refetchInterval, shouldSkip]);
57
+ }, [fetchData, options.refetchInterval, options.skip]);
49
58
  return { data, loading, error, refresh: fetchData };
50
59
  }
@@ -3,16 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useAuctionBid = useAuctionBid;
4
4
  // AI-generated · AI-managed · AI-maintained
5
5
  const react_1 = require("react");
6
- const provider_1 = require("../provider");
6
+ const microcosm_context_1 = require("../microcosm-context");
7
7
  function useAuctionBid() {
8
- const { client, isAuthenticated } = (0, provider_1.useAuth)();
8
+ const api = (0, microcosm_context_1.useMicrocosmApi)();
9
9
  const [loading, setLoading] = (0, react_1.useState)(false);
10
10
  const [error, setError] = (0, react_1.useState)(null);
11
11
  const mountedRef = (0, react_1.useRef)(true);
12
12
  const placeBid = (0, react_1.useCallback)(async (auctionId, bidAmount) => {
13
- if (!isAuthenticated)
14
- throw new Error('Authentication required');
15
- const api = client.getApiClient();
16
13
  try {
17
14
  setLoading(true);
18
15
  setError(null);
@@ -29,6 +26,6 @@ function useAuctionBid() {
29
26
  if (mountedRef.current)
30
27
  setLoading(false);
31
28
  }
32
- }, [client, isAuthenticated]);
29
+ }, [api]);
33
30
  return { placeBid, loading, error };
34
31
  }
@@ -3,16 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useAuctionCancel = useAuctionCancel;
4
4
  // AI-generated · AI-managed · AI-maintained
5
5
  const react_1 = require("react");
6
- const provider_1 = require("../provider");
6
+ const microcosm_context_1 = require("../microcosm-context");
7
7
  function useAuctionCancel() {
8
- const { client, isAuthenticated } = (0, provider_1.useAuth)();
8
+ const api = (0, microcosm_context_1.useMicrocosmApi)();
9
9
  const [loading, setLoading] = (0, react_1.useState)(false);
10
10
  const [error, setError] = (0, react_1.useState)(null);
11
11
  const mountedRef = (0, react_1.useRef)(true);
12
12
  const prepareCancelBid = (0, react_1.useCallback)(async (auctionId) => {
13
- if (!isAuthenticated)
14
- throw new Error('Authentication required');
15
- const api = client.getApiClient();
16
13
  try {
17
14
  setLoading(true);
18
15
  setError(null);
@@ -29,6 +26,6 @@ function useAuctionCancel() {
29
26
  if (mountedRef.current)
30
27
  setLoading(false);
31
28
  }
32
- }, [client, isAuthenticated]);
29
+ }, [api]);
33
30
  return { prepareCancelBid, loading, error };
34
31
  }
@@ -3,14 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useAuctionEnd = useAuctionEnd;
4
4
  // AI-generated · AI-managed · AI-maintained
5
5
  const react_1 = require("react");
6
- const provider_1 = require("../provider");
6
+ const microcosm_context_1 = require("../microcosm-context");
7
7
  function useAuctionEnd() {
8
- const { client } = (0, provider_1.useAuth)();
8
+ const api = (0, microcosm_context_1.useMicrocosmApi)();
9
9
  const [loading, setLoading] = (0, react_1.useState)(false);
10
10
  const [error, setError] = (0, react_1.useState)(null);
11
11
  const mountedRef = (0, react_1.useRef)(true);
12
12
  const endAuction = (0, react_1.useCallback)(async (auctionId) => {
13
- const api = client.getApiClient();
14
13
  try {
15
14
  setLoading(true);
16
15
  setError(null);
@@ -27,6 +26,6 @@ function useAuctionEnd() {
27
26
  if (mountedRef.current)
28
27
  setLoading(false);
29
28
  }
30
- }, [client]);
29
+ }, [api]);
31
30
  return { endAuction, loading, error };
32
31
  }
@@ -3,9 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useAuctionHistory = useAuctionHistory;
4
4
  // AI-generated · AI-managed · AI-maintained
5
5
  const react_1 = require("react");
6
- const provider_1 = require("../provider");
6
+ const microcosm_context_1 = require("../microcosm-context");
7
7
  function useAuctionHistory(params) {
8
- const { client } = (0, provider_1.useAuth)();
8
+ const api = (0, microcosm_context_1.useMicrocosmApi)();
9
9
  const [data, setData] = (0, react_1.useState)(null);
10
10
  const [loading, setLoading] = (0, react_1.useState)(true);
11
11
  const [error, setError] = (0, react_1.useState)(null);
@@ -14,7 +14,6 @@ function useAuctionHistory(params) {
14
14
  const page = p.page || 1;
15
15
  const pageSize = p.page_size || 20;
16
16
  const fetchData = (0, react_1.useCallback)(async () => {
17
- const api = client.getApiClient();
18
17
  try {
19
18
  setLoading(true);
20
19
  const res = await api.get(`/auction-solana/history?page=${page}&page_size=${pageSize}`);
@@ -31,7 +30,7 @@ function useAuctionHistory(params) {
31
30
  if (mountedRef.current)
32
31
  setLoading(false);
33
32
  }
34
- }, [client, page, pageSize]);
33
+ }, [api, page, pageSize]);
35
34
  (0, react_1.useEffect)(() => {
36
35
  mountedRef.current = true;
37
36
  fetchData();
@@ -3,14 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useAuctionRefund = useAuctionRefund;
4
4
  // AI-generated · AI-managed · AI-maintained
5
5
  const react_1 = require("react");
6
- const provider_1 = require("../provider");
6
+ const microcosm_context_1 = require("../microcosm-context");
7
7
  function useAuctionRefund() {
8
- const { client } = (0, provider_1.useAuth)();
8
+ const api = (0, microcosm_context_1.useMicrocosmApi)();
9
9
  const [loading, setLoading] = (0, react_1.useState)(false);
10
10
  const [error, setError] = (0, react_1.useState)(null);
11
11
  const mountedRef = (0, react_1.useRef)(true);
12
12
  const prepareRefund = (0, react_1.useCallback)(async (auctionId) => {
13
- const api = client.getApiClient();
14
13
  try {
15
14
  setLoading(true);
16
15
  setError(null);
@@ -27,6 +26,6 @@ function useAuctionRefund() {
27
26
  if (mountedRef.current)
28
27
  setLoading(false);
29
28
  }
30
- }, [client]);
29
+ }, [api]);
31
30
  return { prepareRefund, loading, error };
32
31
  }
@@ -3,16 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useBuybackAction = useBuybackAction;
4
4
  // AI-generated · AI-managed · AI-maintained
5
5
  const react_1 = require("react");
6
- const provider_1 = require("../provider");
6
+ const microcosm_context_1 = require("../microcosm-context");
7
7
  function useBuybackAction() {
8
- const { client, isAuthenticated } = (0, provider_1.useAuth)();
8
+ const api = (0, microcosm_context_1.useMicrocosmApi)();
9
9
  const [loading, setLoading] = (0, react_1.useState)(false);
10
10
  const [error, setError] = (0, react_1.useState)(null);
11
11
  const mountedRef = (0, react_1.useRef)(true);
12
12
  const record = (0, react_1.useCallback)(async (params) => {
13
- if (!isAuthenticated)
14
- throw new Error('Authentication required');
15
- const api = client.getApiClient();
16
13
  try {
17
14
  setLoading(true);
18
15
  setError(null);
@@ -29,6 +26,6 @@ function useBuybackAction() {
29
26
  if (mountedRef.current)
30
27
  setLoading(false);
31
28
  }
32
- }, [client, isAuthenticated]);
29
+ }, [api]);
33
30
  return { record, loading, error };
34
31
  }
@@ -3,9 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useBuybackFlow = useBuybackFlow;
4
4
  // AI-generated · AI-managed · AI-maintained
5
5
  const react_1 = require("react");
6
- const provider_1 = require("../provider");
6
+ const microcosm_context_1 = require("../microcosm-context");
7
7
  function useBuybackFlow() {
8
- const { client } = (0, provider_1.useAuth)();
8
+ const api = (0, microcosm_context_1.useMicrocosmApi)();
9
9
  const [state, setState] = (0, react_1.useState)({
10
10
  step: 'idle',
11
11
  quote: null,
@@ -17,7 +17,6 @@ function useBuybackFlow() {
17
17
  setState({ step: 'idle', quote: null, result: null, txSignature: null, error: null });
18
18
  }, []);
19
19
  const getQuote = (0, react_1.useCallback)(async (params) => {
20
- const api = client.getApiClient();
21
20
  setState(s => ({ ...s, step: 'quoting', error: null }));
22
21
  try {
23
22
  const q = await api.post('/mcc/buyback/quote', params);
@@ -28,9 +27,8 @@ function useBuybackFlow() {
28
27
  setState(s => ({ ...s, step: 'error', error: e.message }));
29
28
  throw e;
30
29
  }
31
- }, [client]);
30
+ }, [api]);
32
31
  const executeBuyback = (0, react_1.useCallback)(async (quoteId, txSignature) => {
33
- const api = client.getApiClient();
34
32
  setState(s => ({ ...s, step: 'signing' }));
35
33
  try {
36
34
  const res = await api.post('/mcc/buyback/execute', { quote_id: quoteId, tx_signature: txSignature });
@@ -41,6 +39,6 @@ function useBuybackFlow() {
41
39
  setState(s => ({ ...s, step: 'error', error: e.message }));
42
40
  throw e;
43
41
  }
44
- }, [client]);
42
+ }, [api]);
45
43
  return { ...state, getQuote, executeBuyback, reset };
46
44
  }
@@ -10,5 +10,6 @@ function useBuybackHistory(options) {
10
10
  path: `/reincarnation/user-history?page=${page}&page_size=${pageSize}`,
11
11
  requireAuth: true,
12
12
  refetchInterval: options?.refetchInterval ?? 0,
13
+ select: (d) => Array.isArray(d) ? d : d?.records ?? [],
13
14
  });
14
15
  }
@@ -3,9 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useBuybackQuote = useBuybackQuote;
4
4
  // AI-generated · AI-managed · AI-maintained
5
5
  const react_1 = require("react");
6
- const provider_1 = require("../provider");
6
+ const microcosm_context_1 = require("../microcosm-context");
7
7
  function useBuybackQuote(mccAmount) {
8
- const { client } = (0, provider_1.useAuth)();
8
+ const api = (0, microcosm_context_1.useMicrocosmApi)();
9
9
  const [data, setData] = (0, react_1.useState)(null);
10
10
  const [loading, setLoading] = (0, react_1.useState)(false);
11
11
  const [error, setError] = (0, react_1.useState)(null);
@@ -16,7 +16,6 @@ function useBuybackQuote(mccAmount) {
16
16
  setLoading(false);
17
17
  return;
18
18
  }
19
- const api = client.getApiClient();
20
19
  try {
21
20
  setLoading(true);
22
21
  const res = await api.post('/reincarnation/quote', { mcc_amount: mccAmount });
@@ -34,7 +33,7 @@ function useBuybackQuote(mccAmount) {
34
33
  if (mountedRef.current)
35
34
  setLoading(false);
36
35
  }
37
- }, [client, mccAmount]);
36
+ }, [api, mccAmount]);
38
37
  (0, react_1.useEffect)(() => {
39
38
  mountedRef.current = true;
40
39
  fetchQuote();
@@ -3,14 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useCreateAuction = useCreateAuction;
4
4
  // AI-generated · AI-managed · AI-maintained
5
5
  const react_1 = require("react");
6
- const provider_1 = require("../provider");
6
+ const microcosm_context_1 = require("../microcosm-context");
7
7
  function useCreateAuction() {
8
- const { client } = (0, provider_1.useAuth)();
8
+ const api = (0, microcosm_context_1.useMicrocosmApi)();
9
9
  const [loading, setLoading] = (0, react_1.useState)(false);
10
10
  const [error, setError] = (0, react_1.useState)(null);
11
11
  const mountedRef = (0, react_1.useRef)(true);
12
12
  const createAuction = (0, react_1.useCallback)(async (input) => {
13
- const api = client.getApiClient();
14
13
  try {
15
14
  setLoading(true);
16
15
  setError(null);
@@ -27,6 +26,6 @@ function useCreateAuction() {
27
26
  if (mountedRef.current)
28
27
  setLoading(false);
29
28
  }
30
- }, [client]);
29
+ }, [api]);
31
30
  return { createAuction, loading, error };
32
31
  }
@@ -3,9 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useCycleHistory = useCycleHistory;
4
4
  // AI-generated · AI-managed · AI-maintained
5
5
  const react_1 = require("react");
6
- const provider_1 = require("../provider");
6
+ const microcosm_context_1 = require("../microcosm-context");
7
7
  function useCycleHistory(params) {
8
- const { client } = (0, provider_1.useAuth)();
8
+ const api = (0, microcosm_context_1.useMicrocosmApi)();
9
9
  const [data, setData] = (0, react_1.useState)(null);
10
10
  const [loading, setLoading] = (0, react_1.useState)(true);
11
11
  const [error, setError] = (0, react_1.useState)(null);
@@ -14,7 +14,6 @@ function useCycleHistory(params) {
14
14
  const page = p.page || 1;
15
15
  const pageSize = p.page_size || 20;
16
16
  const fetchData = (0, react_1.useCallback)(async () => {
17
- const api = client.getApiClient();
18
17
  try {
19
18
  setLoading(true);
20
19
  const res = await api.get(`/reincarnation/cycle-history?page=${page}&page_size=${pageSize}`);
@@ -31,7 +30,7 @@ function useCycleHistory(params) {
31
30
  if (mountedRef.current)
32
31
  setLoading(false);
33
32
  }
34
- }, [client, page, pageSize]);
33
+ }, [api, page, pageSize]);
35
34
  (0, react_1.useEffect)(() => {
36
35
  mountedRef.current = true;
37
36
  fetchData();
@@ -3,15 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useDashboardSummary = useDashboardSummary;
4
4
  // AI-generated · AI-managed · AI-maintained
5
5
  const react_1 = require("react");
6
- const provider_1 = require("../provider");
6
+ const microcosm_context_1 = require("../microcosm-context");
7
7
  function useDashboardSummary(wallet, options) {
8
- const { client, isAuthenticated } = (0, provider_1.useAuth)();
8
+ const api = (0, microcosm_context_1.useMicrocosmApi)();
9
9
  const [data, setData] = (0, react_1.useState)(null);
10
10
  const [loading, setLoading] = (0, react_1.useState)(true);
11
11
  const [error, setError] = (0, react_1.useState)(null);
12
12
  const mountedRef = (0, react_1.useRef)(true);
13
13
  const fetchData = (0, react_1.useCallback)(async () => {
14
- const api = client.getApiClient();
15
14
  try {
16
15
  setLoading(true);
17
16
  const promises = [
@@ -38,7 +37,7 @@ function useDashboardSummary(wallet, options) {
38
37
  if (mountedRef.current)
39
38
  setLoading(false);
40
39
  }
41
- }, [client, wallet]);
40
+ }, [api, wallet]);
42
41
  (0, react_1.useEffect)(() => {
43
42
  mountedRef.current = true;
44
43
  fetchData();
@@ -3,16 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useFragmentAction = useFragmentAction;
4
4
  // AI-generated · AI-managed · AI-maintained
5
5
  const react_1 = require("react");
6
- const provider_1 = require("../provider");
6
+ const microcosm_context_1 = require("../microcosm-context");
7
7
  function useFragmentAction() {
8
- const { client, isAuthenticated } = (0, provider_1.useAuth)();
8
+ const api = (0, microcosm_context_1.useMicrocosmApi)();
9
9
  const [loading, setLoading] = (0, react_1.useState)(false);
10
10
  const [error, setError] = (0, react_1.useState)(null);
11
11
  const mountedRef = (0, react_1.useRef)(true);
12
12
  const exec = (0, react_1.useCallback)(async (path, params) => {
13
- if (!isAuthenticated)
14
- throw new Error('Authentication required');
15
- const api = client.getApiClient();
16
13
  try {
17
14
  setLoading(true);
18
15
  setError(null);
@@ -29,7 +26,7 @@ function useFragmentAction() {
29
26
  if (mountedRef.current)
30
27
  setLoading(false);
31
28
  }
32
- }, [client, isAuthenticated]);
29
+ }, [api]);
33
30
  const buy = (0, react_1.useCallback)((params) => exec('/fragment/buy/prepare', params), [exec]);
34
31
  const fragmentize = (0, react_1.useCallback)((params) => exec('/fragment/fragmentize/prepare', params), [exec]);
35
32
  const redeem = (0, react_1.useCallback)((params) => exec('/fragment/redeem/prepare', params), [exec]);
@@ -1,3 +1,3 @@
1
1
  export declare function useFragmentHoldings(wallet?: string, options?: {
2
2
  refetchInterval?: number;
3
- }): import("./use-api-query").UseApiQueryResult<any>;
3
+ }): import("./use-api-query").UseApiQueryResult<any[]>;
@@ -9,5 +9,6 @@ function useFragmentHoldings(wallet, options) {
9
9
  requireAuth: false,
10
10
  skip: !wallet,
11
11
  refetchInterval: options?.refetchInterval ?? 0,
12
+ select: (d) => Array.isArray(d) ? d : d?.holdings ?? [],
12
13
  });
13
14
  }
@@ -7,5 +7,6 @@ function useFragmentVaults(options) {
7
7
  return (0, use_api_query_1.useApiQuery)({
8
8
  path: '/fragment/vaults',
9
9
  refetchInterval: options?.refetchInterval ?? 120000,
10
+ select: (d) => Array.isArray(d) ? d : d?.vaults ?? [],
10
11
  });
11
12
  }
@@ -3,16 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useLendingAction = useLendingAction;
4
4
  // AI-generated · AI-managed · AI-maintained
5
5
  const react_1 = require("react");
6
- const provider_1 = require("../provider");
6
+ const microcosm_context_1 = require("../microcosm-context");
7
7
  function useLendingAction() {
8
- const { client, isAuthenticated } = (0, provider_1.useAuth)();
8
+ const api = (0, microcosm_context_1.useMicrocosmApi)();
9
9
  const [loading, setLoading] = (0, react_1.useState)(false);
10
10
  const [error, setError] = (0, react_1.useState)(null);
11
11
  const mountedRef = (0, react_1.useRef)(true);
12
12
  const exec = (0, react_1.useCallback)(async (path, params) => {
13
- if (!isAuthenticated)
14
- throw new Error('Authentication required');
15
- const api = client.getApiClient();
16
13
  try {
17
14
  setLoading(true);
18
15
  setError(null);
@@ -29,7 +26,7 @@ function useLendingAction() {
29
26
  if (mountedRef.current)
30
27
  setLoading(false);
31
28
  }
32
- }, [client, isAuthenticated]);
29
+ }, [api]);
33
30
  const deposit = (0, react_1.useCallback)((params) => exec('/lending/deposit/prepare', params), [exec]);
34
31
  const withdraw = (0, react_1.useCallback)((params) => exec('/lending/withdraw/prepare', params), [exec]);
35
32
  const borrow = (0, react_1.useCallback)((params) => exec('/lending/borrow/prepare', params), [exec]);
@@ -1,3 +1,3 @@
1
1
  export declare function useLendingLoans(wallet?: string, options?: {
2
2
  refetchInterval?: number;
3
- }): import("./use-api-query").UseApiQueryResult<any>;
3
+ }): import("./use-api-query").UseApiQueryResult<any[]>;
@@ -9,5 +9,6 @@ function useLendingLoans(wallet, options) {
9
9
  requireAuth: false,
10
10
  skip: !wallet,
11
11
  refetchInterval: options?.refetchInterval ?? 0,
12
+ select: (d) => Array.isArray(d) ? d : d?.loans ?? [],
12
13
  });
13
14
  }
@@ -3,9 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useMCCHistory = useMCCHistory;
4
4
  // AI-generated · AI-managed · AI-maintained
5
5
  const react_1 = require("react");
6
- const provider_1 = require("../provider");
6
+ const microcosm_context_1 = require("../microcosm-context");
7
7
  function useMCCHistory(params) {
8
- const { client, isAuthenticated } = (0, provider_1.useAuth)();
8
+ const api = (0, microcosm_context_1.useMicrocosmApi)();
9
+ const { getAccessToken } = (0, microcosm_context_1.useMicrocosmContext)();
9
10
  const [data, setData] = (0, react_1.useState)(null);
10
11
  const [loading, setLoading] = (0, react_1.useState)(true);
11
12
  const [error, setError] = (0, react_1.useState)(null);
@@ -15,12 +16,12 @@ function useMCCHistory(params) {
15
16
  const pageSize = p.page_size || 20;
16
17
  const txType = p.tx_type;
17
18
  const fetchData = (0, react_1.useCallback)(async () => {
18
- if (!isAuthenticated) {
19
+ const _token = await getAccessToken();
20
+ if (!_token) {
19
21
  setData(null);
20
22
  setLoading(false);
21
23
  return;
22
24
  }
23
- const api = client.getApiClient();
24
25
  try {
25
26
  setLoading(true);
26
27
  let qs = `?page=${page}&page_size=${pageSize}`;
@@ -40,7 +41,7 @@ function useMCCHistory(params) {
40
41
  if (mountedRef.current)
41
42
  setLoading(false);
42
43
  }
43
- }, [client, isAuthenticated, page, pageSize, txType]);
44
+ }, [api, getAccessToken, page, pageSize, txType]);
44
45
  (0, react_1.useEffect)(() => {
45
46
  mountedRef.current = true;
46
47
  fetchData();
@@ -8,5 +8,6 @@ function useMCCLocks(options) {
8
8
  path: '/mcc/locks',
9
9
  requireAuth: true,
10
10
  refetchInterval: options?.refetchInterval ?? 0,
11
+ select: (d) => Array.isArray(d) ? d : d?.locks ?? [],
11
12
  });
12
13
  }
@@ -3,21 +3,22 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useMCC = useMCC;
4
4
  // AI-generated · AI-managed · AI-maintained
5
5
  const react_1 = require("react");
6
- const provider_1 = require("../provider");
6
+ const microcosm_context_1 = require("../microcosm-context");
7
7
  function useMCC(refreshInterval) {
8
- const { client, isAuthenticated } = (0, provider_1.useAuth)();
8
+ const api = (0, microcosm_context_1.useMicrocosmApi)();
9
+ const { getAccessToken } = (0, microcosm_context_1.useMicrocosmContext)();
9
10
  const [balance, setBalance] = (0, react_1.useState)(null);
10
11
  const [price, setPrice] = (0, react_1.useState)(null);
11
12
  const [loading, setLoading] = (0, react_1.useState)(true);
12
13
  const [error, setError] = (0, react_1.useState)(null);
13
14
  const fetchData = (0, react_1.useCallback)(async () => {
14
- const api = client.getApiClient();
15
15
  try {
16
16
  setLoading(true);
17
17
  const pricePromise = api.get('/mcc/price')
18
18
  .then(res => setPrice(res.data))
19
19
  .catch(() => { });
20
- if (isAuthenticated) {
20
+ const token = await getAccessToken();
21
+ if (token) {
21
22
  const balancePromise = api.get('/mcc/balance')
22
23
  .then(res => setBalance(res.data))
23
24
  .catch(() => { });
@@ -35,7 +36,7 @@ function useMCC(refreshInterval) {
35
36
  finally {
36
37
  setLoading(false);
37
38
  }
38
- }, [client, isAuthenticated]);
39
+ }, [api, getAccessToken]);
39
40
  (0, react_1.useEffect)(() => {
40
41
  fetchData();
41
42
  if (refreshInterval && refreshInterval > 0) {
@@ -15,5 +15,6 @@ function useMCDRewards(options) {
15
15
  path: `/mcd/rewards${qs}`,
16
16
  requireAuth: true,
17
17
  refetchInterval: options?.refetchInterval ?? 0,
18
+ select: (d) => Array.isArray(d) ? d : d?.records ?? [],
18
19
  });
19
20
  }
@@ -13,5 +13,6 @@ function useMCDTransactions(options) {
13
13
  path: `/mcd/transactions${qs}`,
14
14
  requireAuth: true,
15
15
  refetchInterval: options?.refetchInterval ?? 0,
16
+ select: (d) => Array.isArray(d) ? d : d?.records ?? [],
16
17
  });
17
18
  }
@@ -3,21 +3,22 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useMCD = useMCD;
4
4
  // AI-generated · AI-managed · AI-maintained
5
5
  const react_1 = require("react");
6
- const provider_1 = require("../provider");
6
+ const microcosm_context_1 = require("../microcosm-context");
7
7
  function useMCD(refreshInterval) {
8
- const { client, isAuthenticated } = (0, provider_1.useAuth)();
8
+ const api = (0, microcosm_context_1.useMicrocosmApi)();
9
+ const { getAccessToken } = (0, microcosm_context_1.useMicrocosmContext)();
9
10
  const [balance, setBalance] = (0, react_1.useState)(null);
10
11
  const [loading, setLoading] = (0, react_1.useState)(true);
11
12
  const [error, setError] = (0, react_1.useState)(null);
12
13
  const fetchBalance = (0, react_1.useCallback)(async () => {
13
- if (!isAuthenticated) {
14
+ const _token = await getAccessToken();
15
+ if (!_token) {
14
16
  setBalance(null);
15
17
  setLoading(false);
16
18
  return;
17
19
  }
18
20
  try {
19
21
  setLoading(true);
20
- const api = client.getApiClient();
21
22
  const data = await api.get('/mcd/balance');
22
23
  setBalance(data.data || null);
23
24
  setError(null);
@@ -28,7 +29,7 @@ function useMCD(refreshInterval) {
28
29
  finally {
29
30
  setLoading(false);
30
31
  }
31
- }, [client, isAuthenticated]);
32
+ }, [api, getAccessToken]);
32
33
  (0, react_1.useEffect)(() => {
33
34
  fetchBalance();
34
35
  if (refreshInterval && refreshInterval > 0) {