Skip to content

Commit b27d5cb

Browse files
committed
fixed ts errors
1 parent 768d1f6 commit b27d5cb

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

src/components/Construct.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { UnpublishedConstructType } from "../types/Construct"
2+
import ConstructViewer from "./ConstructViewer"
23

34
type UnpublishedConstructProps = {
45
construct: UnpublishedConstructType
@@ -11,6 +12,7 @@ export const UnpublishedConstruct = ({ construct }: UnpublishedConstructProps) =
1112
<div className="construct" key={construct.id}>
1213
<h2>{ construct.workCompleted }pow</h2>
1314
<small>{ construct.id }</small>
15+
<ConstructViewer constructSize={construct.workCompleted} hexLocation={construct.id} />
1416
</div>
1517
)
1618
}

src/components/MinerController.tsx

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { IdentityContext } from "../providers/IdentityProvider"
55
import { MinerMessage, WORKER_COUNT, BATCH_SIZE, serializeEvent, getNonceBounds, calculateHashrate, convertNumberToUint8Array, MinerCommand } from "../libraries/Miner"
66
import { encoder, decoder, uint8ToHex } from "../libraries/Hash"
77
import Worker from '../workers/ConstructMiner.worker?worker'
8-
import { UnsignedEvent, getEventHash, validateEvent, verifySignature } from "nostr-tools"
8+
import { Event, UnsignedEvent, getEventHash, validateEvent, verifySignature } from "nostr-tools"
99
import { signEvent } from "../libraries/NIP-07"
1010
import { UnpublishedConstructType } from "../types/Construct"
1111
import { UnpublishedConstruct } from "./Construct"
@@ -25,7 +25,15 @@ type MinerProps = {
2525
targetWork: number
2626
}
2727

28-
const constructsReducer = (state, action) => {
28+
type ConstructsReducerState = {
29+
[key: string]: UnpublishedConstructType
30+
}
31+
type ConstructsReducerAction = {
32+
type: 'add',
33+
construct: UnpublishedConstructType
34+
}
35+
36+
const constructsReducer = (state: ConstructsReducerState, action: ConstructsReducerAction) => {
2937
switch(action.type) {
3038
case 'add':
3139
return {
@@ -63,7 +71,7 @@ export const Miner = ({targetHex, targetWork}: MinerProps) => {
6371
useEffect(() => {
6472
const storedConstructs = localStorage.getItem('constructs')
6573
if (storedConstructs) {
66-
const parsedConstructs = JSON.parse(storedConstructs)
74+
const parsedConstructs = JSON.parse(storedConstructs) as {[key: string]: UnpublishedConstructType}
6775
Object.keys(parsedConstructs).forEach(key => {
6876
constructsDispatch({type: 'add', construct: parsedConstructs[key]})
6977
})
@@ -120,12 +128,14 @@ export const Miner = ({targetHex, targetWork}: MinerProps) => {
120128
work,
121129
} = msg.data
122130

131+
const eventWithID = event as Event<37515>
132+
123133
const decoded = JSON.parse(decoder.decode(binaryEvent))
124-
event.tags[0][1] = decoded[4][0][1]
134+
eventWithID.tags[0][1] = decoded[4][0][1]
125135
const id = bytesToHex(hash)
126-
event.id = id
127-
console.log(work, event)
128-
if (!validateEvent(event)){
136+
eventWithID.id = id
137+
console.log(work, eventWithID)
138+
if (!validateEvent(eventWithID)){
129139
// console.log()
130140
throw new Error('invalid event')
131141
}
@@ -138,7 +148,7 @@ export const Miner = ({targetHex, targetWork}: MinerProps) => {
138148
// all good
139149

140150
const construct: UnpublishedConstructType = {
141-
readyForSignature: event,
151+
readyForSignature: eventWithID,
142152
workCompleted: work,
143153
createdAt,
144154
id,

0 commit comments

Comments
 (0)