Skip to content

Commit

Permalink
Add EOA Wallet link demo (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
taylanpince authored Jun 10, 2024
1 parent dbb72c6 commit 56f9914
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { AnimatePresence } from 'framer-motion'
import { PINCodeInput } from './components/PINCodeInput'
import { SendERC20View } from './components/views/SendERC20View'
import { SendERC1155View } from './components/views/SendERC1155View'
import { EOALinkView } from './components/views/EOALinkView'
import { NetworkSwitch } from './components/NetworkSwitch.tsx'
import { Network } from '@0xsequence/waas'

Expand Down Expand Up @@ -170,6 +171,10 @@ function App() {
<Divider background="buttonGlass" />
<CallContractsView network={network} />
</Collapsible>
<Collapsible marginY={'3'} label="EOA Link">
<Divider background="buttonGlass" />
<EOALinkView network={network} walletAddress={walletAddress} />
</Collapsible>
</Box>
</>
)
Expand Down
86 changes: 86 additions & 0 deletions src/components/views/EOALinkView.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@

import { Box, Text, Button, Spinner } from "@0xsequence/design-system"
import { useState } from "react"
import { sequence } from "../../main.tsx"
import {
Network,
} from "@0xsequence/waas"

export function EOALinkView(props: {network?: Network, walletAddress?: string}) {
const [authProofSignature, setAuthProofSignature] = useState<string>()
const [authProofSessionId, setAuthProofSessionId] = useState<string>()
const [verificationLink, setVerificationLink] = useState<string>()
const [externalNonce, setExternalNonce] = useState<string>()
const [inProgress, setInProgress] = useState<boolean>(false)
const [sendTransactionError, setSendTransactionError] = useState<string>()

const generateEOALink = async () => {
try {
setSendTransactionError(undefined)
setInProgress(true)

const response = await fetch('https://demo-waas-wallet-link-server.tpin.workers.dev/generateNonce', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ walletAddress: props.walletAddress })
})

const data = await response.json()

setVerificationLink(data.verificationUrl)
setExternalNonce(data.nonce)

const authProof = await sequence.sessionAuthProof({
nonce: data.nonce,
network: props.network?.name
})

setAuthProofSessionId(authProof.data.sessionId)
setAuthProofSignature(authProof.data.signature)

setInProgress(false)
} catch (e) {
console.error(e)
setInProgress(false)
}
}

return (
<Box>
{sendTransactionError && (
<Box marginTop="3">
Transaction failed: {sendTransactionError}
</Box>
)}
{!inProgress ? (
<Box>
<Button
marginTop="5"
label="Generate EOA Link"
disabled={
externalNonce !== undefined
}
onClick={() => generateEOALink() }
/>
</Box>
) : (
<Box gap="2" marginY="4" alignItems="center" justifyContent="center">
<Spinner />
</Box>
)}
{externalNonce && (
<Box marginTop="3">
<Text variant="normal" color="text100" fontWeight="bold">
Verification Link:
</Text>
<br />
<a href={`${verificationLink}?nonce=${externalNonce}&signature=${authProofSignature}&sessionId=${authProofSessionId}&chainId=${props.network?.id}`} target="_blank" rel="noopener noreferrer">
{verificationLink}?nonce={externalNonce}&signature={authProofSignature}&sessionId={authProofSessionId}&chainId={props.network?.id}
</a>
</Box>
)}
</Box>
)
}

0 comments on commit 56f9914

Please sign in to comment.