Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
bithalo committed Nov 19, 2024
1 parent 3939267 commit 531a326
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 46 deletions.
127 changes: 82 additions & 45 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2998,7 +2998,7 @@ <h1 t-id="2">BitBay Decentralized Markets</h1>&nbsp
<div id="loader-content" class="loader-content">
<div class="loader"></div>
<p id="loader-text" t-id ="55">Waiting for confirmation...</p>
<button onclick="minimizeLoader()" t-id="58" class="btn-filled">Minimize</button>
<button id="loader-button" style="margin-top: 15px" onclick="minimizeLoader()" t-id="58" class="btn-filled">Minimize</button>
</div>
<div id="loader-minimized" t-id="56" class="loader-minimized" style="display: none;" onclick="maximizeLoader()">
Transaction in progress...
Expand Down Expand Up @@ -3512,27 +3512,36 @@ <h3></h3>
};

// Loder-Modal Methods
function showLoader() {
function showLoader(hideText = '') {
const loaderModal = document.getElementById('loader-modal');
loaderModal.style.display = 'flex';
loaderModal.style.width = '100%'; // Full screen width
loaderModal.style.height = '100%'; // Full screen height
loaderModal.style.backgroundColor = 'rgba(0, 0, 0, 0.5)'; // Enable background fading
document.getElementById('loader-content').style.display = 'block';
if(hideText != '') {
document.getElementById('loader-text').style.display = 'none';
}
document.getElementById('loader-minimized').style.display = 'none';
}

function hideLoader() {
document.getElementById('loader-modal').style.display = 'none';
document.getElementById('loader-text').style.display = 'block';
}

function minimizeLoader() {
const loaderModal = document.getElementById('loader-modal');
if(document.getElementById('loader-text').style.display == 'none') {
hideLoader();
return;
}
loaderModal.style.backgroundColor = 'transparent'; // Remove background fading
loaderModal.style.width = '0'; // Minimize modal size
loaderModal.style.height = '0'; // Minimize modal size
document.getElementById('loader-content').style.display = 'none';
document.getElementById('loader-minimized').style.display = 'block';
document.getElementById('loader-text').style.display = 'block';
}

function maximizeLoader() {
Expand All @@ -3542,6 +3551,7 @@ <h3></h3>
loaderModal.style.backgroundColor = 'rgba(0, 0, 0, 0.5)'; // Re-enable background fading
document.getElementById('loader-content').style.display = 'block';
document.getElementById('loader-minimized').style.display = 'none';
document.getElementById('loader-text').style.display = 'block';
}

function togglePendingTransactionsDropdown() {
Expand Down Expand Up @@ -4971,6 +4981,12 @@ <h6>${translateThis("Transaction Pending")}</h6>
} else {
localStorage.setItem(myaccounts + DDEaddy + myCurrentChainId + ":api", "a");
localStorage.setItem(myaccounts + DDEaddy + myCurrentChainId + ":apiKeys", "none");
sightengineApiUser = '';
sightengineApiSecret = '';
pinataApiKey = '';
pinataSecretApiKey = '';
pinataGateway = '';
pinataToken = '';
}
}
}
Expand Down Expand Up @@ -5962,24 +5978,6 @@ <h6>${translateThis("Transaction Pending")}</h6>
request.publicKey = userpubkey;
const timestamp = new Date().getTime();
const padding = Crypto.SHA256(timestamp).substring(0, 16); //Pad to avoid chosen cipher attack
var gatewayPub = gatewayList[currentGateway]['pub'];
if(window.globalPublicKey) {
gatewayPub = window.globalPublicKey;
}
var finalMessage = cryptico.encrypt(JSON.stringify(orderData) + "#*#*#" + timestamp + padding, gatewayPub, userprivkey).cipher;
request.message = finalMessage;
if(ipfs != '') {
request.ipfs = true;
}
if(window.globalPublicKey) {
return localVerify(request);
}
const requestData = {
action: "verify",
item: "",
value: request, // Keep this as an object
key: ""
};
var maxtries = 3;
var checkedThis = {};
if(maxtries>gatewayList.length) {
Expand All @@ -5992,6 +5990,24 @@ <h6>${translateThis("Transaction Pending")}</h6>
continue;
}
checkedThis[x.toString()] = 1;
var gatewayPub = gatewayList[currentGateway]['pub'];
if(window.globalPublicKey) {
gatewayPub = window.globalPublicKey;
}
var finalMessage = cryptico.encrypt(JSON.stringify(orderData) + "#*#*#" + timestamp + padding, gatewayPub, userprivkey).cipher;
request.message = finalMessage;
if(ipfs != '') {
request.ipfs = true;
}
if(window.globalPublicKey) {
return localVerify(request);
}
const requestData = {
action: "verify",
item: "",
value: request, // Keep this as an object
key: ""
};
const response = await axios.post(gatewayList[currentGateway]['url'], requestData, {
headers: { 'ngrok-skip-browser-warning':true, 'Content-Type': 'application/json'}
});
Expand Down Expand Up @@ -6399,7 +6415,7 @@ <h6>${translateThis("Transaction Pending")}</h6>
orderData = {
message: 'error',
contact: '',
image: [''],
image: [],
title: '',
location: ''
};
Expand Down Expand Up @@ -7131,6 +7147,7 @@ <h6>${translateThis("Transaction Pending")}</h6>
};

var isGood = await validateOrderData(orderData, hash);
console.log(isGood)
if(isGood.toString().toLowerCase().includes("order passed ai test") || isGood.toString().toLowerCase().includes("order failed ai test") || isGood.toString().toLowerCase() == 'true' || isGood.toString().toLowerCase() == 'false') {
if(isGood.toString().toLowerCase().includes("order passed ai test")) {
isGood = true;
Expand Down Expand Up @@ -7314,13 +7331,13 @@ <h6>${translateThis("Transaction Pending")}</h6>
try {
var messageData = JSON.parse(jsondata.message);
if('recipient' in messageData && 'cipher' in messageData.recipient) {
jsondata.image = [''];
jsondata.image = [];
jsondata.message = DOMPurify.sanitize(text);
jsondata.contact = '';
jsondata.title = '';
jsondata.location = '';
} else {
var myimg = Array.isArray(messageData.image) ? messageData.image : [''];
var myimg = Array.isArray(messageData.image) ? messageData.image : [];
storeFile(Crypto.SHA256(JSON.stringify(myimg)), myimg);
jsondata.image = Crypto.SHA256(JSON.stringify(myimg));
jsondata.message = messageData.message;
Expand All @@ -7330,14 +7347,14 @@ <h6>${translateThis("Transaction Pending")}</h6>
}
} catch (e) {
console.log("Error loading data");
jsondata.image = [''];
jsondata.image = [];
jsondata.message = DOMPurify.sanitize(text);
jsondata.contact = '';
jsondata.title = '';
jsondata.location = '';
}
} else {
jsondata.image = [''];
jsondata.image = [];
jsondata.message = '';
jsondata.title = '';
jsondata.location = '';
Expand Down Expand Up @@ -7415,10 +7432,13 @@ <h6>${translateThis("Transaction Pending")}</h6>
if (myimg && myimg.length > 0) {
const imageMimeTypes = ['image/jpeg', 'image/png', 'image/gif', 'image/svg+xml'];
for (let i = 0; i < myimg.length; i++) {
const mimeTypeMatch = myimg[i].match(/^data:(.*?);/);
if (mimeTypeMatch && imageMimeTypes.includes(mimeTypeMatch[1].toLowerCase())) {
dataUrl = myimg[i];
break;
try {
const mimeTypeMatch = myimg[i].match(/^data:(.*?);/);
if (mimeTypeMatch && imageMimeTypes.includes(mimeTypeMatch[1].toLowerCase())) {
dataUrl = myimg[i];
break;
}
} catch {
}
}
}
Expand Down Expand Up @@ -7531,10 +7551,13 @@ <h6>${translateThis("Transaction Pending")}</h6>
if (myimg && myimg.length > 0) {
const imageMimeTypes = ['image/jpeg', 'image/png', 'image/gif', 'image/svg+xml'];
for (let i = 0; i < myimg.length; i++) {
const mimeTypeMatch = myimg[i].match(/^data:(.*?);/);
if (mimeTypeMatch && imageMimeTypes.includes(mimeTypeMatch[1].toLowerCase())) {
dataUrl2 = myimg[i];
break;
try {
const mimeTypeMatch = myimg[i].match(/^data:(.*?);/);
if (mimeTypeMatch && imageMimeTypes.includes(mimeTypeMatch[1].toLowerCase())) {
dataUrl2 = myimg[i];
break;
}
} catch {
}
}
}
Expand Down Expand Up @@ -7720,12 +7743,15 @@ <h6>${translateThis("Transaction Pending")}</h6>

if (myimg && myimg.length > 0) {
const imageMimeTypes = ['image/jpeg', 'image/png', 'image/gif', 'image/svg+xml'];
for (let i = 0; i < myimg.length; i++) {
const mimeTypeMatch = myimg[i].match(/^data:(.*?);/);
if (mimeTypeMatch && imageMimeTypes.includes(mimeTypeMatch[1].toLowerCase())) {
dataUrl3 = myimg[i];
break;
try {
for (let i = 0; i < myimg.length; i++) {
const mimeTypeMatch = myimg[i].match(/^data:(.*?);/);
if (mimeTypeMatch && imageMimeTypes.includes(mimeTypeMatch[1].toLowerCase())) {
dataUrl3 = myimg[i];
break;
}
}
} catch {
}
}
li3.innerHTML = `
Expand Down Expand Up @@ -8035,13 +8061,15 @@ <h6>${translateThis("Transaction Pending")}</h6>
const imageMimeTypes = ['image/jpeg', 'image/png', 'image/gif', 'image/svg+xml'];

for (let j = 0; j < myimg.length; j++) {
try {
const mimeType = myimg[j].match(/^data:(.*?);/)[1].toLowerCase();

if (imageMimeTypes.includes(mimeType)) {
tempimg = '<img src="' + myimg[j] + '" alt="./blank-image.jpg">';
foundImage = true;
break;
}
} catch {
}
}

if (!foundImage) {
Expand Down Expand Up @@ -8201,11 +8229,14 @@ <h6>${translateThis("Transaction Pending")}</h6>
const imageMimeTypes = ['image/jpeg', 'image/png', 'image/gif', 'image/svg+xml'];

for (let i = 0; i < myimg.length; i++) {
const mimeTypeMatch = myimg[i].match(/^data:(.*?);/);
if (mimeTypeMatch && imageMimeTypes.includes(mimeTypeMatch[1].toLowerCase())) {
tempimg = `<img src="${myimg[i]}" alt="Notification image">`;
foundImage = true;
break;
try {
const mimeTypeMatch = myimg[i].match(/^data:(.*?);/);
if (mimeTypeMatch && imageMimeTypes.includes(mimeTypeMatch[1].toLowerCase())) {
tempimg = `<img src="${myimg[i]}" alt="Notification image">`;
foundImage = true;
break;
}
} catch {
}
}

Expand Down Expand Up @@ -8593,7 +8624,7 @@ <h6>${notification.message[0] || "Default Title"}</h6>
throw new Error("Failed");
}
var messageData = JSON.parse(thisText);
var myimg = Array.isArray(messageData.image) ? messageData.image : [''];
var myimg = Array.isArray(messageData.image) ? messageData.image : [];
storeFile(Crypto.SHA256(JSON.stringify(myimg)), myimg);
storeFile(Crypto.SHA256(listing.message), thisText);
listing.image = Crypto.SHA256(JSON.stringify(myimg));
Expand Down Expand Up @@ -10449,6 +10480,7 @@ <h6>${notification.message[0] || "Default Title"}</h6>
});
if (response.isConfirmed) {
await registerData();
return;
} else {
return;
}
Expand Down Expand Up @@ -11061,7 +11093,9 @@ <h2>` + translateThis('Create Contract') + `</h2>
};
if(contractDetails || title || location) {
if(sightengineApiUser != '') {
showLoader(1);
var isGood = await validateOrderData(orderData);
hideLoader();
if(!isGood) {
await Swal.fire(translateThis("Your title or description has been flagged as inappropriate. Please try again with a different title or description.")+" "+translateThis("Orders should not contain links, sex, violence, fraud, drugs, weapons, insults, etc."));
return false;
Expand Down Expand Up @@ -11178,7 +11212,9 @@ <h2>` + translateThis('Create Contract') + `</h2>
return false;
}
} else {
showLoader(1);
var isGood = await validateOrderData(orderData, '', true);
hideLoader();
var validated = false;
if(isGood.toString().toLowerCase().includes("order passed ai test") || isGood.toString().toLowerCase().includes("order failed ai test")) {
if(isGood.toString().toLowerCase().includes("order passed ai test")) {
Expand Down Expand Up @@ -11638,6 +11674,7 @@ <h2>` + translateThis('Create Contract') + `</h2>
});
if (response.isConfirmed) {
await registerData();
return;
} else {
return;
}
Expand Down
14 changes: 13 additions & 1 deletion node/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,18 @@
title: DOMPurify.sanitize(message?.title),
location: DOMPurify.sanitize(message?.location)
};
orderData['image'] = orderData.image.map((img, index) => {
try {
const mime = img.match(/^data:(.*);base64,/)[1]; // Match base64 data URL
if (['image/gif', 'image/jpeg', 'image/png', 'image/svg+xml'].includes(mime)) {
dataURLtoFile(img, `image${index}.${mime.split('/')[1]}`);
return img;
}
} catch {
return null; // Return null for invalid or non-base64 images
}
return null; // Return null for any image that doesn't match the valid mime types
}).filter(img => img !== null);
} catch (e) {
return {'false':'Invalid JSON'};
}
Expand Down Expand Up @@ -430,7 +442,7 @@
} else {
if('ipfs' in request) {
userData.IPFSRequests += 1;
var ipfshash = await pinToPinataIPFS(message);
var ipfshash = await pinToPinataIPFS(JSON.stringify(message));
console.log(ipfshash)
if(ipfshash == "error") {
return {'false': "error posting to ipfs"};
Expand Down

0 comments on commit 531a326

Please sign in to comment.