Skip to content

Commit

Permalink
add structures to bridge
Browse files Browse the repository at this point in the history
  • Loading branch information
aymericdelab committed Dec 22, 2024
1 parent 1d3d7e5 commit 7d2eaad
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 56 deletions.
14 changes: 7 additions & 7 deletions landing/src/components/modules/bridge-in.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export const BridgeIn = () => {
});
};

const { playerRealms } = useEntities();
const { playerStructures } = useEntities();

const travelTime = useMemo(() => {
if (realmEntityId) {
Expand Down Expand Up @@ -238,21 +238,21 @@ export const BridgeIn = () => {
}
>
{address ? (
<SelectValue placeholder="Select Realm To Transfer" />
<SelectValue placeholder="Select Structure To Transfer" />
) : (
<div> -- Connect your wallet --</div>
)}
</SelectTrigger>
<SelectContent>
{playerRealms?.length
? playerRealms.map((realm) => {
{playerStructures?.length
? playerStructures.map((structure) => {
return (
<SelectItem key={realm.realmId} value={realm.entityId.toString()}>
#{realm.realmId} - {realm.name}
<SelectItem key={structure.realmId} value={structure.entityId.toString()}>
#{structure.realmId} - {structure.name}
</SelectItem>
);
})
: "No Realms settled in Eternum"}
: "No Structure settled in Eternum"}
</SelectContent>
</Select>
</div>
Expand Down
10 changes: 5 additions & 5 deletions landing/src/components/modules/bridge-out-step-1.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export const BridgeOutStep1 = () => {
}
}, [getBalance, realmEntityId]);

const { playerRealms } = useEntities();
const { playerStructures } = useEntities();

const travelTime = useMemo(() => {
if (realmEntityId) {
Expand Down Expand Up @@ -226,13 +226,13 @@ export const BridgeOutStep1 = () => {
: "border-gold/40")
}
>
{address ? <SelectValue placeholder="Select Settled Realm" /> : <div> -- Connect your wallet --</div>}
{address ? <SelectValue placeholder="Select Structure" /> : <div> -- Connect your wallet --</div>}
</SelectTrigger>
<SelectContent>
{playerRealms?.map((realm) => {
{playerStructures?.map((structure) => {
return (
<SelectItem key={realm.realmId} value={realm.entityId.toString()}>
#{realm.realmId} - {realm.name}
<SelectItem key={structure.realmId} value={structure.entityId.toString()}>
#{structure.realmId} - {structure.name}
</SelectItem>
);
})}
Expand Down
6 changes: 2 additions & 4 deletions landing/src/components/modules/bridge-out-step-2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@ import { BridgeFees } from "./bridge-fees";
export const BridgeOutStep2 = () => {
const { address } = useAccount();

const { playerRealms } = useEntities();
const { playerStructures } = useEntities();

console.log({ playerRealms });

const { donkeyInfos } = useDonkeyArrivals(playerRealms.map((realm) => realm.entityId));
const { donkeyInfos } = useDonkeyArrivals(playerStructures.map((structure) => structure.entityId));

const [isLoading, setIsLoading] = useState(false);
const [isRefreshing, setIsRefreshing] = useState(false);
Expand Down
2 changes: 1 addition & 1 deletion landing/src/hooks/gql/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7352,7 +7352,7 @@ export const GetCapacitySpeedConfigDocument = new TypedDocumentString(`
`) as unknown as TypedDocumentString<GetCapacitySpeedConfigQuery, GetCapacitySpeedConfigQueryVariables>;
export const GetEternumOwnerRealmIdsDocument = new TypedDocumentString(`
query getEternumOwnerRealmIds($accountAddress: ContractAddress!) {
s0EternumOwnerModels(where: {address: $accountAddress}) {
s0EternumOwnerModels(where: {address: $accountAddress}, limit: 1000) {
edges {
node {
address
Expand Down
39 changes: 0 additions & 39 deletions landing/src/hooks/helpers/use-sync-entity.tsx

This file was deleted.

23 changes: 23 additions & 0 deletions landing/src/hooks/helpers/useEntities.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ export function isS0EternumRealm(model: any): model is S0EternumRealm {
return model?.__typename === "s0_eternum_Realm";
}

export function isS0EternumStructure(model: any): model is S0EternumRealm {
return model?.__typename === "s0_eternum_Structure";
}

export const useEntities = () => {
const { address } = useAccount();
const { getRealmNameById } = useRealm();
Expand All @@ -40,8 +44,27 @@ export const useEntities = () => {
.filter(Boolean) as { realmId: number; entityId: number; name: string }[];
}, [data, getRealmNameById]);

const playerStructures = useMemo(() => {
if (!data) return [];

return data.s0EternumOwnerModels?.edges
?.map((structure) => {
const structureModel = structure?.node?.entity?.models?.find(isS0EternumStructure);
if (!structureModel) return null;
const realmModel = structure?.node?.entity?.models?.find(isS0EternumRealm);
const entityId = structure?.node?.entity_id;
return {
realmId: realmModel?.realm_id || entityId,
entityId,
name: realmModel ? getRealmNameById(realmModel?.realm_id ?? 0) : "Structure",
};
})
.filter(Boolean) as { realmId: number | undefined; entityId: number; name: string }[];
}, [data, getRealmNameById]);

return {
playerRealms,
playerStructures,
isLoading,
};
};

0 comments on commit 7d2eaad

Please sign in to comment.