Monorepo for Aesthetic.Computer aesthetic.computer
4
fork

Configure Feed

Select the types of activity you want to include in your feed.

Fix blank mobile buy button checkout flow

+22 -5
+22 -5
system/public/aesthetic.computer/disks/blank.mjs
··· 8 8 let checkoutUrl = null; 9 9 let checkoutReady = false; 10 10 let checkoutError = null; 11 + let checkoutLoading = false; 11 12 let buyPending = false; 12 13 let thanks = false; 13 14 ··· 48 49 49 50 const SPEC_URL = 50 51 "https://psref.lenovo.com/Product/Lenovo/Lenovo_ThinkPad_11e_Yoga_Gen_6"; 52 + const AUTH_TIMEOUT_MS = 1200; 51 53 52 54 // Animation 53 55 let frame = 0; ··· 118 120 } 119 121 120 122 async function fetchCheckout(api) { 123 + if (checkoutLoading) return; 124 + 125 + checkoutLoading = true; 121 126 checkoutReady = false; 122 127 checkoutError = null; 123 128 checkoutUrl = null; 124 129 125 130 try { 126 131 const headers = { "Content-Type": "application/json" }; 127 - const token = await api?.authorize?.(); 132 + const token = await Promise.race([ 133 + api?.authorize?.(), 134 + new Promise((resolve) => setTimeout(() => resolve(null), AUTH_TIMEOUT_MS)), 135 + ]); 128 136 if (token) headers.Authorization = `Bearer ${token}`; 129 137 130 138 const res = await fetch("/api/blank?new=true", { ··· 147 155 } 148 156 } catch (e) { 149 157 checkoutError = e?.message || "Checkout error"; 158 + } finally { 159 + checkoutLoading = false; 150 160 } 151 161 } 152 162 ··· 736 746 setupButtons(ui, screen); 737 747 } 738 748 739 - specBtn?.act(e, { 749 + specBtn?.btn?.act(e, { 740 750 push: () => jump(`out:${SPEC_URL}`), 741 751 }); 742 752 743 - buyBtn?.act(e, { 753 + buyBtn?.btn?.act(e, { 744 754 down: () => { 745 755 sound?.synth({ type: "sine", tone: 440, duration: 0.05, volume: 0.3 }); 746 756 }, ··· 754 764 checkoutError = null; 755 765 fetchCheckout(api); 756 766 sound?.synth({ type: "sine", tone: 550, duration: 0.06, volume: 0.3 }); 767 + buyPending = true; 768 + waitForCheckout(jump, sound, api); 757 769 } else { 758 770 buyPending = true; 771 + if (!checkoutLoading) fetchCheckout(api); 759 772 sound?.synth({ type: "sine", tone: 660, duration: 0.08, volume: 0.3 }); 760 - waitForCheckout(jump, sound); 773 + waitForCheckout(jump, sound, api); 761 774 } 762 775 }, 763 776 }); 764 777 } 765 778 766 - async function waitForCheckout(jump, sound) { 779 + async function waitForCheckout(jump, sound, api) { 767 780 const maxWait = 10000; 768 781 const startTime = Date.now(); 782 + 783 + if (!checkoutReady && !checkoutError && !checkoutLoading) { 784 + fetchCheckout(api); 785 + } 769 786 770 787 while (!checkoutReady && !checkoutError && Date.now() - startTime < maxWait) { 771 788 await new Promise((r) => setTimeout(r, 100));