ok
This commit is contained in:
46
src/App.js
46
src/App.js
@@ -109,6 +109,10 @@ function App() {
|
|||||||
|
|
||||||
const handleStorageChange = () => {
|
const handleStorageChange = () => {
|
||||||
calculateTotalsFromLocalStorage();
|
calculateTotalsFromLocalStorage();
|
||||||
|
|
||||||
|
if (!localStorage.getItem("lastTransaction")) {
|
||||||
|
setLastTransaction(null);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
window.addEventListener("localStorageUpdated", handleStorageChange);
|
window.addEventListener("localStorageUpdated", handleStorageChange);
|
||||||
@@ -237,24 +241,23 @@ function App() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
socket.on("transaction_confirmed", async (data) => {
|
socket.on("transaction_confirmed", async (data) => {
|
||||||
console.log("transaction notification: " + data);
|
console.log( JSON.stringify(data));
|
||||||
setModal("transaction_confirmed", data);
|
setModal("transaction_confirmed", data);
|
||||||
|
|
||||||
localStorage.setItem('cart', []);
|
localStorage.setItem('cart', []);
|
||||||
|
|
||||||
const startTime = Date.now(); // Capture the start time
|
// const startTime = Date.now(); // Capture the start time
|
||||||
const timeout = 10000; // 10 seconds timeout in milliseconds
|
// const timeout = 10000; // 10 seconds timeout in milliseconds
|
||||||
|
|
||||||
calculateTotalsFromLocalStorage();
|
calculateTotalsFromLocalStorage();
|
||||||
|
|
||||||
while (localStorage.getItem("lastTransaction") === null) {
|
// while (localStorage.getItem("lastTransaction") === null) {
|
||||||
if (Date.now() - startTime > timeout) {
|
// if (Date.now() - startTime > timeout) {
|
||||||
return; // Exit the function and don't proceed further
|
// return; // Exit the function and don't proceed further
|
||||||
}
|
// }
|
||||||
|
|
||||||
await new Promise((resolve) => setTimeout(resolve, 1000)); // Wait 1 second
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// await new Promise((resolve) => setTimeout(resolve, 1000)); // Wait 1 second
|
||||||
|
// }
|
||||||
|
|
||||||
// If 'lastTransaction' exists, proceed
|
// If 'lastTransaction' exists, proceed
|
||||||
const lastTransaction = JSON.parse(localStorage.getItem("lastTransaction"));
|
const lastTransaction = JSON.parse(localStorage.getItem("lastTransaction"));
|
||||||
@@ -271,17 +274,23 @@ function App() {
|
|||||||
setModal("transaction_success", data);
|
setModal("transaction_success", data);
|
||||||
|
|
||||||
// If 'lastTransaction' exists, proceed
|
// If 'lastTransaction' exists, proceed
|
||||||
localStorage.removeItem("lastTransaction");
|
if (localStorage.getItem("lastTransaction")) {
|
||||||
|
|
||||||
if (lastTransaction != null) {
|
|
||||||
setLastTransaction(null);
|
setLastTransaction(null);
|
||||||
console.log('remove last transaction')
|
localStorage.removeItem("lastTransaction");
|
||||||
|
window.dispatchEvent(new Event("localStorageUpdated"));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on("transaction_end", async (data) => {
|
socket.on("transaction_end", async (data) => {
|
||||||
console.log("transaction notification");
|
console.log("transaction notification");
|
||||||
setModal("transaction_end", data);
|
setModal("transaction_end", data);
|
||||||
|
|
||||||
|
// If 'lastTransaction' exists, proceed
|
||||||
|
if (localStorage.getItem("lastTransaction")) {
|
||||||
|
setLastTransaction(null);
|
||||||
|
localStorage.removeItem("lastTransaction");
|
||||||
|
window.dispatchEvent(new Event("localStorageUpdated"));
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on("payment_claimed", async (data) => {
|
socket.on("payment_claimed", async (data) => {
|
||||||
@@ -290,8 +299,15 @@ function App() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
socket.on("transaction_failed", async (data) => {
|
socket.on("transaction_failed", async (data) => {
|
||||||
console.log("transaction notification");
|
console.log(JSON.stringify(data));
|
||||||
setModal("transaction_failed", data);
|
setModal("transaction_failed", data);
|
||||||
|
|
||||||
|
// If 'lastTransaction' exists, proceed
|
||||||
|
if (localStorage.getItem("lastTransaction")) {
|
||||||
|
setLastTransaction(null);
|
||||||
|
localStorage.removeItem("lastTransaction");
|
||||||
|
window.dispatchEvent(new Event("localStorageUpdated"));
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user