Skip to content

Commit

Permalink
Fix (?) 0x api
Browse files Browse the repository at this point in the history
  • Loading branch information
SvineruS committed Jul 12, 2023
1 parent cba8a4e commit a2878fd
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 2 additions & 3 deletions relay/pkg/price/price_0x.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ const (
var NetworkUrls = []NetworkUrl{EthUrl, BscUrl}
var ErrValidationFailed = errors.New("Validation Failed")

var ApiKey = os.Getenv("0X_API_KEY")

type NetworkUrl string
type response struct {
Price float64 `json:"price,string"`
Expand Down Expand Up @@ -49,14 +47,15 @@ func Get0x(token *TokenInfo) (price float64, err error) {
}

func doRequest(urlFormat NetworkUrl, sellToken string) (float64, error) {
apiKey := os.Getenv("0X_API_KEY")
client := http.Client{}

url := fmt.Sprintf(string(urlFormat), sellToken)
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return 0, err
}
req.Header.Set("0x-api-key", ApiKey)
req.Header.Set("0x-api-key", apiKey)

resp, err := client.Do(req)
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions relay/pkg/price/price_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ package price

import (
"fmt"
"os"
"testing"

"github.com/ethereum/go-ethereum/common"
)

func Test0x(t *testing.T) {
os.Setenv("0X_API_KEY", "c7a70fdd-3474-425b-9fc3-2e40a7275ca3") // test api key
e, err := TokenToUSD(&TokenInfo{Symbol: "ETH", Decimals: 18, Address: common.Address{}})
if err != nil {
t.Fatal(err)
Expand Down

0 comments on commit a2878fd

Please sign in to comment.