fplus_lib/core/application/
lifecycle.rs1use chrono::prelude::*;
2
3use super::file::{AppState, LifeCycle};
4
5impl AppState {
6 pub fn as_str(&self) -> &str {
7 match *self {
8 AppState::Submitted => "Submitted",
9 AppState::ReadyToSign => "Ready to Sign Datacap",
10 AppState::StartSignDatacap => "Start Sign Datacap",
11 AppState::Granted => "Granted",
12 AppState::TotalDatacapReached => "Total Datacap Reached",
13 AppState::Error => "Error",
14 }
15 }
16}
17
18impl LifeCycle {
19 pub fn submitted(client_on_chain_address: String, multisig_address: String) -> Self {
20 let empty = "".to_string();
21 LifeCycle {
22 state: AppState::Submitted,
23 validated_at: empty.clone(),
24 validated_by: empty.clone(),
25 is_active: true,
26 updated_at: Utc::now().to_string(),
27 active_request: Some(empty),
28 client_on_chain_address,
29 multisig_address,
30 }
31 }
32
33 pub fn finish_governance_review(&self, actor: String, current_allocation_id: String) -> Self {
36 LifeCycle {
37 state: AppState::ReadyToSign,
38 validated_by: actor,
39 validated_at: Utc::now().to_string(),
40 updated_at: Utc::now().to_string(),
41 active_request: Some(current_allocation_id),
42 ..self.clone()
43 }
44 }
45
46 pub fn finish_proposal(&self) -> Self {
47 LifeCycle {
48 state: AppState::StartSignDatacap,
49 updated_at: Utc::now().to_string(),
50 ..self.clone()
51 }
52 }
53
54 pub fn finish_approval(&self) -> Self {
55 LifeCycle {
56 state: AppState::Granted,
57 updated_at: Utc::now().to_string(),
58 ..self.clone()
59 }
60 }
61
62 pub fn get_state(&self) -> AppState {
63 let res = self.state.clone();
64 res
65 }
66
67 pub fn start_refill_request(&self, request_id: String) -> Self {
68 LifeCycle {
69 state: AppState::ReadyToSign,
70 updated_at: Utc::now().to_string(),
71 active_request: Some(request_id),
72 ..self.clone()
73 }
74 }
75
76 pub fn get_active_allocation_id(self) -> Option<String> {
77 self.active_request
78 }
79
80 pub fn reached_total_datacap(self) -> Self {
81 let empty = "".to_string();
82
83 LifeCycle {
84 is_active: false,
85 updated_at: Utc::now().to_string(),
86 active_request: Some(empty),
87 ..self
88 }
89 }
90
91 pub fn move_back_to_governance_review(self) -> Self {
92 let empty = "".to_string();
93
94 LifeCycle {
95 state: AppState::Submitted,
96 validated_at: empty.clone(),
97 validated_by: empty.clone(),
98 updated_at: Utc::now().to_string(),
99 active_request: Some(empty),
100 ..self
101 }
102 }
103}