From 0d42c289cb4cb9ef9a2a2750d1b0729b421e6096 Mon Sep 17 00:00:00 2001 From: Sosthene00 <674694@protonmail.ch> Date: Wed, 17 Apr 2024 08:41:38 +0200 Subject: [PATCH] mv html to ts, update process acquisition --- crates/sp_client/src/api.rs | 66 +++------ crates/sp_client/src/process.rs | 177 +++++++---------------- src/services.ts | 240 ++++++++++++++++++++++++++------ 3 files changed, 263 insertions(+), 220 deletions(-) diff --git a/crates/sp_client/src/api.rs b/crates/sp_client/src/api.rs index ea6bd9e..2788999 100644 --- a/crates/sp_client/src/api.rs +++ b/crates/sp_client/src/api.rs @@ -197,60 +197,38 @@ pub struct get_process_return(Vec); #[wasm_bindgen] pub fn get_processes() -> ApiResult { - let number_managers: u8 = 5; - - let birthday_signet = 50000; - let mut members: Vec = Vec::with_capacity((number_managers) as usize); - - for _ in 0..number_managers { - //add sp_client - let sp_wallet = generate_sp_wallet(None, birthday_signet, true)?; - let sp_address = sp_wallet.get_client().get_receiving_address(); - members.push(sp_address); - } + let MEMBERS: [String;5] = [ + "tsp1qqdvmxycf3c3tf2qhpev0npx25rj05270d6j2pcsrfk2qn5gdy0rpwq6hd9u9sztl3fwmrzzqafzl3ymkq86aqfz5jl5egdkz72tqmhcnrswdz3pk".to_owned(), + "tsp1qqwafwn7dcr9d6ta0w8fjtd9s53u72x9qmmtgd8adqr7454xl90a5jq3vw23l2x8ypt55nrg7trl9lwz5xr5j357ucu4sf9rfmvc0zujcpqcps6rm".to_owned(), + "tsp1qqw02t5hmg5rxpjdkmjdnnmhvuc76wt6vlqdmn2zafnh6axxjd6e2gqcz04gzvnkzf572mur8spyx2a2s8sqzll2ymdpyz59cpl96j4zuvcdvrzxz".to_owned(), + "tsp1qqgpay2r5jswm7vcv24xd94shdf90w30vxtql9svw7qnlnrzd6xt02q7s7z57uw0sssh6c0xddcrryq4mxup93jsh3gfau3autrawl8umkgsyupkm".to_owned(), + "tsp1qqtsqmtgnxp0lsmnxyxcq52zpgxwugwlq8urlprs5pr5lwyqc789gjqhx5qra6g4rszsq43pms6nguee2l9trx905rk5sgntek05hnf7say4ru69y".to_owned(), + ]; //instances of process let process1 = Process { - id: 1, - name: String::from("CREATE_ID"), + id: 6, + name: String::from("Messaging"), version: String::from("1.0"), - members: members.clone(), - html: crate::process::HTML_CREATE_ID.to_owned(), + members: MEMBERS.to_vec(), + html: crate::process::HTML_MESSAGING.to_owned(), style: crate::process::CSS.to_owned(), script: "".to_owned(), }; let process2 = Process { - id: 2, - name: String::from("UPDATE_ID"), + id: 7, + name: String::from("Kotpart"), version: String::from("1.0"), - members: members.clone(), - html: crate::process::HTML_UPDATE_ID.to_owned(), - style: crate::process::CSSUPDATE.to_owned(), - script: crate::process::JSUPDATE.to_owned(), + members: MEMBERS.to_vec(), + html: crate::process::HTML_MESSAGING.to_owned(), + style: crate::process::CSS.to_owned(), + script: "".to_owned(), }; let process3 = Process { - id: 3, - name: String::from("RECOVER"), + id: 8, + name: String::from("Storage"), version: String::from("1.0"), - members: members.clone(), - html: crate::process::HTML_RECOVER.to_owned(), - style: crate::process::CSS.to_owned(), - script: "".to_owned(), - }; - let process4 = Process { - id: 4, - name: String::from("REVOKE_IMAGE"), - version: String::from("1.0"), - members: members.clone(), - html: crate::process::HTML_REVOKE_IMAGE.to_owned(), - style: crate::process::CSS.to_owned(), - script: "".to_owned(), - }; - let process5 = Process { - id: 5, - name: String::from("REVOKE"), - version: String::from("1.0"), - members: members.clone(), - html: crate::process::HTML_REVOKE.to_owned(), + members: MEMBERS.to_vec(), + html: crate::process::HTML_MESSAGING.to_owned(), style: crate::process::CSS.to_owned(), script: "".to_owned(), }; @@ -260,8 +238,6 @@ pub fn get_processes() -> ApiResult { data_process.push(process1); data_process.push(process2); data_process.push(process3); - data_process.push(process4); - data_process.push(process5); Ok(get_process_return(data_process)) } diff --git a/crates/sp_client/src/process.rs b/crates/sp_client/src/process.rs index 56f95d6..2e6af74 100644 --- a/crates/sp_client/src/process.rs +++ b/crates/sp_client/src/process.rs @@ -6,144 +6,63 @@ use sp_backend::silentpayments::sending::SilentPaymentAddress; use tsify::Tsify; use wasm_bindgen::prelude::*; -pub const HTML_CREATE_ID: &str = " +pub const HTML_KOTPART: &str = "
-

Create an Id

- -
-
- -
- -
-
- -
- Recover -
-
-

-
-
- "; - -pub const HTML_UPDATE_ID: &str = " - -
-
-

Update an Id

-
-
-
- - - - - - - - - - - - - -
-
- - -
-
-
- -
- -
-
- - "; - -pub const HTML_RECOVER: &str = " -
-
-

Recover my Id

- -
-
- - - -
-
- +

Send encrypted messages

-

- Revoke -

-
-
- "; - -pub const HTML_REVOKE_IMAGE: &str = " -
-
-

Revoke image

- -
-
-
- - - - - -
- -
-
- "; - -pub const HTML_REVOKE: &str = " -
-
-

Revoke an Id

-
- - + +
-
- - + + +
+ + +
+ "; + +pub const HTML_STORAGE: &str = " +
+
+

Send encrypted messages

+ +
+
+ +
- + + +
+ +
+
+ "; + +pub const HTML_MESSAGING: &str = " +
+
+

Send encrypted messages

+ +
+
+
+ + +
+ + +
+
"; diff --git a/src/services.ts b/src/services.ts index 7160fbc..e7de153 100644 --- a/src/services.ts +++ b/src/services.ts @@ -24,27 +24,9 @@ class Services { private async init(): Promise { this.sdkClient = await import("../dist/pkg/sdk_client"); this.sdkClient.setup(); + await this.updateProcesses(); } - // public async getSpAddressDefaultClient(): Promise { - // try { - // const indexedDB = await IndexedDB.getInstance(); - // const db = indexedDB.getDb(); - // const spClient = await indexedDB.getObject(db, indexedDB.getStoreList().SpClient, "default"); - - // if (spClient) { - // return this.sdkClient.get_receiving_address(spClient); - // } else { - // console.error("SP client not found"); - // return null; - // } - // } catch (error) { - // console.error("Failed to retrieve object or get sp address:", error); - // return null; - // } - - // } - public async addWebsocketConnection(url: string): Promise { const services = await Services.getInstance(); const newClient = new WebSocketClient(url, services); @@ -70,7 +52,7 @@ class Services { public async displayCreateId(): Promise { const services = await Services.getInstance(); - await services.injectHtml('CREATE_ID'); + await services.createIdInjectHtml(); services.attachSubmitListener("form4nk", (event) => services.createId(event)); services.attachClickListener("displayrecover", services.displayRecover); await services.displayProcess(); @@ -136,8 +118,8 @@ class Services { public async displayRecover(): Promise { const services = await Services.getInstance(); - await services.injectHtml('RECOVER'); - services.attachSubmitListener("form4nk", services.recover); + await services.recoverInjectHtml(); + services.attachSubmitListener("form4nk", (event) => services.recover(event)); services.attachClickListener("displaycreateid", services.displayCreateId); services.attachClickListener("displayrevoke", services.displayRevoke); services.attachClickListener("submitButtonRevoke", services.revoke); @@ -168,7 +150,7 @@ class Services { public async displayRevokeImage(revokeData: Uint8Array): Promise { const services = await Services.getInstance(); - await services.injectHtml('REVOKE_IMAGE'); + await services.revokeImageInjectHtml(); services.attachClickListener("displayupdateanid", services.displayUpdateAnId); let imageBytes = await services.getRecoverImage('assets/4nk_revoke.jpg'); @@ -209,7 +191,7 @@ class Services { public async displayRevoke(): Promise { const services = await Services.getInstance(); - services.injectHtml('REVOKE'); + await services.revokeInjectHtml(); services.attachClickListener("displayrecover", Services.instance.displayRecover); services.attachSubmitListener("form4nk", Services.instance.revoke); } @@ -224,24 +206,8 @@ class Services { public async displayUpdateAnId() { const services = await Services.getInstance(); - console.log("JS displayUpdateAnId process : "+services.current_process); - let body = ""; - let style = ""; - let script = ""; - try { - const processObject = await services.getProcessByName("UPDATE_ID"); - if (processObject) { - body = processObject.html; - style = processObject.style; - script = processObject.script; - console.log("JS displayUpdateAnId body : "+body); + await services.updateIdInjectHtml(); - } - } catch (error) { - console.error("Failed to retrieve process with Error:", error); - } - - services.injectUpdateAnIdHtml(body, style, script); services.attachSubmitListener("form4nk", services.updateAnId); } @@ -370,22 +336,20 @@ class Services { return process; } - public async loadProcesses(): Promise { + public async updateProcesses(): Promise { const services = await Services.getInstance(); const processList: Process[] = services.sdkClient.get_processes(); - console.error('processList size: '+processList.length); processList.forEach(async (process: Process) => { const indexedDB = await IndexedDB.getInstance(); - const db = indexedDB.getDb(); + const db = await indexedDB.getDb(); try { const processStore = await indexedDB.getObject(db, indexedDB.getStoreList().AnkProcess, process.id); if (!processStore) { - console.error('Adding process.id : '+process.id); await indexedDB.writeObject(db, indexedDB.getStoreList().AnkProcess, process, null); } } catch (error) { - console.warn('Error while writing process', process.name, 'to indexedDB:', error); + console.error('Error while writing process', process.name, 'to indexedDB:', error); } }) } @@ -401,6 +365,190 @@ class Services { element?.removeEventListener("submit", callback); element?.addEventListener("submit", callback); } + public async revokeInjectHtml() { + const container = document.getElementById('containerId'); + + if (!container) { + console.error("No html container"); + return; + } + + container.innerHTML = + `
+
+

Revoke an Id

+
+ Recover +
+
+
+ + +
+
+ + +
+
+ +
+
+ `; + } + public async revokeImageInjectHtml() { + const container = document.getElementById('containerId'); + + if (!container) { + console.error("No html container"); + return; + } + + container.innerHTML = + `
+
+

Revoke image

+ +
+
+
+ + + + + +
+ +
+
`; + } + + public async recoverInjectHtml() { + const container = document.getElementById('containerId'); + + if (!container) { + console.error("No html container"); + return; + } + + const services = await Services.getInstance(); + await services.updateProcesses(); + + container.innerHTML = + `
+
+

Recover my Id

+ +
+
+ + + +
+
+ + +

+ Revoke +

+
+
`; + } + + public async createIdInjectHtml() { + const container = document.getElementById('containerId'); + + if (!container) { + console.error("No html container"); + return; + } + + container.innerHTML = + `
+
+

Create an Id

+ +
+
+ +
+ +
+
+ +
+ Recover +
+
+

+
+
`; + } + + public async updateIdInjectHtml() { + const container = document.getElementById('containerId'); + + if (!container) { + console.error("No html container"); + return; + } + + container.innerHTML = + ` +
+
+

Update an Id

+
+
+
+ + + + + + + + + + + + + +
+
+ + +
+
+
+ +
+ +
+
+ `; + } public async injectHtml(processName: string) { const container = document.getElementById('containerId');