diff --git a/.env b/.env index bb0484a..8714dd4 100644 --- a/.env +++ b/.env @@ -6,3 +6,4 @@ REACT_APP_AVAILABLE_SHARDS=0,1,2,3 REACT_APP_EXPLORER_V1_API_URL=https://ctrver.t.hmny.io/ REACT_APP_INDEXER_IPFS_GATEWAY=https://ipfs.io/ipfs/ REACT_APP_PROD_ADDRESS=https://ws.explorer-v2-api.hmny.io +REACT_APP_CONTRACT_SHARD=0 diff --git a/.env.devnet b/.env.devnet index ee5925c..6f114da 100644 --- a/.env.devnet +++ b/.env.devnet @@ -6,3 +6,4 @@ REACT_APP_AVAILABLE_SHARDS=0,1 REACT_APP_EXPLORER_V1_API_URL=https://ctrver.t.hmny.io/ REACT_APP_INDEXER_IPFS_GATEWAY=https://ipfs.io/ipfs/ REACT_APP_PROD_ADDRESS=https://explorer-v2-api.ps.hmny.io +REACT_APP_CONTRACT_SHARD=0 diff --git a/.env.example b/.env.example index 36639fe..b9372f6 100644 --- a/.env.example +++ b/.env.example @@ -11,3 +11,4 @@ REACT_APP_EXPLORER_V1_API_URL=https://ctrver.t.hmny.io/ REACT_APP_INDEXER_IPFS_GATEWAY=https://ipfs.io/ipfs/ # backend websocket API url REACT_APP_PROD_ADDRESS=https://explorer-v2-api.hmny.io/ +REACT_APP_CONTRACT_SHARD=0 diff --git a/.env.testnet b/.env.testnet index 4c558d2..b6e9d1f 100644 --- a/.env.testnet +++ b/.env.testnet @@ -5,4 +5,5 @@ REACT_APP_RPC_URL_SHARD3=https://api.s3.b.hmny.io/ REACT_APP_AVAILABLE_SHARDS=0,1,2,3 REACT_APP_EXPLORER_V1_API_URL=https://ctrver.t.hmny.io/ REACT_APP_INDEXER_IPFS_GATEWAY=https://ipfs.io/ipfs/ -REACT_APP_PROD_ADDRESS=https://api.explorer.pops.one/ \ No newline at end of file +REACT_APP_PROD_ADDRESS=https://api.explorer.pops.one/ +REACT_APP_CONTRACT_SHARD=0 diff --git a/src/api/client.ts b/src/api/client.ts index 5df190e..d976965 100644 --- a/src/api/client.ts +++ b/src/api/client.ts @@ -25,6 +25,8 @@ import { eth_traceTransaction } from './rpc' // TODO: hardcode let pairCache: { [pair: string]: IPairPrice } = {}; +const contractShardID = +process.env.REACT_APP_CONTRACT_SHARD || 0 + setInterval(() => { pairCache = {}; }, 90000); @@ -154,41 +156,41 @@ export function getContractsByField(params: any[]) { } export function getAllERC20() { - return transport("getAllERC20", []) as Promise; + return transport("getAllERC20", [contractShardID]) as Promise; } export function getAllERC721() { - return transport("getAllERC721", []) as Promise; + return transport("getAllERC721", [contractShardID]) as Promise; } export function getAllERC1155() { - return transport("getAllERC1155", []) as Promise; + return transport("getAllERC1155", [contractShardID]) as Promise; } export function getUserERC20Balances(params: any[]) { - return transport("getUserERC20Balances", params) as Promise; + return transport("getUserERC20Balances", [contractShardID, ...params]) as Promise; } export function getUserERC721Assets(params: any[]) { - return transport("getUserERC721Assets", params) as Promise< + return transport("getUserERC721Assets", [contractShardID, ...params]) as Promise< IUserERC721Assets[] >; } export function getTokenERC721Assets(params: [string]) { - return transport("getTokenERC721Assets", params) as Promise< + return transport("getTokenERC721Assets", [contractShardID, ...params]) as Promise< IUserERC721Assets[] >; } export function getTokenERC1155Assets(params: [string]) { - return transport("getTokenERC1155Assets", params) as Promise< + return transport("getTokenERC1155Assets", [contractShardID, ...params]) as Promise< IUserERC721Assets[] >; } export function getUserERC1155Balances(params: [string]) { - return transport("getUserERC1155Balances", params) as Promise< + return transport("getUserERC1155Balances", [contractShardID, ...params]) as Promise< { tokenID: string; ownerAddress: string; @@ -201,7 +203,7 @@ export function getUserERC1155Balances(params: [string]) { } export function getTokenERC1155Balances(params: [string]) { - return transport("getTokenERC1155Balances", params) as Promise< + return transport("getTokenERC1155Balances", [contractShardID, ...params]) as Promise< { tokenID: string; ownerAddress: string; @@ -214,17 +216,17 @@ export function getTokenERC1155Balances(params: [string]) { } export function getRelatedTransactionsByType( - params: [0, string, TRelatedTransaction, any] + params: [number, string, TRelatedTransaction, any] ) { - return transport("getRelatedTransactionsByType", params) as Promise< + return transport("getRelatedTransactionsByType", [contractShardID, params[1], params[2], params[3]]) as Promise< RelatedTransaction[] >; } export function getRelatedTransactionsCountByType( - params: [0, string, TRelatedTransaction, any] + params: [number, string, TRelatedTransaction, any] ) { - return transport("getRelatedTransactionsCountByType", params) as Promise; + return transport("getRelatedTransactionsCountByType", [contractShardID, params[1], params[2], params[3]]) as Promise; } export function getBinancePairPrice(params: [string]) { @@ -242,11 +244,11 @@ export function getBinancePairHistoricalPrice(params: [string]) { } export function getERC20TokenHolders(params: [string, number, number]) { - return transport("getERC20TokenHolders", params) as Promise; + return transport("getERC20TokenHolders", [contractShardID, ...params]) as Promise; } export async function getTokenERC1155AssetDetails(address: string, tokenID: string) { - const res = await transport("getTokenERC1155AssetDetails", [address, tokenID]) + const res = await transport("getTokenERC1155AssetDetails", [contractShardID, address, tokenID]) // todo fix on backend return res && res[0] }