-
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.
Merge pull request #44 from argentlabs/develop
starknetkit and starknet-react update
- Loading branch information
Showing
13 changed files
with
844 additions
and
742 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,10 +7,11 @@ | |
"build": "next build", | ||
"start": "next start", | ||
"lint": "next lint", | ||
"prepare": "husky" | ||
"prepare": "husky", | ||
"format": "prettier --write ." | ||
}, | ||
"dependencies": { | ||
"@argent/x-sessions": "^6.7.4", | ||
"@argent/x-sessions": "^6.7.8", | ||
"@argent/x-shared": "^1.32.1", | ||
"@chakra-ui/react": "^2.8.2", | ||
"@emotion/react": "^11.11.4", | ||
|
@@ -20,18 +21,18 @@ | |
"@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].0-beta.2", | ||
"starknet-react-chains-next": "npm:@starknet-react/[email protected].3", | ||
"starknet-react-core-next": "npm:@starknet-react/[email protected].1-beta.0", | ||
"starknetkit-latest": "npm:starknetkit@^1.1.9", | ||
"starknetkit-next": "npm:starknetkit@^2.2.25" | ||
"starknetkit-next": "npm:starknetkit@^2.3.1" | ||
}, | ||
"devDependencies": { | ||
"@types/lodash-es": "^4.17.12", | ||
|
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
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": [] | ||
} | ||
] |
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
File renamed without changes.
File renamed without changes.
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
98 changes: 98 additions & 0 deletions
98
src/app/withStarknetReactNext/_components/TransferWithStarknetReact.tsx
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,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") | ||
|
||
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> | ||
) | ||
} |
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