-
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
Enh/wonders #2367
Enh/wonders #2367
Changes from 3 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 |
---|---|---|
|
@@ -3,7 +3,7 @@ import { currencyFormat } from "../../../utils/utils"; | |
|
||
import { ArmyInfo, getArmyByEntityId } from "@/hooks/helpers/useArmies"; | ||
import { useQuery } from "@/hooks/helpers/useQuery"; | ||
import { useIsStructureImmune, useStructureImmunityTimer, useStructures } from "@/hooks/helpers/useStructures"; | ||
import { Structure, useIsStructureImmune, useStructureImmunityTimer, useStructures } from "@/hooks/helpers/useStructures"; | ||
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. Potential runtime error: Unsafe type assertion The type assertion Consider adding a null check or using optional chaining: - const timer = useStructureImmunityTimer(structure as Structure, nextBlockTimestamp || 0);
+ const timer = structure ? useStructureImmunityTimer(structure, nextBlockTimestamp || 0) : undefined; Also applies to: 58-58 |
||
import { ArmyCapacity } from "@/ui/elements/ArmyCapacity"; | ||
import { BaseThreeTooltip, Position } from "@/ui/elements/BaseThreeTooltip"; | ||
import { Headline } from "@/ui/elements/Headline"; | ||
|
@@ -55,7 +55,7 @@ const RaiderInfo = ({ army }: ArmyInfoLabelProps) => { | |
const nextBlockTimestamp = useUIStore((state) => state.nextBlockTimestamp); | ||
|
||
const isImmune = useIsStructureImmune(structure, nextBlockTimestamp || 0); | ||
const timer = useStructureImmunityTimer(structure, nextBlockTimestamp || 0); | ||
const timer = useStructureImmunityTimer(structure as Structure, nextBlockTimestamp || 0); | ||
|
||
return ( | ||
<BaseThreeTooltip | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -37,7 +37,7 @@ export const BattleInfoLabel = () => { | |||||
battleEntityId={battle.entity_id} | ||||||
dojo={dojo} | ||||||
currentTimestamp={currentTimestamp} | ||||||
structure={structure} | ||||||
structure={structure as Structure} | ||||||
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 Remove unnecessary type assertion The - structure={structure as Structure}
+ structure={structure} 📝 Committable suggestion
Suggested change
|
||||||
/> | ||||||
))} | ||||||
</div> | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import { useGuilds } from "@/hooks/helpers/useGuilds"; | ||
import { useQuery } from "@/hooks/helpers/useQuery"; | ||
import { useIsStructureImmune, useStructureImmunityTimer, useStructures } from "@/hooks/helpers/useStructures"; | ||
import { Structure, useIsStructureImmune, useStructureImmunityTimer, useStructures } from "@/hooks/helpers/useStructures"; | ||
import { BaseThreeTooltip, Position } from "@/ui/elements/BaseThreeTooltip"; | ||
import { Headline } from "@/ui/elements/Headline"; | ||
import { formatTime } from "@/ui/utils/utils"; | ||
|
@@ -47,7 +47,7 @@ export const StructureInfoLabel = () => { | |
const nextBlockTimestamp = useUIStore((state) => state.nextBlockTimestamp); | ||
|
||
const isImmune = useIsStructureImmune(structure, nextBlockTimestamp || 0); | ||
const timer = useStructureImmunityTimer(structure, nextBlockTimestamp || 0); | ||
const timer = useStructureImmunityTimer(structure as Structure, nextBlockTimestamp || 0); | ||
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. Add null check before type assertion The type assertion - const timer = useStructureImmunityTimer(structure as Structure, nextBlockTimestamp || 0);
+ const timer = structure ? useStructureImmunityTimer(structure, nextBlockTimestamp || 0) : 0;
|
||
|
||
return ( | ||
<> | ||
|
@@ -65,7 +65,7 @@ export const StructureInfoLabel = () => { | |
)} | ||
</Headline> | ||
<StructureListItem | ||
structure={structure} | ||
structure={structure as Structure} | ||
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. Use conditional rendering instead of type assertion Similar to the timer issue, casting potentially undefined - structure={structure as Structure}
+ structure={structure!} Additionally, consider adding a type guard: if (!structure) return null; before the JSX return statement. |
||
ownArmySelected={undefined} | ||
setShowMergeTroopsPopup={() => {}} | ||
maxInventory={3} | ||
|
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -1,4 +1,4 @@ | ||||||||||
import { useIsStructureImmune, useStructureByEntityId, useStructureImmunityTimer } from "@/hooks/helpers/useStructures"; | ||||||||||
import { Structure, useIsStructureImmune, useStructureByEntityId, useStructureImmunityTimer } from "@/hooks/helpers/useStructures"; | ||||||||||
import useUIStore from "@/hooks/store/useUIStore"; | ||||||||||
import { HintSection } from "@/ui/components/hints/HintModal"; | ||||||||||
import { HintModalButton } from "@/ui/elements/HintModalButton"; | ||||||||||
|
@@ -42,7 +42,7 @@ export const RealmDetails = () => { | |||||||||
); | ||||||||||
|
||||||||||
const isImmune = useIsStructureImmune(structure, nextBlockTimestamp || 0); | ||||||||||
const timer = useStructureImmunityTimer(structure, nextBlockTimestamp || 0); | ||||||||||
const timer = useStructureImmunityTimer(structure as Structure, nextBlockTimestamp || 0); | ||||||||||
|
||||||||||
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 Leverage existing checks for type safety The component already has proper null checking with - const timer = useStructureImmunityTimer(structure as Structure, nextBlockTimestamp || 0);
+ const timer = structure && isImmune
+ ? useStructureImmunityTimer(structure, nextBlockTimestamp || 0)
+ : 0; 📝 Committable suggestion
Suggested change
|
||||||||||
return ( | ||||||||||
structure && ( | ||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ import { BattleManager } from "@/dojo/modelManager/BattleManager"; | |
import { useDojo } from "@/hooks/context/DojoContext"; | ||
import { useBattleManager } from "@/hooks/helpers/battles/useBattles"; | ||
import { getArmiesByBattleId, getArmyByEntityId, useArmyByArmyEntityId } from "@/hooks/helpers/useArmies"; | ||
import { useStructureByEntityId, useStructureByPosition } from "@/hooks/helpers/useStructures"; | ||
import { Structure, useStructureByEntityId, useStructureByPosition } from "@/hooks/helpers/useStructures"; | ||
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. Improve type safety for Battle component structure prop The type assertion Consider these improvements:
- structure={structure as Structure}
+ structure={structure || undefined}
interface BattleProps {
structure?: Structure;
// ... other props
}
if (structure && !isStructure(structure)) {
console.warn('Invalid structure provided to Battle component');
} Also applies to: 147-147 |
||
import useUIStore from "@/hooks/store/useUIStore"; | ||
import { BattleSide } from "@bibliothecadao/eternum"; | ||
import { useMemo } from "react"; | ||
|
@@ -144,7 +144,7 @@ export const BattleView = () => { | |
defenderHealth={defenderHealth} | ||
defenderTroops={defenderTroops} | ||
userArmiesInBattle={armies.userArmiesInBattle} | ||
structure={structure} | ||
structure={structure as Structure} | ||
/> | ||
); | ||
}; |
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.
🛠️ Refactor suggestion
Remove redundant fallback for guildName
The fallback
|| ""
is unnecessary sinceguildName
is already initialized with an empty string on line 30 whenguildMember
is null. This creates redundant defensive programming.📝 Committable suggestion