fix: build
This commit is contained in:
parent
23b2959d9b
commit
f4384a2d3d
|
@ -176,11 +176,6 @@ const BottomMenu: FC<Props> = ({ className }) => {
|
|||
<button
|
||||
disabled={isWelcoming}
|
||||
className="bg-purple-500 p-1 h-7 rounded hover:bg-purple-400 disabled:hover:bg-purple-500 shadow-lg disabled:cursor-default"
|
||||
onClick={() =>
|
||||
computeWorkAsync(
|
||||
account?.frontier ?? account?.publicKey ?? ''
|
||||
).then(console.log)
|
||||
}
|
||||
>
|
||||
<RssIcon className="h-full text-purple-50 dark:text-gray-900" />
|
||||
</button>
|
||||
|
|
|
@ -29,9 +29,7 @@ const mockAddressBook: Record<string, { displayName: string }> = {
|
|||
}
|
||||
|
||||
const RecentTransactions: FC<Props> = ({ className }) => {
|
||||
const account = useAccount()
|
||||
|
||||
const receiveNano = useReceiveNano()
|
||||
const { receive } = useReceiveNano()
|
||||
|
||||
return (
|
||||
<div className={clsx('flex flex-col gap-6 w-full', className)}>
|
||||
|
@ -62,7 +60,7 @@ const RecentTransactions: FC<Props> = ({ className }) => {
|
|||
>
|
||||
<button
|
||||
className="contents"
|
||||
onClick={() => receiveNano(txn.hash, txn.amount)}
|
||||
onClick={() => receive(txn.hash, txn.amount)}
|
||||
>
|
||||
{txn.send ? (
|
||||
<UploadIcon className="w-6 text-yellow-500 flex-shrink-0" />
|
||||
|
|
|
@ -23,7 +23,7 @@ export const registerBiometrics = async () => {
|
|||
},
|
||||
],
|
||||
timeout: 30000,
|
||||
challenge: challenge,
|
||||
challenge: challenge.cryptoAsset,
|
||||
attestation: 'direct',
|
||||
authenticatorSelection: {
|
||||
authenticatorAttachment: 'platform',
|
||||
|
@ -62,10 +62,10 @@ export const checkBiometrics = async () => {
|
|||
const getCredentialParams: CredentialRequestOptions = {
|
||||
publicKey: {
|
||||
timeout: 60000,
|
||||
challenge: challenge,
|
||||
challenge: challenge.cryptoAsset,
|
||||
allowCredentials: [
|
||||
{
|
||||
id: credentialId,
|
||||
id: credentialId.cryptoAsset,
|
||||
transports: ['internal'] as AuthenticatorTransport[],
|
||||
type: 'public-key' as 'public-key',
|
||||
},
|
||||
|
|
|
@ -9,9 +9,10 @@ const decryptSeed = async (id: 'os' | 'pin') => {
|
|||
// @ts-expect-error
|
||||
response: { signature: sig },
|
||||
} = await checkBiometrics()
|
||||
const decryptedSeed = AES.decrypt(encryptedSeed!, sig.toString()).toString(
|
||||
enc.Utf8
|
||||
)
|
||||
const decryptedSeed = AES.decrypt(
|
||||
encryptedSeed!.encryptedSeed,
|
||||
sig.toString()
|
||||
).toString(enc.Utf8)
|
||||
return decryptedSeed
|
||||
}
|
||||
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
import { useEffect, useState } from 'react'
|
||||
|
||||
const useMounted = () => {
|
||||
const [mounted, setMounted] = useState(false)
|
||||
useEffect(() => {
|
||||
setMounted(true)
|
||||
}, [])
|
||||
return mounted
|
||||
}
|
||||
|
||||
export default useMounted
|
|
@ -1,5 +1,5 @@
|
|||
import { computeWork, hashBlock } from 'nanocurrency'
|
||||
import { useCallback } from 'react'
|
||||
import { useCallback, useState } from 'react'
|
||||
|
||||
import computeWorkAsync from '../computeWorkAsync'
|
||||
import { useAccount } from '../context/accountContext'
|
||||
|
@ -10,15 +10,20 @@ import receiveNano from '../xno/receiveNano'
|
|||
|
||||
const useReceiveNano = () => {
|
||||
const account = useAccount()
|
||||
const [generatingWork, setGeneratingWork] = useState(false)
|
||||
|
||||
const receive = useCallback(
|
||||
async (hash: string, amount: string) => {
|
||||
if (account === undefined) return
|
||||
let precomputedWork = await getPrecomputedWork(account.address)
|
||||
if (precomputedWork === null)
|
||||
if (precomputedWork === null) {
|
||||
setGeneratingWork(true)
|
||||
precomputedWork = await computeWorkAsync(
|
||||
account.frontier ?? account.address
|
||||
account.frontier ?? account.address,
|
||||
{ send: false }
|
||||
)
|
||||
setGeneratingWork(false)
|
||||
}
|
||||
if (precomputedWork === null) throw new Error('couldnt_compute_work')
|
||||
await receiveNano(
|
||||
{
|
||||
|
@ -36,7 +41,7 @@ const useReceiveNano = () => {
|
|||
[account]
|
||||
)
|
||||
|
||||
return receive
|
||||
return { receive, generatingWork }
|
||||
}
|
||||
|
||||
export default useReceiveNano
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { hashBlock } from 'nanocurrency'
|
||||
import { useCallback } from 'react'
|
||||
import { useCallback, useState } from 'react'
|
||||
|
||||
import computeWorkAsync from '../computeWorkAsync'
|
||||
import { useAccount } from '../context/accountContext'
|
||||
|
@ -12,6 +12,7 @@ import sendNano from '../xno/sendNano'
|
|||
|
||||
const useSendNano = () => {
|
||||
const account = useAccount()
|
||||
const [generatingWork, setGeneratingWork] = useState(false)
|
||||
|
||||
const send = useCallback(
|
||||
async (to: string, amount: string) => {
|
||||
|
@ -22,7 +23,17 @@ const useSendNano = () => {
|
|||
account.frontier === null
|
||||
)
|
||||
throw new Error('wrong_block_data') // todo improve this error
|
||||
const signedBlock = await sendNano(
|
||||
let precomputedWork = await getPrecomputedWork(account.address)
|
||||
if (precomputedWork === null) {
|
||||
setGeneratingWork(true)
|
||||
precomputedWork = await computeWorkAsync(
|
||||
account.frontier ?? account.address,
|
||||
{ send: true }
|
||||
)
|
||||
setGeneratingWork(false)
|
||||
}
|
||||
if (precomputedWork === null) throw new Error('couldnt_compute_work')
|
||||
await sendNano(
|
||||
{
|
||||
walletBalanceRaw: account.balance,
|
||||
fromAddress: account.address,
|
||||
|
@ -30,7 +41,7 @@ const useSendNano = () => {
|
|||
representativeAddress: account.representative,
|
||||
frontier: account.frontier,
|
||||
amountRaw: amount,
|
||||
work: (await getPrecomputedWork(account.address)) ?? undefined,
|
||||
work: precomputedWork,
|
||||
},
|
||||
account.index
|
||||
)
|
||||
|
@ -38,7 +49,7 @@ const useSendNano = () => {
|
|||
[account]
|
||||
)
|
||||
|
||||
return send
|
||||
return { send, generatingWork }
|
||||
}
|
||||
|
||||
export default useSendNano
|
||||
|
|
|
@ -1,37 +0,0 @@
|
|||
import { useCallback, useState } from 'react'
|
||||
|
||||
import { getAccount, putAccount } from '../db/accounts'
|
||||
import fetchAccountInfo from '../nano/fetchAccountInfo'
|
||||
import { AccountInfoCache } from '../types'
|
||||
import useSetup from './useSetup'
|
||||
|
||||
const useSetupAccounts = (skip?: boolean) => {
|
||||
const [accounts, setAccounts] = useState<
|
||||
{ [key: number]: AccountInfoCache } | undefined
|
||||
>(undefined)
|
||||
const setupAddress = useCallback(async () => {
|
||||
const dbAccount = await getAccount(0)
|
||||
if (dbAccount !== undefined) {
|
||||
setAccounts({ 0: dbAccount })
|
||||
const infoResponse = await fetchAccountInfo(dbAccount.address)
|
||||
|
||||
const freshAccountInfo = {
|
||||
...dbAccount,
|
||||
frontier:
|
||||
'error' in infoResponse ? null : infoResponse.confirmed_frontier,
|
||||
representative:
|
||||
'error' in infoResponse
|
||||
? null
|
||||
: infoResponse.confirmed_representative,
|
||||
balance:
|
||||
'error' in infoResponse ? null : infoResponse.confirmed_balance,
|
||||
}
|
||||
setAccounts({ 0: freshAccountInfo })
|
||||
putAccount(dbAccount.index, freshAccountInfo)
|
||||
}
|
||||
}, [setAccounts])
|
||||
const { settingUp } = useSetup(setupAddress, skip)
|
||||
return { accounts, settingUp }
|
||||
}
|
||||
|
||||
export default useSetupAccounts
|
|
@ -3,8 +3,9 @@ import { useRouter } from 'next/router'
|
|||
import { useCallback, useState } from 'react'
|
||||
|
||||
import { registerBiometrics } from '../biometrics'
|
||||
import computeWorkAsync from '../computeWorkAsync'
|
||||
import { useAccounts } from '../context/accountContext'
|
||||
import { addAccount } from '../db/accounts'
|
||||
import { addAccount, addPrecomputedWork } from '../db/accounts'
|
||||
import { addEncryptedSeed, hasEncryptedSeed } from '../db/encryptedSeeds'
|
||||
import encryptSeed from '../encryptSeed'
|
||||
import { AccountInfoCache } from '../types'
|
||||
|
@ -43,7 +44,14 @@ const useSetupSeed = (skip?: boolean) => {
|
|||
}
|
||||
setSeed({ seed: generatedSeed, mnemonic })
|
||||
setAccount(account)
|
||||
await addAccount(0, account)
|
||||
addAccount(0, account)
|
||||
|
||||
computeWorkAsync(address, { send: false }).then(work => {
|
||||
if (work !== null) {
|
||||
setAccount({ ...account, precomputedWork: work })
|
||||
addPrecomputedWork(address, work)
|
||||
}
|
||||
})
|
||||
} catch {}
|
||||
}, [replace, setAccount])
|
||||
|
||||
|
|
|
@ -57,9 +57,9 @@
|
|||
},
|
||||
"browserslist": {
|
||||
"production": [
|
||||
">0.2%",
|
||||
"not dead",
|
||||
"not op_mini all"
|
||||
"last 3 chrome version",
|
||||
"last 3 firefox version",
|
||||
"last 3 safari version"
|
||||
],
|
||||
"development": [
|
||||
"last 1 chrome version",
|
||||
|
|
|
@ -13,7 +13,7 @@ const Send: NextPage = () => {
|
|||
const hasAmount = amount !== undefined
|
||||
|
||||
const [xnoToSend, setXnoToSend] = useState('')
|
||||
const send = useSendNano()
|
||||
const { send } = useSendNano()
|
||||
|
||||
return (
|
||||
<div>
|
||||
|
|
Reference in a new issue