@evefrontier/dapp-kit 0.1.7 → 0.1.9
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/graphql/client.ts +9 -6
- package/hooks/useSmartObject.ts +1 -1
- package/hooks/useSponsoredTransaction.ts +47 -4
- package/package.json +14 -13
- package/providers/NotificationProvider.tsx +13 -1
- package/providers/SmartObjectProvider.tsx +25 -12
- package/providers/VaultProvider.tsx +7 -5
- package/types/contexts.ts +14 -5
- package/types/types.ts +39 -0
- package/utils/__tests__/characterOwnedObjects.test.ts +4 -1
- package/utils/__tests__/datahub.test.ts +20 -10
- package/utils/__tests__/logger.test.ts +145 -0
- package/utils/__tests__/mapping.test.ts +9 -9
- package/utils/__tests__/utils.test.ts +299 -0
- package/utils/characterOwnedObjects.ts +4 -3
- package/utils/constants.ts +35 -16
- package/utils/index.ts +4 -4
- package/utils/logger.ts +300 -0
- package/utils/transforms.ts +4 -1
- package/utils/utils.ts +9 -15
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
2
|
+
import {
|
|
3
|
+
createLogger,
|
|
4
|
+
resolveLogLevelFromEnv,
|
|
5
|
+
} from "../logger";
|
|
6
|
+
|
|
7
|
+
describe("resolveLogLevelFromEnv", () => {
|
|
8
|
+
it("uses error when viteMode is production", () => {
|
|
9
|
+
expect(resolveLogLevelFromEnv({ viteMode: "production" })).toBe("error");
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it("uses warn when viteMode is test", () => {
|
|
13
|
+
expect(resolveLogLevelFromEnv({ viteMode: "test" })).toBe("warn");
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it("uses debug for development or unset mode", () => {
|
|
17
|
+
expect(resolveLogLevelFromEnv({ viteMode: "development" })).toBe("debug");
|
|
18
|
+
expect(resolveLogLevelFromEnv({})).toBe("debug");
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it("prefers VITE_LOG_LEVEL over mode when it is a valid level", () => {
|
|
22
|
+
expect(
|
|
23
|
+
resolveLogLevelFromEnv({
|
|
24
|
+
viteLogLevel: "info",
|
|
25
|
+
viteMode: "production",
|
|
26
|
+
}),
|
|
27
|
+
).toBe("info");
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("normalizes explicit log level to lowercase", () => {
|
|
31
|
+
expect(
|
|
32
|
+
resolveLogLevelFromEnv({ viteLogLevel: "WARN", viteMode: "development" }),
|
|
33
|
+
).toBe("warn");
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("ignores invalid VITE_LOG_LEVEL and falls back to mode", () => {
|
|
37
|
+
expect(
|
|
38
|
+
resolveLogLevelFromEnv({
|
|
39
|
+
viteLogLevel: "not-a-level",
|
|
40
|
+
viteMode: "production",
|
|
41
|
+
}),
|
|
42
|
+
).toBe("error");
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
describe("createLogger — level gating", () => {
|
|
47
|
+
afterEach(() => {
|
|
48
|
+
vi.restoreAllMocks();
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("at error level, only error logs call console", () => {
|
|
52
|
+
const debugSpy = vi.spyOn(console, "debug").mockImplementation(() => {});
|
|
53
|
+
const infoSpy = vi.spyOn(console, "info").mockImplementation(() => {});
|
|
54
|
+
const warnSpy = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
55
|
+
const errorSpy = vi.spyOn(console, "error").mockImplementation(() => {});
|
|
56
|
+
|
|
57
|
+
const log = createLogger({ level: "error", scope: "gate" });
|
|
58
|
+
log.debug("d");
|
|
59
|
+
log.info("i");
|
|
60
|
+
log.warn("w");
|
|
61
|
+
log.error("e");
|
|
62
|
+
|
|
63
|
+
expect(debugSpy).not.toHaveBeenCalled();
|
|
64
|
+
expect(infoSpy).not.toHaveBeenCalled();
|
|
65
|
+
expect(warnSpy).not.toHaveBeenCalled();
|
|
66
|
+
expect(errorSpy).toHaveBeenCalledTimes(1);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it("at silent level, no console methods are invoked", () => {
|
|
70
|
+
const debugSpy = vi.spyOn(console, "debug").mockImplementation(() => {});
|
|
71
|
+
const errorSpy = vi.spyOn(console, "error").mockImplementation(() => {});
|
|
72
|
+
|
|
73
|
+
const log = createLogger({ level: "silent", scope: "quiet" });
|
|
74
|
+
log.debug("d");
|
|
75
|
+
log.error("e");
|
|
76
|
+
|
|
77
|
+
expect(debugSpy).not.toHaveBeenCalled();
|
|
78
|
+
expect(errorSpy).not.toHaveBeenCalled();
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it("at warn level, warn and error log but not info or debug", () => {
|
|
82
|
+
const debugSpy = vi.spyOn(console, "debug").mockImplementation(() => {});
|
|
83
|
+
const infoSpy = vi.spyOn(console, "info").mockImplementation(() => {});
|
|
84
|
+
const warnSpy = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
85
|
+
const errorSpy = vi.spyOn(console, "error").mockImplementation(() => {});
|
|
86
|
+
|
|
87
|
+
const log = createLogger({ level: "warn", scope: "w" });
|
|
88
|
+
log.debug("d");
|
|
89
|
+
log.info("i");
|
|
90
|
+
log.warn("w");
|
|
91
|
+
log.error("e");
|
|
92
|
+
|
|
93
|
+
expect(debugSpy).not.toHaveBeenCalled();
|
|
94
|
+
expect(infoSpy).not.toHaveBeenCalled();
|
|
95
|
+
expect(warnSpy).toHaveBeenCalledTimes(1);
|
|
96
|
+
expect(errorSpy).toHaveBeenCalledTimes(1);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it("child logger inherits parent level", () => {
|
|
100
|
+
const debugSpy = vi.spyOn(console, "debug").mockImplementation(() => {});
|
|
101
|
+
|
|
102
|
+
const parent = createLogger({ level: "error", scope: "p" });
|
|
103
|
+
const child = parent.child("c");
|
|
104
|
+
child.debug("x");
|
|
105
|
+
|
|
106
|
+
expect(debugSpy).not.toHaveBeenCalled();
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
describe("createLogger — console format args (%s preservation)", () => {
|
|
111
|
+
afterEach(() => {
|
|
112
|
+
vi.restoreAllMocks();
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it("merges prefix into the first string so %s remains the console format string", () => {
|
|
116
|
+
const infoSpy = vi.spyOn(console, "info").mockImplementation(() => {});
|
|
117
|
+
|
|
118
|
+
const log = createLogger({ level: "info", scope: "fmt" });
|
|
119
|
+
log.info("%s world", "hello");
|
|
120
|
+
|
|
121
|
+
expect(infoSpy).toHaveBeenCalledTimes(1);
|
|
122
|
+
const args = infoSpy.mock.calls[0] as unknown[];
|
|
123
|
+
expect(args.length).toBe(2);
|
|
124
|
+
expect(typeof args[0]).toBe("string");
|
|
125
|
+
expect(args[0]).toContain("%s world");
|
|
126
|
+
expect(args[0]).toMatch(/\[fmt\]/);
|
|
127
|
+
expect(args[1]).toBe("hello");
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it("keeps prefix as a separate first arg when the first log argument is not a string", () => {
|
|
131
|
+
const infoSpy = vi.spyOn(console, "info").mockImplementation(() => {});
|
|
132
|
+
|
|
133
|
+
const log = createLogger({ level: "info", scope: "obj" });
|
|
134
|
+
const payload = { a: 1 };
|
|
135
|
+
log.info(payload, "extra");
|
|
136
|
+
|
|
137
|
+
expect(infoSpy).toHaveBeenCalledTimes(1);
|
|
138
|
+
const args = infoSpy.mock.calls[0] as unknown[];
|
|
139
|
+
expect(args.length).toBe(3);
|
|
140
|
+
expect(typeof args[0]).toBe("string");
|
|
141
|
+
expect(args[0]).toMatch(/\[obj\]/);
|
|
142
|
+
expect(args[1]).toBe(payload);
|
|
143
|
+
expect(args[2]).toBe("extra");
|
|
144
|
+
});
|
|
145
|
+
});
|
|
@@ -298,7 +298,7 @@ describe("mapping utilities", () => {
|
|
|
298
298
|
it("works with new SSUID", () => {
|
|
299
299
|
const key = TenantItemIdBcs.serialize({
|
|
300
300
|
item_id: 1000000012533,
|
|
301
|
-
tenant: "
|
|
301
|
+
tenant: "tauceti",
|
|
302
302
|
}).toBytes();
|
|
303
303
|
|
|
304
304
|
const result = deriveObjectID(
|
|
@@ -308,7 +308,7 @@ describe("mapping utilities", () => {
|
|
|
308
308
|
);
|
|
309
309
|
|
|
310
310
|
expect(result).toBe(
|
|
311
|
-
"
|
|
311
|
+
"0xd4e78bd8312d46b58ad8acb0a352c278384914c705fd90968bef5eb8c44cb667",
|
|
312
312
|
);
|
|
313
313
|
});
|
|
314
314
|
|
|
@@ -380,7 +380,7 @@ describe("mapping utilities", () => {
|
|
|
380
380
|
const { getObjectId } = await import("../mapping");
|
|
381
381
|
const itemId = "12345";
|
|
382
382
|
|
|
383
|
-
const objectId = await getObjectId(itemId, "
|
|
383
|
+
const objectId = await getObjectId(itemId, "tauceti");
|
|
384
384
|
|
|
385
385
|
expect(getSingletonObjectByType).toHaveBeenCalledWith(
|
|
386
386
|
getObjectRegistryType(),
|
|
@@ -392,7 +392,7 @@ describe("mapping utilities", () => {
|
|
|
392
392
|
it("uses OBJECT registry type when specified", async () => {
|
|
393
393
|
const { getObjectId } = await import("../mapping");
|
|
394
394
|
|
|
395
|
-
await getObjectId("12345", "
|
|
395
|
+
await getObjectId("12345", "tauceti");
|
|
396
396
|
|
|
397
397
|
expect(getSingletonObjectByType).toHaveBeenCalledWith(
|
|
398
398
|
getObjectRegistryType(),
|
|
@@ -402,7 +402,7 @@ describe("mapping utilities", () => {
|
|
|
402
402
|
it("uses default OBJECT registry type when not specified", async () => {
|
|
403
403
|
const { getObjectId } = await import("../mapping");
|
|
404
404
|
|
|
405
|
-
await getObjectId("12345", "
|
|
405
|
+
await getObjectId("12345", "tauceti");
|
|
406
406
|
|
|
407
407
|
expect(getSingletonObjectByType).toHaveBeenCalledWith(
|
|
408
408
|
getObjectRegistryType(),
|
|
@@ -420,7 +420,7 @@ describe("mapping utilities", () => {
|
|
|
420
420
|
|
|
421
421
|
const { getObjectId } = await import("../mapping");
|
|
422
422
|
|
|
423
|
-
await expect(getObjectId("12345", "
|
|
423
|
+
await expect(getObjectId("12345", "tauceti")).rejects.toThrow(
|
|
424
424
|
`ObjectRegistry not found for type: ${getObjectRegistryType()}`,
|
|
425
425
|
);
|
|
426
426
|
});
|
|
@@ -428,9 +428,9 @@ describe("mapping utilities", () => {
|
|
|
428
428
|
it("caches registry address across multiple calls", async () => {
|
|
429
429
|
const { getObjectId } = await import("../mapping");
|
|
430
430
|
|
|
431
|
-
await getObjectId("12345", "
|
|
432
|
-
await getObjectId("67890", "
|
|
433
|
-
await getObjectId("11111", "
|
|
431
|
+
await getObjectId("12345", "tauceti");
|
|
432
|
+
await getObjectId("67890", "tauceti");
|
|
433
|
+
await getObjectId("11111", "tauceti");
|
|
434
434
|
|
|
435
435
|
// Should only fetch registry once (cached)
|
|
436
436
|
expect(getSingletonObjectByType).toHaveBeenCalledTimes(1);
|
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
import { describe, expect, it, vi, beforeEach, afterEach } from "vitest";
|
|
2
|
+
import {
|
|
3
|
+
abbreviateAddress,
|
|
4
|
+
isOwner,
|
|
5
|
+
getTxUrl,
|
|
6
|
+
parseURL,
|
|
7
|
+
clickToCopy,
|
|
8
|
+
getCommonItems,
|
|
9
|
+
removeTrailingZeros,
|
|
10
|
+
getEnv,
|
|
11
|
+
getVolumeM3,
|
|
12
|
+
formatM3,
|
|
13
|
+
getDappUrl,
|
|
14
|
+
findOwnerByAddress,
|
|
15
|
+
assertAssemblyType,
|
|
16
|
+
formatDuration,
|
|
17
|
+
} from "../utils";
|
|
18
|
+
import { Assemblies } from "../../types";
|
|
19
|
+
|
|
20
|
+
describe("abbreviateAddress", () => {
|
|
21
|
+
it("returns empty string for undefined or empty input", () => {
|
|
22
|
+
expect(abbreviateAddress()).toBe("");
|
|
23
|
+
expect(abbreviateAddress("")).toBe("");
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("abbreviates long address with default precision (5)", () => {
|
|
27
|
+
expect(abbreviateAddress("0x1234567890abcdef1234567890abcdef")).toBe(
|
|
28
|
+
"0x123...bcdef",
|
|
29
|
+
);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it("abbreviates with custom precision", () => {
|
|
33
|
+
expect(abbreviateAddress("0x1234567890abcdef", 3)).toBe("0x1...def");
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("returns full string when expanded is true", () => {
|
|
37
|
+
const addr = "0x1234567890abcdef";
|
|
38
|
+
expect(abbreviateAddress(addr, 5, true)).toBe(addr);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("returns string as-is when length <= precision * 2", () => {
|
|
42
|
+
expect(abbreviateAddress("0x12345", 5)).toBe("0x12345");
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
describe("isOwner", () => {
|
|
47
|
+
it("returns false when assembly is null", () => {
|
|
48
|
+
expect(isOwner(null, "0xabc")).toBe(false);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("returns false when assembly has no character address", () => {
|
|
52
|
+
expect(isOwner({} as any, "0xabc")).toBe(false);
|
|
53
|
+
expect(isOwner({ character: {} } as any, "0xabc")).toBe(false);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it("returns false when account is 0x", () => {
|
|
57
|
+
expect(isOwner({ character: { address: "0xabc" } } as any, "0x")).toBe(
|
|
58
|
+
false,
|
|
59
|
+
);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it("returns true when character address matches account", () => {
|
|
63
|
+
expect(isOwner({ character: { address: "0xabc" } } as any, "0xabc")).toBe(
|
|
64
|
+
true,
|
|
65
|
+
);
|
|
66
|
+
expect(isOwner({ character: { address: "0xdef" } } as any, "0xdef")).toBe(
|
|
67
|
+
true,
|
|
68
|
+
);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it("returns false when character address does not match account", () => {
|
|
72
|
+
expect(isOwner({ character: { address: "0xabc" } } as any, "0xdef")).toBe(
|
|
73
|
+
false,
|
|
74
|
+
);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it("treats undefined account as empty string (no match unless address is empty)", () => {
|
|
78
|
+
expect(isOwner({ character: { address: "0xabc" } } as any, undefined)).toBe(
|
|
79
|
+
false,
|
|
80
|
+
);
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
describe("getTxUrl", () => {
|
|
85
|
+
it("builds Suiscan URL for testnet", () => {
|
|
86
|
+
expect(getTxUrl("sui:testnet", "ABC123")).toBe(
|
|
87
|
+
"https://suiscan.xyz/testnet/tx/ABC123",
|
|
88
|
+
);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it("builds Suiscan URL for mainnet", () => {
|
|
92
|
+
expect(getTxUrl("sui:mainnet", "xyz789")).toBe(
|
|
93
|
+
"https://suiscan.xyz/mainnet/tx/xyz789",
|
|
94
|
+
);
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
describe("parseURL", () => {
|
|
99
|
+
it("strips https:// and returns the rest", () => {
|
|
100
|
+
expect(parseURL("https://example.com/path")).toBe("example.com/path");
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it("strips http:// and returns the rest", () => {
|
|
104
|
+
expect(parseURL("http://foo.bar")).toBe("foo.bar");
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it("returns string unchanged when no protocol", () => {
|
|
108
|
+
expect(parseURL("example.com")).toBe("example.com");
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
describe("clickToCopy", () => {
|
|
113
|
+
beforeEach(() => {
|
|
114
|
+
vi.stubGlobal("navigator", {
|
|
115
|
+
clipboard: { writeText: vi.fn().mockResolvedValue(undefined) },
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
afterEach(() => {
|
|
120
|
+
vi.unstubAllGlobals();
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it("calls navigator.clipboard.writeText with the given string", async () => {
|
|
124
|
+
await clickToCopy("hello");
|
|
125
|
+
expect(navigator.clipboard.writeText).toHaveBeenCalledWith("hello");
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
describe("getCommonItems", () => {
|
|
130
|
+
it("returns empty array when either array is empty", () => {
|
|
131
|
+
expect(getCommonItems([], [1, 2])).toEqual([]);
|
|
132
|
+
expect(getCommonItems([1, 2], [])).toEqual([]);
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it("returns common elements", () => {
|
|
136
|
+
expect(getCommonItems([1, 2, 3], [2, 3, 4])).toEqual([2, 3]);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it("includes duplicates from second array when they appear in first", () => {
|
|
140
|
+
expect(getCommonItems([1, 1, 2], [1, 2, 2])).toEqual([1, 2, 2]);
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
it("works with string arrays", () => {
|
|
144
|
+
expect(getCommonItems(["a", "b"], ["b", "c"])).toEqual(["b"]);
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
describe("removeTrailingZeros", () => {
|
|
149
|
+
it("removes trailing zeros after last significant decimal", () => {
|
|
150
|
+
expect(removeTrailingZeros("1.23000")).toBe("1.23");
|
|
151
|
+
expect(removeTrailingZeros("1.100")).toBe("1.1");
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
it("removes trailing decimal zeros only", () => {
|
|
155
|
+
expect(removeTrailingZeros("1.23400")).toBe("1.234");
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it("handles integer-like string", () => {
|
|
159
|
+
expect(removeTrailingZeros("1.0")).toBe("1");
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
describe("getEnv", () => {
|
|
164
|
+
it("returns env value when truthy", () => {
|
|
165
|
+
expect(getEnv("value", "fallback")).toBe("value");
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
it("returns fallback when env is empty string", () => {
|
|
169
|
+
expect(getEnv("", "fallback")).toBe("fallback");
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
describe("getVolumeM3", () => {
|
|
174
|
+
it("computes volume from quantity and volume per unit", () => {
|
|
175
|
+
expect(getVolumeM3(10n, 1000n)).toBe(10000);
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
it("handles single unit", () => {
|
|
179
|
+
expect(getVolumeM3(1n, 500n)).toBe(500);
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
describe("formatM3", () => {
|
|
184
|
+
it("converts litres (1000) to 1 m³", () => {
|
|
185
|
+
expect(formatM3("1000")).toBe(1);
|
|
186
|
+
expect(formatM3(BigInt("1000"))).toBe(1);
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
it("converts string input", () => {
|
|
190
|
+
expect(formatM3("2500")).toBe(2.5);
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
describe("getDappUrl", () => {
|
|
195
|
+
it("returns empty string when assembly has no dappURL", () => {
|
|
196
|
+
expect(getDappUrl(null as any)).toBe("");
|
|
197
|
+
expect(getDappUrl({} as any)).toBe("");
|
|
198
|
+
expect(getDappUrl({ dappURL: undefined } as any)).toBe("");
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
it("returns dappURL as-is when it has protocol", () => {
|
|
202
|
+
expect(getDappUrl({ dappURL: "https://example.com" } as any)).toBe(
|
|
203
|
+
"https://example.com",
|
|
204
|
+
);
|
|
205
|
+
expect(getDappUrl({ dappURL: "http://foo.bar" } as any)).toBe(
|
|
206
|
+
"http://foo.bar",
|
|
207
|
+
);
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
it("adds https:// when dappURL has no protocol (bare hostname)", () => {
|
|
211
|
+
expect(getDappUrl({ dappURL: "example.com" } as any)).toBe(
|
|
212
|
+
"https://example.com",
|
|
213
|
+
);
|
|
214
|
+
expect(getDappUrl({ dappURL: "google.com" } as any)).toBe(
|
|
215
|
+
"https://google.com",
|
|
216
|
+
);
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
it("adds https:// only when dappURL already starts with www.", () => {
|
|
220
|
+
expect(getDappUrl({ dappURL: "www.foo.com" } as any)).toBe(
|
|
221
|
+
"https://www.foo.com",
|
|
222
|
+
);
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
it("adds https:// for bare hostname with path", () => {
|
|
226
|
+
expect(getDappUrl({ dappURL: "example.com/path" } as any)).toBe(
|
|
227
|
+
"https://example.com/path",
|
|
228
|
+
);
|
|
229
|
+
});
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
describe("findOwnerByAddress", () => {
|
|
233
|
+
it("returns false when either address is missing or empty", () => {
|
|
234
|
+
expect(findOwnerByAddress(undefined, "0xabc")).toBe(false);
|
|
235
|
+
expect(findOwnerByAddress("0xabc", undefined)).toBe(false);
|
|
236
|
+
expect(findOwnerByAddress("", "0xabc")).toBe(false);
|
|
237
|
+
expect(findOwnerByAddress("0xabc", "")).toBe(false);
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
it("returns true when addresses match", () => {
|
|
241
|
+
expect(findOwnerByAddress("0xabc", "0xabc")).toBe(true);
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
it("returns false when addresses differ", () => {
|
|
245
|
+
expect(findOwnerByAddress("0xabc", "0xdef")).toBe(false);
|
|
246
|
+
});
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
describe("assertAssemblyType", () => {
|
|
250
|
+
it("returns false when assembly is null", () => {
|
|
251
|
+
expect(assertAssemblyType(null, Assemblies.SmartStorageUnit)).toBe(false);
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
it("returns false when assembly has no type", () => {
|
|
255
|
+
expect(assertAssemblyType({} as any, Assemblies.SmartStorageUnit)).toBe(
|
|
256
|
+
false,
|
|
257
|
+
);
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
it("returns true when assembly type matches", () => {
|
|
261
|
+
expect(
|
|
262
|
+
assertAssemblyType(
|
|
263
|
+
{ type: Assemblies.SmartStorageUnit } as any,
|
|
264
|
+
Assemblies.SmartStorageUnit,
|
|
265
|
+
),
|
|
266
|
+
).toBe(true);
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
it("returns false when assembly type does not match", () => {
|
|
270
|
+
expect(
|
|
271
|
+
assertAssemblyType(
|
|
272
|
+
{ type: Assemblies.SmartGate } as any,
|
|
273
|
+
Assemblies.SmartStorageUnit,
|
|
274
|
+
),
|
|
275
|
+
).toBe(false);
|
|
276
|
+
});
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
describe("formatDuration", () => {
|
|
280
|
+
it("returns 0m 0s for zero", () => {
|
|
281
|
+
expect(formatDuration(0)).toBe("0m 0s");
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
it("formats seconds only", () => {
|
|
285
|
+
expect(formatDuration(45)).toBe("45s");
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
it("formats minutes and seconds", () => {
|
|
289
|
+
expect(formatDuration(90)).toBe("01m 30s");
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
it("formats hours, minutes, seconds", () => {
|
|
293
|
+
expect(formatDuration(3665)).toBe("01h 01m 05s");
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
it("formats days, hours, minutes, seconds", () => {
|
|
297
|
+
expect(formatDuration(90061)).toBe("01d 01h 01m 01s");
|
|
298
|
+
});
|
|
299
|
+
});
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { getCharacterAndOwnedObjects } from "../graphql/client";
|
|
2
2
|
import type { GetCharacterAndOwnedObjectsResponse } from "../graphql/types";
|
|
3
|
+
import { createLogger } from "./logger";
|
|
4
|
+
|
|
5
|
+
const log = createLogger();
|
|
3
6
|
|
|
4
7
|
/**
|
|
5
8
|
* Extracts the JSON payloads from the first character's owned objects
|
|
@@ -38,9 +41,7 @@ export async function getCharacterOwnedObjects(
|
|
|
38
41
|
(response) => {
|
|
39
42
|
const data = response.data;
|
|
40
43
|
if (!data) {
|
|
41
|
-
|
|
42
|
-
"[Dapp] No data returned from getCharacterAndOwnedObjects",
|
|
43
|
-
);
|
|
44
|
+
log.warn("[Dapp] No data returned from getCharacterAndOwnedObjects");
|
|
44
45
|
return;
|
|
45
46
|
}
|
|
46
47
|
const ownedObjectsJson = getCharacterOwnedObjectsJson(data);
|
package/utils/constants.ts
CHANGED
|
@@ -84,10 +84,22 @@ export const getFuelEfficiencyConfigType = (): string =>
|
|
|
84
84
|
*/
|
|
85
85
|
export const DEFAULT_GRAPHQL_NETWORK: SuiGraphqlNetwork = "testnet";
|
|
86
86
|
|
|
87
|
+
/** Tenant IDs.
|
|
88
|
+
* @category Constants
|
|
89
|
+
*/
|
|
90
|
+
export enum TenantId {
|
|
91
|
+
UTOPIA = "utopia",
|
|
92
|
+
STILLNESS = "stillness",
|
|
93
|
+
TAUCETI = "tauceti",
|
|
94
|
+
TIAKI = "tiaki",
|
|
95
|
+
TETRA = "tetra",
|
|
96
|
+
TESSERACT = "tesseract",
|
|
97
|
+
}
|
|
98
|
+
|
|
87
99
|
/** Tenant when not provided via URL ?tenant= (e.g. dev/default chain).
|
|
88
100
|
* @category Constants
|
|
89
101
|
*/
|
|
90
|
-
export const DEFAULT_TENANT =
|
|
102
|
+
export const DEFAULT_TENANT = TenantId.STILLNESS;
|
|
91
103
|
|
|
92
104
|
/** Allowed Sui network identifiers for GraphQL endpoint selection.
|
|
93
105
|
* @category Constants
|
|
@@ -143,13 +155,6 @@ export const EXCLUDED_TYPEIDS = [
|
|
|
143
155
|
TYPEIDS.REFUGE,
|
|
144
156
|
];
|
|
145
157
|
|
|
146
|
-
/** Volume - from wei units to m3.
|
|
147
|
-
* @category Constants
|
|
148
|
-
*/
|
|
149
|
-
export const ONE_M3 = 1000000000000000000;
|
|
150
|
-
|
|
151
|
-
export type TenantId = "utopia" | "stillness" | "testevenet" | "nebula";
|
|
152
|
-
|
|
153
158
|
/** Per-tenant config: EVE token package ID (Sui) and Datahub API host. v0.0.18
|
|
154
159
|
* @category Constants
|
|
155
160
|
*/
|
|
@@ -159,33 +164,47 @@ export interface TenantConfig {
|
|
|
159
164
|
datahubHost: string;
|
|
160
165
|
}
|
|
161
166
|
|
|
162
|
-
/** Single source of truth for the
|
|
167
|
+
/** Single source of truth for the six tenants (package ID + datahub host).
|
|
163
168
|
* Corresponds to world contracts v0.0.18
|
|
164
169
|
* @category Constants
|
|
165
170
|
*/
|
|
166
171
|
export const TENANT_CONFIG: Record<TenantId, TenantConfig> = {
|
|
167
|
-
|
|
172
|
+
[TenantId.TAUCETI]: {
|
|
173
|
+
packageId:
|
|
174
|
+
"0x353988e063b4683580e3603dbe9e91fefd8f6a06263a646d43fd3a2f3ef6b8c1",
|
|
175
|
+
evePackageId:
|
|
176
|
+
"0x6407060579895a8b30f7d30d2447046eb80ecc23f0c9acde09222b2a505583c9",
|
|
177
|
+
datahubHost: "world-api-tauceti.test.priv.evefrontier.com",
|
|
178
|
+
},
|
|
179
|
+
[TenantId.TIAKI]: {
|
|
180
|
+
packageId:
|
|
181
|
+
"0x353988e063b4683580e3603dbe9e91fefd8f6a06263a646d43fd3a2f3ef6b8c1",
|
|
182
|
+
evePackageId:
|
|
183
|
+
"0x6407060579895a8b30f7d30d2447046eb80ecc23f0c9acde09222b2a505583c9",
|
|
184
|
+
datahubHost: "world-api-tiaki.test.priv.evefrontier.com",
|
|
185
|
+
},
|
|
186
|
+
[TenantId.TESSERACT]: {
|
|
168
187
|
packageId:
|
|
169
188
|
"0x353988e063b4683580e3603dbe9e91fefd8f6a06263a646d43fd3a2f3ef6b8c1",
|
|
170
189
|
evePackageId:
|
|
171
190
|
"0x6407060579895a8b30f7d30d2447046eb80ecc23f0c9acde09222b2a505583c9",
|
|
172
|
-
datahubHost: "world-api-
|
|
191
|
+
datahubHost: "world-api-tesseract.test.priv.evefrontier.com",
|
|
173
192
|
},
|
|
174
|
-
|
|
193
|
+
[TenantId.TETRA]: {
|
|
175
194
|
packageId:
|
|
176
195
|
"0x353988e063b4683580e3603dbe9e91fefd8f6a06263a646d43fd3a2f3ef6b8c1",
|
|
177
196
|
evePackageId:
|
|
178
197
|
"0x6407060579895a8b30f7d30d2447046eb80ecc23f0c9acde09222b2a505583c9",
|
|
179
|
-
datahubHost: "world-api-
|
|
198
|
+
datahubHost: "world-api-tetra.test.priv.evefrontier.com",
|
|
180
199
|
},
|
|
181
|
-
|
|
200
|
+
[TenantId.UTOPIA]: {
|
|
182
201
|
packageId:
|
|
183
202
|
"0xd12a70c74c1e759445d6f209b01d43d860e97fcf2ef72ccbbd00afd828043f75",
|
|
184
203
|
evePackageId:
|
|
185
204
|
"0xf0446b93345c1118f21239d7ac58fb82d005219b2016e100f074e4d17162a465",
|
|
186
205
|
datahubHost: "world-api-utopia.uat.pub.evefrontier.com",
|
|
187
206
|
},
|
|
188
|
-
|
|
207
|
+
[TenantId.STILLNESS]: {
|
|
189
208
|
packageId:
|
|
190
209
|
"0x28b497559d65ab320d9da4613bf2498d5946b2c0ae3597ccfda3072ce127448c",
|
|
191
210
|
evePackageId:
|
|
@@ -218,7 +237,7 @@ const EVE_COIN_TYPE_SUFFIX = "::EVE::EVE";
|
|
|
218
237
|
/**
|
|
219
238
|
* Returns the EVE token coin type for the given tenant.
|
|
220
239
|
* Format: `{packageId}::EVE::EVE` (Sui Move type used by RPC/GraphQL).
|
|
221
|
-
* @param tenantId - The tenant identifier (e.g.,
|
|
240
|
+
* @param tenantId - The tenant identifier (e.g., TenantId.UTOPIA, TenantId.STILLNESS)
|
|
222
241
|
* @returns The fully qualified EVE coin type string
|
|
223
242
|
*
|
|
224
243
|
* @category Utilities - Config
|
package/utils/index.ts
CHANGED
|
@@ -6,10 +6,7 @@ export {
|
|
|
6
6
|
getRegistryAddress,
|
|
7
7
|
} from "./mapping";
|
|
8
8
|
export { getEnergyUsageForType, getFuelEfficiencyForType } from "./config";
|
|
9
|
-
export {
|
|
10
|
-
getAdjustedBurnRate,
|
|
11
|
-
type AdjustedBurnRate,
|
|
12
|
-
} from "./burnRate";
|
|
9
|
+
export { getAdjustedBurnRate, type AdjustedBurnRate } from "./burnRate";
|
|
13
10
|
export { parseCharacterFromJson } from "./character";
|
|
14
11
|
export {
|
|
15
12
|
getCharacterOwnedObjectsJson,
|
|
@@ -45,3 +42,6 @@ export * from "./constants";
|
|
|
45
42
|
// Error handling
|
|
46
43
|
export { ERRORS, ERROR_MESSAGES, parseErrorFromMessage } from "./errors";
|
|
47
44
|
export type { ErrorType } from "./errors";
|
|
45
|
+
|
|
46
|
+
// Logging
|
|
47
|
+
export * from "./logger";
|