diff --git a/pkg/fetchers/cosmos/responses/params.go b/pkg/fetchers/cosmos/responses/params.go index e9c9bd0..4c2c1b9 100644 --- a/pkg/fetchers/cosmos/responses/params.go +++ b/pkg/fetchers/cosmos/responses/params.go @@ -60,17 +60,22 @@ func (params ParamsResponse) ToParams(chain *types.Chain) (*types.ChainWithVotin } return &types.ChainWithVotingParams{ - Chain: chain, - VotingPeriod: votingPeriod, - MaxDepositPeriod: maxDepositPeriod, - MinDepositAmount: utils.Map(params.DepositParams.MinDepositAmount, func(amount Amount) types.Amount { - return types.Amount{ - Denom: amount.Denom, - Amount: amount.Amount, - } - }), - Quorum: quorum, - Threshold: threshold, - VetoThreshold: vetoThreshold, + Chain: chain, + Params: []types.ChainParam{ + types.DurationParam{Description: "Voting period", Value: votingPeriod}, + types.DurationParam{Description: "Max deposit period", Value: maxDepositPeriod}, + types.AmountsParam{ + Description: "Min deposit amount", + Value: utils.Map(params.DepositParams.MinDepositAmount, func(amount Amount) types.Amount { + return types.Amount{ + Denom: amount.Denom, + Amount: amount.Amount, + } + }), + }, + types.PercentParam{Description: "Quorum", Value: quorum}, + types.PercentParam{Description: "Threshold", Value: threshold}, + types.PercentParam{Description: "Veto threshold", Value: vetoThreshold}, + }, }, nil } diff --git a/pkg/types/params.go b/pkg/types/params.go index e022b8e..d0a15e1 100644 --- a/pkg/types/params.go +++ b/pkg/types/params.go @@ -8,35 +8,64 @@ import ( "main/pkg/utils" ) -type Amount struct { - Denom string - Amount string +type ChainWithVotingParams struct { + Chain *Chain + Params []ChainParam } -type ChainWithVotingParams struct { - Chain *Chain - VotingPeriod time.Duration - MinDepositAmount []Amount - MaxDepositPeriod time.Duration - Quorum float64 - Threshold float64 - VetoThreshold float64 +type ChainParam interface { + GetDescription() string + Serialize() string +} + +/* ------------------------------------------------ */ + +type PercentParam struct { + Description string + Value float64 +} + +func (p PercentParam) GetDescription() string { + return p.Description +} + +func (p PercentParam) Serialize() string { + return fmt.Sprintf("%.2f%%", p.Value*100) } -func (c ChainWithVotingParams) FormatQuorum() string { - return fmt.Sprintf("%.2f%%", c.Quorum*100) +/* ------------------------------------------------ */ + +type DurationParam struct { + Description string + Value time.Duration +} + +func (p DurationParam) GetDescription() string { + return p.Description +} + +func (p DurationParam) Serialize() string { + return utils.FormatDuration(p.Value) +} + +/* ------------------------------------------------ */ + +type Amount struct { + Denom string + Amount string } -func (c ChainWithVotingParams) FormatThreshold() string { - return fmt.Sprintf("%.2f%%", c.Threshold*100) +type AmountsParam struct { + Description string + Value []Amount } -func (c ChainWithVotingParams) FormatVetoThreshold() string { - return fmt.Sprintf("%.2f%%", c.VetoThreshold*100) +func (p AmountsParam) GetDescription() string { + return p.Description } -func (c ChainWithVotingParams) FormatMinDepositAmount() string { - amountsAsStrings := utils.Map(c.MinDepositAmount, func(a Amount) string { +func (p AmountsParam) Serialize() string { + amountsAsStrings := utils.Map(p.Value, func(a Amount) string { return a.Amount + " " + a.Denom }) return strings.Join(amountsAsStrings, ",") diff --git a/pkg/types/params_test.go b/pkg/types/params_test.go index 8e9f985..d69159d 100644 --- a/pkg/types/params_test.go +++ b/pkg/types/params_test.go @@ -2,49 +2,65 @@ package types import ( "testing" + "time" "github.com/stretchr/testify/assert" ) -func TestParamsFormatQuorum(t *testing.T) { +func TestParamsDescription(t *testing.T) { t.Parallel() - params := ChainWithVotingParams{ - Quorum: 0.4, - } + assert.Equal( + t, + "Description", + PercentParam{Description: "Description"}.GetDescription(), + "Wrong value!", + ) + + assert.Equal( + t, + "Description", + AmountsParam{Description: "Description"}.GetDescription(), + "Wrong value!", + ) - assert.Equal(t, "40.00%", params.FormatQuorum(), "Wrong value!") + assert.Equal( + t, + "Description", + DurationParam{Description: "Description"}.GetDescription(), + "Wrong value!", + ) } -func TestParamsFormatThreshold(t *testing.T) { +func TestPercentParamSerialize(t *testing.T) { t.Parallel() - params := ChainWithVotingParams{ - Threshold: 0.4, + params := PercentParam{ + Value: 0.4, } - assert.Equal(t, "40.00%", params.FormatThreshold(), "Wrong value!") + assert.Equal(t, "40.00%", params.Serialize(), "Wrong value!") } -func TestParamsFormatVetoThreshold(t *testing.T) { +func TestAmountParamSerialize(t *testing.T) { t.Parallel() - params := ChainWithVotingParams{ - VetoThreshold: 0.4, + params := AmountsParam{ + Value: []Amount{ + {Denom: "stake", Amount: "100"}, + {Denom: "test", Amount: "100"}, + }, } - assert.Equal(t, "40.00%", params.FormatVetoThreshold(), "Wrong value!") + assert.Equal(t, "100 stake,100 test", params.Serialize(), "Wrong value!") } -func TestParamsFormatFormatMinDepositAmount(t *testing.T) { +func TestDurationParamSerialize(t *testing.T) { t.Parallel() - params := ChainWithVotingParams{ - MinDepositAmount: []Amount{ - {Denom: "stake", Amount: "100"}, - {Denom: "test", Amount: "100"}, - }, + params := DurationParam{ + Value: time.Hour + time.Minute, } - assert.Equal(t, "100 stake,100 test", params.FormatMinDepositAmount(), "Wrong value!") + assert.Equal(t, "1 hour 1 minute", params.Serialize(), "Wrong value!") } diff --git a/templates/telegram/params.html b/templates/telegram/params.html index 68a7f5f..df6cab5 100644 --- a/templates/telegram/params.html +++ b/templates/telegram/params.html @@ -1,9 +1,7 @@ {{- range $chainName, $params := . }} Params of chain {{ $params.Chain.GetName }}: -Voting period: {{ FormatDuration $params.VotingPeriod }} -Max deposit period: {{ FormatDuration $params.MaxDepositPeriod }} -Min deposit amount: {{ $params.FormatMinDepositAmount }} -Quorum: {{ $params.FormatQuorum }} -Threshold: {{ $params.FormatThreshold }} -Veto threshold: {{ $params.FormatVetoThreshold }} +{{- range $param := .Params }} +{{ $param.GetDescription }}: {{ $param.Serialize }} +{{- end }} + {{ end }}