@@ -11,6 +11,7 @@ import (
1111 "github.com/gobitfly/beaconchain/pkg/api/enums"
1212 "github.com/gobitfly/beaconchain/pkg/api/types"
1313 "github.com/gorilla/mux"
14+ "github.com/shopspring/decimal"
1415)
1516
1617// All handler function names must include the HTTP method and the path they handle
@@ -2243,7 +2244,7 @@ func (h *HandlerService) PublicPutUserNotificationSettingsGeneral(w http.Respons
22432244// @Accept json
22442245// @Produce json
22452246// @Param network path string true "The networks name or chain ID."
2246- // @Param request body types.NotificationSettingsNetwork true "Description Todo"
2247+ // @Param request body handlers.PublicPutUserNotificationSettingsNetworks.request true "Description Todo"
22472248// @Success 200 {object} types.InternalPutUserNotificationSettingsNetworksResponse
22482249// @Failure 400 {object} types.ApiErrorResponse
22492250// @Router /users/me/notifications/settings/networks/{network} [put]
@@ -2254,27 +2255,48 @@ func (h *HandlerService) PublicPutUserNotificationSettingsNetworks(w http.Respon
22542255 handleErr (w , r , err )
22552256 return
22562257 }
2257- var req types.NotificationSettingsNetwork
2258+ type request struct {
2259+ IsGasAboveSubscribed bool `json:"is_gas_above_subscribed"`
2260+ GasAboveThreshold string `json:"gas_above_threshold"`
2261+ IsGasBelowSubscribed bool `json:"is_gas_below_subscribed"`
2262+ GasBelowThreshold string `json:"gas_below_threshold" `
2263+ IsParticipationRateSubscribed bool `json:"is_participation_rate_subscribed"`
2264+ ParticipationRateThreshold float64 `json:"participation_rate_threshold" faker:"boundary_start=0, boundary_end=1"`
2265+ }
2266+ var req request
22582267 if err := v .checkBody (& req , r ); err != nil {
22592268 handleErr (w , r , err )
22602269 return
22612270 }
22622271 checkMinMax (& v , req .ParticipationRateThreshold , 0 , 1 , "participation_rate_threshold" )
2263-
22642272 chainId := v .checkNetworkParameter (mux .Vars (r )["network" ])
2273+
2274+ minWei := decimal .New (1000000 , 1 ) // 0.001 Gwei
2275+ maxWei := decimal .New (1000000000000 , 1 ) // 1000 Gwei
2276+ gasAboveThreshold := v .checkWeiMinMax (req .GasAboveThreshold , "gas_above_threshold" , minWei , maxWei )
2277+ gasBelowThreshold := v .checkWeiMinMax (req .GasBelowThreshold , "gas_below_threshold" , minWei , maxWei )
22652278 if v .hasErrors () {
22662279 handleErr (w , r , v )
22672280 return
22682281 }
2269- err = h .dai .UpdateNotificationSettingsNetworks (r .Context (), userId , chainId , req )
2282+ settings := types.NotificationSettingsNetwork {
2283+ IsGasAboveSubscribed : req .IsGasAboveSubscribed ,
2284+ GasAboveThreshold : gasAboveThreshold ,
2285+ IsGasBelowSubscribed : req .IsGasBelowSubscribed ,
2286+ GasBelowThreshold : gasBelowThreshold ,
2287+ IsParticipationRateSubscribed : req .IsParticipationRateSubscribed ,
2288+ ParticipationRateThreshold : req .ParticipationRateThreshold ,
2289+ }
2290+
2291+ err = h .dai .UpdateNotificationSettingsNetworks (r .Context (), userId , chainId , settings )
22702292 if err != nil {
22712293 handleErr (w , r , err )
22722294 return
22732295 }
22742296 response := types.InternalPutUserNotificationSettingsNetworksResponse {
22752297 Data : types.NotificationNetwork {
22762298 ChainId : chainId ,
2277- Settings : req ,
2299+ Settings : settings ,
22782300 },
22792301 }
22802302 returnOk (w , r , response )
0 commit comments