Skip to content

Commit

Permalink
refactor: components
Browse files Browse the repository at this point in the history
  • Loading branch information
bluecco committed Jun 4, 2024
1 parent aabdfaf commit 5a4cc54
Show file tree
Hide file tree
Showing 15 changed files with 154 additions and 669 deletions.
32 changes: 16 additions & 16 deletions src/app/starknetkitLatest/page.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
"use client"

import { AccountSection } from "@/components/AccountSection"
import { SignMessage } from "@/components/Actions/SignMessage"
import { Transfer } from "@/components/Actions/Transfer"
import { AddNetworkLatest } from "@/components/Actions/AddNetwork"
import { AddTokenLatest } from "@/components/Actions/AddToken"
import { Declare } from "@/components/Actions/Declare"
import { DeployLatest } from "@/components/Actions/Deploy"
import { MintLatest } from "@/components/Actions/Mint"
import { SignMessageLatest } from "@/components/Actions/SignMessage"
import { TransferLatest } from "@/components/Actions/Transfer"
import { DisconnectButton } from "@/components/DisconnectButton"
import { Section } from "@/components/Section"
import { ARGENT_WEBWALLET_URL } from "@/constants"
import { useWaitForTx } from "@/hooks/useWaitForTx"
import { walletStarknetkitLatestAtom } from "@/state/connectedWalletStarknetkitLatest"
import { Box, Button, Flex } from "@chakra-ui/react"
import { Flex } from "@chakra-ui/react"
import { useAtom } from "jotai"
import { RESET } from "jotai/utils"
import { useRouter } from "next/navigation"
import { useEffect } from "react"
import { connect, disconnect } from "starknetkit-latest"
import { RESET } from "jotai/utils"
import { ARGENT_WEBWALLET_URL } from "@/constants"
import { constants } from "starknet"
import { Declare } from "@/components/Actions/Declare"
import { Deploy } from "@/components/Actions/Deploy"
import { Mint } from "@/components/Actions/Mint"
import { DisconnectButton } from "@/components/DisconnectButton"
import { AddNetworkLatest } from "@/components/Actions/AddNetwork"
import { AddTokenLatest } from "@/components/Actions/AddToken"
import { connect, disconnect } from "starknetkit-latest"

export default function StarknetkitLatest() {
const [wallet, setWallet] = useAtom(walletStarknetkitLatestAtom)
Expand Down Expand Up @@ -64,20 +64,20 @@ export default function StarknetkitLatest() {
chainId={wallet.chainId}
/>
<Section>
<Mint />
<MintLatest />
</Section>
<Section>
<Transfer />
<TransferLatest />
</Section>
<Section>
<SignMessage />
<SignMessageLatest />
</Section>
{wallet.id !== "argentWebWallet" &&
wallet.id !== "argentMobileWallet" && (
<Section>
<Flex alignItems="center" gap="10">
<Declare />
<Deploy />
<DeployLatest />
</Flex>
</Section>
)}
Expand Down
16 changes: 8 additions & 8 deletions src/app/starknetkitNext/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import { AccountSection } from "@/components/AccountSection"
import { AddNetworkNext } from "@/components/Actions/AddNetwork"
import { AddTokenNext } from "@/components/Actions/AddToken"
import { Declare } from "@/components/Actions/Declare"
import { Deploy } from "@/components/Actions/Deploy"
import { MintRpcMethod } from "@/components/Actions/MintRpcMethod"
import { DeployNext } from "@/components/Actions/Deploy"
import { MintNext } from "@/components/Actions/Mint"
import { SessionKeysExecute } from "@/components/Actions/SessionKeysExecute"
import { SessionKeysExecuteOutside } from "@/components/Actions/SessionKeysExecuteOutside"
import { SessionKeysSign } from "@/components/Actions/SessionKeysSign"
import { SessionKeysTypedDataOutside } from "@/components/Actions/SessionKeysTypedDataOutside"
import { SignMessageRpcMethod } from "@/components/Actions/SignMessageRpcMethod"
import { TransferRpcMethod } from "@/components/Actions/TransferRpcMethod"
import { SignMessageNext } from "@/components/Actions/SignMessage"
import { TransferNext } from "@/components/Actions/Transfer"
import { WalletRpcMsgContainer } from "@/components/Actions/WalletRpcMsgContainer"
import { DisconnectButton } from "@/components/DisconnectButton"
import { Section } from "@/components/Section"
Expand Down Expand Up @@ -83,13 +83,13 @@ export default function StarknetkitLatest() {
chainId={connectorData?.chainId}
/>
<Section>
<MintRpcMethod />
<MintNext />
</Section>
<Section>
<TransferRpcMethod />
<TransferNext />
</Section>
<Section>
<SignMessageRpcMethod />
<SignMessageNext />
</Section>
<Section>
<SessionKeysSign />
Expand All @@ -105,7 +105,7 @@ export default function StarknetkitLatest() {
<Section>
<Flex alignItems="center" gap="10">
<Declare />
<Deploy />
<DeployNext />
</Flex>
</Section>
)}
Expand Down
154 changes: 2 additions & 152 deletions src/app/withStarknetReactLatest/page.tsx
Original file line number Diff line number Diff line change
@@ -1,153 +1,3 @@
"use client"

import { ConnectButton } from "@/components/ConnectButton"
import { DeploymentData } from "@/components/DeploymentData"
import { SessionKeysExecute } from "@/components/SessionKeysExecute"
import { SessionKeysExecuteOutside } from "@/components/SessionKeysExecuteOutside"
import { SessionKeysSign } from "@/components/SessionKeysSign"
import { SessionKeysTypedDataOutside } from "@/components/SessionKeysTypedDataOutside"
import { provider } from "@/constants"
import { Status } from "@/types/status"
import { OffChainSession } from "@argent/x-sessions"
import { useEffect, useState } from "react"
import { GatewayError, Signature, constants } from "starknet"
import { StarknetChainId } from "starknet-types"
import { StarknetWindowObject, disconnect } from "starknetkit"

export default function Session() {
const [connectedWallet, setConnectedWallet] = useState<
StarknetWindowObject | undefined | null
>(null)
const [connectorData, setConnectorData] = useState<
| {
account?: string
chainId?: StarknetChainId
}
| undefined
| null
>(null)
const [chainId, setChainId] = useState<constants.StarknetChainId | undefined>(
undefined,
)

const [lastTransactionHash, setLastTransactionHash] = useState("")
const [transactionStatus, setTransactionStatus] = useState<Status>("idle")
const [transactionError, setTransactionError] = useState("")
const [accountSessionSignature, setAccountSessionSignature] = useState<
string[] | Signature
>()
const [sessionRequest, setSessionRequest] = useState<OffChainSession>()

useEffect(() => {
const waitTx = async () => {
if (lastTransactionHash && transactionStatus === "pending") {
setTransactionError("")
try {
await provider.waitForTransaction(lastTransactionHash)
setTransactionStatus("success")
} catch (error) {
setTransactionStatus("failure")
let message = error ? `${error}` : "No further details"
if (error instanceof GatewayError) {
message = JSON.stringify(error.message, null, 2)
}
setTransactionError(message)
}
}
}
waitTx()
}, [transactionStatus, lastTransactionHash])

return (
<main className="flex min-h-screen flex-col p-24 gap-4">
<div>
{!connectedWallet && (
<ConnectButton
setConnectedWallet={setConnectedWallet}
setChainId={setChainId}
setConnectorData={setConnectorData}
/>
)}
</div>

{connectedWallet && connectorData?.account && (
<>
<button
className="bg-white text-black p-2 rounded-lg absolute top-4 right-4"
onClick={() => {
disconnect()
setConnectedWallet(undefined)
}}
>
Disconnect
</button>
<div>
<div>Account: {connectorData?.account}</div>
</div>
<div>
{connectedWallet && <DeploymentData wallet={connectedWallet} />}
</div>
<div>
Chain:{" "}
{chainId === constants.StarknetChainId.SN_SEPOLIA
? "SN_SEPOLIA"
: "SN_MAIN"}
</div>
<div
className={`${lastTransactionHash ? "cursor-pointer hover:underline" : "default"}`}
onClick={() => {
if (!lastTransactionHash) return
window.open(
`https://sepolia.starkscan.co/tx/${lastTransactionHash}`,
"_blank",
)
}}
>
Last tx hash: {lastTransactionHash || "---"}
</div>
<div>Tx status: {transactionStatus}</div>
<div color="##ff4848">{transactionError.toString()}</div>

<div className="flex flex-col text-black">
<SessionKeysSign
wallet={connectedWallet}
setTransactionStatus={setTransactionStatus}
setAccountSessionSignature={setAccountSessionSignature}
setSessionRequest={setSessionRequest}
/>
</div>

<div className="flex flex-col text-black">
<SessionKeysExecute
address={connectorData?.account}
accountSessionSignature={accountSessionSignature}
sessionRequest={sessionRequest}
setTransactionStatus={setTransactionStatus}
setLastTransactionHash={setLastTransactionHash}
transactionStatus={transactionStatus}
/>
</div>

<div className="flex text-black justify-between">
<div className="flex flex-col text-black ">
<SessionKeysExecuteOutside
address={connectorData?.account}
accountSessionSignature={accountSessionSignature}
sessionRequest={sessionRequest}
transactionStatus={transactionStatus}
/>
</div>
<div className="flex flex-col text-black ">
<SessionKeysTypedDataOutside
address={connectorData?.account}
accountSessionSignature={accountSessionSignature}
sessionRequest={sessionRequest}
transactionStatus={transactionStatus}
/>
</div>
</div>
</>
)}
</main>
)
export default function StarknetReactLatest() {
return <>todo</>
}
Loading

0 comments on commit 5a4cc54

Please sign in to comment.