From 57f46a6b9eeace7b9ff9ed39cb22abd5731b73fc Mon Sep 17 00:00:00 2001 From: David Dal Busco Date: Sun, 6 Oct 2024 07:39:55 +0200 Subject: [PATCH 01/10] feat(deprecate): redo invitation code Signed-off-by: David Dal Busco --- src/console/console.did | 2 +- src/console/src/factory/mission_control.rs | 16 +++++++++++----- src/console/src/lib.rs | 4 ++-- src/declarations/console/console.did.d.ts | 2 +- src/declarations/console/console.factory.did.js | 2 +- src/declarations/console/console.factory.did.mjs | 2 +- 6 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/console/console.did b/src/console/console.did index 53d49c3a4..06701e12c 100644 --- a/src/console/console.did +++ b/src/console/console.did @@ -209,7 +209,7 @@ service : () -> { ) query; init_asset_upload : (InitAssetKey, nat) -> (InitUploadResult); init_proposal : (ProposalType) -> (nat, Proposal); - init_user_mission_control_center : () -> (MissionControl); + init_user_mission_control_center : (opt text) -> (MissionControl); list_assets : (text, ListParams) -> (ListResults) query; list_custom_domains : () -> (vec record { text; CustomDomain }) query; list_payments : () -> (vec record { nat64; Payment }) query; diff --git a/src/console/src/factory/mission_control.rs b/src/console/src/factory/mission_control.rs index b39767632..3c206a8f9 100644 --- a/src/console/src/factory/mission_control.rs +++ b/src/console/src/factory/mission_control.rs @@ -1,5 +1,5 @@ use crate::controllers::update_mission_control_controllers; -use crate::store::heap::increment_mission_controls_rate; +use crate::store::heap::{increment_mission_controls_rate, redeem_invitation_code}; use crate::store::stable::{ add_mission_control, delete_mission_control, get_mission_control, init_empty_mission_control, }; @@ -13,17 +13,23 @@ use junobuild_shared::types::state::UserId; pub async fn init_user_mission_control( console: &Principal, caller: &Principal, + invitation_code: &Option, ) -> Result { let result = get_mission_control(caller); match result { Err(error) => Err(error.to_string()), Ok(mission_control) => match mission_control { Some(mission_control) => Ok(mission_control), - None => { - // Guard too many requests - increment_mission_controls_rate()?; + None => match invitation_code { + None => Err("No invitation code provided.".to_string()), + Some(invitation_code) => { + // Guard too many requests + increment_mission_controls_rate()?; - create_mission_control(caller, console).await + redeem_invitation_code(caller, invitation_code)?; + + create_mission_control(caller, console).await + } } }, } diff --git a/src/console/src/lib.rs b/src/console/src/lib.rs index fcfc2e584..481cff493 100644 --- a/src/console/src/lib.rs +++ b/src/console/src/lib.rs @@ -155,11 +155,11 @@ fn list_user_mission_control_centers() -> MissionControls { } #[update] -async fn init_user_mission_control_center() -> MissionControl { +async fn init_user_mission_control_center(invitation_code: Option) -> MissionControl { let caller = caller(); let console = id(); - init_user_mission_control(&console, &caller) + init_user_mission_control(&console, &caller, &invitation_code) .await .unwrap_or_else(|e| trap(&e)) } diff --git a/src/declarations/console/console.did.d.ts b/src/declarations/console/console.did.d.ts index 47f50838f..590bb632f 100644 --- a/src/declarations/console/console.did.d.ts +++ b/src/declarations/console/console.did.d.ts @@ -248,7 +248,7 @@ export interface _SERVICE { >; init_asset_upload: ActorMethod<[InitAssetKey, bigint], InitUploadResult>; init_proposal: ActorMethod<[ProposalType], [bigint, Proposal]>; - init_user_mission_control_center: ActorMethod<[], MissionControl>; + init_user_mission_control_center: ActorMethod<[[] | [string]], MissionControl>; list_assets: ActorMethod<[string, ListParams], ListResults>; list_custom_domains: ActorMethod<[], Array<[string, CustomDomain]>>; list_payments: ActorMethod<[], Array<[bigint, Payment]>>; diff --git a/src/declarations/console/console.factory.did.js b/src/declarations/console/console.factory.did.js index ae0242f13..2fa8fabb5 100644 --- a/src/declarations/console/console.factory.did.js +++ b/src/declarations/console/console.factory.did.js @@ -259,7 +259,7 @@ export const idlFactory = ({ IDL }) => { ), init_asset_upload: IDL.Func([InitAssetKey, IDL.Nat], [InitUploadResult], []), init_proposal: IDL.Func([ProposalType], [IDL.Nat, Proposal], []), - init_user_mission_control_center: IDL.Func([], [MissionControl], []), + init_user_mission_control_center: IDL.Func([IDL.Opt(IDL.Text)], [MissionControl], []), list_assets: IDL.Func([IDL.Text, ListParams], [ListResults], ['query']), list_custom_domains: IDL.Func([], [IDL.Vec(IDL.Tuple(IDL.Text, CustomDomain))], ['query']), list_payments: IDL.Func([], [IDL.Vec(IDL.Tuple(IDL.Nat64, Payment))], ['query']), diff --git a/src/declarations/console/console.factory.did.mjs b/src/declarations/console/console.factory.did.mjs index ae0242f13..2fa8fabb5 100644 --- a/src/declarations/console/console.factory.did.mjs +++ b/src/declarations/console/console.factory.did.mjs @@ -259,7 +259,7 @@ export const idlFactory = ({ IDL }) => { ), init_asset_upload: IDL.Func([InitAssetKey, IDL.Nat], [InitUploadResult], []), init_proposal: IDL.Func([ProposalType], [IDL.Nat, Proposal], []), - init_user_mission_control_center: IDL.Func([], [MissionControl], []), + init_user_mission_control_center: IDL.Func([IDL.Opt(IDL.Text)], [MissionControl], []), list_assets: IDL.Func([IDL.Text, ListParams], [ListResults], ['query']), list_custom_domains: IDL.Func([], [IDL.Vec(IDL.Tuple(IDL.Text, CustomDomain))], ['query']), list_payments: IDL.Func([], [IDL.Vec(IDL.Tuple(IDL.Nat64, Payment))], ['query']), From d667f5f15f07485bfb6f8741c581261e62ae4bad Mon Sep 17 00:00:00 2001 From: David Dal Busco Date: Sun, 6 Oct 2024 20:06:23 +0200 Subject: [PATCH 02/10] test: adapt args Signed-off-by: David Dal Busco --- src/tests/utils/console-tests.utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tests/utils/console-tests.utils.ts b/src/tests/utils/console-tests.utils.ts index f04c41acc..ad41438c7 100644 --- a/src/tests/utils/console-tests.utils.ts +++ b/src/tests/utils/console-tests.utils.ts @@ -257,7 +257,7 @@ export const initMissionControls = async ({ actor.setIdentity(user); const { init_user_mission_control_center } = actor; - await init_user_mission_control_center(); + await init_user_mission_control_center([]); await tick(pic); } From b0b7cd532944fe9b602445706a41356add0f539e Mon Sep 17 00:00:00 2001 From: David Dal Busco Date: Sun, 6 Oct 2024 20:32:45 +0200 Subject: [PATCH 03/10] feat: update sign-in with deprecation text Signed-off-by: David Dal Busco --- src/frontend/src/lib/api/console.api.ts | 13 ++++++++++--- .../src/lib/components/core/SignIn.svelte | 15 ++++++++++++--- src/frontend/src/lib/i18n/en.json | 2 +- src/frontend/src/lib/i18n/zh-cn.json | 2 +- .../src/lib/services/console.services.ts | 14 ++++++++++---- src/frontend/src/lib/stores/auth.store.ts | 17 ++++++++++++----- src/frontend/src/lib/types/console.ts | 1 + src/frontend/src/lib/types/i18n.d.ts | 2 +- src/frontend/src/routes/+layout.svelte | 3 ++- 9 files changed, 50 insertions(+), 19 deletions(-) create mode 100644 src/frontend/src/lib/types/console.ts diff --git a/src/frontend/src/lib/api/console.api.ts b/src/frontend/src/lib/api/console.api.ts index d84ff5589..d20c5d579 100644 --- a/src/frontend/src/lib/api/console.api.ts +++ b/src/frontend/src/lib/api/console.api.ts @@ -1,10 +1,17 @@ import type { MissionControl } from '$declarations/console/console.did'; +import type { OptionInvitationCode } from '$lib/types/console'; import type { OptionIdentity } from '$lib/types/itentity'; import { getConsoleActor } from '$lib/utils/actor.juno.utils'; import type { Principal } from '@dfinity/principal'; -import { fromNullable, isNullish } from '@dfinity/utils'; +import { fromNullable, isNullish, toNullable } from '@dfinity/utils'; -export const initMissionControl = async (identity: OptionIdentity): Promise => { +export const initMissionControl = async ({ + identity, + invitationCode +}: { + identity: OptionIdentity; + invitationCode: OptionInvitationCode; +}): Promise => { const actor = await getConsoleActor(identity); const existingMissionControl: MissionControl | undefined = fromNullable( @@ -12,7 +19,7 @@ export const initMissionControl = async (identity: OptionIdentity): Promise

{title}

-

{$i18n.sign_in.future}

+

{$i18n.sign_in.deprecated}