From 3e63503f3a6b2f2e1ae8b127fc6ae8451aac15f3 Mon Sep 17 00:00:00 2001 From: raschel <38816784+aymericdelab@users.noreply.github.com> Date: Sat, 11 Jan 2025 13:25:46 +0100 Subject: [PATCH] knip (#2635) * fix knip * fixed landing knip * fix knip balancing * knip --- .knip.json | 25 + client/.knip.json | 42 -- .../balancing/src/components/ui/badge.tsx | 6 +- .../balancing/src/components/ui/table.tsx | 2 +- client/apps/game/.eslintrc.json | 13 - client/apps/game/pwa-assets.config.ts | 6 - .../apps/game/src/dojo/contractComponents.ts | 2 - client/apps/game/src/dojo/debouncedQueries.ts | 41 -- client/apps/game/src/dojo/queries.ts | 50 -- client/apps/game/src/dojo/setup.ts | 2 +- client/apps/game/src/dojo/worker.ts | 56 -- .../src/hooks/context/mainnet-policies.tsx | 574 ------------------ .../apps/game/src/hooks/helpers/useQuests.tsx | 13 +- .../game/src/hooks/store/useQuestStore.tsx | 16 - .../game/src/hooks/store/useWorldLoading.tsx | 2 +- client/apps/game/src/hooks/useUISound.tsx | 156 +---- .../game/src/three/components/FogManager.ts | 32 - .../apps/game/src/three/scenes/constants.ts | 2 +- .../components/resources/realm-transfer.tsx | 2 +- client/apps/game/src/ui/elements/Switch.tsx | 27 - client/apps/game/src/ui/utils/utils.tsx | 4 +- client/apps/landing/env.ts | 3 - .../components/modules/bridge-out-step-1.tsx | 2 +- .../components/modules/bridge-out-step-2.tsx | 29 +- .../components/modules/bridged-resources.tsx | 2 +- .../modules/cartridge-connect-button.tsx | 64 -- .../src/components/modules/filters.tsx | 34 -- .../modules/guild-leaderboard-panel.tsx | 202 ------ .../src/components/modules/leaderboard.tsx | 41 -- .../src/components/modules/realm-card.tsx | 2 +- .../landing/src/components/ui/command.tsx | 132 ---- .../src/components/ui/custom-iframe.tsx | 42 -- .../landing/src/components/ui/utils/utils.ts | 2 +- client/apps/landing/src/config.ts | 8 +- .../landing/src/dojo/contractComponents.ts | 2 +- .../src/dojo/createClientComponents.ts | 2 +- client/apps/landing/src/dojo/queries.ts | 104 ---- .../landing/src/hooks/context/DojoContext.tsx | 4 +- client/apps/landing/src/hooks/get-guilds.tsx | 46 -- .../landing/src/hooks/gql/fragment-masking.ts | 4 +- .../src/hooks/helpers/use-contributions.tsx | 71 --- .../landing/src/hooks/helpers/useEntities.tsx | 6 +- .../landing/src/hooks/query/leaderboard.tsx | 16 - .../apps/landing/src/hooks/query/players.tsx | 8 - .../landing/src/hooks/use-entities-utils.tsx | 38 -- .../src/hooks/use-entity-resources.tsx | 0 .../landing/src/hooks/use-get-all-players.tsx | 78 --- .../landing/src/hooks/use-lords-bridged.tsx | 61 -- .../landing/src/hooks/use-realms-settled.tsx | 7 - .../landing/src/hooks/useCollectionTokens.tsx | 45 -- .../apps/landing/src/hooks/usePrizeClaim.tsx | 13 - .../src/lib/ark/getCollectionTokens.ts | 106 ---- client/apps/landing/src/lib/utils.ts | 195 +----- client/apps/landing/src/types/index.ts | 384 ------------ client/apps/landing/src/utils/leaderboard.tsx | 12 - client/apps/landing/tsconfig.app.tsbuildinfo | 114 +++- client/config/speed.ts | 11 - .../{components => }/contractComponents.ts | 0 .../createClientComponents.ts | 0 client/sdk/packages/eternum/src/dojo/index.ts | 2 + client/sdk/packages/eternum/src/index.ts | 1 + .../eternum/src/modelManager/ArmyManager.ts | 2 +- .../src/modelManager/ArmyMovementManager.ts | 2 +- .../eternum/src/modelManager/BattleManager.ts | 2 +- .../eternum/src/modelManager/ConfigManager.ts | 2 +- .../src/modelManager/LeaderboardManager.ts | 4 +- .../eternum/src/modelManager/MarketManager.ts | 2 +- .../modelManager/ResourceInventoryManager.ts | 2 +- .../src/modelManager/ResourceManager.ts | 2 +- .../src/modelManager/StaminaManager.ts | 2 +- .../eternum/src/modelManager/TileManager.ts | 2 +- .../eternum/src/modelManager/types/index.ts | 2 +- .../modelManager/utils/ArmyMovementUtils.ts | 2 +- .../modelManager/utils/LeaderboardUtils.ts | 2 +- .../packages/eternum/src/scripts/extract.ts | 97 --- .../eternum/src/scripts/extractBuildings.ts | 22 - 76 files changed, 187 insertions(+), 2926 deletions(-) create mode 100644 .knip.json delete mode 100644 client/.knip.json delete mode 100644 client/apps/game/.eslintrc.json delete mode 100644 client/apps/game/pwa-assets.config.ts delete mode 100644 client/apps/game/src/dojo/worker.ts delete mode 100644 client/apps/game/src/hooks/context/mainnet-policies.tsx delete mode 100644 client/apps/game/src/hooks/store/useQuestStore.tsx delete mode 100644 client/apps/game/src/three/components/FogManager.ts delete mode 100644 client/apps/game/src/ui/elements/Switch.tsx delete mode 100644 client/apps/landing/src/components/modules/cartridge-connect-button.tsx delete mode 100644 client/apps/landing/src/components/modules/filters.tsx delete mode 100644 client/apps/landing/src/components/modules/guild-leaderboard-panel.tsx delete mode 100644 client/apps/landing/src/components/modules/leaderboard.tsx delete mode 100644 client/apps/landing/src/components/ui/command.tsx delete mode 100644 client/apps/landing/src/components/ui/custom-iframe.tsx delete mode 100644 client/apps/landing/src/dojo/queries.ts delete mode 100644 client/apps/landing/src/hooks/get-guilds.tsx delete mode 100644 client/apps/landing/src/hooks/helpers/use-contributions.tsx delete mode 100644 client/apps/landing/src/hooks/query/players.tsx delete mode 100644 client/apps/landing/src/hooks/use-entities-utils.tsx delete mode 100644 client/apps/landing/src/hooks/use-entity-resources.tsx delete mode 100644 client/apps/landing/src/hooks/use-get-all-players.tsx delete mode 100644 client/apps/landing/src/hooks/use-realms-settled.tsx delete mode 100644 client/apps/landing/src/hooks/useCollectionTokens.tsx delete mode 100644 client/apps/landing/src/lib/ark/getCollectionTokens.ts delete mode 100644 client/apps/landing/src/utils/leaderboard.tsx delete mode 100644 client/config/speed.ts rename client/sdk/packages/eternum/src/dojo/{components => }/contractComponents.ts (100%) rename client/sdk/packages/eternum/src/dojo/{components => }/createClientComponents.ts (100%) create mode 100644 client/sdk/packages/eternum/src/dojo/index.ts delete mode 100644 client/sdk/packages/eternum/src/scripts/extract.ts delete mode 100644 client/sdk/packages/eternum/src/scripts/extractBuildings.ts diff --git a/.knip.json b/.knip.json new file mode 100644 index 000000000..b4b33132d --- /dev/null +++ b/.knip.json @@ -0,0 +1,25 @@ +{ + "ignore": [ + "eliza/**", + + "**/*.js", + "**/vitest**", + "client/apps/game/src/setupTests.ts", + + "client/sdk/packages/eternum/global.d.ts", + + "**/**__test__**/**", + "**/**__tests__**/**", + + "client/apps/landing/src/routeTree.gen.ts", + "client/apps/landing/src/components/ui/**", + "client/apps/landing/src/components/typography/**", + "client/apps/landing/src/hooks/gql/**", + + "client/apps/game-docs/vocs.config.ts", + "client/apps/game-docs/docs/**", + "client/apps/game-docs/vocs.config.ts", + + "client/apps/game/src/ui/modules/chat/**" + ] +} diff --git a/client/.knip.json b/client/.knip.json deleted file mode 100644 index cbdd51f80..000000000 --- a/client/.knip.json +++ /dev/null @@ -1,42 +0,0 @@ -{ - "entry": ["eternum-docs/**/*.mdx", "eternum-docs/**/*.tsx"], - "ignore": [ - "eliza/**", - - ".trunk/**", - "**/*.js", - "bot/**", - "**/vitest**", - - "eternum-docs/vocs.config.ts", - - "sdk/packages/eternum/global.d.ts", - "config/bank/index.ts", - "config/speed.ts", - - "**/**__test__**/**", - "**/**__tests__**/**", - - "season_resources/scripts/deployment/config/index.ts", - "season_resources/scripts/deployment/config/provider/index.ts", - - "client/src/three/components/FogManager.ts", - "client/src/hooks/useUISound.tsx", - "balancing/**", - "landing/**", - "client/pwa-assets.config.ts", - - "docs/components/**", - "docs/utils/**", - "vocs.config.ts", - - "client/src/ui/modules/chat/types.tsx", - "client/src/ui/modules/chat/constants.tsx", - "client/src/ui/modules/chat/ChatTab.tsx", - "client/src/hooks/helpers/useGetAllPlayers.tsx", - "client/src/ui/modules/chat/InputField.tsx", - "client/src/ui/modules/chat/Chat.tsx", - "sdk/packages/eternum/src/scripts/extract.ts", - "sdk/packages/eternum/src/scripts/extractBuildings.ts" - ] -} diff --git a/client/apps/balancing/src/components/ui/badge.tsx b/client/apps/balancing/src/components/ui/badge.tsx index 10c5d3f47..418a26e8a 100644 --- a/client/apps/balancing/src/components/ui/badge.tsx +++ b/client/apps/balancing/src/components/ui/badge.tsx @@ -1,5 +1,5 @@ -import * as React from "react"; import { cva, type VariantProps } from "class-variance-authority"; +import * as React from "react"; import { cn } from "@/lib/utils"; @@ -20,10 +20,10 @@ const badgeVariants = cva( }, ); -export interface BadgeProps extends React.HTMLAttributes, VariantProps {} +interface BadgeProps extends React.HTMLAttributes, VariantProps {} function Badge({ className, variant, ...props }: BadgeProps) { return
; } -export { Badge, badgeVariants }; +export { Badge }; diff --git a/client/apps/balancing/src/components/ui/table.tsx b/client/apps/balancing/src/components/ui/table.tsx index 1f70268eb..6c32ac9f8 100644 --- a/client/apps/balancing/src/components/ui/table.tsx +++ b/client/apps/balancing/src/components/ui/table.tsx @@ -73,4 +73,4 @@ const TableCaption = React.forwardRef; - export function defineContractComponents(world: World) { return { AddressName: (() => { diff --git a/client/apps/game/src/dojo/debouncedQueries.ts b/client/apps/game/src/dojo/debouncedQueries.ts index ea350511a..4fbd5fec3 100644 --- a/client/apps/game/src/dojo/debouncedQueries.ts +++ b/client/apps/game/src/dojo/debouncedQueries.ts @@ -7,8 +7,6 @@ import { addMarketSubscription, addToSubscription, addToSubscriptionOneKeyModelbyRealmEntityId, - addToSubscriptionTwoKeyModelbyRealmEntityId, - syncPosition, } from "./queries"; // Queue class to manage requests @@ -52,40 +50,9 @@ class RequestQueue { } } -// Create separate queues for different types of requests -const positionQueue = new RequestQueue(); const subscriptionQueue = new RequestQueue(); const marketQueue = new RequestQueue(); const hyperstructureQueue = new RequestQueue(); -// Debounced functions that add to queues -export const debouncedSyncPosition = debounce( - async ( - client: ToriiClient, - components: Component[], - entityID: string, - onComplete?: () => void, - ) => { - await positionQueue.add(() => syncPosition(client, components, entityID), onComplete); - }, - 100, - { leading: true }, // Add leading: true to execute immediately on first call -); - -export const debouncedAddToSubscriptionTwoKey = debounce( - async ( - client: ToriiClient, - components: Component[], - entityID: string[], - onComplete?: () => void, - ) => { - await subscriptionQueue.add( - () => addToSubscriptionTwoKeyModelbyRealmEntityId(client, components, entityID), - onComplete, - ); - }, - 250, - { leading: true }, -); export const debouncedAddToSubscriptionOneKey = debounce( async ( @@ -153,11 +120,3 @@ export const debouncedAddHyperstructureSubscription = debounce( 500, { leading: true }, ); - -// Utility function to clear all queues if needed -export const clearAllQueues = () => { - positionQueue.clear(); - subscriptionQueue.clear(); - marketQueue.clear(); - hyperstructureQueue.clear(); -}; diff --git a/client/apps/game/src/dojo/queries.ts b/client/apps/game/src/dojo/queries.ts index 99575f481..7b8fb219a 100644 --- a/client/apps/game/src/dojo/queries.ts +++ b/client/apps/game/src/dojo/queries.ts @@ -7,56 +7,6 @@ import { PatternMatching, ToriiClient } from "@dojoengine/torii-client"; // on hexception -> fetch below queries based on entityID // background sync after load -> - -export const syncPosition = async ( - client: ToriiClient, - components: Component[], - entityID: string, -) => { - await getEntities( - client, - { - Keys: { - keys: [entityID], - pattern_matching: "FixedLen" as PatternMatching, - models: ["s0_eternum-Position"], - }, - }, - components, - [], - [], - 5_000, - ); -}; - -export const addToSubscriptionTwoKeyModelbyRealmEntityId = async ( - client: ToriiClient, - components: Component[], - entityID: string[], -) => { - await getEntities( - client, - { - Composite: { - operator: "Or", - clauses: [ - ...entityID.map((id) => ({ - Keys: { - keys: [id, undefined], - pattern_matching: "VariableLen" as PatternMatching, - models: ["s0_eternum-BuildingQuantityv2"], - }, - })), - ], - }, - }, - components, - [], - [], - 5_000, - ); -}; - export const addToSubscriptionOneKeyModelbyRealmEntityId = async ( client: ToriiClient, components: Component[], diff --git a/client/apps/game/src/dojo/setup.ts b/client/apps/game/src/dojo/setup.ts index 0a2882286..a2bed67bd 100644 --- a/client/apps/game/src/dojo/setup.ts +++ b/client/apps/game/src/dojo/setup.ts @@ -19,7 +19,7 @@ export type SetupResult = Awaited>; export const configManager = ClientConfigManager.instance(); -export const syncEntitiesDebounced = async ( +const syncEntitiesDebounced = async ( client: ToriiClient, components: Component[], entityKeyClause: EntityKeysClause[], diff --git a/client/apps/game/src/dojo/worker.ts b/client/apps/game/src/dojo/worker.ts deleted file mode 100644 index 39e2a54f1..000000000 --- a/client/apps/game/src/dojo/worker.ts +++ /dev/null @@ -1,56 +0,0 @@ -import { Component, Metadata, Schema } from "@dojoengine/recs"; -import { setEntities } from "@dojoengine/state"; -import { EntityKeysClause, createClient } from "@dojoengine/torii-wasm"; - -export async function setupWorker( - config: { rpcUrl: string; toriiUrl: string; relayUrl: string; worldAddress: string }, - components: Component[], - entityKeyClause: EntityKeysClause[], - historical: boolean, - logging = false, -) { - if (logging) console.log("Starting syncEntities"); - - const worker = new Worker(new URL("./entityWorker.js", import.meta.url), { type: "module" }); - - // Create the client in the main thread - const toriiClient = await createClient({ - rpcUrl: config.rpcUrl, - toriiUrl: config.toriiUrl, - relayUrl: config.relayUrl, - worldAddress: config.worldAddress, - }); - - // Listen for batches from the Worker - worker.onmessage = (event) => { - const { updatedEntities } = event.data; - setEntities(updatedEntities, components, logging); - }; - - // Set up subscriptions in the main thread - await toriiClient.onEntityUpdated(entityKeyClause, (fetchedEntities: any, data: any) => { - if (logging) console.log("Main: Entity updated", fetchedEntities); - // Send updates to worker for processing - worker.postMessage({ - type: "update", - entities: { fetchedEntities, data }, - logging, - }); - }); - - await toriiClient.onEventMessageUpdated(entityKeyClause, historical, (fetchedEntities: any, data: any) => { - if (logging) console.log("Main: Event message updated", fetchedEntities); - // Send updates to worker for processing - worker.postMessage({ - type: "update", - entities: { fetchedEntities, data }, - logging, - }); - }); - - return { - cancel: () => { - worker.terminate(); - }, - }; -} diff --git a/client/apps/game/src/hooks/context/mainnet-policies.tsx b/client/apps/game/src/hooks/context/mainnet-policies.tsx deleted file mode 100644 index f0587b11e..000000000 --- a/client/apps/game/src/hooks/context/mainnet-policies.tsx +++ /dev/null @@ -1,574 +0,0 @@ -export const mainnetPolicies = [ - { - target: "0x7f4862123d52dffae89ec3fb4557690cd7fe2e92c9bf48d3bf8e44abfeafcf4", - method: "dojo_name", - }, - { - target: "0x7f4862123d52dffae89ec3fb4557690cd7fe2e92c9bf48d3bf8e44abfeafcf4", - method: "change_owner_amm_fee", - }, - { - target: "0x7f4862123d52dffae89ec3fb4557690cd7fe2e92c9bf48d3bf8e44abfeafcf4", - method: "change_owner_bridge_fee", - }, - { - target: "0x7f4862123d52dffae89ec3fb4557690cd7fe2e92c9bf48d3bf8e44abfeafcf4", - method: "world_dispatcher", - }, - { - target: "0x4ed3a7c5f53c6e96186eaf1b670bd2e2a3699c08e070aedf4e5fc6ac246ddc1", - method: "dojo_name", - }, - { - target: "0x4ed3a7c5f53c6e96186eaf1b670bd2e2a3699c08e070aedf4e5fc6ac246ddc1", - method: "battle_pillage", - }, - { - target: "0x4ed3a7c5f53c6e96186eaf1b670bd2e2a3699c08e070aedf4e5fc6ac246ddc1", - method: "world_dispatcher", - }, - { - target: "0x2620f65aa2fd72d705306ada1ee7410023a3df03da9291f1ccb744fabfebc0", - method: "dojo_name", - }, - { - target: "0x2620f65aa2fd72d705306ada1ee7410023a3df03da9291f1ccb744fabfebc0", - method: "battle_start", - }, - { - target: "0x2620f65aa2fd72d705306ada1ee7410023a3df03da9291f1ccb744fabfebc0", - method: "battle_force_start", - }, - { - target: "0x2620f65aa2fd72d705306ada1ee7410023a3df03da9291f1ccb744fabfebc0", - method: "battle_join", - }, - { - target: "0x2620f65aa2fd72d705306ada1ee7410023a3df03da9291f1ccb744fabfebc0", - method: "battle_leave", - }, - { - target: "0x2620f65aa2fd72d705306ada1ee7410023a3df03da9291f1ccb744fabfebc0", - method: "battle_claim", - }, - { - target: "0x2620f65aa2fd72d705306ada1ee7410023a3df03da9291f1ccb744fabfebc0", - method: "battle_resolve", - }, - { - target: "0x2620f65aa2fd72d705306ada1ee7410023a3df03da9291f1ccb744fabfebc0", - method: "world_dispatcher", - }, - { - target: "0x6bf57710571fd159e71b1ed155bb0759027e416c88a06556f321c94c214e768", - method: "dojo_name", - }, - { - target: "0x6bf57710571fd159e71b1ed155bb0759027e416c88a06556f321c94c214e768", - method: "leave_battle", - }, - { - target: "0x6bf57710571fd159e71b1ed155bb0759027e416c88a06556f321c94c214e768", - method: "leave_battle_if_ended", - }, - { - target: "0x6bf57710571fd159e71b1ed155bb0759027e416c88a06556f321c94c214e768", - method: "world_dispatcher", - }, - { - target: "0x4b6a35c0c541467674ebb9640113a6d79c6f5a468796e9299b8e484a770032a", - method: "dojo_name", - }, - { - target: "0x4b6a35c0c541467674ebb9640113a6d79c6f5a468796e9299b8e484a770032a", - method: "create", - }, - { - target: "0x4b6a35c0c541467674ebb9640113a6d79c6f5a468796e9299b8e484a770032a", - method: "pause_production", - }, - { - target: "0x4b6a35c0c541467674ebb9640113a6d79c6f5a468796e9299b8e484a770032a", - method: "resume_production", - }, - { - target: "0x4b6a35c0c541467674ebb9640113a6d79c6f5a468796e9299b8e484a770032a", - method: "destroy", - }, - { - target: "0x4b6a35c0c541467674ebb9640113a6d79c6f5a468796e9299b8e484a770032a", - method: "world_dispatcher", - }, - { - target: "0x421446d51cac1e926cb1a2b00ae318b52df71beb737159d5c1d7061030758cf", - method: "dojo_name", - }, - { - target: "0x421446d51cac1e926cb1a2b00ae318b52df71beb737159d5c1d7061030758cf", - method: "set_world_config", - }, - { - target: "0x421446d51cac1e926cb1a2b00ae318b52df71beb737159d5c1d7061030758cf", - method: "set_season_config", - }, - { - target: "0x421446d51cac1e926cb1a2b00ae318b52df71beb737159d5c1d7061030758cf", - method: "set_season_bridge_config", - }, - { - target: "0x421446d51cac1e926cb1a2b00ae318b52df71beb737159d5c1d7061030758cf", - method: "set_vrf_config", - }, - { - target: "0x421446d51cac1e926cb1a2b00ae318b52df71beb737159d5c1d7061030758cf", - method: "set_quest_config", - }, - { - target: "0x421446d51cac1e926cb1a2b00ae318b52df71beb737159d5c1d7061030758cf", - method: "set_quest_reward_config", - }, - { - target: "0x421446d51cac1e926cb1a2b00ae318b52df71beb737159d5c1d7061030758cf", - method: "set_map_config", - }, - { - target: "0x421446d51cac1e926cb1a2b00ae318b52df71beb737159d5c1d7061030758cf", - method: "set_capacity_config", - }, - { - target: "0x421446d51cac1e926cb1a2b00ae318b52df71beb737159d5c1d7061030758cf", - method: "set_travel_stamina_cost_config", - }, - { - target: "0x421446d51cac1e926cb1a2b00ae318b52df71beb737159d5c1d7061030758cf", - method: "set_weight_config", - }, - { - target: "0x421446d51cac1e926cb1a2b00ae318b52df71beb737159d5c1d7061030758cf", - method: "set_battle_config", - }, - { - target: "0x421446d51cac1e926cb1a2b00ae318b52df71beb737159d5c1d7061030758cf", - method: "set_tick_config", - }, - { - target: "0x421446d51cac1e926cb1a2b00ae318b52df71beb737159d5c1d7061030758cf", - method: "set_stamina_config", - }, - { - target: "0x421446d51cac1e926cb1a2b00ae318b52df71beb737159d5c1d7061030758cf", - method: "set_travel_food_cost_config", - }, - { - target: "0x421446d51cac1e926cb1a2b00ae318b52df71beb737159d5c1d7061030758cf", - method: "set_stamina_refill_config", - }, - { - target: "0x421446d51cac1e926cb1a2b00ae318b52df71beb737159d5c1d7061030758cf", - method: "set_leveling_config", - }, - { - target: "0x421446d51cac1e926cb1a2b00ae318b52df71beb737159d5c1d7061030758cf", - method: "set_production_config", - }, - { - target: "0x421446d51cac1e926cb1a2b00ae318b52df71beb737159d5c1d7061030758cf", - method: "set_speed_config", - }, - { - target: "0x421446d51cac1e926cb1a2b00ae318b52df71beb737159d5c1d7061030758cf", - method: "set_hyperstructure_config", - }, - { - target: "0x421446d51cac1e926cb1a2b00ae318b52df71beb737159d5c1d7061030758cf", - method: "set_bank_config", - }, - { - target: "0x421446d51cac1e926cb1a2b00ae318b52df71beb737159d5c1d7061030758cf", - method: "set_troop_config", - }, - { - target: "0x421446d51cac1e926cb1a2b00ae318b52df71beb737159d5c1d7061030758cf", - method: "set_building_category_pop_config", - }, - { - target: "0x421446d51cac1e926cb1a2b00ae318b52df71beb737159d5c1d7061030758cf", - method: "set_population_config", - }, - { - target: "0x421446d51cac1e926cb1a2b00ae318b52df71beb737159d5c1d7061030758cf", - method: "set_building_general_config", - }, - { - target: "0x421446d51cac1e926cb1a2b00ae318b52df71beb737159d5c1d7061030758cf", - method: "set_building_config", - }, - { - target: "0x421446d51cac1e926cb1a2b00ae318b52df71beb737159d5c1d7061030758cf", - method: "set_mercenaries_config", - }, - { - target: "0x421446d51cac1e926cb1a2b00ae318b52df71beb737159d5c1d7061030758cf", - method: "set_resource_bridge_config", - }, - { - target: "0x421446d51cac1e926cb1a2b00ae318b52df71beb737159d5c1d7061030758cf", - method: "set_resource_bridge_fee_split_config", - }, - { - target: "0x421446d51cac1e926cb1a2b00ae318b52df71beb737159d5c1d7061030758cf", - method: "set_resource_bridge_whitelist_config", - }, - { - target: "0x421446d51cac1e926cb1a2b00ae318b52df71beb737159d5c1d7061030758cf", - method: "set_realm_max_level_config", - }, - { - target: "0x421446d51cac1e926cb1a2b00ae318b52df71beb737159d5c1d7061030758cf", - method: "set_realm_level_config", - }, - { - target: "0x421446d51cac1e926cb1a2b00ae318b52df71beb737159d5c1d7061030758cf", - method: "set_settlement_config", - }, - { - target: "0x421446d51cac1e926cb1a2b00ae318b52df71beb737159d5c1d7061030758cf", - method: "world_dispatcher", - }, - { - target: "0xee829901be444844e0771a0c793b106c3192c312c8e58685f7c6941893b5f9", - method: "dojo_name", - }, - { - target: "0xee829901be444844e0771a0c793b106c3192c312c8e58685f7c6941893b5f9", - method: "create_admin_bank", - }, - { - target: "0xee829901be444844e0771a0c793b106c3192c312c8e58685f7c6941893b5f9", - method: "world_dispatcher", - }, - { - target: "0x729222a8e3757daec72d37dd434a3a44d3c0bddbec95cf087fb1b983b166b1a", - method: "dojo_name", - }, - { - target: "0x729222a8e3757daec72d37dd434a3a44d3c0bddbec95cf087fb1b983b166b1a", - method: "create", - }, - { - target: "0x729222a8e3757daec72d37dd434a3a44d3c0bddbec95cf087fb1b983b166b1a", - method: "world_dispatcher", - }, - { - target: "0x17410a6c37040ef285251f763799939f69033c69c6d5f9ddb61ff4a139d3f58", - method: "dojo_name", - }, - { - target: "0x17410a6c37040ef285251f763799939f69033c69c6d5f9ddb61ff4a139d3f58", - method: "mint", - }, - { - target: "0x17410a6c37040ef285251f763799939f69033c69c6d5f9ddb61ff4a139d3f58", - method: "world_dispatcher", - }, - { - target: "0x68a2cb801dc504acb121c7609d13f1f4bea6739dc80c31d789868ebda339067", - method: "dojo_name", - }, - { - target: "0x68a2cb801dc504acb121c7609d13f1f4bea6739dc80c31d789868ebda339067", - method: "world_dispatcher", - }, - { - target: "0x57d514154bb4dc319539d4e338312a41c248fb6a5122f82b2f2e11ddd3e67e4", - method: "dojo_name", - }, - { - target: "0x57d514154bb4dc319539d4e338312a41c248fb6a5122f82b2f2e11ddd3e67e4", - method: "create_guild", - }, - { - target: "0x57d514154bb4dc319539d4e338312a41c248fb6a5122f82b2f2e11ddd3e67e4", - method: "join_guild", - }, - { - target: "0x57d514154bb4dc319539d4e338312a41c248fb6a5122f82b2f2e11ddd3e67e4", - method: "whitelist_player", - }, - { - target: "0x57d514154bb4dc319539d4e338312a41c248fb6a5122f82b2f2e11ddd3e67e4", - method: "transfer_guild_ownership", - }, - { - target: "0x57d514154bb4dc319539d4e338312a41c248fb6a5122f82b2f2e11ddd3e67e4", - method: "remove_guild_member", - }, - { - target: "0x57d514154bb4dc319539d4e338312a41c248fb6a5122f82b2f2e11ddd3e67e4", - method: "remove_player_from_whitelist", - }, - { - target: "0x57d514154bb4dc319539d4e338312a41c248fb6a5122f82b2f2e11ddd3e67e4", - method: "world_dispatcher", - }, - { - target: "0x2fcc3c1691387321c2f4d6310eda7a14365bd274c1a37ed3948d2e93a56f821", - method: "dojo_name", - }, - { - target: "0x2fcc3c1691387321c2f4d6310eda7a14365bd274c1a37ed3948d2e93a56f821", - method: "get_points", - }, - { - target: "0x2fcc3c1691387321c2f4d6310eda7a14365bd274c1a37ed3948d2e93a56f821", - method: "create", - }, - { - target: "0x2fcc3c1691387321c2f4d6310eda7a14365bd274c1a37ed3948d2e93a56f821", - method: "contribute_to_construction", - }, - { - target: "0x2fcc3c1691387321c2f4d6310eda7a14365bd274c1a37ed3948d2e93a56f821", - method: "set_co_owners", - }, - { - target: "0x2fcc3c1691387321c2f4d6310eda7a14365bd274c1a37ed3948d2e93a56f821", - method: "end_game", - }, - { - target: "0x2fcc3c1691387321c2f4d6310eda7a14365bd274c1a37ed3948d2e93a56f821", - method: "set_access", - }, - { - target: "0x2fcc3c1691387321c2f4d6310eda7a14365bd274c1a37ed3948d2e93a56f821", - method: "world_dispatcher", - }, - { - target: "0xa052c5ca082356bcc8457f0f805eaf18f97d0fdddde3f90f5b238923859ed4", - method: "dojo_name", - }, - { - target: "0xa052c5ca082356bcc8457f0f805eaf18f97d0fdddde3f90f5b238923859ed4", - method: "add", - }, - { - target: "0xa052c5ca082356bcc8457f0f805eaf18f97d0fdddde3f90f5b238923859ed4", - method: "remove", - }, - { - target: "0xa052c5ca082356bcc8457f0f805eaf18f97d0fdddde3f90f5b238923859ed4", - method: "world_dispatcher", - }, - { - target: "0x7f274766f8f7fb0503d3d72b15a4d853f6189402a2ad1c9780fc7a1b017f678", - method: "dojo_name", - }, - { - target: "0x7f274766f8f7fb0503d3d72b15a4d853f6189402a2ad1c9780fc7a1b017f678", - method: "discover_shards_mine", - }, - { - target: "0x7f274766f8f7fb0503d3d72b15a4d853f6189402a2ad1c9780fc7a1b017f678", - method: "add_mercenaries_to_structure", - }, - { - target: "0x7f274766f8f7fb0503d3d72b15a4d853f6189402a2ad1c9780fc7a1b017f678", - method: "world_dispatcher", - }, - { - target: "0x4a212c52c4035bc9bd170125216604f406dcd75b41be11d3b4d89047366d84d", - method: "dojo_name", - }, - { - target: "0x4a212c52c4035bc9bd170125216604f406dcd75b41be11d3b4d89047366d84d", - method: "explore", - }, - { - target: "0x4a212c52c4035bc9bd170125216604f406dcd75b41be11d3b4d89047366d84d", - method: "world_dispatcher", - }, - { - target: "0x7e3bae0e253a0131063b63ee4d7b27b50329c617ae88b82d529a70f1a11c63", - method: "dojo_name", - }, - { - target: "0x7e3bae0e253a0131063b63ee4d7b27b50329c617ae88b82d529a70f1a11c63", - method: "set_address_name", - }, - { - target: "0x7e3bae0e253a0131063b63ee4d7b27b50329c617ae88b82d529a70f1a11c63", - method: "set_entity_name", - }, - { - target: "0x7e3bae0e253a0131063b63ee4d7b27b50329c617ae88b82d529a70f1a11c63", - method: "world_dispatcher", - }, - { - target: "0x30516789ee1b822d7b448f01be67cec7bf383d3ac4b2380a09f85ad0765f846", - method: "dojo_name", - }, - { - target: "0x30516789ee1b822d7b448f01be67cec7bf383d3ac4b2380a09f85ad0765f846", - method: "transfer_ownership", - }, - { - target: "0x30516789ee1b822d7b448f01be67cec7bf383d3ac4b2380a09f85ad0765f846", - method: "world_dispatcher", - }, - { - target: "0x1b480f620ea35431ab43dba634795b14f547ef3e77370db6f0a31f2fdc21d86", - method: "dojo_name", - }, - { - target: "0x1b480f620ea35431ab43dba634795b14f547ef3e77370db6f0a31f2fdc21d86", - method: "create", - }, - { - target: "0x1b480f620ea35431ab43dba634795b14f547ef3e77370db6f0a31f2fdc21d86", - method: "upgrade_level", - }, - { - target: "0x1b480f620ea35431ab43dba634795b14f547ef3e77370db6f0a31f2fdc21d86", - method: "quest_claim", - }, - { - target: "0x1b480f620ea35431ab43dba634795b14f547ef3e77370db6f0a31f2fdc21d86", - method: "world_dispatcher", - }, - { - target: "0x691a60b709ca5c1c5ff86824831f84deb26f0f5d07d70c0f807eab48110d2f6", - method: "dojo_name", - }, - { - target: "0x691a60b709ca5c1c5ff86824831f84deb26f0f5d07d70c0f807eab48110d2f6", - method: "deposit_initial", - }, - { - target: "0x691a60b709ca5c1c5ff86824831f84deb26f0f5d07d70c0f807eab48110d2f6", - method: "deposit", - }, - { - target: "0x691a60b709ca5c1c5ff86824831f84deb26f0f5d07d70c0f807eab48110d2f6", - method: "start_withdraw", - }, - { - target: "0x691a60b709ca5c1c5ff86824831f84deb26f0f5d07d70c0f807eab48110d2f6", - method: "finish_withdraw", - }, - { - target: "0x691a60b709ca5c1c5ff86824831f84deb26f0f5d07d70c0f807eab48110d2f6", - method: "world_dispatcher", - }, - { - target: "0x42c0303a2119a9e20daa60e83c48221cdf1bb2a4c009bab031d1cd3555a127e", - method: "dojo_name", - }, - { - target: "0x42c0303a2119a9e20daa60e83c48221cdf1bb2a4c009bab031d1cd3555a127e", - method: "approve", - }, - { - target: "0x42c0303a2119a9e20daa60e83c48221cdf1bb2a4c009bab031d1cd3555a127e", - method: "send", - }, - { - target: "0x42c0303a2119a9e20daa60e83c48221cdf1bb2a4c009bab031d1cd3555a127e", - method: "pickup", - }, - { - target: "0x42c0303a2119a9e20daa60e83c48221cdf1bb2a4c009bab031d1cd3555a127e", - method: "world_dispatcher", - }, - { - target: "0x4b5e65a9617c7ba3c7ea64324ff4338a400adb1a3cfe903b3f8b647cbb59fb7", - method: "dojo_name", - }, - { - target: "0x4b5e65a9617c7ba3c7ea64324ff4338a400adb1a3cfe903b3f8b647cbb59fb7", - method: "register_to_leaderboard", - }, - { - target: "0x4b5e65a9617c7ba3c7ea64324ff4338a400adb1a3cfe903b3f8b647cbb59fb7", - method: "claim_leaderboard_rewards", - }, - { - target: "0x4b5e65a9617c7ba3c7ea64324ff4338a400adb1a3cfe903b3f8b647cbb59fb7", - method: "world_dispatcher", - }, - { - target: "0x4f92a1d00d3aec8cece60fc2d0fc236fe1d95c54ff0ceb2f393fbc7e0863d8e", - method: "dojo_name", - }, - { - target: "0x4f92a1d00d3aec8cece60fc2d0fc236fe1d95c54ff0ceb2f393fbc7e0863d8e", - method: "buy", - }, - { - target: "0x4f92a1d00d3aec8cece60fc2d0fc236fe1d95c54ff0ceb2f393fbc7e0863d8e", - method: "sell", - }, - { - target: "0x4f92a1d00d3aec8cece60fc2d0fc236fe1d95c54ff0ceb2f393fbc7e0863d8e", - method: "world_dispatcher", - }, - { - target: "0x7e2b1334398fafbe640f34bacae99b649d633417960ee397b6a8fb117fec819", - method: "dojo_name", - }, - { - target: "0x7e2b1334398fafbe640f34bacae99b649d633417960ee397b6a8fb117fec819", - method: "create_order", - }, - { - target: "0x7e2b1334398fafbe640f34bacae99b649d633417960ee397b6a8fb117fec819", - method: "accept_order", - }, - { - target: "0x7e2b1334398fafbe640f34bacae99b649d633417960ee397b6a8fb117fec819", - method: "accept_partial_order", - }, - { - target: "0x7e2b1334398fafbe640f34bacae99b649d633417960ee397b6a8fb117fec819", - method: "cancel_order", - }, - { - target: "0x7e2b1334398fafbe640f34bacae99b649d633417960ee397b6a8fb117fec819", - method: "world_dispatcher", - }, - { - target: "0x4069c2be57f08fef9f31afc85a5b4c03c208ebdb278b9d853606caa7a9cbee6", - method: "dojo_name", - }, - { - target: "0x4069c2be57f08fef9f31afc85a5b4c03c208ebdb278b9d853606caa7a9cbee6", - method: "travel_hex", - }, - { - target: "0x4069c2be57f08fef9f31afc85a5b4c03c208ebdb278b9d853606caa7a9cbee6", - method: "world_dispatcher", - }, - { - target: "0x26be0ed574aa9ee6f73b53b12f0a199ddbf4ac697470316cdb3d9d1f5680cab", - method: "dojo_name", - }, - { - target: "0x26be0ed574aa9ee6f73b53b12f0a199ddbf4ac697470316cdb3d9d1f5680cab", - method: "army_create", - }, - { - target: "0x26be0ed574aa9ee6f73b53b12f0a199ddbf4ac697470316cdb3d9d1f5680cab", - method: "army_delete", - }, - { - target: "0x26be0ed574aa9ee6f73b53b12f0a199ddbf4ac697470316cdb3d9d1f5680cab", - method: "army_buy_troops", - }, - { - target: "0x26be0ed574aa9ee6f73b53b12f0a199ddbf4ac697470316cdb3d9d1f5680cab", - method: "army_merge_troops", - }, - { - target: "0x26be0ed574aa9ee6f73b53b12f0a199ddbf4ac697470316cdb3d9d1f5680cab", - method: "world_dispatcher", - }, -]; diff --git a/client/apps/game/src/hooks/helpers/useQuests.tsx b/client/apps/game/src/hooks/helpers/useQuests.tsx index 675278aa4..38da63b7f 100644 --- a/client/apps/game/src/hooks/helpers/useQuests.tsx +++ b/client/apps/game/src/hooks/helpers/useQuests.tsx @@ -10,17 +10,6 @@ import { useArmiesByEntityOwnerWithPositionAndQuantity } from "./useArmies"; import { useEntitiesUtils } from "./useEntities"; import { useGetMyOffers } from "./useTrade"; -export interface Quest { - id: QuestType; - view: string; - name: string; - description: string | React.ReactNode; - steps: (string | React.ReactNode)[]; - prizes: Prize[]; - depth: number; - status: QuestStatus; -} - export interface Prize { id: QuestType; title: string; @@ -184,7 +173,7 @@ const useQuestDependencies = () => { ); }; -export const useQuestClaimStatus = () => { +const useQuestClaimStatus = () => { const { setup: { components: { Quest, Realm }, diff --git a/client/apps/game/src/hooks/store/useQuestStore.tsx b/client/apps/game/src/hooks/store/useQuestStore.tsx deleted file mode 100644 index b025194f9..000000000 --- a/client/apps/game/src/hooks/store/useQuestStore.tsx +++ /dev/null @@ -1,16 +0,0 @@ -import { create } from "zustand"; -import { Quest } from "../helpers/useQuests"; - -interface QuestStore { - selectedQuest: Quest | null; - setSelectedQuest: (selectedQuest: Quest | null) => void; - showCompletedQuests: boolean; - setShowCompletedQuests: (showCompletedQuests: boolean) => void; -} - -export const useQuestStore = create((set) => ({ - selectedQuest: null, - setSelectedQuest: (selectedQuest: Quest | null) => set({ selectedQuest }), - showCompletedQuests: false, - setShowCompletedQuests: (showCompletedQuests: boolean) => set({ showCompletedQuests }), -})); diff --git a/client/apps/game/src/hooks/store/useWorldLoading.tsx b/client/apps/game/src/hooks/store/useWorldLoading.tsx index 55e76cf11..3830ee97f 100644 --- a/client/apps/game/src/hooks/store/useWorldLoading.tsx +++ b/client/apps/game/src/hooks/store/useWorldLoading.tsx @@ -17,7 +17,7 @@ export enum LoadingStateKey { Events = "events", } -export type LoadingState = { +type LoadingState = { [key in LoadingStateKey]: boolean; }; diff --git a/client/apps/game/src/hooks/useUISound.tsx b/client/apps/game/src/hooks/useUISound.tsx index f52226498..989e73de7 100644 --- a/client/apps/game/src/hooks/useUISound.tsx +++ b/client/apps/game/src/hooks/useUISound.tsx @@ -1,6 +1,5 @@ -import { ResourceMiningTypes } from "@/types"; -import { BuildingType, ResourcesIds } from "@bibliothecadao/eternum"; -import { useCallback, useState } from "react"; +import { ResourcesIds } from "@bibliothecadao/eternum"; +import { useCallback } from "react"; import useSound from "use-sound"; import useUIStore from "./store/useUIStore"; @@ -213,154 +212,3 @@ export const usePlayResourceSound = () => { playResourceSound, }; }; - -const useRunningSound = () => { - const { play: playFirst, fade: fadeFirst } = useUiSounds(soundSelector.unitRunning); - const { play: playSecond, fade: fadeSecond } = useUiSounds(soundSelector.unitRunningAlternative); - const [isFirst, setIsFirst] = useState(true); - - const play = useCallback(() => { - if (isFirst) { - playFirst(); - } else { - playSecond(); - } - setIsFirst((prev) => !prev); - }, [isFirst, playFirst, playSecond]); - - const stop = useCallback(() => { - fadeFirst(); - fadeSecond(); - }, [fadeFirst, fadeSecond, isFirst]); - - return { - play, - stop, - }; -}; - -const useMarchingSound = () => { - const { repeat: playFirst, stop: stopFirst } = useUiSounds(soundSelector.unitMarching1); - const { repeat: playSecond, stop: stopSecond } = useUiSounds(soundSelector.unitMarching2); - const [isFirst, setIsFirst] = useState(true); - - const play = useCallback(() => { - if (isFirst) { - playFirst(); - } else { - playSecond(); - } - setIsFirst((prev) => !prev); - }, [isFirst, playFirst, playSecond]); - - const stop = useCallback(() => { - stopFirst(); - stopSecond(); - }, [stopFirst, stopSecond, isFirst]); - - return { - play, - stop, - }; -}; - -export const useSelectedArmySound = () => { - const soundSelectors = [soundSelector.unitSelected1, soundSelector.unitSelected2, soundSelector.unitSelected3]; - - const soundHooks = soundSelectors.map((selector) => useUiSounds(selector)); - - const [index, setIndex] = useState(0); - - const play = useCallback(() => { - soundHooks[index].play(); - setIndex((prev) => (prev + 1) % soundHooks.length); - }, [index, soundHooks]); - - const stop = useCallback(() => { - soundHooks.forEach(({ stop }) => stop()); - }, [soundHooks]); - - return { - play, - stop, - }; -}; - -export const useShovelSound = () => { - const { play: playShovelMain } = useUiSounds(soundSelector.shovelMain); - const { play: playShovelAlternative } = useUiSounds(soundSelector.shovelAlternative); - const [isFirst, setIsFirst] = useState(true); - - const play = useCallback(() => { - if (isFirst) { - playShovelMain(); - } else { - playShovelAlternative(); - } - setIsFirst((prev) => !prev); - }, [isFirst, playShovelAlternative, playShovelMain]); - - return { - play, - }; -}; - -// todo: add battle sounds -const useBattleSound = () => { - const { play: playPillageSucess } = useUiSounds(soundSelector.buildFarm); - - return { - playPillageSucess, - }; -}; - -export const useBuildingSound = () => { - const { play: playBuildCastle } = useUiSounds(soundSelector.buildCastle); - const { play: playBuildFarm } = useUiSounds(soundSelector.buildFarm); - const { play: playBuildFishingVillage } = useUiSounds(soundSelector.buildFishingVillage); - const { play: playBuildMine } = useUiSounds(soundSelector.buildMine); - const { play: playBuildStables } = useUiSounds(soundSelector.buildStables); - const { play: playBuildArcherRange } = useUiSounds(soundSelector.buildArcherRange); - const { play: playBuildBarracks } = useUiSounds(soundSelector.buildBarracks); - const { play: playBuildMarket } = useUiSounds(soundSelector.buildMarket); - const { play: playLumberMill } = useUiSounds(soundSelector.buildLumberMill); - - const playBuildingSound = (buildingType: BuildingType | ResourceMiningTypes) => { - switch (buildingType) { - case BuildingType.Castle: - playBuildCastle(); - break; - case BuildingType.Farm: - playBuildFarm(); - break; - case BuildingType.FishingVillage: - playBuildFishingVillage(); - break; - case BuildingType.Resource: - playBuildMine(); - break; - case BuildingType.Stable: - playBuildStables(); - break; - case BuildingType.ArcheryRange: - playBuildArcherRange(); - break; - case BuildingType.Barracks: - playBuildBarracks(); - break; - case BuildingType.Market: - playBuildMarket(); - break; - case ResourceMiningTypes.LumberMill: - playLumberMill(); - break; - default: - playBuildMine(); - break; - } - }; - - return { - playBuildingSound, - }; -}; diff --git a/client/apps/game/src/three/components/FogManager.ts b/client/apps/game/src/three/components/FogManager.ts deleted file mode 100644 index 04e1947a7..000000000 --- a/client/apps/game/src/three/components/FogManager.ts +++ /dev/null @@ -1,32 +0,0 @@ -import * as THREE from "three"; -import { Scene, Raycaster } from "three"; - -export class FogManager { - private fog: THREE.Fog; - private fogRadius: number = 30; // Adjust this value to change the size of the clear area - - constructor( - private scene: Scene, - private camera: THREE.PerspectiveCamera, - ) { - const fogColor = new THREE.Color(0xcccccc); // Light gray fog - this.fog = new THREE.Fog(fogColor, 0.1, this.fogRadius); - //this.scene.fog = this.fog; - } - - updateFog() { - const cameraPosition = new THREE.Vector3(); - this.camera.getWorldPosition(cameraPosition); - - // Set fog start and end distances relative to camera position - this.fog.near = this.fogRadius * 0.8; // Start fog slightly before the edge of visible area - this.fog.far = this.fogRadius; - - // Update fog color based on distance from center (optional) - const distanceFromCenter = Math.sqrt(cameraPosition.x * cameraPosition.x + cameraPosition.z * cameraPosition.z); - const fogIntensity = Math.min(distanceFromCenter / (this.fogRadius * 2), 1); - const fogColor = new THREE.Color(0xcccccc).lerp(new THREE.Color(0x666666), fogIntensity); - this.fog.color.copy(fogColor); - //this.scene.background = fogColor; - } -} diff --git a/client/apps/game/src/three/scenes/constants.ts b/client/apps/game/src/three/scenes/constants.ts index 8c3b251ce..5579800a5 100644 --- a/client/apps/game/src/three/scenes/constants.ts +++ b/client/apps/game/src/three/scenes/constants.ts @@ -77,7 +77,7 @@ const BASE_PATH = "/models/biomes-opt/"; const FLAT_PATH = "/models/biomes-flat-opt/"; const MODELS_PATH = IS_FLAT_MODE ? FLAT_PATH : BASE_PATH; -export enum BiomeFilenames { +enum BiomeFilenames { Bare = "bare.glb", Beach = "beach.glb", TemperateDeciduousForest = "deciduousForest.glb", diff --git a/client/apps/game/src/ui/components/resources/realm-transfer.tsx b/client/apps/game/src/ui/components/resources/realm-transfer.tsx index 72b781fea..d9df4c725 100644 --- a/client/apps/game/src/ui/components/resources/realm-transfer.tsx +++ b/client/apps/game/src/ui/components/resources/realm-transfer.tsx @@ -163,7 +163,7 @@ export const RealmTransfer = memo( }, ); -export const RealmTransferBalance = memo( +const RealmTransferBalance = memo( ({ resource, structure, diff --git a/client/apps/game/src/ui/elements/Switch.tsx b/client/apps/game/src/ui/elements/Switch.tsx deleted file mode 100644 index e3ea99498..000000000 --- a/client/apps/game/src/ui/elements/Switch.tsx +++ /dev/null @@ -1,27 +0,0 @@ -import * as SwitchPrimitives from "@radix-ui/react-switch"; -import * as React from "react"; - -import { cn } from "./lib/utils"; - -const Switch = React.forwardRef< - React.ElementRef, - React.ComponentPropsWithoutRef ->(({ className, ...props }, ref) => ( - - - -)); -Switch.displayName = SwitchPrimitives.Root.displayName; - -export { Switch }; diff --git a/client/apps/game/src/ui/utils/utils.tsx b/client/apps/game/src/ui/utils/utils.tsx index c633bb1c7..9bd2a98f0 100644 --- a/client/apps/game/src/ui/utils/utils.tsx +++ b/client/apps/game/src/ui/utils/utils.tsx @@ -441,10 +441,10 @@ export const adjustWonderLordsCost = (cost: ResourceCost[]): ResourceCost[] => { return cost.map((item) => (item.resource === ResourcesIds.Lords ? { ...item, amount: item.amount * 0.1 } : item)); }; -export const getSeasonAddressesPath = () => { +const getSeasonAddressesPath = () => { return `/resource_addresses/${env.VITE_PUBLIC_CHAIN}/resource_addresses.json`; }; -export const getJSONFile = async (filePath: string) => { +const getJSONFile = async (filePath: string) => { const response = await fetch(filePath); const data = await response.json(); return data; diff --git a/client/apps/landing/env.ts b/client/apps/landing/env.ts index f85a88f74..f5643fc5b 100644 --- a/client/apps/landing/env.ts +++ b/client/apps/landing/env.ts @@ -49,6 +49,3 @@ try { } export { env }; - -// Type for your validated env -export type Env = z.infer; diff --git a/client/apps/landing/src/components/modules/bridge-out-step-1.tsx b/client/apps/landing/src/components/modules/bridge-out-step-1.tsx index a8dd204de..10f7eb8cb 100644 --- a/client/apps/landing/src/components/modules/bridge-out-step-1.tsx +++ b/client/apps/landing/src/components/modules/bridge-out-step-1.tsx @@ -315,7 +315,7 @@ export const BridgeOutStep1 = () => { ); }; -export const SelectResourceRow = ({ +const SelectResourceRow = ({ realmEntityId, selectedResourceIds, setSelectedResourceIds, diff --git a/client/apps/landing/src/components/modules/bridge-out-step-2.tsx b/client/apps/landing/src/components/modules/bridge-out-step-2.tsx index b0cb882f1..dcb7665e0 100644 --- a/client/apps/landing/src/components/modules/bridge-out-step-2.tsx +++ b/client/apps/landing/src/components/modules/bridge-out-step-2.tsx @@ -6,9 +6,8 @@ import { displayAddress } from "@/lib/utils"; import { ADMIN_BANK_ENTITY_ID, RESOURCE_PRECISION, ResourcesIds } from "@bibliothecadao/eternum"; import { useAccount } from "@starknet-react/core"; import { ChevronDown, ChevronUp, Loader } from "lucide-react"; -import { useEffect, useMemo, useState } from "react"; +import { useEffect, useState } from "react"; import { TypeP } from "../typography/type-p"; -import { ShowSingleResource } from "../ui/SelectResources"; import { Button } from "../ui/button"; import { ResourceIcon } from "../ui/elements/ResourceIcon"; import { Input } from "../ui/input"; @@ -334,29 +333,3 @@ export const BridgeOutStep2 = () => { ); }; - -export const SelectResourceRow = ({ - selectedResourceIds, - setSelectedResourceIds, - selectedResourceAmounts, - setSelectedResourceAmounts, -}: { - selectedResourceIds: number[]; - setSelectedResourceIds: (value: number[]) => void; - selectedResourceAmounts: { [key: string]: number }; - setSelectedResourceAmounts: (value: { [key: string]: number }) => void; -}) => { - return ( -
-
- -
-
- ); -}; diff --git a/client/apps/landing/src/components/modules/bridged-resources.tsx b/client/apps/landing/src/components/modules/bridged-resources.tsx index 03c7f1a61..74892de31 100644 --- a/client/apps/landing/src/components/modules/bridged-resources.tsx +++ b/client/apps/landing/src/components/modules/bridged-resources.tsx @@ -104,7 +104,7 @@ export const BridgedResources = () => { ); }; -export const BridgeResource = ({ +const BridgeResource = ({ name, resourceId, contractAddress, diff --git a/client/apps/landing/src/components/modules/cartridge-connect-button.tsx b/client/apps/landing/src/components/modules/cartridge-connect-button.tsx deleted file mode 100644 index 1e8408ca9..000000000 --- a/client/apps/landing/src/components/modules/cartridge-connect-button.tsx +++ /dev/null @@ -1,64 +0,0 @@ -import { displayAddress } from "@/lib/utils"; -import ControllerConnector from "@cartridge/connector/controller"; -import { useConnect } from "@starknet-react/core"; -import { TrashIcon } from "lucide-react"; -import { useEffect, useState } from "react"; -import { Button, ButtonProps } from "../ui/button"; - -export const CartridgeConnectButton = ( - props: ButtonProps & { cartridgeAddress?: string; setCartridgeAddress?: (address: string | undefined) => void }, -) => { - const { connectors } = useConnect(); - const [username, setUsername] = useState(); - const controller = connectors[0] as ControllerConnector; - const controllerAddress = controller?.controller.account?.address; - - const connectCartridge = async () => { - try { - const res = await controller.connect({ chainIdHint: 1n }); - if (res.account) { - props.setCartridgeAddress?.(res.account); - } - } catch (e) { - console.log(e); - } - }; - const disconnectCartridge = () => { - connectors[0].disconnect(); - props.setCartridgeAddress?.(undefined); - }; - useEffect(() => { - if (!controllerAddress) return; - controller.username()?.then((n) => setUsername(n)); - }, [controllerAddress, controller]); - - return ( - <> - {controllerAddress ? ( -
-
-
Minting to:
-
-
- -
-
- {username} - {displayAddress(controllerAddress)} -
-
- -
-
-
-
- ) : ( - - )} - - ); -}; diff --git a/client/apps/landing/src/components/modules/filters.tsx b/client/apps/landing/src/components/modules/filters.tsx deleted file mode 100644 index 5ce530e1a..000000000 --- a/client/apps/landing/src/components/modules/filters.tsx +++ /dev/null @@ -1,34 +0,0 @@ -import { Switch } from "@/components/ui/switch"; -import { useState } from "react"; -import { MultiSelect } from "../ui/multi-select"; - -import { ResourcesIds } from "@bibliothecadao/eternum"; - -const frameworksList = Object.values(ResourcesIds) - .filter((value) => isNaN(Number(value))) - .map((value) => ({ - value: value.toString(), - label: value.toString(), - })); - -export const AttributeFilters = () => { - const [selectedFrameworks, setSelectedFrameworks] = useState( - Object.values(ResourcesIds) - .filter((value) => isNaN(Number(value))) - .map((value) => value.toString()), - ); - return ( -
- - -
- ); -}; diff --git a/client/apps/landing/src/components/modules/guild-leaderboard-panel.tsx b/client/apps/landing/src/components/modules/guild-leaderboard-panel.tsx deleted file mode 100644 index a61b9b004..000000000 --- a/client/apps/landing/src/components/modules/guild-leaderboard-panel.tsx +++ /dev/null @@ -1,202 +0,0 @@ -import { Guild } from "@/types"; -import { ResourcesIds } from "@bibliothecadao/eternum"; -import { ChevronLeft, ChevronRight } from "lucide-react"; -import { useState } from "react"; -import { Button } from "../ui/button"; -import { CardContent } from "../ui/card"; -import { ResourceIcon } from "../ui/elements/ResourceIcon"; -import { Input } from "../ui/input"; -import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "../ui/tooltip"; - -interface GuildLeaderboardPanelProps { - /** Title displayed at the top of the leaderboard */ - title?: string; - /** Array of players to display in the leaderboard */ - guilds: Guild[]; - /** Custom class name for the card container */ - className?: string; - /** Whether to show player rankings */ - showRank?: boolean; - /** Custom points suffix (e.g. "pts", "points", etc) */ - pointsSuffix?: string; -} - -export const GuildLeaderboardPanel = ({ - guilds, - showRank = true, - pointsSuffix = "pts", -}: GuildLeaderboardPanelProps) => { - const [currentPage, setCurrentPage] = useState(0); - const [searchTerm, setSearchTerm] = useState(""); - - const elementsPerPage = 10; - - const filteredGuilds = guilds.filter((guild) => guild.name.toLowerCase().includes(searchTerm.toLowerCase())); - - const totalPages = Math.ceil(filteredGuilds.length / elementsPerPage); - const startIndex = currentPage * elementsPerPage; - const displayedGuilds = filteredGuilds.slice(startIndex, startIndex + elementsPerPage); - - return ( - - { - setSearchTerm(e.target.value); - }} - /> -
-
- {showRank && ( - - - -
#
-
- -

Guilds ranking position

-
-
-
- )} - - - -
Guild
-
- -

Guild's name

-
-
-
- - - -
- Realms -
-
- -

Number of realms owned

-
-
-
- - - -
- Mines -
-
- -

Number of mines owned

-
-
-
- - - -
- Hypers -
-
- -

Number of hyperstructures owned

-
-
-
- - - -
- Points -
-
- -

Total points earned in the game

-
-
-
- - - -
- Share -
-
- -

Percentage share of the prize pool

-
-
-
- - - -
-
- LORDS - -
-
-
- -

$LORDS tokens earned if game ends now

-
-
-
-
- {displayedGuilds.map((guild, index) => ( -
- {showRank &&
{startIndex + index + 1}
} -
{guild.name}
-
{guild.realms}
-
{guild.mines}
-
{guild.hyperstructures}
-
- {guild.points.toLocaleString()} {pointsSuffix} -
-
{guild.percentage.toFixed(2)}%
-
- {guild.lords.toLocaleString()} - -
-
- ))} -
- {totalPages > 1 && ( -
-
- - -
- - {startIndex + 1}-{Math.min(startIndex + elementsPerPage, filteredGuilds.length)} of {filteredGuilds.length} - -
- )} -
- ); -}; diff --git a/client/apps/landing/src/components/modules/leaderboard.tsx b/client/apps/landing/src/components/modules/leaderboard.tsx deleted file mode 100644 index 7f99bf94f..000000000 --- a/client/apps/landing/src/components/modules/leaderboard.tsx +++ /dev/null @@ -1,41 +0,0 @@ -import { getGuilds } from "@/hooks/get-guilds"; -import { useGetAllPlayers } from "@/hooks/use-get-all-players"; -import { Trophy } from "lucide-react"; -import { useMemo } from "react"; -import { TypeH2 } from "../typography/type-h2"; -import { Card, CardHeader } from "../ui/card"; -import { Tabs, TabsContent, TabsList, TabsTrigger } from "../ui/tabs"; -import { GuildLeaderboardPanel } from "./guild-leaderboard-panel"; -import { PlayerLeaderboardPanel } from "./player-leaderboard-panel"; - -export const Leaderboard = () => { - const getPlayers = useGetAllPlayers(); - const players = useMemo(() => getPlayers().sort((a, b) => b.points - a.points), [getPlayers]); - const guilds = useMemo(() => getGuilds(players).sort((a, b) => b.points - a.points), [players]); - - return ( - - - - {} - {"Leaderboard"} - - - - -
- - Players - Guilds - -
- - - - - - -
-
- ); -}; diff --git a/client/apps/landing/src/components/modules/realm-card.tsx b/client/apps/landing/src/components/modules/realm-card.tsx index 81389b6fc..d6955a724 100644 --- a/client/apps/landing/src/components/modules/realm-card.tsx +++ b/client/apps/landing/src/components/modules/realm-card.tsx @@ -7,7 +7,7 @@ import { Loader } from "lucide-react"; import { useEffect, useState } from "react"; import { Checkbox } from "../ui/checkbox"; import { ResourceIcon } from "../ui/elements/ResourceIcon"; -export interface RealmCardProps { +interface RealmCardProps { realm: NonNullable["tokenBalances"]>["edges"]>[0] & { seasonPassMinted?: boolean; }; diff --git a/client/apps/landing/src/components/ui/command.tsx b/client/apps/landing/src/components/ui/command.tsx deleted file mode 100644 index 0d77ce7cc..000000000 --- a/client/apps/landing/src/components/ui/command.tsx +++ /dev/null @@ -1,132 +0,0 @@ -import * as React from "react"; -import { type DialogProps } from "@radix-ui/react-dialog"; -import { MagnifyingGlassIcon } from "@radix-ui/react-icons"; -import { Command as CommandPrimitive } from "cmdk"; - -import { cn } from "@/lib/utils"; -import { Dialog, DialogContent } from "@/components/ui/dialog"; - -const Command = React.forwardRef< - React.ElementRef, - React.ComponentPropsWithoutRef ->(({ className, ...props }, ref) => ( - -)); -Command.displayName = CommandPrimitive.displayName; - -interface CommandDialogProps extends DialogProps {} - -const CommandDialog = ({ children, ...props }: CommandDialogProps) => { - return ( - - - - {children} - - - - ); -}; - -const CommandInput = React.forwardRef< - React.ElementRef, - React.ComponentPropsWithoutRef ->(({ className, ...props }, ref) => ( -
- - -
-)); - -CommandInput.displayName = CommandPrimitive.Input.displayName; - -const CommandList = React.forwardRef< - React.ElementRef, - React.ComponentPropsWithoutRef ->(({ className, ...props }, ref) => ( - -)); - -CommandList.displayName = CommandPrimitive.List.displayName; - -const CommandEmpty = React.forwardRef< - React.ElementRef, - React.ComponentPropsWithoutRef ->((props, ref) => ); - -CommandEmpty.displayName = CommandPrimitive.Empty.displayName; - -const CommandGroup = React.forwardRef< - React.ElementRef, - React.ComponentPropsWithoutRef ->(({ className, ...props }, ref) => ( - -)); - -CommandGroup.displayName = CommandPrimitive.Group.displayName; - -const CommandSeparator = React.forwardRef< - React.ElementRef, - React.ComponentPropsWithoutRef ->(({ className, ...props }, ref) => ( - -)); -CommandSeparator.displayName = CommandPrimitive.Separator.displayName; - -const CommandItem = React.forwardRef< - React.ElementRef, - React.ComponentPropsWithoutRef ->(({ className, ...props }, ref) => ( - -)); - -CommandItem.displayName = CommandPrimitive.Item.displayName; - -const CommandShortcut = ({ className, ...props }: React.HTMLAttributes) => { - return ; -}; -CommandShortcut.displayName = "CommandShortcut"; - -export { - Command, - CommandDialog, - CommandInput, - CommandList, - CommandEmpty, - CommandGroup, - CommandItem, - CommandShortcut, - CommandSeparator, -}; diff --git a/client/apps/landing/src/components/ui/custom-iframe.tsx b/client/apps/landing/src/components/ui/custom-iframe.tsx deleted file mode 100644 index 40b4a4b7c..000000000 --- a/client/apps/landing/src/components/ui/custom-iframe.tsx +++ /dev/null @@ -1,42 +0,0 @@ -import { useEffect, useState } from "react"; -import { createPortal } from "react-dom"; -import style from "../../index.css?inline"; - -interface CustomIframeProps extends React.IframeHTMLAttributes { - children: React.ReactNode; -} - -const CustomIframe: React.FC = ({ children, ...props }) => { - const [contentRef, setContentRef] = useState(null); - const [mountNode, setMountNode] = useState(null); - - useEffect(() => { - if (contentRef) { - const iframeDocument = contentRef.contentDocument; - const iframeWindow = contentRef.contentWindow; - - if (iframeDocument) { - const styleTag = iframeDocument.createElement("style"); - styleTag.textContent = style; - iframeDocument.head.appendChild(styleTag); - } - - setMountNode(iframeDocument?.body || null); - } - }, [contentRef]); - - useEffect(() => { - if (mountNode) { - mountNode.style.overflow = "hidden"; - mountNode.style.backgroundColor = "transparent"; - } - }, [mountNode]); - - return ( - - ); -}; - -export default CustomIframe; diff --git a/client/apps/landing/src/components/ui/utils/utils.ts b/client/apps/landing/src/components/ui/utils/utils.ts index 61dbbe9da..b39d543ca 100644 --- a/client/apps/landing/src/components/ui/utils/utils.ts +++ b/client/apps/landing/src/components/ui/utils/utils.ts @@ -373,7 +373,7 @@ export const getJSONFile = async (filePath: string) => { return data; }; -export interface ResourceAddresses { +interface ResourceAddresses { [key: string]: [number, string]; } diff --git a/client/apps/landing/src/config.ts b/client/apps/landing/src/config.ts index bff902331..781740813 100644 --- a/client/apps/landing/src/config.ts +++ b/client/apps/landing/src/config.ts @@ -1,18 +1,18 @@ import { env } from "../env"; -export enum Chain { +enum Chain { MAINNET = "mainnet", SEPOLIA = "sepolia", LOCAL = "local", } -export enum Token { +enum Token { LORDS = "LORDS", SEASON_PASS = "SEASON_PASS", REALMS = "REALMS", } -export const tokens: { +const tokens: { [key in Chain]: { [Token.LORDS]?: { address: string; @@ -65,7 +65,7 @@ export const tokens: { }, }; -export const chain = import.meta.env.VITE_PUBLIC_CHAIN as Chain | Chain.LOCAL; +const chain = import.meta.env.VITE_PUBLIC_CHAIN as Chain | Chain.LOCAL; export const seasonPassAddress = tokens[chain][Token.SEASON_PASS]?.address as `0x${string}`; export const lordsAddress = tokens[chain][Token.LORDS]?.address as `0x${string}`; diff --git a/client/apps/landing/src/dojo/contractComponents.ts b/client/apps/landing/src/dojo/contractComponents.ts index 5c6c04872..e5c449866 100644 --- a/client/apps/landing/src/dojo/contractComponents.ts +++ b/client/apps/landing/src/dojo/contractComponents.ts @@ -2,7 +2,7 @@ import { defineComponent, Type as RecsType, type World } from "@dojoengine/recs"; -export type ContractComponents = ReturnType; +type ContractComponents = ReturnType; export function defineContractComponents(world: World) { return { diff --git a/client/apps/landing/src/dojo/createClientComponents.ts b/client/apps/landing/src/dojo/createClientComponents.ts index f10fdb1fc..9382ccff7 100644 --- a/client/apps/landing/src/dojo/createClientComponents.ts +++ b/client/apps/landing/src/dojo/createClientComponents.ts @@ -1,7 +1,7 @@ import { overridableComponent } from "@dojoengine/recs"; import { SetupNetworkResult } from "./setupNetwork"; -export type ClientComponents = ReturnType; +type ClientComponents = ReturnType; export function createClientComponents({ contractComponents }: SetupNetworkResult) { return { diff --git a/client/apps/landing/src/dojo/queries.ts b/client/apps/landing/src/dojo/queries.ts deleted file mode 100644 index 0c79e7e7c..000000000 --- a/client/apps/landing/src/dojo/queries.ts +++ /dev/null @@ -1,104 +0,0 @@ -// onload -> fetch single key entities - -import { Component, Metadata, Schema } from "@dojoengine/recs"; -import { setEntities } from "@dojoengine/state"; -import { Clause, EntityKeysClause, PatternMatching, ToriiClient } from "@dojoengine/torii-client"; - -// on hexception -> fetch below queries based on entityID - -// background sync after load -> - -export const getEntities = async ( - client: ToriiClient, - clause: Clause | undefined, - components: Component[], - limit: number = 100, - logging: boolean = false, -) => { - if (logging) console.log("Starting getEntities"); - let offset = 0; - let continueFetching = true; - - while (continueFetching) { - const entities = await client.getEntities({ - limit, - offset, - clause, - dont_include_hashed_keys: false, - order_by: [], - }); - - setEntities(entities, components); - - if (Object.keys(entities).length < limit) { - continueFetching = false; - } else { - offset += limit; - } - } -}; - -export const syncEntitiesEternum = async ( - client: ToriiClient, - components: Component[], - entityKeyClause: EntityKeysClause[], - logging: boolean = false, -) => { - // if (logging) console.log("Starting syncEntities"); - return await client.onEntityUpdated(entityKeyClause, (fetchedEntities: any, data: any) => { - // if (logging) console.log("Entity updated", fetchedEntities); - - setEntities({ [fetchedEntities]: data }, components); - }); -}; - -export const addToSubscription = async ( - client: ToriiClient, - components: Component[], - entityID: string, - position?: { x: number; y: number }, -) => { - const positionClause: EntityKeysClause = { - Keys: { - keys: [String(position?.x || 0), String(position?.y || 0), undefined, undefined], - pattern_matching: "FixedLen" as PatternMatching, - models: [], - }, - }; - - await getEntities( - client, - { - Composite: { - operator: "Or", - clauses: [ - positionClause, - { - Keys: { - keys: [entityID], - pattern_matching: "FixedLen", - models: [], - }, - }, - { - Keys: { - keys: [entityID, undefined], - pattern_matching: "FixedLen", - models: [], - }, - }, - { - Keys: { - keys: [entityID, undefined, undefined], - pattern_matching: "FixedLen", - models: [], - }, - }, - ], - }, - }, - components, - 20_000, - false, - ); -}; diff --git a/client/apps/landing/src/hooks/context/DojoContext.tsx b/client/apps/landing/src/hooks/context/DojoContext.tsx index 19825e37a..b9dc3127c 100644 --- a/client/apps/landing/src/hooks/context/DojoContext.tsx +++ b/client/apps/landing/src/hooks/context/DojoContext.tsx @@ -23,14 +23,14 @@ interface DojoContextType extends SetupResult { account: DojoAccount; } -export interface DojoResult { +interface DojoResult { setup: DojoContextType; account: DojoAccount; network: SetupNetworkResult; masterAccount: Account | AccountInterface; } -export const DojoContext = createContext(null); +const DojoContext = createContext(null); const requiredEnvs: (keyof typeof env)[] = [ "VITE_PUBLIC_MASTER_ADDRESS", diff --git a/client/apps/landing/src/hooks/get-guilds.tsx b/client/apps/landing/src/hooks/get-guilds.tsx deleted file mode 100644 index 9d6e8c8a4..000000000 --- a/client/apps/landing/src/hooks/get-guilds.tsx +++ /dev/null @@ -1,46 +0,0 @@ -import { PRIZE_POOL_GUILDS } from "@/constants"; -import { Guild } from "@/types"; -import { calculateGuildLordsPrize, Player } from "@bibliothecadao/eternum"; - -export const getGuilds = (players: Player[]): Guild[] => { - const guildMap = new Map(); - - players.forEach((player) => { - if (!player.guildName) return; - - if (!guildMap.has(player.guildName)) { - guildMap.set(player.guildName, { - name: player.guildName, - points: 0, - percentage: 0, - lords: 0, - realms: 0, - mines: 0, - hyperstructures: 0, - isAlive: true, - playerCount: 0, - }); - } - - const guild = guildMap.get(player.guildName); - if (!guild) return; - guild.points += player.points; - guild.realms += player.realms; - guild.mines += player.mines; - guild.hyperstructures += player.hyperstructures; - guild.isAlive = guild.isAlive && player.isAlive; - guild.playerCount++; - }); - - const totalPoints = Array.from(guildMap.values()).reduce((sum, guild) => sum + guild.points, 0); - - const guildsArray = Array.from(guildMap.values()) - .sort((a, b) => b.points - a.points) - .map((guild, index) => ({ - ...guild, - percentage: (guild.points / totalPoints) * 100, - lords: calculateGuildLordsPrize(index + 1, PRIZE_POOL_GUILDS), - })); - - return guildsArray; -}; diff --git a/client/apps/landing/src/hooks/gql/fragment-masking.ts b/client/apps/landing/src/hooks/gql/fragment-masking.ts index f347f50e1..36dd77203 100644 --- a/client/apps/landing/src/hooks/gql/fragment-masking.ts +++ b/client/apps/landing/src/hooks/gql/fragment-masking.ts @@ -1,9 +1,9 @@ /* eslint-disable */ -import { ResultOf, DocumentTypeDecoration } from '@graphql-typed-document-node/core'; +import { DocumentTypeDecoration, ResultOf } from '@graphql-typed-document-node/core'; import { Incremental, TypedDocumentString } from './graphql'; -export type FragmentType> = TDocumentType extends DocumentTypeDecoration< +type FragmentType> = TDocumentType extends DocumentTypeDecoration< infer TType, any > diff --git a/client/apps/landing/src/hooks/helpers/use-contributions.tsx b/client/apps/landing/src/hooks/helpers/use-contributions.tsx deleted file mode 100644 index e6f4d66d3..000000000 --- a/client/apps/landing/src/hooks/helpers/use-contributions.tsx +++ /dev/null @@ -1,71 +0,0 @@ -import { divideByPrecision } from "@/components/ui/utils/utils"; -import { ClientComponents } from "@/dojo/createClientComponents"; -import { configManager } from "@/dojo/setup"; -import { ContractAddress, ID, Resource } from "@bibliothecadao/eternum"; -import { useEntityQuery } from "@dojoengine/react"; -import { ComponentValue, HasValue, getComponentValue, runQuery } from "@dojoengine/recs"; -import { useCallback } from "react"; -import { useDojo } from "../context/DojoContext"; - -export const useContributions = () => { - const { - setup: { - components: { Contribution }, - }, - } = useDojo(); - - const getContributions = (hyperstructureEntityId: ID) => { - const contributionsToHyperstructure = Array.from( - runQuery([HasValue(Contribution, { hyperstructure_entity_id: hyperstructureEntityId })]), - ).map((id) => getComponentValue(Contribution, id)); - - return contributionsToHyperstructure as ComponentValue[]; - }; - - const useContributionsByPlayerAddress = (playerAddress: ContractAddress, hyperstructureEntityId: ID) => { - const contributionsToHyperstructure = useEntityQuery([ - HasValue(Contribution, { hyperstructure_entity_id: hyperstructureEntityId, player_address: playerAddress }), - ]) - .map((id) => getComponentValue(Contribution, id)) - .filter((x): x is ComponentValue => x !== undefined); - - return contributionsToHyperstructure; - }; - - const getContributionsTotalPercentage = (hyperstructureId: number, contributions: Resource[]) => { - const totalPlayerContribution = divideByPrecision( - contributions.reduce((acc, { amount, resourceId }) => { - return acc + amount * configManager.getResourceRarity(resourceId); - }, 0), - ); - - const totalHyperstructureContribution = configManager.getHyperstructureTotalContributableAmount(hyperstructureId); - - return totalPlayerContribution / totalHyperstructureContribution; - }; - - return { - getContributions, - useContributionsByPlayerAddress, - getContributionsTotalPercentage, - }; -}; - -export const useGetHyperstructuresWithContributionsFromPlayer = () => { - const { - account: { account }, - setup: { - components: { Contribution }, - }, - } = useDojo(); - - const getContributions = useCallback(() => { - const entityIds = runQuery([HasValue(Contribution, { player_address: ContractAddress(account.address) })]); - const hyperstructureEntityIds = Array.from(entityIds).map( - (entityId) => getComponentValue(Contribution, entityId)?.hyperstructure_entity_id ?? 0, - ); - return new Set(hyperstructureEntityIds); - }, [account?.address]); - - return getContributions; -}; diff --git a/client/apps/landing/src/hooks/helpers/useEntities.tsx b/client/apps/landing/src/hooks/helpers/useEntities.tsx index df7543947..5f93d05a9 100644 --- a/client/apps/landing/src/hooks/helpers/useEntities.tsx +++ b/client/apps/landing/src/hooks/helpers/useEntities.tsx @@ -5,16 +5,16 @@ import { execute } from "../gql/execute"; import { GET_ETERNUM_OWNER_REALM_IDS } from "../query/entities"; import { useRealm } from "./useRealms"; -export interface S0EternumRealm { +interface S0EternumRealm { __typename: "s0_eternum_Realm"; realm_id: number; } -export function isS0EternumRealm(model: any): model is S0EternumRealm { +function isS0EternumRealm(model: any): model is S0EternumRealm { return model?.__typename === "s0_eternum_Realm"; } -export function isS0EternumStructure(model: any) { +function isS0EternumStructure(model: any) { return model?.__typename === "s0_eternum_Structure"; } diff --git a/client/apps/landing/src/hooks/query/leaderboard.tsx b/client/apps/landing/src/hooks/query/leaderboard.tsx index a44d64aa9..5578960b7 100644 --- a/client/apps/landing/src/hooks/query/leaderboard.tsx +++ b/client/apps/landing/src/hooks/query/leaderboard.tsx @@ -12,22 +12,6 @@ export const GET_GAME_WINNER = graphql(` } `); -export const GET_PLAYER_HAS_REGISTRED = graphql(` - query hasPlayerRegistered($accountAddress: ContractAddress!) { - s0EternumOwnerModels(where: { address: $accountAddress }) { - totalCount - } - } -`); - -export const GET_PLAYER_HAS_CLAIMED = graphql(` - query hasPlayerClaimed($accountAddress: ContractAddress!) { - s0EternumLeaderboardRewardClaimedModels(where: { address: $accountAddress }) { - totalCount - } - } -`); - export const GET_LEADERBOARD_ENTRY = graphql(` query getLeaderboardEntry($accountAddress: ContractAddress!) { s0EternumLeaderboardEntryModels(where: { address: $accountAddress }) { diff --git a/client/apps/landing/src/hooks/query/players.tsx b/client/apps/landing/src/hooks/query/players.tsx deleted file mode 100644 index cfa7c2b0c..000000000 --- a/client/apps/landing/src/hooks/query/players.tsx +++ /dev/null @@ -1,8 +0,0 @@ -/* Not currently in World Contract*/ -/*export const GET_USERS = graphql(` - query totalPlayers { - eternumOwnerModels { - totalCount - } - } -`);*/ diff --git a/client/apps/landing/src/hooks/use-entities-utils.tsx b/client/apps/landing/src/hooks/use-entities-utils.tsx deleted file mode 100644 index 23b0f2276..000000000 --- a/client/apps/landing/src/hooks/use-entities-utils.tsx +++ /dev/null @@ -1,38 +0,0 @@ -import { ID, StructureType } from "@bibliothecadao/eternum"; -import { getComponentValue } from "@dojoengine/recs"; -import { getEntityIdFromKeys } from "@dojoengine/utils"; -import { shortString } from "starknet"; -import { useDojo } from "./context/DojoContext"; - -export const useEntitiesUtils = () => { - const { - setup: { - components: { EntityName, Structure }, - }, - } = useDojo(); - - const getEntityName = (entityId: ID, abbreviate: boolean = false) => { - const entityName = getComponentValue(EntityName, getEntityIdFromKeys([BigInt(entityId)])); - const structure = getComponentValue(Structure, getEntityIdFromKeys([BigInt(entityId)])); - - if (structure?.category === StructureType[StructureType.Realm]) { - // if realm is needed at some point we can add it here - return "realm"; - } else if (entityName) { - return shortString.decodeShortString(entityName.name.toString()); - } else { - if (abbreviate) { - if (structure?.category === StructureType[StructureType.FragmentMine]) { - return `FM ${structure.entity_id}`; - } else if (structure?.category === StructureType[StructureType.Hyperstructure]) { - return `HS ${structure.entity_id}`; - } else if (structure?.category === StructureType[StructureType.Bank]) { - return `BK ${structure.entity_id}`; - } - } - return `${structure?.category} ${structure?.entity_id}`; - } - }; - - return { getEntityName }; -}; diff --git a/client/apps/landing/src/hooks/use-entity-resources.tsx b/client/apps/landing/src/hooks/use-entity-resources.tsx deleted file mode 100644 index e69de29bb..000000000 diff --git a/client/apps/landing/src/hooks/use-get-all-players.tsx b/client/apps/landing/src/hooks/use-get-all-players.tsx deleted file mode 100644 index dfbfa536d..000000000 --- a/client/apps/landing/src/hooks/use-get-all-players.tsx +++ /dev/null @@ -1,78 +0,0 @@ -import { LeaderboardManager } from "@/dojo/modelManager/leaderboard/LeaderboardManager"; -import { calculateLordsShare, calculatePlayerSharePercentage } from "@/utils/leaderboard"; -import { Player, StructureType } from "@bibliothecadao/eternum"; -import { getComponentValue, Has, HasValue, runQuery } from "@dojoengine/recs"; -import { shortString } from "starknet"; -import { formatEther } from "viem"; -import { useDojo } from "./context/DojoContext"; -import { useEntitiesUtils } from "./use-entities-utils"; -import { usePrizePool } from "./use-rewards"; - -export const useGetAllPlayers = () => { - const dojo = useDojo(); - const { - setup: { - components: { Realm, Owner, GuildMember, AddressName, Hyperstructure, Structure }, - }, - } = dojo; - - const nextBlockTimestamp = Math.floor(Date.now() / 1000); - - const { getEntityName } = useEntitiesUtils(); - - const prizePool = usePrizePool(); - - const playerEntities = runQuery([Has(AddressName)]); - const playersByRank = LeaderboardManager.instance(dojo).getPlayersByRank(nextBlockTimestamp || 0); - - const totalPoints = playersByRank.reduce((sum, [, points]) => sum + points, 0); - - const getPlayers = (): Player[] => { - const players = Array.from(Array.from(playerEntities)) - .map((id) => { - const addressName = getComponentValue(AddressName, id); - if (!addressName) return; - - const isAlive = !!runQuery([HasValue(Owner, { address: addressName.address })]).size; - - const guildMember = getComponentValue(GuildMember, id); - const guildName = guildMember ? getEntityName(guildMember.guild_entity_id) : ""; - - return { - address: addressName.address, - addressName: shortString.decodeShortString(addressName.name.toString()), - isAlive, - guildName, - }; - }) - .filter((player) => player !== undefined); - - let unrankedCount = 0; - - return players.map((player) => { - const rankIndex = playersByRank.findIndex(([address]) => address === player.address); - if (rankIndex === -1) unrankedCount++; - - const points = rankIndex === -1 ? 0 : playersByRank[rankIndex][1]; - - return { - name: player.addressName, - address: player.address, - points, - rank: rankIndex === -1 ? Number.MAX_SAFE_INTEGER : rankIndex + 1, - percentage: calculatePlayerSharePercentage(points, totalPoints), - lords: calculateLordsShare(points, totalPoints, Number(formatEther(prizePool))), - realms: runQuery([Has(Realm), HasValue(Owner, { address: player.address })]).size, - mines: runQuery([ - HasValue(Structure, { category: StructureType[StructureType.FragmentMine] }), - HasValue(Owner, { address: player.address }), - ]).size, - hyperstructures: runQuery([Has(Hyperstructure), HasValue(Owner, { address: player.address })]).size, - isAlive: player.isAlive, - guildName: player.guildName, - }; - }); - }; - - return getPlayers; -}; diff --git a/client/apps/landing/src/hooks/use-lords-bridged.tsx b/client/apps/landing/src/hooks/use-lords-bridged.tsx index 59932ca65..517fc3d66 100644 --- a/client/apps/landing/src/hooks/use-lords-bridged.tsx +++ b/client/apps/landing/src/hooks/use-lords-bridged.tsx @@ -1,69 +1,8 @@ import { lordsAddress } from "@/config"; import { useEffect, useState } from "react"; import { getManifest } from "../../dojoConfig"; -import { env } from "./../../env"; import { useDojo } from "./context/DojoContext"; -const ERC20EVENT_SELECTOR = "0x166373381772db0a01c3a66865fc326c297787697aa52a6ea318e38c42302f7"; -const TRANSFER_SELECTOR = "0x99cd8bde557814842a3121e8ddfd433a539b8c9f14bf31ebf108d12e6196e9"; -const START_BLOCK = 951460; - -export const useLordsBridgedIn = () => { - const { - network: { provider }, - } = useDojo(); - - const [lordsBridgedIn, setLordsBridgedIn] = useState(0n); - - const manifest = getManifest(); - const bridgeContract = manifest.contracts.find((contract) => contract.tag === "s0_eternum-resource_bridge_systems"); - - // lords contract is different between mainnet and sepolia/local - const isMainnet = env.VITE_PUBLIC_CHAIN === "mainnet"; - - const keys = isMainnet - ? [[TRANSFER_SELECTOR]] - : [ - // Event key - [ERC20EVENT_SELECTOR], - // Transfer selector - [TRANSFER_SELECTOR], - // from anybody - [], - // bridge contract address - [bridgeContract?.address || "0x0"], - ]; - - const block_number = isMainnet ? START_BLOCK : 0; - - useEffect(() => { - const fetchTransferEvents = async () => { - try { - const events = await provider.provider.getEvents({ - address: lordsAddress, - from_block: { block_number }, - to_block: "latest", - keys, - chunk_size: 100, - }); - - let total = 0n; - events.events.forEach((event) => { - total += BigInt(event.data[0]); - }); - - setLordsBridgedIn(total); - } catch (error) { - console.error("Error fetching transfer events:", error); - } - }; - - fetchTransferEvents(); - }, [provider, bridgeContract?.address]); - - return Number(lordsBridgedIn) / 10 ** 18; -}; - export const useLordsBridgeBalance = () => { const { network: { provider }, diff --git a/client/apps/landing/src/hooks/use-realms-settled.tsx b/client/apps/landing/src/hooks/use-realms-settled.tsx deleted file mode 100644 index ae9fffd0c..000000000 --- a/client/apps/landing/src/hooks/use-realms-settled.tsx +++ /dev/null @@ -1,7 +0,0 @@ -import { useEntityQuery } from "@dojoengine/react"; -import { Has } from "@dojoengine/recs"; -import { useDojo } from "./context/DojoContext"; - -export const useRealmsSettled = () => { - return useEntityQuery([Has(useDojo().setup.components.Realm)]).length; -}; diff --git a/client/apps/landing/src/hooks/useCollectionTokens.tsx b/client/apps/landing/src/hooks/useCollectionTokens.tsx deleted file mode 100644 index a0d0bead2..000000000 --- a/client/apps/landing/src/hooks/useCollectionTokens.tsx +++ /dev/null @@ -1,45 +0,0 @@ -import { useSuspenseInfiniteQuery } from "@tanstack/react-query"; - -import type { - CollectionSortBy, - CollectionSortDirection, - CollectionTokensApiResponse, -} from "@/lib/ark/getCollectionTokens"; -import type { Filters } from "@/types"; - -import { getCollectionTokens } from "@/lib/ark/getCollectionTokens"; - -interface useCollectionTokensProps { - collectionAddress: string; - sortBy: CollectionSortBy; - sortDirection: CollectionSortDirection; - filters: Filters; - buyNow: boolean; -} - -const REFETCH_INTERVAL = 10_000; - -export default function useCollectionTokens({ - collectionAddress, - sortDirection, - sortBy, - filters, - buyNow, -}: useCollectionTokensProps) { - const result = useSuspenseInfiniteQuery({ - queryKey: ["collectionTokens", sortDirection, sortBy, collectionAddress, filters, buyNow], - refetchInterval: REFETCH_INTERVAL, - getNextPageParam: (lastPage: CollectionTokensApiResponse) => lastPage.next_page, - initialPageParam: undefined as number | undefined, - queryFn: ({ pageParam }) => - getCollectionTokens({ - collectionAddress, - page: pageParam, - sortDirection, - sortBy, - filters, - buyNow, - }), - }); - return result; -} diff --git a/client/apps/landing/src/hooks/usePrizeClaim.tsx b/client/apps/landing/src/hooks/usePrizeClaim.tsx index 5bc075317..4daf6f868 100644 --- a/client/apps/landing/src/hooks/usePrizeClaim.tsx +++ b/client/apps/landing/src/hooks/usePrizeClaim.tsx @@ -6,7 +6,6 @@ import { GET_HYPERSTRUCTURE_EPOCHS, GET_LEADERBOARD, GET_LEADERBOARD_ENTRY, - GET_PLAYER_HAS_CLAIMED, GET_PLAYER_HYPERSTRUCTURE_CONTRIBUTIONS, } from "./query/leaderboard"; @@ -34,18 +33,6 @@ export const useLeaderboardStatus = () => { return { leaderboard, isLoading }; }; -export const useHasPlayerClaimed = (playerAddress: string) => { - const { data, isLoading } = useQuery({ - queryKey: ["address", playerAddress], - queryFn: () => execute(GET_PLAYER_HAS_CLAIMED, { accountAddress: playerAddress }), - refetchInterval: 10_000, - }); - - const hasClaimed = (data?.s0EternumLeaderboardRewardClaimedModels?.totalCount || 0) > 0; - - return { hasClaimed, isLoading }; -}; - export const useGameWinner = () => { const { data, isLoading } = useQuery({ queryKey: ["gameEnded"], diff --git a/client/apps/landing/src/lib/ark/getCollectionTokens.ts b/client/apps/landing/src/lib/ark/getCollectionTokens.ts deleted file mode 100644 index 49f806668..000000000 --- a/client/apps/landing/src/lib/ark/getCollectionTokens.ts +++ /dev/null @@ -1,106 +0,0 @@ -import { /*createSearchParamsCache,*/ parseAsStringLiteral } from "nuqs/server"; - -import type { CollectionToken, Filters } from "@/types"; -import { env } from "../../../env"; -export const itemsPerPage = 50; - -export const collectionSortDirectionKey = "direction"; -export const collectionSortDirectionsValues = ["asc", "desc"] as const; -export const collectionSortDirectionsParser = parseAsStringLiteral(collectionSortDirectionsValues).withDefault("asc"); -export type CollectionSortDirection = (typeof collectionSortDirectionsValues)[number]; - -export const collectionSortByKey = "sort"; -export const collectionSortByValues = ["price"] as const; -export const collectionSortByParser = parseAsStringLiteral(collectionSortByValues).withDefault("price"); -export type CollectionSortBy = (typeof collectionSortByValues)[number]; - -/*export const collectionPageSearchParamsCache = createSearchParamsCache({ - [collectionSortDirectionKey]: collectionSortDirectionsParser, - [collectionSortByKey]: collectionSortByParser, -});*/ - -export interface CollectionTokensApiResponse { - data: CollectionToken[]; - next_page: number | null; - token_count: number; -} - -interface GetCollectionTokensParams { - collectionAddress: string; - page?: number; - sortDirection?: CollectionSortDirection; - sortBy?: CollectionSortBy; - filters?: Filters; - buyNow?: boolean; -} - -export async function getCollectionTokens({ - collectionAddress, - page, - sortDirection, - sortBy, - filters, - buyNow, -}: GetCollectionTokensParams) { - const queryParams = [`items_per_page=${itemsPerPage}`]; - - if (Object.keys(filters?.traits ?? {}).length) { - queryParams.push(`filters=${encodeURIComponent(JSON.stringify(filters))}`); - } - - if (page !== undefined) { - queryParams.push(`page=${page}`); - } - - if (buyNow) { - queryParams.push("buy_now=true"); - } - - if (sortBy !== undefined) { - queryParams.push(`sort=${sortBy}`); - } - if (sortBy !== undefined) { - queryParams.push(`direction=${sortDirection}`); - } - - const url = `${ - env.VITE_PUBLIC_ARK_MARKETPLACE_API - }/collections/${collectionAddress}/0x534e5f4d41494e/tokens?${queryParams.join("&")}`; - const response = await fetch(url, { - headers: { - "Content-Type": "application/json", - }, - }); - - if (!response.ok) { - console.error(url, response.status); - - return { - data: [], - next_page: null, - token_count: 0, - }; - } - - const result = (await response.json()) as CollectionTokensApiResponse; - - return result; -} - -export function getMediaSrc( - src?: string | null, - mediaKey?: string | null, - thumbnailKey?: string | null, - width?: number, - height?: number, -) { - if (thumbnailKey) { - return `${env.VITE_PUBLIC_IMAGE_CDN_URL}/${thumbnailKey}`; - } - - if (mediaKey && width && height) { - const resolutionParam = `:${width}:${height}`; - return `${env.VITE_PUBLIC_IMAGE_PROXY_URL}/_/rs:fit${resolutionParam}/plain/${env.VITE_PUBLIC_IMAGE_CDN_URL}/${mediaKey}`; - } - return src?.replace("ipfs://", env.VITE_PUBLIC_IPFS_GATEWAY); -} diff --git a/client/apps/landing/src/lib/utils.ts b/client/apps/landing/src/lib/utils.ts index 336695c87..96d64878f 100644 --- a/client/apps/landing/src/lib/utils.ts +++ b/client/apps/landing/src/lib/utils.ts @@ -1,30 +1,11 @@ -import { - BuildingType, - ContractAddress, - EternumGlobalConfig, - type ID, - type Position, - type Resource, -} from "@bibliothecadao/eternum"; -import { getEntityIdFromKeys } from "@dojoengine/utils"; -import { Connector } from "@starknet-react/core"; +import { EternumGlobalConfig } from "@bibliothecadao/eternum"; import { clsx, type ClassValue } from "clsx"; import { twMerge } from "tailwind-merge"; -export { getEntityIdFromKeys }; - export function cn(...inputs: ClassValue[]) { return twMerge(clsx(inputs)); } -export const toHexString = (num: bigint) => { - return `0x${num.toString(16)}`; -}; - -export const checkCartridgeConnector = (connector?: Connector) => { - return connector?.id === "controller"; -}; - export const formatNumber = (num: number, decimals: number): string => { return num.toFixed(decimals).replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,"); }; @@ -33,13 +14,6 @@ export const currencyFormat = (num: number, decimals: number): string => { return formatNumber(divideByPrecision(num), decimals); }; -export function currencyIntlFormat(num: number, decimals: number = 2): string { - return Intl.NumberFormat("en-US", { - notation: "compact", - maximumFractionDigits: decimals, - }).format(num || 0); -} - export function displayAddress(string: string) { if (string === undefined) return "unknown"; return string.substring(0, 6) + "..." + string.substring(string.length - 4); @@ -52,170 +26,3 @@ export function multiplyByPrecision(value: number): number { export function divideByPrecision(value: number): number { return value / EternumGlobalConfig.resources.resourcePrecision; } - -export function addressToNumber(address: string) { - // Convert the address to a big integer - let numericValue = ContractAddress(address); - - // Sum the digits of the numeric value - let sum = 0; - while (numericValue > 0) { - sum += Number(numericValue % 5n); - numericValue /= 5n; - } - - // Map the sum to a number between 1 and 10 - return (sum % 5) + 1; -} - -export function calculateDistance(start: Position, destination: Position): number | undefined { - // d = √((x2-x1)² + (y2-y1)²) - - if (start && destination) { - // Calculate the difference in x and y coordinates - const deltaX = Math.abs(start.x - destination.x); - const deltaY = Math.abs(start.y - destination.y); - - // Calculate the distance using the Pythagorean theorem - // Each tile is 1 km, so we don't need to divide by 10000 here - const distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY); - - return distance; - } -} - -export enum TimeFormat { - D = 1, - H = 2, - M = 4, - S = 8, -} - -export const formatTime = ( - seconds: number, - format: TimeFormat = TimeFormat.D | TimeFormat.H | TimeFormat.M | TimeFormat.S, -): string => { - const days = Math.floor(seconds / (3600 * 24)); - const hours = Math.floor((seconds % (3600 * 24)) / 3600); - const minutes = Math.floor((seconds % 3600) / 60); - const remainingSeconds = Math.floor(seconds % 60); - - const parts = []; - if (days > 0 && format & TimeFormat.D) parts.push(`${days}d`); - if (hours > 0 && format & TimeFormat.H) parts.push(`${hours}h`); - if (minutes > 0 && format & TimeFormat.M) parts.push(`${minutes}m`); - if (remainingSeconds > 0 && format & TimeFormat.S) parts.push(`${remainingSeconds}s`); - - return parts.join(" "); -}; - -export const copyPlayerAddressToClipboard = (address: ContractAddress, name: string) => { - navigator.clipboard - .writeText(address.toString()) - .then(() => { - alert(`Address of ${name} copied to clipboard`); - }) - .catch((err) => { - console.error("Failed to copy: ", err); - }); -}; - -export const isRealmSelected = (structureEntityId: ID, structures: any) => { - const selectedStructure = structures?.find((structure: any) => structure?.entity_id === structureEntityId); - return selectedStructure?.category === "Realm"; -}; - -export const formatSecondsInHoursMinutes = (seconds: number) => { - const hours = Math.floor(seconds / 3600); - const minutes = Math.floor((seconds % 3600) / 60); - - return `${hours}h:${minutes}m`; -}; - -export const isResourceProductionBuilding = (buildingId: BuildingType) => { - return ( - buildingId === BuildingType.Resource || - buildingId === BuildingType.Farm || - buildingId === BuildingType.FishingVillage || - buildingId === BuildingType.Barracks || - buildingId === BuildingType.ArcheryRange || - buildingId === BuildingType.Stable - ); -}; - -export function gramToKg(grams: number): number { - return Number(grams) / 1000; -} - -export function kgToGram(kg: number): number { - return Number(kg) * 1000; -} - -export const formatResources = (resources: any[]): Resource[] => { - return resources - .map((resource) => ({ - resourceId: Number(resource[0].value), - amount: Number(resource[1].value), - })) - .filter((resource) => resource.amount > 0); -}; - -const accentsToAscii = (str: string) => { - // Character map for transliteration to ASCII - const charMap: Record = { - á: "a", - ú: "u", - é: "e", - ä: "a", - Š: "S", - Ï: "I", - š: "s", - Í: "I", - í: "i", - ó: "o", - ï: "i", - ë: "e", - ê: "e", - â: "a", - Ó: "O", - ü: "u", - Á: "A", - Ü: "U", - ô: "o", - ž: "z", - Ê: "E", - ö: "o", - č: "c", - Â: "A", - Ä: "A", - Ë: "E", - É: "E", - Č: "C", - Ž: "Z", - Ö: "O", - Ú: "U", - Ô: "O", - "‘": "'", - }; - const transliterate = (str: string) => { - return str - .split("") - .map((char) => charMap[char] || char) - .join(""); - }; - return transliterate(str); -}; - -export const toValidAscii = (str: string) => { - const intermediateString = str.normalize("NFD").replace(/[\u0300-\u036f]/g, ""); - return accentsToAscii(intermediateString); -}; - -export const separateCamelCase = (str: string): string => { - return str - .replace(/([a-z])([A-Z])/g, "$1 $2") - .replace(/([A-Z])([A-Z][a-z])/g, "$1 $2") - .split(" ") - .map((word) => word.charAt(0).toUpperCase() + word.slice(1)) - .join(" "); -}; diff --git a/client/apps/landing/src/types/index.ts b/client/apps/landing/src/types/index.ts index 281751046..eb79d8020 100644 --- a/client/apps/landing/src/types/index.ts +++ b/client/apps/landing/src/types/index.ts @@ -1,373 +1,3 @@ -export interface Guild { - name: string; - points: number; - percentage: number; - lords: number; - realms: number; - mines: number; - hyperstructures: number; - isAlive: boolean; - playerCount: number; -} - -export interface SeasonPass { - realm: string; -} -export interface Collection { - address: string; - floor?: string; - image?: string; - is_verified: boolean; - listed_items: number; - listed_percentage: number; - marketcap: number; - name: string; - owner_count: number; - sales_7d: number; - token_count: number; - total_sales: number; - total_volume: number; - volume_7d_eth: number; - floor_7d_percentage: string; -} - -export type CollectionTrait = Record; - -export type CollectionTraits = Record; - -export interface PortfolioCollection { - address: string; - image?: string; - name: string; - floor?: number; - user_listed_tokens: number; - user_token_count: number; -} - -export interface Offer { - order_hash: string; - offer_maker: string; - offer_amount: string; - offer_quantity: `0x${string}`; - offer_timestamp: number; - currency_address: string; - currency_chain_id: string; - start_date: number; - end_date: number; - status: string; -} - -export interface CollectionTokenOffersApiResponse { - token_address: string; - token_id: string; - current_owner: string; - last_price: null; - offers: Offer[]; -} - -export interface Activity { - event_type: string; - event_timestamp: number; - order_status: string; - previous_owner: string; - new_owner: string; - amount: string; - canceled_reason: string; - end_amount: string; - start_date: number; - end_date: number; -} - -export interface CollectionTokenActivityApiResponse { - token_address: string; - token_id: string; - history: Activity[]; -} - -export interface CollectionTokenApiResponse { - result: Token; -} - -interface TokenMetadataAttribute { - display_type?: string; - trait_type?: string; - value?: string; -} - -export interface TokenMetadata { - image: string; - name: string; - animation_key: string | null; - animation_url: string | null; - image_key: string | null; - image_key_540_540?: string | null; - attributes: TokenMetadataAttribute[]; -} - -export interface Token { - collection_image: string; - collection_name: string; - collection_address: string; - last_price?: string; - metadata?: TokenMetadata; - owner: string; - price?: string; - top_offer?: string; - token_id: string; -} - -export interface CollectionToken { - buy_in_progress: boolean; - collection_address: string; - collection_name: string; - floor_difference: number | null; - last_price?: string; - is_listed: boolean; - listed_at?: number; - listing: { - is_auction: boolean; - }; - metadata?: TokenMetadata; - owner: string; - price?: string; - token_id: string; -} - -export interface AccountSearchResult { - owner: string; - starknet_id: string | null; - image: string | null; -} - -export interface CollectionSearchResult { - address: string; - image: string | null; - is_verified: boolean; - name: string; - token_count: number; -} - -export interface PortfolioToken { - collection_name: string; - collection_address: string; - best_offer?: number; - floor?: number; - list_price?: number; - owner: string; - received_at?: string; - token_id: string; - metadata?: TokenMetadata; -} - -export const activityTypes = [ - "AUCTION", - "BURN", - "CANCELLED", - "CANCEL_AUCTION", - "CANCEL_OFFER", - "DELISTING", - "EXECUTED", - "EXPIRED_LISTING", - "EXPIRED_OFFER", - "FULFILL", - "LISTING", - "MINT", - "OFFER", - "SALE", - "TRANSFER", -] as const; - -export type ActivityType = (typeof activityTypes)[number]; - -export interface PortfolioActivity { - activity_type: ActivityType; - collection_address: string; - collection_is_verified: boolean; - collection_name: string; - from: string; - metadata?: TokenMetadata; - price: string; - time_stamp: number; - to: string; - token_id: string; - transaction_hash: string | null; - currency?: { - contract: string; - decimals: number; - symbol: string; - } | null; -} - -export interface PortfolioOffers { - collection_address: string; - collection_name: string; - currency_address: string; - expire_at: number; - floor_difference: string | null; - from_address: string; - hash: string; - is_verified: boolean; - metadata?: TokenMetadata; - offer_id: number; - price: string; - to_address: string | null; - token_id: string; - is_listed: boolean; - listing: { - currency_address: string | null; - end_amount: string | null; - end_date: number | null; - is_auction: boolean; - order_hash: string; - start_amount: string | null; - start_date: number | null; - }; - currency?: { - contract: string; - decimals: number; - symbol: string; - } | null; -} - -export interface CollectionActivity { - activity_type: ActivityType; - address: string; - from: string; - is_verified: boolean; - name: string; - price: string; - time_stamp: number; - to: string; - token_id: string; - token_metadata: TokenMetadata | null; - transaction_hash: string | null; - currency?: { - contract: string; - decimals: number; - symbol: string; - } | null; -} - -export interface TokenOffer { - expire_at: number; - floor_difference: number | null; - hash: string; - offer_id: number; - price: string; - source: string; -} - -export interface TokenApiResponse { - result: Token; -} - -export interface OwnersTokensApiResponse { - result: Token[]; -} - -export interface PortfolioStats { - total_value: string | null; -} - -export interface TokenMarketData { - buy_in_progress: boolean; - created_timestamp: number | null; - floor: string | null; - has_offer: boolean; - is_listed: boolean; - last_price: string | null; - listing: { - currency_address: string | null; - end_amount: string | null; - end_date: number | null; - is_auction: boolean; - order_hash: string; - start_amount: string | null; - start_date: number | null; - }; - owner: string; - top_offer: { - amount: string; - currency_address: string; - end_date: number; - order_hash: string; - start_date: number; - }; - updated_timestamp: number; -} - -export interface ContractInfo { - contract_address: string; - contract_type: string; - image: string; - name: string; - symbol: string; -} - -export interface PricesResult { - ethereum: { - price: number; - }; - starknet: { - price: number; - }; -} - -export interface SystemStatus { - status: string; -} - -export interface TokenActivity { - activity_type: ActivityType; - from: string | null; - price: string | null; - time_stamp: number; - to: string | null; - transaction_hash: string | null; - currency?: { - contract: string; - decimals: number; - symbol: string; - } | null; -} - -export interface Filters { - traits: Record; -} - -export interface LatestSales { - collection_address: string; - collection_name: string; - token_id: string; - from: string; - metadata: TokenMetadata | null; - price: string; - timestamp: number; - to: string; - transaction_hash: string | null; - currency: { - contract: string; - decimals: number; - symbol: string; - } | null; -} - -export interface TrendingNow { - collection_address: string; - collection_image: string; - collection_name: string; - floor_difference: number; - floor_price: string | null; - preview_nfts: [{ metadata?: TokenMetadata }, { metadata?: TokenMetadata }, { metadata?: TokenMetadata }]; -} - -export interface LiveAuctions { - collection_address: string; - token_id: string; - end_timestamp: number; - metadata?: TokenMetadata; -} - export type RealmMetadata = { name: string; description: string; @@ -377,17 +7,3 @@ export type RealmMetadata = { value: string | number; }[]; }; - -export type SeasonPassMint = { - node: { - __typename?: "Token__Balance"; - tokenMetadata: { - __typename: "ERC721__Token"; - tokenId: string; - metadataDescription: string; - imagePath: string; - contractAddress: string; - metadata: string; - }; - }; -} | null; diff --git a/client/apps/landing/src/utils/leaderboard.tsx b/client/apps/landing/src/utils/leaderboard.tsx deleted file mode 100644 index db87214ba..000000000 --- a/client/apps/landing/src/utils/leaderboard.tsx +++ /dev/null @@ -1,12 +0,0 @@ -export const calculateLordsShare = (points: number, totalPoints: number, prizePoolAmount: number): number => { - if (totalPoints === 0) return 0; - - const playerShare = (points / totalPoints) * prizePoolAmount; - return Math.floor(playerShare); -}; - -export const calculatePlayerSharePercentage = (points: number, totalPoints: number): number => { - if (totalPoints === 0) return 0; - - return Math.floor((points / totalPoints) * 100); -}; diff --git a/client/apps/landing/tsconfig.app.tsbuildinfo b/client/apps/landing/tsconfig.app.tsbuildinfo index b60f4b603..b6dab9039 100644 --- a/client/apps/landing/tsconfig.app.tsbuildinfo +++ b/client/apps/landing/tsconfig.app.tsbuildinfo @@ -1 +1,113 @@ -{"root":["./src/config.ts","./src/main.tsx","./src/routetree.gen.ts","./src/vite-env.d.ts","./src/components/layouts/dashboard-layout.tsx","./src/components/modules/animated-grid.tsx","./src/components/modules/app-sidebar.tsx","./src/components/modules/bridge-in.tsx","./src/components/modules/bridge-out-step-1.tsx","./src/components/modules/bridge-out-step-2.tsx","./src/components/modules/bridge.tsx","./src/components/modules/cartridge-connect-button.tsx","./src/components/modules/data-card.tsx","./src/components/modules/data.tsx","./src/components/modules/filters.tsx","./src/components/modules/mode-toggle.tsx","./src/components/modules/realm-card.tsx","./src/components/modules/realm-mint-dialog.tsx","./src/components/modules/realms-grid.tsx","./src/components/modules/season-pass-mint-dialog.tsx","./src/components/modules/season-pass-row.tsx","./src/components/modules/season-pass.tsx","./src/components/modules/select-nft-actions.tsx","./src/components/modules/swap-panel.tsx","./src/components/modules/top-navigation.tsx","./src/components/providers/starknet.tsx","./src/components/providers/cartridge-controller.tsx","./src/components/providers/theme-provider.tsx","./src/components/typography/type-h1.tsx","./src/components/typography/type-h2.tsx","./src/components/typography/type-h3.tsx","./src/components/typography/type-h4.tsx","./src/components/typography/type-p.tsx","./src/components/ui/selectresources.tsx","./src/components/ui/badge.tsx","./src/components/ui/button.tsx","./src/components/ui/card.tsx","./src/components/ui/checkbox.tsx","./src/components/ui/collapsible.tsx","./src/components/ui/command.tsx","./src/components/ui/custom-iframe.tsx","./src/components/ui/dialog.tsx","./src/components/ui/dropdown-menu.tsx","./src/components/ui/input.tsx","./src/components/ui/label.tsx","./src/components/ui/multi-select.tsx","./src/components/ui/popover.tsx","./src/components/ui/select.tsx","./src/components/ui/separator.tsx","./src/components/ui/sheet.tsx","./src/components/ui/sidebar.tsx","./src/components/ui/skeleton.tsx","./src/components/ui/sonner.tsx","./src/components/ui/switch.tsx","./src/components/ui/tabs.tsx","./src/components/ui/tooltip.tsx","./src/components/ui/elements/button.tsx","./src/components/ui/elements/listselect.tsx","./src/components/ui/elements/numberinput.tsx","./src/components/ui/elements/resourcecost.tsx","./src/components/ui/elements/resourceicon.tsx","./src/components/ui/utils/utils.ts","./src/dojo/contractcomponents.ts","./src/dojo/createclientcomponents.ts","./src/dojo/createsystemcalls.ts","./src/dojo/setup.ts","./src/dojo/setupnetwork.ts","./src/dojo/world.ts","./src/dojo/modelmanager/configmanager.ts","./src/dojo/modelmanager/resourcemanager.ts","./src/hooks/use-lords.tsx","./src/hooks/use-mobile.tsx","./src/hooks/useaccountorburner.tsx","./src/hooks/usebridge.tsx","./src/hooks/usecollectiontokens.tsx","./src/hooks/usemintseasonpass.tsx","./src/hooks/useminttestrealm.tsx","./src/hooks/usenftselection.tsx","./src/hooks/usetravel.tsx","./src/hooks/context/dojocontext.tsx","./src/hooks/gql/execute.ts","./src/hooks/gql/fragment-masking.ts","./src/hooks/gql/gql.ts","./src/hooks/gql/graphql.ts","./src/hooks/gql/index.ts","./src/hooks/helpers/userealms.tsx","./src/hooks/helpers/useresources.tsx","./src/hooks/query/players.tsx","./src/hooks/query/realms.tsx","./src/lib/utils.ts","./src/lib/ark/getcollectiontokens.ts","./src/routes/__root.tsx","./src/routes/bridge.lazy.tsx","./src/routes/index.lazy.tsx","./src/routes/mint.lazy.tsx","./src/routes/my-empire.tsx","./src/routes/passes.lazy.tsx","./src/routes/trade.lazy.tsx","./src/stories/button.stories.tsx","./src/stories/dashboard-layout.stories.tsx","./src/stories/data-card.stories.tsx","./src/stories/season-pass-row.stories.tsx","./src/stories/season-pass.stories.tsx","./src/stories/swap-panel.stories.tsx","./src/stories/swap.stories.tsx","./src/stories/top-navigation.stories.tsx","./src/types/index.ts","./env.ts"],"errors":true,"version":"5.7.2"} \ No newline at end of file +{ + "root": [ + "./src/config.ts", + "./src/main.tsx", + "./src/routetree.gen.ts", + "./src/vite-env.d.ts", + "./src/components/layouts/dashboard-layout.tsx", + "./src/components/modules/animated-grid.tsx", + "./src/components/modules/app-sidebar.tsx", + "./src/components/modules/bridge-in.tsx", + "./src/components/modules/bridge-out-step-1.tsx", + "./src/components/modules/bridge-out-step-2.tsx", + "./src/components/modules/bridge.tsx", + "./src/components/modules/cartridge-connect-button.tsx", + "./src/components/modules/data-card.tsx", + "./src/components/modules/data.tsx", + "./src/components/modules/filters.tsx", + "./src/components/modules/mode-toggle.tsx", + "./src/components/modules/realm-card.tsx", + "./src/components/modules/realm-mint-dialog.tsx", + "./src/components/modules/realms-grid.tsx", + "./src/components/modules/season-pass-mint-dialog.tsx", + "./src/components/modules/season-pass-row.tsx", + "./src/components/modules/season-pass.tsx", + "./src/components/modules/select-nft-actions.tsx", + "./src/components/modules/swap-panel.tsx", + "./src/components/modules/top-navigation.tsx", + "./src/components/providers/starknet.tsx", + "./src/components/providers/cartridge-controller.tsx", + "./src/components/providers/theme-provider.tsx", + "./src/components/typography/type-h1.tsx", + "./src/components/typography/type-h2.tsx", + "./src/components/typography/type-h3.tsx", + "./src/components/typography/type-h4.tsx", + "./src/components/typography/type-p.tsx", + "./src/components/ui/selectresources.tsx", + "./src/components/ui/badge.tsx", + "./src/components/ui/button.tsx", + "./src/components/ui/card.tsx", + "./src/components/ui/checkbox.tsx", + "./src/components/ui/collapsible.tsx", + "./src/components/ui/command.tsx", + "./src/components/ui/dialog.tsx", + "./src/components/ui/dropdown-menu.tsx", + "./src/components/ui/input.tsx", + "./src/components/ui/label.tsx", + "./src/components/ui/multi-select.tsx", + "./src/components/ui/popover.tsx", + "./src/components/ui/select.tsx", + "./src/components/ui/separator.tsx", + "./src/components/ui/sheet.tsx", + "./src/components/ui/sidebar.tsx", + "./src/components/ui/skeleton.tsx", + "./src/components/ui/sonner.tsx", + "./src/components/ui/switch.tsx", + "./src/components/ui/tabs.tsx", + "./src/components/ui/tooltip.tsx", + "./src/components/ui/elements/button.tsx", + "./src/components/ui/elements/listselect.tsx", + "./src/components/ui/elements/numberinput.tsx", + "./src/components/ui/elements/resourcecost.tsx", + "./src/components/ui/elements/resourceicon.tsx", + "./src/components/ui/utils/utils.ts", + "./src/dojo/contractcomponents.ts", + "./src/dojo/createclientcomponents.ts", + "./src/dojo/createsystemcalls.ts", + "./src/dojo/setup.ts", + "./src/dojo/setupnetwork.ts", + "./src/dojo/world.ts", + "./src/dojo/modelmanager/configmanager.ts", + "./src/dojo/modelmanager/resourcemanager.ts", + "./src/hooks/use-lords.tsx", + "./src/hooks/use-mobile.tsx", + "./src/hooks/useaccountorburner.tsx", + "./src/hooks/usebridge.tsx", + "./src/hooks/usecollectiontokens.tsx", + "./src/hooks/usemintseasonpass.tsx", + "./src/hooks/useminttestrealm.tsx", + "./src/hooks/usenftselection.tsx", + "./src/hooks/usetravel.tsx", + "./src/hooks/context/dojocontext.tsx", + "./src/hooks/gql/execute.ts", + "./src/hooks/gql/fragment-masking.ts", + "./src/hooks/gql/gql.ts", + "./src/hooks/gql/graphql.ts", + "./src/hooks/gql/index.ts", + "./src/hooks/helpers/userealms.tsx", + "./src/hooks/helpers/useresources.tsx", + "./src/hooks/query/players.tsx", + "./src/hooks/query/realms.tsx", + "./src/lib/utils.ts", + "./src/lib/ark/getcollectiontokens.ts", + "./src/routes/__root.tsx", + "./src/routes/bridge.lazy.tsx", + "./src/routes/index.lazy.tsx", + "./src/routes/mint.lazy.tsx", + "./src/routes/my-empire.tsx", + "./src/routes/passes.lazy.tsx", + "./src/routes/trade.lazy.tsx", + "./src/stories/button.stories.tsx", + "./src/stories/dashboard-layout.stories.tsx", + "./src/stories/data-card.stories.tsx", + "./src/stories/season-pass-row.stories.tsx", + "./src/stories/season-pass.stories.tsx", + "./src/stories/swap-panel.stories.tsx", + "./src/stories/swap.stories.tsx", + "./src/stories/top-navigation.stories.tsx", + "./src/types/index.ts", + "./env.ts" + ], + "errors": true, + "version": "5.7.2" +} diff --git a/client/config/speed.ts b/client/config/speed.ts deleted file mode 100644 index 2c68f8d6d..000000000 --- a/client/config/speed.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { QUEST_RESOURCES } from "@bibliothecadao/eternum"; - -export const MAX_QUEST_RESOURCES = Object.fromEntries( - Object.entries(QUEST_RESOURCES).map(([questType, resources]) => [ - questType, - resources.map((resource) => ({ - resource: resource.resource, - amount: resource.amount * 10000000, - })), - ]), -); diff --git a/client/sdk/packages/eternum/src/dojo/components/contractComponents.ts b/client/sdk/packages/eternum/src/dojo/contractComponents.ts similarity index 100% rename from client/sdk/packages/eternum/src/dojo/components/contractComponents.ts rename to client/sdk/packages/eternum/src/dojo/contractComponents.ts diff --git a/client/sdk/packages/eternum/src/dojo/components/createClientComponents.ts b/client/sdk/packages/eternum/src/dojo/createClientComponents.ts similarity index 100% rename from client/sdk/packages/eternum/src/dojo/components/createClientComponents.ts rename to client/sdk/packages/eternum/src/dojo/createClientComponents.ts diff --git a/client/sdk/packages/eternum/src/dojo/index.ts b/client/sdk/packages/eternum/src/dojo/index.ts new file mode 100644 index 000000000..a668e9cb1 --- /dev/null +++ b/client/sdk/packages/eternum/src/dojo/index.ts @@ -0,0 +1,2 @@ +export * from "./contractComponents"; +export * from "./createClientComponents"; diff --git a/client/sdk/packages/eternum/src/index.ts b/client/sdk/packages/eternum/src/index.ts index f991f7b8f..59ed7c8b6 100644 --- a/client/sdk/packages/eternum/src/index.ts +++ b/client/sdk/packages/eternum/src/index.ts @@ -1,5 +1,6 @@ export * from "./config"; export * from "./constants"; +export * from "./dojo"; export * from "./modelManager"; export * from "./provider"; export * from "./types"; diff --git a/client/sdk/packages/eternum/src/modelManager/ArmyManager.ts b/client/sdk/packages/eternum/src/modelManager/ArmyManager.ts index 3d8415835..7dc6e149e 100644 --- a/client/sdk/packages/eternum/src/modelManager/ArmyManager.ts +++ b/client/sdk/packages/eternum/src/modelManager/ArmyManager.ts @@ -3,7 +3,7 @@ import { getEntityIdFromKeys } from "@dojoengine/utils"; import { uuid } from "@latticexyz/utils"; import { Account, AccountInterface } from "starknet"; import { ResourcesIds } from "../constants"; -import { ClientComponents } from "../dojo/components/createClientComponents"; +import { ClientComponents } from "../dojo/createClientComponents"; import { EternumProvider } from "../provider"; import { ID } from "../types"; import { ResourceManager } from "./ResourceManager"; diff --git a/client/sdk/packages/eternum/src/modelManager/ArmyMovementManager.ts b/client/sdk/packages/eternum/src/modelManager/ArmyMovementManager.ts index ad325a054..e89d821cb 100644 --- a/client/sdk/packages/eternum/src/modelManager/ArmyMovementManager.ts +++ b/client/sdk/packages/eternum/src/modelManager/ArmyMovementManager.ts @@ -9,7 +9,7 @@ import { getNeighborHexes, ResourcesIds, } from "../constants"; -import { ClientComponents } from "../dojo/components/createClientComponents"; +import { ClientComponents } from "../dojo/createClientComponents"; import { EternumProvider } from "../provider"; import { ContractAddress, ID, TravelTypes, type HexPosition } from "../types"; import { multiplyByPrecision } from "../utils"; diff --git a/client/sdk/packages/eternum/src/modelManager/BattleManager.ts b/client/sdk/packages/eternum/src/modelManager/BattleManager.ts index 9aabb7c6f..6e86ac291 100644 --- a/client/sdk/packages/eternum/src/modelManager/BattleManager.ts +++ b/client/sdk/packages/eternum/src/modelManager/BattleManager.ts @@ -1,7 +1,7 @@ import { ComponentValue, Components, Has, HasValue, getComponentValue, runQuery } from "@dojoengine/recs"; import { getEntityIdFromKeys } from "@dojoengine/utils"; import { EternumGlobalConfig, MIN_TROOPS_BATTLE } from "../constants"; -import { ClientComponents } from "../dojo/components/createClientComponents"; +import { ClientComponents } from "../dojo/createClientComponents"; import { EternumProvider } from "../provider"; import { BattleSide, Health, ID } from "../types"; import { multiplyByPrecision } from "../utils"; diff --git a/client/sdk/packages/eternum/src/modelManager/ConfigManager.ts b/client/sdk/packages/eternum/src/modelManager/ConfigManager.ts index 9dfde0af4..2137b7fa0 100644 --- a/client/sdk/packages/eternum/src/modelManager/ConfigManager.ts +++ b/client/sdk/packages/eternum/src/modelManager/ConfigManager.ts @@ -14,7 +14,7 @@ import { StructureType, WORLD_CONFIG_ID, } from "../constants"; -import { ContractComponents } from "../dojo/components/contractComponents"; +import { ContractComponents } from "../dojo/contractComponents"; import { TickIds, TravelTypes } from "../types"; export class ClientConfigManager { diff --git a/client/sdk/packages/eternum/src/modelManager/LeaderboardManager.ts b/client/sdk/packages/eternum/src/modelManager/LeaderboardManager.ts index 02344f6e4..2feb3dda0 100644 --- a/client/sdk/packages/eternum/src/modelManager/LeaderboardManager.ts +++ b/client/sdk/packages/eternum/src/modelManager/LeaderboardManager.ts @@ -1,7 +1,7 @@ import { Entity, getComponentValue, HasValue, runQuery } from "@dojoengine/recs"; import { getEntityIdFromKeys } from "@dojoengine/utils"; import { RESOURCE_RARITY, ResourcesIds, WORLD_CONFIG_ID } from "../constants"; -import { ClientComponents } from "../dojo/components/createClientComponents"; +import { ClientComponents } from "../dojo/createClientComponents"; import { ContractAddress, GuildInfo, ID, TickIds } from "../types"; import { configManager } from "./ConfigManager"; @@ -130,7 +130,7 @@ export class LeaderboardManager { const epochEndTimestamp = season.is_over && nextEpoch === undefined ? season.ended_at - : nextEpoch?.start_timestamp ?? BigInt(currentTimestamp); + : (nextEpoch?.start_timestamp ?? BigInt(currentTimestamp)); const epochDuration = epochEndTimestamp - epoch.start_timestamp; const nbOfCycles = Number(epochDuration) / configManager.getTick(TickIds.Default); diff --git a/client/sdk/packages/eternum/src/modelManager/MarketManager.ts b/client/sdk/packages/eternum/src/modelManager/MarketManager.ts index 1bd17861f..084e4e17f 100644 --- a/client/sdk/packages/eternum/src/modelManager/MarketManager.ts +++ b/client/sdk/packages/eternum/src/modelManager/MarketManager.ts @@ -1,7 +1,7 @@ import { getComponentValue, HasValue, runQuery, type ComponentValue } from "@dojoengine/recs"; import { getEntityIdFromKeys } from "@dojoengine/utils"; import { ResourcesIds } from "../constants"; -import { ClientComponents } from "../dojo/components/createClientComponents"; +import { ClientComponents } from "../dojo/createClientComponents"; import { ContractAddress, ID } from "../types"; import { configManager } from "./ConfigManager"; diff --git a/client/sdk/packages/eternum/src/modelManager/ResourceInventoryManager.ts b/client/sdk/packages/eternum/src/modelManager/ResourceInventoryManager.ts index 6e382b550..02e69ba63 100644 --- a/client/sdk/packages/eternum/src/modelManager/ResourceInventoryManager.ts +++ b/client/sdk/packages/eternum/src/modelManager/ResourceInventoryManager.ts @@ -1,7 +1,7 @@ import { getComponentValue } from "@dojoengine/recs"; import { getEntityIdFromKeys } from "@dojoengine/utils"; import { uuid } from "@latticexyz/utils"; -import { ClientComponents } from "../dojo/components/createClientComponents"; +import { ClientComponents } from "../dojo/createClientComponents"; import { EternumProvider } from "../provider"; import { type ID, type Resource } from "../types"; import { DojoAccount } from "./types"; diff --git a/client/sdk/packages/eternum/src/modelManager/ResourceManager.ts b/client/sdk/packages/eternum/src/modelManager/ResourceManager.ts index f64a03792..66816df12 100644 --- a/client/sdk/packages/eternum/src/modelManager/ResourceManager.ts +++ b/client/sdk/packages/eternum/src/modelManager/ResourceManager.ts @@ -2,7 +2,7 @@ import { getComponentValue } from "@dojoengine/recs"; import { getEntityIdFromKeys } from "@dojoengine/utils"; import { BuildingType, CapacityConfigCategory, ResourcesIds, StructureType } from "../constants"; -import { ClientComponents } from "../dojo/components/createClientComponents"; +import { ClientComponents } from "../dojo/createClientComponents"; import { ID } from "../types"; import { gramToKg, multiplyByPrecision } from "../utils"; import { configManager } from "./ConfigManager"; diff --git a/client/sdk/packages/eternum/src/modelManager/StaminaManager.ts b/client/sdk/packages/eternum/src/modelManager/StaminaManager.ts index 265091ef3..83a59b379 100644 --- a/client/sdk/packages/eternum/src/modelManager/StaminaManager.ts +++ b/client/sdk/packages/eternum/src/modelManager/StaminaManager.ts @@ -1,7 +1,7 @@ import { ComponentValue, getComponentValue } from "@dojoengine/recs"; import { getEntityIdFromKeys } from "@dojoengine/utils"; import { ResourcesIds, WORLD_CONFIG_ID } from "../constants"; -import { ClientComponents } from "../dojo/components/createClientComponents"; +import { ClientComponents } from "../dojo/createClientComponents"; import { ID } from "../types"; export class StaminaManager { diff --git a/client/sdk/packages/eternum/src/modelManager/TileManager.ts b/client/sdk/packages/eternum/src/modelManager/TileManager.ts index 802a37916..a7b2fcc18 100644 --- a/client/sdk/packages/eternum/src/modelManager/TileManager.ts +++ b/client/sdk/packages/eternum/src/modelManager/TileManager.ts @@ -14,7 +14,7 @@ import { getDirectionBetweenAdjacentHexes, getNeighborHexes, } from "../constants"; -import { ClientComponents } from "../dojo/components/createClientComponents"; +import { ClientComponents } from "../dojo/createClientComponents"; import { EternumProvider } from "../provider"; import { ContractAddress, HexPosition, ID, Position } from "../types"; import { configManager } from "./ConfigManager"; diff --git a/client/sdk/packages/eternum/src/modelManager/types/index.ts b/client/sdk/packages/eternum/src/modelManager/types/index.ts index 57ecff119..653679737 100644 --- a/client/sdk/packages/eternum/src/modelManager/types/index.ts +++ b/client/sdk/packages/eternum/src/modelManager/types/index.ts @@ -1,6 +1,6 @@ import { ComponentValue } from "@dojoengine/recs"; import { Account, AccountInterface } from "starknet"; -import { ClientComponents } from "../../dojo/components/createClientComponents"; +import { ClientComponents } from "../../dojo/createClientComponents"; import { Position } from "../../types"; export type DojoAccount = Account | AccountInterface; diff --git a/client/sdk/packages/eternum/src/modelManager/utils/ArmyMovementUtils.ts b/client/sdk/packages/eternum/src/modelManager/utils/ArmyMovementUtils.ts index adef9a162..db730a977 100644 --- a/client/sdk/packages/eternum/src/modelManager/utils/ArmyMovementUtils.ts +++ b/client/sdk/packages/eternum/src/modelManager/utils/ArmyMovementUtils.ts @@ -1,6 +1,6 @@ import { type ComponentValue } from "@dojoengine/recs"; import { EternumGlobalConfig, ResourcesIds } from "../../constants"; -import { ClientComponents } from "../../dojo/components/createClientComponents"; +import { ClientComponents } from "../../dojo/createClientComponents"; import { divideByPrecision, gramToKg } from "../../utils"; import { configManager } from "../ConfigManager"; diff --git a/client/sdk/packages/eternum/src/modelManager/utils/LeaderboardUtils.ts b/client/sdk/packages/eternum/src/modelManager/utils/LeaderboardUtils.ts index aeca9d959..af47db650 100644 --- a/client/sdk/packages/eternum/src/modelManager/utils/LeaderboardUtils.ts +++ b/client/sdk/packages/eternum/src/modelManager/utils/LeaderboardUtils.ts @@ -1,5 +1,5 @@ import { ComponentValue } from "@dojoengine/recs"; -import { ClientComponents } from "../../dojo/components/createClientComponents"; +import { ClientComponents } from "../../dojo/createClientComponents"; import { Resource } from "../../types"; import { divideByPrecision } from "../../utils"; import { ClientConfigManager, configManager } from "../ConfigManager"; diff --git a/client/sdk/packages/eternum/src/scripts/extract.ts b/client/sdk/packages/eternum/src/scripts/extract.ts deleted file mode 100644 index 1982c4453..000000000 --- a/client/sdk/packages/eternum/src/scripts/extract.ts +++ /dev/null @@ -1,97 +0,0 @@ -import * as fs from "fs"; -import * as path from "path"; - -interface Example { - methodName: string; - description: string; - code: string; - params: Array<{ - name: string; - description: string; - }>; -} - -function extractExamples(filePath: string): string { - try { - // Read the file content - const content = fs.readFileSync(filePath, "utf8"); - - // Pattern to match full JSDoc blocks with examples - const methodPattern = /\/\*\*\s*([\s\S]*?)\*\/\s*public\s+async\s+([a-zA-Z_]+)/g; - const paramPattern = /@param\s+props\.([a-zA-Z_]+)\s*-\s*([^\n]+)/g; - const examplePattern = /@example[\s\S]*?```typescript\n([\s\S]*?)```/; - - const examples: Example[] = []; - let match: RegExpExecArray | null; - - // Extract all examples - while ((match = methodPattern.exec(content)) !== null) { - const docBlock = match[1]; - const methodName = match[2]; - - // Get description (first line after /** and before @) - const description = docBlock.split("\n")[1].trim().replace(/^\* /, ""); - - // Get parameters - const params: Array<{ name: string; description: string }> = []; - let paramMatch; - while ((paramMatch = paramPattern.exec(docBlock)) !== null) { - params.push({ - name: paramMatch[1], - description: paramMatch[2].trim(), - }); - } - - // Get example code - const exampleMatch = docBlock.match(examplePattern); - if (exampleMatch) { - const code = exampleMatch[1].trim(); - examples.push({ - methodName, - description, - code, - params, - }); - } - } - - // Generate text content - const text = generateText(examples); - - // Write to file - const outputPath = path.join(path.dirname(filePath), "provider-examples.ts"); - fs.writeFileSync(outputPath, `export const PROVIDER_EXAMPLES = \`${text}\`;`); - - console.log(`Examples extracted to ${outputPath}`); - return text; - } catch (error) { - console.error("Error processing file:", error); - return ""; - } -} - -function generateText(examples: Example[]): string { - let text = "Eternum Provider Examples\n\n"; - - examples.forEach(({ methodName, description, code, params }) => { - text += `${methodName}\n`; - text += "=".repeat(methodName.length) + "\n\n"; - text += `${description}\n\n`; - - text += "Parameters:\n"; - params.forEach((param) => { - text += `- ${param.name}: ${param.description}\n`; - }); - text += "\n"; - - text += "Example:\n"; - text += code; - text += "\n\n"; - }); - - return text; -} - -// Run the extractor -const filePath = path.join(process.cwd(), "../provider/index.ts"); -extractExamples(filePath); diff --git a/client/sdk/packages/eternum/src/scripts/extractBuildings.ts b/client/sdk/packages/eternum/src/scripts/extractBuildings.ts deleted file mode 100644 index 12388a688..000000000 --- a/client/sdk/packages/eternum/src/scripts/extractBuildings.ts +++ /dev/null @@ -1,22 +0,0 @@ -import * as fs from "fs"; -import { BUILDING_COSTS, BuildingType, ResourcesIds } from "../constants"; - -const buildingCosts = Object.entries(BUILDING_COSTS).reduce((output, [buildingId, costs]) => { - const buildingName = BuildingType[Number(buildingId)].toUpperCase(); - - if (costs.length === 0) { - return output + `${buildingName}\n`; - } - - output += `${buildingName}:\n`; - for (const cost of costs) { - const resourceName = ResourcesIds[cost.resource]; - output += ` ${resourceName}: ${cost.amount}\n`; - } - output += "\n"; - - return output; -}, ""); - -// Write to file -fs.writeFileSync("buildingCosts.ts", `export const BUILDING_COSTS_TEXT = \`${buildingCosts}\`;`);