Skip to content

Commit

Permalink
chore: use chainId from connectorData
Browse files Browse the repository at this point in the history
  • Loading branch information
bluecco committed Jun 18, 2024
1 parent 1be19a8 commit 8d79ea1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
14 changes: 11 additions & 3 deletions src/components/Actions/SignMessage.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { signMessage, signMessageRcpMethod } from "@/services/signMessage"
import { walletStarknetkitLatestAtom } from "@/state/connectedWalletStarknetkitLatest"
import { walletStarknetkitNextAtom } from "@/state/connectedWalletStarknetkitNext"
import {
connectorDataAtom,
walletStarknetkitNextAtom,
} from "@/state/connectedWalletStarknetkitNext"
import { lastTxStatusAtom } from "@/state/transactionState"
import { Button, Flex, Heading, Input, Textarea } from "@chakra-ui/react"
import { useAtomValue, useSetAtom } from "jotai"
Expand All @@ -26,7 +29,7 @@ interface SignMessageProps {
const SignMessage: FC<SignMessageProps> = ({ account, wallet }) => {
const [shortText, setShortText] = useState("")
const [lastSig, setLastSig] = useState<string[]>([])

const connectorData = useAtomValue(connectorDataAtom)
const setTransactionStatus = useSetAtom(lastTxStatusAtom)

const handleSignSubmit = async (skipDeploy?: boolean) => {
Expand All @@ -42,7 +45,12 @@ const SignMessage: FC<SignMessageProps> = ({ account, wallet }) => {
await account.getChainId(),
shortText,
)
: await signMessageRcpMethod(wallet, shortText, skipDeploy)
: await signMessageRcpMethod(
wallet,
connectorData?.chainId,
shortText,
skipDeploy,
)
setLastSig(stark.formatSignature(result))
setTransactionStatus("success")
} catch (e) {
Expand Down
5 changes: 1 addition & 4 deletions src/services/signMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const signMessage = async (

export const signMessageRcpMethod = async (
wallet: StarknetWindowObject | undefined | null,
chainId: constants.StarknetChainId | undefined,
message: string,
skipDeploy = false,
) => {
Expand All @@ -44,10 +45,6 @@ export const signMessageRcpMethod = async (
throw Error("wallet not connected")
}

const chainId = await wallet?.request({
type: "wallet_requestChainId",
})

return wallet.request({
type: "wallet_signTypedData",
params: {
Expand Down

0 comments on commit 8d79ea1

Please sign in to comment.