-
Notifications
You must be signed in to change notification settings - Fork 3
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
Changes from all commits
6d98350
ae5fd0e
b026169
27dc8ba
4954330
c271e9b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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", | ||
|
@@ -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", | ||
"starknetkit-latest": "npm:starknetkit@^1.1.9", | ||
"starknetkit-next": "npm:starknetkit@^2.2.25" | ||
}, | ||
|
Large diffs are not rendered by default.
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": [] | ||
} | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,19 @@ | ||
import { ETHTokenAddress, provider } from "@/constants" | ||
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 { Abi, useContract } from "starknet-react-core-next" | ||
import Erc20Abi from "@/abi/ERC20TransferAbi.json" | ||
|
||
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 = () => { | ||
export const MintWithStarknetReact = () => { | ||
const { account } = useAccount() | ||
const [mintAmount, setMintAmount] = useState("10") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be prepopulated with There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
@@ -33,20 +22,32 @@ const MintWithStarknetReact = () => { | |
const buttonsDisabled = ["approve", "pending"].includes(transactionStatus) | ||
|
||
const { contract } = useContract({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. using new api from newest version of starknet-react |
||
abi, | ||
abi: Erc20Abi as Abi, | ||
address: ETHTokenAddress, | ||
provider, | ||
}) | ||
|
||
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 contract | ||
const { transaction_hash } = await mintWithStarknetReact() | ||
setLastTransactionHash(transaction_hash) | ||
setTransactionStatus("pending") | ||
} catch (e) { | ||
console.error(e) | ||
console.error(error) | ||
setTransactionStatus("idle") | ||
} | ||
} | ||
|
@@ -72,15 +73,10 @@ const MintWithStarknetReact = () => { | |
value={mintAmount} | ||
onChange={(e) => setMintAmount(e.target.value)} | ||
/> | ||
{/* TODO: Verify it's ok that the submit has been enabled */} | ||
|
||
<Input | ||
type="submit" | ||
disabled={true || buttonsDisabled} | ||
value="Not possible with ETH!" | ||
/> | ||
<Input type="submit" disabled={buttonsDisabled} value="Submit" /> | ||
</Flex> | ||
</Flex> | ||
) | ||
} | ||
|
||
export { MintWithStarknetReact } |
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") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. value There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> | ||
) | ||
} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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