diff --git a/example-apps/dashnote/src/dash/contract.ts b/example-apps/dashnote/src/dash/contract.ts index 7e7be7c..8fba063 100644 --- a/example-apps/dashnote/src/dash/contract.ts +++ b/example-apps/dashnote/src/dash/contract.ts @@ -5,9 +5,8 @@ * sdk.contracts.publish({ dataContract, identityKey, signer }) * sdk.identities.nonce(identityId) */ -import { DataContract, Identifier } from "@dashevo/evo-sdk"; - import type { Logger } from "../lib/logger"; +import { loadSdkModule } from "./sdkModule"; import type { DashKeyManager, DashSdk } from "./types"; export const NOTE_SCHEMAS = { @@ -78,6 +77,7 @@ export async function refreshContractCache({ if (!contractId || typeof sdk.getWasmSdkConnected !== "function") return; const wasm = await sdk.getWasmSdkConnected(); if (!wasm || typeof wasm.removeCachedContract !== "function") return; + const { Identifier } = await loadSdkModule(); const identifier = new Identifier(contractId); try { wasm.removeCachedContract(identifier); @@ -98,6 +98,7 @@ export async function registerContract({ log?.("Registering Dashnote note contract…"); const { identity, identityKey, signer } = await keyManager.getAuth(); const identityNonce = await sdk.identities.nonce(identity.id.toString()); + const { DataContract } = await loadSdkModule(); const dataContract = new DataContract({ ownerId: identity.id, identityNonce: (identityNonce || 0n) + 1n, diff --git a/example-apps/dashnote/src/dash/createNote.ts b/example-apps/dashnote/src/dash/createNote.ts index fb2af0e..e5516f4 100644 --- a/example-apps/dashnote/src/dash/createNote.ts +++ b/example-apps/dashnote/src/dash/createNote.ts @@ -3,9 +3,8 @@ * * SDK method: sdk.documents.create({ document, identityKey, signer }) */ -import { Document } from "@dashevo/evo-sdk"; - import type { Logger } from "../lib/logger"; +import { loadSdkModule } from "./sdkModule"; import type { DashKeyManager, DashSdk } from "./types"; export interface CreateNoteParams { @@ -27,6 +26,7 @@ export async function createNote({ }: CreateNoteParams): Promise { log?.("Creating note…"); const { identity, identityKey, signer } = await keyManager.getAuth(); + const { Document } = await loadSdkModule(); const trimmedTitle = title?.trim(); const document = new Document({ properties: { diff --git a/example-apps/dashnote/src/dash/sdkModule.ts b/example-apps/dashnote/src/dash/sdkModule.ts new file mode 100644 index 0000000..5cab25b --- /dev/null +++ b/example-apps/dashnote/src/dash/sdkModule.ts @@ -0,0 +1,17 @@ +// Defer the @dashevo/evo-sdk value import so it doesn't anchor the SDK chunk +// to the entry graph via files statically imported by SessionContext / +// LoginModal / NotesWorkspace. Cached after first call; cleared on failure +// so a transient chunk fetch can retry. +export type SdkModule = typeof import("@dashevo/evo-sdk"); + +let sdkModulePromise: Promise | null = null; + +export function loadSdkModule(): Promise { + if (!sdkModulePromise) { + sdkModulePromise = import("@dashevo/evo-sdk").catch((err) => { + sdkModulePromise = null; + throw err; + }); + } + return sdkModulePromise; +} diff --git a/example-apps/dashnote/src/dash/updateNote.ts b/example-apps/dashnote/src/dash/updateNote.ts index 7a227e0..1e4556f 100644 --- a/example-apps/dashnote/src/dash/updateNote.ts +++ b/example-apps/dashnote/src/dash/updateNote.ts @@ -6,9 +6,8 @@ * sdk.documents.get(contractId, documentTypeName, documentId) * sdk.documents.replace({ document, identityKey, signer }) */ -import { Document } from "@dashevo/evo-sdk"; - import type { Logger } from "../lib/logger"; +import { loadSdkModule } from "./sdkModule"; import type { DashKeyManager, DashSdk } from "./types"; export interface UpdateNoteParams { @@ -37,6 +36,7 @@ export async function updateNote({ throw new Error(`Note ${noteId} not found.`); } + const { Document } = await loadSdkModule(); const revision = BigInt(existingDoc.revision ?? 0) + 1n; const trimmedTitle = title?.trim(); const document = new Document({