From 401b554a38aa0e67d7724c8ca9c92abe1af089f4 Mon Sep 17 00:00:00 2001 From: JustEngineer Date: Thu, 16 Oct 2025 16:00:34 +0300 Subject: [PATCH 1/2] removed unnecessary fetch from droplets purchase, update all account data on purchase --- Extension/scripts/Auto-Image.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/Extension/scripts/Auto-Image.js b/Extension/scripts/Auto-Image.js index e9c9a41..9ba46a5 100644 --- a/Extension/scripts/Auto-Image.js +++ b/Extension/scripts/Auto-Image.js @@ -10380,13 +10380,21 @@ localStorage.removeItem("lp"); console.error("Error: Invalid purchase type provided."); return; } - const { droplets } = await WPlaceService.getCharges(); + // Refresh and update full account data, then use it for purchasing + const accountData = await WPlaceService.getCharges(); + // Update the current account with the latest fetched info + if (accountData) { + try { accountManager.updateAccountData(accountData); } catch (e) { console.warn('⚠️ Failed to update account manager from getCharges()', e); } + } + // Prefer droplets from the AccountManager (updated), fallback to fetched value + const current = typeof accountManager !== 'undefined' ? accountManager.getCurrentAccount() : null; + const droplets = (current && typeof current.Droplets === 'number') ? current.Droplets : (accountData?.droplets || 0); console.log("There are currently : ", droplets, "droplets."); try { const amounts = Math.floor(droplets / 500); if (amounts < 1) { console.log("Not enough droplets to purchase."); - return; + return 1; } const payload = { "product": { @@ -10403,8 +10411,7 @@ localStorage.removeItem("lp"); credentials: "include" }); // POST request completed - const { droplets: newDroplets } = await WPlaceService.getCharges(); - if (droplets != newDroplets) { + if (res.ok) { console.log("Successfully bought", amounts * chargeMultiplier, type.replace('_', ' '), "."); return 2; } else { From 2cc7e280be88313b3021cea382550304e0722986 Mon Sep 17 00:00:00 2001 From: JustEngineer Date: Thu, 16 Oct 2025 16:29:17 +0300 Subject: [PATCH 2/2] update max charges after buying to account --- Extension/scripts/Auto-Image.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Extension/scripts/Auto-Image.js b/Extension/scripts/Auto-Image.js index 9ba46a5..796d2ad 100644 --- a/Extension/scripts/Auto-Image.js +++ b/Extension/scripts/Auto-Image.js @@ -10413,6 +10413,21 @@ localStorage.removeItem("lp"); // POST request completed if (res.ok) { console.log("Successfully bought", amounts * chargeMultiplier, type.replace('_', ' '), "."); + // Update AccountManager to reflect new limits/charges after successful purchase + try { + const acc = (typeof accountManager !== 'undefined' && accountManager?.getCurrentAccount) ? accountManager.getCurrentAccount() : null; + if (acc) { + if (type === "max_charges") { + const newMax = Math.floor((typeof acc.Max === 'number' ? acc.Max : 0) + (amounts * chargeMultiplier)); + accountManager.updateAccountData({ Max: newMax }); + } else if (type === "paint_charges") { + const newCharges = Math.floor((typeof acc.Charges === 'number' ? acc.Charges : 0) + (amounts * chargeMultiplier)); + accountManager.updateAccountData({ Charges: newCharges }); + } + } + } catch (e) { + console.warn('⚠️ Failed to update account manager after purchase', e); + } return 2; } else { console.log("Failed to buy charges");