Skip to content

Commit

Permalink
- upgrade starknet-react
Browse files Browse the repository at this point in the history
- fix type issues
  • Loading branch information
starknetdev committed Mar 18, 2024
1 parent 8586e15 commit f7692da
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 56 deletions.
2 changes: 1 addition & 1 deletion ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"@apollo/client": "^3.7.11",
"@cartridge/controller": "^0.3.18",
"@fontsource/vt323": "^4.5.10",
"@starknet-react/core": "^2.1.5",
"@starknet-react/core": "^2.5.0",
"@svgr/webpack": "^7.0.0",
"@types/js-cookie": "^3.0.3",
"@types/node": "18.15.11",
Expand Down
6 changes: 4 additions & 2 deletions ui/src/app/components/interlude/Lobby.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useState } from "react";
import { Block } from "starknet";
import { useQueriesStore } from "@/app/hooks/useQueryStore";
import { Adventurer, NullAdventurer } from "@/app/types";
import { useBlock } from "@starknet-react/core";
Expand All @@ -19,7 +20,8 @@ export default function Lobby() {
});
const handleFilterLobby = (adventurers: Adventurer[]) => {
return adventurers.filter(
(adventurer) => adventurer?.revealBlock! > blockData?.block_number!
(adventurer) =>
adventurer?.revealBlock! > (blockData as Block)?.block_number!
);
};

Expand Down Expand Up @@ -78,7 +80,7 @@ export default function Lobby() {
key={index}
adventurer={adventurer}
handleRowSelected={handleRowSelected}
currentBlock={blockData?.block_number!}
currentBlock={(blockData as Block)?.block_number!}
/>
)
)}
Expand Down
2 changes: 1 addition & 1 deletion ui/src/app/components/marketplace/MarketplaceRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const MarketplaceRow = ({
const enoughGold = calculatedNewGold >= itemPrice;

const checkTransacting = (item: string) => {
if (txData?.status == "RECEIVED") {
if (txData?.finality_status !== undefined) {
return transactingMarketIds?.includes(item);
} else {
return false;
Expand Down
4 changes: 2 additions & 2 deletions ui/src/app/components/navigation/TxActivity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ export const TxActivity = () => {
hash: hash ? hash : "0x0",
}) as { data: InvokeTransactionReceiptResponse };

if (data?.status === "ACCEPTED_ON_L2") {
if (data?.finality_status === "ACCEPTED_ON_L2") {
setTxAccepted(true);
}

if (data?.status === "REJECTED") {
if (data?.execution_status === "REVERTED") {
stopLoading("Rejected");
}

Expand Down
4 changes: 2 additions & 2 deletions ui/src/app/components/start/Spawn.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useState, useEffect } from "react";
import { CallData, Contract } from "starknet";
import { Block, CallData, Contract } from "starknet";
import { useAccount, useConnect, useBlock } from "@starknet-react/core";
import Image from "next/image";
import { TypeAnimation } from "react-type-animation";
Expand Down Expand Up @@ -120,7 +120,7 @@ export const Spawn = ({
refetchInterval: false,
});

const currentBlockNumber = blockData?.block_number ?? 0;
const currentBlockNumber = (blockData as Block)?.block_number ?? 0;

const [fetchedAverageBlockTime, setFetchedAverageBlockTime] = useState(false);

Expand Down
4 changes: 2 additions & 2 deletions ui/src/app/containers/BeastScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useEffect, useState } from "react";
import { useBlock } from "@starknet-react/core";
import { Contract } from "starknet";
import { Contract, Block } from "starknet";
import { BattleDisplay } from "@/app/components/beast/BattleDisplay";
import { BeastDisplay } from "@/app/components/beast/BeastDisplay";
import useLoadingStore from "@/app/hooks/useLoadingStore";
Expand Down Expand Up @@ -171,7 +171,7 @@ export default function BeastScreen({
</div>
);

const currentBlockNumber = blockData?.block_number ?? 0;
const currentBlockNumber = (blockData as Block)?.block_number ?? 0;

const revealBlockReached =
currentBlockNumber >= (adventurer?.revealBlock ?? 0);
Expand Down
2 changes: 1 addition & 1 deletion ui/src/app/containers/InventoryScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export default function InventoryScreen({
const gameData = new GameData();

const checkTransacting = (item: string) => {
if (txData?.status == "RECEIVED") {
if (txData?.finality_status !== undefined) {
return transactingItemIds?.includes(item);
} else {
return false;
Expand Down
4 changes: 2 additions & 2 deletions ui/src/app/containers/LeaderboardScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useEffect, useState } from "react";
import { Contract } from "starknet";
import { Block, Contract } from "starknet";
import { useBlock } from "@starknet-react/core";
import {
getAdventurerByXP,
Expand Down Expand Up @@ -45,7 +45,7 @@ export default function LeaderboardScreen({
refetchInterval: false,
});

const currentBlock = blockData?.block_number;
const currentBlock = (blockData as Block)?.block_number;

const { data, refetch, setData, setIsLoading, setNotLoading } =
useQueriesStore();
Expand Down
6 changes: 2 additions & 4 deletions ui/src/app/containers/TopUp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ import {
AccountInterface,
Contract,
DeclareTransactionReceiptResponse,
RevertedTransactionReceiptResponse,
RejectedTransactionReceiptResponse,
GetTransactionReceiptResponse,
} from "starknet";
import { ETH_PREFUND_AMOUNT } from "@/app/lib/burner";
import Eth from "public/icons/eth-2.svg";
Expand Down Expand Up @@ -77,8 +76,7 @@ interface SectionContentProps {
ethAmount?: number | undefined
) => Promise<
| DeclareTransactionReceiptResponse
| RevertedTransactionReceiptResponse
| RejectedTransactionReceiptResponse
| GetTransactionReceiptResponse
| undefined
>;
isToppingUpEth: boolean;
Expand Down
3 changes: 1 addition & 2 deletions ui/src/app/lib/burner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ export const ETH_PREFUND_AMOUNT = isMainnet

const rpc_addr = process.env.NEXT_PUBLIC_RPC_URL;
const provider = new Provider({
rpc: { nodeUrl: rpc_addr! },
sequencer: { baseUrl: rpc_addr! },
nodeUrl: rpc_addr!,
});

interface UseBurnerProps {
Expand Down
33 changes: 16 additions & 17 deletions ui/src/app/lib/utils/syscalls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
InvokeTransactionReceiptResponse,
Contract,
AccountInterface,
RevertedTransactionReceiptResponse,
GetTransactionReceiptResponse,
Provider,
} from "starknet";
import { GameData } from "@/app/lib/data/GameData";
Expand Down Expand Up @@ -38,8 +38,7 @@ import { TRANSACTION_WAIT_RETRY_INTERVAL } from "@/app/lib/constants";

const rpc_addr = process.env.NEXT_PUBLIC_RPC_URL;
const provider = new Provider({
rpc: { nodeUrl: rpc_addr! },
sequencer: { baseUrl: rpc_addr! },
nodeUrl: rpc_addr!,
});

export interface SyscallsProps {
Expand Down Expand Up @@ -348,11 +347,11 @@ export function syscalls({
});
// Handle if the tx was reverted
if (
(receipt as RevertedTransactionReceiptResponse).execution_status ===
(receipt as GetTransactionReceiptResponse).execution_status ===
"REVERTED"
) {
throw new Error(
(receipt as RevertedTransactionReceiptResponse).revert_reason
(receipt as GetTransactionReceiptResponse).revert_reason
);
}
// Here we need to process the StartGame event first and use the output for AmbushedByBeast event
Expand Down Expand Up @@ -463,11 +462,11 @@ export function syscalls({
});
// Handle if the tx was reverted
if (
(receipt as RevertedTransactionReceiptResponse).execution_status ===
(receipt as GetTransactionReceiptResponse).execution_status ===
"REVERTED"
) {
throw new Error(
(receipt as RevertedTransactionReceiptResponse).revert_reason
(receipt as GetTransactionReceiptResponse).revert_reason
);
}
const events = await parseEvents(
Expand Down Expand Up @@ -733,11 +732,11 @@ export function syscalls({
});
// Handle if the tx was reverted
if (
(receipt as RevertedTransactionReceiptResponse).execution_status ===
(receipt as GetTransactionReceiptResponse).execution_status ===
"REVERTED"
) {
throw new Error(
(receipt as RevertedTransactionReceiptResponse).revert_reason
(receipt as GetTransactionReceiptResponse).revert_reason
);
}
// reset battles by tx hash
Expand Down Expand Up @@ -1001,11 +1000,11 @@ export function syscalls({
});
// Handle if the tx was reverted
if (
(receipt as RevertedTransactionReceiptResponse).execution_status ===
(receipt as GetTransactionReceiptResponse).execution_status ===
"REVERTED"
) {
throw new Error(
(receipt as RevertedTransactionReceiptResponse).revert_reason
(receipt as GetTransactionReceiptResponse).revert_reason
);
}
// Add optimistic data
Expand Down Expand Up @@ -1207,11 +1206,11 @@ export function syscalls({
});
// Handle if the tx was reverted
if (
(receipt as RevertedTransactionReceiptResponse).execution_status ===
(receipt as GetTransactionReceiptResponse).execution_status ===
"REVERTED"
) {
throw new Error(
(receipt as RevertedTransactionReceiptResponse).revert_reason
(receipt as GetTransactionReceiptResponse).revert_reason
);
}
// Add optimistic data
Expand Down Expand Up @@ -1359,11 +1358,11 @@ export function syscalls({
});
// Handle if the tx was reverted
if (
(receipt as RevertedTransactionReceiptResponse).execution_status ===
(receipt as GetTransactionReceiptResponse).execution_status ===
"REVERTED"
) {
throw new Error(
(receipt as RevertedTransactionReceiptResponse).revert_reason
(receipt as GetTransactionReceiptResponse).revert_reason
);
}
const events = await parseEvents(
Expand Down Expand Up @@ -1444,11 +1443,11 @@ export function syscalls({
});
// Handle if the tx was reverted
if (
(receipt as RevertedTransactionReceiptResponse).execution_status ===
(receipt as GetTransactionReceiptResponse).execution_status ===
"REVERTED"
) {
throw new Error(
(receipt as RevertedTransactionReceiptResponse).revert_reason
(receipt as GetTransactionReceiptResponse).revert_reason
);
}
const events = await parseEvents(
Expand Down
40 changes: 20 additions & 20 deletions ui/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1601,17 +1601,17 @@
"@stablelib/random" "^1.0.2"
"@stablelib/wipe" "^1.0.1"

"@starknet-react/chains@^0.1.3":
version "0.1.3"
resolved "https://registry.yarnpkg.com/@starknet-react/chains/-/chains-0.1.3.tgz#8e5d248f860b850b0b03e1059d6a4010d4801818"
integrity sha512-dSpLgDS02PmPzFVoW07EBVRbsX+h7MH7DYx2FF7vJv/J6eMGY7KtSupJW9R6ys0iADAxSg0UDcZr7syuy+b/Pg==
"@starknet-react/chains@^0.1.7":
version "0.1.7"
resolved "https://registry.yarnpkg.com/@starknet-react/chains/-/chains-0.1.7.tgz#58503379e2ffabe33b4f6e0f2aef775e84745a4d"
integrity sha512-UNh97I1SvuJKaAhKOmpEk8JcWuZWMlPG/ba2HcvFYL9x/47BKndJ+Da9V+iJFtkHUjreVnajT1snsaz1XMG+UQ==

"@starknet-react/core@^2.1.5":
version "2.1.5"
resolved "https://registry.yarnpkg.com/@starknet-react/core/-/core-2.1.5.tgz#a6a68f5223bd42190f3235e9737a66f47f4b3c07"
integrity sha512-lHBZMVFkz7XzyCy24Ca7/b55AkJU+alTD5520lBEbqYYOUAALdKCVp8+rlwPYv5Z8pkJzqRLoB//X6mTsky6Lw==
"@starknet-react/core@^2.5.0":
version "2.5.0"
resolved "https://registry.yarnpkg.com/@starknet-react/core/-/core-2.5.0.tgz#77da3204f2207e3b4b25bfef40ee80df12651534"
integrity sha512-nH5Vf0oAeqn0+rerUpaAzgbd9z+sBKYZNk6pgFX2s1BNCuRGXyJDoVkQoouVeGKdJO2M8jyMDUVWQn9rE1dDqw==
dependencies:
"@starknet-react/chains" "^0.1.3"
"@starknet-react/chains" "^0.1.7"
"@tanstack/react-query" "^5.0.1"
eventemitter3 "^5.0.1"
immutable "^4.3.4"
Expand Down Expand Up @@ -1729,17 +1729,17 @@
dependencies:
tslib "^2.4.0"

"@tanstack/query-core@5.14.0":
version "5.14.0"
resolved "https://registry.yarnpkg.com/@tanstack/query-core/-/query-core-5.14.0.tgz#96a88030b7f104a37d42e549dd7453373ba7879f"
integrity sha512-OEri9fVDYT8XEqgh/dc6fFp1niyqu+MDY+Vp/LwU+scdk9xQLZ7KdUMEUh/sqTEjRM5BlFzAhAv+EIYcvSxt0Q==
"@tanstack/query-core@5.28.4":
version "5.28.4"
resolved "https://registry.yarnpkg.com/@tanstack/query-core/-/query-core-5.28.4.tgz#fa416532f8b33ca8608d40bb9728b60e2e1a38dc"
integrity sha512-uQZqOFqLWUvXNIQZ63XdKzg22NtHzgCBUfDmjDHi3BoF+nUYeBNvMi/xFPtFrMhqRzG2Ir4mYaGsWZzmiEjXpA==

"@tanstack/react-query@^5.0.1":
version "5.14.0"
resolved "https://registry.yarnpkg.com/@tanstack/react-query/-/react-query-5.14.0.tgz#d2c79ee88f473cd859b9a7885d2f5c33ca3bd749"
integrity sha512-+qCooNZr7aGr6a0UEblfEgDSO1y+H7h7JnT4nUlbyfgCGE695lmBiqTciuW1C1Jr6J6Z2bwyd6YmBDKFKszWhA==
version "5.28.4"
resolved "https://registry.yarnpkg.com/@tanstack/react-query/-/react-query-5.28.4.tgz#32e56ca4fd08513a906fe6323908f0e38ffccbba"
integrity sha512-BErcoB/QQG6YwLSUKnaGxF+lSc270RH2w3kMBpG0i4YzDCsFs2pdxPX1WVknQvFk9bNgukMb158hc2Zb4SdwSA==
dependencies:
"@tanstack/query-core" "5.14.0"
"@tanstack/query-core" "5.28.4"

"@trpc/client@^10.38.1":
version "10.44.1"
Expand Down Expand Up @@ -3705,9 +3705,9 @@ ignore@^5.2.0:
integrity sha512-MAb38BcSbH0eHNBxn7ql2NH/kX33OkB3lZ1BNdh7ENeRChHTYsTvWrMubiIAMNS2llXEEgZ1MUOBtXChP3kaFQ==

immutable@^4.3.4:
version "4.3.4"
resolved "https://registry.yarnpkg.com/immutable/-/immutable-4.3.4.tgz#2e07b33837b4bb7662f288c244d1ced1ef65a78f"
integrity sha512-fsXeu4J4i6WNWSikpI88v/PcVflZz+6kMhUfIwc5SY+poQRPnaf5V7qds6SUyUN3cVxEzuCab7QIoLOQ+DQ1wA==
version "4.3.5"
resolved "https://registry.yarnpkg.com/immutable/-/immutable-4.3.5.tgz#f8b436e66d59f99760dc577f5c99a4fd2a5cc5a0"
integrity sha512-8eabxkth9gZatlwl5TBuJnCsoTADlL6ftEr7A4qgdaTsPyreilDSnUk57SO+jfKcNtxPa22U5KK6DSeAYhpBJw==

import-fresh@^3.0.0, import-fresh@^3.2.1:
version "3.3.0"
Expand Down

0 comments on commit f7692da

Please sign in to comment.