Skip to content

Commit

Permalink
Merge into main (#2603)
Browse files Browse the repository at this point in the history
* Fix missing arrival when sending lords & donkeys (#2594)

* contracts: fix share points check

* contracts: fix share points check

* Add resource filter for contributions (#2596)

* Add resource filter for contributions

* Change % for specific resource contribution

* Fix missing donkeys in bridge step 2 (#2598)

* Fix missing donkeys in bridge step 2

* fix rerenders

* Remove filter

* Fix registration delay (#2602)

* Fix registration delay

* styling

* Open popup on load

* Add burned donkeys back (#2601)

---------

Co-authored-by: Credence <[email protected]>
Co-authored-by: Loaf <[email protected]>
  • Loading branch information
3 people authored Dec 26, 2024
1 parent 7e6a523 commit 9798c65
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 21 deletions.
6 changes: 6 additions & 0 deletions client/src/ui/layouts/World.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { ADMIN_BANK_ENTITY_ID } from "@bibliothecadao/eternum";
import { getComponentValue } from "@dojoengine/recs";
import { getEntityIdFromKeys } from "@dojoengine/utils";
import { env } from "../../../env";
import { rewards } from "../components/navigation/Config";
import { IS_MOBILE } from "../config";
import { LoadingOroborus } from "../modules/loading-oroborus";
import { LoadingScreen } from "../modules/LoadingScreen";
Expand Down Expand Up @@ -251,6 +252,11 @@ export const World = ({ backgroundImage }: { backgroundImage: string }) => {
fetch();
}, []);

const openPopup = useUIStore((state) => state.openPopup);
useEffect(() => {
openPopup(rewards);
}, []);

const battleViewContent = useMemo(
() => (
<div>
Expand Down
47 changes: 34 additions & 13 deletions client/src/ui/modules/rewards/Rewards.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import { shortString } from "starknet";
import { formatEther } from "viem";
import { env } from "../../../../env";

const REGISTRATION_DELAY = 1800; // 1 week
const REGISTRATION_DELAY = 60 * 60 * 24 * 4; // 4 days
const BRIDGE_OUT_DELAY = 60 * 60 * 24 * 2; // 2 days

export const Rewards = () => {
const {
Expand All @@ -35,6 +36,8 @@ export const Rewards = () => {

const [timeRemaining, setTimeRemaining] = useState<string>("");
const [isLoading, setIsLoading] = useState(false);
const [registrationTimeRemaining, setRegistrationTimeRemaining] = useState<string>("");
const [bridgeOutTimeRemaining, setBridgeOutTimeRemaining] = useState<string>("");

const prizePool = usePrizePool();
const togglePopup = useUIStore((state) => state.togglePopup);
Expand Down Expand Up @@ -77,15 +80,24 @@ export const Rewards = () => {
if (gameEnded) {
const calculateTimeRemaining = () => {
const currentTime = Math.floor(Date.now() / 1000);
const endTime = Number(gameEnded.timestamp + REGISTRATION_DELAY);

if (currentTime >= endTime) {
setTimeRemaining("Registration Closed");
return;
const registrationEndTime = Number(gameEnded.timestamp + REGISTRATION_DELAY);
const bridgeOutEndTime = Number(gameEnded.timestamp + BRIDGE_OUT_DELAY);

// Calculate registration time
if (currentTime >= registrationEndTime) {
setRegistrationTimeRemaining("Registration Closed");
} else {
const registrationDifference = registrationEndTime - currentTime;
setRegistrationTimeRemaining(formatTime(registrationDifference, undefined));
}

const difference = endTime - currentTime;
setTimeRemaining(formatTime(difference, undefined));
// Calculate bridge out time
if (currentTime >= bridgeOutEndTime) {
setBridgeOutTimeRemaining("Bridge Out Closed");
} else {
const bridgeOutDifference = bridgeOutEndTime - currentTime;
setBridgeOutTimeRemaining(formatTime(bridgeOutDifference, undefined));
}
};

calculateTimeRemaining();
Expand Down Expand Up @@ -135,10 +147,19 @@ export const Rewards = () => {
<div className="text-lg">{Number(formatEther(prizePool)).toFixed(2)} $LORDS</div>
</div>
</Compartment>
<Compartment>
</div>

<div className="grid grid-cols-2 gap-4">
<Compartment isCountdown>
<div className="text-center text-lg font-semibold self-center w-full">
<div className="text-md uppercase font-extrabold text-danger">Time left to register</div>
<div className="text-lg">{registrationTimeRemaining}</div>
</div>
</Compartment>
<Compartment isCountdown>
<div className="text-center text-lg font-semibold self-center w-full">
<div className="text-sm font-bold uppercase">Time left to register</div>
<div className="text-lg">{timeRemaining}</div>
<div className="text-md font-extrabold text-danger uppercase">Time left to bridge out</div>
<div className="text-lg">{bridgeOutTimeRemaining}</div>
</div>
</Compartment>
</div>
Expand Down Expand Up @@ -184,9 +205,9 @@ export const Rewards = () => {
);
};

const Compartment = ({ children }: { children: React.ReactNode }) => {
const Compartment = ({ children, isCountdown }: { children: React.ReactNode; isCountdown?: boolean }) => {
return (
<div className="flex flex-col w-full justify-center border-b border-brown/50 p-4 rounded-md bg-brown/50 bg-hex m-auto h-28">
<div className={`flex flex-col w-full justify-center border-b border-brown/50 p-4 rounded-md ${isCountdown ? 'bg-brown/70' : 'bg-brown/50'} bg-hex m-auto h-28 ${isCountdown ? 'border-2 border-danger/50' : ''}`}>
{children}
</div>
);
Expand Down
13 changes: 10 additions & 3 deletions contracts/src/systems/hyperstructure/contracts.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ trait IHyperstructureSystems<T> {
mod hyperstructure_systems {
use achievement::store::{Store, StoreTrait};
use core::array::ArrayIndex;
use core::poseidon::poseidon_hash_span;
use dojo::event::EventStorage;
use dojo::model::ModelStorage;

Expand Down Expand Up @@ -596,10 +597,16 @@ mod hyperstructure_systems {
let (hyperstructure_entity_id, index) = *hyperstructure_shareholder_epochs.at(i);

// ensure we don't double count points for the same hyperstructure
if points_already_added.get(hyperstructure_entity_id.into()) {
panic!("points already added for hyperstructure {}", hyperstructure_entity_id);

let points_already_added_key: felt252 = poseidon_hash_span(
array![hyperstructure_entity_id.into(), index.into()].span()
);

if points_already_added.get(points_already_added_key) {
panic!("points already added for hyperstructure {}, epoch {}", hyperstructure_entity_id, index);
};
points_already_added.insert(hyperstructure_entity_id.into(), true);

points_already_added.insert(points_already_added_key, true);

let epoch: Epoch = world.read_model((hyperstructure_entity_id, index));
let next_epoch: Epoch = world.read_model((hyperstructure_entity_id, index + 1));
Expand Down
12 changes: 7 additions & 5 deletions landing/src/dojo/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { createClientComponents } from "./createClientComponents";
import { createSystemCalls } from "./createSystemCalls";
import { ClientConfigManager } from "./modelManager/ConfigManager";
import { setupNetwork } from "./setupNetwork";
import { getEvents } from "@dojoengine/state";

export type SetupResult = Awaited<ReturnType<typeof setup>>;
export const configManager = ClientConfigManager.instance();
Expand Down Expand Up @@ -36,9 +37,9 @@ export async function setup({ ...config }: DojoConfig) {
const filteredEvents = [
"BurnDonkey",
// points
"HyperstructureCoOwnersChange",
"HyperstructureFinished",
"GameEnded",
// "HyperstructureCoOwnersChange",
// "HyperstructureFinished",
// "GameEnded",
];

const clauses: Clause[] = [
Expand Down Expand Up @@ -87,6 +88,7 @@ export async function setup({ ...config }: DojoConfig) {
const sync = await syncEntities(network.toriiClient, filteredModels as any, [], false);
*/
const eventSync = getEvents(
network.toriiClient,
network.contractComponents.events as any,
Expand All @@ -101,14 +103,14 @@ export async function setup({ ...config }: DojoConfig) {
false,
false,
);
*/

configManager.setDojo(components);

return {
network,
components,
systemCalls,
//sync,
/*eventSync,*/
eventSync,
};
}

0 comments on commit 9798c65

Please sign in to comment.