-
Notifications
You must be signed in to change notification settings - Fork 49
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 #2545
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 |
---|---|---|
|
@@ -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 ( | ||
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 using the LoadingOroborus component here for consistency with other loading states in the application |
||
<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; | ||
} | ||
|
||
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, | ||
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 retry logic here in case the fetch fails, rather than just setting loading to false immediately |
||
); | ||
).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.
The useEffect dependency array should include isStructuresLoading since it's used in fetchHyperstructureData