-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TD-1515: chore: add examples for signing ERC1155 listings in Passport…
… sample app. (#1939)
- Loading branch information
1 parent
5e3f5f8
commit f4d7312
Showing
5 changed files
with
333 additions
and
18 deletions.
There are no files selected for viewing
85 changes: 85 additions & 0 deletions
85
...pp/src/components/zkevm/EthSignTypedDataV4Examples/SeaportCreateERC1155ListingDefault.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,85 @@ | ||
import React, { | ||
useCallback, useEffect, useMemo, useState, | ||
} from 'react'; | ||
import { | ||
Accordion, Alert, Form, Stack, | ||
} from 'react-bootstrap'; | ||
import WorkflowButton from '@/components/WorkflowButton'; | ||
import { RequestExampleProps } from '@/types'; | ||
import { useImmutableProvider } from '@/context/ImmutableProvider'; | ||
import { usePassportProvider } from '@/context/PassportProvider'; | ||
import { getCreateERC1155ListingPayload } from './SeaportCreateListingExample'; | ||
|
||
function SeaportCreateERC1155ListingDefault({ disabled, handleExampleSubmitted }: RequestExampleProps) { | ||
const { orderbookClient } = useImmutableProvider(); | ||
const { zkEvmProvider } = usePassportProvider(); | ||
|
||
const [params, setParams] = useState<any>(); | ||
|
||
const seaportContractAddress = useMemo( | ||
() => ( | ||
orderbookClient.config().seaportContractAddress | ||
), | ||
[orderbookClient], | ||
); | ||
|
||
useEffect(() => { | ||
const getAddress = async () => { | ||
if (zkEvmProvider) { | ||
const [address] = await zkEvmProvider.request({ | ||
method: 'eth_requestAccounts', | ||
}); | ||
const chainIdHex = await zkEvmProvider.request({ method: 'eth_chainId' }); | ||
const chainId = parseInt(chainIdHex, 16); | ||
const data = getCreateERC1155ListingPayload({ seaportContractAddress, walletAddress: address, chainId }); | ||
setParams([address, data]); | ||
} | ||
}; | ||
getAddress().catch(console.log); | ||
}, [zkEvmProvider, seaportContractAddress]); | ||
|
||
const handleSubmit = useCallback(async (e: React.FormEvent<HTMLFormElement>) => { | ||
e.preventDefault(); | ||
e.stopPropagation(); | ||
|
||
return handleExampleSubmitted({ | ||
method: 'eth_signTypedData_v4', | ||
params, | ||
}); | ||
}, [handleExampleSubmitted, params]); | ||
|
||
return ( | ||
<Accordion.Item eventKey="5"> | ||
<Accordion.Header>Seaport Create Listing - ERC1155 order (Hardcoded example)</Accordion.Header> | ||
<Accordion.Body> | ||
<Alert variant="warning"> | ||
Note: This method only returns a signed message, it does not submit an order to the orderbook. | ||
</Alert> | ||
<Form onSubmit={handleSubmit} className="mb-4"> | ||
<Form.Group className="mb-3"> | ||
<Form.Label> | ||
Preview | ||
</Form.Label> | ||
<Form.Control | ||
required | ||
disabled | ||
as="textarea" | ||
rows={7} | ||
value={JSON.stringify(params, null, '\t')} | ||
/> | ||
</Form.Group> | ||
<Stack direction="horizontal" gap={3}> | ||
<WorkflowButton | ||
disabled={disabled} | ||
type="submit" | ||
> | ||
Submit | ||
</WorkflowButton> | ||
</Stack> | ||
</Form> | ||
</Accordion.Body> | ||
</Accordion.Item> | ||
); | ||
} | ||
|
||
export default SeaportCreateERC1155ListingDefault; |
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
Oops, something went wrong.