Skip to content

Commit

Permalink
feat: add config data variable in state service
Browse files Browse the repository at this point in the history
  • Loading branch information
0xExp-po committed Sep 11, 2024
1 parent 3b9580c commit 97b618d
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
33 changes: 33 additions & 0 deletions dapp/src/service/StateService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as pkg from "js-sha3";
const { keccak256 } = pkg;
import { Buffer } from "buffer";
import type { Project } from "soroban_versioning";
import type { ConfigData } from "../types/projectConfig";

const projectState: {
project_name: string | undefined;
Expand Down Expand Up @@ -36,6 +37,12 @@ const projectLatestSha: {
sha: undefined,
};

// Add this new type definition


// Add this new state variable
let configData: ConfigData | undefined = undefined;

function initializeProjectState() {
if (typeof window !== 'undefined') {
const storedState = localStorage.getItem('projectState');
Expand Down Expand Up @@ -65,6 +72,12 @@ function initializeProjectState() {
const parsedLatestSha = JSON.parse(storedLatestSha);
projectLatestSha.sha = parsedLatestSha.sha;
}

// Add this new initialization
const storedConfigData = localStorage.getItem('configData');
if (storedConfigData) {
configData = JSON.parse(storedConfigData);
}
}
}

Expand Down Expand Up @@ -114,6 +127,20 @@ function setProjectLatestSha(sha: string): void {
}
}

function setConfigData(data: Partial<ConfigData>): void {
if (!configData) {
configData = data as ConfigData;
} else {
configData = {
...configData,
...data
};
}
if (typeof window !== 'undefined') {
localStorage.setItem('configData', JSON.stringify(configData));
}
}

function loadedProjectId(): Buffer | undefined {
return projectState.project_id;
}
Expand Down Expand Up @@ -150,6 +177,10 @@ function loadProjectLatestSha(): string | undefined {
return projectLatestSha.sha;
}

function loadConfigData(): ConfigData | undefined {
return configData;
}

export {
initializeProjectState,
setProjectId,
Expand All @@ -161,4 +192,6 @@ export {
setProjectLatestSha,
loadProjectLatestSha,
loadProjectName, // Add this new export
setConfigData,
loadConfigData,
};
20 changes: 20 additions & 0 deletions dapp/src/types/projectConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export interface ConfigData {
projectName: string;
logoImageLink: string;
thumbnailImageLink: string;
description: string;
companyName: string;
officials: {
websiteLink: string;
githubLink: string;
};
socialLinks: {
twitter: string;
telegram: string;
discord: string;
instagram: string;
};
version: string;
authorGithubNames: string[];
maintainersAddresses: string[];
};

0 comments on commit 97b618d

Please sign in to comment.