@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.
- package/dist/hooks/use-api-query.js +17 -8
- package/dist/hooks/use-auction-bid.js +3 -6
- package/dist/hooks/use-auction-cancel.js +3 -6
- package/dist/hooks/use-auction-end.js +3 -4
- package/dist/hooks/use-auction-history.js +3 -4
- package/dist/hooks/use-auction-refund.js +3 -4
- package/dist/hooks/use-buyback-action.js +3 -6
- package/dist/hooks/use-buyback-flow.js +4 -6
- package/dist/hooks/use-buyback-quote.js +3 -4
- package/dist/hooks/use-create-auction.js +3 -4
- package/dist/hooks/use-cycle-history.js +3 -4
- package/dist/hooks/use-dashboard-summary.js +3 -4
- package/dist/hooks/use-fragment-action.js +3 -6
- package/dist/hooks/use-lending-action.js +3 -6
- package/dist/hooks/use-mcc-history.js +6 -5
- package/dist/hooks/use-mcc.js +6 -5
- package/dist/hooks/use-mcd.js +6 -5
- package/dist/hooks/use-mining-action.js +4 -10
- package/dist/hooks/use-mining-config.js +3 -4
- package/dist/hooks/use-mining-flow.js +4 -6
- package/dist/hooks/use-mining-history.js +6 -5
- package/dist/hooks/use-multi-wallet-balance.js +6 -5
- package/dist/hooks/use-notification-action.js +4 -6
- package/dist/hooks/use-profile.js +20 -21
- package/dist/hooks/use-proposal-settle.js +3 -4
- package/dist/hooks/use-public-mining.js +4 -6
- package/dist/hooks/use-reincarnation-config.js +3 -4
- package/dist/hooks/use-station-join.js +3 -4
- package/dist/hooks/use-station-leave.js +3 -4
- package/dist/hooks/use-tech-tree-action.js +4 -6
- package/dist/hooks/use-territory-distribution-plan.js +3 -4
- package/dist/hooks/use-territory-image.js +3 -4
- package/dist/hooks/use-territory-income.js +6 -5
- package/dist/hooks/use-territory-join.js +3 -4
- package/dist/hooks/use-territory-kpi.js +6 -5
- package/dist/hooks/use-territory-leave.js +3 -4
- package/dist/hooks/use-territory-nft-action.js +4 -6
- package/dist/hooks/use-territory-nft-mint.js +3 -4
- package/dist/hooks/use-territory-ranking.js +6 -5
- package/dist/hooks/use-territory-update.js +4 -10
- package/dist/hooks/use-vote-action.js +4 -10
- package/dist/index.d.ts +3 -1
- package/dist/index.js +8 -3
- package/dist/microcosm-context.d.ts +18 -0
- package/dist/microcosm-context.js +70 -0
- package/dist/provider.d.ts +1 -0
- package/dist/provider.js +7 -2
- package/package.json +2 -2
|
@@ -3,21 +3,30 @@ 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
|
|
6
|
+
const microcosm_context_1 = require("../microcosm-context");
|
|
7
7
|
function useApiQuery(options) {
|
|
8
|
-
const
|
|
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
|
|
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 (
|
|
17
|
+
if (skipRef.current) {
|
|
16
18
|
setData(null);
|
|
17
19
|
setLoading(false);
|
|
18
20
|
return;
|
|
19
21
|
}
|
|
20
|
-
|
|
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);
|
|
@@ -35,16 +44,16 @@ function useApiQuery(options) {
|
|
|
35
44
|
if (mountedRef.current)
|
|
36
45
|
setLoading(false);
|
|
37
46
|
}
|
|
38
|
-
}, [
|
|
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 && !
|
|
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,
|
|
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
|
|
6
|
+
const microcosm_context_1 = require("../microcosm-context");
|
|
7
7
|
function useAuctionBid() {
|
|
8
|
-
const
|
|
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
|
-
}, [
|
|
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
|
|
6
|
+
const microcosm_context_1 = require("../microcosm-context");
|
|
7
7
|
function useAuctionCancel() {
|
|
8
|
-
const
|
|
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
|
-
}, [
|
|
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
|
|
6
|
+
const microcosm_context_1 = require("../microcosm-context");
|
|
7
7
|
function useAuctionEnd() {
|
|
8
|
-
const
|
|
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
|
-
}, [
|
|
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
|
|
6
|
+
const microcosm_context_1 = require("../microcosm-context");
|
|
7
7
|
function useAuctionHistory(params) {
|
|
8
|
-
const
|
|
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
|
-
}, [
|
|
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
|
|
6
|
+
const microcosm_context_1 = require("../microcosm-context");
|
|
7
7
|
function useAuctionRefund() {
|
|
8
|
-
const
|
|
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
|
-
}, [
|
|
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
|
|
6
|
+
const microcosm_context_1 = require("../microcosm-context");
|
|
7
7
|
function useBuybackAction() {
|
|
8
|
-
const
|
|
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
|
-
}, [
|
|
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
|
|
6
|
+
const microcosm_context_1 = require("../microcosm-context");
|
|
7
7
|
function useBuybackFlow() {
|
|
8
|
-
const
|
|
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
|
-
}, [
|
|
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
|
-
}, [
|
|
42
|
+
}, [api]);
|
|
45
43
|
return { ...state, getQuote, executeBuyback, reset };
|
|
46
44
|
}
|
|
@@ -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
|
|
6
|
+
const microcosm_context_1 = require("../microcosm-context");
|
|
7
7
|
function useBuybackQuote(mccAmount) {
|
|
8
|
-
const
|
|
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
|
-
}, [
|
|
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
|
|
6
|
+
const microcosm_context_1 = require("../microcosm-context");
|
|
7
7
|
function useCreateAuction() {
|
|
8
|
-
const
|
|
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
|
-
}, [
|
|
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
|
|
6
|
+
const microcosm_context_1 = require("../microcosm-context");
|
|
7
7
|
function useCycleHistory(params) {
|
|
8
|
-
const
|
|
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
|
-
}, [
|
|
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
|
|
6
|
+
const microcosm_context_1 = require("../microcosm-context");
|
|
7
7
|
function useDashboardSummary(wallet, options) {
|
|
8
|
-
const
|
|
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
|
-
}, [
|
|
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
|
|
6
|
+
const microcosm_context_1 = require("../microcosm-context");
|
|
7
7
|
function useFragmentAction() {
|
|
8
|
-
const
|
|
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
|
-
}, [
|
|
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]);
|
|
@@ -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
|
|
6
|
+
const microcosm_context_1 = require("../microcosm-context");
|
|
7
7
|
function useLendingAction() {
|
|
8
|
-
const
|
|
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
|
-
}, [
|
|
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]);
|
|
@@ -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
|
|
6
|
+
const microcosm_context_1 = require("../microcosm-context");
|
|
7
7
|
function useMCCHistory(params) {
|
|
8
|
-
const
|
|
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
|
-
|
|
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
|
-
}, [
|
|
44
|
+
}, [api, getAccessToken, page, pageSize, txType]);
|
|
44
45
|
(0, react_1.useEffect)(() => {
|
|
45
46
|
mountedRef.current = true;
|
|
46
47
|
fetchData();
|
package/dist/hooks/use-mcc.js
CHANGED
|
@@ -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
|
|
6
|
+
const microcosm_context_1 = require("../microcosm-context");
|
|
7
7
|
function useMCC(refreshInterval) {
|
|
8
|
-
const
|
|
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
|
-
|
|
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
|
-
}, [
|
|
39
|
+
}, [api, getAccessToken]);
|
|
39
40
|
(0, react_1.useEffect)(() => {
|
|
40
41
|
fetchData();
|
|
41
42
|
if (refreshInterval && refreshInterval > 0) {
|
package/dist/hooks/use-mcd.js
CHANGED
|
@@ -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
|
|
6
|
+
const microcosm_context_1 = require("../microcosm-context");
|
|
7
7
|
function useMCD(refreshInterval) {
|
|
8
|
-
const
|
|
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
|
-
|
|
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
|
-
}, [
|
|
32
|
+
}, [api, getAccessToken]);
|
|
32
33
|
(0, react_1.useEffect)(() => {
|
|
33
34
|
fetchBalance();
|
|
34
35
|
if (refreshInterval && refreshInterval > 0) {
|
|
@@ -3,16 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.useMiningAction = useMiningAction;
|
|
4
4
|
// AI-generated · AI-managed · AI-maintained
|
|
5
5
|
const react_1 = require("react");
|
|
6
|
-
const
|
|
6
|
+
const microcosm_context_1 = require("../microcosm-context");
|
|
7
7
|
function useMiningAction() {
|
|
8
|
-
const
|
|
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
|
-
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,11 +26,8 @@ function useMiningAction() {
|
|
|
29
26
|
if (mountedRef.current)
|
|
30
27
|
setLoading(false);
|
|
31
28
|
}
|
|
32
|
-
}, [
|
|
29
|
+
}, [api]);
|
|
33
30
|
const confirm = (0, react_1.useCallback)(async (params) => {
|
|
34
|
-
if (!isAuthenticated)
|
|
35
|
-
throw new Error('Authentication required');
|
|
36
|
-
const api = client.getApiClient();
|
|
37
31
|
try {
|
|
38
32
|
setLoading(true);
|
|
39
33
|
setError(null);
|
|
@@ -50,6 +44,6 @@ function useMiningAction() {
|
|
|
50
44
|
if (mountedRef.current)
|
|
51
45
|
setLoading(false);
|
|
52
46
|
}
|
|
53
|
-
}, [
|
|
47
|
+
}, [api]);
|
|
54
48
|
return { createRequest, confirm, loading, error };
|
|
55
49
|
}
|
|
@@ -3,15 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.useMiningConfig = useMiningConfig;
|
|
4
4
|
// AI-generated · AI-managed · AI-maintained
|
|
5
5
|
const react_1 = require("react");
|
|
6
|
-
const
|
|
6
|
+
const microcosm_context_1 = require("../microcosm-context");
|
|
7
7
|
function useMiningConfig() {
|
|
8
|
-
const
|
|
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('/mining/config');
|
|
@@ -28,7 +27,7 @@ function useMiningConfig() {
|
|
|
28
27
|
if (mountedRef.current)
|
|
29
28
|
setLoading(false);
|
|
30
29
|
}
|
|
31
|
-
}, [
|
|
30
|
+
}, [api]);
|
|
32
31
|
(0, react_1.useEffect)(() => {
|
|
33
32
|
mountedRef.current = true;
|
|
34
33
|
fetchData();
|
|
@@ -3,9 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.useMiningFlow = useMiningFlow;
|
|
4
4
|
// AI-generated · AI-managed · AI-maintained
|
|
5
5
|
const react_1 = require("react");
|
|
6
|
-
const
|
|
6
|
+
const microcosm_context_1 = require("../microcosm-context");
|
|
7
7
|
function useMiningFlow() {
|
|
8
|
-
const
|
|
8
|
+
const api = (0, microcosm_context_1.useMicrocosmApi)();
|
|
9
9
|
const [state, setState] = (0, react_1.useState)({
|
|
10
10
|
step: 'idle',
|
|
11
11
|
requestData: null,
|
|
@@ -17,7 +17,6 @@ function useMiningFlow() {
|
|
|
17
17
|
setState({ step: 'idle', requestData: null, confirmData: null, txSignature: null, error: null });
|
|
18
18
|
}, []);
|
|
19
19
|
const startMining = (0, react_1.useCallback)(async (params) => {
|
|
20
|
-
const api = client.getApiClient();
|
|
21
20
|
setState(s => ({ ...s, step: 'requesting', error: null }));
|
|
22
21
|
try {
|
|
23
22
|
const req = await api.post('/mcc/mining/request', params);
|
|
@@ -28,9 +27,8 @@ function useMiningFlow() {
|
|
|
28
27
|
setState(s => ({ ...s, step: 'error', error: e.message }));
|
|
29
28
|
throw e;
|
|
30
29
|
}
|
|
31
|
-
}, [
|
|
30
|
+
}, [api]);
|
|
32
31
|
const confirmMining = (0, react_1.useCallback)(async (requestId, txSignature) => {
|
|
33
|
-
const api = client.getApiClient();
|
|
34
32
|
setState(s => ({ ...s, step: 'signing' }));
|
|
35
33
|
try {
|
|
36
34
|
const res = await api.post('/mcc/mining/confirm', { request_id: requestId, tx_signature: txSignature });
|
|
@@ -41,6 +39,6 @@ function useMiningFlow() {
|
|
|
41
39
|
setState(s => ({ ...s, step: 'error', error: e.message }));
|
|
42
40
|
throw e;
|
|
43
41
|
}
|
|
44
|
-
}, [
|
|
42
|
+
}, [api]);
|
|
45
43
|
return { ...state, startMining, confirmMining, reset };
|
|
46
44
|
}
|