166166</template >
167167
168168<script setup lang="ts">
169+ import { getAccount , signTypedData } from " @wagmi/core" ;
169170import {
170171 type Address ,
171- createWalletClient ,
172172 type Hex ,
173- http ,
174- parseEther ,
175- type TypedDataDefinition } from " viem" ;
176- import { erc7739Actions } from " viem/experimental" ;
173+ isAddress ,
174+ parseEther } from " viem" ;
177175import { reactive , ref } from " vue" ;
178176
179- const { account } = storeToRefs (useConnectorStore ());
180-
181177const runtimeConfig = useRuntimeConfig ();
182- const chain = runtimeConfig .public .chain ;
183178
184179const config = reactive ({
185180 marketplaceName: " SimpleMarketplace" ,
@@ -216,59 +211,39 @@ const listRequestTypes = {
216211 ],
217212} as const ;
218213
214+ const { account } = storeToRefs (useConnectorStore ());
215+
219216async function handleSignListRequest() {
220- isLoading .value = true ;
221217 errorMsg .value = null ;
222218 signature .value = null ;
223219 signedDomain .value = null ;
224220 signedTypes .value = null ;
225221 signedMessage .value = null ;
222+ const connectedAccount = getAccount ();
226223
227- if (! config .marketplaceAddress ) {
228- errorMsg .value = " Marketplace address is required." ;
229- isLoading .value = false ;
230- console .error (" Marketplace address is required." , runtimeConfig .public .contracts .marketplace );
224+ if (! connectedAccount .isConnected || ! connectedAccount .address ) {
225+ errorMsg .value = " Please connect your wallet first." ;
231226 return ;
232227 }
233- if (! account .value .address ) {
234- errorMsg .value = " Smart Account address is required." ;
235- isLoading .value = false ;
236- return ;
237- }
238- if (! config .nftContractAddress ) {
239- errorMsg .value = " nft address is required." ;
240- isLoading .value = false ;
228+
229+ // --- Pre-flight Checks for Addresses and Critical Values ---
230+ if (! config .marketplaceAddress || ! isAddress (config .marketplaceAddress )) {
231+ errorMsg .value = " Marketplace Contract Address (Verifying Contract) is missing or invalid." ;
241232 return ;
242233 }
243- if ( ! chain ) {
244- errorMsg . value = " Chain not found in wagmiConfig. " ;
245- isLoading .value = false ;
234+ const smartAccount = account . value ;
235+ if ( ! smartAccount . address || ! isAddress ( smartAccount . address )) {
236+ errorMsg .value = " Seller Smart Account Address is missing or invalid. " ;
246237 return ;
247238 }
248- if (! chain .id ) {
249- errorMsg .value = " Chain ID is required." ;
250- isLoading .value = false ;
239+ if (! config .nftContractAddress || ! isAddress (config .nftContractAddress )) {
240+ errorMsg .value = " NFT Contract Address is missing or invalid." ;
251241 return ;
252242 }
243+ // --- End Pre-flight Checks ---
244+ const chain = runtimeConfig .public .chain ;
253245
254246 try {
255- const accountValue = account .value ;
256- if (! accountValue || ! accountValue .address ) {
257- errorMsg .value = " Smart Account address is required." ;
258- isLoading .value = false ;
259- return ;
260- }
261- if (! config .marketplaceAddress || ! config .nftContractAddress ) {
262- errorMsg .value = " Marketplace and NFT contract addresses are required." ;
263- isLoading .value = false ;
264- return ;
265- }
266- // this needs to be a wagmi account, not a private key
267- const client = createWalletClient ({
268- account: accountValue ,
269- chain: chain ,
270- transport: http (),
271- }).extend (erc7739Actions ());
272247 const domain = {
273248 name: config .marketplaceName ,
274249 version: config .marketplaceVersion ,
@@ -277,7 +252,7 @@ async function handleSignListRequest() {
277252 } as const ;
278253
279254 const message = {
280- seller: accountValue .address ,
255+ seller: smartAccount .address as Address , // The smart account is the seller
281256 nftContract: config .nftContractAddress as Address ,
282257 tokenId: BigInt (config .tokenId ),
283258 price: parseEther (config .priceInEth ),
@@ -289,22 +264,19 @@ async function handleSignListRequest() {
289264 signedTypes .value = listRequestTypes ;
290265 signedMessage .value = message ;
291266
292- const typedData : TypedDataDefinition < typeof listRequestTypes , " ListRequest " > = {
267+ const typedDataArgs = {
293268 domain ,
294269 types: listRequestTypes ,
295270 primaryType: " ListRequest" ,
296271 message ,
297- };
272+ } as const ;
298273
299- const sig = await client .signTypedData (typedData );
274+ // Use wagmi/core's signTypedData
275+ const sig = await signTypedData (typedDataArgs );
300276 signature .value = sig ;
301277 } catch (e ) {
302- errorMsg .value = e .message || " An unknown error occurred during signing." ;
303- if (e .shortMessage ) { // Viem often has a shortMessage
304- errorMsg .value = e .shortMessage ;
305- }
306- } finally {
307- isLoading .value = false ;
278+ console .error (" Error in handleSignListRequest:" , e );
279+ errorMsg .value = e .message || " An unknown error occurred during the signing process preparation." ;
308280 }
309281}
310282 </script >
0 commit comments