Skip to content

Commit

Permalink
congif
Browse files Browse the repository at this point in the history
  • Loading branch information
ponderingdemocritus committed Dec 12, 2024
2 parents 1cc2263 + 9fc09d6 commit e795852
Show file tree
Hide file tree
Showing 23 changed files with 409 additions and 327 deletions.
49 changes: 30 additions & 19 deletions client/src/dojo/setup.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import {
BUILDING_CATEGORY_POPULATION_CONFIG_ID,
HYPERSTRUCTURE_CONFIG_ID,
WORLD_CONFIG_ID
} from "@bibliothecadao/eternum";
import { DojoConfig } from "@dojoengine/core";
import { getSyncEntities, getSyncEvents, syncEntities } from "@dojoengine/state";
import { getEntities, getSyncEntities, getSyncEvents, syncEntities } from "@dojoengine/state";
import { Clause } from "@dojoengine/torii-client";
import { createClientComponents } from "./createClientComponents";
import { createSystemCalls } from "./createSystemCalls";
Expand All @@ -19,37 +20,47 @@ export async function setup({ ...config }: DojoConfig) {
const components = createClientComponents(network);
const systemCalls = createSystemCalls(network);

const clauses: Clause[] = [
{
Keys: {
keys: [undefined],
pattern_matching: "FixedLen",
models: [],
},
},
const configClauses: Clause[] = [
{
Keys: {
keys: [WORLD_CONFIG_ID.toString(), undefined, undefined],
pattern_matching: "FixedLen",
models: [],
},
},
{
Keys: {
keys: [WORLD_CONFIG_ID.toString(), undefined],
pattern_matching: "FixedLen",
models: [],
},
},
{
Keys: {
keys: [BUILDING_CATEGORY_POPULATION_CONFIG_ID.toString(), undefined],
pattern_matching: "FixedLen",
models: [],
},
},
{
Keys: {
keys: [HYPERSTRUCTURE_CONFIG_ID.toString(), undefined],
pattern_matching: "VariableLen",
models: [],
},
},
];

await getEntities(network.toriiClient, {Composite: {operator: "Or", clauses: configClauses}}, network.contractComponents as any);

const clauses: Clause[] = [
{
Keys: {
keys: [WORLD_CONFIG_ID.toString(), undefined],
pattern_matching: "FixedLen",
models: [],
},
},
{
Keys: {
keys: [BUILDING_CATEGORY_POPULATION_CONFIG_ID.toString(), undefined],
keys: [undefined],
pattern_matching: "FixedLen",
models: [],
},
},


];

// fetch all existing entities from torii
Expand Down
31 changes: 29 additions & 2 deletions client/src/ui/components/entities/Entity.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { addToSubscription } from "@/dojo/queries";
import { useDojo } from "@/hooks/context/DojoContext";
import { ArrivalInfo } from "@/hooks/helpers/use-resource-arrivals";
import { getArmyByEntityId } from "@/hooks/helpers/useArmies";
Expand All @@ -10,7 +11,7 @@ import { divideByPrecision, formatTime, getEntityIdFromKeys } from "@/ui/utils/u
import { EntityType } from "@bibliothecadao/eternum";
import { useComponentValue } from "@dojoengine/react";
import clsx from "clsx";
import React, { useMemo } from "react";
import React, { useEffect, useMemo, useState } from "react";
import { DepositResources } from "../resources/DepositResources";

const entityIcon: Record<EntityType, string> = {
Expand All @@ -32,6 +33,8 @@ type EntityProps = {
export const EntityArrival = ({ arrival, ...props }: EntityProps) => {
const dojo = useDojo();

const [isSyncing, setIsSyncing] = useState(false);

const { getEntityInfo, getEntityName } = useEntitiesUtils();
const { getResourcesFromBalance } = useResourcesUtils();
const nextBlockTimestamp = useUIStore.getState().nextBlockTimestamp;
Expand All @@ -45,6 +48,26 @@ export const EntityArrival = ({ arrival, ...props }: EntityProps) => {
return getResourcesFromBalance(arrival.entityId);
}, [weight]);

useEffect(() => {
if (entityResources.length === 0) {
setIsSyncing(true);
const fetch = async () => {
try {
await addToSubscription(
dojo.network.toriiClient,
dojo.network.contractComponents as any,
arrival.entityId.toString(),
);
} catch (error) {
console.error("Fetch failed", error);
} finally {
setIsSyncing(false);
}
};
fetch();
}
}, [arrival.entityId, dojo.network.toriiClient, dojo.network.contractComponents, entityResources.length]);

const army = useMemo(() => getArmy(arrival.entityId), [arrival.entityId, entity.resources]);

const renderEntityStatus = useMemo(() => {
Expand All @@ -62,6 +85,10 @@ export const EntityArrival = ({ arrival, ...props }: EntityProps) => {
}, [nextBlockTimestamp, arrival.recipientEntityId, arrival.hasResources, entity.arrivalTime]);

const renderedResources = useMemo(() => {
if (isSyncing) {
return <div className="text-gold/50 italic">Syncing resources...</div>;
}

return entityResources
.filter(Boolean)
.map((resource) => (
Expand All @@ -74,7 +101,7 @@ export const EntityArrival = ({ arrival, ...props }: EntityProps) => {
amount={divideByPrecision(resource.amount)}
/>
));
}, [entityResources]);
}, [entityResources, isSyncing]);

const name = entity.entityType === EntityType.TROOP ? army?.name : entityName[entity.entityType];

Expand Down
8 changes: 6 additions & 2 deletions landing/dojoConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@ const {
// const isLocal = VITE_PUBLIC_CHAIN === "local" || VITE_PUBLIC_CHAIN === "testnet";
// const manifest = VITE_PUBLIC_DEV === true && isLocal ? devManifest : productionManifest;

let manifest = VITE_PUBLIC_DEV === true ? devManifest : sepoliaManifest;
const manifestMap = {
'local': devManifest,
'mainnet': productionManifest,
'sepolia': sepoliaManifest
} as const;

manifest = VITE_PUBLIC_CHAIN === "mainnet" ? productionManifest : manifest;
const manifest = manifestMap[VITE_PUBLIC_CHAIN as keyof typeof manifestMap] ?? sepoliaManifest;

export const getManifest = () => {
return manifest;
Expand Down
12 changes: 6 additions & 6 deletions landing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
"@bibliothecadao/eternum": "workspace:^",
"@cartridge/connector": "^0.5.3",
"@cartridge/controller": "^0.5.3",
"@dojoengine/core": "1.0.1",
"@dojoengine/create-burner": "1.0.1",
"@dojoengine/react": "1.0.1",
"@dojoengine/core": "1.0.3-alpha.1",
"@dojoengine/create-burner": "1.0.3-alpha.1",
"@dojoengine/react": "1.0.3-alpha.1",
"@dojoengine/recs": "^2.0.13",
"@dojoengine/state": "1.0.1",
"@dojoengine/torii-client": "1.0.1",
"@dojoengine/utils": "1.0.1",
"@dojoengine/state": "1.0.3-alpha.1",
"@dojoengine/torii-client": "1.0.3-alpha.1",
"@dojoengine/utils": "1.0.3-alpha.1",
"@graphql-codegen/schema-ast": "^4.1.0",
"@graphql-typed-document-node/core": "^3.2.0",
"@headlessui/react": "^1.7.18",
Expand Down
10 changes: 6 additions & 4 deletions landing/src/components/modules/app-sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,12 @@ export function AppSidebar() {
return (
<Sidebar>
<SidebarContent>
<div className="flex flex-col items-center">
<EternumLogo className="w-24 h-24 fill-gold mx-auto pt-8" />
<TypeH2 className="p-3">Eternum</TypeH2>
</div>
<a href="/">
<div className="flex flex-col items-center">
<EternumLogo className="w-24 h-24 fill-gold mx-auto pt-8" />
<TypeH2 className="p-3">Eternum</TypeH2>
</div>
</a>
<SidebarGroup>
<SidebarGroupContent>
<SidebarMenu>
Expand Down
7 changes: 3 additions & 4 deletions landing/src/components/modules/bridge-fees.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ export const BridgeFees = ({
<div>{formatFee(feesForAllResources.reduce((sum, fees) => sum + Number(fees.totalFee), 0))} units</div>
</Button>
</CollapsibleTrigger>
<CollapsibleContent className="flex flex-col gap-4 py-4">
<CollapsibleContent className="flex flex-col ">
{feesForAllResources.map((fees) => {
const resourceName = ResourcesIds[fees.id as keyof typeof ResourcesIds];
return (
<div key={fees.id} className="flex flex-col gap-2">
<div key={fees.id} className="flex flex-col gap-2 py-4 border-b border-gold/15">
<div className="font-semibold text-sm">
<div className="flex justify-between w-full">
<span>{resourceName} </span>
Expand All @@ -114,11 +114,10 @@ export const BridgeFees = ({
</div>
<div>{fees.seasonPoolFee}</div>
</div>
<div className="flex justify-between text-xs mb-3">
<div className="flex justify-between text-xs">
<div>Client Fees ({calculateBridgeFeeDisplayPercent(bridgeConfig.client_fee_on_dpt_percent)}%)</div>
<div>{fees.clientFee}</div>
</div>
<hr />
</div>
);
})}
Expand Down
24 changes: 13 additions & 11 deletions landing/src/components/modules/bridge-in.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,11 @@ export const BridgeIn = () => {
throw new Error("No valid resources selected");
}

await bridgeIntoRealm(validResources, ADMIN_BANK_ENTITY_ID, BigInt(realmEntityId!));
setSelectedResourceIds([]);
setSelectedResourceAmounts({});
const resp = await bridgeIntoRealm(validResources, ADMIN_BANK_ENTITY_ID, BigInt(realmEntityId!));
if (resp) {
setSelectedResourceIds([]);
setSelectedResourceAmounts({});
}
} catch (error) {
console.error("Bridge into realm error:", error);
toast.error("Failed to transfer resources");
Expand Down Expand Up @@ -180,10 +182,10 @@ export const BridgeIn = () => {
<div>{displayAddress(address || "")}</div>
</div>
<div>
<div className="text-xs uppercase mb-1">To Realm</div>
<div className="text-xs text-slate-500 uppercase mb-1">To Realm</div>

<Select onValueChange={(value) => setRealmEntityId(Number(value))}>
<SelectTrigger className="w-full border-gold/15">
<SelectTrigger className="w-full bg-dark-brown [background:linear-gradient(45deg,#1a1311,#1a1311)_padding-box,conic-gradient(from_var(--border-angle),#8b7355_80%,_#c6a366_86%,_#e5c088_90%,_#c6a366_94%,_#8b7355)_border-box] border border-transparent animate-border">
<SelectValue placeholder="Select Realm To Transfer" />
</SelectTrigger>
<SelectContent>
Expand Down Expand Up @@ -256,17 +258,17 @@ export const BridgeIn = () => {
setResourceFees={setResourceFees}
type="deposit"
/>
<div className="flex flex-col gap-2 font-bold mt-3">
<div className="flex flex-col gap-2 font-bold mt-5">
<div className="flex justify-between">
<div>Total Amount Received</div>
<div>Resources Received</div>
</div>
{Object.entries(selectedResourceAmounts).map(([id, amount]) => {
if (amount === 0) return null;
const resourceName = ResourcesIds[id as keyof typeof ResourcesIds];
return (
<div key={id} className="flex justify-between text-sm font-normal">
<div className="flex items-center gap-2">
<ResourceIcon resource={resourceName} size="md" /> {resourceName}
<ResourceIcon resource={resourceName} size="sm" className="md:w-5 md:h-5" withTooltip={false} /> {resourceName}
</div>
<div>{(amount - Number(resourceFees.find((fee) => fee.id === id)?.totalFee ?? 0)).toFixed(2)}</div>
</div>
Expand All @@ -281,7 +283,7 @@ export const BridgeIn = () => {
disabled={
isLoading ||
!realmEntityId ||
donkeyBalance.balance <= donkeysNeeded ||
donkeyBalance.balance < donkeysNeeded ||
!Object.values(selectedResourceAmounts).some((amount) => amount > 0)
}
onClick={() => onBridgeIntoRealm()}
Expand Down Expand Up @@ -337,7 +339,7 @@ const ResourceInputRow = ({
: "0";

return (
<div className="rounded-lg p-3 border border-gold/15 shadow-lg bg-dark-brown flex gap-3 items-center">
<div key={id} className="rounded-lg p-3 border border-gold/15 shadow-lg bg-dark-brown flex gap-3 items-center">
<div className="relative w-full">
<Input
type="text"
Expand Down Expand Up @@ -390,7 +392,7 @@ const ResourceInputRow = ({
<>
{res?.id && (
<SelectItem
key={res?.id}
key={res.id}
disabled={Object.keys(selectedResourceAmounts).includes(res?.id.toString() ?? "")}
value={res?.id.toString() ?? ""}
>
Expand Down
12 changes: 6 additions & 6 deletions landing/src/components/modules/bridge-out-step-1.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,11 @@ export const BridgeOutStep1 = () => {
};
}),
);
console.log(validResources);
await bridgeStartWithdrawFromRealm(validResources, ADMIN_BANK_ENTITY_ID, BigInt(realmEntityId!));

setSelectedResourceIds([]);
setSelectedResourceAmounts({});
const tx = await bridgeStartWithdrawFromRealm(validResources, ADMIN_BANK_ENTITY_ID, BigInt(realmEntityId!));
if (tx) {
setSelectedResourceIds([]);
setSelectedResourceAmounts({});
}
} finally {
setIsLoading(false);
}
Expand All @@ -161,7 +161,7 @@ export const BridgeOutStep1 = () => {
<div className="flex flex-col min-w-40">
<div className="text-xs uppercase mb-1 ">From Realm</div>
<Select onValueChange={(value) => setRealmEntityId(value)}>
<SelectTrigger className="w-full border-gold/15">
<SelectTrigger className="w-full bg-dark-brown [background:linear-gradient(45deg,#1a1311,#1a1311)_padding-box,conic-gradient(from_var(--border-angle),#8b7355_80%,_#c6a366_86%,_#e5c088_90%,_#c6a366_94%,_#8b7355)_border-box] border border-transparent animate-border">
<SelectValue placeholder="Select Settled Realm" />
</SelectTrigger>
<SelectContent>
Expand Down
Loading

0 comments on commit e795852

Please sign in to comment.