4
1
mirror of https://github.com/Qortal/qortal-ui.git synced 2025-02-11 17:55:51 +00:00

fix url and get fee for modal

This commit is contained in:
Phillip 2023-08-15 15:25:32 -05:00
parent ccc7822646
commit b6d9410621
4 changed files with 43 additions and 13 deletions

View File

@ -719,7 +719,8 @@
"bchange43": "Do you give this application permission to add to this list?",
"bchange44": "Do you give this application permission to delete from this list?",
"bchange45": "Encrypt",
"bchange46": "Do you give this application permission to save the following file"
"bchange46": "Do you give this application permission to save the following file",
"bchange47": "Instant publish - requires"
},
"datapage": {
"dchange1": "Data Management",

View File

@ -425,6 +425,22 @@ class WebBrowser extends LitElement {
const joinFee = (Number(data) / 1e8).toFixed(8)
return joinFee
}
async getArbitraryFee (){
const timestamp = Date.now()
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=ARBITRARY&timestamp=${timestamp}`
const response = await fetch(url)
if (!response.ok) {
throw new Error('Error when fetching arbitrary fee');
}
const data = await response.json()
const arbitraryFee = (Number(data) / 1e8).toFixed(8)
return {
timestamp,
fee : arbitraryFee
}
}
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
@ -975,6 +991,7 @@ class WebBrowser extends LitElement {
const tag3 = data.tag3;
const tag4 = data.tag4;
const tag5 = data.tag5;
let feeAmount = null
if (data.identifier == null) {
identifier = 'default';
}
@ -994,6 +1011,8 @@ class WebBrowser extends LitElement {
if (data.file) {
data64 = await fileToBase64(data.file)
}
const getArbitraryFee = await this.getArbitraryFee()
feeAmount = getArbitraryFee.fee
if (data.encrypt) {
try {
@ -1014,6 +1033,7 @@ class WebBrowser extends LitElement {
}
const res2 = await showModalAndWait(
@ -1022,7 +1042,8 @@ class WebBrowser extends LitElement {
name,
identifier,
service,
encrypt: data.encrypt
encrypt: data.encrypt,
feeAmount
}
);
if (res2.action === 'accept') {
@ -1052,7 +1073,8 @@ class WebBrowser extends LitElement {
tag4,
tag5,
apiVersion: 2,
withFee: res2.userData.isWithFee === true ? true : false
withFee: res2.userData.isWithFee === true ? true : false,
feeAmount: feeAmount
});
response = JSON.stringify(resPublish);
@ -1080,7 +1102,7 @@ class WebBrowser extends LitElement {
case actions.PUBLISH_MULTIPLE_QDN_RESOURCES: {
const requiredFields = ['resources'];
const missingFields = [];
let feeAmount = null
requiredFields.forEach((field) => {
if (!data[field]) {
missingFields.push(field);
@ -1114,11 +1136,14 @@ class WebBrowser extends LitElement {
response = JSON.stringify(data);
break
}
const getArbitraryFee = await this.getArbitraryFee()
feeAmount = getArbitraryFee.fee
const res2 = await showModalAndWait(
actions.PUBLISH_MULTIPLE_QDN_RESOURCES,
{
resources,
encrypt: data.encrypt
encrypt: data.encrypt,
feeAmount
}
);
@ -1217,7 +1242,8 @@ class WebBrowser extends LitElement {
tag4,
tag5,
apiVersion: 2,
withFee: res2.userData.isWithFee === true ? true : false
withFee: res2.userData.isWithFee === true ? true : false,
feeAmount: feeAmount
});
worker.terminate();
@ -3001,7 +3027,7 @@ async function showModalAndWait(type, data) {
</table>
<div class="checkbox-row">
<label for="isWithFee" id="isWithFeeLabel" style="color: var(--black);">
${get('browserpage.bchange33')} ${data.resources.length * 0.001} QORT fee
${get('browserpage.bchange33')} ${data.resources.length * data.feeAmount} QORT fee
</label>
<mwc-checkbox checked style="margin-right: -15px;" id="isWithFee"></mwc-checkbox>
</div>
@ -3017,7 +3043,7 @@ async function showModalAndWait(type, data) {
<p style="font-size: 16px;overflow-wrap: anywhere;" class="modal-paragraph"><span style="font-weight: bold">${get("browserpage.bchange45")}:</span> ${data.encrypt ? true : false}</p>
<div class="checkbox-row">
<label for="isWithFee" id="isWithFeeLabel" style="color: var(--black);">
${get('browserpage.bchange29')}
${get('browserpage.bchange47')} ${data.feeAmount} QORT fee
</label>
<mwc-checkbox checked style="margin-right: -15px;" id="isWithFee"></mwc-checkbox>
</div>

View File

@ -491,7 +491,7 @@ class PublishData extends LitElement {
const getArbitraryFee = async () => {
const timestamp = Date.now()
let fee = await parentEpml.request('apiCall', {
url: `/unitfee?txType=ARBITRARY&timestamp=${timestamp}`
url: `/transactions/unitfee?txType=ARBITRARY&timestamp=${timestamp}`
})
return {
timestamp,

View File

@ -28,7 +28,8 @@ export const publishData = async ({
tag2,
tag3,
tag4,
tag5
tag5,
feeAmount
}) => {
const validateName = async (receiverName) => {
let nameRes = await parentEpml.request("apiCall", {
@ -51,7 +52,7 @@ export const publishData = async ({
const getArbitraryFee = async () => {
const timestamp = Date.now()
let fee = await parentEpml.request('apiCall', {
url: `/unitfee?txType=ARBITRARY&timestamp=${timestamp}`
url: `/transactions/unitfee?txType=ARBITRARY&timestamp=${timestamp}`
})
return {
timestamp,
@ -136,9 +137,11 @@ export const publishData = async ({
throw new Error('Name not found');
}
let fee = null
if(withFee){
if(withFee && feeAmount){
fee= feeAmount
} else if(withFee){
const res = await getArbitraryFee()
if(res.fee){
if(res.fee){
fee= res.fee
} else {
throw new Error('unable to get fee')