mirror of
https://github.com/Qortal/qortal-ui.git
synced 2025-07-31 14:11:45 +00:00
Added qortal requests
This commit is contained in:
@@ -1,6 +1,15 @@
|
||||
// IS_USING_PUBLIC_NODE
|
||||
export const IS_USING_PUBLIC_NODE = 'IS_USING_PUBLIC_NODE'
|
||||
|
||||
// GET_ARRR_SYNC_STATUS
|
||||
export const GET_ARRR_SYNC_STATUS = 'GET_ARRR_SYNC_STATUS'
|
||||
|
||||
// GET_NODE_INFO
|
||||
export const GET_NODE_INFO = 'GET_NODE_INFO'
|
||||
|
||||
// GET_NODE_STATUS
|
||||
export const GET_NODE_STATUS = 'GET_NODE_STATUS'
|
||||
|
||||
// ADMIN_ACTION
|
||||
export const ADMIN_ACTION = 'ADMIN_ACTION'
|
||||
|
||||
@@ -123,6 +132,9 @@ export const OPEN_PROFILE = 'OPEN_PROFILE'
|
||||
// GET_USER_WALLET
|
||||
export const GET_USER_WALLET = 'GET_USER_WALLET'
|
||||
|
||||
// GET_USER_WALLET_TRANSACTIONS
|
||||
export const GET_USER_WALLET_TRANSACTIONS = 'GET_USER_WALLET_TRANSACTIONS'
|
||||
|
||||
// GET_WALLET_BALANCE
|
||||
export const GET_WALLET_BALANCE = 'GET_WALLET_BALANCE'
|
||||
|
||||
|
@@ -13,7 +13,10 @@ import {
|
||||
processTransactionV2,
|
||||
publishData,
|
||||
requestQueueGetAtAddresses,
|
||||
tradeBotCreateRequest
|
||||
tradeBotCreateRequest,
|
||||
getArrrSyncStatus,
|
||||
getNodeInfo,
|
||||
getNodeStatus
|
||||
} from '../../../utils/classes'
|
||||
import {appendBuffer} from '../../../utils/utilities'
|
||||
import {QORT_DECIMALS} from '../../../../../crypto/api/constants'
|
||||
@@ -319,6 +322,21 @@ class WebBrowser extends LitElement {
|
||||
}
|
||||
break
|
||||
|
||||
case actions.GET_ARRR_SYNC_STATUS: {
|
||||
response = await getArrrSyncStatus()
|
||||
}
|
||||
break
|
||||
|
||||
case actions.GET_NODE_INFO: {
|
||||
response = await getNodeInfo()
|
||||
}
|
||||
break
|
||||
|
||||
case actions.GET_NODE_STATUS: {
|
||||
response = await getNodeStatus()
|
||||
}
|
||||
break
|
||||
|
||||
case actions.ADMIN_ACTION: {
|
||||
let type = data.type
|
||||
let value = data.value
|
||||
@@ -2701,6 +2719,132 @@ class WebBrowser extends LitElement {
|
||||
}
|
||||
break
|
||||
|
||||
case actions.GET_USER_WALLET_TRANSACTIONS: {
|
||||
const requiredFields = ['coin']
|
||||
const missingFields = []
|
||||
let dataSentBack = {}
|
||||
let skip = false
|
||||
let res3
|
||||
requiredFields.forEach((field) => {
|
||||
if (!data[field]) {
|
||||
missingFields.push(field)
|
||||
}
|
||||
})
|
||||
if (missingFields.length > 0) {
|
||||
const missingFieldsString = missingFields.join(', ')
|
||||
const tryAgain = get("walletpage.wchange44")
|
||||
await showErrorAndWait(
|
||||
"MISSING_FIELDS",
|
||||
{
|
||||
id1: missingFieldsString,
|
||||
id2: tryAgain
|
||||
}
|
||||
)
|
||||
dataSentBack['error'] = `Missing fields: ${missingFieldsString}`
|
||||
response = JSON.stringify(dataSentBack)
|
||||
break
|
||||
}
|
||||
if (window.parent.reduxStore.getState().app.qAPPAutoTransactions) {
|
||||
skip = true
|
||||
}
|
||||
if (!skip) {
|
||||
res3 = await showModalAndWait(
|
||||
actions.GET_USER_WALLET_TRANSACTIONS
|
||||
)
|
||||
}
|
||||
if ((res3 && res3.action === 'accept') || skip) {
|
||||
let coin = data.coin
|
||||
if (coin === "QORT") {
|
||||
let qortAddress = window.parent.reduxStore.getState().app.selectedAddress.address
|
||||
try {
|
||||
this.loader.show()
|
||||
response = await parentEpml.request('apiCall', {
|
||||
url: `/transactions/address/${qortAddress}?limit=0&reverse=true`
|
||||
})
|
||||
this.loader.hide()
|
||||
break
|
||||
} catch (error) {
|
||||
this.loader.hide()
|
||||
let myMsg1 = get("browserpage.bchange21")
|
||||
let myMsg2 = get("walletpage.wchange44")
|
||||
await showErrorAndWait("ACTION_FAILED", {id1: myMsg1, id2: myMsg2})
|
||||
const data = {}
|
||||
data['error'] = error.message ? error.message : get("browserpage.bchange21")
|
||||
response = JSON.stringify(data)
|
||||
}
|
||||
} else {
|
||||
let _url = ``
|
||||
let _body = null
|
||||
switch (coin) {
|
||||
case 'BTC':
|
||||
_url = `/crosschain/btc/wallettransactions?apiKey=${this.getApiKey()}`
|
||||
_body = window.parent.reduxStore.getState().app.selectedAddress.btcWallet.derivedMasterPublicKey
|
||||
break
|
||||
case 'LTC':
|
||||
_url = `/crosschain/ltc/wallettransactions?apiKey=${this.getApiKey()}`
|
||||
_body = window.parent.reduxStore.getState().app.selectedAddress.ltcWallet.derivedMasterPublicKey
|
||||
break
|
||||
case 'DOGE':
|
||||
_url = `/crosschain/doge/wallettransactions?apiKey=${this.getApiKey()}`
|
||||
_body = window.parent.reduxStore.getState().app.selectedAddress.dogeWallet.derivedMasterPublicKey
|
||||
break
|
||||
case 'DGB':
|
||||
_url = `/crosschain/dgb/wallettransactions?apiKey=${this.getApiKey()}`
|
||||
_body = window.parent.reduxStore.getState().app.selectedAddress.dgbWallet.derivedMasterPublicKey
|
||||
break
|
||||
case 'RVN':
|
||||
_url = `/crosschain/rvn/wallettransactions?apiKey=${this.getApiKey()}`
|
||||
_body = window.parent.reduxStore.getState().app.selectedAddress.rvnWallet.derivedMasterPublicKey
|
||||
break
|
||||
case 'ARRR':
|
||||
_url = `/crosschain/arrr/wallettransactions?apiKey=${this.getApiKey()}`
|
||||
_body = window.parent.reduxStore.getState().app.selectedAddress.arrrWallet.seed58
|
||||
break
|
||||
default:
|
||||
break
|
||||
}
|
||||
try {
|
||||
this.loader.show()
|
||||
const res = await parentEpml.request('apiCall', {
|
||||
url: _url,
|
||||
method: 'POST',
|
||||
body: _body
|
||||
})
|
||||
if (!res.ok) {
|
||||
this.loader.hide()
|
||||
let myMsg1 = get("browserpage.bchange21")
|
||||
let myMsg2 = get("walletpage.wchange44")
|
||||
await showErrorAndWait("ACTION_FAILED", { id1: myMsg1, id2: myMsg2 })
|
||||
const data = {}
|
||||
data['error'] = get("browserpage.bchange21")
|
||||
response = JSON.stringify(data)
|
||||
break
|
||||
} else {
|
||||
this.loader.hide()
|
||||
response = res
|
||||
break
|
||||
}
|
||||
} catch (error) {
|
||||
this.loader.hide()
|
||||
let myMsg1 = get("browserpage.bchange21")
|
||||
let myMsg2 = get("walletpage.wchange44")
|
||||
await showErrorAndWait("ACTION_FAILED", { id1: myMsg1, id2: myMsg2 })
|
||||
const data = {}
|
||||
data['error'] = error.message ? error.message : get("browserpage.bchange21")
|
||||
response = JSON.stringify(data)
|
||||
break
|
||||
}
|
||||
}
|
||||
} else if (res3.action === 'reject') {
|
||||
let myMsg1 = get("transactions.declined")
|
||||
let myMsg2 = get("walletpage.wchange44")
|
||||
await showErrorAndWait("DECLINED_REQUEST", { id1: myMsg1, id2: myMsg2 })
|
||||
response = '{"error": "User declined request"}'
|
||||
break
|
||||
}
|
||||
}
|
||||
break
|
||||
|
||||
case actions.GET_WALLET_BALANCE: {
|
||||
const requiredFields = ['coin']
|
||||
const missingFields = []
|
||||
@@ -5226,7 +5370,6 @@ async function showModalAndWait(type, data) {
|
||||
${type === actions.GET_PROFILE_DATA ? `
|
||||
<div class="modal-subcontainer">
|
||||
<p class="modal-paragraph">${get("browserpage.bchange49")}: <span style="font-weight: bold"> ${data.property}</span></p>
|
||||
|
||||
</div>
|
||||
` : ''}
|
||||
|
||||
@@ -5294,6 +5437,18 @@ async function showModalAndWait(type, data) {
|
||||
<p class="modal-paragraph">${data.text3}</p>
|
||||
<p class="modal-paragraph">${get("walletpage.wchange36")}: <span>${data.fee}</span></p>
|
||||
` : ''}
|
||||
|
||||
${type === actions.GET_USER_WALLET_TRANSACTIONS ? `
|
||||
<div class="modal-subcontainer">
|
||||
<p class="modal-paragraph">Do you give this application permission to retrieve your wallet transactions?</p>
|
||||
<div class="checkbox-row">
|
||||
<label for="transactionsButton" id="transactionsButtonLabel" style="color: var(--black);">
|
||||
Always allow wallet txs to be retrieved automatically
|
||||
</label>
|
||||
<mwc-checkbox style="margin-right: -15px;" id="transactionsButton" ?checked=${window.parent.reduxStore.getState().app.qAPPAutoTransactions}></mwc-checkbox>
|
||||
</div>
|
||||
</div>
|
||||
` : ''}
|
||||
</div>
|
||||
<div class="modal-buttons">
|
||||
<button id="cancel-button">${get("browserpage.bchange27")}</button>
|
||||
@@ -5365,7 +5520,7 @@ async function showModalAndWait(type, data) {
|
||||
})
|
||||
}
|
||||
|
||||
const checkbox1 = modal.querySelector('#abalanceButton')
|
||||
const checkbox1 = modal.querySelector('#balanceButton')
|
||||
if (checkbox1) {
|
||||
checkbox1.addEventListener('click', (e) => {
|
||||
if (e.target.checked) {
|
||||
@@ -5394,6 +5549,24 @@ async function showModalAndWait(type, data) {
|
||||
})
|
||||
}
|
||||
|
||||
const labelButton3 = modal.querySelector('#transactionsButtonLabel')
|
||||
if (labelButton3) {
|
||||
labelButton1.addEventListener('click', () => {
|
||||
this.shadowRoot.getElementById('transactionsButton').click()
|
||||
})
|
||||
}
|
||||
|
||||
const checkbox3 = modal.querySelector('#transactionsButton')
|
||||
if (checkbox3) {
|
||||
checkbox1.addEventListener('click', (e) => {
|
||||
if (e.target.checked) {
|
||||
window.parent.reduxStore.dispatch(window.parent.reduxAction.removeQAPPAutoTransacions(false))
|
||||
return
|
||||
}
|
||||
window.parent.reduxStore.dispatch(window.parent.reduxAction.allowQAPPAutoTransacions(true))
|
||||
})
|
||||
}
|
||||
|
||||
const labelButtonFriendsList = modal.querySelector('#friendsListLabel')
|
||||
if (labelButtonFriendsList) {
|
||||
labelButtonFriendsList.addEventListener('click', () => {
|
||||
|
@@ -1552,3 +1552,99 @@ export const cancelTradeOfferTradeBot = async (body, keyPair) => {
|
||||
throw new Error("Failed to Cancel Sell Order. Try again!")
|
||||
}
|
||||
}
|
||||
|
||||
export const getArrrSyncStatus = async () => {
|
||||
const myNode = window.parent.reduxStore.getState().app.nodeConfig.knownNodes[window.parent.reduxStore.getState().app.nodeConfig.node]
|
||||
const nodeUrl = `${myNode.protocol}://${myNode.domain}:${myNode.port}`
|
||||
const myApiKey = myNode.apiKey
|
||||
const url = `${nodeUrl}/crosschain/arrr/syncstatus?apiKey=${myApiKey}`
|
||||
const arrrSeed = window.parent.reduxStore.getState().app.selectedAddress.arrrWallet.seed58
|
||||
|
||||
try {
|
||||
const response = await fetch(url, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
Accept: "*/*"
|
||||
},
|
||||
body: arrrSeed
|
||||
})
|
||||
|
||||
let res
|
||||
|
||||
try {
|
||||
res = await response.clone().json()
|
||||
} catch (e) {
|
||||
res = await response.text()
|
||||
}
|
||||
|
||||
return res
|
||||
} catch (error) {
|
||||
console.error(error.message || "Error in retrieving arrr sync status")
|
||||
}
|
||||
}
|
||||
|
||||
export const getNodeInfo = async () => {
|
||||
const myNode = window.parent.reduxStore.getState().app.nodeConfig.knownNodes[window.parent.reduxStore.getState().app.nodeConfig.node]
|
||||
const nodeUrl = `${myNode.protocol}://${myNode.domain}:${myNode.port}`
|
||||
const url = `${nodeUrl}/admin/info`
|
||||
|
||||
try {
|
||||
const response = await fetch(url, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
Accept: "*/*"
|
||||
}
|
||||
})
|
||||
|
||||
if (!response.ok) console.error("Failed to retrieve node info")
|
||||
|
||||
let res
|
||||
|
||||
try {
|
||||
res = await response.clone().json()
|
||||
} catch (e) {
|
||||
res = await response.text()
|
||||
}
|
||||
|
||||
if (res.error && res.message) {
|
||||
console.error(res.message)
|
||||
}
|
||||
|
||||
return res
|
||||
} catch (error) {
|
||||
console.error(error.message || "Error in retrieving node info")
|
||||
}
|
||||
}
|
||||
|
||||
export const getNodeStatus = async () => {
|
||||
const myNode = window.parent.reduxStore.getState().app.nodeConfig.knownNodes[window.parent.reduxStore.getState().app.nodeConfig.node]
|
||||
const nodeUrl = `${myNode.protocol}://${myNode.domain}:${myNode.port}`
|
||||
const url = `${nodeUrl}/admin/status`
|
||||
|
||||
try {
|
||||
const response = await fetch(url, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
Accept: "*/*"
|
||||
}
|
||||
})
|
||||
|
||||
if (!response.ok) console.error("Failed to retrieve node status")
|
||||
|
||||
let res
|
||||
|
||||
try {
|
||||
res = await response.clone().json()
|
||||
} catch (e) {
|
||||
res = await response.text()
|
||||
}
|
||||
|
||||
if (res.error && res.message) {
|
||||
console.error(res.message)
|
||||
}
|
||||
|
||||
return res
|
||||
} catch (error) {
|
||||
console.error(error.message || "Error in retrieving node status")
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user