Fix response

This commit is contained in:
AlphaX-Qortal 2025-03-19 09:19:54 +01:00
parent 9dbc4b085b
commit e4eede5087

View File

@ -2703,6 +2703,7 @@ class WebBrowser extends LitElement {
break break
case 'ARRR': case 'ARRR':
userWallet['address'] = arrrAddress userWallet['address'] = arrrAddress
userWallet['publicKey'] = window.parent.reduxStore.getState().app.selectedAddress.arrrWallet.seed58
break break
default: default:
break break
@ -2723,8 +2724,8 @@ class WebBrowser extends LitElement {
const requiredFields = ['coin'] const requiredFields = ['coin']
const missingFields = [] const missingFields = []
let dataSentBack = {} let dataSentBack = {}
let skip = false let skipWalletTransactions = false
let res3 let resSkipWalletTransactions
requiredFields.forEach((field) => { requiredFields.forEach((field) => {
if (!data[field]) { if (!data[field]) {
missingFields.push(field) missingFields.push(field)
@ -2745,32 +2746,30 @@ class WebBrowser extends LitElement {
break break
} }
if (window.parent.reduxStore.getState().app.qAPPAutoTransactions) { if (window.parent.reduxStore.getState().app.qAPPAutoTransactions) {
skip = true skipWalletTransactions = true
} }
if (!skip) { if (!skipWalletTransactions) {
res3 = await showModalAndWait( resSkipWalletTransactions = await showModalAndWait(
actions.GET_USER_WALLET_TRANSACTIONS actions.GET_USER_WALLET_TRANSACTIONS
) )
} }
if ((res3 && res3.action === 'accept') || skip) { if ((resSkipWalletTransactions && resSkipWalletTransactions.action === 'accept') || skipWalletTransactions) {
let coin = data.coin let coin = data.coin
if (coin === "QORT") { if (coin === "QORT") {
let qortAddress = window.parent.reduxStore.getState().app.selectedAddress.address let qortAddress = window.parent.reduxStore.getState().app.selectedAddress.address
try { try {
this.loader.show()
response = await parentEpml.request('apiCall', { response = await parentEpml.request('apiCall', {
url: `/transactions/address/${qortAddress}?limit=0&reverse=true` url: `/transactions/address/${qortAddress}?limit=0&reverse=true`
}) })
this.loader.hide()
break break
} catch (error) { } catch (error) {
this.loader.hide()
let myMsg1 = get("browserpage.bchange21") let myMsg1 = get("browserpage.bchange21")
let myMsg2 = get("walletpage.wchange44") let myMsg2 = get("walletpage.wchange44")
await showErrorAndWait("ACTION_FAILED", {id1: myMsg1, id2: myMsg2}) await showErrorAndWait("ACTION_FAILED", {id1: myMsg1, id2: myMsg2})
const data = {} const data = {}
data['error'] = error.message ? error.message : get("browserpage.bchange21") data['error'] = error.message ? error.message : get("browserpage.bchange21")
response = JSON.stringify(data) response = JSON.stringify(data)
break
} }
} else { } else {
let _url = `` let _url = ``
@ -2804,28 +2803,13 @@ class WebBrowser extends LitElement {
break break
} }
try { try {
this.loader.show() response = await parentEpml.request('apiCall', {
const res = await parentEpml.request('apiCall', {
url: _url, url: _url,
method: 'POST', method: 'POST',
body: _body body: _body
}) })
if (!res.ok) { break
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) { } catch (error) {
this.loader.hide()
let myMsg1 = get("browserpage.bchange21") let myMsg1 = get("browserpage.bchange21")
let myMsg2 = get("walletpage.wchange44") let myMsg2 = get("walletpage.wchange44")
await showErrorAndWait("ACTION_FAILED", { id1: myMsg1, id2: myMsg2 }) await showErrorAndWait("ACTION_FAILED", { id1: myMsg1, id2: myMsg2 })
@ -2835,7 +2819,7 @@ class WebBrowser extends LitElement {
break break
} }
} }
} else if (res3.action === 'reject') { } else if (resSkipWalletTransactions.action === 'reject') {
let myMsg1 = get("transactions.declined") let myMsg1 = get("transactions.declined")
let myMsg2 = get("walletpage.wchange44") let myMsg2 = get("walletpage.wchange44")
await showErrorAndWait("DECLINED_REQUEST", { id1: myMsg1, id2: myMsg2 }) await showErrorAndWait("DECLINED_REQUEST", { id1: myMsg1, id2: myMsg2 })
@ -2849,8 +2833,8 @@ class WebBrowser extends LitElement {
const requiredFields = ['coin'] const requiredFields = ['coin']
const missingFields = [] const missingFields = []
let dataSentBack = {} let dataSentBack = {}
let skip = false let skipWalletBalance = false
let res3 let resSkipWalletBalance
requiredFields.forEach((field) => { requiredFields.forEach((field) => {
if (!data[field]) { if (!data[field]) {
missingFields.push(field) missingFields.push(field)
@ -2875,32 +2859,30 @@ class WebBrowser extends LitElement {
// then set the response string from the core to the `response` variable (defined above) // then set the response string from the core to the `response` variable (defined above)
// If they decline, send back JSON that includes an `error` key, such as `{"error": "User declined request"}` // If they decline, send back JSON that includes an `error` key, such as `{"error": "User declined request"}`
if (window.parent.reduxStore.getState().app.qAPPAutoBalance) { if (window.parent.reduxStore.getState().app.qAPPAutoBalance) {
skip = true skipWalletBalance = true
} }
if (!skip) { if (!skipWalletBalance) {
res3 = await showModalAndWait( resSkipWalletBalance = await showModalAndWait(
actions.GET_WALLET_BALANCE actions.GET_WALLET_BALANCE
) )
} }
if ((res3 && res3.action === 'accept') || skip) { if ((resSkipWalletBalance && resSkipWalletBalance.action === 'accept') || skipWalletBalance) {
let coin = data.coin let coin = data.coin
if (coin === "QORT") { if (coin === "QORT") {
let qortAddress = window.parent.reduxStore.getState().app.selectedAddress.address let qortAddress = window.parent.reduxStore.getState().app.selectedAddress.address
try { try {
this.loader.show()
response = await parentEpml.request('apiCall', { response = await parentEpml.request('apiCall', {
url: `/addresses/balance/${qortAddress}?apiKey=${this.getApiKey()}` url: `/addresses/balance/${qortAddress}?apiKey=${this.getApiKey()}`
}) })
this.loader.hide()
break break
} catch (error) { } catch (error) {
this.loader.hide()
let myMsg1 = get("browserpage.bchange21") let myMsg1 = get("browserpage.bchange21")
let myMsg2 = get("walletpage.wchange44") let myMsg2 = get("walletpage.wchange44")
await showErrorAndWait("ACTION_FAILED", {id1: myMsg1, id2: myMsg2}) await showErrorAndWait("ACTION_FAILED", {id1: myMsg1, id2: myMsg2})
const data = {} const data = {}
data['error'] = error.message ? error.message : get("browserpage.bchange21") data['error'] = error.message ? error.message : get("browserpage.bchange21")
response = JSON.stringify(data) response = JSON.stringify(data)
break
} }
} else { } else {
let _url = `` let _url = ``
@ -2934,14 +2916,12 @@ class WebBrowser extends LitElement {
break break
} }
try { try {
this.loader.show()
const res = await parentEpml.request('apiCall', { const res = await parentEpml.request('apiCall', {
url: _url, url: _url,
method: 'POST', method: 'POST',
body: _body body: _body
}) })
if (isNaN(Number(res))) { if (isNaN(Number(res))) {
this.loader.hide()
let myMsg1 = get("browserpage.bchange21") let myMsg1 = get("browserpage.bchange21")
let myMsg2 = get("walletpage.wchange44") let myMsg2 = get("walletpage.wchange44")
await showErrorAndWait("ACTION_FAILED", { id1: myMsg1, id2: myMsg2 }) await showErrorAndWait("ACTION_FAILED", { id1: myMsg1, id2: myMsg2 })
@ -2950,12 +2930,10 @@ class WebBrowser extends LitElement {
response = JSON.stringify(data) response = JSON.stringify(data)
break break
} else { } else {
this.loader.hide()
response = (Number(res) / 1e8).toFixed(8) response = (Number(res) / 1e8).toFixed(8)
break break
} }
} catch (error) { } catch (error) {
this.loader.hide()
let myMsg1 = get("browserpage.bchange21") let myMsg1 = get("browserpage.bchange21")
let myMsg2 = get("walletpage.wchange44") let myMsg2 = get("walletpage.wchange44")
await showErrorAndWait("ACTION_FAILED", { id1: myMsg1, id2: myMsg2 }) await showErrorAndWait("ACTION_FAILED", { id1: myMsg1, id2: myMsg2 })
@ -2965,7 +2943,7 @@ class WebBrowser extends LitElement {
break break
} }
} }
} else if (res3.action === 'reject') { } else if (resSkipWalletBalance.action === 'reject') {
let myMsg1 = get("transactions.declined") let myMsg1 = get("transactions.declined")
let myMsg2 = get("walletpage.wchange44") let myMsg2 = get("walletpage.wchange44")
await showErrorAndWait("DECLINED_REQUEST", { id1: myMsg1, id2: myMsg2 }) await showErrorAndWait("DECLINED_REQUEST", { id1: myMsg1, id2: myMsg2 })
@ -2978,7 +2956,9 @@ class WebBrowser extends LitElement {
case actions.GET_USER_WALLET_INFO: { case actions.GET_USER_WALLET_INFO: {
const requiredFields = ['coin'] const requiredFields = ['coin']
const missingFields = [] const missingFields = []
let skipUserWalletInfo = false
let dataSentBack = {} let dataSentBack = {}
let resSkipUserWalletInfo
requiredFields.forEach((field) => { requiredFields.forEach((field) => {
if (!data[field]) { if (!data[field]) {
missingFields.push(field) missingFields.push(field)
@ -2998,16 +2978,20 @@ class WebBrowser extends LitElement {
response = JSON.stringify(dataSentBack) response = JSON.stringify(dataSentBack)
break break
} }
const userWallet = await showModalAndWait( if (window.parent.reduxStore.getState().app.qAPPAutoAuth) {
actions.GET_USER_WALLET skipUserWalletInfo = true
) }
if (userWallet.action === 'accept') { if (!skipUserWalletInfo) {
resSkipUserWalletInfo = await showModalAndWait(
actions.GET_USER_WALLET
)
}
if ((resSkipUserWalletInfo && resSkipUserWalletInfo.action === 'accept') || skipUserWalletInfo) {
let coin = data.coin let coin = data.coin
let walletKeys = this.getUserWallet(coin) let walletKeys = this.getUserWallet(coin)
let _url = `/crosschain/` + data.coin.toLowerCase() + `/addressinfos?apiKey=${this.getApiKey()}` let _url = `/crosschain/` + data.coin.toLowerCase() + `/addressinfos?apiKey=${this.getApiKey()}`
let _body = { xpub58: walletKeys['publicKey'] } let _body = { xpub58: walletKeys['publicKey'] }
try { try {
this.loader.show()
const bodyToString = JSON.stringify(_body) const bodyToString = JSON.stringify(_body)
const res = await parentEpml.request('apiCall', { const res = await parentEpml.request('apiCall', {
url: _url, url: _url,
@ -3020,7 +3004,6 @@ class WebBrowser extends LitElement {
}) })
response = JSON.stringify(res) response = JSON.stringify(res)
} catch (error) { } catch (error) {
this.loader.hide()
let myMsg1 = get("browserpage.bchange21") let myMsg1 = get("browserpage.bchange21")
let myMsg2 = get("walletpage.wchange44") let myMsg2 = get("walletpage.wchange44")
await showErrorAndWait("ACTION_FAILED", { id1: myMsg1, id2: myMsg2 }) await showErrorAndWait("ACTION_FAILED", { id1: myMsg1, id2: myMsg2 })
@ -3028,10 +3011,8 @@ class WebBrowser extends LitElement {
data['error'] = error.message ? error.message : get("browserpage.bchange21") data['error'] = error.message ? error.message : get("browserpage.bchange21")
response = JSON.stringify(data) response = JSON.stringify(data)
return return
} finally {
this.loader.hide()
} }
} else if (userWallet.action === 'reject') { } else if (resSkipUserWalletInfo.action === 'reject') {
let myMsg1 = get("transactions.declined") let myMsg1 = get("transactions.declined")
let myMsg2 = get("walletpage.wchange44") let myMsg2 = get("walletpage.wchange44")
await showErrorAndWait("DECLINED_REQUEST", { id1: myMsg1, id2: myMsg2 }) await showErrorAndWait("DECLINED_REQUEST", { id1: myMsg1, id2: myMsg2 })
@ -3065,7 +3046,6 @@ class WebBrowser extends LitElement {
} }
let _url = `/crosschain/` + data.coin.toLowerCase() + `/serverinfos` let _url = `/crosschain/` + data.coin.toLowerCase() + `/serverinfos`
try { try {
this.loader.show()
const res = await parentEpml.request('apiCall', { const res = await parentEpml.request('apiCall', {
url: _url, url: _url,
method: 'GET', method: 'GET',
@ -3075,7 +3055,6 @@ class WebBrowser extends LitElement {
}) })
response = JSON.stringify(res.servers) response = JSON.stringify(res.servers)
} catch (error) { } catch (error) {
this.loader.hide()
let myMsg1 = get("modals.mpchange55") let myMsg1 = get("modals.mpchange55")
let myMsg2 = get("walletpage.wchange44") let myMsg2 = get("walletpage.wchange44")
await showErrorAndWait("ACTION_FAILED", { id1: myMsg1, id2: myMsg2 }) await showErrorAndWait("ACTION_FAILED", { id1: myMsg1, id2: myMsg2 })
@ -3083,8 +3062,6 @@ class WebBrowser extends LitElement {
data['error'] = error.message ? error.message : get("modals.mpchange55") data['error'] = error.message ? error.message : get("modals.mpchange55")
response = JSON.stringify(data) response = JSON.stringify(data)
return return
} finally {
this.loader.hide()
} }
} }
break break