Update appinfo

This commit is contained in:
AlphaX-Projects 2023-02-14 12:31:48 +01:00
parent 44cd02a45f
commit 326b21a269
2 changed files with 88 additions and 83 deletions

View File

@ -18,6 +18,7 @@ class AppInfo extends connect(store)(LitElement) {
coreInfo: { type: Array }, coreInfo: { type: Array },
nodeConfig: { type: Object }, nodeConfig: { type: Object },
pageUrl: { type: String }, pageUrl: { type: String },
publicizeAddress: { type: String },
theme: { type: String, reflect: true } theme: { type: String, reflect: true }
} }
} }
@ -95,6 +96,7 @@ class AppInfo extends connect(store)(LitElement) {
this.coreInfo = [] this.coreInfo = []
this.nodeStatus = {} this.nodeStatus = {}
this.pageUrl = '' this.pageUrl = ''
this.publicizeAddress = ''
this.theme = localStorage.getItem('qortalTheme') ? localStorage.getItem('qortalTheme') : 'light' this.theme = localStorage.getItem('qortalTheme') ? localStorage.getItem('qortalTheme') : 'light'
this.publicKeyisOnChainConfirmation = false this.publicKeyisOnChainConfirmation = false
this.interval this.interval
@ -112,22 +114,44 @@ 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) { async confirmPublicKeyOnChain(address) {
const _computePow2 = async (chatBytes) => { const _computePow2 = async (chatBytes) => {
const difficulty = 14; const difficulty = 14
const path = window.parent.location.origin + '/memory-pow/memory-pow.wasm.full' const path = window.parent.location.origin + '/memory-pow/memory-pow.wasm.full'
const worker = new WebWorker(); const worker = new WebWorker();
let nonce = null let nonce = null
let chatBytesArray = null let chatBytesArray = null
await new Promise((res, rej) => { await new Promise((res, rej) => {
worker.postMessage({chatBytes, path, difficulty}); worker.postMessage({chatBytes, path, difficulty})
worker.onmessage = e => { worker.onmessage = e => {
worker.terminate() worker.terminate()
chatBytesArray = e.data.chatBytesArray chatBytesArray = e.data.chatBytesArray
nonce = e.data.nonce nonce = e.data.nonce
res() res()
} }
}) })
@ -137,37 +161,35 @@ class AppInfo extends connect(store)(LitElement) {
chatBytesArray: chatBytesArray, chatBytesArray: chatBytesArray,
chatNonce: nonce chatNonce: nonce
}, },
})
});
return _response return _response
}; }
let stop = false let stop = false
const checkPublicKey = async () => { const checkPublicKey = async () => {
if (!stop) { if (!stop) {
stop = true; stop = true
try { try {
if(this.publicKeyisOnChainConfirmation){ if(localStorage.getItem(this.publicizeAddress) === 'true') {
clearInterval(this.interval) clearInterval(this.interval)
return return
} }
const myNode = store.getState().app.nodeConfig.knownNodes[store.getState().app.nodeConfig.node]; const myNode = store.getState().app.nodeConfig.knownNodes[store.getState().app.nodeConfig.node]
const nodeUrl = myNode.protocol + '://' + myNode.domain + ':' + myNode.port; const nodeUrl = myNode.protocol + '://' + myNode.domain + ':' + myNode.port
const url = `${nodeUrl}/addresses/publickey/${address}`; const url = `${nodeUrl}/addresses/publickey/${address}`
const res = await fetch(url) const res = await fetch(url)
let data = '' let data = ''
try { try {
data = await res.text(); data = await res.text()
} catch (error) { } catch (error) {
data = { data = {
error: 'error' error: 'error'
} }
} }
if(data === 'false' && this.nodeInfo.isSynchronizing !== true) { if(data === 'false' && this.nodeInfo.isSynchronizing !== true) {
let _reference = new Uint8Array(64); let _reference = new Uint8Array(64)
window.crypto.getRandomValues(_reference); window.crypto.getRandomValues(_reference)
let reference = window.parent.Base58.encode(_reference); let reference = window.parent.Base58.encode(_reference)
const chatRes = await routes.chat({ const chatRes = await routes.chat({
data: { data: {
type: 19, type: 19,
@ -177,7 +199,6 @@ class AppInfo extends connect(store)(LitElement) {
proofOfWorkNonce: 0, proofOfWorkNonce: 0,
fee: 0, fee: 0,
timestamp: Date.now(), timestamp: Date.now(),
}, },
disableModal: true disableModal: true
}, },
@ -188,8 +209,8 @@ class AppInfo extends connect(store)(LitElement) {
const powRes = await _computePow2(chatRes) const powRes = await _computePow2(chatRes)
if(powRes === true) { if(powRes === true) {
clearInterval(this.interval) clearInterval(this.interval)
localStorage.removeItem(this.publicizeAddress)
this.publicKeyisOnChainConfirmation = true localStorage.setItem(this.publicizeAddress, 'true')
} }
} catch (error) { } catch (error) {
console.error(error) console.error(error)
@ -198,34 +219,18 @@ class AppInfo extends connect(store)(LitElement) {
if (!data.error && data !== 'false' && data) { if (!data.error && data !== 'false' && data) {
clearInterval(this.interval) clearInterval(this.interval)
localStorage.removeItem(this.publicizeAddress)
this.publicKeyisOnChainConfirmation = true localStorage.setItem(this.publicizeAddress, 'true')
} }
} catch (error) { } catch (error) {
} }
stop = false stop = false
} }
}; }
this.interval = setInterval(checkPublicKey, 5000); 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)
}
async getNodeInfo() { async getNodeInfo() {
const appinfoNode = store.getState().app.nodeConfig.knownNodes[store.getState().app.nodeConfig.node] const appinfoNode = store.getState().app.nodeConfig.knownNodes[store.getState().app.nodeConfig.node]
const appinfoUrl = appinfoNode.protocol + '://' + appinfoNode.domain + ':' + appinfoNode.port const appinfoUrl = appinfoNode.protocol + '://' + appinfoNode.domain + ':' + appinfoNode.port

View File

@ -4686,10 +4686,10 @@ class MultiWallet extends LitElement {
} }
}) })
const txsQort = await parentEpml.request('apiCall', { 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', { 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) { if (this._selectedWallet == coin) {
this.wallets.get(coin).transactions = pendingTxsQort.concat(txsQort) this.wallets.get(coin).transactions = pendingTxsQort.concat(txsQort)