From b6d9410621a00fb6997a49a2477585ab7a6dfcc4 Mon Sep 17 00:00:00 2001 From: Phillip Date: Tue, 15 Aug 2023 15:25:32 -0500 Subject: [PATCH] fix url and get fee for modal --- core/language/us.json | 3 +- .../plugins/core/qdn/browser/browser.src.js | 40 +++++++++++++++---- .../plugins/core/qdn/publish/publish.src.js | 2 +- plugins/plugins/utils/publish-image.js | 11 +++-- 4 files changed, 43 insertions(+), 13 deletions(-) diff --git a/core/language/us.json b/core/language/us.json index cbf85a4f..768d9ac7 100644 --- a/core/language/us.json +++ b/core/language/us.json @@ -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", diff --git a/plugins/plugins/core/qdn/browser/browser.src.js b/plugins/plugins/core/qdn/browser/browser.src.js index db59e4fd..20b66767 100644 --- a/plugins/plugins/core/qdn/browser/browser.src.js +++ b/plugins/plugins/core/qdn/browser/browser.src.js @@ -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×tamp=${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) {
@@ -3017,7 +3043,7 @@ async function showModalAndWait(type, data) {
diff --git a/plugins/plugins/core/qdn/publish/publish.src.js b/plugins/plugins/core/qdn/publish/publish.src.js index 0d0ce8f0..aaf16793 100644 --- a/plugins/plugins/core/qdn/publish/publish.src.js +++ b/plugins/plugins/core/qdn/publish/publish.src.js @@ -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×tamp=${timestamp}` + url: `/transactions/unitfee?txType=ARBITRARY×tamp=${timestamp}` }) return { timestamp, diff --git a/plugins/plugins/utils/publish-image.js b/plugins/plugins/utils/publish-image.js index bde9a78f..fde18985 100644 --- a/plugins/plugins/utils/publish-image.js +++ b/plugins/plugins/utils/publish-image.js @@ -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×tamp=${timestamp}` + url: `/transactions/unitfee?txType=ARBITRARY×tamp=${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')