|
1 | 1 | /** |
2 | | - * NFT card data contract schema + ensureContract(). |
| 2 | + * NFT card data contract schema + registerContract / ensureContract. |
3 | 3 | * |
4 | 4 | * WHAT: A Dash Platform "data contract" defines the schema for documents. |
5 | 5 | * This one describes a single document type (`card`) with four fields |
|
11 | 11 | * tradeMode: 1 — documents can be priced and purchased (0 to disable) |
12 | 12 | * creationRestrictionMode: 1 — (1 - only the contract owner can mint; 0 - anyone can mint) |
13 | 13 | * |
| 14 | + * Storage helpers (loadStoredContractId, saveContractId, …) and the owner |
| 15 | + * lookup live in contractStorage.ts so they can be imported without |
| 16 | + * pulling the @dashevo/evo-sdk runtime into the entry bundle. |
| 17 | + * |
14 | 18 | * SDK methods: new DataContract({ ... }), sdk.contracts.publish(...) |
15 | 19 | */ |
16 | 20 | import { DataContract } from "@dashevo/evo-sdk"; |
17 | 21 |
|
| 22 | +import { loadStoredContractId, saveContractId } from "./contractStorage"; |
18 | 23 | import type { Logger } from "./logger"; |
19 | 24 | import type { DashKeyManager, DashSdk } from "./types"; |
20 | 25 |
|
| 26 | +export { |
| 27 | + DEFAULT_CONTRACT_ID, |
| 28 | + clearStoredContractId, |
| 29 | + fetchContractOwnerId, |
| 30 | + loadStoredContractId, |
| 31 | + saveContractId, |
| 32 | +} from "./contractStorage"; |
| 33 | + |
21 | 34 | export const CARD_SCHEMAS = { |
22 | 35 | card: { |
23 | 36 | type: "object", |
@@ -62,49 +75,6 @@ export const CARD_SCHEMAS = { |
62 | 75 | }, |
63 | 76 | } as const; |
64 | 77 |
|
65 | | -/** |
66 | | - * Fetch the owner identity ID for a given data contract. |
67 | | - * |
68 | | - * SDK method: sdk.contracts.fetch(...) |
69 | | - */ |
70 | | -export async function fetchContractOwnerId({ |
71 | | - sdk, |
72 | | - contractId, |
73 | | -}: { |
74 | | - sdk: DashSdk; |
75 | | - contractId: string; |
76 | | -}): Promise<string | null> { |
77 | | - const contract = await sdk.contracts.fetch(contractId); |
78 | | - if (!contract) return null; |
79 | | - const json = |
80 | | - typeof contract.toJSON === "function" ? contract.toJSON() : contract; |
81 | | - const ownerId = json.$ownerId ?? json.ownerId ?? null; |
82 | | - return ownerId ? String(ownerId) : null; |
83 | | -} |
84 | | - |
85 | | -const STORAGE_KEY = "dashmint-lab.contractId"; |
86 | | - |
87 | | -/** |
88 | | - * Default contract ID baked into the tutorial so browse-only mode works |
89 | | - * on a fresh machine without any setup. Comes from the original |
90 | | - * HTML tutorial's pre-deployed testnet contract. Users can override it |
91 | | - * in the Settings modal or register their own. |
92 | | - */ |
93 | | -export const DEFAULT_CONTRACT_ID = |
94 | | - "4eJR4pgV9mQdyoodfTTwFUp3SYBRJbUrJ5X1ViN2zBhY"; |
95 | | - |
96 | | -export function loadStoredContractId(): string | null { |
97 | | - return localStorage.getItem(STORAGE_KEY) ?? DEFAULT_CONTRACT_ID; |
98 | | -} |
99 | | - |
100 | | -export function saveContractId(id: string): void { |
101 | | - localStorage.setItem(STORAGE_KEY, id); |
102 | | -} |
103 | | - |
104 | | -export function clearStoredContractId(): void { |
105 | | - localStorage.removeItem(STORAGE_KEY); |
106 | | -} |
107 | | - |
108 | 78 | /** |
109 | 79 | * Register a fresh NFT card data contract on Platform and persist its ID. |
110 | 80 | * |
|
0 commit comments