Skip to content

Commit 32afc1b

Browse files
committed
Update create_project flow in order to be compatible with UI design
1 parent 7bee8b9 commit 32afc1b

File tree

3 files changed

+50
-53
lines changed

3 files changed

+50
-53
lines changed

pallets/proxy/src/functions.rs

Lines changed: 43 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,23 @@ impl<T: Config> Pallet<T> {
9292

9393
pub fn do_create_project(
9494
admin: T::AccountId,
95-
tittle: FieldName,
95+
title: FieldName,
9696
description: FieldDescription,
9797
image: CID,
98-
adress: FieldName,
98+
address: FieldName,
9999
project_type: ProjectType,
100-
completition_date: u64,
100+
completion_date: u64,
101+
expenditures: BoundedVec<(
102+
FieldName,
103+
ExpenditureType,
104+
Option<u64>,
105+
Option<u32>,
106+
Option<u32>,
107+
), T::MaxRegistrationsAtTime>,
108+
users: Option<BoundedVec<(
109+
T::AccountId,
110+
ProxyRole
111+
), T::MaxRegistrationsAtTime>>,
101112
) -> DispatchResult {
102113
// Ensure admin permissions
103114
Self::is_superuser(admin.clone(), &Self::get_global_scope(), ProxyRole::Administrator.id())?;
@@ -107,25 +118,25 @@ impl<T: Config> Pallet<T> {
107118

108119
//Create project_id
109120
//TOREVIEW: We could use only name as project_id or use a method/storagemap to check if the name is already in use
110-
let project_id = (tittle.clone()).using_encoded(blake2_256);
121+
let project_id = (title.clone()).using_encoded(blake2_256);
111122

112-
//ensure completition date is in the future
113-
ensure!(completition_date > timestamp, Error::<T>::CompletitionDateMustBeLater);
123+
//ensure completion_date is in the future
124+
ensure!(completion_date > timestamp, Error::<T>::CompletionDateMustBeLater);
114125

115126
//Create project data
116127
let project_data = ProjectData::<T> {
117128
developer: Some(BoundedVec::<T::AccountId, T::MaxDevelopersPerProject>::default()),
118129
investor: Some(BoundedVec::<T::AccountId, T::MaxInvestorsPerProject>::default()),
119130
issuer: Some(BoundedVec::<T::AccountId, T::MaxIssuersPerProject>::default()),
120131
regional_center: Some(BoundedVec::<T::AccountId, T::MaxRegionalCenterPerProject>::default()),
121-
tittle,
132+
title,
122133
description,
123134
image,
124-
adress,
135+
address,
125136
status: ProjectStatus::default(),
126137
project_type,
127138
creation_date: timestamp,
128-
completition_date,
139+
completion_date,
129140
updated_date: timestamp,
130141
};
131142

@@ -137,30 +148,16 @@ impl<T: Config> Pallet<T> {
137148
ensure!(!ProjectsInfo::<T>::contains_key(project_id), Error::<T>::ProjectIdAlreadyInUse);
138149
ProjectsInfo::<T>::insert(project_id, project_data);
139150

140-
// Match project type, call default expenditures
141-
// match project_type {
142-
// ProjectType::Construction => {
143-
// //Generate its related expenditures
144-
// Self::do_generate_hard_cost_defaults(admin.clone(), project_id)?;
145-
// Self::do_generate_soft_cost_defaults(admin.clone(), project_id)?;
146-
// },
147-
// ProjectType::ConstructionOperation => {
148-
// //Generate its related expenditures
149-
// Self::do_generate_hard_cost_defaults(admin.clone(), project_id)?;
150-
// Self::do_generate_soft_cost_defaults(admin.clone(), project_id)?;
151-
// Self::do_generate_operational_defaults(admin.clone(), project_id)?;
152-
// },
153-
// ProjectType::ConstructionBridge => {
154-
// //Generate its related expenditures
155-
// Self::do_generate_hard_cost_defaults(admin.clone(), project_id)?;
156-
// Self::do_generate_soft_cost_defaults(admin.clone(), project_id)?;
157-
// Self::do_generate_others_defaults(admin.clone(), project_id)?;
158-
// },
159-
// ProjectType::Operation => {
160-
// //Generate its related expenditures
161-
// Self::do_generate_operational_defaults(admin.clone(), project_id)?;
162-
// },
163-
// }
151+
//Add expenditures
152+
Self::do_create_expenditure(admin.clone(), project_id, expenditures)?;
153+
154+
match users {
155+
Some(users) => {
156+
//Add users
157+
Self::do_assign_user(admin.clone(), project_id, users)?;
158+
},
159+
None => {}
160+
}
164161

165162
//Initialize drawdowns
166163
Self::do_initialize_drawdowns(admin.clone(), project_id)?;
@@ -174,11 +171,11 @@ impl<T: Config> Pallet<T> {
174171
pub fn do_edit_project(
175172
admin: T::AccountId,
176173
project_id: [u8;32],
177-
tittle: Option<BoundedVec<FieldName, T::MaxBoundedVecs>>,
174+
title: Option<BoundedVec<FieldName, T::MaxBoundedVecs>>,
178175
description: Option<BoundedVec<FieldDescription, T::MaxBoundedVecs>>,
179176
image: Option<BoundedVec<CID, T::MaxBoundedVecs>>,
180-
adress: Option<BoundedVec<FieldName, T::MaxBoundedVecs>>,
181-
completition_date: Option<u64>,
177+
address: Option<BoundedVec<FieldName, T::MaxBoundedVecs>>,
178+
completion_date: Option<u64>,
182179
) -> DispatchResult {
183180
//ensure admin permissions
184181
Self::is_superuser(admin.clone(), &Self::get_global_scope(), ProxyRole::Administrator.id())?;
@@ -196,9 +193,9 @@ impl<T: Config> Pallet<T> {
196193
<ProjectsInfo<T>>::try_mutate::<_,_,DispatchError,_>(project_id, |project| {
197194
let project = project.as_mut().ok_or(Error::<T>::ProjectNotFound)?;
198195

199-
if let Some(tittle) = tittle {
200-
let mod_tittle = tittle.into_inner();
201-
project.tittle = mod_tittle[0].clone();
196+
if let Some(title) = title {
197+
let mod_title = title.into_inner();
198+
project.title = mod_title[0].clone();
202199
}
203200
if let Some(description) = description {
204201
let mod_description = description.into_inner();
@@ -208,14 +205,14 @@ impl<T: Config> Pallet<T> {
208205
let mod_image = image.into_inner();
209206
project.image = mod_image[0].clone();
210207
}
211-
if let Some(adress) = adress {
212-
let mod_adress = adress.into_inner();
213-
project.adress = mod_adress[0].clone();
208+
if let Some(address) = address {
209+
let mod_address = address.into_inner();
210+
project.address = mod_address[0].clone();
214211
}
215-
if let Some(completition_date) = completition_date {
216-
//ensure new completition date is in the future
217-
ensure!(completition_date > current_timestamp, Error::<T>::CompletitionDateMustBeLater);
218-
project.completition_date = completition_date;
212+
if let Some(completion_date) = completion_date {
213+
//ensure new completion_date date is in the future
214+
ensure!(completion_date > current_timestamp, Error::<T>::CompletionDateMustBeLater);
215+
project.completion_date = completion_date;
219216
}
220217
//TOREVIEW: Check if this is working
221218
project.updated_date = current_timestamp;

pallets/proxy/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ pub mod pallet {
334334
/// Timestamp error
335335
TimestampError,
336336
/// Completition date must be later than creation date
337-
CompletitionDateMustBeLater,
337+
CompletionDateMustBeLater,
338338
/// User is already registered
339339
UserAlreadyRegistered,
340340
/// Project is not found
@@ -533,14 +533,14 @@ pub mod pallet {
533533
Option<u32>,
534534
Option<u32>,
535535
), T::MaxRegistrationsAtTime>,
536-
users: BoundedVec<(
536+
users: Option<BoundedVec<(
537537
T::AccountId,
538538
ProxyRole
539-
), T::MaxRegistrationsAtTime>,
539+
), T::MaxRegistrationsAtTime>>,
540540
) -> DispatchResult {
541541
let who = ensure_signed(origin)?; // origin need to be an admin
542542

543-
Self::do_create_project(who, title, description, image, address, project_type, completion_date)
543+
Self::do_create_project(who, title, description, image, address, project_type, completion_date, expenditures, users)
544544
}
545545

546546
#[transactional]

pallets/proxy/src/types.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ pub struct ProjectData<T: Config>{
1818
pub investor: Option<BoundedVec<T::AccountId, T::MaxInvestorsPerProject>>,
1919
pub issuer: Option<BoundedVec<T::AccountId, T::MaxIssuersPerProject>>,
2020
pub regional_center: Option<BoundedVec<T::AccountId, T::MaxRegionalCenterPerProject>>,
21-
pub tittle: FieldName,
21+
pub title: FieldName,
2222
pub description: FieldDescription,
2323
pub image: CID,
24-
pub adress: FieldName,
24+
pub address: FieldName,
2525
pub status: ProjectStatus,
2626
pub project_type: ProjectType,
2727
pub creation_date: u64,
28-
pub completition_date: u64,
28+
pub completion_date: u64,
2929
pub updated_date: u64,
3030
}
3131

0 commit comments

Comments
 (0)