Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release #14

Merged
merged 7 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
2 changes: 1 addition & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/app/starknetkitNext/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -35,6 +36,8 @@ export default function StarknetkitLatest() {
const setConnector = useSetAtom(connectorAtom)
const navigate = useRouter()

useWaitForTx()

useEffect(() => {
const autoConnect = async () => {
const {
Expand Down
3 changes: 3 additions & 0 deletions src/app/withStarknetReactLatest/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -28,6 +29,8 @@ const StarknetReactDappContent = () => {
undefined,
)

useWaitForTx()

useEffect(() => {
const getChainId = async () => {
setChainId(await account?.getChainId())
Expand Down
1 change: 1 addition & 0 deletions src/app/withStarknetReactNext/page.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export default function StarknetReactNext() {
//useWaitForTx()
return <>TODO: wait for starknet-react v3</>
}
1 change: 0 additions & 1 deletion src/components/Actions/Mint.tsx
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
3 changes: 2 additions & 1 deletion src/components/Actions/Transfer.tsx
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -43,9 +42,11 @@ const Transfer: FC<TransferProps> = ({ 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("")
Expand Down
24 changes: 17 additions & 7 deletions src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -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
28 changes: 14 additions & 14 deletions src/hooks/useWaitForTx.ts
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand All @@ -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 }
Loading