|
@@ -107,12 +107,6 @@ function bountyActorToMembership(actor: BountyActor): Membership | undefined {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-function isBountyFundingLimited(
|
|
|
- fundingType: BountyFundingPerpetual | BountyFundingLimited
|
|
|
-): fundingType is BountyFundingLimited {
|
|
|
- return fundingType.isTypeOf === BountyFundingLimited.name
|
|
|
-}
|
|
|
-
|
|
|
function fundingPeriodEnd(bounty: Bounty): number {
|
|
|
return (
|
|
|
bounty.maxFundingReachedEvent?.inBlock ??
|
|
@@ -120,13 +114,17 @@ function fundingPeriodEnd(bounty: Bounty): number {
|
|
|
)
|
|
|
}
|
|
|
|
|
|
+function whenDef<T, R>(value: T | null | undefined, fn: (value: T) => R): R | undefined {
|
|
|
+ if (value !== null && typeof value !== 'undefined') return fn(value)
|
|
|
+}
|
|
|
+
|
|
|
/**
|
|
|
* Schedule Periods changes
|
|
|
*/
|
|
|
|
|
|
export function bountyScheduleFundingEnd(store: DatabaseManager, bounty: Bounty): void {
|
|
|
const { fundingType } = bounty
|
|
|
- if (bounty.stage !== BountyStage.Funding || !isBountyFundingLimited(fundingType)) return
|
|
|
+ if (bounty.stage !== BountyStage.Funding || !('fundingPeriod' in fundingType)) return
|
|
|
|
|
|
const fundingPeriodEnd = bounty.createdInEvent.inBlock + fundingType.fundingPeriod
|
|
|
scheduleAtBlock(fundingPeriodEnd, () => {
|
|
@@ -214,7 +212,7 @@ export async function bounty_BountyCreated({ event, store }: EventContext & Stor
|
|
|
|
|
|
stage: BountyStage.Funding,
|
|
|
totalFunding: bountyParams.cherry,
|
|
|
- discussionThread: asForumThread(metadata?.discussionThread ?? undefined),
|
|
|
+ discussionThread: whenDef(metadata?.discussionThread, (id) => new ForumThread({ id })),
|
|
|
})
|
|
|
await store.save<Bounty>(bounty)
|
|
|
|
|
@@ -247,12 +245,6 @@ export async function bounty_BountyCreated({ event, store }: EventContext & Stor
|
|
|
return closedContract
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- function asForumThread(threadId: number | undefined) {
|
|
|
- if (typeof threadId === 'number') {
|
|
|
- return new ForumThread({ id: String(threadId) })
|
|
|
- }
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
// Store bounties canceled events
|
|
@@ -447,7 +439,7 @@ export async function bounty_WorkEntrantFundsWithdrawn({ event, store }: EventCo
|
|
|
if ('reward' in entry.status) {
|
|
|
status.reward = entry.status.reward
|
|
|
}
|
|
|
- return { status: new BountyEntryStatusCashedOut() }
|
|
|
+ return { status }
|
|
|
})
|
|
|
|
|
|
await store.save<BountyEntry>(entry)
|