From 9cb8f6354f4a359efb444a129a5453dce4d0f5ac Mon Sep 17 00:00:00 2001 From: bluecco Date: Thu, 6 Jun 2024 17:06:26 +0200 Subject: [PATCH 1/3] fix: rpc provider --- src/constants/index.ts | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/constants/index.ts b/src/constants/index.ts index 202e194..fffddf5 100644 --- a/src/constants/index.ts +++ b/src/constants/index.ts @@ -6,9 +6,24 @@ export const ETHTokenAddress = export const DAITokenAddress = "0x00da114221cb83fa859dbdb4c44beeaa0bb37c7537ad5ae66fe5e0efd20e6eb3" +export const CHAIN_ID = + process.env.NEXT_PUBLIC_CHAIN_ID === constants.NetworkName.SN_MAIN + ? constants.NetworkName.SN_MAIN + : constants.NetworkName.SN_SEPOLIA + +const NODE_URL = + process.env.NEXT_PUBLIC_CHAIN_ID === constants.NetworkName.SN_MAIN + ? "https://starknet-mainnet.public.blastapi.io" + : "https://starknet-sepolia.public.blastapi.io/rpc/v0_7" + +const STARKNET_CHAIN_ID = + process.env.NEXT_PUBLIC_CHAIN_ID === constants.NetworkName.SN_MAIN + ? constants.StarknetChainId.SN_MAIN + : constants.StarknetChainId.SN_SEPOLIA + export const provider = new RpcProvider({ - nodeUrl: "https://starknet-sepolia.public.blastapi.io/rpc/v0_7", - chainId: constants.StarknetChainId.SN_SEPOLIA, + nodeUrl: NODE_URL, + chainId: STARKNET_CHAIN_ID, }) export const ARGENT_SESSION_SERVICE_BASE_URL = @@ -17,8 +32,3 @@ export const ARGENT_SESSION_SERVICE_BASE_URL = export const ARGENT_WEBWALLET_URL = process.env.NEXT_PUBLIC_ARGENT_WEBWALLET_URL || "https://web.argent.xyz" - -export const CHAIN_ID = - process.env.NEXT_PUBLIC_CHAIN_ID === constants.NetworkName.SN_MAIN - ? constants.NetworkName.SN_MAIN - : constants.NetworkName.SN_SEPOLIA From 49e043e594ecf1697f1c0b2461785f4fc290e9a5 Mon Sep 17 00:00:00 2001 From: bluecco Date: Tue, 18 Jun 2024 09:34:31 +0200 Subject: [PATCH 2/3] chore: udate starknetjs and small fixes --- package.json | 2 +- pnpm-lock.yaml | 2 +- src/app/starknetkitNext/page.tsx | 3 +++ src/components/Actions/Mint.tsx | 1 - src/components/Actions/Transfer.tsx | 3 ++- src/hooks/useWaitForTx.ts | 28 ++++++++++++++-------------- 6 files changed, 21 insertions(+), 18 deletions(-) diff --git a/package.json b/package.json index 6f9d763..dd97612 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "popmotion": "^11.0.5", "react": "^18.3.1", "react-dom": "^18.3.1", - "starknet": "^6.7.0", + "starknet": "^6.9.0", "starknetkit-latest": "npm:starknetkit@^1.1.9", "starknetkit-next": "npm:starknetkit@^2.2.9" }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f940a51..2cbff59 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -54,7 +54,7 @@ importers: specifier: ^18.3.1 version: 18.3.1(react@18.3.1) starknet: - specifier: ^6.7.0 + specifier: ^6.9.0 version: 6.9.0 starknetkit-latest: specifier: npm:starknetkit@^1.1.9 diff --git a/src/app/starknetkitNext/page.tsx b/src/app/starknetkitNext/page.tsx index 0eaa373..dad7b2c 100644 --- a/src/app/starknetkitNext/page.tsx +++ b/src/app/starknetkitNext/page.tsx @@ -16,6 +16,7 @@ import { WalletRpcMsgContainer } from "@/components/Actions/WalletRpcMsgContaine import { DisconnectButton } from "@/components/DisconnectButton" import { Section } from "@/components/Section" import { ARGENT_WEBWALLET_URL } from "@/constants" +import { useWaitForTx } from "@/hooks/useWaitForTx" import { connectorAtom, connectorDataAtom, @@ -35,6 +36,8 @@ export default function StarknetkitLatest() { const setConnector = useSetAtom(connectorAtom) const navigate = useRouter() + useWaitForTx() + useEffect(() => { const autoConnect = async () => { const { diff --git a/src/components/Actions/Mint.tsx b/src/components/Actions/Mint.tsx index 5ebb750..afc0a62 100644 --- a/src/components/Actions/Mint.tsx +++ b/src/components/Actions/Mint.tsx @@ -1,4 +1,3 @@ -import { useWaitForTx } from "@/hooks/useWaitForTx" import { mintToken, mintTokenRcpMethod } from "@/services/mint" import { walletStarknetkitLatestAtom } from "@/state/connectedWalletStarknetkitLatest" import { walletStarknetkitNextAtom } from "@/state/connectedWalletStarknetkitNext" diff --git a/src/components/Actions/Transfer.tsx b/src/components/Actions/Transfer.tsx index 497be55..2d40218 100644 --- a/src/components/Actions/Transfer.tsx +++ b/src/components/Actions/Transfer.tsx @@ -1,4 +1,3 @@ -import { useWaitForTx } from "@/hooks/useWaitForTx" import { transfer, transferJSONRpcMethod } from "@/services/transfer" import { walletStarknetkitLatestAtom } from "@/state/connectedWalletStarknetkitLatest" import { walletStarknetkitNextAtom } from "@/state/connectedWalletStarknetkitNext" @@ -43,9 +42,11 @@ const Transfer: FC = ({ account, wallet }) => { e.preventDefault() setTransactionStatus("approve") + const { transaction_hash } = account ? await transfer(account as Account, transferTo, transferAmount) : await transferJSONRpcMethod(wallet, transferTo, transferAmount) + setLastTransactionHash(transaction_hash) setTransactionStatus("pending") setTransferAmount("") diff --git a/src/hooks/useWaitForTx.ts b/src/hooks/useWaitForTx.ts index 9fa93dc..b1325c6 100644 --- a/src/hooks/useWaitForTx.ts +++ b/src/hooks/useWaitForTx.ts @@ -1,11 +1,17 @@ import { provider } from "@/constants" -import { useEffect, useState } from "react" +import { + lastTxErrorAtom, + lastTxHashAtom, + lastTxStatusAtom, +} from "@/state/transactionState" +import { useAtom, useAtomValue, useSetAtom } from "jotai" +import { useEffect } from "react" import { GatewayError } from "starknet" const useWaitForTx = () => { - const [lastTxHash, setLastTxHash] = useState("") - const [lastTxStatus, setLastTxStatus] = useState("idle") - const [lastTxError, setLastTxError] = useState("") + const lastTxHash = useAtomValue(lastTxHashAtom) + const [lastTxStatus, setLastTxStatus] = useAtom(lastTxStatusAtom) + const setLastTxError = useSetAtom(lastTxErrorAtom) useEffect(() => { const waitTx = async () => { @@ -24,17 +30,11 @@ const useWaitForTx = () => { } } } - waitTx() - }, [lastTxStatus, lastTxHash]) - return { - lastTxHash, - setLastTxHash, - lastTxError, - setLastTxError, - lastTxStatus, - setLastTxStatus, - } + if (lastTxHash && lastTxStatus === "pending") { + waitTx() + } + }, [lastTxStatus, lastTxHash]) } export { useWaitForTx } From e22666df120e9ec71ae39a27cf89582e40a6d790 Mon Sep 17 00:00:00 2001 From: bluecco Date: Tue, 18 Jun 2024 09:36:25 +0200 Subject: [PATCH 3/3] fix: state tx --- src/app/withStarknetReactLatest/page.tsx | 3 +++ src/app/withStarknetReactNext/page.tsx | 1 + 2 files changed, 4 insertions(+) diff --git a/src/app/withStarknetReactLatest/page.tsx b/src/app/withStarknetReactLatest/page.tsx index a74eebc..4079564 100644 --- a/src/app/withStarknetReactLatest/page.tsx +++ b/src/app/withStarknetReactLatest/page.tsx @@ -9,6 +9,7 @@ import { Section } from "@/components/Section" import { ConnectStarknetReact } from "@/components/connect/ConnectStarknetReact" import { CHAIN_ID } from "@/constants" import { availableConnectors } from "@/helpers/connectorsLatest" +import { useWaitForTx } from "@/hooks/useWaitForTx" import { Flex } from "@chakra-ui/react" import { mainnet, sepolia } from "@starknet-react/chains" import { @@ -28,6 +29,8 @@ const StarknetReactDappContent = () => { undefined, ) + useWaitForTx() + useEffect(() => { const getChainId = async () => { setChainId(await account?.getChainId()) diff --git a/src/app/withStarknetReactNext/page.tsx b/src/app/withStarknetReactNext/page.tsx index f4eb1ae..ba9b259 100644 --- a/src/app/withStarknetReactNext/page.tsx +++ b/src/app/withStarknetReactNext/page.tsx @@ -1,3 +1,4 @@ export default function StarknetReactNext() { + //useWaitForTx() return <>TODO: wait for starknet-react v3 }