Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(backend): create settings property in user profile #3770

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/backend/backend.did
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ type CustomToken = record {
version : opt nat64;
enabled : bool;
};
type DappCarouselSettings = record { hidden_dapp_ids : vec text };
type DappSettings = record { dapp_carousel : DappCarouselSettings };
type DefiniteCanisterSettingsArgs = record {
controller : principal;
freezing_threshold : nat;
Expand Down Expand Up @@ -179,6 +181,7 @@ type SelectedUtxosFeeResponse = record {
fee_satoshis : nat64;
utxos : vec Utxo;
};
type Settings = record { dapp : DappSettings };
type Stats = record {
user_profile_count : nat64;
custom_token_count : nat64;
Expand Down Expand Up @@ -219,6 +222,7 @@ type UserCredential = record {
type UserProfile = record {
credentials : vec UserCredential;
version : opt nat64;
settings : Settings;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be opt?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed offline, I included #[serde(default)] ; would that be enough? WDYT?

created_timestamp : nat64;
updated_timestamp : nat64;
};
Expand Down
6 changes: 6 additions & 0 deletions src/backend/tests/it/user_profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ fn test_create_user_profile_creates_default_profile() {

let user_profile = response.expect("Create failed");

assert!(user_profile
.settings
.dapp
.dapp_carousel
.hidden_dapp_ids
.is_empty());
assert_eq!(user_profile.credentials.len(), 0);
assert!(user_profile.version.is_none());
}
Expand Down
4 changes: 4 additions & 0 deletions src/declarations/backend/backend.did
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ type CustomToken = record {
version : opt nat64;
enabled : bool;
};
type DappCarouselSettings = record { hidden_dapp_ids : vec text };
type DappSettings = record { dapp_carousel : DappCarouselSettings };
type DefiniteCanisterSettingsArgs = record {
controller : principal;
freezing_threshold : nat;
Expand Down Expand Up @@ -179,6 +181,7 @@ type SelectedUtxosFeeResponse = record {
fee_satoshis : nat64;
utxos : vec Utxo;
};
type Settings = record { dapp : DappSettings };
type Stats = record {
user_profile_count : nat64;
custom_token_count : nat64;
Expand Down Expand Up @@ -219,6 +222,7 @@ type UserCredential = record {
type UserProfile = record {
credentials : vec UserCredential;
version : opt nat64;
settings : Settings;
created_timestamp : nat64;
updated_timestamp : nat64;
};
Expand Down
10 changes: 10 additions & 0 deletions src/declarations/backend/backend.did.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ export interface CustomToken {
version: [] | [bigint];
enabled: boolean;
}
export interface DappCarouselSettings {
hidden_dapp_ids: Array<string>;
}
export interface DappSettings {
dapp_carousel: DappCarouselSettings;
}
export interface DefiniteCanisterSettingsArgs {
controller: Principal;
freezing_threshold: bigint;
Expand Down Expand Up @@ -189,6 +195,9 @@ export interface SelectedUtxosFeeResponse {
fee_satoshis: bigint;
utxos: Array<Utxo>;
}
export interface Settings {
dapp: DappSettings;
}
export interface Stats {
user_profile_count: bigint;
custom_token_count: bigint;
Expand Down Expand Up @@ -235,6 +244,7 @@ export interface UserCredential {
export interface UserProfile {
credentials: Array<UserCredential>;
version: [] | [bigint];
settings: Settings;
created_timestamp: bigint;
updated_timestamp: bigint;
}
Expand Down
6 changes: 6 additions & 0 deletions src/declarations/backend/backend.factory.certified.did.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,15 @@ export const idlFactory = ({ IDL }) => {
verified_date_timestamp: IDL.Opt(IDL.Nat64),
credential_type: CredentialType
});
const DappCarouselSettings = IDL.Record({
hidden_dapp_ids: IDL.Vec(IDL.Text)
});
const DappSettings = IDL.Record({ dapp_carousel: DappCarouselSettings });
const Settings = IDL.Record({ dapp: DappSettings });
const UserProfile = IDL.Record({
credentials: IDL.Vec(UserCredential),
version: IDL.Opt(IDL.Nat64),
settings: Settings,
created_timestamp: IDL.Nat64,
updated_timestamp: IDL.Nat64
});
Expand Down
6 changes: 6 additions & 0 deletions src/declarations/backend/backend.factory.did.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,15 @@ export const idlFactory = ({ IDL }) => {
verified_date_timestamp: IDL.Opt(IDL.Nat64),
credential_type: CredentialType
});
const DappCarouselSettings = IDL.Record({
hidden_dapp_ids: IDL.Vec(IDL.Text)
});
const DappSettings = IDL.Record({ dapp_carousel: DappCarouselSettings });
const Settings = IDL.Record({ dapp: DappSettings });
const UserProfile = IDL.Record({
credentials: IDL.Vec(UserCredential),
version: IDL.Opt(IDL.Nat64),
settings: Settings,
created_timestamp: IDL.Nat64,
updated_timestamp: IDL.Nat64
});
Expand Down
1 change: 1 addition & 0 deletions src/frontend/src/tests/mocks/user-profile.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { UserProfile } from '$declarations/backend/backend.did';
export const mockUserProfile: UserProfile = {
credentials: [],
version: [],
settings: { dapp: { dapp_carousel: { hidden_dapp_ids: [] } } },
created_timestamp: 1234n,
updated_timestamp: 1234n
};
12 changes: 12 additions & 0 deletions src/shared/src/impls.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use crate::types::custom_token::{CustomToken, CustomTokenId, Token};
use crate::types::dapp::{DappCarouselSettings, DappSettings};
use crate::types::settings::Settings;
use crate::types::token::UserToken;
use crate::types::user_profile::{
AddUserCredentialError, OisyUser, StoredUserProfile, UserCredential, UserProfile,
Expand Down Expand Up @@ -120,8 +122,16 @@ impl TokenVersion for StoredUserProfile {
impl StoredUserProfile {
#[must_use]
pub fn from_timestamp(now: Timestamp) -> StoredUserProfile {
let settings = Settings {
dapp: DappSettings {
dapp_carousel: DappCarouselSettings {
hidden_dapp_ids: Vec::new(),
},
},
};
let credentials: BTreeMap<CredentialType, UserCredential> = BTreeMap::new();
StoredUserProfile {
settings,
credentials,
created_timestamp: now,
updated_timestamp: now,
Expand Down Expand Up @@ -163,12 +173,14 @@ impl From<&StoredUserProfile> for UserProfile {
updated_timestamp,
version,
credentials,
settings,
} = user;
UserProfile {
created_timestamp: *created_timestamp,
updated_timestamp: *updated_timestamp,
version: *version,
credentials: credentials.clone().into_values().collect(),
settings: settings.clone(),
}
}
}
Expand Down
33 changes: 31 additions & 2 deletions src/shared/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,34 @@ pub mod signer {
}
}

pub mod dapp {
use candid::{CandidType, Deserialize};

#[derive(CandidType, Deserialize, Clone, Debug, Eq, PartialEq, Default)]
pub struct DappCarouselSettings {
pub hidden_dapp_ids: Vec<String>,
}

#[derive(CandidType, Deserialize, Clone, Debug, Eq, PartialEq, Default)]
pub struct DappSettings {
pub dapp_carousel: DappCarouselSettings,
}
}

pub mod settings {
use crate::types::dapp::DappSettings;
use candid::{CandidType, Deserialize};

#[derive(CandidType, Deserialize, Clone, Debug, Eq, PartialEq, Default)]
pub struct Settings {
pub dapp: DappSettings,
}
}

/// Types specifics to the user profile.
pub mod user_profile {
use super::{CredentialType, Timestamp};
use crate::types::settings::Settings;
use crate::types::Version;
use candid::{CandidType, Deserialize, Principal};
use ic_verifiable_credentials::issuer_api::CredentialSpec;
Expand All @@ -328,16 +353,20 @@ pub mod user_profile {
}

// Used in the endpoint
#[derive(CandidType, Deserialize, Clone, Eq, PartialEq, Debug)]
#[derive(CandidType, Deserialize, Clone, Eq, PartialEq, Debug, Default)]
pub struct UserProfile {
#[serde(default)]
pub settings: Settings,
pub credentials: Vec<UserCredential>,
pub created_timestamp: Timestamp,
pub updated_timestamp: Timestamp,
pub version: Option<Version>,
}

#[derive(CandidType, Deserialize, Clone, Eq, PartialEq, Debug)]
#[derive(CandidType, Deserialize, Clone, Eq, PartialEq, Debug, Default)]
pub struct StoredUserProfile {
#[serde(default)]
pub settings: Settings,
pub credentials: BTreeMap<CredentialType, UserCredential>,
pub created_timestamp: Timestamp,
pub updated_timestamp: Timestamp,
Expand Down