Skip to content

Commit

Permalink
- add break page for sepolia
Browse files Browse the repository at this point in the history
- add vercel analytics code
- add code for future optimistic updates
  • Loading branch information
starknetdev committed May 20, 2024
1 parent 39d07e7 commit ad5bd3e
Show file tree
Hide file tree
Showing 13 changed files with 103 additions and 14 deletions.
2 changes: 1 addition & 1 deletion indexer/env-sepolia
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
GAME="0x02b66531874c952844913b8cbc573878c794112b546cbf39409013e33d4777fe"
GAME="0x00e55a2cde54c0051a72e44e81ddeed12103cc1cd1a20dc14fe52520e69b14ea"
START=60000
MONGO_CONNECTION_STRING="mongodb://mongo:mongo@mongo:27017"
MONGO_DB="mongo"
Expand Down
2 changes: 1 addition & 1 deletion indexer/graphql/Dockerfile.sepolia
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ RUN python3 -m pip install pycryptodome
RUN poetry config virtualenvs.create false
RUN poetry install

ENTRYPOINT [ "indexer", "graphql", "--mongo", "mongodb://${MONGO_USERNAME}:${MONGO_PASSWORD}@54.74.126.103:27017", "--port", "8080" ]
ENTRYPOINT [ "indexer", "graphql", "--mongo", "mongodb://${MONGO_USERNAME}:${MONGO_PASSWORD}@34.245.17.93:27017", "--port", "8080" ]
44 changes: 44 additions & 0 deletions indexer/restart-compose-sepolia.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/bash

# Path to your docker-compose.yml file
COMPOSE_PATH="sepolia-compose.yaml"

# Container names (as specified in docker-compose.yml)
CONTAINER_NAMES=("indexer-adventurers_indexer-1" "indexer-battles_indexer-1" "indexer-beasts_indexer-1" "indexer-discoveries_indexer-1" "indexer-items_indexer-1" "indexer-scores_indexer-1")

# Time to wait between checks (5mins / 300 seconds)
INTERVAL=300

# Check if a block has been processed in the last minute
check_container_activity() {
local CONTAINER_NAME="$1"
LAST_LOG=$(docker logs "$CONTAINER_NAME" 2>&1 | tail -1) # Assuming you want the last log entry
echo "Extracted log: $LAST_LOG" # Print timestamp for verification
LAST_TIMESTAMP=$(echo "$LAST_LOG" | sed -E 's/\x1B\[[0-9;]*[JKmsu]//g' | cut -d' ' -f1)

echo "Extracted timestamp: $LAST_TIMESTAMP" # Print timestamp for verification

# Convert timestamp to epoch (seconds since 1970)
LAST_EPOCH=$(date -d "$LAST_TIMESTAMP" +%s)
CURRENT_EPOCH=$(date +%s)
echo "Current time difference: $((CURRENT_EPOCH - LAST_EPOCH)) seconds"

# If the difference is more than the interval, return 1 (unhealthy)
if (( CURRENT_EPOCH - LAST_EPOCH > INTERVAL )); then
return 1
else
return 0
fi
}

while true; do
for CONTAINER_NAME in "${CONTAINER_NAMES[@]}"; do
if ! check_container_activity "$CONTAINER_NAME"; then
echo "Container $CONTAINER_NAME seems to be stuck. Restarting..."
docker-compose -f $COMPOSE_PATH stop "$CONTAINER_NAME"
docker-compose -f $COMPOSE_PATH up -d "$CONTAINER_NAME"
# # Add a notification mechanism here if needed
fi
done
sleep $INTERVAL
done
2 changes: 1 addition & 1 deletion ui/.env.preview
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ NEXT_PUBLIC_RPC_API_KEY=efb20d63-c5e0-4f5d-ab72-ef7add92779f
NEXT_PUBLIC_LS_GQL_URL=https://survivor-sepolia-indexer.realms.world/graphql
NEXT_PUBLIC_TOKENS_GQL_URL=https://testnet.realms.world/api/graphql
NEXT_PUBLIC_ETH_ADDRESS=0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7
NEXT_PUBLIC_GAME_ADDRESS=0x02b66531874c952844913b8cbc573878c794112b546cbf39409013e33d4777fe
NEXT_PUBLIC_GAME_ADDRESS=0x027069eaf29f2db58ff8321b58f162b9e8365304688fd96b01f1a0dd17d07fd3
NEXT_PUBLIC_OLD_GAME_ADDRESS=0x0
NEXT_PUBLIC_LORDS_ADDRESS=0x019c92fa87f4d5e3be25c3dd6a284f30282a07e87cd782f5fd387b82c8142017
NEXT_PUBLIC_BEASTS_ADDRESS=0x020c7c02c973ffa3a48fb78e9472b679c72c11b59512f524154ade0a39f54136
Expand Down
1 change: 1 addition & 0 deletions ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"@types/node": "18.15.11",
"@types/react": "18.0.31",
"@types/react-dom": "18.0.11",
"@vercel/analytics": "^1.2.2",
"autoprefixer": "^10.4.14",
"class-variance-authority": "^0.4.0",
"clsx": "^1.2.1",
Expand Down
8 changes: 6 additions & 2 deletions ui/src/app/components/start/Spawn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,11 @@ export const Spawn = ({
}
};

const onMainnet = process.env.NEXT_PUBLIC_NETWORK === "mainnet";
const onMainnet =
process.env.NEXT_PUBLIC_NETWORK === "mainnet" ||
process.env.NEXT_PUBLIC_NETWORK === "sepolia";

const waitEstimate = 12 * averageBlockTime; // add one for closer estimate
const waitEstimate = 2 * averageBlockTime;

const { data: blockData } = useBlock({
refetchInterval: false,
Expand All @@ -130,6 +132,8 @@ export const Spawn = ({
setFetchedAverageBlockTime(true);
};

console.log(averageBlockTime);

useEffect(() => {
if (onMainnet && !fetchedAverageBlockTime && currentBlockNumber > 0) {
fetchData();
Expand Down
17 changes: 13 additions & 4 deletions ui/src/app/containers/BeastScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ export default function BeastScreen({
(state) => state.data.battlesByBeastQuery?.battles || []
);

const mainnetBotProtection = process.env.NEXT_PUBLIC_NETWORK === "mainnet";
const mainnetBotProtection =
process.env.NEXT_PUBLIC_NETWORK === "mainnet" ||
process.env.NEXT_PUBLIC_NETWORK === "sepolia";

const { data: blockData } = useBlock({
refetchInterval:
Expand Down Expand Up @@ -96,7 +98,12 @@ export default function BeastScreen({
label: "TILL DEATH",
action: async () => {
resetNotification();
await attack(true, beastData);
if (adventurer?.level === 1) {
const entropyBlockData = await getBlock(adventurer?.startBlock! + 1);
await attack(true, beastData, entropyBlockData?.block_hash ?? 0);
} else {
await attack(true, beastData);
}
},
disabled:
adventurer?.beastHealth == undefined ||
Expand Down Expand Up @@ -184,7 +191,7 @@ export default function BeastScreen({
const currentBlockNumber = (blockData as Block)?.block_number ?? 0;

const revealBlockReached =
currentBlockNumber >= (adventurer?.revealBlock ?? 0);
currentBlockNumber >= (adventurer?.revealBlock! + 1 ?? 0);

useEffect(() => {
if (revealBlockReached) {
Expand All @@ -197,6 +204,8 @@ export default function BeastScreen({
return <BattleLog />;
}

console.log(revealBlockReached, mainnetBotProtection, averageBlockTime);

return (
<div className="sm:w-2/3 flex flex-col sm:flex-row h-full">
{!revealBlockReached && mainnetBotProtection && (
Expand Down Expand Up @@ -267,7 +276,7 @@ export default function BeastScreen({
<div className="flex flex-row items-center gap-2">
Reveal:
<div className="border border-terminal-green p-2">
{adventurer?.revealBlock}
{adventurer?.revealBlock! + 1}
</div>
</div>
</div>
Expand Down
8 changes: 8 additions & 0 deletions ui/src/app/containers/InterludeScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export default function InterludeScreen({
const nextEntropyTime =
adventurerCreatedTime + secondsUntilNextEntropy * 1000;
setNextEntropyTime(nextEntropyTime);
console.log(secondsUntilNextEntropy, averageBlockTime, "hello");
};

const onMainnet = process.env.NEXT_PUBLIC_NETWORK === "mainnet";
Expand All @@ -34,6 +35,13 @@ export default function InterludeScreen({
getNextEntropyTime();
}, []);

console.log(
countDownExpired,
nextEntropyTime,
new Date().getTime(),
new Date(adventurer?.createdTime!).getTime()
);

return (
<>
{!countDownExpired && (
Expand Down
2 changes: 2 additions & 0 deletions ui/src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import { ApolloProvider } from "@apollo/client";
import { gameClient, goldenTokenClient } from "@/app/lib/clients";
import { Analytics } from "@vercel/analytics/react";
import "@/app/globals.css";

export default function RootLayout({
Expand All @@ -23,6 +24,7 @@ export default function RootLayout({
<ApolloProvider client={gameClient}>
<ApolloProvider client={goldenTokenClient}>{children}</ApolloProvider>
</ApolloProvider>
<Analytics />
</body>
</html>
);
Expand Down
10 changes: 8 additions & 2 deletions ui/src/app/lib/utils/syscalls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -710,15 +710,20 @@ export function syscalls({
const setBlockHashTx: Call = {
contractAddress: gameContract?.address ?? "",
entrypoint: "set_starting_entropy",
calldata: [adventurer?.id?.toString() ?? "", blockHash!],
calldata: [
adventurer?.id?.toString() ?? "",
BigInt(blockHash! ?? 0).toString(),
],
};
const attackTx: Call = {
contractAddress: gameContract?.address ?? "",
entrypoint: "attack",
calldata: [adventurer?.id?.toString() ?? "", tillDeath ? "1" : "0"],
};
const attackCalls =
process.env.NEXT_PUBLIC_NETWORK === "mainnet"
(process.env.NEXT_PUBLIC_NETWORK === "mainnet" ||
process.env.NEXT_PUBLIC_NETWORK === "sepolia") &&
blockHash
? [setBlockHashTx, attackTx]
: [attackTx];
addToCalls(attackTx);
Expand All @@ -734,6 +739,7 @@ export function syscalls({
showTopUpDialog,
setTopUpAccount
);
// }
setTxHash(tx?.transaction_hash);
addTransaction({
hash: tx?.transaction_hash,
Expand Down
7 changes: 5 additions & 2 deletions ui/src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,10 @@ function Home({ updateConnectors }: HomeProps) {
<main
className={`min-h-screen container mx-auto flex flex-col sm:pt-8 sm:p-8 lg:p-10 2xl:p-20 `}
>
{introComplete ? (
<div className="text-3xl">
Loot Survivor is being reborn. More death coming soon.
</div>
{/* {introComplete ? (
<>
<NetworkSwitchError isWrongNetwork={isWrongNetwork} />
{screen === "onboarding" ? (
Expand Down Expand Up @@ -688,7 +691,7 @@ function Home({ updateConnectors }: HomeProps) {
</>
) : (
<Intro onIntroComplete={handleIntroComplete} />
)}
)} */}
</main>
);
}
2 changes: 1 addition & 1 deletion ui/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"moduleResolution": "Node",
"resolveJsonModule": true,
"isolatedModules": true,
"noUnusedLocals": true,
// "noUnusedLocals": true,
// "noUnusedParameters": true,
"noEmit": true,
"jsx": "preserve",
Expand Down
12 changes: 12 additions & 0 deletions ui/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1886,6 +1886,13 @@
"@typescript-eslint/types" "5.59.2"
eslint-visitor-keys "^3.3.0"

"@vercel/analytics@^1.2.2":
version "1.2.2"
resolved "https://registry.yarnpkg.com/@vercel/analytics/-/analytics-1.2.2.tgz#715d8f203a170c06ba36b363e03b048c03060d5d"
integrity sha512-X0rctVWkQV1e5Y300ehVNqpOfSOufo7ieA5PIdna8yX/U7Vjz0GFsGf4qvAhxV02uQ2CVt7GYcrFfddXXK2Y4A==
dependencies:
server-only "^0.0.1"

"@walletconnect/[email protected]":
version "2.12.2"
resolved "https://registry.yarnpkg.com/@walletconnect/core/-/core-2.12.2.tgz#12bd568b90daed876e58ebcc098c12843a3321e6"
Expand Down Expand Up @@ -5125,6 +5132,11 @@ semver@^7.3.7:
dependencies:
lru-cache "^6.0.0"

server-only@^0.0.1:
version "0.0.1"
resolved "https://registry.yarnpkg.com/server-only/-/server-only-0.0.1.tgz#0f366bb6afb618c37c9255a314535dc412cd1c9e"
integrity sha512-qepMx2JxAa5jjfzxG79yPPq+8BuFToHd1hm7kI+Z4zAq1ftQiP7HcxMhDDItrbtwVeLg/cY2JnKnrcFkmiswNA==

set-cookie-parser@^2.4.8:
version "2.6.0"
resolved "https://registry.yarnpkg.com/set-cookie-parser/-/set-cookie-parser-2.6.0.tgz#131921e50f62ff1a66a461d7d62d7b21d5d15a51"
Expand Down

0 comments on commit ad5bd3e

Please sign in to comment.