Newer
Older
import React, { useEffect, useState } from 'react'
import { createAccountExternal } from '../../messaging/uiActions'
cancelAndGoHomeHeaderAction,
doneAndGoHomeHeaderAction,
import { Address } from '../components/Address'
import { H1 } from '../components/H1'
interface QrAccount {
isAddress: boolean
content: string
genesisHash: string
name?: string
}
const [scanned, setScanned] = useState<QrAccount[]>([])
const onCreate = (account: QrAccount) => {
const alreadyScanned = scanned.find(
(a) =>
a.content === account.content && a.genesisHash === account.genesisHash
)
if (alreadyScanned) return
createAccountExternal(
account.name || 'Unknown',
account.content,
account.genesisHash
)
.then(() => setScanned((s) => [...s, account]))
.catch(console.error)
scanned.length === 0
? addHeaderAction(cancelAndGoHomeHeaderAction)
: addHeaderAction(doneAndGoHomeHeaderAction)
<div className='flex flex-col'>
<div className='flex w-full mb-4'>
<div className='flex flex-col basis-1/2 justify-between'>
<H1>
<span className='block text-6xl leading-none'>
{scanned.length}
</span>
<div className='flex flex-col basis-1/2 border-8 rounded'>
<QrScanAddress onScan={onCreate} />
</div>
</div>
{scanned.reverse().map((account) => (
<Address
{...account}
address={account.content}
name={account.name}
key={account.content}
/>
))}
</div>