Rollback electron and cleanup code

This commit is contained in:
AlphaX-Projects
2024-03-17 12:48:05 +01:00
parent f2afe9c147
commit 732f3f97f2
9 changed files with 1838 additions and 2040 deletions

View File

@@ -1,105 +1,70 @@
import {css, html, LitElement} from 'lit'
import {connect} from 'pwa-helpers'
import {store} from '../store.js'
import {doPageUrl} from '../redux/app/app-actions.js'
import {translate} from '../../translate/index.js'
import WebWorker from 'web-worker:./computePowWorker.js';
import {routes} from '../plugins/routes.js';
import '@material/mwc-icon'
import '@material/mwc-button'
import {translate} from '../../translate'
class AppInfo extends connect(store)(LitElement) {
static get properties() {
return {
blockInfo: { type: Object },
nodeStatus: { type: Object },
nodeInfo: { type: Array },
coreInfo: { type: Array },
nodeConfig: { type: Object },
pageUrl: { type: String },
publicizeAddress: { type: String },
theme: { type: String, reflect: true }
}
}
static get styles() {
return [
css`
* {
--mdc-theme-primary: rgb(3, 169, 244);
--paper-input-container-focus-color: var(--mdc-theme-primary);
}
.normal {
--mdc-theme-primary: rgb(3, 169, 244);
}
return css`
* {
--mdc-theme-primary: rgb(3, 169, 244);
--paper-input-container-focus-color: var(--mdc-theme-primary);
}
.normal-button {
--mdc-theme-primary: rgb(3, 169, 244);
--mdc-theme-on-primary: white;
}
.normal {
--mdc-theme-primary: rgb(3, 169, 244);
}
mwc-button.normal-button {
--mdc-theme-primary: rgb(3, 169, 244);
--mdc-theme-on-primary: white;
}
.test-net {
--mdc-theme-primary: black;
}
#profileInMenu {
flex: 0 0 100px;
padding:12px;
border-top: 1px solid var(--border);
background: var(--sidetopbar);
}
.test-net-button {
--mdc-theme-primary: black;
--mdc-theme-on-primary: white;
}
.info {
margin: 0;
font-size: 14px;
font-weight: 100;
display: inline-block;
width: 100%;
padding-bottom: 8px;
color: var(--black);
}
mwc-button.test-net-button {
--mdc-theme-primary: black;
--mdc-theme-on-primary: white;
}
#profileInMenu {
flex: 0 0 100px;
padding:12px;
border-top: 1px solid var(--border);
background: var(--sidetopbar);
}
.info {
margin: 0;
font-size: 14px;
font-weight:100;
display: inline-block;
width:100%;
padding-bottom:8px;
color: var(--black);
}
.blue {
color: #03a9f4;
margin: 0;
font-size: 14px;
font-weight:200;
display: inline;
}
.black {
color: var(--black);
margin: 0;
font-size: 14px;
font-weight:200;
display: inline;
}
`
]
.blue {
color: #03a9f4;
margin: 0;
font-size: 14px;
font-weight: 200;
display: inline;
}
.black {
color: var(--black);
margin: 0;
font-size: 14px;
font-weight: 200;
display: inline;
}
`
}
constructor() {
super()
this.blockInfo = {}
this.nodeInfo = []
this.coreInfo = []
this.nodeStatus = {}
this.pageUrl = ''
this.publicizeAddress = ''
this.theme = localStorage.getItem('qortalTheme') ? localStorage.getItem('qortalTheme') : 'light'
this.publicKeyisOnChainConfirmation = false
this.interval
}
render() {
@@ -115,133 +80,25 @@ class AppInfo extends connect(store)(LitElement) {
}
firstUpdated() {
this.publicizeAddress = store.getState().app.selectedAddress.address + '_publicize'
this.setStorage()
this.getNodeInfo()
this.getCoreInfo()
// try {
// this.confirmPublicKeyOnChain(store.getState().app.selectedAddress.address)
// } catch (error) {
// console.error(error)
// }
setInterval(() => {
this.getNodeInfo()
this.getCoreInfo()
}, 30000)
}
setStorage() {
if (localStorage.getItem(this.publicizeAddress) === null) {
localStorage.setItem(this.publicizeAddress, 'false')
}
}
async confirmPublicKeyOnChain(address) {
const _computePow2 = async (chatBytes) => {
const difficulty = 14
const path = window.parent.location.origin + '/memory-pow/memory-pow.wasm.full'
const worker = new WebWorker();
let nonce = null
let chatBytesArray = null
await new Promise((res, rej) => {
worker.postMessage({chatBytes, path, difficulty})
worker.onmessage = e => {
worker.terminate()
chatBytesArray = e.data.chatBytesArray
nonce = e.data.nonce
res()
}
})
let _response = await routes.sign_chat({
data: {
nonce: store.getState().app.selectedAddress.nonce,
chatBytesArray: chatBytesArray,
chatNonce: nonce
},
})
return _response
}
let stop = false
const checkPublicKey = async () => {
if (!stop) {
stop = true
try {
if(localStorage.getItem(this.publicizeAddress) === 'true') {
clearInterval(this.interval)
return
}
const myNode = store.getState().app.nodeConfig.knownNodes[store.getState().app.nodeConfig.node]
const nodeUrl = myNode.protocol + '://' + myNode.domain + ':' + myNode.port
const url = `${nodeUrl}/addresses/publickey/${address}`
const res = await fetch(url)
let data = ''
try {
data = await res.text()
} catch (error) {
data = {
error: 'error'
}
}
if(data === 'false' && this.nodeInfo.isSynchronizing !== true) {
let _reference = new Uint8Array(64)
window.crypto.getRandomValues(_reference)
let reference = window.parent.Base58.encode(_reference)
const chatRes = await routes.chat({
data: {
type: 19,
nonce: store.getState().app.selectedAddress.nonce,
params: {
lastReference: reference,
proofOfWorkNonce: 0,
fee: 0,
timestamp: Date.now(),
},
disableModal: true
},
disableModal: true,
});
try {
const powRes = await _computePow2(chatRes)
if(powRes === true) {
clearInterval(this.interval)
localStorage.removeItem(this.publicizeAddress)
localStorage.setItem(this.publicizeAddress, 'true')
}
} catch (error) {
console.error(error)
}
}
if (!data.error && data !== 'false' && data) {
clearInterval(this.interval)
localStorage.removeItem(this.publicizeAddress)
localStorage.setItem(this.publicizeAddress, 'true')
}
} catch (error) {
}
stop = false
}
}
this.interval = setInterval(checkPublicKey, 5000);
}, 60000)
}
async getNodeInfo() {
const appinfoNode = store.getState().app.nodeConfig.knownNodes[store.getState().app.nodeConfig.node]
const appinfoUrl = appinfoNode.protocol + '://' + appinfoNode.domain + ':' + appinfoNode.port
const url = `${appinfoUrl}/admin/status`
await fetch(url).then(response => {
return response.json()
})
.then(data => {
}).then(data => {
this.nodeInfo = data
})
.catch(err => {
}).catch(err => {
console.error('Request failed', err)
})
}
@@ -250,13 +107,12 @@ class AppInfo extends connect(store)(LitElement) {
const appinfoNode = store.getState().app.nodeConfig.knownNodes[store.getState().app.nodeConfig.node]
const appinfoUrl = appinfoNode.protocol + '://' + appinfoNode.domain + ':' + appinfoNode.port
const url = `${appinfoUrl}/admin/info`
await fetch(url).then(response => {
return response.json()
})
.then(data => {
}).then(data => {
this.coreInfo = data
})
.catch(err => {
}).catch(err => {
console.error('Request failed', err)
})
}
@@ -283,21 +139,8 @@ class AppInfo extends connect(store)(LitElement) {
return html`<span class="info">${translate("appinfo.coreversion")}: ${this.coreInfo.buildVersion ? this.coreInfo.buildVersion : ''}</span>`
}
gotoPage(url) {
const myLink = this.shadowRoot.querySelector('#pageLink')
myLink.href = url
myLink.click()
store.dispatch(doPageUrl(''))
}
stateChanged(state) {
this.blockInfo = state.app.blockInfo
this.nodeStatus = state.app.nodeStatus
this.nodeConfig = state.app.nodeConfig
this.pageUrl = state.app.pageUrl
if (this.pageUrl.length > 5) {
this.gotoPage(this.pageUrl)
}
}
}

View File

@@ -1,10 +1,7 @@
import {css, html, LitElement} from 'lit'
import {connect} from 'pwa-helpers'
import {store} from '../store.js'
import {translate} from '../../translate/index.js'
import '@polymer/paper-toast'
import '@material/mwc-icon-button'
import {translate} from '../../translate'
class WalletProfile extends connect(store)(LitElement) {
static get properties() {
@@ -12,82 +9,76 @@ class WalletProfile extends connect(store)(LitElement) {
wallet: { type: Object },
nodeConfig: { type: Object },
accountInfo: { type: Object },
imageUrl: { type: String },
theme: { type: String, reflect: true }
}
}
static get styles() {
return [
css`
`
]
return css`
#profileInMenu {
padding: 12px;
border-top: var(--border);
background: var(--sidetopbar);
color: var(--black);
}
#accountName {
margin: 0;
font-size: 18px;
font-weight: 500;
width: 100%;
padding-bottom: 8px;
display: flex;
}
#blocksMinted {
margin:0;
margin-top: 0;
font-size: 12px;
color: #03a9f4;
}
#address {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
margin:0;
margin-top: 8px;
font-size: 11px;
}
.round-fullinfo {
position: relative;
width: 68px;
height: 68px;
border-radius: 50%;
}
.full-info-logo {
width: 68px;
height: 68px;
border-radius: 50%;
}
.inline-block-child {
flex: 1;
}
`
}
constructor() {
super()
this.wallet = {}
this.nodeConfig = {}
this.accountInfo = {
names: [],
addressInfo: {}
}
this.imageUrl = ''
this.theme = localStorage.getItem('qortalTheme') ? localStorage.getItem('qortalTheme') : 'light'
}
render() {
return html`
<style>
#profileInMenu {
padding: 12px;
border-top: var(--border);
background: var(--sidetopbar);
color: var(--black);
}
#profileInMenu:hover {
}
#accountIcon {
font-size:48px;
color: var(--mdc-theme-primary);
display: inline-block;
}
#accountName {
margin: 0;
font-size: 18px;
font-weight:500;
width:100%;
padding-bottom:8px;
display: flex;
}
#blocksMinted {
margin:0;
margin-top: 0;
font-size: 12px;
color: #03a9f4;
}
#address {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
margin:0;
margin-top:8px;
font-size:11px;
}
.round-fullinfo {
position: relative;
width: 68px;
height: 68px;
border-radius: 50%;
}
.full-info-logo {
width: 68px;
height: 68px;
border-radius: 50%;
}
.inline-block-child {
flex: 1;
}
</style>
<div id="profileInMenu">
<div style="padding: 8px 0;">
<div id="accountName">
@@ -102,26 +93,10 @@ class WalletProfile extends connect(store)(LitElement) {
<p id="address">${this.wallet.addresses[0].address}</p>
</div>
</div>
<paper-toast id="toast" horizontal-align="right" vertical-align="top" vertical-offset="64"></paper-toast>
`
}
firstUpdated() {
const container = document.body.querySelector('main-app').shadowRoot.querySelector('app-view').shadowRoot;
const toast = this.shadowRoot.getElementById('toast')
const isMobile = window.matchMedia(`(max-width: ${getComputedStyle(document.body).getPropertyValue('--layout-breakpoint-tablet')})`).matches
if (isMobile) {
toast.verticalAlign = 'bottom'
toast.verticalOffset = 0
}
this.toast = container.appendChild(toast)
}
async getAllWithAddress(myAddress) {
await this.getAddressUserAvatar(myAddress)
}
firstUpdated() {}
getAvatar() {
if (this.accountInfo.names.length === 0) {
@@ -135,9 +110,9 @@ class WalletProfile extends connect(store)(LitElement) {
}
getApiKey() {
const apiNode = store.getState().app.nodeConfig.knownNodes[store.getState().app.nodeConfig.node];
let apiKey = apiNode.apiKey;
return apiKey;
const apiNode = store.getState().app.nodeConfig.knownNodes[store.getState().app.nodeConfig.node]
let apiKey = apiNode.apiKey
return apiKey
}
stateChanged(state) {