updated publish qortalRequests

This commit is contained in:
PhilReact 2025-01-15 03:21:04 +02:00
parent 983db5a087
commit 61d9a6fcd6
4 changed files with 153 additions and 33 deletions

View File

@ -3189,6 +3189,24 @@ function App() {
</> </>
)} )}
{messageQortalRequestExtension?.appFee && (
<>
<TextP
sx={{
textAlign: "center",
lineHeight: 1.2,
fontSize: "16px",
fontWeight: "normal",
maxWidth: "90%",
}}
>
{"App Fee: "}
{messageQortalRequestExtension?.appFee}
{" QORT"}
</TextP>
<Spacer height="15px" />
</>
)}
{messageQortalRequestExtension?.foreignFee && ( {messageQortalRequestExtension?.foreignFee && (
<> <>
<Spacer height="15px" /> <Spacer height="15px" />
@ -3212,7 +3230,6 @@ function App() {
<Box <Box
sx={{ sx={{
display: "flex", display: "flex",
gap: "10px",
alignItems: "center", alignItems: "center",
justifyContent: "center", justifyContent: "center",
width: "90%", width: "90%",

View File

@ -556,6 +556,18 @@ export const Minting = ({
}} }}
> >
<DialogTitle id="alert-dialog-title">{"Manage your minting"}</DialogTitle> <DialogTitle id="alert-dialog-title">{"Manage your minting"}</DialogTitle>
<IconButton
sx={{
position: 'absolute',
right: 8,
top: 8,
}}
color="inherit"
onClick={()=> setIsOpenMinting(false)}
aria-label="close"
>
<CloseIcon />
</IconButton>
<DialogContent <DialogContent
sx={{ sx={{
position: "relative", position: "relative",

View File

@ -75,7 +75,7 @@ body {
} }
::-webkit-scrollbar { ::-webkit-scrollbar {
width: 14px; width: 16px;
height: 10px; height: 10px;
} }
@ -84,7 +84,12 @@ body {
border-radius: 8px; border-radius: 8px;
background-clip: content-box; background-clip: content-box;
border: 4px solid transparent; border: 4px solid transparent;
transition: 0.3s background-color;
} }
::-webkit-scrollbar-thumb:hover {
background-color: #363636;
}
@property --var1 { @property --var1 {
syntax: "<color>"; syntax: "<color>";

View File

@ -569,7 +569,7 @@ export const getUserAccount = async ({isFromExtension, appInfo}) => {
}; };
export const encryptData = async (data, sender) => { export const encryptData = async (data, sender) => {
let data64 = data.data64; let data64 = data.data64 || data.base64;
let publicKeys = data.publicKeys || []; let publicKeys = data.publicKeys || [];
if (data.fileId) { if (data.fileId) {
data64 = await getFileFromContentScript(data.fileId, sender); data64 = await getFileFromContentScript(data.fileId, sender);
@ -818,24 +818,41 @@ export const publishQDNResource = async (data: any, sender, isFromExtension) =>
const errorMsg = `Missing fields: ${missingFieldsString}`; const errorMsg = `Missing fields: ${missingFieldsString}`;
throw new Error(errorMsg); throw new Error(errorMsg);
} }
if (!data.fileId && !data.data64) { if (!data.fileId && !data.data64 && !data.base64) {
throw new Error("No data or file was submitted"); throw new Error("No data or file was submitted");
} }
// Use "default" if user hasn't specified an identifer // Use "default" if user hasn't specified an identifer
const service = data.service; const service = data.service;
const appFee = data?.appFee ? +data.appFee : undefined
const appFeeRecipient = data?.appFeeRecipient
let hasAppFee = false
if(appFee && appFee > 0 && appFeeRecipient){
hasAppFee = true
}
const registeredName = await getNameInfo(); const registeredName = await getNameInfo();
const name = registeredName; const name = registeredName;
if(!name){
throw new Error('User has no Qortal name')
}
let identifier = data.identifier; let identifier = data.identifier;
let data64 = data.data64; let data64 = data.data64 || data.base64;
const filename = data.filename; const filename = data.filename;
const title = data.title; const title = data.title;
const description = data.description; const description = data.description;
const category = data.category; const category = data.category;
const tag1 = data.tag1; const tags = data?.tags || [];
const tag2 = data.tag2; const result = {};
const tag3 = data.tag3;
const tag4 = data.tag4; // Fill tags dynamically while maintaining backward compatibility
const tag5 = data.tag5; for (let i = 0; i < 5; i++) {
result[`tag${i + 1}`] = tags[i] || data[`tag${i + 1}`] || undefined;
}
// Access tag1 to tag5 from result
const { tag1, tag2, tag3, tag4, tag5 } = result;
if (data.identifier == null) { if (data.identifier == null) {
identifier = "default"; identifier = "default";
} }
@ -874,14 +891,30 @@ export const publishQDNResource = async (data: any, sender, isFromExtension) =>
const fee = await getFee("ARBITRARY"); const fee = await getFee("ARBITRARY");
const handleDynamicValues = {}
if(hasAppFee){
const feePayment = await getFee("PAYMENT");
handleDynamicValues['appFee'] = +appFee + +feePayment.fee,
handleDynamicValues['checkbox1'] = {
value: true,
label: "accept app fee",
}
}
if(!!data?.encrypt){
handleDynamicValues['highlightedText'] = `isEncrypted: ${!!data.encrypt}`
}
const resPermission = await getUserPermission({ const resPermission = await getUserPermission({
text1: "Do you give this application permission to publish to QDN?", text1: "Do you give this application permission to publish to QDN?",
text2: `service: ${service}`, text2: `service: ${service}`,
text3: `identifier: ${identifier || null}`, text3: `identifier: ${identifier || null}`,
highlightedText: `isEncrypted: ${!!data.encrypt}`,
fee: fee.fee, fee: fee.fee,
...handleDynamicValues
}, isFromExtension); }, isFromExtension);
const { accepted } = resPermission;
const { accepted, checkbox1 = false } = resPermission;
if (accepted) { if (accepted) {
try { try {
@ -904,6 +937,12 @@ export const publishQDNResource = async (data: any, sender, isFromExtension) =>
apiVersion: 2, apiVersion: 2,
withFee: true, withFee: true,
}); });
if(resPublish?.signature && hasAppFee && checkbox1){
sendCoinFunc({
amount: appFee,
receiver: appFeeRecipient
}, true)
}
return resPublish; return resPublish;
} catch (error) { } catch (error) {
throw new Error(error?.message || "Upload failed"); throw new Error(error?.message || "Upload failed");
@ -969,16 +1008,48 @@ export const publishMultipleQDNResources = async (data: any, sender, isFromExten
if (resources.length === 0) { if (resources.length === 0) {
throw new Error("No resources to publish"); throw new Error("No resources to publish");
} }
if (
data.encrypt && const encrypt = data?.encrypt
(!data.publicKeys ||
(Array.isArray(data.publicKeys) && data.publicKeys.length === 0)) for (const resource of resources) {
) { const resourceEncrypt = encrypt && resource?.disableEncrypt !== true
throw new Error("Encrypting data requires public keys"); if (!resourceEncrypt && resource?.service.endsWith("_PRIVATE")) {
const errorMsg = "Only encrypted data can go into private services";
throw new Error(errorMsg)
} else if(resourceEncrypt && !resource?.service.endsWith("_PRIVATE")){
const errorMsg = "For an encrypted publish please use a service that ends with _PRIVATE";
throw new Error(errorMsg)
}
} }
const fee = await getFee("ARBITRARY"); const fee = await getFee("ARBITRARY");
const registeredName = await getNameInfo(); const registeredName = await getNameInfo();
const name = registeredName; const name = registeredName;
if(!name){
throw new Error('You need a Qortal name to publish.')
}
const appFee = data?.appFee ? +data.appFee : undefined
const appFeeRecipient = data?.appFeeRecipient
let hasAppFee = false
if(appFee && appFee > 0 && appFeeRecipient){
hasAppFee = true
}
const handleDynamicValues = {}
if(hasAppFee){
const feePayment = await getFee("PAYMENT");
handleDynamicValues['appFee'] = +appFee + +feePayment.fee,
handleDynamicValues['checkbox1'] = {
value: true,
label: "accept app fee",
}
}
if(data?.encrypt){
handleDynamicValues['highlightedText'] = `isEncrypted: ${!!data.encrypt}`
}
const resPermission = await getUserPermission({ const resPermission = await getUserPermission({
text1: "Do you give this application permission to publish to QDN?", text1: "Do you give this application permission to publish to QDN?",
html: ` html: `
@ -1028,7 +1099,7 @@ export const publishMultipleQDNResources = async (data: any, sender, isFromExten
<div class="resource-detail"><span>Service:</span> ${ <div class="resource-detail"><span>Service:</span> ${
resource.service resource.service
}</div> }</div>
<div class="resource-detail"><span>Name:</span> ${resource.name}</div> <div class="resource-detail"><span>Name:</span> ${name}</div>
<div class="resource-detail"><span>Identifier:</span> ${ <div class="resource-detail"><span>Identifier:</span> ${
resource.identifier resource.identifier
}</div> }</div>
@ -1043,10 +1114,13 @@ export const publishMultipleQDNResources = async (data: any, sender, isFromExten
</div> </div>
`, `,
highlightedText: `isEncrypted: ${!!data.encrypt}`, fee: +fee.fee * resources.length,
fee: fee.fee * resources.length, ...handleDynamicValues
}, isFromExtension); }, isFromExtension);
const { accepted } = resPermission;
const { accepted, checkbox1 = false } = resPermission;
if (!accepted) { if (!accepted) {
throw new Error("User declined request"); throw new Error("User declined request");
} }
@ -1069,7 +1143,7 @@ export const publishMultipleQDNResources = async (data: any, sender, isFromExten
}); });
continue; continue;
} }
if (!resource.fileId && !resource.data64) { if (!resource.fileId && !resource.data64 && !resource?.base64) {
const errorMsg = "No data or file was submitted"; const errorMsg = "No data or file was submitted";
failedPublishesIdentifiers.push({ failedPublishesIdentifiers.push({
reason: errorMsg, reason: errorMsg,
@ -1079,20 +1153,26 @@ export const publishMultipleQDNResources = async (data: any, sender, isFromExten
} }
const service = resource.service; const service = resource.service;
let identifier = resource.identifier; let identifier = resource.identifier;
let data64 = resource.data64; let data64 = resource?.data64 || resource?.base64;
const filename = resource.filename; const filename = resource.filename;
const title = resource.title; const title = resource.title;
const description = resource.description; const description = resource.description;
const category = resource.category; const category = resource.category;
const tag1 = resource.tag1; const tags = resource?.tags || [];
const tag2 = resource.tag2; const result = {};
const tag3 = resource.tag3;
const tag4 = resource.tag4; // Fill tags dynamically while maintaining backward compatibility
const tag5 = resource.tag5; for (let i = 0; i < 5; i++) {
result[`tag${i + 1}`] = tags[i] || resource[`tag${i + 1}`] || undefined;
}
// Access tag1 to tag5 from result
const { tag1, tag2, tag3, tag4, tag5 } = result;
const resourceEncrypt = encrypt && resource?.disableEncrypt !== true
if (resource.identifier == null) { if (resource.identifier == null) {
identifier = "default"; identifier = "default";
} }
if (!data.encrypt && service.endsWith("_PRIVATE")) { if (!resourceEncrypt && service.endsWith("_PRIVATE")) {
const errorMsg = "Only encrypted data can go into private services"; const errorMsg = "Only encrypted data can go into private services";
failedPublishesIdentifiers.push({ failedPublishesIdentifiers.push({
reason: errorMsg, reason: errorMsg,
@ -1103,7 +1183,7 @@ export const publishMultipleQDNResources = async (data: any, sender, isFromExten
if (resource.fileId) { if (resource.fileId) {
data64 = await getFileFromContentScript(resource.fileId, sender); data64 = await getFileFromContentScript(resource.fileId, sender);
} }
if (data.encrypt) { if (resourceEncrypt) {
try { try {
const resKeyPair = await getKeyPair() const resKeyPair = await getKeyPair()
const parsedData = JSON.parse(resKeyPair) const parsedData = JSON.parse(resKeyPair)
@ -1155,7 +1235,7 @@ export const publishMultipleQDNResources = async (data: any, sender, isFromExten
}, 1000); }, 1000);
}); });
} catch (error) { } catch (error) {
const errorMsg = error.message || "Upload failed"; const errorMsg = error?.message || "Upload failed";
failedPublishesIdentifiers.push({ failedPublishesIdentifiers.push({
reason: errorMsg, reason: errorMsg,
identifier: resource.identifier, identifier: resource.identifier,
@ -1163,7 +1243,7 @@ export const publishMultipleQDNResources = async (data: any, sender, isFromExten
} }
} catch (error) { } catch (error) {
failedPublishesIdentifiers.push({ failedPublishesIdentifiers.push({
reason: "Unknown error", reason: error?.message || "Unknown error",
identifier: resource.identifier, identifier: resource.identifier,
}); });
} }
@ -1175,6 +1255,12 @@ export const publishMultipleQDNResources = async (data: any, sender, isFromExten
}; };
return obj; return obj;
} }
if(hasAppFee && checkbox1){
sendCoinFunc({
amount: appFee,
receiver: appFeeRecipient
}, true)
}
return true; return true;
}; };