Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: laboratory add siwx status #3451

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions apps/laboratory/src/components/DefaultSIWXStatus.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
'use client'

import { Card, CardHeader, Code, Heading, Text } from '@chakra-ui/react'
import { useEffect, useState } from 'react'

export interface DefaultSIWXStatusProps {
localStorageKey?: string
}

export function DefaultSIWXStatus({ localStorageKey = '@appkit/siwx' }: DefaultSIWXStatusProps) {
const [status, setStatus] = useState('')

useEffect(() => {
const interval = setInterval(() => {
const newStatus = localStorage.getItem(localStorageKey) || ''
if (newStatus !== status) {
setStatus(newStatus)
}
}, 1000)

return () => {
clearInterval(interval)
}
}, [])

if (!status) {
return null
}

return (
<Card marginTop={10} marginBottom={10}>
<CardHeader>
<Heading size="md">SIWX Status</Heading>
</CardHeader>

<Text mx="4">Below is shown the data stored for SIWX sessions:</Text>

<Code m="4" maxH="64" whiteSpace="pre" overflow="auto" variant="outline">
{JSON.stringify(JSON.parse(status), null, 2)}
</Code>
</Card>
)
}
13 changes: 12 additions & 1 deletion apps/laboratory/src/pages/library/siwx-default.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createAppKit } from '@reown/appkit/react'
import { createAppKit, useAppKitNetwork } from '@reown/appkit/react'
import { EthersAdapter } from '@reown/appkit-adapter-ethers'
import { SolanaAdapter } from '@reown/appkit-adapter-solana'
import { ThemeStore } from '../../utils/StoreUtil'
Expand All @@ -9,6 +9,10 @@ import { HuobiWalletAdapter, SolflareWalletAdapter } from '@solana/wallet-adapte
import { mainnet } from '@reown/appkit/networks'
import { DefaultSIWX } from '@reown/appkit-siwx'
import { BitcoinAdapter } from '@reown/appkit-adapter-bitcoin'
import { DefaultSIWXStatus } from '../../components/DefaultSIWXStatus'
import { EthersTests } from '../../components/Ethers/EthersTests'
import { SolanaTests } from '../../components/Solana/SolanaTests'
import { BitcoinTests } from '../../components/Bitcoin/BitcoinTests'

const networks = ConstantsUtil.AllNetworks
networks.push(...ConstantsUtil.BitcoinNetworks)
Expand Down Expand Up @@ -37,9 +41,16 @@ const modal = createAppKit({
ThemeStore.setModal(modal)

export default function SIWXDefault() {
const { caipNetwork } = useAppKitNetwork()

return (
<>
<AppKitButtons />
<DefaultSIWXStatus />

{caipNetwork?.chainNamespace === 'eip155' && <EthersTests />}
{caipNetwork?.chainNamespace === 'solana' && <SolanaTests />}
{caipNetwork?.chainNamespace === 'bip122' && <BitcoinTests />}
</>
)
}
Loading