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