@@ -20,19 +20,28 @@ function updateDataPoint(
2020 timestamp : BigInt ,
2121 variable : string
2222) : void {
23- let counter = store . get ( "Counter" , "0" ) ;
24- if ( ! counter ) {
25- counter = new Entity ( ) ;
26- for ( let i = 0 ; i < VARIABLES . length ; i ++ ) {
27- counter . set ( VARIABLES [ i ] , Value . fromBigInt ( ZERO ) ) ;
23+ const newCounter = new Entity ( ) ;
24+ const counter = store . get ( "Counter" , "0" ) ;
25+ for ( let i = 0 ; i < VARIABLES . length ; i ++ ) {
26+ const targetVar = VARIABLES [ i ] ;
27+ if ( targetVar === variable ) {
28+ newCounter . set (
29+ targetVar ,
30+ ! counter
31+ ? Value . fromBigInt ( delta )
32+ : Value . fromBigInt ( counter . get ( targetVar ) ! . toBigInt ( ) . plus ( delta ) )
33+ ) ;
34+ } else {
35+ newCounter . set (
36+ targetVar ,
37+ ! counter ? Value . fromBigInt ( ZERO ) : counter . get ( VARIABLES [ i ] ) !
38+ ) ;
2839 }
2940 }
3041 const dayID = timestamp . toI32 ( ) / 86400 ;
3142 const dayStartTimestamp = dayID * 86400 ;
32- const newValue = counter . get ( variable ) ! . toBigInt ( ) . plus ( delta ) ;
33- counter . set ( variable , Value . fromBigInt ( newValue ) ) ;
34- store . set ( "Counter" , dayStartTimestamp . toString ( ) , counter ) ;
35- store . set ( "Counter" , "0" , counter ) ;
43+ store . set ( "Counter" , dayStartTimestamp . toString ( ) , newCounter ) ;
44+ store . set ( "Counter" , "0" , newCounter ) ;
3645}
3746
3847export function updateStakedPNK ( delta : BigInt , timestamp : BigInt ) : void {
0 commit comments