@evefrontier/dapp-kit 0.1.9 → 0.2.0-alpha.1
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/README.md +28 -25
- package/dist/config/dapp-kit.d.ts +4 -0
- package/dist/config/dapp-kit.d.ts.map +1 -0
- package/dist/config/dapp-kit.js +14 -0
- package/dist/config/index.d.ts +2 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +1 -0
- package/dist/graphql/client.d.ts +277 -0
- package/dist/graphql/client.d.ts.map +1 -0
- package/dist/graphql/client.js +346 -0
- package/dist/graphql/index.d.ts +4 -0
- package/dist/graphql/index.d.ts.map +1 -0
- package/dist/graphql/index.js +16 -0
- package/dist/graphql/queries.d.ts +103 -0
- package/dist/graphql/queries.d.ts.map +1 -0
- package/{graphql/queries.ts → dist/graphql/queries.js} +113 -223
- package/dist/graphql/types.d.ts +396 -0
- package/dist/graphql/types.d.ts.map +1 -0
- package/dist/graphql/types.js +4 -0
- package/dist/hooks/index.d.ts +10 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/index.js +8 -0
- package/dist/hooks/useCharacterDirectory.d.ts +16 -0
- package/dist/hooks/useCharacterDirectory.d.ts.map +1 -0
- package/dist/hooks/useCharacterDirectory.js +23 -0
- package/dist/hooks/useCharacterSearch.d.ts +24 -0
- package/dist/hooks/useCharacterSearch.d.ts.map +1 -0
- package/dist/hooks/useCharacterSearch.js +24 -0
- package/dist/hooks/useConnection.d.ts +51 -0
- package/dist/hooks/useConnection.d.ts.map +1 -0
- package/{hooks/useConnection.ts → dist/hooks/useConnection.js} +8 -10
- package/dist/hooks/useEntityRole.d.ts +26 -0
- package/dist/hooks/useEntityRole.d.ts.map +1 -0
- package/dist/hooks/useEntityRole.js +91 -0
- package/dist/hooks/useNotification.d.ts +72 -0
- package/dist/hooks/useNotification.d.ts.map +1 -0
- package/{hooks/useNotification.ts → dist/hooks/useNotification.js} +8 -12
- package/dist/hooks/useSmartObject.d.ts +44 -0
- package/dist/hooks/useSmartObject.d.ts.map +1 -0
- package/dist/hooks/useSmartObject.js +50 -0
- package/dist/hooks/useSponsoredTransaction.d.ts +147 -0
- package/dist/hooks/useSponsoredTransaction.d.ts.map +1 -0
- package/dist/hooks/useSponsoredTransaction.js +240 -0
- package/dist/hooks/useTypeNames.d.ts +11 -0
- package/dist/hooks/useTypeNames.d.ts.map +1 -0
- package/dist/hooks/useTypeNames.js +24 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +29 -0
- package/dist/providers/EveFrontierProvider.d.ts +23 -0
- package/dist/providers/EveFrontierProvider.d.ts.map +1 -0
- package/dist/providers/EveFrontierProvider.js +23 -0
- package/dist/providers/NotificationProvider.d.ts +14 -0
- package/dist/providers/NotificationProvider.d.ts.map +1 -0
- package/dist/providers/NotificationProvider.js +66 -0
- package/dist/providers/SmartObjectProvider.d.ts +31 -0
- package/dist/providers/SmartObjectProvider.d.ts.map +1 -0
- package/dist/providers/SmartObjectProvider.js +80 -0
- package/dist/providers/VaultProvider.d.ts +10 -0
- package/dist/providers/VaultProvider.d.ts.map +1 -0
- package/dist/providers/VaultProvider.js +79 -0
- package/dist/providers/index.d.ts +5 -0
- package/dist/providers/index.d.ts.map +1 -0
- package/dist/providers/index.js +4 -0
- package/dist/providers/smartObject/useEntityData.d.ts +29 -0
- package/dist/providers/smartObject/useEntityData.d.ts.map +1 -0
- package/dist/providers/smartObject/useEntityData.js +135 -0
- package/dist/providers/smartObject/useEntitySubscription.d.ts +14 -0
- package/dist/providers/smartObject/useEntitySubscription.d.ts.map +1 -0
- package/dist/providers/smartObject/useEntitySubscription.js +58 -0
- package/dist/providers/smartObject/useObjectSelection.d.ts +11 -0
- package/dist/providers/smartObject/useObjectSelection.d.ts.map +1 -0
- package/dist/providers/smartObject/useObjectSelection.js +27 -0
- package/dist/providers/smartObject/usePollingBackstop.d.ts +18 -0
- package/dist/providers/smartObject/usePollingBackstop.d.ts.map +1 -0
- package/dist/providers/smartObject/usePollingBackstop.js +38 -0
- package/dist/types/character.d.ts +21 -0
- package/dist/types/character.d.ts.map +1 -0
- package/dist/types/character.js +1 -0
- package/dist/types/contexts.d.ts +61 -0
- package/dist/types/contexts.d.ts.map +1 -0
- package/dist/types/contexts.js +6 -0
- package/dist/types/entity.d.ts +245 -0
- package/dist/types/entity.d.ts.map +1 -0
- package/dist/types/entity.js +6 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +5 -0
- package/dist/types/sponsoredTransaction.d.ts +26 -0
- package/dist/types/sponsoredTransaction.d.ts.map +1 -0
- package/dist/types/sponsoredTransaction.js +10 -0
- package/dist/types/types.d.ts +110 -0
- package/dist/types/types.d.ts.map +1 -0
- package/dist/types/types.js +41 -0
- package/dist/types/worldApiReturnTypes.d.ts +68 -0
- package/dist/types/worldApiReturnTypes.d.ts.map +1 -0
- package/dist/types/worldApiReturnTypes.js +1 -0
- package/{utils/burnRate.ts → dist/utils/burnRate.d.ts} +4 -29
- package/dist/utils/burnRate.d.ts.map +1 -0
- package/dist/utils/burnRate.js +25 -0
- package/dist/utils/characters.d.ts +26 -0
- package/dist/utils/characters.d.ts.map +1 -0
- package/dist/utils/characters.js +84 -0
- package/dist/utils/constants.d.ts +153 -0
- package/dist/utils/constants.d.ts.map +1 -0
- package/dist/utils/constants.js +190 -0
- package/dist/utils/datahub.d.ts +40 -0
- package/dist/utils/datahub.d.ts.map +1 -0
- package/{utils/datahub.ts → dist/utils/datahub.js} +32 -25
- package/dist/utils/entity.d.ts +58 -0
- package/dist/utils/entity.d.ts.map +1 -0
- package/dist/utils/entity.js +386 -0
- package/dist/utils/errors.d.ts +18 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/errors.js +128 -0
- package/dist/utils/events/entityEvents.d.ts +44 -0
- package/dist/utils/events/entityEvents.d.ts.map +1 -0
- package/dist/utils/events/entityEvents.js +95 -0
- package/dist/utils/events/entitySubscription.d.ts +30 -0
- package/dist/utils/events/entitySubscription.d.ts.map +1 -0
- package/dist/utils/events/entitySubscription.js +84 -0
- package/dist/utils/events/graphqlEventStream.d.ts +90 -0
- package/dist/utils/events/graphqlEventStream.d.ts.map +1 -0
- package/dist/utils/events/graphqlEventStream.js +198 -0
- package/dist/utils/events/refetchScheduler.d.ts +30 -0
- package/dist/utils/events/refetchScheduler.d.ts.map +1 -0
- package/dist/utils/events/refetchScheduler.js +57 -0
- package/dist/utils/events/sseClient.d.ts +42 -0
- package/dist/utils/events/sseClient.d.ts.map +1 -0
- package/dist/utils/events/sseClient.js +97 -0
- package/dist/utils/fuel.d.ts +231 -0
- package/dist/utils/fuel.d.ts.map +1 -0
- package/dist/utils/fuel.js +652 -0
- package/dist/utils/grid.d.ts +115 -0
- package/dist/utils/grid.d.ts.map +1 -0
- package/dist/utils/grid.js +115 -0
- package/dist/utils/index.d.ts +15 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +22 -0
- package/dist/utils/inventory.d.ts +3 -0
- package/dist/utils/inventory.d.ts.map +1 -0
- package/dist/utils/inventory.js +12 -0
- package/dist/utils/logger.d.ts +25 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +228 -0
- package/dist/utils/mapping.d.ts +30 -0
- package/dist/utils/mapping.d.ts.map +1 -0
- package/dist/utils/mapping.js +73 -0
- package/dist/utils/mvr/worldTypes.d.ts +35 -0
- package/dist/utils/mvr/worldTypes.d.ts.map +1 -0
- package/dist/utils/mvr/worldTypes.js +54 -0
- package/dist/utils/role.d.ts +116 -0
- package/dist/utils/role.d.ts.map +1 -0
- package/dist/utils/role.js +120 -0
- package/dist/utils/smartObject.d.ts +24 -0
- package/dist/utils/smartObject.d.ts.map +1 -0
- package/dist/utils/smartObject.js +24 -0
- package/dist/utils/utils.d.ts +133 -0
- package/dist/utils/utils.d.ts.map +1 -0
- package/dist/utils/utils.js +213 -0
- package/dist/wallet/features.d.ts +28 -0
- package/dist/wallet/features.d.ts.map +1 -0
- package/dist/wallet/features.js +22 -0
- package/dist/wallet/index.d.ts +9 -0
- package/dist/wallet/index.d.ts.map +1 -0
- package/dist/wallet/index.js +9 -0
- package/dist/wallet/utils.d.ts +71 -0
- package/dist/wallet/utils.d.ts.map +1 -0
- package/dist/wallet/utils.js +79 -0
- package/package.json +69 -35
- package/config/dapp-kit.ts +0 -20
- package/config/index.ts +0 -1
- package/graphql/client.ts +0 -578
- package/graphql/index.ts +0 -39
- package/graphql/types.ts +0 -468
- package/hooks/index.ts +0 -15
- package/hooks/useSmartObject.ts +0 -66
- package/hooks/useSponsoredTransaction.ts +0 -442
- package/index.ts +0 -88
- package/providers/EveFrontierProvider.tsx +0 -41
- package/providers/NotificationProvider.tsx +0 -108
- package/providers/SmartObjectProvider.tsx +0 -296
- package/providers/VaultProvider.tsx +0 -108
- package/providers/index.ts +0 -10
- package/types/contexts.ts +0 -67
- package/types/global.d.ts +0 -7
- package/types/index.ts +0 -4
- package/types/sponsoredTransaction.ts +0 -70
- package/types/types.ts +0 -198
- package/types/worldApiReturnTypes.ts +0 -144
- package/utils/__tests__/burnRate.test.ts +0 -121
- package/utils/__tests__/character.test.ts +0 -112
- package/utils/__tests__/characterOwnedObjects.test.ts +0 -225
- package/utils/__tests__/config.test.ts +0 -424
- package/utils/__tests__/datahub.test.ts +0 -58
- package/utils/__tests__/logger.test.ts +0 -145
- package/utils/__tests__/mapping.test.ts +0 -439
- package/utils/__tests__/utils.test.ts +0 -299
- package/utils/character.ts +0 -46
- package/utils/characterOwnedObjects.ts +0 -53
- package/utils/config.ts +0 -151
- package/utils/constants.ts +0 -254
- package/utils/errors.ts +0 -171
- package/utils/index.ts +0 -47
- package/utils/logger.ts +0 -300
- package/utils/mapping.ts +0 -118
- package/utils/transforms.ts +0 -263
- package/utils/utils.ts +0 -270
- package/wallet/features.ts +0 -136
- package/wallet/index.ts +0 -26
- package/wallet/utils.ts +0 -117
|
@@ -1,299 +0,0 @@
|
|
|
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
|
-
});
|
package/utils/character.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import type { CharacterInfo, RawCharacterData } from "../graphql/types";
|
|
2
|
-
|
|
3
|
-
function parseOptionalInt(value: unknown): number {
|
|
4
|
-
if (value == null) return 0;
|
|
5
|
-
if (typeof value === "number" && Number.isFinite(value)) return value;
|
|
6
|
-
if (typeof value === "string") {
|
|
7
|
-
const n = parseInt(value, 10);
|
|
8
|
-
return Number.isNaN(n) ? 0 : n;
|
|
9
|
-
}
|
|
10
|
-
return 0;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Normalize raw character JSON (from wallet/assembly GQL responses) into CharacterInfo.
|
|
15
|
-
* Accepts varying shapes; returns null when input is not a usable object.
|
|
16
|
-
*
|
|
17
|
-
* @param json - Raw JSON (e.g. from contents.json or extract...contents.json)
|
|
18
|
-
* @returns CharacterInfo or null
|
|
19
|
-
* @category Character Helpers
|
|
20
|
-
*/
|
|
21
|
-
export function parseCharacterFromJson(json: unknown): CharacterInfo | null {
|
|
22
|
-
if (json == null || typeof json !== "object" || Array.isArray(json)) {
|
|
23
|
-
return null;
|
|
24
|
-
}
|
|
25
|
-
const obj = json as Record<string, unknown>;
|
|
26
|
-
const metadata =
|
|
27
|
-
obj.metadata != null &&
|
|
28
|
-
typeof obj.metadata === "object" &&
|
|
29
|
-
!Array.isArray(obj.metadata)
|
|
30
|
-
? (obj.metadata as Record<string, unknown>)
|
|
31
|
-
: undefined;
|
|
32
|
-
const key =
|
|
33
|
-
obj.key != null && typeof obj.key === "object" && !Array.isArray(obj.key)
|
|
34
|
-
? (obj.key as Record<string, unknown>)
|
|
35
|
-
: undefined;
|
|
36
|
-
|
|
37
|
-
return {
|
|
38
|
-
id: typeof obj.id === "string" ? obj.id : "",
|
|
39
|
-
address:
|
|
40
|
-
typeof obj.character_address === "string" ? obj.character_address : "",
|
|
41
|
-
name: typeof metadata?.name === "string" ? metadata.name : "",
|
|
42
|
-
tribeId: parseOptionalInt(obj.tribe_id),
|
|
43
|
-
characterId: parseOptionalInt(key?.item_id),
|
|
44
|
-
_raw: json as RawCharacterData,
|
|
45
|
-
};
|
|
46
|
-
}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { getCharacterAndOwnedObjects } from "../graphql/client";
|
|
2
|
-
import type { GetCharacterAndOwnedObjectsResponse } from "../graphql/types";
|
|
3
|
-
import { createLogger } from "./logger";
|
|
4
|
-
|
|
5
|
-
const log = createLogger();
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Extracts the JSON payloads from the first character's owned objects
|
|
9
|
-
* (from getCharacterAndOwnedObjects response data).
|
|
10
|
-
*
|
|
11
|
-
* @param data - Response data from getCharacterAndOwnedObjects
|
|
12
|
-
* @returns Array of contents.json for each owned object, or undefined if missing
|
|
13
|
-
*
|
|
14
|
-
* @category Character Helpers
|
|
15
|
-
*/
|
|
16
|
-
export function getCharacterOwnedObjectsJson(
|
|
17
|
-
data: GetCharacterAndOwnedObjectsResponse | undefined,
|
|
18
|
-
): Record<string, unknown>[] | undefined {
|
|
19
|
-
const objects =
|
|
20
|
-
data?.address?.objects?.nodes?.[0]?.contents?.extract?.asAddress?.objects;
|
|
21
|
-
if (!objects?.nodes?.length) return undefined;
|
|
22
|
-
return objects.nodes.map(
|
|
23
|
-
(node) =>
|
|
24
|
-
node.contents.extract.asAddress.asObject.asMoveObject.contents.json,
|
|
25
|
-
);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Fetches the character and owned objects for an address, then returns the JSON
|
|
30
|
-
* payloads of the first character's owned objects.
|
|
31
|
-
*
|
|
32
|
-
* @param address - Wallet/signer address to query
|
|
33
|
-
* @returns Promise resolving to an array of contents.json per owned object, or undefined if none
|
|
34
|
-
*
|
|
35
|
-
* @category Character Helpers
|
|
36
|
-
*/
|
|
37
|
-
export async function getCharacterOwnedObjects(
|
|
38
|
-
address: string,
|
|
39
|
-
): Promise<Record<string, unknown>[] | undefined> {
|
|
40
|
-
const response = await getCharacterAndOwnedObjects(address).then(
|
|
41
|
-
(response) => {
|
|
42
|
-
const data = response.data;
|
|
43
|
-
if (!data) {
|
|
44
|
-
log.warn("[Dapp] No data returned from getCharacterAndOwnedObjects");
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
const ownedObjectsJson = getCharacterOwnedObjectsJson(data);
|
|
48
|
-
return ownedObjectsJson;
|
|
49
|
-
},
|
|
50
|
-
);
|
|
51
|
-
|
|
52
|
-
return response;
|
|
53
|
-
}
|
package/utils/config.ts
DELETED
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
import { getSingletonConfigObjectByType } from "../graphql/client";
|
|
2
|
-
import { getEnergyConfigType, getFuelEfficiencyConfigType } from "./constants";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Cached energy config: type_id -> energy usage (e.g. energy_constant).
|
|
6
|
-
* Populated from the on-chain EnergyConfig singleton.
|
|
7
|
-
*/
|
|
8
|
-
let energyConfigCache: Record<number, number> | null = null;
|
|
9
|
-
let fuelEfficiencyConfigCache: Record<number, number> | null = null;
|
|
10
|
-
|
|
11
|
-
/** In-flight promise for energy config so concurrent callers share one fetch. */
|
|
12
|
-
let energyConfigInFlight: Promise<Record<number, number>> | null = null;
|
|
13
|
-
/** In-flight promise for fuel efficiency config so concurrent callers share one fetch. */
|
|
14
|
-
let fuelEfficiencyConfigInFlight: Promise<Record<number, number>> | null = null;
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Resets in-memory and in-flight caches. Only for use in tests.
|
|
18
|
-
* @internal
|
|
19
|
-
*/
|
|
20
|
-
export function resetConfigCachesForTesting(): void {
|
|
21
|
-
energyConfigCache = null;
|
|
22
|
-
fuelEfficiencyConfigCache = null;
|
|
23
|
-
energyConfigInFlight = null;
|
|
24
|
-
fuelEfficiencyConfigInFlight = null;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Parses EnergyConfig or FuelConfig object JSON (contents + dynamic fields) into a map of typeId -> value (e.g. energy_constant or fuel_efficiency).
|
|
29
|
-
* Supports:
|
|
30
|
-
* - Dynamic fields where name is type_id (string/number) and contents.json has value
|
|
31
|
-
* - contents.json with a table/map of type_id -> value
|
|
32
|
-
*/
|
|
33
|
-
function parseConfig(
|
|
34
|
-
configJson: Record<string, unknown> | undefined,
|
|
35
|
-
): Record<number, number> {
|
|
36
|
-
const byTypeId: Record<number, number> = {};
|
|
37
|
-
const nodes = configJson as unknown as
|
|
38
|
-
| Array<{ key: { json: string }; value: { json: string } }>
|
|
39
|
-
| undefined;
|
|
40
|
-
if (!Array.isArray(nodes) || !nodes.length) return byTypeId;
|
|
41
|
-
for (const node of nodes) {
|
|
42
|
-
const typeId = parseInt(node.key?.json ?? "", 10);
|
|
43
|
-
if (Number.isNaN(typeId)) continue;
|
|
44
|
-
const energy = parseInt(node.value?.json ?? "", 10);
|
|
45
|
-
byTypeId[typeId] = Number.isNaN(energy) ? 0 : energy;
|
|
46
|
-
}
|
|
47
|
-
return byTypeId;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Fetches the EnergyConfig singleton via GraphQL (using getEnergyConfigType), parses it,
|
|
52
|
-
* caches the result, and returns the map of type_id -> energy usage.
|
|
53
|
-
* Subsequent calls return the cached map.
|
|
54
|
-
*
|
|
55
|
-
* @category Utilities - Config
|
|
56
|
-
*/
|
|
57
|
-
export async function getEnergyConfig(): Promise<Record<number, number>> {
|
|
58
|
-
if (energyConfigCache) {
|
|
59
|
-
return energyConfigCache;
|
|
60
|
-
}
|
|
61
|
-
if (energyConfigInFlight) {
|
|
62
|
-
return energyConfigInFlight;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
energyConfigInFlight = (async () => {
|
|
66
|
-
const result = await getSingletonConfigObjectByType(
|
|
67
|
-
getEnergyConfigType(),
|
|
68
|
-
"assembly_energy",
|
|
69
|
-
);
|
|
70
|
-
|
|
71
|
-
const energyConfigJson = result.data?.objects?.nodes[0]?.asMoveObject
|
|
72
|
-
?.contents?.extract?.extract?.asAddress?.addressAt?.dynamicFields
|
|
73
|
-
?.nodes as Record<string, unknown> | undefined;
|
|
74
|
-
|
|
75
|
-
energyConfigCache = parseConfig(energyConfigJson);
|
|
76
|
-
return energyConfigCache;
|
|
77
|
-
})();
|
|
78
|
-
|
|
79
|
-
try {
|
|
80
|
-
return await energyConfigInFlight;
|
|
81
|
-
} finally {
|
|
82
|
-
energyConfigInFlight = null;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Fetches the Fuel Efficiency Config singleton via GraphQL (using getFuelEfficiencyConfigType), parses it,
|
|
88
|
-
* caches the result, and returns the map of type_id -> fuel efficiency.
|
|
89
|
-
* Subsequent calls return the cached map.
|
|
90
|
-
*
|
|
91
|
-
* @category Utilities - Config
|
|
92
|
-
*/
|
|
93
|
-
export async function getFuelEfficiencyConfig(): Promise<
|
|
94
|
-
Record<number, number>
|
|
95
|
-
> {
|
|
96
|
-
if (fuelEfficiencyConfigCache) {
|
|
97
|
-
return fuelEfficiencyConfigCache;
|
|
98
|
-
}
|
|
99
|
-
if (fuelEfficiencyConfigInFlight) {
|
|
100
|
-
return fuelEfficiencyConfigInFlight;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
fuelEfficiencyConfigInFlight = (async () => {
|
|
104
|
-
const result = await getSingletonConfigObjectByType(
|
|
105
|
-
getFuelEfficiencyConfigType(),
|
|
106
|
-
"fuel_efficiency",
|
|
107
|
-
);
|
|
108
|
-
|
|
109
|
-
const fuelEfficiencyConfigJson = result.data?.objects?.nodes[0]
|
|
110
|
-
?.asMoveObject?.contents?.extract?.extract?.asAddress?.addressAt
|
|
111
|
-
?.dynamicFields?.nodes as Record<string, unknown> | undefined;
|
|
112
|
-
|
|
113
|
-
fuelEfficiencyConfigCache = parseConfig(fuelEfficiencyConfigJson);
|
|
114
|
-
return fuelEfficiencyConfigCache;
|
|
115
|
-
})();
|
|
116
|
-
|
|
117
|
-
try {
|
|
118
|
-
return await fuelEfficiencyConfigInFlight;
|
|
119
|
-
} finally {
|
|
120
|
-
fuelEfficiencyConfigInFlight = null;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* Returns the energy usage for a given assembly type ID from the on-chain EnergyConfig.
|
|
126
|
-
* Uses cached EnergyConfig data after the first fetch.
|
|
127
|
-
*
|
|
128
|
-
* @param typeId - In-game type ID (e.g. from rawData.type_id)
|
|
129
|
-
* @returns Energy usage (e.g. energy_constant), or 0 if not found or not yet loaded
|
|
130
|
-
* @category Utilities - Config
|
|
131
|
-
*/
|
|
132
|
-
export async function getEnergyUsageForType(typeId: number): Promise<number> {
|
|
133
|
-
const config = await getEnergyConfig();
|
|
134
|
-
|
|
135
|
-
return config[typeId] ?? 0;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* Returns the fuel efficiency for a given assembly type ID from the on-chain Fuel Efficiency Config.
|
|
140
|
-
* Uses cached Fuel Efficiency Config data after the first fetch.
|
|
141
|
-
*
|
|
142
|
-
* @param typeId - In-game type ID (e.g. from rawData.type_id)
|
|
143
|
-
* @returns Fuel efficiency (e.g. fuel_efficiency), or 0 if not found or not yet loaded
|
|
144
|
-
* @category Utilities - Config
|
|
145
|
-
*/
|
|
146
|
-
export async function getFuelEfficiencyForType(
|
|
147
|
-
typeId: number,
|
|
148
|
-
): Promise<number> {
|
|
149
|
-
const config = await getFuelEfficiencyConfig();
|
|
150
|
-
return config[typeId] ?? 0;
|
|
151
|
-
}
|