From fb3ef387acd8ac8be2ad5eae4df52ea77e3bd0da Mon Sep 17 00:00:00 2001 From: Anthony Laibe Date: Fri, 17 Sep 2021 10:01:35 +0200 Subject: [PATCH] feat: Add more attributes from opensea (#2354) * feat: Add more attributes from opensea Add sale / orders information as well as collection traits * feat: add background color to opensea response * feat: Add max value and handle float to opensea response --- services/wallet/opensea.go | 39 ++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/services/wallet/opensea.go b/services/wallet/opensea.go index 563d3dbaf..2b68783d5 100644 --- a/services/wallet/opensea.go +++ b/services/wallet/opensea.go @@ -22,7 +22,10 @@ func (st *TraitValue) UnmarshalJSON(b []byte) error { if err := json.Unmarshal(b, &item); err != nil { return err } + switch v := item.(type) { + case float64: + *st = TraitValue(strconv.FormatFloat(v, 'f', 2, 64)) case int: *st = TraitValue(strconv.Itoa(v)) case string: @@ -48,8 +51,27 @@ type OpenseaTrait struct { TraitType string `json:"trait_type"` Value TraitValue `json:"value"` DisplayType string `json:"display_type"` + MaxValue string `json:"max_value"` } +type OpenseaPaymentToken struct { + ID int `json:"id"` + Symbol string `json:"symbol"` + Address string `json:"address"` + ImageURL string `json:"image_url"` + Name string `json:"name"` + Decimals int `json:"decimals"` + EthPrice string `json:"eth_price"` + UsdPrice string `json:"usd_price"` +} + +type OpenseaLastSale struct { + PaymentToken OpenseaPaymentToken `json:"payment_token"` +} + +type OpenseaSellOrder struct { + CurrentPrice string `json:"current_price"` +} type OpenseaAsset struct { ID int `json:"id"` Name string `json:"name"` @@ -60,13 +82,22 @@ type OpenseaAsset struct { Contract OpenseaContract `json:"asset_contract"` Collection OpenseaAssetCollection `json:"collection"` Traits []OpenseaTrait `json:"traits"` + LastSale OpenseaLastSale `json:"last_sale"` + SellOrders []OpenseaSellOrder `json:"sell_orders"` + BackgroundColor string `json:"background_color"` +} + +type OpenseaCollectionTrait struct { + Min float64 `json:"min"` + Max float64 `json:"max"` } type OpenseaCollection struct { - Name string `json:"name"` - Slug string `json:"slug"` - ImageURL string `json:"image_url"` - OwnedAssetCount int `json:"owned_asset_count"` + Name string `json:"name"` + Slug string `json:"slug"` + ImageURL string `json:"image_url"` + OwnedAssetCount int `json:"owned_asset_count"` + Traits map[string]OpenseaCollectionTrait `json:"traits"` } type OpenseaClient struct {