@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 +1 -0
- package/dist/const.js +1 -0
- package/dist/lib/utils/blob.d.ts +8 -0
- package/dist/lib/utils/blob.js +17 -0
- package/dist/lib/utils/helpers.js +3 -6
- package/dist/lib/utils/index.d.ts +0 -2
- package/dist/lib/utils/index.js +0 -2
- package/dist/lib/utils/types.d.ts +0 -2
- package/package.json +1 -1
- package/dist/lib/utils/colorful-logger.d.ts +0 -2
- package/dist/lib/utils/colorful-logger.js +0 -23
- package/dist/lib/utils/const.d.ts +0 -25
- package/dist/lib/utils/const.js +0 -25
- package/dist/lib/utils/init-app-with-shadow.d.ts +0 -6
- package/dist/lib/utils/init-app-with-shadow.js +0 -28
package/dist/const.d.ts
CHANGED
package/dist/const.js
CHANGED
|
@@ -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
|
-
|
|
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(
|
|
14
|
+
}).format(credits);
|
|
18
15
|
};
|
|
19
16
|
export const getDaysRemaining = (comp) => {
|
|
20
17
|
const now = new Date();
|
package/dist/lib/utils/index.js
CHANGED
|
@@ -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
|
@@ -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
|
-
};
|
package/dist/lib/utils/const.js
DELETED
|
@@ -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,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
|
-
};
|