-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix structure owners & transfers #2544
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,18 +28,26 @@ export const syncPosition = async <S extends Schema>( | |
30_000, | ||
); | ||
}; | ||
export const syncBuildingQty = async <S extends Schema>( | ||
|
||
export const addToSubscriptionTwoKeyModelbyRealmEntityId = async <S extends Schema>( | ||
client: ToriiClient, | ||
components: Component<S, Metadata, undefined>[], | ||
entityID: string, | ||
entityID: string[], | ||
) => { | ||
await getEntities( | ||
client, | ||
{ | ||
Keys: { | ||
keys: [entityID, undefined], | ||
pattern_matching: "FixedLen" as PatternMatching, | ||
models: ["s0_eternum-BuildingQuantityv2"], | ||
Composite: { | ||
operator: "Or", | ||
clauses: [ | ||
...entityID.map((id) => ({ | ||
Keys: { | ||
keys: [id, undefined], | ||
pattern_matching: "VariableLen" as PatternMatching, | ||
models: ["s0_eternum-BuildingQuantityv2"], | ||
}, | ||
})), | ||
Comment on lines
+32
to
+49
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Refactor duplicate code in subscription functions The functions |
||
], | ||
}, | ||
}, | ||
components, | ||
|
@@ -49,12 +57,11 @@ export const syncBuildingQty = async <S extends Schema>( | |
); | ||
}; | ||
|
||
export const addToSubscriptionBuildingQty = async <S extends Schema>( | ||
export const addToSubscriptionOneKeyModelbyRealmEntityId = async <S extends Schema>( | ||
client: ToriiClient, | ||
components: Component<S, Metadata, undefined>[], | ||
entityID: string[], | ||
) => { | ||
const start = performance.now(); | ||
await getEntities( | ||
client, | ||
{ | ||
|
@@ -63,9 +70,9 @@ export const addToSubscriptionBuildingQty = async <S extends Schema>( | |
clauses: [ | ||
...entityID.map((id) => ({ | ||
Keys: { | ||
keys: [id, undefined], | ||
keys: [id], | ||
pattern_matching: "VariableLen" as PatternMatching, | ||
models: ["s0_eternum-BuildingQuantityv2"], | ||
models: ["s0_eternum-ArrivalTime", "s0_eternum-OwnedResourcesTracker"], | ||
}, | ||
})), | ||
], | ||
|
@@ -76,8 +83,6 @@ export const addToSubscriptionBuildingQty = async <S extends Schema>( | |
[], | ||
30_000, | ||
); | ||
const end = performance.now(); | ||
console.log("AddToSubscription Building qty", end - start); | ||
}; | ||
|
||
export const addToSubscription = async <S extends Schema>( | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -59,9 +59,10 @@ const usePlayerArrivals = () => { | |||||||||||||||
]; | ||||||||||||||||
|
||||||||||||||||
const getArrivalsWithResourceOnPosition = useCallback((positions: Position[]) => { | ||||||||||||||||
return positions.flatMap((position) => { | ||||||||||||||||
const arrivals = positions.flatMap((position) => { | ||||||||||||||||
return Array.from(runQuery([HasValue(Position, { x: position.x, y: position.y }), ...queryFragments])); | ||||||||||||||||
}); | ||||||||||||||||
return arrivals; | ||||||||||||||||
Comment on lines
+62
to
+65
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This intermediate variable assignment is unnecessary. You can return the flatMap result directly.
Suggested change
|
||||||||||||||||
}, []); | ||||||||||||||||
|
||||||||||||||||
const createArrivalInfo = useCallback( | ||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ import { useFragmentMines } from "@/hooks/helpers/useFragmentMines"; | |
import { useGuilds } from "@/hooks/helpers/useGuilds"; | ||
import { useHyperstructureProgress, useHyperstructures } from "@/hooks/helpers/useHyperstructures"; | ||
import { useResourceBalance } from "@/hooks/helpers/useResources"; | ||
import { useWorldStore } from "@/hooks/store/useWorldLoading"; | ||
import { FragmentMinePanel } from "@/ui/components/fragmentMines/FragmentMinePanel"; | ||
import { HintSection } from "@/ui/components/hints/HintModal"; | ||
import { DisplayedAccess, HyperstructurePanel } from "@/ui/components/hyperstructures/HyperstructurePanel"; | ||
|
@@ -16,16 +17,9 @@ import { ViewOnMapIcon } from "@/ui/components/military/ArmyManagementCard"; | |
import { Checkbox } from "@/ui/elements/Checkbox"; | ||
import { HintModalButton } from "@/ui/elements/HintModalButton"; | ||
import { ResourceIcon } from "@/ui/elements/ResourceIcon"; | ||
import { currencyFormat, currencyIntlFormat, divideByPrecision, getEntityIdFromKeys } from "@/ui/utils/utils"; | ||
import { | ||
BattleSide, | ||
ContractAddress, | ||
HYPERSTRUCTURE_CONFIG_ID, | ||
ID, | ||
ResourcesIds, | ||
findResourceById, | ||
} from "@bibliothecadao/eternum"; | ||
import { Metadata, getComponentValue } from "@dojoengine/recs"; | ||
import { currencyFormat, currencyIntlFormat, divideByPrecision } from "@/ui/utils/utils"; | ||
import { BattleSide, ContractAddress, ID, ResourcesIds, findResourceById } from "@bibliothecadao/eternum"; | ||
import { Metadata } from "@dojoengine/recs"; | ||
import { S } from "@dojoengine/recs/dist/types-3444e4c1"; | ||
import { getEntities } from "@dojoengine/state"; | ||
import { ToriiClient } from "@dojoengine/torii-wasm"; | ||
|
@@ -39,10 +33,18 @@ export const WorldStructuresMenu = ({ className }: { className?: string }) => { | |
network: { toriiClient, contractComponents }, | ||
} = useDojo(); | ||
|
||
const isStructuresLoading = useWorldStore((state) => state.isStructuresLoading); | ||
const setStructuresLoading = useWorldStore((state) => state.setStructuresLoading); | ||
|
||
useEffect(() => { | ||
const fetchData = async () => { | ||
try { | ||
await fetchHyperstructureData(toriiClient, contractComponents as any); | ||
await fetchHyperstructureData( | ||
toriiClient, | ||
contractComponents as any, | ||
isStructuresLoading, | ||
setStructuresLoading, | ||
); | ||
} catch (error) { | ||
console.error("Failed to fetch hyperstructure data:", error); | ||
} | ||
|
@@ -140,6 +142,14 @@ export const WorldStructuresMenu = ({ className }: { className?: string }) => { | |
[selectedTab, hyperstructures, fragmentMines, showOnlyMine, account.address, myHyperstructures], | ||
); | ||
|
||
if (isStructuresLoading) { | ||
return ( | ||
<div className="flex items-center justify-center h-full"> | ||
<div className="text-gold">Loading structures...</div> | ||
</div> | ||
); | ||
} | ||
|
||
return ( | ||
<> | ||
<HintModalButton className="absolute top-1 right-1" section={HintSection.WorldStructures} /> | ||
|
@@ -333,16 +343,17 @@ const EntityHeader = ({ entity }: { entity: any }) => { | |
); | ||
}; | ||
|
||
const fetchHyperstructureData = async (client: ToriiClient, components: Component<S, Metadata, undefined>[]) => { | ||
const hyperstructureConfig = getComponentValue( | ||
(components as any).HyperstructureResourceConfig, | ||
getEntityIdFromKeys([HYPERSTRUCTURE_CONFIG_ID, 4n]), | ||
); | ||
|
||
if (hyperstructureConfig) { | ||
const fetchHyperstructureData = async ( | ||
client: ToriiClient, | ||
components: Component<S, Metadata, undefined>[], | ||
isStructuresLoading: boolean, | ||
setStructuresLoading: (loading: boolean) => void, | ||
) => { | ||
if (!isStructuresLoading) { | ||
return; | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider adding a timeout to prevent infinite loading states |
||
console.log("Fetching hyperstructure data"); | ||
await getEntities( | ||
client, | ||
{ | ||
|
@@ -363,13 +374,6 @@ const fetchHyperstructureData = async (client: ToriiClient, components: Componen | |
models: ["s0_eternum-Epoch", "s0_eternum-Progress"], | ||
}, | ||
}, | ||
{ | ||
Keys: { | ||
keys: [HYPERSTRUCTURE_CONFIG_ID.toString(), undefined], | ||
pattern_matching: "VariableLen", | ||
models: [], | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
|
@@ -378,5 +382,7 @@ const fetchHyperstructureData = async (client: ToriiClient, components: Componen | |
[], | ||
40_000, | ||
false, | ||
); | ||
).finally(() => { | ||
setStructuresLoading(false); | ||
}); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding error handling and retry logic for failed entity fetches