@meddleware/dao-ui 0.1.5 → 0.1.6
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/package.json +1 -1
- package/src/composables/useGates.ts +44 -19
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ref, onMounted } from 'vue'
|
|
2
2
|
import { getSuiClient } from '../wallet.js'
|
|
3
|
-
import { PACKAGE_ID } from '../config.js'
|
|
3
|
+
import { PACKAGE_ID, CONFIG_ID } from '../config.js'
|
|
4
4
|
|
|
5
5
|
export interface Gate {
|
|
6
6
|
id: string
|
|
@@ -8,7 +8,6 @@ export interface Gate {
|
|
|
8
8
|
price: bigint
|
|
9
9
|
paused: boolean
|
|
10
10
|
frozen: boolean
|
|
11
|
-
txDigest: string
|
|
12
11
|
checkpoint: string | null
|
|
13
12
|
}
|
|
14
13
|
|
|
@@ -18,28 +17,54 @@ export function useGates() {
|
|
|
18
17
|
const error = ref<string | null>(null)
|
|
19
18
|
|
|
20
19
|
async function load() {
|
|
21
|
-
if (!PACKAGE_ID) return
|
|
20
|
+
if (!PACKAGE_ID || !CONFIG_ID) return
|
|
22
21
|
loading.value = true
|
|
23
22
|
error.value = null
|
|
24
23
|
try {
|
|
25
24
|
const client = getSuiClient()
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
25
|
+
|
|
26
|
+
// Get treasury address from PlatformConfig so we know whose AdminCaps to look for.
|
|
27
|
+
// This is resilient to event pruning (the GateCreatedEvent is pruned on testnet
|
|
28
|
+
// after ~3 months, making event-based discovery unreliable).
|
|
29
|
+
const configRes = await client.getObject({ objectId: CONFIG_ID, include: { json: true } })
|
|
30
|
+
const configFields = configRes.object?.json as Record<string, unknown> | null
|
|
31
|
+
const treasury = configFields?.treasury as string | undefined
|
|
32
|
+
if (!treasury) {
|
|
33
|
+
gates.value = []
|
|
34
|
+
return
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// List AdminCap objects owned by treasury — one per gate the treasury controls.
|
|
38
|
+
const { objects } = await client.listOwnedObjects({
|
|
39
|
+
owner: treasury,
|
|
40
|
+
type: `${PACKAGE_ID}::access_gate::AdminCap`,
|
|
41
|
+
include: { json: true },
|
|
42
42
|
})
|
|
43
|
+
|
|
44
|
+
// Fetch each Gate shared object referenced by the AdminCap's gate_id.
|
|
45
|
+
const gateList = await Promise.all(
|
|
46
|
+
(objects ?? []).map(async (o: any): Promise<Gate | null> => {
|
|
47
|
+
const capFields = o?.json ?? o?.object?.json
|
|
48
|
+
const gateId = String(capFields?.gate_id ?? '')
|
|
49
|
+
if (!gateId || gateId === 'undefined') return null
|
|
50
|
+
try {
|
|
51
|
+
const gateRes = await client.getObject({ objectId: gateId, include: { json: true } })
|
|
52
|
+
const f = gateRes.object?.json as Record<string, unknown> | null
|
|
53
|
+
if (!f) return null
|
|
54
|
+
return {
|
|
55
|
+
id: gateId,
|
|
56
|
+
name: String(f.nft_name ?? 'Unnamed Gate'),
|
|
57
|
+
price: BigInt(String(f.price_mist ?? '0')),
|
|
58
|
+
paused: Boolean(f.paused),
|
|
59
|
+
frozen: Boolean(f.frozen),
|
|
60
|
+
checkpoint: null,
|
|
61
|
+
}
|
|
62
|
+
} catch {
|
|
63
|
+
return null
|
|
64
|
+
}
|
|
65
|
+
}),
|
|
66
|
+
)
|
|
67
|
+
gates.value = gateList.filter((g): g is Gate => g !== null)
|
|
43
68
|
} catch (e) {
|
|
44
69
|
error.value = e instanceof Error ? e.message : String(e)
|
|
45
70
|
} finally {
|