@microcosmmoney/auth-react 1.5.1 → 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 (48) hide show
  1. package/dist/hooks/use-api-query.js +17 -8
  2. package/dist/hooks/use-auction-bid.js +3 -6
  3. package/dist/hooks/use-auction-cancel.js +3 -6
  4. package/dist/hooks/use-auction-end.js +3 -4
  5. package/dist/hooks/use-auction-history.js +3 -4
  6. package/dist/hooks/use-auction-refund.js +3 -4
  7. package/dist/hooks/use-buyback-action.js +3 -6
  8. package/dist/hooks/use-buyback-flow.js +4 -6
  9. package/dist/hooks/use-buyback-quote.js +3 -4
  10. package/dist/hooks/use-create-auction.js +3 -4
  11. package/dist/hooks/use-cycle-history.js +3 -4
  12. package/dist/hooks/use-dashboard-summary.js +3 -4
  13. package/dist/hooks/use-fragment-action.js +3 -6
  14. package/dist/hooks/use-lending-action.js +3 -6
  15. package/dist/hooks/use-mcc-history.js +6 -5
  16. package/dist/hooks/use-mcc.js +6 -5
  17. package/dist/hooks/use-mcd.js +6 -5
  18. package/dist/hooks/use-mining-action.js +4 -10
  19. package/dist/hooks/use-mining-config.js +3 -4
  20. package/dist/hooks/use-mining-flow.js +4 -6
  21. package/dist/hooks/use-mining-history.js +6 -5
  22. package/dist/hooks/use-multi-wallet-balance.js +6 -5
  23. package/dist/hooks/use-notification-action.js +4 -6
  24. package/dist/hooks/use-profile.js +20 -21
  25. package/dist/hooks/use-proposal-settle.js +3 -4
  26. package/dist/hooks/use-public-mining.js +4 -6
  27. package/dist/hooks/use-reincarnation-config.js +3 -4
  28. package/dist/hooks/use-station-join.js +3 -4
  29. package/dist/hooks/use-station-leave.js +3 -4
  30. package/dist/hooks/use-tech-tree-action.js +4 -6
  31. package/dist/hooks/use-territory-distribution-plan.js +3 -4
  32. package/dist/hooks/use-territory-image.js +3 -4
  33. package/dist/hooks/use-territory-income.js +6 -5
  34. package/dist/hooks/use-territory-join.js +3 -4
  35. package/dist/hooks/use-territory-kpi.js +6 -5
  36. package/dist/hooks/use-territory-leave.js +3 -4
  37. package/dist/hooks/use-territory-nft-action.js +4 -6
  38. package/dist/hooks/use-territory-nft-mint.js +3 -4
  39. package/dist/hooks/use-territory-ranking.js +6 -5
  40. package/dist/hooks/use-territory-update.js +4 -10
  41. package/dist/hooks/use-vote-action.js +4 -10
  42. package/dist/index.d.ts +3 -1
  43. package/dist/index.js +8 -3
  44. package/dist/microcosm-context.d.ts +18 -0
  45. package/dist/microcosm-context.js +70 -0
  46. package/dist/provider.d.ts +1 -0
  47. package/dist/provider.js +7 -2
  48. package/package.json +2 -2
@@ -3,9 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useMiningHistory = useMiningHistory;
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 useMiningHistory(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);
@@ -14,12 +15,12 @@ function useMiningHistory(params) {
14
15
  const limit = p.limit || 20;
15
16
  const offset = p.offset || 0;
16
17
  const fetchData = (0, react_1.useCallback)(async () => {
17
- if (!isAuthenticated) {
18
+ const _token = await getAccessToken();
19
+ if (!_token) {
18
20
  setData(null);
19
21
  setLoading(false);
20
22
  return;
21
23
  }
22
- const api = client.getApiClient();
23
24
  try {
24
25
  setLoading(true);
25
26
  const res = await api.get(`/mining/history?limit=${limit}&offset=${offset}`);
@@ -36,7 +37,7 @@ function useMiningHistory(params) {
36
37
  if (mountedRef.current)
37
38
  setLoading(false);
38
39
  }
39
- }, [client, isAuthenticated, limit, offset]);
40
+ }, [api, getAccessToken, limit, offset]);
40
41
  (0, react_1.useEffect)(() => {
41
42
  mountedRef.current = true;
42
43
  fetchData();
@@ -3,20 +3,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useMultiWalletBalance = useMultiWalletBalance;
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 useMultiWalletBalance(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
14
  const fetchData = (0, react_1.useCallback)(async () => {
14
- if (!isAuthenticated) {
15
+ const _token = await getAccessToken();
16
+ if (!_token) {
15
17
  setData(null);
16
18
  setLoading(false);
17
19
  return;
18
20
  }
19
- const api = client.getApiClient();
20
21
  try {
21
22
  setLoading(true);
22
23
  const walletsRes = await api.get('/wallets');
@@ -38,7 +39,7 @@ function useMultiWalletBalance(options) {
38
39
  if (mountedRef.current)
39
40
  setLoading(false);
40
41
  }
41
- }, [client, isAuthenticated]);
42
+ }, [api, getAccessToken]);
42
43
  (0, react_1.useEffect)(() => {
43
44
  mountedRef.current = true;
44
45
  fetchData();
@@ -3,14 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useNotificationAction = useNotificationAction;
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 useNotificationAction() {
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 markRead = (0, react_1.useCallback)(async (notificationId) => {
13
- const api = client.getApiClient();
14
13
  try {
15
14
  setLoading(true);
16
15
  setError(null);
@@ -26,9 +25,8 @@ function useNotificationAction() {
26
25
  if (mountedRef.current)
27
26
  setLoading(false);
28
27
  }
29
- }, [client]);
28
+ }, [api]);
30
29
  const markAllRead = (0, react_1.useCallback)(async () => {
31
- const api = client.getApiClient();
32
30
  try {
33
31
  setLoading(true);
34
32
  setError(null);
@@ -44,6 +42,6 @@ function useNotificationAction() {
44
42
  if (mountedRef.current)
45
43
  setLoading(false);
46
44
  }
47
- }, [client]);
45
+ }, [api]);
48
46
  return { markRead, markAllRead, loading, error };
49
47
  }
@@ -3,21 +3,30 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useProfile = useProfile;
4
4
  // AI-generated · AI-managed · AI-maintained
5
5
  const react_1 = require("react");
6
+ const microcosm_context_1 = require("../microcosm-context");
6
7
  const provider_1 = require("../provider");
7
8
  function useProfile() {
8
- const { user, client, isAuthenticated } = (0, provider_1.useAuth)();
9
+ const api = (0, microcosm_context_1.useMicrocosmApi)();
10
+ const { getAccessToken } = (0, microcosm_context_1.useMicrocosmContext)();
11
+ const authCtx = (0, provider_1.useAuthOptional)();
12
+ const user = authCtx?.user ?? null;
9
13
  const [profile, setProfile] = (0, react_1.useState)(user);
10
14
  const [loading, setLoading] = (0, react_1.useState)(false);
11
15
  const [error, setError] = (0, react_1.useState)(null);
12
16
  (0, react_1.useEffect)(() => {
13
17
  setProfile(user);
14
18
  }, [user]);
19
+ const syncUser = (0, react_1.useCallback)((updated) => {
20
+ setProfile(updated);
21
+ if (authCtx?.client)
22
+ authCtx.client.setUser(updated);
23
+ }, [authCtx]);
15
24
  const refresh = (0, react_1.useCallback)(async () => {
16
- if (!isAuthenticated)
25
+ const token = await getAccessToken();
26
+ if (!token)
17
27
  return;
18
28
  try {
19
29
  setLoading(true);
20
- const api = client.getApiClient();
21
30
  const data = await api.get('/users/me/profile');
22
31
  const raw = data.user || data;
23
32
  const updated = {
@@ -30,8 +39,7 @@ function useProfile() {
30
39
  title: raw.title,
31
40
  stationId: raw.station_id || null,
32
41
  };
33
- setProfile(updated);
34
- client.setUser(updated);
42
+ syncUser(updated);
35
43
  setError(null);
36
44
  }
37
45
  catch (err) {
@@ -40,18 +48,13 @@ function useProfile() {
40
48
  finally {
41
49
  setLoading(false);
42
50
  }
43
- }, [client, isAuthenticated, profile]);
51
+ }, [api, getAccessToken, syncUser, profile]);
44
52
  const updateProfile = (0, react_1.useCallback)(async (data) => {
45
- if (!isAuthenticated)
46
- throw new Error('Not authenticated');
47
53
  try {
48
54
  setLoading(true);
49
- const api = client.getApiClient();
50
55
  await api.patch('/users/me/profile', data);
51
56
  if (profile && data.display_name !== undefined) {
52
- const updated = { ...profile, displayName: data.display_name };
53
- setProfile(updated);
54
- client.setUser(updated);
57
+ syncUser({ ...profile, displayName: data.display_name });
55
58
  }
56
59
  setError(null);
57
60
  }
@@ -63,18 +66,16 @@ function useProfile() {
63
66
  finally {
64
67
  setLoading(false);
65
68
  }
66
- }, [client, isAuthenticated, profile]);
69
+ }, [api, syncUser, profile]);
67
70
  const uploadAvatar = (0, react_1.useCallback)(async (file) => {
68
- if (!isAuthenticated)
69
- throw new Error('Not authenticated');
70
71
  try {
71
72
  setLoading(true);
72
- const token = await client.getAccessToken();
73
+ const token = await getAccessToken();
73
74
  const formData = new FormData();
74
75
  formData.append('avatar', file);
75
76
  const response = await fetch('https://api.microcosm.money/v1/users/me/avatar', {
76
77
  method: 'POST',
77
- headers: { Authorization: `Bearer ${token}` },
78
+ headers: token ? { Authorization: `Bearer ${token}` } : {},
78
79
  body: formData,
79
80
  });
80
81
  if (!response.ok)
@@ -82,9 +83,7 @@ function useProfile() {
82
83
  const data = await response.json();
83
84
  const avatarUrl = data.avatar_url || null;
84
85
  if (profile && avatarUrl) {
85
- const updated = { ...profile, avatarUrl };
86
- setProfile(updated);
87
- client.setUser(updated);
86
+ syncUser({ ...profile, avatarUrl });
88
87
  }
89
88
  setError(null);
90
89
  return avatarUrl;
@@ -97,6 +96,6 @@ function useProfile() {
97
96
  finally {
98
97
  setLoading(false);
99
98
  }
100
- }, [client, isAuthenticated, profile]);
99
+ }, [getAccessToken, syncUser, profile]);
101
100
  return { profile, loading, error, updateProfile, uploadAvatar, refresh };
102
101
  }
@@ -3,14 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useProposalSettle = useProposalSettle;
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 useProposalSettle() {
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 settle = (0, react_1.useCallback)(async (proposalId) => {
13
- const api = client.getApiClient();
14
13
  try {
15
14
  setLoading(true);
16
15
  setError(null);
@@ -27,6 +26,6 @@ function useProposalSettle() {
27
26
  if (mountedRef.current)
28
27
  setLoading(false);
29
28
  }
30
- }, [client]);
29
+ }, [api]);
31
30
  return { settle, loading, error };
32
31
  }
@@ -3,14 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.usePublicMining = usePublicMining;
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 usePublicMining() {
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 createRequest = (0, react_1.useCallback)(async (params) => {
13
- const api = client.getApiClient();
14
13
  try {
15
14
  setLoading(true);
16
15
  setError(null);
@@ -27,9 +26,8 @@ function usePublicMining() {
27
26
  if (mountedRef.current)
28
27
  setLoading(false);
29
28
  }
30
- }, [client]);
29
+ }, [api]);
31
30
  const verify = (0, react_1.useCallback)(async (requestId, txSignature) => {
32
- const api = client.getApiClient();
33
31
  try {
34
32
  setLoading(true);
35
33
  setError(null);
@@ -49,6 +47,6 @@ function usePublicMining() {
49
47
  if (mountedRef.current)
50
48
  setLoading(false);
51
49
  }
52
- }, [client]);
50
+ }, [api]);
53
51
  return { createRequest, verify, loading, error };
54
52
  }
@@ -3,15 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useReincarnationConfig = useReincarnationConfig;
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 useReincarnationConfig() {
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);
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 res = await api.get('/reincarnation/config');
@@ -28,7 +27,7 @@ function useReincarnationConfig() {
28
27
  if (mountedRef.current)
29
28
  setLoading(false);
30
29
  }
31
- }, [client]);
30
+ }, [api]);
32
31
  (0, react_1.useEffect)(() => {
33
32
  mountedRef.current = true;
34
33
  fetchData();
@@ -3,14 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useStationJoin = useStationJoin;
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 useStationJoin() {
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 joinStation = (0, react_1.useCallback)(async (stationId) => {
13
- const api = client.getApiClient();
14
13
  try {
15
14
  setLoading(true);
16
15
  setError(null);
@@ -27,6 +26,6 @@ function useStationJoin() {
27
26
  if (mountedRef.current)
28
27
  setLoading(false);
29
28
  }
30
- }, [client]);
29
+ }, [api]);
31
30
  return { joinStation, loading, error };
32
31
  }
@@ -3,14 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useStationLeave = useStationLeave;
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 useStationLeave() {
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 leaveStation = (0, react_1.useCallback)(async (stationId) => {
13
- const api = client.getApiClient();
14
13
  try {
15
14
  setLoading(true);
16
15
  setError(null);
@@ -27,6 +26,6 @@ function useStationLeave() {
27
26
  if (mountedRef.current)
28
27
  setLoading(false);
29
28
  }
30
- }, [client]);
29
+ }, [api]);
31
30
  return { leaveStation, loading, error };
32
31
  }
@@ -3,14 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useTechTreeAction = useTechTreeAction;
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 useTechTreeAction() {
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 unlock = (0, react_1.useCallback)(async (nodeId) => {
13
- const api = client.getApiClient();
14
13
  try {
15
14
  setLoading(true);
16
15
  setError(null);
@@ -27,9 +26,8 @@ function useTechTreeAction() {
27
26
  if (mountedRef.current)
28
27
  setLoading(false);
29
28
  }
30
- }, [client]);
29
+ }, [api]);
31
30
  const upgrade = (0, react_1.useCallback)(async (nodeId) => {
32
- const api = client.getApiClient();
33
31
  try {
34
32
  setLoading(true);
35
33
  setError(null);
@@ -46,6 +44,6 @@ function useTechTreeAction() {
46
44
  if (mountedRef.current)
47
45
  setLoading(false);
48
46
  }
49
- }, [client]);
47
+ }, [api]);
50
48
  return { unlock, upgrade, loading, error };
51
49
  }
@@ -3,10 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useTerritoryDistributionPlan = useTerritoryDistributionPlan;
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
  const use_api_query_1 = require("./use-api-query");
8
8
  function useTerritoryDistributionPlan(territoryId) {
9
- const { client } = (0, provider_1.useAuth)();
9
+ const api = (0, microcosm_context_1.useMicrocosmApi)();
10
10
  const [updating, setUpdating] = (0, react_1.useState)(false);
11
11
  const [updateError, setUpdateError] = (0, react_1.useState)(null);
12
12
  const mountedRef = (0, react_1.useRef)(true);
@@ -18,7 +18,6 @@ function useTerritoryDistributionPlan(territoryId) {
18
18
  const updatePlan = (0, react_1.useCallback)(async (plan) => {
19
19
  if (!territoryId)
20
20
  return;
21
- const api = client.getApiClient();
22
21
  try {
23
22
  setUpdating(true);
24
23
  setUpdateError(null);
@@ -36,6 +35,6 @@ function useTerritoryDistributionPlan(territoryId) {
36
35
  if (mountedRef.current)
37
36
  setUpdating(false);
38
37
  }
39
- }, [client, territoryId, query]);
38
+ }, [api, territoryId, query]);
40
39
  return { ...query, updatePlan, updating, updateError };
41
40
  }
@@ -3,14 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useTerritoryImage = useTerritoryImage;
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 useTerritoryImage() {
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 uploadImage = (0, react_1.useCallback)(async (territoryId, imageUrl) => {
13
- const api = client.getApiClient();
14
13
  try {
15
14
  setLoading(true);
16
15
  setError(null);
@@ -27,6 +26,6 @@ function useTerritoryImage() {
27
26
  if (mountedRef.current)
28
27
  setLoading(false);
29
28
  }
30
- }, [client]);
29
+ }, [api]);
31
30
  return { uploadImage, loading, error };
32
31
  }
@@ -3,20 +3,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useTerritoryIncome = useTerritoryIncome;
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 useTerritoryIncome(territoryId, period = '30d') {
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
14
  const fetchData = (0, react_1.useCallback)(async () => {
14
- if (!isAuthenticated || !territoryId) {
15
+ const _token = await getAccessToken();
16
+ if (!_token || !territoryId) {
15
17
  setData(null);
16
18
  setLoading(false);
17
19
  return;
18
20
  }
19
- const api = client.getApiClient();
20
21
  try {
21
22
  setLoading(true);
22
23
  const res = await api.get(`/territories/${territoryId}/income-chart?period=${period}`);
@@ -33,7 +34,7 @@ function useTerritoryIncome(territoryId, period = '30d') {
33
34
  if (mountedRef.current)
34
35
  setLoading(false);
35
36
  }
36
- }, [client, isAuthenticated, territoryId, period]);
37
+ }, [api, getAccessToken, territoryId, period]);
37
38
  (0, react_1.useEffect)(() => {
38
39
  mountedRef.current = true;
39
40
  fetchData();
@@ -3,14 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useTerritoryJoin = useTerritoryJoin;
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 useTerritoryJoin() {
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 joinTerritory = (0, react_1.useCallback)(async (territoryId) => {
13
- const api = client.getApiClient();
14
13
  try {
15
14
  setLoading(true);
16
15
  setError(null);
@@ -27,6 +26,6 @@ function useTerritoryJoin() {
27
26
  if (mountedRef.current)
28
27
  setLoading(false);
29
28
  }
30
- }, [client]);
29
+ }, [api]);
31
30
  return { joinTerritory, loading, error };
32
31
  }
@@ -3,20 +3,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useTerritoryKPI = useTerritoryKPI;
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 useTerritoryKPI(territoryId) {
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
14
  const fetchData = (0, react_1.useCallback)(async () => {
14
- if (!isAuthenticated || !territoryId) {
15
+ const _token = await getAccessToken();
16
+ if (!_token || !territoryId) {
15
17
  setData(null);
16
18
  setLoading(false);
17
19
  return;
18
20
  }
19
- const api = client.getApiClient();
20
21
  try {
21
22
  setLoading(true);
22
23
  const res = await api.get(`/territories/${territoryId}/kpi-history`);
@@ -33,7 +34,7 @@ function useTerritoryKPI(territoryId) {
33
34
  if (mountedRef.current)
34
35
  setLoading(false);
35
36
  }
36
- }, [client, isAuthenticated, territoryId]);
37
+ }, [api, getAccessToken, territoryId]);
37
38
  (0, react_1.useEffect)(() => {
38
39
  mountedRef.current = true;
39
40
  fetchData();
@@ -3,14 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useTerritoryLeave = useTerritoryLeave;
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 useTerritoryLeave() {
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 leaveTerritory = (0, react_1.useCallback)(async (territoryId) => {
13
- const api = client.getApiClient();
14
13
  try {
15
14
  setLoading(true);
16
15
  setError(null);
@@ -27,6 +26,6 @@ function useTerritoryLeave() {
27
26
  if (mountedRef.current)
28
27
  setLoading(false);
29
28
  }
30
- }, [client]);
29
+ }, [api]);
31
30
  return { leaveTerritory, loading, error };
32
31
  }
@@ -3,14 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useTerritoryNFTAction = useTerritoryNFTAction;
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 useTerritoryNFTAction() {
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 transferNFT = (0, react_1.useCallback)(async (params) => {
13
- const api = client.getApiClient();
14
13
  try {
15
14
  setLoading(true);
16
15
  setError(null);
@@ -27,9 +26,8 @@ function useTerritoryNFTAction() {
27
26
  if (mountedRef.current)
28
27
  setLoading(false);
29
28
  }
30
- }, [client]);
29
+ }, [api]);
31
30
  const burnNFT = (0, react_1.useCallback)(async (params) => {
32
- const api = client.getApiClient();
33
31
  try {
34
32
  setLoading(true);
35
33
  setError(null);
@@ -46,6 +44,6 @@ function useTerritoryNFTAction() {
46
44
  if (mountedRef.current)
47
45
  setLoading(false);
48
46
  }
49
- }, [client]);
47
+ }, [api]);
50
48
  return { transferNFT, burnNFT, loading, error };
51
49
  }
@@ -3,14 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useTerritoryNFTMint = useTerritoryNFTMint;
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 useTerritoryNFTMint() {
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 mint = (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 useTerritoryNFTMint() {
27
26
  if (mountedRef.current)
28
27
  setLoading(false);
29
28
  }
30
- }, [client]);
29
+ }, [api]);
31
30
  return { mint, loading, error };
32
31
  }