mirror of
https://github.com/Qortal/qortal-ui.git
synced 2025-02-12 02:05:51 +00:00
fixes
This commit is contained in:
parent
fb9da8d1d4
commit
697157c79f
@ -19,6 +19,7 @@ import WebWorker from 'web-worker:./computePowWorkerFile.src.js';
|
|||||||
import WebWorkerChat from 'web-worker:./computePowWorker.src.js';
|
import WebWorkerChat from 'web-worker:./computePowWorker.src.js';
|
||||||
import { publishData } from '../../../utils/publish-image.js';
|
import { publishData } from '../../../utils/publish-image.js';
|
||||||
import { Loader } from '../../../utils/loader.js';
|
import { Loader } from '../../../utils/loader.js';
|
||||||
|
import { QORT_DECIMALS } from 'qortal-ui-crypto/api/constants';
|
||||||
const parentEpml = new Epml({ type: 'WINDOW', source: window.parent });
|
const parentEpml = new Epml({ type: 'WINDOW', source: window.parent });
|
||||||
|
|
||||||
class WebBrowser extends LitElement {
|
class WebBrowser extends LitElement {
|
||||||
@ -818,7 +819,24 @@ class WebBrowser extends LitElement {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
|
|
||||||
case 'GET_WALLET_BALANCE':
|
case 'GET_WALLET_BALANCE': {
|
||||||
|
const requiredFields = ['coin'];
|
||||||
|
const missingFields = [];
|
||||||
|
|
||||||
|
requiredFields.forEach((field) => {
|
||||||
|
if (!data[field]) {
|
||||||
|
missingFields.push(field);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (missingFields.length > 0) {
|
||||||
|
const missingFieldsString = missingFields.join(', ');
|
||||||
|
const errorMsg = `Missing fields: ${missingFieldsString}`
|
||||||
|
let data = {};
|
||||||
|
data['error'] = errorMsg;
|
||||||
|
response = JSON.stringify(data);
|
||||||
|
break
|
||||||
|
}
|
||||||
// Params: data.coin (QORT / LTC / DOGE / DGB / C / ARRR)
|
// Params: data.coin (QORT / LTC / DOGE / DGB / C / ARRR)
|
||||||
// TODO: prompt user to share wallet balance. If they confirm, call `GET /crosschain/:coin/walletbalance`, or for QORT, call `GET /addresses/balance/:address`
|
// TODO: prompt user to share wallet balance. If they confirm, call `GET /crosschain/:coin/walletbalance`, or for QORT, call `GET /addresses/balance/:address`
|
||||||
// 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)
|
||||||
@ -826,6 +844,7 @@ class WebBrowser extends LitElement {
|
|||||||
const res3 = await showModalAndWait(
|
const res3 = await showModalAndWait(
|
||||||
actions.GET_WALLET_BALANCE
|
actions.GET_WALLET_BALANCE
|
||||||
);
|
);
|
||||||
|
|
||||||
if (res3.action === 'accept') {
|
if (res3.action === 'accept') {
|
||||||
let coin = data.coin;
|
let coin = data.coin;
|
||||||
if (coin === "QORT") {
|
if (coin === "QORT") {
|
||||||
@ -835,14 +854,16 @@ class WebBrowser extends LitElement {
|
|||||||
const QORTBalance = await parentEpml.request('apiCall', {
|
const QORTBalance = await parentEpml.request('apiCall', {
|
||||||
url: `/addresses/balance/${qortAddress}?apiKey=${this.getApiKey()}`,
|
url: `/addresses/balance/${qortAddress}?apiKey=${this.getApiKey()}`,
|
||||||
})
|
})
|
||||||
return QORTBalance;
|
response = QORTBalance
|
||||||
|
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
const data = {};
|
const data = {};
|
||||||
const errorMsg = error.message || get("browserpage.bchange21");
|
const errorMsg = error.message || get("browserpage.bchange21");
|
||||||
data['error'] = errorMsg;
|
data['error'] = errorMsg;
|
||||||
response = JSON.stringify(data);
|
response = JSON.stringify(data);
|
||||||
return;
|
|
||||||
} finally {
|
} finally {
|
||||||
this.loader.hide();
|
this.loader.hide();
|
||||||
}
|
}
|
||||||
@ -904,36 +925,39 @@ class WebBrowser extends LitElement {
|
|||||||
} else if (res3.action === 'reject') {
|
} else if (res3.action === 'reject') {
|
||||||
response = '{"error": "User declined request"}';
|
response = '{"error": "User declined request"}';
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
case 'SEND_COIN':
|
case 'SEND_COIN':
|
||||||
// Params: data.coin, data.destinationAddress, data.amount, data.fee
|
// Params: data.coin, data.destinationAddress, data.amount, data.fee
|
||||||
// TODO: prompt user to send. If they confirm, call `POST /crosschain/:coin/send`, or for QORT, broadcast a PAYMENT transaction
|
// TODO: prompt user to send. If they confirm, call `POST /crosschain/:coin/send`, or for QORT, broadcast a PAYMENT transaction
|
||||||
// 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"}`
|
||||||
const amount = data.amount;
|
const amount = data.amount
|
||||||
let recipient = data.destinationAddress;
|
let recipient = data.destinationAddress;
|
||||||
const fee = data.fee
|
const fee = data.fee
|
||||||
this.loader.show();
|
this.loader.show();
|
||||||
|
|
||||||
const walletBalance = await parentEpml.request('apiCall', {
|
const walletBalance = await parentEpml.request('apiCall', {
|
||||||
url: `/addresses/balance/${this.myAddress.address}?apiKey=${this.getApiKey()}`,
|
url: `/addresses/balance/${this.myAddress.address}?apiKey=${this.getApiKey()}`,
|
||||||
}).then((res) => {
|
})
|
||||||
if (isNaN(Number(res))) {
|
if (isNaN(Number(walletBalance))) {
|
||||||
let snack4string = get("chatpage.cchange48")
|
let snack4string = get("chatpage.cchange48")
|
||||||
parentEpml.request('showSnackBar', `${snack4string}`)
|
parentEpml.request('showSnackBar', `${snack4string}`)
|
||||||
return;
|
return;
|
||||||
} else {
|
|
||||||
return Number(res).toFixed(8);
|
|
||||||
}
|
}
|
||||||
})
|
|
||||||
|
|
||||||
const myRef = await parentEpml.request("apiCall", {
|
const myRef = await parentEpml.request("apiCall", {
|
||||||
type: "api",
|
type: "api",
|
||||||
url: `/addresses/lastreference/${this.myAddress.address}`,
|
url: `/addresses/lastreference/${this.myAddress.address}`,
|
||||||
})
|
})
|
||||||
|
|
||||||
if (parseFloat(amount) + parseFloat(data.fee) > parseFloat(walletBalance)) {
|
const walletBalanceDecimals = parseFloat(walletBalance) * QORT_DECIMALS;
|
||||||
|
|
||||||
|
if (parseFloat(amount) + parseFloat(data.fee) > parseFloat(walletBalanceDecimals)) {
|
||||||
this.loader.hide();
|
this.loader.hide();
|
||||||
let snack1string = get("chatpage.cchange51");
|
let snack1string = get("chatpage.cchange51");
|
||||||
parentEpml.request('showSnackBar', `${snack1string}`);
|
parentEpml.request('showSnackBar', `${snack1string}`);
|
||||||
@ -1084,15 +1108,14 @@ class WebBrowser extends LitElement {
|
|||||||
// Not all responses will be JSON
|
// Not all responses will be JSON
|
||||||
responseObj = response;
|
responseObj = response;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Respond to app
|
// Respond to app
|
||||||
if (responseObj.error != null) {
|
if (responseObj.error != null) {
|
||||||
console.log('hello error')
|
|
||||||
event.ports[0].postMessage({
|
event.ports[0].postMessage({
|
||||||
result: null,
|
result: null,
|
||||||
error: responseObj,
|
error: responseObj,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
console.log('hello success')
|
|
||||||
event.ports[0].postMessage({
|
event.ports[0].postMessage({
|
||||||
result: responseObj,
|
result: responseObj,
|
||||||
error: null,
|
error: null,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user