Skip to content

Commit

Permalink
chore: laboratory add siwx status (#3451)
Browse files Browse the repository at this point in the history
  • Loading branch information
zoruka authored Jan 23, 2025
1 parent 7113f4d commit 41f2849
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
44 changes: 44 additions & 0 deletions apps/laboratory/src/components/DefaultSIWXStatus.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
'use client'

import { useEffect, useState } from 'react'

import { Card, CardHeader, Code, Heading, Text } from '@chakra-ui/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
Expand Up @@ -5,9 +5,13 @@ import { EthersAdapter } from '@reown/appkit-adapter-ethers'
import { SolanaAdapter } from '@reown/appkit-adapter-solana'
import { DefaultSIWX } from '@reown/appkit-siwx'
import { mainnet } from '@reown/appkit/networks'
import { createAppKit } from '@reown/appkit/react'
import { createAppKit, useAppKitNetwork } from '@reown/appkit/react'

import { AppKitButtons } from '../../components/AppKitButtons'
import { BitcoinTests } from '../../components/Bitcoin/BitcoinTests'
import { DefaultSIWXStatus } from '../../components/DefaultSIWXStatus'
import { EthersTests } from '../../components/Ethers/EthersTests'
import { SolanaTests } from '../../components/Solana/SolanaTests'
import { ConstantsUtil } from '../../utils/ConstantsUtil'
import { ThemeStore } from '../../utils/StoreUtil'

Expand Down Expand Up @@ -38,9 +42,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 />}
</>
)
}

0 comments on commit 41f2849

Please sign in to comment.