From 56f991400d0a449868568967b3753bf81972d3e9 Mon Sep 17 00:00:00 2001 From: Taylan Pince Date: Mon, 10 Jun 2024 12:32:04 +0200 Subject: [PATCH] Add EOA Wallet link demo (#23) --- src/App.tsx | 5 ++ src/components/views/EOALinkView.tsx | 86 ++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 src/components/views/EOALinkView.tsx diff --git a/src/App.tsx b/src/App.tsx index adc68e4..f76b7df 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -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' @@ -170,6 +171,10 @@ function App() { + + + + ) diff --git a/src/components/views/EOALinkView.tsx b/src/components/views/EOALinkView.tsx new file mode 100644 index 0000000..8d491c9 --- /dev/null +++ b/src/components/views/EOALinkView.tsx @@ -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() + const [authProofSessionId, setAuthProofSessionId] = useState() + const [verificationLink, setVerificationLink] = useState() + const [externalNonce, setExternalNonce] = useState() + const [inProgress, setInProgress] = useState(false) + const [sendTransactionError, setSendTransactionError] = useState() + + 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 ( + + {sendTransactionError && ( + + Transaction failed: {sendTransactionError} + + )} + {!inProgress ? ( + +