mirror of
https://github.com/Qortal/qortal-ui.git
synced 2025-04-24 20:07:51 +00:00
fix issues
This commit is contained in:
parent
ef0f7406c3
commit
abe7be473d
@ -1,5 +1,6 @@
|
|||||||
'use strict'
|
'use strict'
|
||||||
import TransactionBase from './TransactionBase.js'
|
import TransactionBase from './TransactionBase.js'
|
||||||
|
import { store } from '../../api.js'
|
||||||
|
|
||||||
export default class DeployAtTransaction extends TransactionBase {
|
export default class DeployAtTransaction extends TransactionBase {
|
||||||
constructor() {
|
constructor() {
|
||||||
@ -33,7 +34,7 @@ export default class DeployAtTransaction extends TransactionBase {
|
|||||||
this._feeBytes = this.constructor.utils.int64ToBytes(this._fee)
|
this._feeBytes = this.constructor.utils.int64ToBytes(this._fee)
|
||||||
}
|
}
|
||||||
set rAmount(rAmount) {
|
set rAmount(rAmount) {
|
||||||
this._rAmount = rAmount
|
this._rAmount = Math.round(rAmount * store.getState().config.coin.decimals)
|
||||||
this._rAmountBytes = this.constructor.utils.int64ToBytes(this._rAmount)
|
this._rAmountBytes = this.constructor.utils.int64ToBytes(this._rAmount)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,7 +61,6 @@ export default class DeployAtTransaction extends TransactionBase {
|
|||||||
}
|
}
|
||||||
set rCreationBytes(rCreationBytes) {
|
set rCreationBytes(rCreationBytes) {
|
||||||
const decode = this.constructor.Base58.decode(rCreationBytes)
|
const decode = this.constructor.Base58.decode(rCreationBytes)
|
||||||
console.log({decode})
|
|
||||||
this._rCreationBytes = this.constructor.utils.stringtoUTF8Array(decode)
|
this._rCreationBytes = this.constructor.utils.stringtoUTF8Array(decode)
|
||||||
this._rCreationBytesLength = this.constructor.utils.int32ToBytes(this._rCreationBytes.length)
|
this._rCreationBytesLength = this.constructor.utils.int32ToBytes(this._rCreationBytes.length)
|
||||||
}
|
}
|
||||||
|
@ -231,7 +231,6 @@ class WebBrowser extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
console.log(1, "browser page here");
|
|
||||||
return html`
|
return html`
|
||||||
<div id="websitesWrapper" style="width:auto; padding:10px; background: var(--white);">
|
<div id="websitesWrapper" style="width:auto; padding:10px; background: var(--white);">
|
||||||
<div class="layout horizontal center">
|
<div class="layout horizontal center">
|
||||||
@ -295,7 +294,20 @@ class WebBrowser extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const data = await response.json()
|
const data = await response.json()
|
||||||
const joinFee = data
|
const joinFee = (Number(data) / 1e8).toFixed(8)
|
||||||
|
return joinFee
|
||||||
|
}
|
||||||
|
async sendQortFee() {
|
||||||
|
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}/transactions/unitfee?txType=PAYMENT`
|
||||||
|
const response = await fetch(url)
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error('Error when fetching join fee');
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = await response.json()
|
||||||
|
const joinFee = (Number(data) / 1e8).toFixed(8)
|
||||||
return joinFee
|
return joinFee
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -452,10 +464,8 @@ class WebBrowser extends LitElement {
|
|||||||
|
|
||||||
let response = '{"error": "Request could not be fulfilled"}';
|
let response = '{"error": "Request could not be fulfilled"}';
|
||||||
let data = event.data;
|
let data = event.data;
|
||||||
console.log('UI received event: ' + JSON.stringify(data));
|
|
||||||
|
|
||||||
switch (data.action) {
|
switch (data.action) {
|
||||||
case 'GET_USER_ACCOUNT':
|
|
||||||
case actions.GET_USER_ACCOUNT:
|
case actions.GET_USER_ACCOUNT:
|
||||||
const res1 = await showModalAndWait(
|
const res1 = await showModalAndWait(
|
||||||
actions.GET_USER_ACCOUNT
|
actions.GET_USER_ACCOUNT
|
||||||
@ -469,12 +479,12 @@ class WebBrowser extends LitElement {
|
|||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
const data = {};
|
const data = {};
|
||||||
const errorMsg = get('browserpage.bchange17');
|
const errorMsg = "User declined to share account details"
|
||||||
data['error'] = errorMsg;
|
data['error'] = errorMsg;
|
||||||
response = JSON.stringify(data);
|
response = JSON.stringify(data);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'LINK_TO_QDN_RESOURCE':
|
case actions.LINK_TO_QDN_RESOURCE:
|
||||||
case actions.QDN_RESOURCE_DISPLAYED:
|
case actions.QDN_RESOURCE_DISPLAYED:
|
||||||
// Links are handled by the core, but the UI also listens for these actions in order to update the address bar.
|
// Links are handled by the core, but the UI also listens for these actions in order to update the address bar.
|
||||||
// Note: don't update this.url here, as we don't want to force reload the iframe each time.
|
// Note: don't update this.url here, as we don't want to force reload the iframe each time.
|
||||||
@ -566,11 +576,11 @@ class WebBrowser extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
case 'SEND_CHAT_MESSAGE': {
|
case actions.SEND_CHAT_MESSAGE: {
|
||||||
const message = data.message;
|
const message = data.message;
|
||||||
const recipient = data.destinationAddress;
|
const recipient = data.destinationAddress;
|
||||||
const sendMessage = async (messageText, chatReference) => {
|
const sendMessage = async (messageText, chatReference) => {
|
||||||
this.loader.show();
|
|
||||||
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);
|
||||||
@ -623,13 +633,13 @@ class WebBrowser extends LitElement {
|
|||||||
|
|
||||||
const getSendChatResponse = (res) => {
|
const getSendChatResponse = (res) => {
|
||||||
if (res === true) {
|
if (res === true) {
|
||||||
let successString = get("browserpage.bchange23");
|
return res
|
||||||
parentEpml.request('showSnackBar', `${successString}`);
|
|
||||||
} else if (res.error) {
|
} else if (res.error) {
|
||||||
parentEpml.request('showSnackBar', res.message);
|
throw new Error(res.message);
|
||||||
|
} else {
|
||||||
|
throw new Error('ERROR: Could not send message');
|
||||||
}
|
}
|
||||||
this.loader.hide();
|
|
||||||
return res;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const chatResponse = await sendMessageRequest();
|
const chatResponse = await sendMessageRequest();
|
||||||
@ -665,7 +675,7 @@ class WebBrowser extends LitElement {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
this.loader.show();
|
|
||||||
|
|
||||||
const tiptapJson = {
|
const tiptapJson = {
|
||||||
type: 'doc',
|
type: 'doc',
|
||||||
@ -699,14 +709,15 @@ class WebBrowser extends LitElement {
|
|||||||
// this.sendMessage(stringifyMessageObject, typeMessage);
|
// this.sendMessage(stringifyMessageObject, typeMessage);
|
||||||
// }
|
// }
|
||||||
try {
|
try {
|
||||||
|
this.loader.show();
|
||||||
const msgResponse = await sendMessage(stringifyMessageObject);
|
const msgResponse = await sendMessage(stringifyMessageObject);
|
||||||
response = msgResponse;
|
response = msgResponse;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
return '{"error": "Request could not be fulfilled"}';
|
response = '{"error": "Request could not be fulfilled"}';
|
||||||
} finally {
|
} finally {
|
||||||
this.loader.hide();
|
this.loader.hide();
|
||||||
console.log("Case completed.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@ -820,7 +831,7 @@ class WebBrowser extends LitElement {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
|
|
||||||
case 'GET_WALLET_BALANCE': {
|
case actions.GET_WALLET_BALANCE: {
|
||||||
const requiredFields = ['coin'];
|
const requiredFields = ['coin'];
|
||||||
const missingFields = [];
|
const missingFields = [];
|
||||||
|
|
||||||
@ -931,23 +942,43 @@ class WebBrowser extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
case 'SEND_COIN':
|
case actions.SEND_COIN: {
|
||||||
|
const requiredFields = ['coin', 'destinationAddress', 'amount'];
|
||||||
|
const missingFields = [];
|
||||||
|
|
||||||
|
requiredFields.forEach((field) => {
|
||||||
|
if (!data[field]) {
|
||||||
|
missingFields.push(field);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (missingFields.length > 0) {
|
||||||
|
this.loader.hide();
|
||||||
|
const missingFieldsString = missingFields.join(', ');
|
||||||
|
const errorMsg = `Missing fields: ${missingFieldsString}`
|
||||||
|
let data = {};
|
||||||
|
data['error'] = errorMsg;
|
||||||
|
response = JSON.stringify(data);
|
||||||
|
break
|
||||||
|
}
|
||||||
// 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 = Number(data.amount)
|
||||||
let recipient = data.destinationAddress;
|
let recipient = data.destinationAddress;
|
||||||
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()}`,
|
||||||
})
|
})
|
||||||
if (isNaN(Number(walletBalance))) {
|
if (isNaN(Number(walletBalance))) {
|
||||||
let snack4string = get("chatpage.cchange48")
|
this.loader.hide();
|
||||||
parentEpml.request('showSnackBar', `${snack4string}`)
|
let errorMsg = "Failed to Fetch QORT Balance. Try again!"
|
||||||
return;
|
let obj = {};
|
||||||
|
obj['error'] = errorMsg;
|
||||||
|
response = JSON.stringify(obj);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
const myRef = await parentEpml.request("apiCall", {
|
const myRef = await parentEpml.request("apiCall", {
|
||||||
@ -955,27 +986,35 @@ class WebBrowser extends LitElement {
|
|||||||
url: `/addresses/lastreference/${this.myAddress.address}`,
|
url: `/addresses/lastreference/${this.myAddress.address}`,
|
||||||
})
|
})
|
||||||
|
|
||||||
const walletBalanceDecimals = parseFloat(walletBalance) * QORT_DECIMALS;
|
const walletBalanceDecimals = Number(walletBalance) * QORT_DECIMALS;
|
||||||
|
const amountDecimals = Number(amount) * QORT_DECIMALS
|
||||||
if (parseFloat(amount) + parseFloat(data.fee) > parseFloat(walletBalanceDecimals)) {
|
const fee = await this.sendQortFee()
|
||||||
|
// TODO fee
|
||||||
|
if (amountDecimals + (fee * QORT_DECIMALS) > walletBalanceDecimals) {
|
||||||
this.loader.hide();
|
this.loader.hide();
|
||||||
let snack1string = get("chatpage.cchange51");
|
let errorMsg = "Insufficient Funds!"
|
||||||
parentEpml.request('showSnackBar', `${snack1string}`);
|
let obj = {};
|
||||||
return false;
|
obj['error'] = errorMsg;
|
||||||
|
response = JSON.stringify(obj);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parseFloat(amount) <= 0) {
|
if (amount <= 0) {
|
||||||
this.loader.hide();
|
this.loader.hide();
|
||||||
let snack2string = get("chatpage.cchange52");
|
let errorMsg = "Invalid Amount!"
|
||||||
parentEpml.request('showSnackBar', `${snack2string}`);
|
let obj = {};
|
||||||
return false;
|
obj['error'] = errorMsg;
|
||||||
|
response = JSON.stringify(obj);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (recipient.length === 0) {
|
if (recipient.length === 0) {
|
||||||
this.loader.hide();
|
this.loader.hide();
|
||||||
let snack3string = get("chatpage.cchange53");
|
let errorMsg = "Receiver cannot be empty!"
|
||||||
parentEpml.request('showSnackBar', `${snack3string}`);
|
let obj = {};
|
||||||
return false;
|
obj['error'] = errorMsg;
|
||||||
|
response = JSON.stringify(obj);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
const validateName = async (receiverName) => {
|
const validateName = async (receiverName) => {
|
||||||
@ -1020,9 +1059,10 @@ class WebBrowser extends LitElement {
|
|||||||
const res = getTxnRequestResponse(myTransaction)
|
const res = getTxnRequestResponse(myTransaction)
|
||||||
return res;
|
return res;
|
||||||
} else {
|
} else {
|
||||||
console.error(`${translate("chatpage.cchange54")}`)
|
|
||||||
parentEpml.request('showSnackBar', `${translate("chatpage.cchange54")}`)
|
let errorMsg = "Invalid Receiver!"
|
||||||
this.loader.hide();
|
throw new Error(errorMsg)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1073,14 +1113,15 @@ class WebBrowser extends LitElement {
|
|||||||
const getTxnRequestResponse = (txnResponse) => {
|
const getTxnRequestResponse = (txnResponse) => {
|
||||||
if (txnResponse.success === false && txnResponse.message) {
|
if (txnResponse.success === false && txnResponse.message) {
|
||||||
this.loader.hide();
|
this.loader.hide();
|
||||||
throw new Error(txnResponse);
|
throw new Error(txnResponse.message);
|
||||||
} else if (txnResponse.success === true && !txnResponse.data.error) {
|
} else if (txnResponse.success === true && !txnResponse.data.error) {
|
||||||
this.loader.hide();
|
this.loader.hide();
|
||||||
|
return txnResponse.data;
|
||||||
} else {
|
} else {
|
||||||
this.loader.hide();
|
this.loader.hide();
|
||||||
throw new Error(txnResponse);
|
throw new Error('Error: could not send coin');
|
||||||
}
|
}
|
||||||
return txnResponse;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -1088,11 +1129,13 @@ class WebBrowser extends LitElement {
|
|||||||
response = result;
|
response = result;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
return '{"error": "Request could not be fulfilled"}';
|
response = '{"error": "Request could not be fulfilled"}';
|
||||||
} finally {
|
} finally {
|
||||||
console.log("Case completed.");
|
this.loader.hide();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
console.log('Unhandled message: ' + JSON.stringify(data));
|
console.log('Unhandled message: ' + JSON.stringify(data));
|
||||||
@ -1107,7 +1150,6 @@ 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) {
|
||||||
event.ports[0].postMessage({
|
event.ports[0].postMessage({
|
||||||
|
Loading…
x
Reference in New Issue
Block a user