@zing-protocol/zing-sdk 0.1.1 → 0.1.3

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.
@@ -4,7 +4,7 @@ export declare const PLATFORMS: readonly ["twitter"];
4
4
  export type PlatformType = (typeof PLATFORMS)[number];
5
5
  export declare const WORKS: readonly ["article"];
6
6
  export type WorkType = (typeof WORKS)[number];
7
- export declare const COIN_SYMBOLS: readonly ["USDC"];
7
+ export declare const COIN_SYMBOLS: readonly ["USDC", "WAL"];
8
8
  export type CoinSymbol = (typeof COIN_SYMBOLS)[number];
9
9
  export declare const AUTH_PROVIDER_ICON_PATH: Record<AuthProvider, string>;
10
10
  export declare const WALRUS_UPLOAD_FLOW_STAGES: readonly ["encode", "register_blob", "upload", "certify_blob", "publish"];
@@ -1,7 +1,7 @@
1
1
  export const AUTH_PROVIDDERS = ["Google"];
2
2
  export const PLATFORMS = ["twitter"];
3
3
  export const WORKS = ["article"];
4
- export const COIN_SYMBOLS = ["USDC"];
4
+ export const COIN_SYMBOLS = ["USDC", "WAL"];
5
5
  export const AUTH_PROVIDER_ICON_PATH = {
6
6
  Google: "icons/google.svg",
7
7
  };
@@ -14,4 +14,5 @@ export const WALRUS_UPLOAD_FLOW_STAGES = [
14
14
  ];
15
15
  export const COIN_DECIMALS = {
16
16
  USDC: 6,
17
+ WAL: 9,
17
18
  };
@@ -42,6 +42,7 @@ export const mainnetWalrusConfig = {
42
42
  // coins
43
43
  export const mainnetCoinConfig = {
44
44
  USDC: "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC",
45
+ WAL: "0x356a26eb9e012a68958082340d4c4116e7f55615cf27affcff209cf0ae544f59::wal::WAL",
45
46
  };
46
47
  // seal
47
48
  export const mainnetSealConfig = {
@@ -43,6 +43,7 @@ export const testnetWalrusConfig = {
43
43
  // coins
44
44
  export const testnetCoinConfig = {
45
45
  USDC: "0xa1ec7fc00a6f40db9693ad1415d0c193ad3906494428cf252621037bd7117e29::usdc::USDC",
46
+ WAL: "0x8270feb7375eee355e64fdb69c50abb6b5f9393a722883c1cf45f8e26048810a::wal::WAL",
46
47
  };
47
48
  export const testnetSealConfig = {
48
49
  serverConfigs: [
package/dist/const.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  import type { SuiNetwork } from "./types.js";
2
2
  import type { KeyServerConfig } from "@mysten/seal";
3
- export declare const WALRUS_UPLOAD_RELAY_BASE_URL: Record<SuiNetwork, string>;
4
3
  export declare const SEAL_SERVERS_CONFIGS: Record<SuiNetwork, KeyServerConfig[]>;
4
+ export declare const WALRUS_BLOB_BASE_UNIT_BYTES = 66028830.72;
package/dist/const.js CHANGED
@@ -1,10 +1,3 @@
1
- // // Walrus upload relay
2
- export const WALRUS_UPLOAD_RELAY_BASE_URL = {
3
- mainnet: "https://walrus-upload-relay-production-73a4.up.railway.app",
4
- testnet: "https://walrus-upload-relay-production-73a4.up.railway.app",
5
- };
6
- // Platform
7
- // seal
8
1
  export const SEAL_SERVERS_CONFIGS = {
9
2
  mainnet: [
10
3
  {
@@ -23,3 +16,4 @@ export const SEAL_SERVERS_CONFIGS = {
23
16
  },
24
17
  ],
25
18
  };
19
+ export const WALRUS_BLOB_BASE_UNIT_BYTES = 66028830.72;
@@ -12,7 +12,6 @@ export function useZingInfiniteQuery(input, options = {}, memo = []) {
12
12
  const methodMap = zingInfiniteQueryMethodMap(zingClient);
13
13
  const { method, params, limit = 20 } = input;
14
14
  return useInfiniteQuery({
15
- // eslint-disable-next-line @tanstack/query/exhaustive-deps
16
15
  queryKey: [zingClient.network, method, memo],
17
16
  queryFn: async ({ pageParam }) => {
18
17
  const fn = methodMap[method];
@@ -19,7 +19,6 @@ export function useZingQueries(options) {
19
19
  const queryConfigs = options.queries.map((queryConfig) => {
20
20
  const { method, params, ...queryOptions } = queryConfig;
21
21
  return {
22
- // eslint-disable-next-line @tanstack/query/exhaustive-deps
23
22
  queryKey: [zingClient.network, method, params],
24
23
  queryFn: async () => {
25
24
  const fn = methodMap[method];
@@ -20,7 +20,6 @@ export function useZingQuery(input, options = {}, memo = []) {
20
20
  const methodMap = zingQueryMethodMap(zingClient);
21
21
  const { method, params } = input;
22
22
  return useQuery({
23
- // eslint-disable-next-line @tanstack/query/exhaustive-deps
24
23
  queryKey: [zingClient.network, method, memo],
25
24
  gcTime: options.gcTime,
26
25
  staleTime: options.staleTime,
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Convert raw bytes ? credits
3
+ */
4
+ export declare const bytesToCredits: (bytes: number) => number;
5
+ /**
6
+ * Convert credits ? raw bytes
7
+ */
8
+ export declare const creditsToBytes: (credits: number) => number;
@@ -0,0 +1,17 @@
1
+ import { WALRUS_BLOB_BASE_UNIT_BYTES } from "../../const.js";
2
+ /**
3
+ * Convert raw bytes ? credits
4
+ */
5
+ export const bytesToCredits = (bytes) => {
6
+ if (!bytes || bytes <= 0)
7
+ return 0;
8
+ return bytes / WALRUS_BLOB_BASE_UNIT_BYTES;
9
+ };
10
+ /**
11
+ * Convert credits ? raw bytes
12
+ */
13
+ export const creditsToBytes = (credits) => {
14
+ if (!credits || credits <= 0)
15
+ return 0;
16
+ return credits * WALRUS_BLOB_BASE_UNIT_BYTES;
17
+ };
@@ -1,3 +1,4 @@
1
+ import { bytesToCredits } from "./blob.js";
1
2
  export const excludeValuesFromBaseArray = (baseArray, excludeArray) => baseArray.filter((value) => !excludeArray.includes(value));
2
3
  export const sleep = async (time) => new Promise((r) => setTimeout(r, time));
3
4
  export const formatBalance = (balance, decimal, digits = 4) => {
@@ -6,15 +7,11 @@ export const formatBalance = (balance, decimal, digits = 4) => {
6
7
  return fixed.replace(/\.?0+$/, "");
7
8
  };
8
9
  export const formatBytes = (bytes) => {
9
- // 62.97 MB base (62.97 * 1024 * 1024)
10
- const BASE_UNIT_BYTES = 66028830.72;
11
- if (!bytes || bytes <= 0)
12
- return "0";
13
- const points = bytes / BASE_UNIT_BYTES;
10
+ const credits = bytesToCredits(bytes);
14
11
  return new Intl.NumberFormat("en-US", {
15
12
  minimumFractionDigits: 0,
16
13
  maximumFractionDigits: 2,
17
- }).format(points);
14
+ }).format(credits);
18
15
  };
19
16
  export const getDaysRemaining = (comp) => {
20
17
  const now = new Date();
@@ -1,4 +1,2 @@
1
1
  export * from "./helpers.js";
2
- export * from "./colorful-logger.js";
3
- export * from "./init-app-with-shadow.js";
4
2
  export type * from "./types.js";
@@ -1,3 +1 @@
1
1
  export * from "./helpers.js";
2
- export * from "./colorful-logger.js";
3
- export * from "./init-app-with-shadow.js";
@@ -1,5 +1,3 @@
1
- import type { COLORS } from "./const.js";
2
1
  import type { TupleToUnion } from "type-fest";
3
2
  export type * from "type-fest";
4
- export type ColorType = "success" | "info" | "error" | "warning" | keyof typeof COLORS;
5
3
  export type ExcludeValuesFromBaseArrayType<B extends string[], E extends (string | number)[]> = Exclude<TupleToUnion<B>, TupleToUnion<E>>[];
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@zing-protocol/zing-sdk",
3
3
  "sideEffects": false,
4
4
  "type": "module",
5
- "version": "0.1.1",
5
+ "version": "0.1.3",
6
6
  "main": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",
8
8
  "exports": {
@@ -13,7 +13,7 @@
13
13
  },
14
14
  "scripts": {
15
15
  "build": "tsc",
16
- "type-check": "tsc --noEmit"
16
+ "lint": "eslint ."
17
17
  },
18
18
  "dependencies": {
19
19
  "@mysten/seal": "^1.0.1",
@@ -1,2 +0,0 @@
1
- import type { ColorType } from "./types.js";
2
- export declare const colorfulLog: (message: string, type: ColorType) => void;
@@ -1,23 +0,0 @@
1
- import { COLORS } from "./const.js";
2
- export const colorfulLog = (message, type) => {
3
- let color;
4
- switch (type) {
5
- case "success":
6
- color = COLORS.FgGreen;
7
- break;
8
- case "info":
9
- color = COLORS.FgBlue;
10
- break;
11
- case "error":
12
- color = COLORS.FgRed;
13
- break;
14
- case "warning":
15
- color = COLORS.FgYellow;
16
- break;
17
- default:
18
- color = COLORS[type];
19
- break;
20
- }
21
- console.info(color, message);
22
- console.info(COLORS["Reset"]);
23
- };
@@ -1,25 +0,0 @@
1
- export declare const COLORS: {
2
- readonly Reset: "\u001B[0m";
3
- readonly Bright: "\u001B[1m";
4
- readonly Dim: "\u001B[2m";
5
- readonly Underscore: "\u001B[4m";
6
- readonly Blink: "\u001B[5m";
7
- readonly Reverse: "\u001B[7m";
8
- readonly Hidden: "\u001B[8m";
9
- readonly FgBlack: "\u001B[30m";
10
- readonly FgRed: "\u001B[31m";
11
- readonly FgGreen: "\u001B[32m";
12
- readonly FgYellow: "\u001B[33m";
13
- readonly FgBlue: "\u001B[34m";
14
- readonly FgMagenta: "\u001B[35m";
15
- readonly FgCyan: "\u001B[36m";
16
- readonly FgWhite: "\u001B[37m";
17
- readonly BgBlack: "\u001B[40m";
18
- readonly BgRed: "\u001B[41m";
19
- readonly BgGreen: "\u001B[42m";
20
- readonly BgYellow: "\u001B[43m";
21
- readonly BgBlue: "\u001B[44m";
22
- readonly BgMagenta: "\u001B[45m";
23
- readonly BgCyan: "\u001B[46m";
24
- readonly BgWhite: "\u001B[47m";
25
- };
@@ -1,25 +0,0 @@
1
- export const COLORS = {
2
- Reset: "\x1b[0m",
3
- Bright: "\x1b[1m",
4
- Dim: "\x1b[2m",
5
- Underscore: "\x1b[4m",
6
- Blink: "\x1b[5m",
7
- Reverse: "\x1b[7m",
8
- Hidden: "\x1b[8m",
9
- FgBlack: "\x1b[30m",
10
- FgRed: "\x1b[31m",
11
- FgGreen: "\x1b[32m",
12
- FgYellow: "\x1b[33m",
13
- FgBlue: "\x1b[34m",
14
- FgMagenta: "\x1b[35m",
15
- FgCyan: "\x1b[36m",
16
- FgWhite: "\x1b[37m",
17
- BgBlack: "\x1b[40m",
18
- BgRed: "\x1b[41m",
19
- BgGreen: "\x1b[42m",
20
- BgYellow: "\x1b[43m",
21
- BgBlue: "\x1b[44m",
22
- BgMagenta: "\x1b[45m",
23
- BgCyan: "\x1b[46m",
24
- BgWhite: "\x1b[47m",
25
- };
@@ -1,6 +0,0 @@
1
- import type { ReactElement } from "react";
2
- export declare const initAppWithShadow: ({ id, app, inlineCss, }: {
3
- id: string;
4
- inlineCss: string;
5
- app: ReactElement;
6
- }) => void;
@@ -1,28 +0,0 @@
1
- import { createRoot } from "react-dom/client";
2
- export const initAppWithShadow = ({ id, app, inlineCss, }) => {
3
- const root = document.createElement("div");
4
- root.id = id;
5
- document.body.append(root);
6
- const rootIntoShadow = document.createElement("div");
7
- rootIntoShadow.id = `shadow-root-${id}`;
8
- const shadowRoot = root.attachShadow({ mode: "open" });
9
- if (navigator.userAgent.includes("Firefox")) {
10
- /**
11
- * In the firefox environment, adoptedStyleSheets cannot be used due to the bug
12
- * @url https://bugzilla.mozilla.org/show_bug.cgi?id=1770592
13
- *
14
- * Injecting styles into the document, this may cause style conflicts with the host page
15
- */
16
- const styleElement = document.createElement("style");
17
- styleElement.innerHTML = inlineCss;
18
- shadowRoot.appendChild(styleElement);
19
- }
20
- else {
21
- /** Inject styles into shadow dom */
22
- const globalStyleSheet = new CSSStyleSheet();
23
- globalStyleSheet.replaceSync(inlineCss);
24
- shadowRoot.adoptedStyleSheets = [globalStyleSheet];
25
- }
26
- shadowRoot.appendChild(rootIntoShadow);
27
- createRoot(rootIntoShadow).render(app);
28
- };