diff --git a/src/components/MeritRequests.svelte b/src/components/MeritRequests.svelte index 2819213..9148347 100644 --- a/src/components/MeritRequests.svelte +++ b/src/components/MeritRequests.svelte @@ -58,7 +58,7 @@ {#each $merits as [id, merit], _ (id)} { - console.log(merit.Request.rawEvent()); + console.log(merit.Event.rawEvent()); goto(`${base}/rockets/merits/${merit.ID}`); }} class="cursor-pointer bg-accent" diff --git a/src/components/MeritSummaryCard.svelte b/src/components/MeritSummaryCard.svelte index 710d788..66a87db 100644 --- a/src/components/MeritSummaryCard.svelte +++ b/src/components/MeritSummaryCard.svelte @@ -1,38 +1,49 @@ - +
Problem: {merit.Problem().substring(0, 20)}{#if merit.Solution()} -
{#if merit.Problem().length > 20}{merit.Problem()}{/if} @@ -76,17 +87,52 @@
Analysis
- A competent freelance developer earns $70 CuckLoserBucks an hour (on average). Using this rate, the contributor is claiming to have spent about {merit.Sats/1000} hours working on this. + A competent freelance developer earns $70 CuckLoserBucks an hour (on average). Using + this rate, the contributor is claiming to have spent about {merit.Sats / 1000} hours working + on this.
Reference Time
-
{merit.Sats/1000} hours
+
{merit.Sats / 1000} hours
- - - + +
Votes
+ + + {#each $votes as [id, vote], _ (id)} + { + console.log(vote.Event.rawEvent()); + goto(`${base}/rockets/merits/${vote.ID}`); + }} + class="cursor-pointer {vote.VoteDirection == "ratify"?"bg-lime-600":"bg-red-700"} " + > + +
+ + +
+
+ + {unixToRelativeTime(vote.TimeStamp * 1000)} +
+ {/each} +
+
+
diff --git a/src/lib/event_helpers/merits.ts b/src/lib/event_helpers/merits.ts index 03ef26c..8af738a 100644 --- a/src/lib/event_helpers/merits.ts +++ b/src/lib/event_helpers/merits.ts @@ -1,31 +1,31 @@ -import type { NDKEvent, NDKFilter } from '@nostr-dev-kit/ndk'; +import type { NDKEvent, NDKFilter, NDKTag } from '@nostr-dev-kit/ndk'; import { getNumberFromTag, isValidUrl } from './rockets'; export class MeritRequest { ID: string; Sats: number; Merits: number; - Request: NDKEvent; + Event: NDKEvent; Pubkey: string; TimeStamp: number; RocketTag: string | undefined; //31108:: Problem(): string { let _problem = ''; //todo: handle 1971 problem tracker event tags somehow - for (let problem of this.Request.getMatchingTags('problem')) { + for (let problem of this.Event.getMatchingTags('problem')) { if (problem && problem.length > 2) { _problem = problem[2]; } } return _problem; } - Solution(): URL|undefined { - let _solution:URL|undefined = undefined; - for (let solution of this.Request.getMatchingTags('solution')) { - if (solution && solution.length > 2 && solution[1] == "url") { + Solution(): URL | undefined { + let _solution: URL | undefined = undefined; + for (let solution of this.Event.getMatchingTags('solution')) { + if (solution && solution.length > 2 && solution[1] == 'url') { if (isValidUrl(solution[2])) { - _solution = new URL(solution[2]) - } + _solution = new URL(solution[2]); + } } } return _solution; @@ -36,28 +36,40 @@ export class MeritRequest { BasicValidation(): boolean { //todo: make a ValidateAgainstRocket and check that pubkey is in WoT let valid = true; - if (!(this.ID.length == 64 && this.Merits > 0 && this.Pubkey.length == 64 && this.TimeStamp && this.RocketTag)) { - valid = false - } + if ( + !( + this.ID.length == 64 && + this.Merits > 0 && + this.Pubkey.length == 64 && + this.TimeStamp && + this.RocketTag + ) + ) { + valid = false; + } return valid; } - REQFilter(kind?:number):NDKFilter { - if (!this.BasicValidation()) { - return {} - } - if (!kind) { - kind = 31108 - } - return { '#d': [this.RocketTag?.split(":")[2]!], authors: [this.RocketTag?.split(":")[1]!], kinds: [kind as number] } - } + REQFilter(kind?: number): NDKFilter { + if (!this.BasicValidation()) { + return {}; + } + if (!kind) { + kind = 31108; + } + return { + '#d': [this.RocketTag?.split(':')[2]!], + authors: [this.RocketTag?.split(':')[1]!], + kinds: [kind as number] + }; + } constructor(request: NDKEvent) { - this.Request = request; + this.Event = request; this.ID = request.id; this.Pubkey = request.pubkey; - if (this.Request.created_at) { - this.TimeStamp = this.Request.created_at; + if (this.Event.created_at) { + this.TimeStamp = this.Event.created_at; } - for (let tag of this.Request.getMatchingTags('a')) { + for (let tag of this.Event.getMatchingTags('a')) { if (tag && tag.length > 1) { if (tag[1].split(':') && tag[1].split(':').length == 3) { if ((tag[1].split(':')[0] = '31108')) { @@ -71,3 +83,75 @@ export class MeritRequest { this.Merits = getNumberFromTag('merits', request); } } + +export class Vote { + ID: string; + Request: string; + VoteDirection: VoteDirection | undefined; + Pubkey: string; + TimeStamp: number; + Event: NDKEvent; + BasicValidation(): boolean { + let valid = true; + if ( + !( + this.ID.length == 64 && + this.Request.length == 64 && + this.VoteDirection && + this.TimeStamp + ) + ) { + valid = false; + } + return valid; + } + RocketTag(): NDKTag | undefined { + let tag: NDKTag | undefined = undefined; + if (this.BasicValidation()) { + for (let t of this.Event.getMatchingTags('a')) { + if (t && t.length > 1 && t[1].split(':').length == 3 && t[1].split(':')[0] == '31108') { + tag = t; + } + } + } + + return tag; + } + REQFilter(kind?: number): NDKFilter { + let filter = {}; + if (!kind) { + kind = 31108; + } + if (this.BasicValidation()) { + let t = this.RocketTag(); + if (t) { + filter = { + '#d': [t[1].split(':')[2]!], + authors: [t[1].split(':')[1]!], + kinds: [kind as number] + }; + } + } + return filter; + } + constructor(event: NDKEvent) { + this.Event = event; + this.ID = event.id; + this.Pubkey = event.pubkey; + if (this.Event.created_at) { + this.TimeStamp = this.Event.created_at; + } + for (let t of this.Event.getMatchingTags("vote")) { + if (t && t.length == 2 && (t[1] == "blackball" || t[1] == "ratify")) { + this.VoteDirection = t[1] + } + } + for (let t of this.Event.getMatchingTags("request")) { + if (t && t.length == 2 && t[1].length == 64) { + this.Request = t[1] + } + } + } +} + +export type VoteDirection = "blackball" | "ratify" \ No newline at end of file diff --git a/src/lib/event_helpers/rockets.ts b/src/lib/event_helpers/rockets.ts index 871569c..6a77e9c 100644 --- a/src/lib/event_helpers/rockets.ts +++ b/src/lib/event_helpers/rockets.ts @@ -1,4 +1,4 @@ -import { NDKEvent, type NDKTag } from '@nostr-dev-kit/ndk'; +import { NDKEvent, type NDKFilter, type NDKTag } from '@nostr-dev-kit/ndk'; export class RocketProduct { ID: string; @@ -143,4 +143,8 @@ export function isValidUrl(string:string):boolean { } catch (err) { return false; } +} + +export function RocketATagFilter(rocket:NDKEvent):string { + return `31108:${rocket.pubkey}:${rocket.dTag}` } \ No newline at end of file