@zing-protocol/zing-sdk 0.1.4 → 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/dist/client/index.d.ts +3 -0
- package/dist/client/index.js +27 -0
- package/dist/getters.js +17 -12
- package/dist/stores/index.d.ts +1 -0
- package/dist/stores/index.js +1 -0
- package/dist/stores/uploadStore.d.ts +29 -0
- package/dist/stores/uploadStore.js +39 -0
- package/package.json +1 -1
package/dist/client/index.d.ts
CHANGED
|
@@ -24,6 +24,8 @@ export declare class ZingClient {
|
|
|
24
24
|
getDerivedWorksID(address: string): string;
|
|
25
25
|
getDerivedMembershipID(address: string): string;
|
|
26
26
|
getReferralID(address: string): string;
|
|
27
|
+
getIsActiveStudio(owner: string): Promise<boolean>;
|
|
28
|
+
getIsStudioOwner(owner: string, studioId: string): boolean;
|
|
27
29
|
getStudio(owner: string): Promise<{
|
|
28
30
|
id: string;
|
|
29
31
|
owner: string;
|
|
@@ -229,6 +231,7 @@ export declare class ZingClient {
|
|
|
229
231
|
}[];
|
|
230
232
|
};
|
|
231
233
|
}[]>;
|
|
234
|
+
getIsWorkOwner(owner: string, workId: string): Promise<boolean>;
|
|
232
235
|
getBalance(owner: string, coinSymbol: CoinSymbol): Promise<import("node_modules/@mysten/sui/dist/grpc/proto/sui/rpc/v2/state_service.mjs").GetBalanceResponse>;
|
|
233
236
|
getSessionKey(saltServerUrl: string, signer: ZKLoginSignerState, owner: string): Promise<SessionKey | null>;
|
|
234
237
|
buildSealApproveTransactionBytes(owner: string): Promise<Uint8Array<ArrayBuffer>>;
|
package/dist/client/index.js
CHANGED
|
@@ -8,6 +8,7 @@ import { getDerivedMembershipID, getDerivedStorageID, getDerivedStudioID, getDer
|
|
|
8
8
|
import { importFileKey } from "../mutations/seal.js";
|
|
9
9
|
import { signPersonalMessage } from "../mutations/signer.js";
|
|
10
10
|
import { SessionKey } from "@mysten/seal";
|
|
11
|
+
import { bcs } from "@mysten/sui/bcs";
|
|
11
12
|
import { Transaction, coinWithBalance } from "@mysten/sui/transactions";
|
|
12
13
|
import { fromHex } from "@mysten/sui/utils";
|
|
13
14
|
export class ZingClient {
|
|
@@ -36,6 +37,17 @@ export class ZingClient {
|
|
|
36
37
|
getReferralID(address) {
|
|
37
38
|
return getReferralID(this.config.zing.ZING_STUDIO_CONFIG_SHARED_OBJECT_REF.objectId, address);
|
|
38
39
|
}
|
|
40
|
+
async getIsActiveStudio(owner) {
|
|
41
|
+
const studio = await this.getStudio(owner);
|
|
42
|
+
const now = new Date();
|
|
43
|
+
if (!studio)
|
|
44
|
+
return false;
|
|
45
|
+
return (now.getTime() >= Number(studio.period[0]) &&
|
|
46
|
+
now.getTime() < Number(studio.period[1]));
|
|
47
|
+
}
|
|
48
|
+
getIsStudioOwner(owner, studioId) {
|
|
49
|
+
return this.getDerivedStudioID(owner) == studioId;
|
|
50
|
+
}
|
|
39
51
|
async getStudio(owner) {
|
|
40
52
|
return getStudio(this.suiGrpcClient, this.getDerivedStudioID(owner));
|
|
41
53
|
}
|
|
@@ -63,6 +75,21 @@ export class ZingClient {
|
|
|
63
75
|
async getWorksByObjectIds(owner, workObjectIds, workType) {
|
|
64
76
|
return getWorksByObjectIds(this.suiGrpcClient, workObjectIds, workType ? this.config.zing.ZING_WORKS_TYPE[workType] : undefined);
|
|
65
77
|
}
|
|
78
|
+
async getIsWorkOwner(owner, workId) {
|
|
79
|
+
try {
|
|
80
|
+
await this.suiGrpcClient.core.getDynamicObjectField({
|
|
81
|
+
parentId: this.getDerivedWorksID(owner),
|
|
82
|
+
name: {
|
|
83
|
+
type: "0x2::object::ID",
|
|
84
|
+
bcs: bcs.Address.serialize(workId).toBytes(),
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
catch {
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
66
93
|
async getBalance(owner, coinSymbol) {
|
|
67
94
|
return this.suiGrpcClient.stateService
|
|
68
95
|
.getBalance({
|
package/dist/getters.js
CHANGED
|
@@ -200,20 +200,25 @@ export async function getMembers(suiGrpcClient, membershipTableId, cursor, limit
|
|
|
200
200
|
};
|
|
201
201
|
}
|
|
202
202
|
export async function getReferral(suiGrpcClient, referralID) {
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
203
|
+
try {
|
|
204
|
+
const res = await suiGrpcClient.ledgerService.getObject({
|
|
205
|
+
objectId: referralID,
|
|
206
|
+
readMask: {
|
|
207
|
+
paths: ["bcs"],
|
|
208
|
+
},
|
|
209
|
+
});
|
|
210
|
+
if (!res.response.object?.bcs?.value) {
|
|
211
|
+
return null;
|
|
212
|
+
}
|
|
213
|
+
const suiMoveObject = bcs.Object.parse(res.response.object.bcs.value);
|
|
214
|
+
if (suiMoveObject.data.$kind === "Package")
|
|
215
|
+
throw new Error("Move Object is Package");
|
|
216
|
+
const field = Field(bcs.vector(bcs.u8()), Referral).parse(suiMoveObject.data.Move.contents);
|
|
217
|
+
return field.value;
|
|
218
|
+
}
|
|
219
|
+
catch {
|
|
210
220
|
return null;
|
|
211
221
|
}
|
|
212
|
-
const suiMoveObject = bcs.Object.parse(res.response.object.bcs.value);
|
|
213
|
-
if (suiMoveObject.data.$kind === "Package")
|
|
214
|
-
throw new Error("Move Object is Package");
|
|
215
|
-
const field = Field(bcs.vector(bcs.u8()), Referral).parse(suiMoveObject.data.Move.contents);
|
|
216
|
-
return field.value;
|
|
217
222
|
}
|
|
218
223
|
export async function getWork(suiGrpcClient, workId, workType) {
|
|
219
224
|
const res = await suiGrpcClient.ledgerService.getObject({
|
package/dist/stores/index.d.ts
CHANGED
package/dist/stores/index.js
CHANGED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { PublishArticleEvent } from "../_generated/zing_studio/article.js";
|
|
2
|
+
import type { WalrusUploadFlowStage } from "../config/common.js";
|
|
3
|
+
type UploadJobType = "post";
|
|
4
|
+
type UploadJobStatus = "uploading" | "success" | "error";
|
|
5
|
+
interface UploadJob {
|
|
6
|
+
id: string;
|
|
7
|
+
type: UploadJobType;
|
|
8
|
+
status: UploadJobStatus;
|
|
9
|
+
progress: number;
|
|
10
|
+
stage?: WalrusUploadFlowStage | "Downloading";
|
|
11
|
+
toastId: string | number;
|
|
12
|
+
error?: string;
|
|
13
|
+
startedAt: number;
|
|
14
|
+
completedAt?: number;
|
|
15
|
+
studioId: string;
|
|
16
|
+
articleData?: typeof PublishArticleEvent.$inferType;
|
|
17
|
+
}
|
|
18
|
+
interface UploadStore {
|
|
19
|
+
jobs: UploadJob[];
|
|
20
|
+
addJob: (job: Omit<UploadJob, "startedAt">) => void;
|
|
21
|
+
updateJob: (id: string, updates: Partial<UploadJob>) => void;
|
|
22
|
+
removeJob: (id: string) => void;
|
|
23
|
+
clearCompleted: () => void;
|
|
24
|
+
getJob: (id: string) => UploadJob | undefined;
|
|
25
|
+
getActiveJobs: () => UploadJob[];
|
|
26
|
+
}
|
|
27
|
+
export declare const useUploadStore: import("zustand").UseBoundStore<import("zustand").StoreApi<UploadStore>>;
|
|
28
|
+
export declare const uploadActions: UploadStore;
|
|
29
|
+
export type { UploadJob, UploadJobStatus, UploadJobType, UploadStore };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { create } from "zustand";
|
|
2
|
+
// Create the Zustand store using the standard React-compatible `create` function
|
|
3
|
+
const useUploadStoreBase = create((set, get) => ({
|
|
4
|
+
jobs: [],
|
|
5
|
+
addJob(job) {
|
|
6
|
+
const newJob = {
|
|
7
|
+
...job,
|
|
8
|
+
startedAt: Date.now(),
|
|
9
|
+
};
|
|
10
|
+
set((state) => ({
|
|
11
|
+
jobs: [...state.jobs, newJob],
|
|
12
|
+
}));
|
|
13
|
+
},
|
|
14
|
+
updateJob(id, updates) {
|
|
15
|
+
set((state) => ({
|
|
16
|
+
jobs: state.jobs.map((j) => (j.id === id ? { ...j, ...updates } : j)),
|
|
17
|
+
}));
|
|
18
|
+
},
|
|
19
|
+
removeJob(id) {
|
|
20
|
+
set((state) => ({
|
|
21
|
+
jobs: state.jobs.filter((j) => j.id !== id),
|
|
22
|
+
}));
|
|
23
|
+
},
|
|
24
|
+
clearCompleted() {
|
|
25
|
+
set((state) => ({
|
|
26
|
+
jobs: state.jobs.filter((j) => j.status === "uploading" || j.status === "error"),
|
|
27
|
+
}));
|
|
28
|
+
},
|
|
29
|
+
getJob(id) {
|
|
30
|
+
return get().jobs.find((j) => j.id === id);
|
|
31
|
+
},
|
|
32
|
+
getActiveJobs() {
|
|
33
|
+
return get().jobs.filter((j) => j.status === "uploading");
|
|
34
|
+
},
|
|
35
|
+
}));
|
|
36
|
+
// Export the hook as the default export (React-compatible)
|
|
37
|
+
export const useUploadStore = useUploadStoreBase;
|
|
38
|
+
// Export actions for non-React usage (these access the store directly)
|
|
39
|
+
export const uploadActions = useUploadStoreBase.getState();
|