Merge branch 'main' of github.com:WalletConnect/examples into main

This commit is contained in:
Ben Kremer committed 2022-02-16 14:12:42 +01:00
commit 415b38759e
34 files changed
+1994 -112

No files matched your search

+11 -6
View File
@@ -2,7 +2,7 @@
"name": "react-wallet-v2",
"private": true,
"scripts": {
"dev": "next dev -p 3100",
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
@@ -11,18 +11,23 @@
"@walletconnect/client": "2.0.0-beta.22",
"@walletconnect/utils": "2.0.0-beta.22",
"@walletconnect/jsonrpc-utils": "1.0.0",
"@nextui-org/react": "1.0.2-beta.3",
"@nextui-org/react": "1.0.2-beta.4",
"next": "12.0.10",
"next-themes": "0.0.15",
"react": "17.0.2",
"react-dom": "17.0.2",
"react-qr-reader-es6": "2.2.1-2",
"framer-motion": "6.2.6",
"ethers": "5.5.4",
"keyvaluestorage": "0.7.1"
"valtio": "1.3.0",
"@json-rpc-tools/utils": "1.7.6",
"react-code-blocks": "0.0.9-0"
},
"devDependencies": {
"@walletconnect/types": "2.0.0-beta.22",
"@types/node": "17.0.14",
"@types/react": "17.0.38",
"eslint": "8.8.0",
"@types/node": "17.0.17",
"@types/react": "17.0.39",
"eslint": "8.9.0",
"eslint-config-next": "12.0.10",
"eslint-config-prettier": "8.3.0",
"prettier": "2.5.1",
@@ -0,0 +1,24 @@
<svg width="512" height="512" viewBox="0 0 512 512" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M160 368H448M160 144H448H160ZM160 256H448H160Z" stroke="url(#paint0_linear_46_13)" stroke-width="48" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M80 160C88.8366 160 96 152.837 96 144C96 135.163 88.8366 128 80 128C71.1634 128 64 135.163 64 144C64 152.837 71.1634 160 80 160Z" stroke="url(#paint1_linear_46_13)" stroke-width="32" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M80 272C88.8366 272 96 264.837 96 256C96 247.163 88.8366 240 80 240C71.1634 240 64 247.163 64 256C64 264.837 71.1634 272 80 272Z" stroke="url(#paint2_linear_46_13)" stroke-width="32" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M80 384C88.8366 384 96 376.837 96 368C96 359.163 88.8366 352 80 352C71.1634 352 64 359.163 64 368C64 376.837 71.1634 384 80 384Z" stroke="url(#paint3_linear_46_13)" stroke-width="32" stroke-linecap="round" stroke-linejoin="round"/>
<defs>
<linearGradient id="paint0_linear_46_13" x1="160" y1="144.018" x2="380.191" y2="421.745" gradientUnits="userSpaceOnUse">
<stop stop-color="#A562D5"/>
<stop offset="1" stop-color="#306FEB"/>
</linearGradient>
<linearGradient id="paint1_linear_46_13" x1="64" y1="128.003" x2="96.3014" y2="159.69" gradientUnits="userSpaceOnUse">
<stop stop-color="#A562D5"/>
<stop offset="1" stop-color="#306FEB"/>
</linearGradient>
<linearGradient id="paint2_linear_46_13" x1="64" y1="240.003" x2="96.3014" y2="271.69" gradientUnits="userSpaceOnUse">
<stop stop-color="#A562D5"/>
<stop offset="1" stop-color="#306FEB"/>
</linearGradient>
<linearGradient id="paint3_linear_46_13" x1="64" y1="352.003" x2="96.3014" y2="383.69" gradientUnits="userSpaceOnUse">
<stop stop-color="#A562D5"/>
<stop offset="1" stop-color="#306FEB"/>
</linearGradient>
</defs>
</svg>

After

Width:  |  Height:  |  Size: 1.8 KiB

+52
View File
@@ -0,0 +1,52 @@
* {
box-sizing: border-box;
-ms-overflow-style: none;
scrollbar-width: none;
}
::-webkit-scrollbar {
display: none;
}
.routeTransition {
display: flex;
flex: 1;
flex-direction: column;
overflow: hidden;
}
.container {
width: 100%;
display: flex;
flex: 1;
flex-direction: column;
justify-content: center;
align-items: center;
}
.qrVideoMask {
width: 100%;
border-radius: 15px;
overflow: hidden !important;
position: relative;
}
.qrPlaceholder {
border: 2px rgba(139, 139, 139, 0.4) dashed;
width: 100%;
border-radius: 15px;
padding: 50px;
}
.qrIcon {
opacity: 0.3;
}
.codeBlock code {
flex: 1;
}
.codeBlock span {
background-color: transparent !important;
overflow: scroll;
}
@@ -0,0 +1,13 @@
<svg width="512" height="512" viewBox="0 0 512 512" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M408 336H344C339.582 336 336 339.582 336 344V408C336 412.418 339.582 416 344 416H408C412.418 416 416 412.418 416 408V344C416 339.582 412.418 336 408 336Z" fill="#8B8B8B"/>
<path d="M328 272H280C275.582 272 272 275.582 272 280V328C272 332.418 275.582 336 280 336H328C332.418 336 336 332.418 336 328V280C336 275.582 332.418 272 328 272Z" fill="#8B8B8B"/>
<path d="M472 416H424C419.582 416 416 419.582 416 424V472C416 476.418 419.582 480 424 480H472C476.418 480 480 476.418 480 472V424C480 419.582 476.418 416 472 416Z" fill="#8B8B8B"/>
<path d="M472 272H440C435.582 272 432 275.582 432 280V312C432 316.418 435.582 320 440 320H472C476.418 320 480 316.418 480 312V280C480 275.582 476.418 272 472 272Z" fill="#8B8B8B"/>
<path d="M312 432H280C275.582 432 272 435.582 272 440V472C272 476.418 275.582 480 280 480H312C316.418 480 320 476.418 320 472V440C320 435.582 316.418 432 312 432Z" fill="#8B8B8B"/>
<path d="M408 96H344C339.582 96 336 99.5817 336 104V168C336 172.418 339.582 176 344 176H408C412.418 176 416 172.418 416 168V104C416 99.5817 412.418 96 408 96Z" fill="#8B8B8B"/>
<path d="M448 48H304C295.163 48 288 55.1634 288 64V208C288 216.837 295.163 224 304 224H448C456.837 224 464 216.837 464 208V64C464 55.1634 456.837 48 448 48Z" stroke="#8B8B8B" stroke-width="32" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M168 96H104C99.5817 96 96 99.5817 96 104V168C96 172.418 99.5817 176 104 176H168C172.418 176 176 172.418 176 168V104C176 99.5817 172.418 96 168 96Z" fill="#8B8B8B"/>
<path d="M208 48H64C55.1634 48 48 55.1634 48 64V208C48 216.837 55.1634 224 64 224H208C216.837 224 224 216.837 224 208V64C224 55.1634 216.837 48 208 48Z" stroke="#8B8B8B" stroke-width="32" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M168 336H104C99.5817 336 96 339.582 96 344V408C96 412.418 99.5817 416 104 416H168C172.418 416 176 412.418 176 408V344C176 339.582 172.418 336 168 336Z" fill="#8B8B8B"/>
<path d="M208 288H64C55.1634 288 48 295.163 48 304V448C48 456.837 55.1634 464 64 464H208C216.837 464 224 456.837 224 448V304C224 295.163 216.837 288 208 288Z" stroke="#8B8B8B" stroke-width="32" stroke-linecap="round" stroke-linejoin="round"/>
</svg>

After

Width:  |  Height:  |  Size: 2.2 KiB

@@ -0,0 +1,9 @@
<svg width="512" height="512" viewBox="0 0 512 512" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M464 249.93C463.865 247.435 462.851 245.067 461.138 243.248C459.425 241.429 457.123 240.275 454.64 239.99L429 235.84C427.847 235.651 426.785 235.094 425.975 234.252C425.164 233.411 424.646 232.33 424.5 231.17C424.01 228.02 423.5 224.75 422.8 221.65C422.574 220.522 422.707 219.353 423.178 218.304C423.65 217.255 424.437 216.38 425.43 215.8L448.21 203.15C450.472 201.997 452.231 200.053 453.153 197.687C454.075 195.322 454.095 192.7 453.21 190.32L449.26 179.42C448.394 177.032 446.677 175.048 444.439 173.847C442.201 172.646 439.599 172.312 437.13 172.91L411.58 177.91C410.438 178.114 409.26 177.952 408.215 177.448C407.17 176.943 406.311 176.122 405.76 175.1C404.27 172.31 402.65 169.47 400.96 166.68C400.346 165.686 400.059 164.525 400.138 163.359C400.216 162.194 400.658 161.082 401.4 160.18L418.4 140.54C420.127 138.686 421.119 136.266 421.191 133.734C421.263 131.201 420.409 128.729 418.79 126.78L411.37 117.87C409.756 115.914 407.473 114.627 404.965 114.258C402.456 113.888 399.9 114.463 397.79 115.87L375.42 129.3C374.428 129.894 373.272 130.154 372.121 130.04C370.97 129.927 369.887 129.446 369.03 128.67C366.56 126.5 364.03 124.41 361.66 122.48C360.75 121.762 360.093 120.773 359.784 119.656C359.475 118.54 359.529 117.354 359.94 116.27L369.2 91.87C370.209 89.5419 370.327 86.9244 369.532 84.5149C368.738 82.1053 367.086 80.0716 364.89 78.8L354.8 72.91C352.603 71.6431 350.016 71.2313 347.534 71.7535C345.052 72.2757 342.85 73.6951 341.35 75.74L325 96.28C324.412 97.1728 323.531 97.8328 322.509 98.1467C321.487 98.4606 320.388 98.4087 319.4 98C318.79 97.75 313.63 95.64 309.62 94.3C308.52 93.9415 307.564 93.2405 306.891 92.2995C306.218 91.3584 305.864 90.2268 305.88 89.07L306.27 63C306.409 60.4544 305.616 57.9453 304.038 55.9426C302.461 53.9398 300.207 52.5808 297.7 52.12L286.25 50.12C283.755 49.689 281.189 50.1784 279.028 51.4971C276.867 52.8159 275.258 54.8743 274.5 57.29L266 82.1C265.614 83.2014 264.885 84.15 263.921 84.8069C262.956 85.4638 261.806 85.7943 260.64 85.75H250.89C249.733 85.7738 248.598 85.4318 247.646 84.7729C246.694 84.114 245.975 83.1716 245.59 82.08L237.13 57.41C236.386 54.9767 234.78 52.8981 232.613 51.5636C230.447 50.229 227.868 49.73 225.36 50.16L213.89 52.16C211.399 52.6172 209.158 53.9629 207.584 55.9473C206.009 57.9317 205.209 60.4199 205.33 62.95L205.73 89.11C205.738 90.2841 205.367 91.4294 204.671 92.3754C203.976 93.3214 202.993 94.0175 201.87 94.36C199.58 95.25 194.61 97.15 192.35 97.99C190.35 98.71 188.17 97.92 186.41 95.89L170.15 75.89C168.658 73.8327 166.458 72.3994 163.974 71.866C161.489 71.3325 158.895 71.7364 156.69 73L146.63 78.83C144.41 80.104 142.741 82.1544 141.943 84.5862C141.146 87.0179 141.276 89.6589 142.31 92L151.56 116.34C151.964 117.426 152.017 118.611 151.712 119.728C151.407 120.846 150.759 121.84 149.86 122.57C147.43 124.57 144.94 126.57 142.46 128.79C141.608 129.56 140.533 130.038 139.39 130.153C138.248 130.268 137.098 130.015 136.11 129.43L114 115.74C111.877 114.359 109.323 113.8 106.817 114.168C104.311 114.537 102.026 115.807 100.39 117.74L93 126.63C91.3585 128.566 90.4886 131.039 90.5569 133.576C90.6252 136.113 91.6268 138.535 93.3701 140.38L110.45 160C111.208 160.884 111.661 161.989 111.742 163.151C111.823 164.312 111.528 165.469 110.9 166.45C109.19 169.17 107.56 172.03 106.08 174.89C105.526 175.919 104.661 176.746 103.608 177.252C102.556 177.759 101.369 177.919 100.22 177.71L74.71 172.78C72.2401 172.184 69.6373 172.518 67.3981 173.719C65.159 174.92 63.4403 176.903 62.57 179.29L58.57 190.17C57.6859 192.553 57.7066 195.177 58.6281 197.545C59.5497 199.914 61.3081 201.862 63.57 203.02L86.35 215.67C87.3745 216.235 88.1871 217.119 88.6652 218.187C89.1432 219.255 89.2608 220.449 89 221.59L88.7601 222.86C88.2401 225.65 87.7601 228.29 87.3001 231.1C87.141 232.245 86.624 233.31 85.823 234.144C85.0219 234.977 83.9778 235.536 82.84 235.74L57.1501 239.89C54.6377 240.198 52.3235 241.411 50.6397 243.301C48.9559 245.191 48.0176 247.629 48 250.16V261.74C47.9854 264.281 48.9141 266.737 50.6063 268.632C52.2985 270.528 54.6338 271.728 57.16 272L82.84 276.14C83.994 276.328 85.0561 276.884 85.8674 277.726C86.6786 278.568 87.1953 279.65 87.34 280.81C87.83 283.97 88.3401 287.23 89.0401 290.33C89.2656 291.458 89.1334 292.627 88.6619 293.676C88.1904 294.725 87.4031 295.6 86.4101 296.18L63.64 308.85C61.3781 310.003 59.6188 311.947 58.6969 314.313C57.775 316.678 57.7548 319.3 58.64 321.68L62.64 332.58C63.5083 334.966 65.2251 336.949 67.4626 338.15C69.7001 339.351 72.3015 339.686 74.77 339.09L100.32 334.14C101.463 333.933 102.642 334.093 103.687 334.598C104.733 335.103 105.592 335.926 106.14 336.95C107.64 339.75 109.25 342.58 110.94 345.37C111.557 346.363 111.846 347.525 111.767 348.691C111.688 349.857 111.245 350.969 110.5 351.87L93.5 371.5C91.7529 373.34 90.7378 375.755 90.6458 378.29C90.5537 380.826 91.3909 383.308 93 385.27L100.41 394.18C102.023 396.138 104.305 397.426 106.815 397.796C109.324 398.165 111.881 397.589 113.99 396.18L136.36 382.75C137.352 382.156 138.508 381.896 139.659 382.Line truncated
<defs>
<linearGradient id="paint0_linear_46_10" x1="48" y1="50" x2="464" y2="462" gradientUnits="userSpaceOnUse">
<stop stop-color="#A562D5"/>
<stop offset="1" stop-color="#306FEB"/>
</linearGradient>
</defs>
</svg>

After

Width:  |  Height:  |  Size: 9.8 KiB

@@ -0,0 +1,3 @@
<svg width="388" height="238" viewBox="0 0 388 238" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M79.4993 46.539C142.716 -15.355 245.209 -15.355 308.426 46.539L316.034 53.988C319.195 57.0827 319.195 62.1002 316.034 65.1949L290.008 90.6766C288.427 92.2239 285.865 92.2239 284.285 90.6766L273.815 80.4258C229.714 37.247 158.211 37.247 114.11 80.4258L102.898 91.4035C101.317 92.9509 98.7551 92.9509 97.1747 91.4035L71.1486 65.9219C67.9878 62.8272 67.9878 57.8096 71.1486 54.715L79.4993 46.539ZM362.25 99.2378L385.413 121.917C388.574 125.011 388.574 130.029 385.413 133.123L280.969 235.385C277.808 238.48 272.683 238.48 269.522 235.385C269.522 235.385 269.522 235.385 269.522 235.385L195.394 162.807C194.604 162.033 193.322 162.033 192.532 162.807C192.532 162.807 192.532 162.807 192.532 162.807L118.405 235.385C115.244 238.48 110.12 238.48 106.959 235.385C106.959 235.385 106.959 235.385 106.959 235.385L2.51129 133.122C-0.649517 130.027 -0.649517 125.01 2.51129 121.915L25.6746 99.2365C28.8354 96.1418 33.9601 96.1418 37.1209 99.2365L111.25 171.816C112.041 172.589 113.322 172.589 114.112 171.816C114.112 171.816 114.112 171.815 114.112 171.815L188.238 99.2365C191.399 96.1417 196.523 96.1416 199.684 99.2362C199.684 99.2362 199.684 99.2363 199.684 99.2363L273.814 171.815C274.604 172.589 275.885 172.589 276.675 171.815L350.804 99.2378C353.964 96.1431 359.089 96.1431 362.25 99.2378Z" fill="white"/>
</svg>

After

Width:  |  Height:  |  Size: 1.4 KiB

@@ -0,0 +1,48 @@
import { truncate } from '@/utils/HelperUtil'
import { Avatar, Card, Text } from '@nextui-org/react'
import Link from 'next/link'
interface Props {
name: string
logo: string
rgb: string
address: string
}
export default function AccountCard({ name, logo, rgb, address }: Props) {
return (
<Link href={`/sessions?address=${address}`} passHref>
<Card
bordered
clickable
borderWeight="light"
css={{
borderColor: `rgba(${rgb}, 0.4)`,
boxShadow: `0 0 10px 0 rgba(${rgb}, 0.15)`,
backgroundColor: `rgba(${rgb}, 0.25)`,
marginBottom: '$6',
minHeight: '70px'
}}
>
<Card.Body
css={{
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'space-between',
overflow: 'hidden'
}}
>
<Avatar src={logo} />
<div style={{ flex: 1 }}>
<Text h5 css={{ marginLeft: '$9' }}>
{name}
</Text>
<Text weight="light" size={13} css={{ marginLeft: '$9' }}>
{truncate(address, 19)}
</Text>
</div>
</Card.Body>
</Card>
</Link>
)
}
@@ -1,32 +1,83 @@
import { Card, Container, Divider } from '@nextui-org/react'
import { ReactNode } from 'react'
import Navigation from '@/components/Navigation'
import RouteTransition from '@/components/RouteTransition'
import { Card, Container, Loading } from '@nextui-org/react'
import { Fragment, ReactNode } from 'react'
/**
* Types
*/
interface Props {
initialized: boolean
children: ReactNode | ReactNode[]
}
export default function Layout({ children }: Props) {
/**
* Container
*/
export default function Layout({ children, initialized }: Props) {
return (
<Container
display="flex"
justify="center"
alignItems="center"
css={{ width: '100vw', height: '100vh' }}
css={{
width: '100vw',
height: '100vh',
paddingLeft: 0,
paddingRight: 0
}}
>
<Card
bordered
borderWeight="light"
css={{ height: '92vh', maxWidth: '600px', width: '100%' }}
bordered={{ '@initial': false, '@xs': true }}
borderWeight={{ '@initial': 'light', '@xs': 'light' }}
css={{
height: '100vh',
width: '100%',
justifyContent: initialized ? 'normal' : 'center',
alignItems: initialized ? 'normal' : 'center',
borderRadius: 0,
paddingBottom: 5,
'@xs': {
borderRadius: '$lg',
height: '95vh',
maxWidth: '450px'
}
}}
>
<Card.Header>Header</Card.Header>
{initialized ? (
<Fragment>
<RouteTransition>
<Card.Body
css={{
paddingLeft: 2,
paddingRight: 2,
'@xs': {
padding: '20px'
}
}}
>
{children}
</Card.Body>
</RouteTransition>
<Divider />
<Card.Body css={{ overflow: 'scroll' }}>{children}</Card.Body>
<Divider />
<Card.Footer>Footer</Card.Footer>
<Card.Footer
css={{
height: '85px',
minHeight: '85px',
position: 'sticky',
justifyContent: 'flex-end',
alignItems: 'flex-end',
bottom: 0,
left: 0
}}
>
<Navigation />
</Card.Footer>
</Fragment>
) : (
<Loading />
)}
</Card>
</Container>
)
@@ -0,0 +1,18 @@
import ModalStore from '@/store/ModalStore'
import SessionProposalModal from '@/views/SessionProposalModal'
import SessionRequestModal from '@/views/SessionSignModal'
import SessionSignTypedDataModal from '@/views/SessionSignTypedDataModal'
import { Modal as NextModal } from '@nextui-org/react'
import { useSnapshot } from 'valtio'
export default function Modal() {
const { open, view } = useSnapshot(ModalStore.state)
return (
<NextModal blur open={open} style={{ border: '1px solid rgba(139, 139, 139, 0.4)' }}>
{view === 'SessionProposalModal' && <SessionProposalModal />}
{view === 'SessionSignModal' && <SessionRequestModal />}
{view === 'SessionSignTypedDataModal' && <SessionSignTypedDataModal />}
</NextModal>
)
}
@@ -0,0 +1,39 @@
import { Avatar, Row } from '@nextui-org/react'
import Image from 'next/image'
import Link from 'next/link'
export default function Navigation() {
return (
<Row justify="space-between" align="center" css={{ width: '80%', margin: '0 auto' }}>
<Link href="/" passHref>
<a>
<Image alt="accounts icon" src="/accounts-icon.svg" width={30} height={30} />
</a>
</Link>
<Link href="/walletconnect" passHref>
<a>
<Avatar
size="lg"
css={{ cursor: 'pointer' }}
color="gradient"
icon={
<Image
alt="wallet connect icon"
src="/wallet-connect-logo.svg"
width={30}
height={30}
/>
}
/>
</a>
</Link>
<Link href="/settings" passHref>
<a>
<Image alt="settings icon" src="/settings-icon.svg" width={35} height={35} />
</a>
</Link>
</Row>
)
}
@@ -1,19 +1,30 @@
import { Text } from '@nextui-org/react'
import { Divider, Text } from '@nextui-org/react'
import { Fragment } from 'react'
/**
* Types
*/
interface Props {
children: string
}
/**
* Component
*/
export default function PageHeader({ children }: Props) {
return (
<Text
h3
css={{
textGradient: '45deg, $cyan300 -30%, $green600 100%'
}}
weight="bold"
>
{children}
</Text>
<Fragment>
<Text
h3
weight="bold"
css={{
textGradient: '90deg, $secondary, $primary 30%',
marginBottom: '$5'
}}
>
{children}
</Text>
<Divider css={{ marginBottom: '$10' }} />
</Fragment>
)
}
@@ -0,0 +1,77 @@
import { Button, Loading } from '@nextui-org/react'
import dynamic from 'next/dynamic'
import Image from 'next/image'
import { Fragment, useState } from 'react'
/**
* You can use normal import if you are not within next / ssr environment
* @info https://nextjs.org/docs/advanced-features/dynamic-import
*/
const ReactQrReader = dynamic(() => import('react-qr-reader-es6'), { ssr: false })
/**
* Types
*/
interface IProps {
onConnect: (uri: string) => Promise<void>
}
/**
* Component
*/
export default function QrReader({ onConnect }: IProps) {
const [show, setShow] = useState(false)
const [loading, setLoading] = useState(false)
function onError() {
setShow(false)
}
async function onScan(data: string | null) {
if (data) {
await onConnect(data)
setShow(false)
}
}
function onShowScanner() {
setLoading(true)
setShow(true)
}
return (
<div className="container">
{show ? (
<Fragment>
{loading && <Loading css={{ position: 'absolute' }} />}
<div className="qrVideoMask">
<ReactQrReader
onLoad={() => setLoading(false)}
showViewFinder={false}
onError={onError}
onScan={onScan}
style={{ width: '100%' }}
/>
</div>
</Fragment>
) : (
<div className="container qrPlaceholder">
<Image
src="/qr-icon.svg"
width={100}
height={100}
alt="qr code icon"
className="qrIcon"
/>
<Button
color="gradient"
css={{ marginTop: '$10', width: '100%' }}
onClick={onShowScanner}
>
Scan QR code
</Button>
</div>
)}
</div>
)
}
@@ -0,0 +1,32 @@
import { AnimatePresence, motion } from 'framer-motion'
import { useRouter } from 'next/router'
import { ReactNode } from 'react'
/**
* Types
*/
interface IProps {
children: ReactNode | ReactNode[]
}
/**
* Components
*/
export default function RouteTransition({ children }: IProps) {
const { pathname } = useRouter()
return (
<AnimatePresence exitBeforeEnter>
<motion.div
className="routeTransition"
key={pathname}
initial={{ opacity: 0, translateY: 7 }}
animate={{ opacity: 1, translateY: 0 }}
exit={{ opacity: 0, translateY: 7 }}
transition={{ duration: 0.18 }}
>
{children}
</motion.div>
</AnimatePresence>
)
}
@@ -1,28 +0,0 @@
import { createContext, ReactNode, useState } from 'react'
/**
* Types
*/
interface State {}
interface Props {
children: ReactNode | ReactNode[]
}
/**
* Context
*/
export const WalletContext = createContext<State>({})
/**
* Provider
*/
export function WalletContextProvider({ children }: Props) {
const [state, setState] = useState<State>({})
const actions = {
async initialise() {}
}
return <WalletContext.Provider value={{ state, actions }}>{children}</WalletContext.Provider>
}
@@ -0,0 +1,87 @@
/**
* @desc Refference list of eip155 chains
* @url https://chainlist.org
*/
/**
* Utilities
*/
const LOGO_BASE_URL = 'https://blockchain-api.xyz/logos/'
/**
* Types
*/
export type TEIP155Chain = keyof typeof EIP155_CHAINS
/**
* Chains
*/
export const EIP155_MAINNET_CHAINS = {
'eip155:1': {
chainId: 1,
name: 'Ethereum',
logo: LOGO_BASE_URL + 'eip155:1.png',
rgb: '99, 125, 234'
},
'eip155:10': {
chainId: 10,
name: 'Optimism',
logo: LOGO_BASE_URL + 'eip155:10.png',
rgb: '233, 1, 1'
},
'eip155:137': {
chainId: 137,
name: 'Polygon',
logo: LOGO_BASE_URL + 'eip155:137.png',
rgb: '130, 71, 229'
},
'eip155:42161': {
chainId: 42161,
name: 'Arbitrum',
logo: LOGO_BASE_URL + 'eip155:42161.png',
rgb: '44, 55, 75'
}
}
export const EIP155_TEST_CHAINS = {
'eip155:4': {
chainId: 4,
name: 'Ethereum Rinkeby',
logo: LOGO_BASE_URL + 'eip155:1.png',
rgb: '99, 125, 234'
},
'eip155:69': {
chainId: 69,
name: 'Optimism Kovan',
logo: LOGO_BASE_URL + 'eip155:10.png',
rgb: '233, 1, 1'
},
'eip155:80001': {
chainId: 80001,
name: 'Polygon Mumbai',
logo: LOGO_BASE_URL + 'eip155:137.png',
rgb: '130, 71, 229'
},
'eip155:421611': {
chainId: 421611,
name: 'Arbitrum Rinkeby',
logo: LOGO_BASE_URL + 'eip155:42161.png',
rgb: '44, 55, 75'
}
}
export const EIP155_CHAINS = { ...EIP155_MAINNET_CHAINS, ...EIP155_TEST_CHAINS }
/**
* Methods
*/
export const EIP155_SIGNING_METHODS = {
PERSONAL_SIGN: 'personal_sign',
ETH_SIGN: 'eth_sign',
ETH_SIGN_TRANSACTION: 'eth_signTransaction',
ETH_SIGN_TYPED_DATA: 'eth_signTypedData',
ETH_SIGN_TYPED_DATA_V3: 'eth_signTypedData_v3',
ETH_SIGN_TYPED_DATA_V4: 'eth_signTypedData_v4',
ETH_SIGN_RAW_TRANSACTION: 'eth_sendRawTransaction',
ETH_SEND_TRANSACTION: 'eth_sendTransaction'
}
@@ -0,0 +1,25 @@
import { createWalletConnectClient } from '@/utils/WalletConnectUtil'
import { createOrRestoreWallet } from '@/utils/WalletUtil'
import { useCallback, useEffect, useState } from 'react'
export default function useInitialization() {
const [initialized, setInitialized] = useState(false)
const onInitialize = useCallback(async () => {
try {
createOrRestoreWallet()
await createWalletConnectClient()
setInitialized(true)
} catch (err: unknown) {
alert(err)
}
}, [])
useEffect(() => {
if (!initialized) {
onInitialize()
}
}, [initialized, onInitialize])
return initialized
}
@@ -0,0 +1,49 @@
import { EIP155_SIGNING_METHODS } from '@/data/EIP155Data'
import ModalStore from '@/store/ModalStore'
import { walletConnectClient } from '@/utils/WalletConnectUtil'
import { CLIENT_EVENTS } from '@walletconnect/client'
import { SessionTypes } from '@walletconnect/types'
import { useCallback, useEffect } from 'react'
export default function useWalletConnectEventsManager(initialized: boolean) {
// 1. Open session proposal modal for confirmation / rejection
const onSessionProposal = useCallback((proposal: SessionTypes.Proposal) => {
ModalStore.open('SessionProposalModal', { proposal })
}, [])
// 2. Open session created modal to show success feedback
const onSessionCreated = useCallback((created: SessionTypes.Created) => {}, [])
// 3. Open request handling modal based on method that was used
const onSessionRequest = useCallback(async (requestEvent: SessionTypes.RequestEvent) => {
const { topic, request } = requestEvent
const { method } = request
const requestSession = await walletConnectClient.session.get(topic)
// Hanle message signing requests of various formats
if ([EIP155_SIGNING_METHODS.ETH_SIGN, EIP155_SIGNING_METHODS.PERSONAL_SIGN].includes(method)) {
ModalStore.open('SessionSignModal', { requestEvent, requestSession })
}
// Hanle data signing requests of various formats
if (
[
EIP155_SIGNING_METHODS.ETH_SIGN_TYPED_DATA,
EIP155_SIGNING_METHODS.ETH_SIGN_TYPED_DATA_V3,
EIP155_SIGNING_METHODS.ETH_SIGN_TYPED_DATA_V4
].includes(method)
) {
ModalStore.open('SessionSignTypedDataModal', { requestEvent, requestSession })
}
}, [])
useEffect(() => {
if (initialized) {
walletConnectClient.on(CLIENT_EVENTS.session.proposal, onSessionProposal)
walletConnectClient.on(CLIENT_EVENTS.session.created, onSessionCreated)
walletConnectClient.on(CLIENT_EVENTS.session.request, onSessionRequest)
}
}, [initialized, onSessionProposal, onSessionCreated, onSessionRequest])
}
+26 -7
View File
@@ -1,17 +1,36 @@
import Layout from '@/components/Layout'
import { WalletContextProvider } from '@/contexts/WalletContext'
import { theme } from '@/utils/ThemeUtil'
import Modal from '@/components/Modal'
import useInitialization from '@/hooks/useInitialization'
import useWalletConnectEventsManager from '@/hooks/useWalletConnectEventsManager'
import { darkTheme, lightTheme } from '@/utils/ThemeUtil'
import { NextUIProvider } from '@nextui-org/react'
import { ThemeProvider } from 'next-themes'
import { AppProps } from 'next/app'
import '../../public/main.css'
export default function App({ Component, pageProps }: AppProps) {
// Step 1 - Initialize wallets and wallet connect client
const initialized = useInitialization()
// Step 2 - Once initialized, set up wallet connect event manager
useWalletConnectEventsManager(initialized)
return (
<NextUIProvider theme={theme}>
<WalletContextProvider>
<Layout>
<ThemeProvider
defaultTheme="system"
attribute="class"
value={{
light: lightTheme.className,
dark: darkTheme.className
}}
>
<NextUIProvider>
<Layout initialized={initialized}>
<Component {...pageProps} />
</Layout>
</WalletContextProvider>
</NextUIProvider>
<Modal />
</NextUIProvider>
</ThemeProvider>
)
}
+31 -1
View File
@@ -1,5 +1,35 @@
import AccountCard from '@/components/AccountCard'
import PageHeader from '@/components/PageHeader'
import { EIP155_MAINNET_CHAINS, EIP155_TEST_CHAINS } from '@/data/EIP155Data'
import SettingsStore from '@/store/SettingsStore'
import { wallet } from '@/utils/WalletUtil'
import { Text } from '@nextui-org/react'
import { Fragment } from 'react'
import { useSnapshot } from 'valtio'
export default function HomePage() {
return <PageHeader>Accounts</PageHeader>
const { testNets } = useSnapshot(SettingsStore.state)
return (
<Fragment>
<PageHeader>Accounts</PageHeader>
<Text h4 css={{ marginBottom: '$5' }}>
Mainnets
</Text>
{Object.values(EIP155_MAINNET_CHAINS).map(({ name, logo, rgb }) => (
<AccountCard key={name} name={name} logo={logo} rgb={rgb} address={wallet.address} />
))}
{testNets ? (
<Fragment>
<Text h4 css={{ marginBottom: '$5' }}>
Testnets
</Text>
{Object.values(EIP155_TEST_CHAINS).map(({ name, logo, rgb }) => (
<AccountCard key={name} name={name} logo={logo} rgb={rgb} address={wallet.address} />
))}
</Fragment>
) : null}
</Fragment>
)
}
@@ -0,0 +1,20 @@
import PageHeader from '@/components/PageHeader'
import { truncate } from '@/utils/HelperUtil'
import { walletConnectClient } from '@/utils/WalletConnectUtil'
import { useRouter } from 'next/router'
import { Fragment, useEffect } from 'react'
export default function SessionsPage() {
const { query } = useRouter()
const address = (query?.address as string) ?? 'Unknown'
useEffect(() => {
console.log(walletConnectClient.session.values)
}, [])
return (
<Fragment>
<PageHeader>{truncate(address, 15)}</PageHeader>
</Fragment>
)
}
@@ -0,0 +1,50 @@
import PageHeader from '@/components/PageHeader'
import SettingsStore from '@/store/SettingsStore'
import { wallet } from '@/utils/WalletUtil'
import { Card, Divider, Row, Switch, Text, useTheme } from '@nextui-org/react'
import { useTheme as useNextTheme } from 'next-themes'
import { Fragment } from 'react'
import { useSnapshot } from 'valtio'
export default function SettingsPage() {
const { setTheme } = useNextTheme()
const { isDark, type } = useTheme()
const { testNets } = useSnapshot(SettingsStore.state)
return (
<Fragment>
<PageHeader>Settings</PageHeader>
<Text h4 css={{ marginBottom: '$5' }}>
Mnemonic
</Text>
<Card bordered borderWeight="light" css={{ minHeight: '75px' }}>
<Text css={{ fontFamily: '$mono' }}>{wallet.mnemonic.phrase}</Text>
</Card>
<Text css={{ color: '$yellow500', marginTop: '$5', textAlign: 'center' }}>
Warning: mnemonic is provided for development purposes only and should not be used
elsewhere!
</Text>
<Divider y={3} />
<Text h4 css={{ marginBottom: '$5' }}>
Testnets
</Text>
<Row justify="space-between" align="center">
<Switch checked={testNets} onChange={SettingsStore.toggleTestNets} />
<Text>{testNets ? 'Enabled' : 'Disabled'}</Text>
</Row>
<Divider y={3} />
<Text h4 css={{ marginBottom: '$5' }}>
Theme
</Text>
<Row justify="space-between" align="center">
<Switch checked={isDark} onChange={e => setTheme(e.target.checked ? 'dark' : 'light')} />
<Text>{type}</Text>
</Row>
</Fragment>
)
}
@@ -0,0 +1,52 @@
import PageHeader from '@/components/PageHeader'
import QrReader from '@/components/QrReader'
import { walletConnectClient } from '@/utils/WalletConnectUtil'
import { Button, Input, Loading, Text } from '@nextui-org/react'
import { Fragment, useState } from 'react'
export default function WalletConnectPage() {
const [uri, setUri] = useState('')
const [loading, setLoading] = useState(false)
async function onConnect(uri: string) {
try {
setLoading(true)
await walletConnectClient.pair({ uri })
} catch (err: unknown) {
alert(err)
} finally {
setUri('')
setLoading(false)
}
}
return (
<Fragment>
<PageHeader>WalletConnect</PageHeader>
<QrReader onConnect={onConnect} />
<Text size={13} css={{ textAlign: 'center', marginTop: '$10', marginBottom: '$10' }}>
or use walletconnect uri
</Text>
<Input
bordered
placeholder="e.g. wc:a281567bb3e4..."
onChange={e => setUri(e.target.value)}
value={uri}
contentRight={
<Button
size="xs"
disabled={!uri}
css={{ marginLeft: -60 }}
onClick={() => onConnect(uri)}
color="gradient"
>
{loading ? <Loading size="sm" /> : 'Connect'}
</Button>
}
/>
</Fragment>
)
}
@@ -0,0 +1,44 @@
import { SessionTypes } from '@walletconnect/types'
import { proxy } from 'valtio'
/**
* Types
*/
interface ModalData {
proposal?: SessionTypes.Proposal
created?: SessionTypes.Created
requestEvent?: SessionTypes.RequestEvent
requestSession?: SessionTypes.Settled
}
interface State {
open: boolean
view?: 'SessionProposalModal' | 'SessionSignModal' | 'SessionSignTypedDataModal'
data?: ModalData
}
/**
* State
*/
const state = proxy<State>({
open: false
})
/**
* Store / Actions
*/
const ModalStore = {
state,
open(view: State['view'], data: State['data']) {
state.view = view
state.data = data
state.open = true
},
close() {
state.open = false
}
}
export default ModalStore
@@ -0,0 +1,33 @@
import { proxy } from 'valtio'
/**
* Types
*/
interface State {
testNets: boolean
}
/**
* State
*/
const state = proxy<State>({
testNets: Boolean(localStorage.getItem('TEST_NETS')) ?? false
})
/**
* Store / Actions
*/
const SettingsStore = {
state,
toggleTestNets() {
state.testNets = !state.testNets
if (state.testNets) {
localStorage.setItem('TEST_NETS', 'YES')
} else {
localStorage.removeItem('TEST_NETS')
}
}
}
export default SettingsStore
@@ -0,0 +1,54 @@
import { utils } from 'ethers'
/**
* Truncates string (in the middle) via given lenght value
*/
export function truncate(value: string, length: number) {
if (value.length <= length) {
return value
}
const separator = '...'
const stringLength = length - separator.length
const frontLength = Math.ceil(stringLength / 2)
const backLength = Math.floor(stringLength / 2)
return value.substring(0, frontLength) + separator + value.substring(value.length - backLength)
}
/**
* Converts hex to utf8 string if it is valid bytes
*/
export function convertHexToUtf8(value: string) {
if (utils.isHexString(value)) {
return utils.toUtf8String(value)
}
return value
}
/**
* Gets message from various signing request methods by filtering out
* a value that is not an address (thus is a message).
* If it is a hex string, it gets converted to utf8 string
*/
export function getSignParamsMessage(params: string[]) {
const message = params.filter(p => !utils.isAddress(p))[0]
return convertHexToUtf8(message)
}
/**
* Gets data from various signTypedData request methods by filtering out
* a value that is not an address (thus is data).
* If data is a string convert it to object
*/
export function getSignTypedDataParamsData(params: string[]) {
const data = params.filter(p => !utils.isAddress(p))[0]
if (typeof data === 'string') {
return JSON.parse(data)
}
return data
}
@@ -0,0 +1,47 @@
import { EIP155_SIGNING_METHODS } from '@/data/EIP155Data'
import { getSignParamsMessage, getSignTypedDataParamsData } from '@/utils/HelperUtil'
import { formatJsonRpcError, formatJsonRpcResult } from '@json-rpc-tools/utils'
import { RequestEvent } from '@walletconnect/types'
import { ERROR } from '@walletconnect/utils'
import { Wallet } from 'ethers'
export async function approveEIP155Request(request: RequestEvent['request'], wallet: Wallet) {
const { method, params, id } = request
switch (method) {
/**
* Handle message signing requests
*/
case EIP155_SIGNING_METHODS.PERSONAL_SIGN:
case EIP155_SIGNING_METHODS.ETH_SIGN:
const message = getSignParamsMessage(params)
const signedMessage = await wallet.signMessage(message)
return formatJsonRpcResult(id, signedMessage)
/**
* Handle data signing requests
*/
case EIP155_SIGNING_METHODS.ETH_SIGN_TYPED_DATA:
case EIP155_SIGNING_METHODS.ETH_SIGN_TYPED_DATA_V3:
case EIP155_SIGNING_METHODS.ETH_SIGN_TYPED_DATA_V4:
const { domain, types, message: data } = getSignTypedDataParamsData(params)
// https://github.com/ethers-io/ethers.js/issues/687#issuecomment-714069471
delete types.EIP712Domain
const signedData = await wallet._signTypedData(domain, types, data)
return formatJsonRpcResult(id, signedData)
/**
* Handle unsuported methods
*/
default:
throw new Error(ERROR.UNKNOWN_JSONRPC_METHOD.format().message)
}
}
export function rejectEIP155Request(request: RequestEvent['request']) {
const { id } = request
return formatJsonRpcError(id, ERROR.JSONRPC_REQUEST_METHOD_REJECTED.format().message)
}
@@ -1,5 +1,5 @@
import { createTheme } from '@nextui-org/react'
export const theme = createTheme({
type: 'dark'
})
export const darkTheme = createTheme({ type: 'dark' })
export const lightTheme = createTheme({ type: 'light' })
@@ -0,0 +1,17 @@
import WalletConnectClient from '@walletconnect/client'
export let walletConnectClient: WalletConnectClient
export async function createWalletConnectClient() {
walletConnectClient = await WalletConnectClient.init({
controller: true,
projectId: '8f331b9812e0e5b8f2da2c7203624869',
relayUrl: 'wss://relay.walletconnect.com',
metadata: {
name: 'React Wallet',
description: 'React Wallet for WalletConnect',
url: 'https://walletconnect.com/',
icons: ['https://avatars.githubusercontent.com/u/37784886']
}
})
}
@@ -0,0 +1,15 @@
import { Wallet } from 'ethers'
export let wallet: Wallet
export function createOrRestoreWallet() {
const mnemonic = localStorage.getItem('WALLET_MNEMONIC')
if (mnemonic) {
wallet = Wallet.fromMnemonic(mnemonic)
} else {
wallet = Wallet.createRandom()
// Don't store mnemonic in local storage in a production project!
localStorage.setItem('WALLET_MNEMONIC', wallet.mnemonic.phrase)
}
}
@@ -0,0 +1,106 @@
import { EIP155_CHAINS, TEIP155Chain } from '@/data/EIP155Data'
import ModalStore from '@/store/ModalStore'
import { walletConnectClient } from '@/utils/WalletConnectUtil'
import { wallet } from '@/utils/WalletUtil'
import { Avatar, Button, Col, Container, Divider, Link, Modal, Row, Text } from '@nextui-org/react'
import { Fragment } from 'react'
export default function SessionProposalModal() {
// Get proposal data and wallet address from store
const proposal = ModalStore.state.data?.proposal
// Ensure proposal is defined
if (!proposal) {
return <Text>Missing proposal data</Text>
}
// Get required proposal data
const { proposer, permissions, relay } = proposal
const { icons, name, url } = proposer.metadata
const { chains } = permissions.blockchain
const { methods } = permissions.jsonrpc
const { protocol } = relay
// Hanlde approve action
async function onApprove() {
if (proposal) {
const response = {
state: {
accounts: chains.map(chain => `${chain}:${wallet.address}`)
}
}
await walletConnectClient.approve({ proposal, response })
}
ModalStore.close()
}
// Hanlde reject action
async function onReject() {
if (proposal) {
await walletConnectClient.reject({ proposal })
}
ModalStore.close()
}
return (
<Fragment>
<Modal.Header>
<Text h3>Session Proposal</Text>
</Modal.Header>
<Modal.Body>
<Container css={{ padding: 0 }}>
<Row align="center">
<Col span={3}>
<Avatar src={icons[0]} />
</Col>
<Col span={14}>
<Text h5>{name}</Text>
<Link href={url}>{url}</Link>
</Col>
</Row>
<Divider y={2} />
<Row>
<Col>
<Text h5>Blockchains</Text>
<Text color="$gray400">
{chains
.map(chain => EIP155_CHAINS[chain as TEIP155Chain]?.name ?? chain)
.join(', ')}
</Text>
</Col>
</Row>
<Divider y={2} />
<Row>
<Col>
<Text h5>Methods</Text>
<Text color="$gray400">{methods.map(method => method).join(', ')}</Text>
</Col>
</Row>
<Divider y={2} />
<Row>
<Col>
<Text h5>Relay Protocol</Text>
<Text color="$gray400">{protocol}</Text>
</Col>
</Row>
</Container>
</Modal.Body>
<Modal.Footer>
<Button auto flat color="error" onClick={onReject}>
Reject
</Button>
<Button auto flat color="success" onClick={onApprove}>
Approve
</Button>
</Modal.Footer>
</Fragment>
)
}
@@ -0,0 +1,121 @@
import { EIP155_CHAINS, TEIP155Chain } from '@/data/EIP155Data'
import ModalStore from '@/store/ModalStore'
import { getSignParamsMessage } from '@/utils/HelperUtil'
import { approveEIP155Request, rejectEIP155Request } from '@/utils/RequestHandlerUtil'
import { walletConnectClient } from '@/utils/WalletConnectUtil'
import { wallet } from '@/utils/WalletUtil'
import { Avatar, Button, Col, Container, Divider, Link, Modal, Row, Text } from '@nextui-org/react'
import { Fragment } from 'react'
export default function SessionSignModal() {
// Get request and wallet data from store
const requestEvent = ModalStore.state.data?.requestEvent
const requestSession = ModalStore.state.data?.requestSession
// Ensure request and wallet are defined
if (!requestEvent || !requestSession) {
return <Text>Missing request data</Text>
}
// Get required request data
const { chainId } = requestEvent
const { method, params } = requestEvent.request
const { protocol } = requestSession.relay
const { name, icons, url } = requestSession.peer.metadata
// Get message, convert it to UTF8 string if it is valid hex
const message = getSignParamsMessage(params)
// Handle approve action (logic varies based on request method)
async function onApprove() {
if (requestEvent) {
const response = await approveEIP155Request(requestEvent.request, wallet)
await walletConnectClient.respond({
topic: requestEvent.topic,
response
})
ModalStore.close()
}
}
// Handle reject action
async function onReject() {
if (requestEvent) {
const response = rejectEIP155Request(requestEvent.request)
await walletConnectClient.respond({
topic: requestEvent.topic,
response
})
ModalStore.close()
}
}
return (
<Fragment>
<Modal.Header>
<Text h3>Sign Message</Text>
</Modal.Header>
<Modal.Body>
<Container css={{ padding: 0 }}>
<Row align="center">
<Col span={3}>
<Avatar src={icons[0]} />
</Col>
<Col span={14}>
<Text h5>{name}</Text>
<Link href={url}>{url}</Link>
</Col>
</Row>
<Divider y={2} />
<Row>
<Col>
<Text h5>Blockchain</Text>
<Text color="$gray400">
{EIP155_CHAINS[chainId as TEIP155Chain]?.name ?? chainId}
</Text>
</Col>
</Row>
<Divider y={2} />
<Row>
<Col>
<Text h5>Message</Text>
<Text color="$gray400">{message}</Text>
</Col>
</Row>
<Divider y={2} />
<Row>
<Col>
<Text h5>Method</Text>
<Text color="$gray400">{method}</Text>
</Col>
</Row>
<Divider y={2} />
<Row>
<Col>
<Text h5>Relay Protocol</Text>
<Text color="$gray400">{protocol}</Text>
</Col>
</Row>
</Container>
</Modal.Body>
<Modal.Footer>
<Button auto flat color="error" onClick={onReject}>
Reject
</Button>
<Button auto flat color="success" onClick={onApprove}>
Approve
</Button>
</Modal.Footer>
</Fragment>
)
}
@@ -0,0 +1,155 @@
import { EIP155_CHAINS, TEIP155Chain } from '@/data/EIP155Data'
import ModalStore from '@/store/ModalStore'
import { getSignTypedDataParamsData } from '@/utils/HelperUtil'
import { approveEIP155Request, rejectEIP155Request } from '@/utils/RequestHandlerUtil'
import { walletConnectClient } from '@/utils/WalletConnectUtil'
import { wallet } from '@/utils/WalletUtil'
import { Avatar, Button, Col, Container, Divider, Link, Modal, Row, Text } from '@nextui-org/react'
import { Fragment } from 'react'
import { CodeBlock, codepen } from 'react-code-blocks'
export default function SessionSignTypedDataModal() {
// Get request and wallet data from store
const requestEvent = ModalStore.state.data?.requestEvent
const requestSession = ModalStore.state.data?.requestSession
// Ensure request and wallet are defined
if (!requestEvent || !requestSession) {
return <Text>Missing request data</Text>
}
// Get required request data
const { chainId } = requestEvent
const { method, params } = requestEvent.request
const { protocol } = requestSession.relay
const { name, icons, url } = requestSession.peer.metadata
// Get data
const data = getSignTypedDataParamsData(params)
// Handle approve action (logic varies based on request method)
async function onApprove() {
if (requestEvent) {
const response = await approveEIP155Request(requestEvent.request, wallet)
await walletConnectClient.respond({
topic: requestEvent.topic,
response
})
ModalStore.close()
}
}
// Handle reject action
async function onReject() {
if (requestEvent) {
const response = rejectEIP155Request(requestEvent.request)
await walletConnectClient.respond({
topic: requestEvent.topic,
response
})
ModalStore.close()
}
}
return (
<Fragment>
<Modal.Header>
<Text h3>Sign Typed Data</Text>
</Modal.Header>
<Modal.Body>
<Container css={{ padding: 0 }}>
<Row align="center">
<Col span={3}>
<Avatar src={icons[0]} />
</Col>
<Col span={14}>
<Text h5>{name}</Text>
<Link href={url}>{url}</Link>
</Col>
</Row>
<Divider y={2} />
<Row>
<Col>
<Text h5>Blockchain</Text>
<Text color="$gray400">
{EIP155_CHAINS[chainId as TEIP155Chain]?.name ?? chainId}
</Text>
</Col>
</Row>
<Divider y={2} />
<Row>
<Col className="codeBlock">
<Text h5>Domain</Text>
<CodeBlock
showLineNumbers={false}
text={JSON.stringify(data.domain, null, 2)}
theme={codepen}
language="json"
/>
</Col>
</Row>
<Divider y={2} />
<Row>
<Col className="codeBlock">
<Text h5>Types</Text>
<CodeBlock
showLineNumbers={false}
text={JSON.stringify(data.types, null, 2)}
theme={codepen}
language="json"
/>
</Col>
</Row>
<Divider y={2} />
<Row>
<Col className="codeBlock">
<Text h5>Message</Text>
<CodeBlock
showLineNumbers={false}
text={JSON.stringify(data.message, null, 2)}
theme={codepen}
language="json"
/>
</Col>
</Row>
<Divider y={2} />
<Row>
<Col>
<Text h5>Method</Text>
<Text color="$gray400">{method}</Text>
</Col>
</Row>
<Divider y={2} />
<Row>
<Col>
<Text h5>Relay Protocol</Text>
<Text color="$gray400">{protocol}</Text>
</Col>
</Row>
</Container>
</Modal.Body>
<Modal.Footer>
<Button auto flat color="error" onClick={onReject}>
Reject
</Button>
<Button auto flat color="success" onClick={onApprove}>
Approve
</Button>
</Modal.Footer>
</Fragment>
)
}
+1 -1
View File
@@ -8,7 +8,7 @@
],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"incremental": true,
File diff suppressed because it is too large. Load diff