Skip to content

Commit cceedb6

Browse files
committed
refactor(swap): change ICY amount to use float64 type
1 parent 89e279a commit cceedb6

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

internal/handler/swap/swap.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -154,15 +154,15 @@ func (h *handler) CreateSwapRequest(c *gin.Context) {
154154
return
155155
}
156156

157-
icyAmountInt, err := strconv.ParseInt(req.ICYAmount, 10, 64)
157+
icyAmountFloat, err := strconv.ParseFloat(req.ICYAmount, 64)
158158
if err != nil {
159159
h.logger.Error("[CreateSwapRequest][ParseFloat]", map[string]string{
160160
"error": err.Error(),
161161
})
162162
c.JSON(http.StatusBadRequest, view.CreateResponse[any](nil, err, req, "invalid ICY amount"))
163163
return
164164
}
165-
if icyAmountInt < h.appConfig.MinIcySwapAmount {
165+
if float64(icyAmountFloat) < h.appConfig.MinIcySwapAmount {
166166
c.JSON(http.StatusBadRequest, view.CreateResponse[any](nil, fmt.Errorf("minimum ICY amount is %v", h.appConfig.MinIcySwapAmount), nil, "invalid ICY amount"))
167167
return
168168
}

internal/utils/config/config.go

+12-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ type AppConfig struct {
1616
Bitcoin BitcoinConfig
1717
Blockchain BlockchainConfig
1818
IndexInterval string
19-
MinIcySwapAmount int64
19+
MinIcySwapAmount float64
2020
}
2121

2222
type ApiServerConfig struct {
@@ -87,7 +87,7 @@ func New() *AppConfig {
8787
IcySwapSignerPrivateKey: os.Getenv("BLOCKCHAIN_SWAP_SIGNER_PRIVATE_KEY"),
8888
},
8989
IndexInterval: os.Getenv("INDEX_INTERVAL"),
90-
MinIcySwapAmount: int64(envVarAtoi("MIN_ICY_SWAP_AMOUNT")),
90+
MinIcySwapAmount: envVarAsFloat("MIN_ICY_SWAP_AMOUNT", 1000000000000000000),
9191
}
9292
}
9393

@@ -115,6 +115,16 @@ func envVarAtoi(envName string) int {
115115
return value
116116
}
117117

118+
func envVarAsInt64(envName string) int64 {
119+
valueStr := os.Getenv(envName)
120+
value, err := strconv.ParseInt(valueStr, 10, 64)
121+
if err != nil {
122+
panic(err)
123+
}
124+
125+
return value
126+
}
127+
118128
func envVarAsBool(envName string) bool {
119129
valueStr := os.Getenv(envName)
120130
return valueStr == "true"

0 commit comments

Comments
 (0)