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

fix(backend): optional settings #3825

Merged
merged 10 commits into from
Dec 4, 2024
2 changes: 1 addition & 1 deletion src/backend/backend.did
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ type UserCredential = record {
type UserProfile = record {
credentials : vec UserCredential;
version : opt nat64;
settings : Settings;
settings : opt Settings;
created_timestamp : nat64;
updated_timestamp : nat64;
};
Expand Down
1 change: 1 addition & 0 deletions src/backend/tests/it/user_profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ fn test_create_user_profile_creates_default_profile() {

assert!(user_profile
.settings
.unwrap()
.dapp
.dapp_carousel
.hidden_dapp_ids
Expand Down
2 changes: 1 addition & 1 deletion src/declarations/backend/backend.did
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ type UserCredential = record {
type UserProfile = record {
credentials : vec UserCredential;
version : opt nat64;
settings : Settings;
settings : opt Settings;
created_timestamp : nat64;
updated_timestamp : nat64;
};
Expand Down
2 changes: 1 addition & 1 deletion src/declarations/backend/backend.did.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ export interface UserCredential {
export interface UserProfile {
credentials: Array<UserCredential>;
version: [] | [bigint];
settings: Settings;
settings: [] | [Settings];
created_timestamp: bigint;
updated_timestamp: bigint;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export const idlFactory = ({ IDL }) => {
const UserProfile = IDL.Record({
credentials: IDL.Vec(UserCredential),
version: IDL.Opt(IDL.Nat64),
settings: Settings,
settings: IDL.Opt(Settings),
created_timestamp: IDL.Nat64,
updated_timestamp: IDL.Nat64
});
Expand Down
2 changes: 1 addition & 1 deletion src/declarations/backend/backend.factory.did.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export const idlFactory = ({ IDL }) => {
const UserProfile = IDL.Record({
credentials: IDL.Vec(UserCredential),
version: IDL.Opt(IDL.Nat64),
settings: Settings,
settings: IDL.Opt(Settings),
created_timestamp: IDL.Nat64,
updated_timestamp: IDL.Nat64
});
Expand Down
3 changes: 2 additions & 1 deletion src/frontend/src/tests/mocks/user-profile.mock.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import type { UserProfile } from '$declarations/backend/backend.did';
import { toNullable } from '@dfinity/utils';

export const mockUserProfile: UserProfile = {
credentials: [],
version: [],
settings: { dapp: { dapp_carousel: { hidden_dapp_ids: [] } } },
settings: toNullable({ dapp: { dapp_carousel: { hidden_dapp_ids: [] } } }),
created_timestamp: 1234n,
updated_timestamp: 1234n
};
2 changes: 1 addition & 1 deletion src/shared/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ impl StoredUserProfile {
};
let credentials: BTreeMap<CredentialType, UserCredential> = BTreeMap::new();
StoredUserProfile {
settings,
settings: Some(settings),
credentials,
created_timestamp: now,
updated_timestamp: now,
Expand Down
16 changes: 7 additions & 9 deletions src/shared/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,12 +315,12 @@ pub mod signer {
pub mod dapp {
use candid::{CandidType, Deserialize};

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

#[derive(CandidType, Deserialize, Clone, Debug, Eq, PartialEq, Default)]
#[derive(CandidType, Deserialize, Clone, Debug, Eq, PartialEq)]
pub struct DappSettings {
pub dapp_carousel: DappCarouselSettings,
}
Expand All @@ -330,7 +330,7 @@ pub mod settings {
use crate::types::dapp::DappSettings;
use candid::{CandidType, Deserialize};

#[derive(CandidType, Deserialize, Clone, Debug, Eq, PartialEq, Default)]
#[derive(CandidType, Deserialize, Clone, Debug, Eq, PartialEq)]
pub struct Settings {
pub dapp: DappSettings,
}
Expand All @@ -353,20 +353,18 @@ pub mod user_profile {
}

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

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