From aa25835a350d4cd4c7796a810d7b8d3b4ecd3b46 Mon Sep 17 00:00:00 2001 From: armyhaylenko Date: Mon, 23 Mar 2026 15:15:14 +0200 Subject: [PATCH] feat: update `ListSwapHistory` method params --- client/swaps.go | 36 +++++++++++++++++++++++++++++++----- examples/get-history/main.go | 14 +++++++++++--- types/swaps.go | 20 ++++++++++++++++++++ 3 files changed, 62 insertions(+), 8 deletions(-) diff --git a/client/swaps.go b/client/swaps.go index 02ae9f1..c651f82 100644 --- a/client/swaps.go +++ b/client/swaps.go @@ -24,12 +24,20 @@ func (c *Client) GetSwapByIntentID(ctx context.Context, intentID uuid.UUID) (Get // ListSwapHistoryParams represents parameters for listing swap history. type ListSwapHistoryParams struct { - // Limit defines the maximum number of tokens to return. + // Limit defines the maximum number of swaps to return. Limit int64 - // Offset defines the number of tokens to skip. + // Offset defines the number of swaps to skip. Offset int64 - // Active specifies whether to return only active swaps. - Active bool + // Status defines the swap status filter (optional). + Status types.UiStatus + // Network defines the swap network filter (optional). + Network int64 + // From defines the swap `from` timestamp filter (optional). + From int64 + // To defines the swap `to` timestamp filter (optional). + To int64 + // Token defines the swap token filter (optional). + Token string // Wallets specify addresses filter. Wallets []string // RetailID specifies the retail ID filter. @@ -47,7 +55,25 @@ func (params *ListSwapHistoryParams) toQueryParams() string { q.Set("offset", strconv.FormatInt(params.Offset, 10)) } - q.Set("active", strconv.FormatBool(params.Active)) + if params.Status != "" { + q.Set("status", string(params.Status)) + } + + if params.Network != 0 { + q.Set("network", strconv.FormatInt(params.Network, 10)) + } + + if params.From != 0 { + q.Set("from", strconv.FormatInt(params.From, 10)) + } + + if params.To != 0 { + q.Set("to", strconv.FormatInt(params.To, 10)) + } + + if params.Token != "" { + q.Set("token", params.Token) + } for _, wallet := range params.Wallets { q.Add("wallet", wallet) diff --git a/examples/get-history/main.go b/examples/get-history/main.go index 72961c0..628a2e3 100644 --- a/examples/get-history/main.go +++ b/examples/get-history/main.go @@ -3,11 +3,15 @@ package main import ( "context" "log" + "time" "github.com/BoostyLabs/hotpot-sdk-go/client" "github.com/BoostyLabs/hotpot-sdk-go/examples" + "github.com/BoostyLabs/hotpot-sdk-go/types" ) +const OneDayInMs int64 = 86_400_000 + func main() { ctx := context.Background() @@ -16,11 +20,11 @@ func main() { // INFO: To specify wallet addresses and retailer ID for swap history, set one of env variables: // - WALLET_ADDRESSES: export WALLET_ADDRESSES=0x1234567890123456789012345678901234567890,bc1pg02klrmyzfkeftcn4j3v2dyly5xh9mpcf5dunxhjst25w7ayu9uq6t2ja0 - // - RETAILER_ID: export RETAILER_ID=1234567890 + // - RETAIL_ID: export RETAIL_ID=1234567890 // // NOTE: Only one of these variables should be set. // - // LIMIT, OFFSET, ACTIVE can be set via env variables. + // LIMIT, OFFSET, NETWORK_ID, TOKEN can be set via env variables. log.Printf("Getting swap history by addresses: %v", cfg.WalletAddresses) log.Printf("or by retail id: %s", cfg.RetailID) @@ -30,7 +34,11 @@ func main() { RetailID: cfg.RetailID, Limit: cfg.Limit, Offset: cfg.Offset, - Active: cfg.ActiveSwaps, + Status: types.UiStatusSubmitted, + Network: cfg.NetworkID, + From: time.Now().UnixMilli() - OneDayInMs, + To: time.Now().UnixMilli() + OneDayInMs, + Token: cfg.Token, }) if err != nil { log.Fatalf("failed to get swap history: %v", err) diff --git a/types/swaps.go b/types/swaps.go index dde771f..9775909 100644 --- a/types/swaps.go +++ b/types/swaps.go @@ -41,3 +41,23 @@ type SwapAdditionalInfo struct { MinDestAmountLots *Int `json:"min_dest_amount_lots"` MaxDestAmountLots *Int `json:"max_dest_amount_lots"` } + +// UiStatus represents a human-readable status of a swap. +type UiStatus string + +const ( + // UiStatusSubmitted defines the `Submitted` status. + UiStatusSubmitted UiStatus = "Submitted" + // UiStatusFailed defines the `Failed` status. + UiStatusFailed UiStatus = "Failed" + // UiStatusExecuting defines the `Executing` status. + UiStatusExecuting UiStatus = "Executing" + // UiStatusCompleted defines the `Completed` status. + UiStatusCompleted UiStatus = "Completed" + // UiStatusRefunding defines the `Refunding` status. + UiStatusRefunding UiStatus = "Refunding" + // UiStatusRefunded defines the `Refunded` status. + UiStatusRefunded UiStatus = "Refunded" + // UiStatusExpired defines the `Expired` status. + UiStatusExpired UiStatus = "Expired" +)