Skip to content

Commit

Permalink
feat: set API key via single env variable
Browse files Browse the repository at this point in the history
  • Loading branch information
vincenttaglia committed Oct 25, 2024
1 parent 0b47e54 commit 6501855
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 62 deletions.
10 changes: 6 additions & 4 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ VITE_DEFAULT_RPC_MAINNET="https://mainnet.infura.io/v3/659344f230804542a4e653f87
VITE_DEFAULT_RPC_ARBITRUM="https://arb-mainnet.g.alchemy.com/v2/er8LBcXpoFwlV8xJee-WXFbFG_M8L4JK"
VITE_DEFAULT_RPC_SEPOLIA="https://eth-sepolia.g.alchemy.com/v2/eKJ8_13LMaVi2bSITYWTMqskgsGiey8K"
VITE_DEFAULT_RPC_ARBITRUM_SEPOLIA="https://arbitrum-sepolia.infura.io/v3/db92de7c459f4d83a2c2c21931a6bdf0"
VITE_DEFAULT_SUBGRAPH_MAINNET="https://gateway-arbitrum.network.thegraph.com/api/146d8cd439901e24257f3c19d82359da/subgraphs/id/9Co7EQe5PgW3ugCUJrJgRv4u9zdEuDJf8NvMWftNsBH8"
VITE_DEFAULT_SUBGRAPH_ARBITRUM="https://gateway-arbitrum.network.thegraph.com/api/146d8cd439901e24257f3c19d82359da/subgraphs/id/DZz4kDTdmzWLWsV373w2bSmoar3umKKH9y82SUKr5qmp"
VITE_DEFAULT_SUBGRAPH_SEPOLIA="https://gateway-arbitrum.network.thegraph.com/api/146d8cd439901e24257f3c19d82359da/subgraphs/id/8pVKDwHniAz87CHEQsiz2wgFXGZXrbMDkrxgauVVfMJC"
VITE_DEFAULT_SUBGRAPH_ARBITRUM_SEPOLIA="https://gateway-arbitrum.network.thegraph.com/api/146d8cd439901e24257f3c19d82359da/subgraphs/id/3xQHhMudr1oh69ut36G2mbzpYmYxwqCeU6wwqyCDCnqV"
VITE_DEFAULT_SUBGRAPH_MAINNET="https://gateway.thegraph.com/api/[api-key]/subgraphs/id/9Co7EQe5PgW3ugCUJrJgRv4u9zdEuDJf8NvMWftNsBH8"
VITE_DEFAULT_SUBGRAPH_ARBITRUM="https://gateway.thegraph.com/api/[api-key]/subgraphs/id/DZz4kDTdmzWLWsV373w2bSmoar3umKKH9y82SUKr5qmp"
VITE_DEFAULT_SUBGRAPH_SEPOLIA="https://gateway.thegraph.com/api/[api-key]/subgraphs/id/8pVKDwHniAz87CHEQsiz2wgFXGZXrbMDkrxgauVVfMJC"
VITE_DEFAULT_SUBGRAPH_ARBITRUM_SEPOLIA="https://gateway.thegraph.com/api/[api-key]/subgraphs/id/3xQHhMudr1oh69ut36G2mbzpYmYxwqCeU6wwqyCDCnqV"
VITE_DEFAULT_QOS_SUBGRAPH="https://gateway.thegraph.com/api/[api-key]/subgraphs/id/Dtr9rETvwokot4BSXaD5tECanXfqfJKcvHuaaEgPDD2D"
VITE_GRAPH_API_KEY="3bab348a7c385b1870039eb890fd0a5f"
22 changes: 11 additions & 11 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
#!/bin/sh

NO_ENV_ACCOUNTS='[ { "address": "0x1b92e4cba0f82c85c1298af861247849988c788c", "name": "vincenttaglia-indexer.eth", "active": true, "chain": "arbitrum-one", "agentConnect": false, "agentEndpoint": "", "poiQuery": false, "poiQueryEndpoint": "" } ]'

JSON_STRING="{
\"DEFAULT_ACCOUNTS\": ${DEFAULT_ACCOUNTS:-$NO_ENV_ACCOUNTS},
\"DEFAULT_RPC_MAINNET\": \"${DEFAULT_RPC_MAINNET:-https://mainnet.infura.io/v3/659344f230804542a4e653f875172105}\",
\"DEFAULT_RPC_ARBITRUM\": \"${DEFAULT_RPC_ARBITRUM:-https://arb-mainnet.g.alchemy.com/v2/er8LBcXpoFwlV8xJee-WXFbFG_M8L4JK}\",
\"DEFAULT_RPC_SEPOLIA\": \"${DEFAULT_RPC_SEPOLIA:-https://eth-sepolia.g.alchemy.com/v2/eKJ8_13LMaVi2bSITYWTMqskgsGiey8K}\",
\"DEFAULT_RPC_ARBITRUM_SEPOLIA\": \"${DEFAULT_RPC_ARBITRUM_SEPOLIA:-https://arbitrum-sepolia.infura.io/v3/db92de7c459f4d83a2c2c21931a6bdf0}\",
\"DEFAULT_SUBGRAPH_MAINNET\": \"${DEFAULT_SUBGRAPH_MAINNET:-https://gateway-arbitrum.network.thegraph.com/api/146d8cd439901e24257f3c19d82359da/subgraphs/id/9Co7EQe5PgW3ugCUJrJgRv4u9zdEuDJf8NvMWftNsBH8}\",
\"DEFAULT_SUBGRAPH_ARBITRUM\": \"${DEFAULT_SUBGRAPH_ARBITRUM:-https://gateway-arbitrum.network.thegraph.com/api/146d8cd439901e24257f3c19d82359da/subgraphs/id/DZz4kDTdmzWLWsV373w2bSmoar3umKKH9y82SUKr5qmp}\",
\"DEFAULT_SUBGRAPH_SEPOLIA\": \"${DEFAULT_SUBGRAPH_SEPOLIA:-https://gateway-arbitrum.network.thegraph.com/api/146d8cd439901e24257f3c19d82359da/subgraphs/id/8pVKDwHniAz87CHEQsiz2wgFXGZXrbMDkrxgauVVfMJC}\",
\"DEFAULT_SUBGRAPH_ARBITRUM_SEPOLIA\": \"${DEFAULT_SUBGRAPH_ARBITRUM_SEPOLIA:-https://gateway-arbitrum.network.thegraph.com/api/146d8cd439901e24257f3c19d82359da/subgraphs/id/3xQHhMudr1oh69ut36G2mbzpYmYxwqCeU6wwqyCDCnqV}\"
\"DEFAULT_ACCOUNTS\": ${DEFAULT_ACCOUNTS:-\"\"},
\"DEFAULT_RPC_MAINNET\": \"${DEFAULT_RPC_MAINNET}\",
\"DEFAULT_RPC_ARBITRUM\": \"${DEFAULT_RPC_ARBITRUM}\",
\"DEFAULT_RPC_SEPOLIA\": \"${DEFAULT_RPC_SEPOLIA}\",
\"DEFAULT_RPC_ARBITRUM_SEPOLIA\": \"${DEFAULT_RPC_ARBITRUM_SEPOLIA}\",
\"DEFAULT_SUBGRAPH_MAINNET\": \"${DEFAULT_SUBGRAPH_MAINNET}\",
\"DEFAULT_SUBGRAPH_ARBITRUM\": \"${DEFAULT_SUBGRAPH_ARBITRUM}\",
\"DEFAULT_SUBGRAPH_SEPOLIA\": \"${DEFAULT_SUBGRAPH_SEPOLIA}\",
\"DEFAULT_SUBGRAPH_ARBITRUM_SEPOLIA\": \"${DEFAULT_SUBGRAPH_ARBITRUM_SEPOLIA}\",
\"DEFAULT_QOS_SUBGRAPH\": \"${DEFAULT_SUBGRAPH_ARBITRUM_SEPOLIA}\",
\"GRAPH_API_KEY\": \"${GRAPH_API_KEY}\"
}"

echo $JSON_STRING > /app/public/indexer-tools-config.json
Expand Down
10 changes: 6 additions & 4 deletions indexer-tools-config.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
"DEFAULT_RPC_ARBITRUM": "https://arb-mainnet.g.alchemy.com/v2/er8LBcXpoFwlV8xJee-WXFbFG_M8L4JK",
"DEFAULT_RPC_SEPOLIA": "https://eth-sepolia.g.alchemy.com/v2/eKJ8_13LMaVi2bSITYWTMqskgsGiey8K"
"DEFAULT_RPC_ARBITRUM_SEPOLIA": "https://arbitrum-sepolia.infura.io/v3/db92de7c459f4d83a2c2c21931a6bdf0"
"DEFAULT_SUBGRAPH_MAINNET": "https://gateway-arbitrum.network.thegraph.com/api/146d8cd439901e24257f3c19d82359da/subgraphs/id/9Co7EQe5PgW3ugCUJrJgRv4u9zdEuDJf8NvMWftNsBH8"
"DEFAULT_SUBGRAPH_ARBITRUM": "https://gateway-arbitrum.network.thegraph.com/api/146d8cd439901e24257f3c19d82359da/subgraphs/id/DZz4kDTdmzWLWsV373w2bSmoar3umKKH9y82SUKr5qmp"
"DEFAULT_SUBGRAPH_SEPOLIA": "https://gateway-arbitrum.network.thegraph.com/api/146d8cd439901e24257f3c19d82359da/subgraphs/id/8pVKDwHniAz87CHEQsiz2wgFXGZXrbMDkrxgauVVfMJC"
"DEFAULT_SUBGRAPH_ARBITRUM_SEPOLIA": "https://gateway-arbitrum.network.thegraph.com/api/146d8cd439901e24257f3c19d82359da/subgraphs/id/3xQHhMudr1oh69ut36G2mbzpYmYxwqCeU6wwqyCDCnqV"
"DEFAULT_SUBGRAPH_MAINNET": "https://gateway.thegraph.com/api/[api-key]/subgraphs/id/9Co7EQe5PgW3ugCUJrJgRv4u9zdEuDJf8NvMWftNsBH8",
"DEFAULT_SUBGRAPH_ARBITRUM": "https://gateway.thegraph.com/api/[api-key]/subgraphs/id/DZz4kDTdmzWLWsV373w2bSmoar3umKKH9y82SUKr5qmp",
"DEFAULT_SUBGRAPH_SEPOLIA": "https://gateway.thegraph.com/api/[api-key]/subgraphs/id/8pVKDwHniAz87CHEQsiz2wgFXGZXrbMDkrxgauVVfMJC",
"DEFAULT_SUBGRAPH_ARBITRUM_SEPOLIA": "https://gateway.thegraph.com/api/[api-key]/subgraphs/id/3xQHhMudr1oh69ut36G2mbzpYmYxwqCeU6wwqyCDCnqV",
"DEFAULT_QOS_SUBGRAPH": "https://gateway.thegraph.com/api/[api-key]/subgraphs/id/Dtr9rETvwokot4BSXaD5tECanXfqfJKcvHuaaEgPDD2D",
"DEFAULT_GRAPH_API_KEY": "3bab348a7c385b1870039eb890fd0a5f"
}
63 changes: 25 additions & 38 deletions src/plugins/defaultsConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,52 +15,39 @@ export const defaultsConfig = {
*/
export const loadDefaultsConfig = async () => {
const resp = await fetch('/indexer-tools-config.json');
let value;
let json;
if(resp.ok){
const value = await resp.json()

return {
variables: {
accounts: value.DEFAULT_ACCOUNTS,
rpcMainnet: value.DEFAULT_RPC_MAINNET,
rpcArbitrum: value.DEFAULT_RPC_ARBITRUM,
rpcSepolia: value.DEFAULT_RPC_SEPOLIA,
rpcArbitrumSepolia: value.DEFAULT_RPC_ARBITRUM_SEPOLIA,
subgraphMainnet: value.DEFAULT_SUBGRAPH_MAINNET,
subgraphArbitrum: value.DEFAULT_SUBGRAPH_ARBITRUM,
subgraphSepolia: value.DEFAULT_SUBGRAPH_SEPOLIA,
subgraphArbitrumSepolia: value.DEFAULT_SUBGRAPH_ARBITRUM_SEPOLIA,
}
}
value = await resp.json();
}else{
value = {};
}

}else if(import.meta.env.VITE_DEFAULT_ACCOUNTS != undefined){
return {
variables: {
accounts: JSON.parse(import.meta.env.VITE_DEFAULT_ACCOUNTS),
rpcMainnet: import.meta.env.VITE_DEFAULT_RPC_MAINNET,
rpcArbitrum: import.meta.env.VITE_DEFAULT_RPC_ARBITRUM,
rpcSepolia: import.meta.env.VITE_DEFAULT_RPC_SEPOLIA,
rpcArbitrumSepolia: import.meta.env.VITE_DEFAULT_RPC_ARBITRUM_SEPOLIA,
subgraphMainnet: import.meta.env.VITE_DEFAULT_SUBGRAPH_MAINNET,
subgraphArbitrum: import.meta.env.VITE_DEFAULT_SUBGRAPH_ARBITRUM,
subgraphSepolia: import.meta.env.VITE_DEFAULT_SUBGRAPH_SEPOLIA,
subgraphArbitrumSepolia: import.meta.env.VITE_DEFAULT_SUBGRAPH_ARBITRUM_SEPOLIA,
}
}
if(import.meta.env.VITE_DEFAULT_ACCOUNTS){
json = JSON.parse(import.meta.env.VITE_DEFAULT_ACCOUNTS);
}else{
json = "";
}

return {
variables: {
accounts: [ { "address": "0x1b92e4cba0f82c85c1298af861247849988c788c", "name": "vincenttaglia-indexer.eth", "active": true, "chain": "arbitrum-one", "agentConnect": false, "agentEndpoint": "", "poiQuery": false, "poiQueryEndpoint": "" } ],
rpcMainnet: "https://mainnet.infura.io/v3/659344f230804542a4e653f875172105",
rpcArbitrum: "https://arb-mainnet.g.alchemy.com/v2/er8LBcXpoFwlV8xJee-WXFbFG_M8L4JK",
rpcSepolia: "https://eth-sepolia.g.alchemy.com/v2/eKJ8_13LMaVi2bSITYWTMqskgsGiey8K",
rpcArbitrumSepolia: "https://arbitrum-sepolia.infura.io/v3/db92de7c459f4d83a2c2c21931a6bdf0",
subgraphMainnet: "https://gateway-arbitrum.network.thegraph.com/api/146d8cd439901e24257f3c19d82359da/subgraphs/id/9Co7EQe5PgW3ugCUJrJgRv4u9zdEuDJf8NvMWftNsBH8",
subgraphArbitrum: "https://gateway-arbitrum.network.thegraph.com/api/146d8cd439901e24257f3c19d82359da/subgraphs/id/DZz4kDTdmzWLWsV373w2bSmoar3umKKH9y82SUKr5qmp",
subgraphSepolia: "https://gateway-arbitrum.network.thegraph.com/api/146d8cd439901e24257f3c19d82359da/subgraphs/id/8pVKDwHniAz87CHEQsiz2wgFXGZXrbMDkrxgauVVfMJC",
subgraphArbitrumSepolia: "https://gateway-arbitrum.network.thegraph.com/api/146d8cd439901e24257f3c19d82359da/subgraphs/id/3xQHhMudr1oh69ut36G2mbzpYmYxwqCeU6wwqyCDCnqV",
accounts: value.DEFAULT_ACCOUNTS || json || [ { "address": "0x1b92e4cba0f82c85c1298af861247849988c788c", "name": "vincenttaglia-indexer.eth", "active": true, "chain": "arbitrum-one", "agentConnect": false, "agentEndpoint": "", "poiQuery": false, "poiQueryEndpoint": "" } ],
rpcMainnet: value.DEFAULT_RPC_MAINNET || import.meta.env.VITE_DEFAULT_RPC_MAINNET || "https://mainnet.infura.io/v3/659344f230804542a4e653f875172105",
rpcArbitrum: value.DEFAULT_RPC_ARBITRUM || import.meta.env.VITE_DEFAULT_RPC_ARBITRUM || "https://arb-mainnet.g.alchemy.com/v2/er8LBcXpoFwlV8xJee-WXFbFG_M8L4JK",
rpcSepolia: value.DEFAULT_RPC_SEPOLIA || import.meta.env.VITE_DEFAULT_RPC_SEPOLIA || "https://eth-sepolia.g.alchemy.com/v2/eKJ8_13LMaVi2bSITYWTMqskgsGiey8K",
rpcArbitrumSepolia: value.DEFAULT_RPC_ARBITRUM_SEPOLIA || import.meta.env.VITE_DEFAULT_RPC_ARBITRUM_SEPOLIA || "https://arbitrum-sepolia.infura.io/v3/db92de7c459f4d83a2c2c21931a6bdf0",
subgraphMainnet: value.DEFAULT_SUBGRAPH_MAINNET || import.meta.env.VITE_DEFAULT_SUBGRAPH_MAINNET || "https://gateway.thegraph.com/api/[api-key]/subgraphs/id/9Co7EQe5PgW3ugCUJrJgRv4u9zdEuDJf8NvMWftNsBH8",
subgraphArbitrum: value.DEFAULT_SUBGRAPH_ARBITRUM || import.meta.env.VITE_DEFAULT_SUBGRAPH_ARBITRUM || "https://gateway.thegraph.com/api/[api-key]/subgraphs/id/DZz4kDTdmzWLWsV373w2bSmoar3umKKH9y82SUKr5qmp",
subgraphSepolia: value.DEFAULT_SUBGRAPH_SEPOLIA || import.meta.env.VITE_DEFAULT_SUBGRAPH_SEPOLIA || "https://gateway.thegraph.com/api/[api-key]/subgraphs/id/8pVKDwHniAz87CHEQsiz2wgFXGZXrbMDkrxgauVVfMJC",
subgraphArbitrumSepolia: value.DEFAULT_SUBGRAPH_ARBITRUM_SEPOLIA || import.meta.env.VITE_DEFAULT_SUBGRAPH_ARBITRUM_SEPOLIA || "https://gateway.thegraph.com/api/[api-key]/subgraphs/id/3xQHhMudr1oh69ut36G2mbzpYmYxwqCeU6wwqyCDCnqV",
qosSubgraph: value.DEFAULT_QOS_SUBGRAPH || import.meta.env.VITE_DEFAULT_QOS_SUBGRAPH || "https://gateway.thegraph.com/api/[api-key]/subgraphs/id/Dtr9rETvwokot4BSXaD5tECanXfqfJKcvHuaaEgPDD2D",
apiKey: value.GRAPH_API_KEY || import.meta.env.VITE_GRAPH_API_KEY || "3bab348a7c385b1870039eb890fd0a5f",
}
}


}

export function replaceAPI(string, apiKey){
return string.replace("[api-key]", apiKey).replace("{api-key}", apiKey);
}
10 changes: 5 additions & 5 deletions src/plugins/graphNetworkSubgraphClient.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { loadDefaultsConfig } from "./defaultsConfig";
import { loadDefaultsConfig, replaceAPI } from "./defaultsConfig";
import { ApolloClient, createHttpLink, InMemoryCache } from '@apollo/client/core'

const defaultsConfigVariables = await loadDefaultsConfig();
Expand All @@ -8,22 +8,22 @@ console.log(defaultsConfig.subgraphArbitrum);
// HTTP connection to the API
const httpLink = createHttpLink({
// You should use an absolute URL here
uri: defaultsConfig.subgraphMainnet,
uri: replaceAPI(defaultsConfig.subgraphMainnet, defaultsConfig.apiKey),
});

const arbitrumHttpLink = createHttpLink({
// You should use an absolute URL here
uri: defaultsConfig.subgraphArbitrum,
uri: replaceAPI(defaultsConfig.subgraphArbitrum, defaultsConfig.apiKey),
});

const sepoliaHttpLink = createHttpLink({
// You should use an absolute URL here
uri: defaultsConfig.subgraphSepolia,
uri: replaceAPI(defaultsConfig.subgraphSepolia, defaultsConfig.apiKey),
});

const arbitrumSepoliaHttpLink = createHttpLink({
// You should use an absolute URL here
uri: defaultsConfig.subgraphArbitrumSepolia,
uri: replaceAPI(defaultsConfig.subgraphArbitrumSepolia, defaultsConfig.apiKey),
});

// Cache implementation
Expand Down
5 changes: 5 additions & 0 deletions src/store/allocations.js
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,11 @@ export const useAllocationStore = defineStore('allocationStore', {
})
}
return data;
}).catch((err) => {
if(err.graphQLErrors){
this.loading = false;
alert(`API Error: ${err.graphQLErrors[0].message}`);
}
});
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/store/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ export const useNetworkStore = defineStore('network', {
this.networks[chain.id].currentEpoch = data.data.graphNetwork.currentEpoch;
this.networks[chain.id].issuancePerYear = data.data.graphNetwork.networkGRTIssuancePerBlock * chainStore.getBlocksPerYear;
this.networks[chain.id].totalTokensAllocated = data.data.graphNetwork.totalTokensAllocated;
}).catch((err) => {
if(err.graphQLErrors){
this.loading = false;
alert(`API Error: ${err.graphQLErrors[0].message}`);
}
}));
}
return queries;
Expand Down
5 changes: 5 additions & 0 deletions src/store/subgraphs.js
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,11 @@ export const useSubgraphsStore = defineStore({
}

return data;
}).catch((err) => {
if(err.graphQLErrors){
this.loading = false;
alert(`API Error: ${err.graphQLErrors[0].message}`);
}
});
},
async fetchData(){
Expand Down

0 comments on commit 6501855

Please sign in to comment.