Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
21 changes: 19 additions & 2 deletions example-apps/dashnote/src/dash/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,26 @@
* sdk.contracts.publish({ dataContract, identityKey, signer })
* sdk.identities.nonce(identityId)
*/
import { DataContract, Identifier } from "@dashevo/evo-sdk";

import type { Logger } from "../lib/logger";
import type { DashKeyManager, DashSdk } from "./types";

// Defer the @dashevo/evo-sdk value import so it doesn't anchor the SDK chunk
// to the entry graph via SessionContext + LoginModal's static imports of this
// file. Synchronous exports below (NOTE_SCHEMAS, loadStoredContractId, etc.)
// don't touch the SDK and stay sync because SessionContext calls them during
// initial render. Cached after first call; cleared on failure for retry.
type SdkModule = typeof import("@dashevo/evo-sdk");
let sdkModulePromise: Promise<SdkModule> | null = null;
function loadSdkModule(): Promise<SdkModule> {
if (!sdkModulePromise) {
sdkModulePromise = import("@dashevo/evo-sdk").catch((err) => {
sdkModulePromise = null;
throw err;
});
}
return sdkModulePromise;
}

export const NOTE_SCHEMAS = {
note: {
type: "object",
Expand Down Expand Up @@ -78,6 +93,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 +114,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
18 changes: 16 additions & 2 deletions example-apps/dashnote/src/dash/createNote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,24 @@
*
* SDK method: sdk.documents.create({ document, identityKey, signer })
*/
import { Document } from "@dashevo/evo-sdk";

import type { Logger } from "../lib/logger";
import type { DashKeyManager, DashSdk } from "./types";

// Defer the @dashevo/evo-sdk value import so it doesn't anchor the SDK chunk
// to the entry graph via NotesWorkspace's static import of this file. Cached
// after first call; cleared on failure so a transient chunk fetch can retry.
type SdkModule = typeof import("@dashevo/evo-sdk");
let sdkModulePromise: Promise<SdkModule> | null = null;
function loadSdkModule(): Promise<SdkModule> {
if (!sdkModulePromise) {
sdkModulePromise = import("@dashevo/evo-sdk").catch((err) => {
sdkModulePromise = null;
throw err;
});
}
return sdkModulePromise;
}

export interface CreateNoteParams {
sdk: DashSdk;
keyManager: DashKeyManager;
Expand All @@ -27,6 +40,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
18 changes: 16 additions & 2 deletions example-apps/dashnote/src/dash/updateNote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,24 @@
* 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 type { DashKeyManager, DashSdk } from "./types";

// Defer the @dashevo/evo-sdk value import so it doesn't anchor the SDK chunk
// to the entry graph via NotesWorkspace's static import of this file. Cached
// after first call; cleared on failure so a transient chunk fetch can retry.
type SdkModule = typeof import("@dashevo/evo-sdk");
let sdkModulePromise: Promise<SdkModule> | null = null;
function loadSdkModule(): Promise<SdkModule> {
if (!sdkModulePromise) {
sdkModulePromise = import("@dashevo/evo-sdk").catch((err) => {
sdkModulePromise = null;
throw err;
});
}
return sdkModulePromise;
}

export interface UpdateNoteParams {
sdk: DashSdk;
keyManager: DashKeyManager;
Expand All @@ -37,6 +50,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