From 64d66d961ef4980c4765b743f7505a701958e7ef Mon Sep 17 00:00:00 2001 From: kennycud Date: Sat, 1 Jun 2024 17:39:16 -0700 Subject: [PATCH] added add and remove foreign server support for Q-Apps --- .../plugins/core/qdn/browser/browser.src.js | 104 ++++++++++++++++++ 1 file changed, 104 insertions(+) diff --git a/plugins/plugins/core/qdn/browser/browser.src.js b/plugins/plugins/core/qdn/browser/browser.src.js index f00843b8..55c9ec97 100644 --- a/plugins/plugins/core/qdn/browser/browser.src.js +++ b/plugins/plugins/core/qdn/browser/browser.src.js @@ -2065,6 +2065,110 @@ class WebBrowser extends LitElement { } } + case actions.ADD_FOREIGN_SERVER: { + const requiredFields = ['coin'] + const missingFields = [] + + requiredFields.forEach((field) => { + if (!data[field]) { + missingFields.push(field) + } + }) + + if (missingFields.length > 0) { + const missingFieldsString = missingFields.join(', ') + const errorMsg = `Missing fields: ${missingFieldsString}` + let data = {} + data['error'] = errorMsg + response = JSON.stringify(data) + break + } + + try { + let coin = data.coin; + let host = data.host; + let port = data.port; + let type = data.type; + + const body = { + hostName: host, + port: port, + connectionType: type + } + + const bodyToString = JSON.stringify(body) + + response = await parentEpml.request('apiCall', { + type: 'api', + method: 'POST', + url: `/crosschain/${coin}/addserver?apiKey=${this.getApiKey()}`, + headers: { + 'Accept': '*/*', + 'Content-Type': 'application/json' + }, + body: `${bodyToString}` + }) + } catch (error) { + const data = {} + data['error'] = "Error in add server" + response = JSON.stringify(data) + } finally { + break + } + } + + case actions.REMOVE_FOREIGN_SERVER: { + const requiredFields = ['coin'] + const missingFields = [] + + requiredFields.forEach((field) => { + if (!data[field]) { + missingFields.push(field) + } + }) + + if (missingFields.length > 0) { + const missingFieldsString = missingFields.join(', ') + const errorMsg = `Missing fields: ${missingFieldsString}` + let data = {} + data['error'] = errorMsg + response = JSON.stringify(data) + break + } + + try { + let coin = data.coin; + let host = data.host; + let port = data.port; + let type = data.type; + + const body = { + hostName: host, + port: port, + connectionType: type + } + + const bodyToString = JSON.stringify(body) + + response = await parentEpml.request('apiCall', { + type: 'api', + method: 'POST', + url: `/crosschain/${coin}/removeserver?apiKey=${this.getApiKey()}`, + headers: { + 'Accept': '*/*', + 'Content-Type': 'application/json' + }, + body: `${bodyToString}` + }) + } catch (error) { + const data = {} + data['error'] = "Error in remove server" + response = JSON.stringify(data) + } finally { + break + } + } + case actions.GET_DAY_SUMMARY: { try { response = await parentEpml.request('apiCall', {