-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add endpoint for platform_ops to set diamond fees
- Loading branch information
Showing
13 changed files
with
189 additions
and
53 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
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
14 changes: 14 additions & 0 deletions
14
backend/canisters/user_index/api/src/updates/set_diamond_membership_fees.rs
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,14 @@ | ||
use candid::CandidType; | ||
use serde::{Deserialize, Serialize}; | ||
use types::DiamondMembershipFees; | ||
|
||
#[derive(CandidType, Serialize, Deserialize, Debug)] | ||
pub struct Args { | ||
pub fees: DiamondMembershipFees, | ||
} | ||
|
||
#[derive(CandidType, Serialize, Deserialize, Debug)] | ||
pub enum Response { | ||
Success, | ||
Invalid, | ||
} |
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
26 changes: 17 additions & 9 deletions
26
backend/canisters/user_index/impl/src/queries/diamond_membership_fees.rs
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
29 changes: 29 additions & 0 deletions
29
backend/canisters/user_index/impl/src/updates/set_diamond_membership_fees.rs
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,29 @@ | ||
use crate::guards::caller_is_platform_operator; | ||
use crate::{mutate_state, RuntimeState}; | ||
use canister_tracing_macros::trace; | ||
use ic_cdk_macros::update; | ||
use types::{DiamondMembershipFees, DiamondMembershipFeesByDuration}; | ||
use user_index_canister::set_diamond_membership_fees::{Response::*, *}; | ||
|
||
#[update(guard = "caller_is_platform_operator")] | ||
#[trace] | ||
fn set_diamond_membership_fees(args: Args) -> Response { | ||
mutate_state(|state| set_diamond_membership_fees_impl(args, state)) | ||
} | ||
|
||
fn set_diamond_membership_fees_impl(args: Args, state: &mut RuntimeState) -> Response { | ||
if fees_valid(&args.fees) { | ||
state.data.diamond_membership_fees = args.fees; | ||
Success | ||
} else { | ||
Invalid | ||
} | ||
} | ||
|
||
fn fees_valid(fees: &DiamondMembershipFees) -> bool { | ||
fees_by_duration_valid(&fees.chat_fees) && fees_by_duration_valid(&fees.icp_fees) | ||
} | ||
|
||
fn fees_by_duration_valid(fees: &DiamondMembershipFeesByDuration) -> bool { | ||
(fees.one_month < fees.three_months) && (fees.three_months < fees.one_year) && (fees.one_year < fees.lifetime) | ||
} |
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
Oops, something went wrong.