Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions example-apps/dashnote/src/dash/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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);
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions example-apps/dashnote/src/dash/createNote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -27,6 +26,7 @@ export async function createNote({
}: CreateNoteParams): Promise<string> {
log?.("Creating note…");
const { identity, identityKey, signer } = await keyManager.getAuth();
const { Document } = await loadSdkModule();
const trimmedTitle = title?.trim();
const document = new Document({
properties: {
Expand Down
17 changes: 17 additions & 0 deletions example-apps/dashnote/src/dash/sdkModule.ts
Original file line number Diff line number Diff line change
@@ -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<SdkModule> | null = null;

export function loadSdkModule(): Promise<SdkModule> {
if (!sdkModulePromise) {
sdkModulePromise = import("@dashevo/evo-sdk").catch((err) => {
sdkModulePromise = null;
throw err;
});
}
return sdkModulePromise;
}
4 changes: 2 additions & 2 deletions example-apps/dashnote/src/dash/updateNote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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({
Expand Down