mirror of
https://github.com/Qortal/qortal-ui.git
synced 2025-03-30 17:25:54 +00:00
add fees to publish
This commit is contained in:
parent
b9e778e346
commit
ccc7822646
@ -488,6 +488,16 @@ class PublishData extends LitElement {
|
|||||||
this.successMessage = ''
|
this.successMessage = ''
|
||||||
console.error(errorMessage)
|
console.error(errorMessage)
|
||||||
}
|
}
|
||||||
|
const getArbitraryFee = async () => {
|
||||||
|
const timestamp = Date.now()
|
||||||
|
let fee = await parentEpml.request('apiCall', {
|
||||||
|
url: `/unitfee?txType=ARBITRARY×tamp=${timestamp}`
|
||||||
|
})
|
||||||
|
return {
|
||||||
|
timestamp,
|
||||||
|
fee : (Number(fee) / 1e8).toFixed(8)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const validate = async () => {
|
const validate = async () => {
|
||||||
let validNameRes = await validateName(registeredName)
|
let validNameRes = await validateName(registeredName)
|
||||||
@ -501,8 +511,17 @@ class PublishData extends LitElement {
|
|||||||
this.generalMessage = `${err6string}`
|
this.generalMessage = `${err6string}`
|
||||||
let transactionBytes
|
let transactionBytes
|
||||||
let previewUrlPath
|
let previewUrlPath
|
||||||
|
let feeAmount = null
|
||||||
|
|
||||||
let uploadDataRes = await uploadData(registeredName, path, file, preview, fee)
|
if(fee){
|
||||||
|
const res = await getArbitraryFee()
|
||||||
|
if(res.fee){
|
||||||
|
feeAmount= res.fee
|
||||||
|
} else {
|
||||||
|
throw new Error('unable to get fee')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let uploadDataRes = await uploadData(registeredName, path, file, preview, fee, feeAmount)
|
||||||
|
|
||||||
if (uploadDataRes.error) {
|
if (uploadDataRes.error) {
|
||||||
let err7string = get("publishpage.pchange20")
|
let err7string = get("publishpage.pchange20")
|
||||||
@ -531,12 +550,13 @@ class PublishData extends LitElement {
|
|||||||
if (fee) {
|
if (fee) {
|
||||||
let err9string = get("publishpage.pchange26")
|
let err9string = get("publishpage.pchange26")
|
||||||
this.generalMessage = `${err9string}`
|
this.generalMessage = `${err9string}`
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
let err9string = get("publishpage.pchange22")
|
let err9string = get("publishpage.pchange22")
|
||||||
this.generalMessage = `${err9string}`
|
this.generalMessage = `${err9string}`
|
||||||
}
|
}
|
||||||
|
|
||||||
let signAndProcessRes = await signAndProcess(transactionBytes, fee)
|
let signAndProcessRes = await signAndProcess(transactionBytes, fee, feeAmount)
|
||||||
|
|
||||||
if (signAndProcessRes.error) {
|
if (signAndProcessRes.error) {
|
||||||
let err10string = get("publishpage.pchange20")
|
let err10string = get("publishpage.pchange20")
|
||||||
@ -554,7 +574,9 @@ class PublishData extends LitElement {
|
|||||||
this.successMessage = `${err11string}`
|
this.successMessage = `${err11string}`
|
||||||
}
|
}
|
||||||
|
|
||||||
const uploadData = async (registeredName, path, file, preview, fee) => {
|
|
||||||
|
|
||||||
|
const uploadData = async (registeredName, path, file, preview, fee, feeAmount) => {
|
||||||
let postBody = path
|
let postBody = path
|
||||||
let urlSuffix = ""
|
let urlSuffix = ""
|
||||||
if (file != null) {
|
if (file != null) {
|
||||||
@ -592,9 +614,9 @@ class PublishData extends LitElement {
|
|||||||
uploadDataUrl = `/arbitrary/${service}/${registeredName}/${this.identifier}${urlSuffix}?${metadataQueryString}&apiKey=${this.getApiKey()}&preview=${new Boolean(preview).toString()}`
|
uploadDataUrl = `/arbitrary/${service}/${registeredName}/${this.identifier}${urlSuffix}?${metadataQueryString}&apiKey=${this.getApiKey()}&preview=${new Boolean(preview).toString()}`
|
||||||
}
|
}
|
||||||
} else if (fee) {
|
} else if (fee) {
|
||||||
uploadDataUrl = `/arbitrary/${this.service}/${registeredName}${urlSuffix}?${metadataQueryString}&fee=100000&apiKey=${this.getApiKey()}`
|
uploadDataUrl = `/arbitrary/${this.service}/${registeredName}${urlSuffix}?${metadataQueryString}&fee=${feeAmount}&apiKey=${this.getApiKey()}`
|
||||||
if (identifier != null && identifier.trim().length > 0) {
|
if (identifier != null && identifier.trim().length > 0) {
|
||||||
uploadDataUrl = `/arbitrary/${service}/${registeredName}/${this.identifier}${urlSuffix}?${metadataQueryString}&fee=100000&apiKey=${this.getApiKey()}`
|
uploadDataUrl = `/arbitrary/${service}/${registeredName}/${this.identifier}${urlSuffix}?${metadataQueryString}&fee=${feeAmount}&apiKey=${this.getApiKey()}`
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
uploadDataUrl = `/arbitrary/${this.service}/${registeredName}${urlSuffix}?${metadataQueryString}&apiKey=${this.getApiKey()}`
|
uploadDataUrl = `/arbitrary/${this.service}/${registeredName}${urlSuffix}?${metadataQueryString}&apiKey=${this.getApiKey()}`
|
||||||
|
@ -48,6 +48,16 @@ export const publishData = async ({
|
|||||||
})
|
})
|
||||||
return convertedBytes
|
return convertedBytes
|
||||||
}
|
}
|
||||||
|
const getArbitraryFee = async () => {
|
||||||
|
const timestamp = Date.now()
|
||||||
|
let fee = await parentEpml.request('apiCall', {
|
||||||
|
url: `/unitfee?txType=ARBITRARY×tamp=${timestamp}`
|
||||||
|
})
|
||||||
|
return {
|
||||||
|
timestamp,
|
||||||
|
fee : (Number(fee) / 1e8).toFixed(8)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const signAndProcess = async (transactionBytesBase58) => {
|
const signAndProcess = async (transactionBytesBase58) => {
|
||||||
let convertedBytesBase58 = await convertBytesForSigning(
|
let convertedBytesBase58 = await convertBytesForSigning(
|
||||||
@ -125,7 +135,16 @@ export const publishData = async ({
|
|||||||
if (validNameRes.error) {
|
if (validNameRes.error) {
|
||||||
throw new Error('Name not found');
|
throw new Error('Name not found');
|
||||||
}
|
}
|
||||||
let transactionBytes = await uploadData(registeredName, path, file)
|
let fee = null
|
||||||
|
if(withFee){
|
||||||
|
const res = await getArbitraryFee()
|
||||||
|
if(res.fee){
|
||||||
|
fee= res.fee
|
||||||
|
} else {
|
||||||
|
throw new Error('unable to get fee')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let transactionBytes = await uploadData(registeredName, path, file, fee)
|
||||||
if (transactionBytes.error) {
|
if (transactionBytes.error) {
|
||||||
throw new Error(transactionBytes.message || 'Error when uploading');
|
throw new Error(transactionBytes.message || 'Error when uploading');
|
||||||
} else if (
|
} else if (
|
||||||
@ -149,7 +168,7 @@ export const publishData = async ({
|
|||||||
return signAndProcessRes
|
return signAndProcessRes
|
||||||
}
|
}
|
||||||
|
|
||||||
const uploadData = async (registeredName, path, file) => {
|
const uploadData = async (registeredName, path, file, fee) => {
|
||||||
if (identifier != null && identifier.trim().length > 0) {
|
if (identifier != null && identifier.trim().length > 0) {
|
||||||
let postBody = path
|
let postBody = path
|
||||||
let urlSuffix = ""
|
let urlSuffix = ""
|
||||||
@ -181,7 +200,7 @@ export const publishData = async ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(withFee){
|
if(withFee){
|
||||||
uploadDataUrl = uploadDataUrl + '&fee=100000'
|
uploadDataUrl = uploadDataUrl + `&fee=${fee}`
|
||||||
}
|
}
|
||||||
|
|
||||||
if(filename != null && filename != "undefined"){
|
if(filename != null && filename != "undefined"){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user