Skip to content

Commit

Permalink
Switched to use env vars for RPC URLs instead of infura URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
jferas committed Jan 17, 2024
1 parent 354a5e1 commit fa4b3e9
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 10 deletions.
22 changes: 15 additions & 7 deletions frontend/src/components/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@ import { BigNumber } from 'src/utils/ethers';
import { JsonRpcSigner, Web3Provider } from 'src/utils/ethers';
import type { TokenList, TokenInfo } from '@uniswap/token-lists/dist/types';
import { UmbraLogger } from 'components/logger';
import { ETH_NETWORK_LOGO } from 'src/utils/constants';
import {
ETH_NETWORK_LOGO,
MAINNET_RPC_URL,
POLYGON_RPC_URL,
OPTIMISM_RPC_URL,
SEPOLIA_RPC_URL,
ARBITRUM_ONE_RPC_URL,
GNOSIS_CHAIN_RPC_URL,
} from 'src/utils/constants';

export type { TokenList, TokenInfo } from '@uniswap/token-lists/dist/types';
export { BigNumber } from 'src/utils/ethers';
Expand Down Expand Up @@ -50,7 +58,7 @@ export const supportedChains: Array<Chain> = [
decimals: 18,
logoURI: ETH_NETWORK_LOGO,
},
rpcUrls: [`https://mainnet.infura.io/v3/${String(process.env.INFURA_ID)}`],
rpcUrls: [MAINNET_RPC_URL],
blockExplorerUrls: ['https://etherscan.io'],
iconUrls: [ETH_NETWORK_LOGO],
logoURI: ETH_NETWORK_LOGO,
Expand All @@ -65,7 +73,7 @@ export const supportedChains: Array<Chain> = [
decimals: 18,
logoURI: ETH_NETWORK_LOGO,
},
rpcUrls: [`https://sepolia.infura.io/v3/${String(process.env.INFURA_ID)}`],
rpcUrls: [SEPOLIA_RPC_URL],
blockExplorerUrls: ['https://sepolia.etherscan.io'],
iconUrls: [ETH_NETWORK_LOGO],
logoURI: ETH_NETWORK_LOGO,
Expand All @@ -80,7 +88,7 @@ export const supportedChains: Array<Chain> = [
decimals: 18,
logoURI: ETH_NETWORK_LOGO,
},
rpcUrls: ['https://mainnet.optimism.io', `https://optimism-mainnet.infura.io/v3/${String(process.env.INFURA_ID)}`],
rpcUrls: ['https://mainnet.optimism.io', OPTIMISM_RPC_URL],
blockExplorerUrls: ['https://optimistic.etherscan.io'],
iconUrls: ['/networks/optimism.svg'],
logoURI: '/networks/optimism.svg',
Expand All @@ -95,7 +103,7 @@ export const supportedChains: Array<Chain> = [
decimals: 18,
logoURI: 'https://docs.gnosischain.com/img/tokens/xdai.png',
},
rpcUrls: ['https://rpc.ankr.com/gnosis'],
rpcUrls: ['https://rpc.ankr.com/gnosis', GNOSIS_CHAIN_RPC_URL],
blockExplorerUrls: ['https://gnosisscan.io'],
iconUrls: ['/networks/gnosis.svg'],
logoURI: '/networks/gnosis.svg',
Expand All @@ -110,7 +118,7 @@ export const supportedChains: Array<Chain> = [
decimals: 18,
logoURI: '/tokens/polygon.png',
},
rpcUrls: ['https://polygon-rpc.com/', `https://polygon-mainnet.infura.io/v3/${String(process.env.INFURA_ID)}`],
rpcUrls: ['https://polygon-rpc.com/', POLYGON_RPC_URL],
blockExplorerUrls: ['https://polygonscan.com'],
iconUrls: ['/networks/polygon.svg'],
logoURI: '/networks/polygon.svg',
Expand All @@ -125,7 +133,7 @@ export const supportedChains: Array<Chain> = [
decimals: 18,
logoURI: ETH_NETWORK_LOGO,
},
rpcUrls: ['https://arb1.arbitrum.io/rpc', `https://arbitrum-mainnet.infura.io/v3/${String(process.env.INFURA_ID)}`],
rpcUrls: ['https://arb1.arbitrum.io/rpc', ARBITRUM_ONE_RPC_URL],
blockExplorerUrls: ['https://arbiscan.io'],
iconUrls: ['/networks/arbitrum.svg'],
logoURI: '/networks/arbitrum.svg',
Expand Down
26 changes: 24 additions & 2 deletions frontend/src/utils/address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@ import {
import { getChainById, jsonFetch } from 'src/utils/utils';
import { tc } from '../boot/i18n';
import Resolution from '@unstoppabledomains/resolution';
import { MAINNET_PROVIDER, POLYGON_PROVIDER, MULTICALL_ABI, MULTICALL_ADDRESS } from 'src/utils/constants';
import {
MAINNET_PROVIDER,
POLYGON_PROVIDER,
MULTICALL_ABI,
MULTICALL_ADDRESS,
MAINNET_RPC_URL,
} from 'src/utils/constants';
import { AddressZero, defaultAbiCoder } from 'src/utils/ethers';
import { UmbraApi } from 'src/utils/umbra-api';

Expand Down Expand Up @@ -49,7 +55,23 @@ export const lookupEnsName = async (address: string, provider: Provider | Static
export const lookupCnsName = async (address: string) => {
try {
// Send request to get names
const resolution = Resolution.infura(String(process.env.INFURA_ID));

const resolution = new Resolution({
sourceConfig: {
uns: {
locations: {
Layer1: {
url: MAINNET_RPC_URL,
network: 'mainnet',
},
Layer2: {
url: '',
network: '',
},
},
},
},
});
const domain = await resolution.reverse(address);
return domain;
} catch (err) {
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ export const MAINNET_RPC_URL = String(process.env.MAINNET_RPC_URL);
export const MAINNET_PROVIDER = new StaticJsonRpcProvider(MAINNET_RPC_URL);
export const POLYGON_RPC_URL = String(process.env.POLYGON_RPC_URL);
export const POLYGON_PROVIDER = new StaticJsonRpcProvider(POLYGON_RPC_URL);
export const OPTIMISM_RPC_URL = String(process.env.OPTIMISM_RPC_URL);
export const ARBITRUM_ONE_RPC_URL = String(process.env.ARBITRUM_ONE_RPC_URL);
export const SEPOLIA_RPC_URL = String(process.env.SEPOLIA_RPC_URL);
export const GNOSIS_CHAIN_RPC_URL = String(process.env.GNOSIS_CHAIN_RPC_URL);

console.log(`MAINNET_RPC_URL ${MAINNET_RPC_URL}`);

Expand Down
3 changes: 2 additions & 1 deletion frontend/src/utils/payment-links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import { providerExport as provider, relayerExport as relayer, tokensExport as t
import { notifyUser } from 'src/utils/alerts';
import { BigNumber, StaticJsonRpcProvider } from 'src/utils/ethers';
import { UmbraApi } from 'src/utils/umbra-api';
import { MAINNET_RPC_URL } from 'src/utils/constants';

/**
* @notice Returns a provider, falling back to a mainnet provider if user's wallet is not connected
*/
function getProvider() {
return provider || new StaticJsonRpcProvider(`https://mainnet.infura.io/v3/${String(process.env.INFURA_ID)}`);
return provider || new StaticJsonRpcProvider(MAINNET_RPC_URL);
}

/**
Expand Down

0 comments on commit fa4b3e9

Please sign in to comment.