Skip to content

Commit

Permalink
Merge pull request #12 from argentlabs/fix/state
Browse files Browse the repository at this point in the history
chore: udate starknetjs and small fixes
  • Loading branch information
bluecco authored Jun 18, 2024
2 parents da9d3de + e22666d commit 1be19a8
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 18 deletions.
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
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 }

0 comments on commit 1be19a8

Please sign in to comment.