From 44c01382012325a990ba1df377147f6e4458c465 Mon Sep 17 00:00:00 2001 From: AlphaX-Projects <77661270+AlphaX-Projects@users.noreply.github.com> Date: Tue, 1 Feb 2022 04:27:39 -0800 Subject: [PATCH] add api key to dialog, setiings auto close after choosed --- .../src/functional-components/mykey-page.js | 100 ++++++++++++++++++ .../functional-components/settings-page.js | 3 +- 2 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 qortal-ui-core/src/functional-components/mykey-page.js diff --git a/qortal-ui-core/src/functional-components/mykey-page.js b/qortal-ui-core/src/functional-components/mykey-page.js new file mode 100644 index 00000000..e8211fac --- /dev/null +++ b/qortal-ui-core/src/functional-components/mykey-page.js @@ -0,0 +1,100 @@ +import { LitElement, html, css } from 'lit-element' +import { connect } from 'pwa-helpers' +import { store } from '../store.js' +import { testApiKey } from '../apiKeyUtils.js' + +import '@material/mwc-dialog' +import '@material/mwc-button' +import '@material/mwc-select' +import '@material/mwc-textfield' +import '@material/mwc-icon' + +import snackbar from './snackbar.js' + +let mykeyDialog + +class MykeyPage extends connect(store)(LitElement) { + static get properties() { + return { + nodeConfig: { type: Object } + } + } + + static get styles() { + return css` + .red { + --mdc-theme-primary: red; + } + ` + } + + constructor() { + super() + this.nodeConfig = {} + } + + render() { + return html` + +
+ +

Please enter the API key for this node. It can be found in a file called "apikey.txt" in the directory where the core is installed. Alternatively, click Cancel to use the core with reduced functionality.

+
+ + Cancel + + + Add + +
+ ` + } + + stateChanged(state) { + this.config = state.config + this.nodeConfig = state.app.nodeConfig + } + + show() { + this.shadowRoot.getElementById('mykeyDialog').show() + } + + async addMykey() { + const mykeyInput = this.shadowRoot.getElementById('mykeyInput').value + let selectedNode = this.nodeConfig.knownNodes[this.nodeConfig.node]; + let testResult = await testApiKey(mykeyInput); + + if (testResult === true) { + selectedNode.apiKey = mykeyInput; + this.nodeConfig.knownNodes[this.nodeConfig.node] = selectedNode; + localStorage.setItem('myQortalNodes', JSON.stringify(this.nodeConfig.knownNodes)); + snackbar.add({ + labelText: 'Successfully Added API Key', + dismiss: true + }) + this.shadowRoot.getElementById('mykeyInput').value = '' + this.shadowRoot.querySelector('#mykeyDialog').close() + } else { + snackbar.add({ + labelText: 'API Key Wrong, No Apikey Added', + dismiss: true + }) + this.shadowRoot.getElementById('mykeyInput').value = '' + this.shadowRoot.querySelector('#mykeyDialog').close() + } + } +} + +window.customElements.define('mykey-page', MykeyPage) + +const mykey = document.createElement('mykey-page') +mykeyDialog = document.body.appendChild(mykey) + +export default mykeyDialog diff --git a/qortal-ui-core/src/functional-components/settings-page.js b/qortal-ui-core/src/functional-components/settings-page.js index 02470517..0a660c33 100644 --- a/qortal-ui-core/src/functional-components/settings-page.js +++ b/qortal-ui-core/src/functional-components/settings-page.js @@ -42,7 +42,7 @@ class SettingsPage extends connect(store)(LitElement) {
- + ${this.nodeConfig.knownNodes.map((n, index) => html` ${n.protocol + '://' + n.domain + ':' + n.port} `)} @@ -109,6 +109,7 @@ class SettingsPage extends connect(store)(LitElement) { labelText: `UI Set To Node : ${selectedNodeUrl}`, dismiss: true }) + this.shadowRoot.querySelector('#settingsDialog').close() } addNode() {