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

fix(deps) Update starknet-reacts next to 3.0.0-beta.3 #37

Merged
merged 6 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"build": "next build",
"start": "next start",
"lint": "next lint",
"prepare": "husky"
"prepare": "husky",
"format": "prettier --write ."
},
"dependencies": {
"@argent/x-sessions": "^6.7.4",
Expand All @@ -20,16 +21,16 @@
"@starknet-react/core": "^2.8.2",
"colord": "^2.9.3",
"framer-motion": "^11.2.10",
"get-starknet-core": "^3.2.0",
"get-starknet-core": "^4.0.0",
"jotai": "^2.8.2",
"lodash-es": "^4.17.21",
"next": "14.2.4",
"popmotion": "^11.0.5",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"starknet": "^6.11.0",
"starknet-react-chains-next": "npm:@starknet-react/[email protected].2",
"starknet-react-core-next": "npm:@starknet-react/[email protected].2",
"starknet-react-chains-next": "npm:@starknet-react/[email protected].3",
"starknet-react-core-next": "npm:@starknet-react/[email protected].3",
Comment on lines +32 to +33
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if we should set it to this version or will they release the final one?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess there shouldn't be any differences, just curious

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idk to be honest, but it is a good question

"starknetkit-latest": "npm:starknetkit@^1.1.9",
"starknetkit-next": "npm:starknetkit@^2.2.25"
},
Expand Down
125 changes: 68 additions & 57 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions src/abi/ERC20TransferAbi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[
{
"type": "function",
"name": "transfer",
"state_mutability": "external",
"inputs": [
{
"name": "recipient",
"type": "core::starknet::contract_address::ContractAddress"
},
{
"name": "amount",
"type": "core::integer::u256"
}
],
"outputs": []
}
]
6 changes: 3 additions & 3 deletions src/app/withStarknetReactLatest/page.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
"use client"

import { AccountSection } from "@/components/AccountSection"
import { MintWithStarknetReact } from "@/components/Actions/MintWithStarknetReact"
import { SignMessageWithStarknetReact } from "@/components/Actions/SignMessageWithStarknetReact"
import { TransferWithStarknetReact } from "@/components/Actions/TransferWithStarknetReact"
import { TransferWithStarknetReact } from "@/app/withStarknetReactLatest/_components/TransferWithStarknetReact"
import { DisconnectButton } from "@/components/DisconnectButton"
import { Section } from "@/components/Section"
import { ConnectStarknetReact } from "@/components/connect/ConnectStarknetReact"
Expand All @@ -20,6 +19,7 @@ import {
import { useEffect, useState } from "react"
import { constants } from "starknet"
import { disconnect } from "starknetkit-next"
import { MintWithStarknetReact } from "@/app/withStarknetReactLatest/_components/MintWithStarknetReact"

const StarknetReactDappContent = () => {
const { account, isConnected } = useAccount()
Expand Down Expand Up @@ -63,7 +63,7 @@ const StarknetReactDappContent = () => {
<Section>
<SignMessageWithStarknetReact chainId={chainId} />
</Section>
{/*
{/*
TODO: wait for the next version of starknetkit and starknet-react with rpc methods
<Section>
<SessionKeysSign />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { ETHTokenAddress } from "@/constants"
import { lastTxHashAtom, lastTxStatusAtom } from "@/state/transactionState"
import { bigDecimal } from "@argent/x-shared"
import { Flex, Heading, Input } from "@chakra-ui/react"
import {
useAccount,
useContract,
Abi,
useSendTransaction,
} from "starknet-react-core-next"
import { useAtom, useSetAtom } from "jotai"
import { useState } from "react"
import Erc20Abi from "@/abi/ERC20TransferAbi.json"

export const MintWithStarknetReact = () => {
const { account } = useAccount()
const [mintAmount, setMintAmount] = useState("10")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be prepopulated with 10?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a copy-paste from previous component, so didn't want to change it. I assume it's just some random default


const [transactionStatus, setTransactionStatus] = useAtom(lastTxStatusAtom)
const setLastTransactionHash = useSetAtom(lastTxHashAtom)

const buttonsDisabled = ["approve", "pending"].includes(transactionStatus)

const { contract } = useContract({
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using new api from newest version of starknet-react

abi: Erc20Abi as Abi,
address: ETHTokenAddress,
})

const { error, sendAsync: mintWithStarknetReact } = useSendTransaction({
calls:
contract && account?.address
? [
contract.populate("transfer", [
account.address,
Number(bigDecimal.parseEther(mintAmount).value),
]),
]
: undefined,
})

const handleMintSubmit = async (e: React.FormEvent) => {
e.preventDefault()
try {
setTransactionStatus("approve")
const { transaction_hash } = await mintWithStarknetReact()
setLastTransactionHash(transaction_hash)
setTransactionStatus("pending")
} catch (e) {
console.error(e)
console.error(error)
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)}
/>
{/* TODO: When will we allow below? Need to ask Ale */}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why would we disable it at all, after all it's just an example dapp?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I asked Ale and blockchian team. He basically said it's always been there. Going yolo and enabling the submit 😂


<Input
type="submit"
disabled={true || buttonsDisabled}
value="Not possible with ETH!"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

value="Not possible with ETH!" what does this mean?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I asked Ale and blockchian team. He basically said it's always been there. Going yolo and enabling the submit 😂

/>
</Flex>
</Flex>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import { ETHTokenAddress } from "@/constants"
import { lastTxHashAtom, lastTxStatusAtom } from "@/state/transactionState"
import { bigDecimal } from "@argent/x-shared"
import { Button, Flex, Heading, Input } from "@chakra-ui/react"
import {
Abi,
useAccount,
useContract,
useSendTransaction,
} from "starknet-react-core-next"
import { useAtom, useSetAtom } from "jotai"
import { useState } from "react"
import Erc20Abi from "@/abi/ERC20TransferAbi.json"

export const TransferWithStarknetReact = () => {
const { account } = useAccount()
const [transferTo, setTransferTo] = useState("")
const [transferAmount, setTransferAmount] = useState("1")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

value 1?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above


const [transactionStatus, setTransactionStatus] = useAtom(lastTxStatusAtom)
const setLastTransactionHash = useSetAtom(lastTxHashAtom)

const { contract } = useContract({
abi: Erc20Abi as Abi,
address: ETHTokenAddress,
})

const { error, sendAsync: transferWithStarknetReact } = useSendTransaction({
calls:
contract && account?.address
? [
contract.populate("transfer", [
account.address,
Number(bigDecimal.parseEther(transferAmount).value),
]),
]
: undefined,
})

const buttonsDisabled = ["approve", "pending"].includes(transactionStatus)

const handleTransferSubmit = async (e: React.FormEvent) => {
try {
e.preventDefault()
setTransactionStatus("approve")
const { transaction_hash } = await transferWithStarknetReact()
setLastTransactionHash(transaction_hash)
setTransactionStatus("pending")
} catch (e) {
console.error(e)
console.error(error)
setTransactionStatus("idle")
}
}

return (
<Flex flex={1} width="full" gap={10}>
<Flex
as="form"
onSubmit={handleTransferSubmit}
direction="column"
flex={1}
p="4"
gap="3"
borderRadius="lg"
>
<Heading as="h2">Transfer token</Heading>

<Input
type="text"
id="transfer-to"
name="fname"
placeholder="To"
value={transferTo}
onChange={(e) => setTransferTo(e.target.value)}
/>

<Input
type="text"
id="transfer-amount"
name="fname"
placeholder="Amount"
value={transferAmount}
onChange={(e) => setTransferAmount(e.target.value)}
/>
<br />
<Button
colorScheme="primary"
type="submit"
isDisabled={buttonsDisabled}
maxW="200px"
>
Transfer
</Button>
</Flex>
</Flex>
)
}
7 changes: 4 additions & 3 deletions src/app/withStarknetReactNext/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
useAccount,
} from "starknet-react-core-next"
import { disconnect } from "starknetkit-next"
import { MintWithStarknetReact } from "./_components/MintWithStarknetReact"

const StarknetReactDappContent = () => {
const { account, isConnected } = useAccount()
Expand Down Expand Up @@ -54,16 +55,16 @@ const StarknetReactDappContent = () => {
<>
<DisconnectButton disconnectFn={disconnect} />
<AccountSection address={account?.address} chainId={chainId} />
{/* <Section>
<Section>
<MintWithStarknetReact />
</Section> */}
</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 />
Expand Down
4 changes: 2 additions & 2 deletions src/state/connectedWalletStarknetkitNext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
ChainId,
NetworkChangeEventHandler,
} from "@starknet-io/types-js"
import { useAtom, useAtomValue, useSetAtom } from "jotai"
import { useAtomValue, useSetAtom } from "jotai"
import { atomWithReset } from "jotai/utils"
import { useEffect } from "react"
import { ConnectorData, StarknetWindowObject } from "starknetkit-next"
Expand Down Expand Up @@ -53,5 +53,5 @@ export const useWalletAccountChange = () => {
wallet?.off("accountsChanged", accountChangeHandler)
wallet?.off("networkChanged", networkChangeHandler)
return
}, [])
}, [wallet, accountChangeHandler, networkChangeHandler])
}