Skip to content

Commit

Permalink
fixes on undefined system
Browse files Browse the repository at this point in the history
  • Loading branch information
ametel01 committed Jan 2, 2024
1 parent 7806a15 commit c9ee099
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 2 additions & 2 deletions packages/testnet/frontend/src/hooks/usePlanetPosition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { GAMEADDRESS } from '../constants/addresses';
import gameContract from '../constants/nogame.json';
import { type Position } from '../shared/types';

const DefaultPosition = {
export const DefaultPosition: Position = {
system: 0,
orbit: 0,
};
Expand All @@ -22,5 +22,5 @@ export function usePlanetPosition(planetId: number | undefined) {
return DefaultPosition;
}

return data as unknown as Position;
return data as Position;
}
8 changes: 7 additions & 1 deletion packages/testnet/frontend/src/shared/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable no-unused-vars */
import BigNumber from 'bignumber.js';
import { type Position, type TechLevels } from '../types';
import { DefaultPosition } from '../../hooks/usePlanetPosition';

export const dataToNumber = (value: unknown[] | string | number | undefined) =>
new BigNumber(value as unknown as number).toNumber();
Expand Down Expand Up @@ -261,7 +262,12 @@ export function convertTechLevelsToNumbers(techLevels: TechLevels): {
return converted;
}

export function convertPositionToNumbers(position: Position): Position {
export function convertPositionToNumbers(
position?: Position
): Position | undefined {
if (!position) {
return DefaultPosition;
}
return {
system: Number(position.system),
orbit: Number(position.orbit),
Expand Down

0 comments on commit c9ee099

Please sign in to comment.