@zing-protocol/zing-sdk 0.1.2 → 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.
package/dist/const.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  import type { SuiNetwork } from "./types.js";
2
2
  import type { KeyServerConfig } from "@mysten/seal";
3
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
@@ -16,3 +16,4 @@ export const SEAL_SERVERS_CONFIGS = {
16
16
  },
17
17
  ],
18
18
  };
19
+ export const WALRUS_BLOB_BASE_UNIT_BYTES = 66028830.72;
@@ -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.2",
5
+ "version": "0.1.3",
6
6
  "main": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",
8
8
  "exports": {
@@ -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
- };