From 326b21a269672474544d9ef9bce77366d4004d5a Mon Sep 17 00:00:00 2001 From: AlphaX-Projects <77661270+AlphaX-Projects@users.noreply.github.com> Date: Tue, 14 Feb 2023 12:31:48 +0100 Subject: [PATCH] Update appinfo --- qortal-ui-core/src/components/app-info.js | 167 +++++++++--------- .../plugins/core/wallet/wallet-app.src.js | 4 +- 2 files changed, 88 insertions(+), 83 deletions(-) diff --git a/qortal-ui-core/src/components/app-info.js b/qortal-ui-core/src/components/app-info.js index 6d0aef89..5ce24ae7 100644 --- a/qortal-ui-core/src/components/app-info.js +++ b/qortal-ui-core/src/components/app-info.js @@ -18,6 +18,7 @@ class AppInfo extends connect(store)(LitElement) { coreInfo: { type: Array }, nodeConfig: { type: Object }, pageUrl: { type: String }, + publicizeAddress: { type: String }, theme: { type: String, reflect: true } } } @@ -95,6 +96,7 @@ class AppInfo extends connect(store)(LitElement) { this.coreInfo = [] this.nodeStatus = {} this.pageUrl = '' + this.publicizeAddress = '' this.theme = localStorage.getItem('qortalTheme') ? localStorage.getItem('qortalTheme') : 'light' this.publicKeyisOnChainConfirmation = false this.interval @@ -112,24 +114,46 @@ 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 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}); - + await new Promise((res, rej) => { + worker.postMessage({chatBytes, path, difficulty}) + worker.onmessage = e => { - worker.terminate() - chatBytesArray = e.data.chatBytesArray + worker.terminate() + chatBytesArray = e.data.chatBytesArray nonce = e.data.nonce res() - } - }) + }) let _response = await routes.sign_chat({ data: { @@ -137,93 +161,74 @@ class AppInfo extends connect(store)(LitElement) { chatBytesArray: chatBytesArray, chatNonce: nonce }, - - }); - return _response - }; + }) + return _response + } - - let stop = false - const checkPublicKey = async () => { - if (!stop) { - stop = true; - try { - if(this.publicKeyisOnChainConfirmation){ - 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 = '' + let stop = false + const checkPublicKey = async () => { + if (!stop) { + stop = true try { - data = await res.text(); - } catch (error) { - data = { - error: 'error' + if(localStorage.getItem(this.publicizeAddress) === 'true') { + clearInterval(this.interval) + return } - } - 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(), - + 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 - }, - disableModal: true, - }); + disableModal: true, + }); try { - const powRes = await _computePow2(chatRes) - if(powRes === true){ + const powRes = await _computePow2(chatRes) + if(powRes === true) { clearInterval(this.interval) - - this.publicKeyisOnChainConfirmation = true + localStorage.removeItem(this.publicizeAddress) + localStorage.setItem(this.publicizeAddress, 'true') } } catch (error) { console.error(error) } } - if (!data.error && data !== 'false' && data) { - clearInterval(this.interval) - - this.publicKeyisOnChainConfirmation = true - } + 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); - } - - firstUpdated() { - this.getNodeInfo() - this.getCoreInfo() - try { - this.confirmPublicKeyOnChain(store.getState().app.selectedAddress.address) - } catch (error) { - console.error(error) - } - - - setInterval(() => { - this.getNodeInfo() - this.getCoreInfo() - }, 30000) + } catch (error) { + } + stop = false + } + } + this.interval = setInterval(checkPublicKey, 5000); } async getNodeInfo() { diff --git a/qortal-ui-plugins/plugins/core/wallet/wallet-app.src.js b/qortal-ui-plugins/plugins/core/wallet/wallet-app.src.js index 01cf544f..c24b550f 100644 --- a/qortal-ui-plugins/plugins/core/wallet/wallet-app.src.js +++ b/qortal-ui-plugins/plugins/core/wallet/wallet-app.src.js @@ -4686,10 +4686,10 @@ class MultiWallet extends LitElement { } }) const txsQort = await parentEpml.request('apiCall', { - url: `/transactions/search?address=${this.wallets.get('qort').wallet.address}&confirmationStatus=CONFIRMED&reverse=true&txType=PAYMENT&txType=REGISTER_NAME&txType=UPDATE_NAME&txType=SELL_NAME&txType=CANCEL_SELL_NAME&txType=BUY_NAME&txType=CREATE_POLL&txType=VOTE_ON_POLL&txType=ISSUE_ASSET&txType=TRANSFER_ASSET&txType=CREATE_ASSET_ORDER&txType=CANCEL_ASSET_ORDER&txType=MULTI_PAYMENT&txType=DEPLOY_AT&txType=MESSAGE&txType=PUBLICIZE&txType=AIRDROP&txType=AT&txType=CREATE_GROUP&txType=UPDATE_GROUP&txType=ADD_GROUP_ADMIN&txType=REMOVE_GROUP_ADMIN&txType=GROUP_BAN&txType=CANCEL_GROUP_BAN&txType=GROUP_KICK&txType=GROUP_INVITE&txType=CANCEL_GROUP_INVITE&txType=JOIN_GROUP&txType=LEAVE_GROUP&txType=GROUP_APPROVAL&txType=SET_GROUP&txType=UPDATE_ASSET&txType=ACCOUNT_FLAGS&txType=ENABLE_FORGING&txType=REWARD_SHARE&txType=ACCOUNT_LEVEL&txType=TRANSFER_PRIVS&txType=PRESENCE`, + url: `/transactions/search?address=${this.wallets.get('qort').wallet.address}&confirmationStatus=CONFIRMED&reverse=true&txType=PAYMENT&txType=REGISTER_NAME&txType=UPDATE_NAME&txType=SELL_NAME&txType=CANCEL_SELL_NAME&txType=BUY_NAME&txType=CREATE_POLL&txType=VOTE_ON_POLL&txType=ISSUE_ASSET&txType=TRANSFER_ASSET&txType=CREATE_ASSET_ORDER&txType=CANCEL_ASSET_ORDER&txType=MULTI_PAYMENT&txType=DEPLOY_AT&txType=MESSAGE&txType=AIRDROP&txType=AT&txType=CREATE_GROUP&txType=UPDATE_GROUP&txType=ADD_GROUP_ADMIN&txType=REMOVE_GROUP_ADMIN&txType=GROUP_BAN&txType=CANCEL_GROUP_BAN&txType=GROUP_KICK&txType=GROUP_INVITE&txType=CANCEL_GROUP_INVITE&txType=JOIN_GROUP&txType=LEAVE_GROUP&txType=GROUP_APPROVAL&txType=SET_GROUP&txType=UPDATE_ASSET&txType=ACCOUNT_FLAGS&txType=ENABLE_FORGING&txType=REWARD_SHARE&txType=ACCOUNT_LEVEL&txType=TRANSFER_PRIVS&txType=PRESENCE`, }) const pendingTxsQort = await parentEpml.request('apiCall', { - url: `/transactions/unconfirmed?creator=${this.wallets.get('qort').wallet.base58PublicKey}&reverse=true&txType=PAYMENT&txType=REGISTER_NAME&txType=UPDATE_NAME&txType=SELL_NAME&txType=CANCEL_SELL_NAME&txType=BUY_NAME&txType=CREATE_POLL&txType=VOTE_ON_POLL&txType=ISSUE_ASSET&txType=TRANSFER_ASSET&txType=CREATE_ASSET_ORDER&txType=CANCEL_ASSET_ORDER&txType=MULTI_PAYMENT&txType=DEPLOY_AT&txType=MESSAGE&txType=PUBLICIZE&txType=AIRDROP&txType=AT&txType=CREATE_GROUP&txType=UPDATE_GROUP&txType=ADD_GROUP_ADMIN&txType=REMOVE_GROUP_ADMIN&txType=GROUP_BAN&txType=CANCEL_GROUP_BAN&txType=GROUP_KICK&txType=GROUP_INVITE&txType=CANCEL_GROUP_INVITE&txType=JOIN_GROUP&txType=LEAVE_GROUP&txType=GROUP_APPROVAL&txType=SET_GROUP&txType=UPDATE_ASSET&txType=ACCOUNT_FLAGS&txType=ENABLE_FORGING&txType=REWARD_SHARE&txType=ACCOUNT_LEVEL&txType=TRANSFER_PRIVS&txType=PRESENCE`, + url: `/transactions/unconfirmed?creator=${this.wallets.get('qort').wallet.base58PublicKey}&reverse=true&txType=PAYMENT&txType=REGISTER_NAME&txType=UPDATE_NAME&txType=SELL_NAME&txType=CANCEL_SELL_NAME&txType=BUY_NAME&txType=CREATE_POLL&txType=VOTE_ON_POLL&txType=ISSUE_ASSET&txType=TRANSFER_ASSET&txType=CREATE_ASSET_ORDER&txType=CANCEL_ASSET_ORDER&txType=MULTI_PAYMENT&txType=DEPLOY_AT&txType=MESSAGE&txType=AIRDROP&txType=AT&txType=CREATE_GROUP&txType=UPDATE_GROUP&txType=ADD_GROUP_ADMIN&txType=REMOVE_GROUP_ADMIN&txType=GROUP_BAN&txType=CANCEL_GROUP_BAN&txType=GROUP_KICK&txType=GROUP_INVITE&txType=CANCEL_GROUP_INVITE&txType=JOIN_GROUP&txType=LEAVE_GROUP&txType=GROUP_APPROVAL&txType=SET_GROUP&txType=UPDATE_ASSET&txType=ACCOUNT_FLAGS&txType=ENABLE_FORGING&txType=REWARD_SHARE&txType=ACCOUNT_LEVEL&txType=TRANSFER_PRIVS&txType=PRESENCE`, }) if (this._selectedWallet == coin) { this.wallets.get(coin).transactions = pendingTxsQort.concat(txsQort)