-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Enhance contract state management and CLI listing (#78)
- Loading branch information
1 parent
a082203
commit 10c3d96
Showing
6 changed files
with
87 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,5 +48,5 @@ | |
"peerDependencies": { | ||
"typescript": "^5.6.2" | ||
}, | ||
"version": "0.1.49" | ||
"version": "0.1.50" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,25 @@ | ||
export interface Contract { | ||
object: string; | ||
status: string; | ||
export type ContractStatus = "active" | "expired" | "upcoming" | "pending"; | ||
|
||
export interface BaseContract { | ||
object: "contract"; | ||
id: string; | ||
status: ContractStatus; | ||
} | ||
|
||
export interface PendingContract extends BaseContract { | ||
status: "pending"; | ||
} | ||
|
||
export interface ActiveContract extends BaseContract { | ||
status: ContractStatus; | ||
created_at: string; | ||
instance_type: string; | ||
shape: { | ||
// These are date strings | ||
intervals: string[]; | ||
quantities: number[]; | ||
}; | ||
colocate_with: string[]; | ||
cluster_id?: string; | ||
} | ||
|
||
export type Contract = PendingContract | ActiveContract; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
export type ContractState = "Upcoming" | "Active" | "Expired"; | ||
|
||
export function getContractState(shape: { | ||
intervals: string[]; | ||
quantities: number[]; | ||
}): ContractState { | ||
const now = new Date(); | ||
const startsAt = new Date(shape.intervals[0]); | ||
const endsAt = new Date(shape.intervals[shape.intervals.length - 1]); | ||
|
||
if (startsAt > now) { | ||
return "Upcoming"; | ||
} | ||
|
||
if (endsAt < now) { | ||
return "Expired"; | ||
} | ||
return "Active"; | ||
} | ||
|
||
export function getContractStateColor( | ||
state: ContractState, | ||
): "green" | "gray" | "cyan" { | ||
switch (state) { | ||
case "Upcoming": | ||
return "green"; | ||
case "Expired": | ||
return "gray"; | ||
case "Active": | ||
return "cyan"; | ||
} | ||
} |