This commit is contained in:
Filipe Medeiros 2021-11-29 20:31:08 +00:00
parent fc94b6e27e
commit 2c6adbd244
4 changed files with 18 additions and 4 deletions

View file

@ -1,4 +1,5 @@
import Big from 'bignumber.js'
import { validateWork } from 'nanocurrency'
import { useCallback, useState } from 'react'
import computeWorkAsync from '../computeWorkAsync'
@ -16,7 +17,13 @@ const useReceiveNano = () => {
async (hash: string, amount: string) => {
if (account === undefined) return
let precomputedWork = await getPrecomputedWork(account.address)
if (precomputedWork === null) {
const isWorkValid =
precomputedWork !== null &&
validateWork({
work: precomputedWork,
blockHash: account.frontier ?? account.publicKey,
})
if (!isWorkValid) {
setGeneratingWork(true)
precomputedWork = await computeWorkAsync(
account.frontier ?? account.publicKey,

View file

@ -1,4 +1,5 @@
import Big from 'bignumber.js'
import { validateWork } from 'nanocurrency'
import { useCallback, useState } from 'react'
import computeWorkAsync from '../computeWorkAsync'
@ -21,7 +22,13 @@ const useSendNano = () => {
)
throw new Error('wrong_block_data') // todo improve this error
let precomputedWork = await getPrecomputedWork(account.address)
if (precomputedWork === null) {
const isWorkValid =
precomputedWork !== null &&
validateWork({
work: precomputedWork,
blockHash: account.frontier,
})
if (!isWorkValid) {
setGeneratingWork(true)
precomputedWork = await computeWorkAsync(
account.frontier ?? account.publicKey,

View file

@ -4,7 +4,7 @@ import useSetup from './useSetup'
const useSetupServiceWorker = (skip?: boolean) =>
useSetup(
useCallback(() => {
useCallback(async () => {
if ('serviceWorker' in navigator) {
try {
navigator.serviceWorker.register('/sw.js')

View file

@ -9,7 +9,7 @@
"noEmit": true,
"incremental": true,
"esModuleInterop": true,
"module": "esnext",
"module": "ESNext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,