-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: update dapp with starknet-react v3
- Loading branch information
Showing
15 changed files
with
1,434 additions
and
561 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
"@chakra-ui/react": "^2.8.2", | ||
"@emotion/react": "^11.11.4", | ||
"@emotion/styled": "^11.11.5", | ||
"@starknet-io/types-js": "^0.7.7", | ||
"@starknet-react/chains": "^0.1.7", | ||
"@starknet-react/core": "^2.8.2", | ||
"colord": "^2.9.3", | ||
|
@@ -25,9 +26,11 @@ | |
"popmotion": "^11.0.5", | ||
"react": "^18.3.1", | ||
"react-dom": "^18.3.1", | ||
"starknet": "^6.9.0", | ||
"starknet": "^6.11.0", | ||
"starknet-react-chains-next": "npm:@starknet-react/[email protected]", | ||
"starknet-react-core-next": "npm:@starknet-react/[email protected]", | ||
"starknetkit-latest": "npm:starknetkit@^1.1.9", | ||
"starknetkit-next": "npm:starknetkit@^2.2.11" | ||
"starknetkit-next": "npm:starknetkit@^2.2.13" | ||
}, | ||
"devDependencies": { | ||
"@types/lodash-es": "^4.17.12", | ||
|
@@ -45,7 +48,6 @@ | |
"lint-staged": "^15.2.5", | ||
"postcss": "^8.4.38", | ||
"prettier": "^3.3.0", | ||
"starknet-types": "^0.7.0", | ||
"typescript": "^5.4.5" | ||
}, | ||
"lint-staged": { | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,104 @@ | ||
"use client" | ||
|
||
import { AccountSection } from "@/components/AccountSection" | ||
import { SignMessageWithStarknetReactNext } from "@/components/Actions/SignMessageWithStarknetReactNext" | ||
import { TransferWithStarknetReactNext } from "@/components/Actions/TransferWithStarknetReactNext" | ||
import { DisconnectButton } from "@/components/DisconnectButton" | ||
import { Section } from "@/components/Section" | ||
import { ConnectStarknetReactNext } from "@/components/connect/ConnectStarknetReactNext" | ||
import { CHAIN_ID } from "@/constants" | ||
import { availableConnectors } from "@/helpers/connectorsNext" | ||
import { useWaitForTx } from "@/hooks/useWaitForTx" | ||
import { Flex } from "@chakra-ui/react" | ||
import { useEffect, useState } from "react" | ||
import { constants } from "starknet" | ||
import { mainnet, sepolia } from "starknet-react-chains-next" | ||
import { | ||
StarknetConfig, | ||
publicProvider, | ||
useAccount, | ||
useWalletRequest, | ||
} from "starknet-react-core-next" | ||
import { Connector, StarknetkitConnector, disconnect } from "starknetkit-next" | ||
|
||
const StarknetReactDappContent = () => { | ||
const { account, status, isConnected } = useAccount() | ||
const [chainId, setChainId] = useState<constants.StarknetChainId | undefined>( | ||
undefined, | ||
) | ||
|
||
console.log({ account, isConnected }) | ||
|
||
useWaitForTx() | ||
|
||
useEffect(() => { | ||
const getChainId = async () => { | ||
setChainId(await account?.getChainId()) | ||
} | ||
|
||
if (account) { | ||
getChainId() | ||
} | ||
}, [account]) | ||
|
||
return ( | ||
<> | ||
{!isConnected && <ConnectStarknetReactNext />} | ||
{isConnected && ( | ||
<Flex | ||
as="main" | ||
flexDirection="column" | ||
p="10" | ||
gap="4" | ||
w="dvw" | ||
h="100dvh" | ||
> | ||
<> | ||
<DisconnectButton disconnectFn={disconnect} /> | ||
<AccountSection address={account?.address} chainId={chainId} /> | ||
{/* <Section> | ||
<MintWithStarknetReact /> | ||
</Section> */} | ||
<Section> | ||
<TransferWithStarknetReactNext /> | ||
</Section> | ||
<Section> | ||
<SignMessageWithStarknetReactNext chainId={chainId} /> | ||
</Section> | ||
{/* | ||
TODO: wait for the next version of starknetkit and starknet-react with rpc methods | ||
<Section> | ||
<SessionKeysSign /> | ||
<SessionKeysExecute /> | ||
<Flex alignItems="center" gap="100"> | ||
<SessionKeysExecuteOutside /> | ||
<SessionKeysTypedDataOutside /> | ||
</Flex> | ||
</Section> */} | ||
</> | ||
</Flex> | ||
)} | ||
</> | ||
) | ||
} | ||
|
||
export default function StarknetReactNext() { | ||
//useWaitForTx() | ||
return <>TODO: wait for starknet-react v3</> | ||
const chains = [ | ||
CHAIN_ID === constants.NetworkName.SN_MAIN ? mainnet : sepolia, | ||
] | ||
const providers = publicProvider() | ||
|
||
return ( | ||
<> | ||
<StarknetConfig | ||
chains={chains} | ||
provider={providers} | ||
connectors={ | ||
availableConnectors as any | ||
} /* remove when starknet-react update types */ | ||
> | ||
<StarknetReactDappContent /> | ||
</StarknetConfig> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import { ETHTokenAddress, provider } from "@/constants" | ||
import { lastTxHashAtom, lastTxStatusAtom } from "@/state/transactionState" | ||
import { Flex, Heading, Input } from "@chakra-ui/react" | ||
import { useAtom, useSetAtom } from "jotai" | ||
import { useState } from "react" | ||
import { Abi, useContract } from "starknet-react-core-next" | ||
|
||
const abi = [ | ||
{ | ||
type: "function", | ||
name: "permissionedMint", | ||
state_mutability: "external", | ||
inputs: [ | ||
{ | ||
name: "recipient", | ||
type: "core::starknet::contract_address::ContractAddress", | ||
}, | ||
{ | ||
name: "amount", | ||
type: "core::integer::u256", | ||
}, | ||
], | ||
outputs: [], | ||
}, | ||
] as const satisfies Abi | ||
|
||
const MintWithStarknetReact = () => { | ||
const [mintAmount, setMintAmount] = useState("10") | ||
|
||
const [transactionStatus, setTransactionStatus] = useAtom(lastTxStatusAtom) | ||
const setLastTransactionHash = useSetAtom(lastTxHashAtom) | ||
|
||
const buttonsDisabled = ["approve", "pending"].includes(transactionStatus) | ||
|
||
const { contract } = useContract({ | ||
abi, | ||
address: ETHTokenAddress, | ||
provider, | ||
}) | ||
|
||
const handleMintSubmit = async (e: React.FormEvent) => { | ||
e.preventDefault() | ||
try { | ||
setTransactionStatus("approve") | ||
const { transaction_hash } = await contract | ||
setLastTransactionHash(transaction_hash) | ||
setTransactionStatus("pending") | ||
} catch (e) { | ||
console.error(e) | ||
setTransactionStatus("idle") | ||
} | ||
} | ||
|
||
return ( | ||
<Flex flex={1} width="full" gap={10}> | ||
<Flex | ||
as="form" | ||
onSubmit={handleMintSubmit} | ||
direction="column" | ||
flex={1} | ||
p="4" | ||
gap="3" | ||
borderRadius="lg" | ||
> | ||
<Heading as="h2">Mint token</Heading> | ||
<Input | ||
disabled | ||
placeholder="Amount" | ||
type="text" | ||
id="mint-amount" | ||
name="fname" | ||
value={mintAmount} | ||
onChange={(e) => setMintAmount(e.target.value)} | ||
/> | ||
|
||
<Input | ||
type="submit" | ||
disabled={true || buttonsDisabled} | ||
value="Not possible with ETH!" | ||
/> | ||
</Flex> | ||
</Flex> | ||
) | ||
} | ||
|
||
export { MintWithStarknetReact } |
Oops, something went wrong.