@@ -430,18 +430,29 @@ const Trades = (() => {
430430// === STATS + UI MODULE ===
431431const Stats = ( ( ) => {
432432 function update ( state ) {
433+ const { balance, wager, duration } = Core . state ;
434+
435+ // ⏱️ Update Duration Display
436+ document . getElementById ( 'durH' ) . textContent = `${ String ( duration . hour ) . padStart ( 2 , '0' ) } h:` ;
437+ document . getElementById ( 'durM' ) . textContent = `${ String ( duration . minute ) . padStart ( 2 , '0' ) } m:` ;
438+ document . getElementById ( 'durS' ) . textContent = `${ String ( duration . second ) . padStart ( 2 , '0' ) } s` ;
439+
440+ // 💰 Update Balance Display
441+ document . getElementById ( 'balance' ) . querySelector ( 'span' ) . textContent = balance . toLocaleString ( undefined , {
442+ minimumFractionDigits : 2 ,
443+ maximumFractionDigits : 2
444+ } ) ;
445+
446+ // 🎯 Update Wager Display
447+ document . getElementById ( 'wager' ) . textContent = wager . toLocaleString ( ) ;
448+
433449 // === 1. Profit + Progress ===
434450 const profit = state . balance - state . startBalance ;
435451 const openPNL = state . openTrades . reduce ( ( acc , trade ) => {
436452 const won = ( trade . type === "buy" && state . currentPrice > trade . entry ) || ( trade . type === "sell" && state . currentPrice < trade . entry ) ;
437453 return acc + ( won ? trade . wager : - trade . wager ) ;
438454 } , 0 ) ;
439455
440- document . getElementById ( 'balance' ) . querySelector ( 'span' ) . textContent = `${ state . balance . toLocaleString ( undefined , {
441- minimumFractionDigits : 2 ,
442- maximumFractionDigits : 2
443- } ) } `;
444-
445456 // === 5. Win Rate & Trade Stats ===
446457 const wins = state . trades . filter ( t => t . pnl > 0 ) ;
447458 const total = state . trades . length ;
@@ -621,51 +632,6 @@ document.addEventListener("keydown", (e) => {
621632} ) ;
622633
623634// === BUTTON EVENT HANDLERS ===
624- document . getElementById ( 'balance' ) . onclick = ( ) => {
625- Modal . render ( {
626- title : `Reset Your Balance` ,
627- content : `
628- <p class="text-sm text-center mb-4 text-yellow-500">🕹️ Start a new run — all previous trades will vanish!</p>
629- <input id="balanceInput" type="number" min="1" step="1" placeholder="1,000" value="${ Core . state . startBalance } ">
630- ` ,
631- onLoad ( ) {
632- // Add event listener for the 'Enter' key
633- document . getElementById ( 'balanceInput' ) . focus ( ) ;
634- document . getElementById ( 'balanceInput' ) . onkeydown = function ( e ) {
635- if ( e . key === 'Enter' ) {
636- // Trigger a click on the Confirm button
637- this . closest ( 'dialog' ) . querySelector ( 'footer button[data-modal=confirm]' ) . click ( ) ;
638- e . preventDefault ( ) ;
639- }
640- } ;
641- } ,
642- onConfirm ( ) {
643- Core . clearStorage ( ) ;
644-
645- // Get the input value and update the balance
646- const newBalance = parseInt ( document . getElementById ( 'balanceInput' ) . value , 10 ) ;
647- if ( ! isNaN ( newBalance ) ) {
648- Core . state . startBalance = newBalance ;
649- Core . state . balance = newBalance ;
650- Core . state . trades = [ ] ;
651-
652- // Update the balance display
653- document . getElementById ( 'balance' ) . querySelector ( 'span' ) . textContent = Core . state . balance . toLocaleString ( undefined , {
654- minimumFractionDigits : 2 ,
655- maximumFractionDigits : 2
656- } ) ;
657-
658- saveStateToLocalStorage ( ) ;
659- }
660- }
661- } ) ;
662- }
663- document . getElementById ( "buy" ) . onclick = ( ) => {
664- Trades . place ( "buy" , Core . state ) ;
665- } ;
666- document . getElementById ( "sell" ) . onclick = ( ) => {
667- Trades . place ( "sell" , Core . state ) ;
668- } ;
669635document . getElementById ( 'performance' ) . onclick = ( ) => {
670636 const state = Core . state ;
671637 const trades = state . trades ;
@@ -844,5 +810,138 @@ document.getElementById('performance').onclick = () => {
844810 }
845811 } ) ;
846812} ;
813+ document . getElementById ( 'balance' ) . onclick = ( ) => {
814+ Modal . render ( {
815+ title : `Reset Your Balance` ,
816+ content : `
817+ <p class="text-sm text-center mb-4 text-yellow-500">🕹️ Start a new run — all previous trades will vanish!</p>
818+ <input id="balanceInput" type="number" min="1" step="1" placeholder="1,000" value="${ Core . state . startBalance } ">
819+ ` ,
820+ onLoad ( ) {
821+ // Add event listener for the 'Enter' key
822+ document . getElementById ( 'balanceInput' ) . focus ( ) ;
823+ document . getElementById ( 'balanceInput' ) . onkeydown = function ( e ) {
824+ if ( e . key === 'Enter' ) {
825+ // Trigger a click on the Confirm button
826+ this . closest ( 'dialog' ) . querySelector ( 'footer button[data-modal=confirm]' ) . click ( ) ;
827+ e . preventDefault ( ) ;
828+ }
829+ } ;
830+ } ,
831+ onConfirm ( ) {
832+ Core . clearStorage ( ) ;
833+
834+ // Get the input value and update the balance
835+ const newBalance = parseInt ( document . getElementById ( 'balanceInput' ) . value , 10 ) ;
836+ if ( ! isNaN ( newBalance ) ) {
837+ Core . state . startBalance = newBalance ;
838+ Core . state . balance = newBalance ;
839+ Core . state . trades = [ ] ;
840+
841+ // Update the balance display
842+ document . getElementById ( 'balance' ) . querySelector ( 'span' ) . textContent = Core . state . balance . toLocaleString ( undefined , {
843+ minimumFractionDigits : 2 ,
844+ maximumFractionDigits : 2
845+ } ) ;
846+
847+ saveStateToLocalStorage ( ) ;
848+ }
849+ }
850+ } ) ;
851+ }
852+ document . getElementById ( "buy" ) . onclick = ( ) => {
853+ Trades . place ( "buy" , Core . state ) ;
854+ } ;
855+ document . getElementById ( 'wager' ) . onclick = ( ) => {
856+ Modal . render ( {
857+ title : `Set Your Wager` ,
858+ content : `
859+ <input
860+ id="wagerInput"
861+ type="number"
862+ min="1"
863+ step="1"
864+ placeholder="250"
865+ value="${ Core . state . wager } "
866+ class="w-full p-2 border border-gray-600 rounded text-center"
867+ >
868+ ` ,
869+ onLoad ( ) {
870+ const input = document . getElementById ( 'wagerInput' ) ;
871+ const confirmBtn = document . querySelector ( 'dialog footer button:last-child' ) ;
872+ confirmBtn . setAttribute ( 'data-modal' , 'confirm' ) ;
873+
874+ input . focus ( ) ;
875+ input . onkeydown = ( e ) => {
876+ if ( e . key === 'Enter' ) {
877+ confirmBtn . click ( ) ;
878+ e . preventDefault ( ) ;
879+ }
880+ } ;
881+ } ,
882+ onConfirm ( ) {
883+ const newWager = parseInt ( document . getElementById ( 'wagerInput' ) . value , 10 ) ;
884+ if ( ! isNaN ( newWager ) && newWager > 0 ) {
885+ Core . state . wager = newWager ;
886+
887+ document . getElementById ( 'wager' ) . textContent = Core . state . wager ;
888+ saveStateToLocalStorage ( ) ;
889+ } else {
890+ showTradeMessage ( "❌ Invalid wager amount." ) ;
891+ }
892+ }
893+ } ) ;
894+ } ;
895+ document . getElementById ( 'duration' ) . onclick = ( ) => {
896+ Modal . render ( {
897+ title : `Set Trade Duration` ,
898+ content : `
899+ <div class="text-center">
900+ <div class="grid grid-cols-3 gap-2">
901+ <input class="duration-input" id="durationHours" type="number" min="0" placeholder="00" value="${ Core . state . duration . hour } " class="p-2 border border-gray-600 rounded">
902+ <input class="duration-input" id="durationMinutes" type="number" min="0" max="59" placeholder="00" value="${ Core . state . duration . minute } " class="p-2 border border-gray-600 rounded">
903+ <input class="duration-input" id="durationSeconds" type="number" min="1" max="59" placeholder="00" value="${ Core . state . duration . second } " class="p-2 border border-gray-600 rounded">
904+ </div>
905+ <div class="grid grid-cols-3 gap-2 text-sm text-gray-400">
906+ <span>Hours</span>
907+ <span>Minutes</span>
908+ <span>Seconds</span>
909+ </div>
910+ </div>
911+ ` ,
912+ onLoad ( ) {
913+ const confirmBtn = document . querySelector ( 'dialog footer button:last-child' ) ;
914+ const inputs = document . querySelectorAll ( '.duration-input' ) ;
915+
916+ function updateConfirmState ( ) {
917+ const h = parseInt ( document . getElementById ( 'durationHours' ) . value ) || 0 ;
918+ const m = parseInt ( document . getElementById ( 'durationMinutes' ) . value ) || 0 ;
919+ const s = parseInt ( document . getElementById ( 'durationSeconds' ) . value ) || 0 ;
920+ confirmBtn . disabled = ( h === 0 && m === 0 && s === 0 ) ;
921+ }
922+
923+ inputs . forEach ( input => input . addEventListener ( 'input' , updateConfirmState ) ) ;
924+ updateConfirmState ( ) ; // Initial state
925+ } ,
926+ onConfirm ( ) {
927+ const h = parseInt ( document . getElementById ( 'durationHours' ) . value ) || 0 ;
928+ const m = parseInt ( document . getElementById ( 'durationMinutes' ) . value ) || 0 ;
929+ const s = parseInt ( document . getElementById ( 'durationSeconds' ) . value ) || 0 ;
930+ if ( h === 0 && m === 0 && s === 0 ) return ;
931+
932+ Core . state . duration = { hour : h , minute : m , second : s } ;
933+
934+ // Update display
935+ durH . textContent = `${ String ( h ) . padStart ( 2 , '0' ) } h:` ;
936+ durM . textContent = `${ String ( m ) . padStart ( 2 , '0' ) } m:` ;
937+ durS . textContent = `${ String ( s ) . padStart ( 2 , '0' ) } s` ;
938+
939+ saveStateToLocalStorage ( ) ;
940+ }
941+ } ) ;
942+ } ;
943+ document . getElementById ( "sell" ) . onclick = ( ) => {
944+ Trades . place ( "sell" , Core . state ) ;
945+ } ;
847946
848947window . addEventListener ( 'DOMContentLoaded' , ( ) => loadStateFromLocalStorage ( ) ) ;
0 commit comments