chore: move chainIDs to constants file

This commit is contained in:
Dario Gabriel Lipicar 2023-04-18 11:33:59 -03:00 committed by dlipicar
parent 633c8d1ed5
commit 4ef5eba6b5
4 changed files with 26 additions and 12 deletions

View File

@ -0,0 +1,13 @@
package common
type ChainID uint64
const (
EthereumMainnet uint64 = 1
EthereumGoerli uint64 = 5
EthereumSepolia uint64 = 11155111
OptimismMainnet uint64 = 10
OptimismGoerli uint64 = 420
ArbitrumMainnet uint64 = 42161
ArbitrumGoerli uint64 = 421613
)

View File

@ -11,24 +11,25 @@ import (
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/status-im/status-go/services/wallet/bigint" "github.com/status-im/status-go/services/wallet/bigint"
walletCommon "github.com/status-im/status-go/services/wallet/common"
"github.com/status-im/status-go/services/wallet/thirdparty" "github.com/status-im/status-go/services/wallet/thirdparty"
) )
func getBaseURL(chainID uint64) (string, error) { func getBaseURL(chainID uint64) (string, error) {
switch chainID { switch chainID {
case 1: case walletCommon.EthereumMainnet:
return "https://eth-mainnet.g.alchemy.com", nil return "https://eth-mainnet.g.alchemy.com", nil
case 5: case walletCommon.EthereumGoerli:
return "https://eth-goerli.g.alchemy.com", nil return "https://eth-goerli.g.alchemy.com", nil
case 11155111: case walletCommon.EthereumSepolia:
return "https://eth-sepolia.g.alchemy.com", nil return "https://eth-sepolia.g.alchemy.com", nil
case 10: case walletCommon.OptimismMainnet:
return "https://opt-mainnet.g.alchemy.com", nil return "https://opt-mainnet.g.alchemy.com", nil
case 420: case walletCommon.OptimismGoerli:
return "https://opt-goerli.g.alchemy.com", nil return "https://opt-goerli.g.alchemy.com", nil
case 42161: case walletCommon.ArbitrumMainnet:
return "https://arb-mainnet.g.alchemy.com", nil return "https://arb-mainnet.g.alchemy.com", nil
case 421613: case walletCommon.ArbitrumGoerli:
return "https://arb-goerli.g.alchemy.com", nil return "https://arb-goerli.g.alchemy.com", nil
} }

View File

@ -10,6 +10,7 @@ import (
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/status-im/status-go/services/wallet/bigint" "github.com/status-im/status-go/services/wallet/bigint"
walletCommon "github.com/status-im/status-go/services/wallet/common"
"github.com/status-im/status-go/services/wallet/thirdparty" "github.com/status-im/status-go/services/wallet/thirdparty"
) )
@ -64,7 +65,7 @@ func (o *Client) doQuery(url string) (*http.Response, error) {
func (o *Client) IsChainSupported(chainID uint64) bool { func (o *Client) IsChainSupported(chainID uint64) bool {
switch chainID { switch chainID {
case 1, 5, 42161, 11155111: case walletCommon.EthereumMainnet, walletCommon.EthereumGoerli, walletCommon.EthereumSepolia, walletCommon.ArbitrumMainnet:
return true return true
} }
return false return false

View File

@ -16,6 +16,7 @@ import (
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
"github.com/status-im/status-go/services/wallet/bigint" "github.com/status-im/status-go/services/wallet/bigint"
walletCommon "github.com/status-im/status-go/services/wallet/common"
"github.com/status-im/status-go/services/wallet/thirdparty" "github.com/status-im/status-go/services/wallet/thirdparty"
"github.com/status-im/status-go/services/wallet/walletevent" "github.com/status-im/status-go/services/wallet/walletevent"
) )
@ -35,11 +36,9 @@ const ChainIDRequiringAPIKey = 1
func getbaseURL(chainID uint64) (string, error) { func getbaseURL(chainID uint64) (string, error) {
switch chainID { switch chainID {
case 1, 10, 42161: case walletCommon.EthereumMainnet, walletCommon.OptimismMainnet, walletCommon.ArbitrumMainnet:
return "https://api.opensea.io/api/v1", nil return "https://api.opensea.io/api/v1", nil
case 4: case walletCommon.EthereumGoerli, walletCommon.OptimismGoerli, walletCommon.ArbitrumGoerli:
return "https://rinkeby-api.opensea.io/api/v1", nil
case 5, 420, 421613:
return "https://testnets-api.opensea.io/api/v1", nil return "https://testnets-api.opensea.io/api/v1", nil
} }