Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:CrocSwap/ambient-ts-app into dev…
Browse files Browse the repository at this point in the history
…elop
  • Loading branch information
Ben Wolski committed Jul 22, 2024
2 parents fcdadeb + 2e3ba05 commit 9c02cc3
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 34 deletions.
5 changes: 5 additions & 0 deletions src/ambient-utils/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ export const BLOCK_POLLING_RPC_URL =
? import.meta.env.VITE_BLOCK_POLLING_RPC_URL
: '';

export const MAINNET_RPC_URL =
import.meta.env.VITE_MAINNET_RPC_URL !== undefined
? import.meta.env.VITE_MAINNET_RPC_URL
: 'https://ethereum-mainnet.core.chainstack.com/55818ec2ac63dfef6ff4d1a74cf14d72';

export const BLAST_RPC_URL =
import.meta.env.VITE_BLAST_RPC_URL !== undefined
? import.meta.env.VITE_BLAST_RPC_URL
Expand Down
18 changes: 12 additions & 6 deletions src/ambient-utils/constants/networks/ethereumMainnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,29 @@ import { GCGO_ETHEREUM_URL } from '../gcgo';
import { Provider } from 'ethers';
import { bigIntToFloat } from '@crocswap-libs/sdk';

const PROVIDER_KEY =
import.meta.env.NODE_ENV === 'test'
? import.meta.env.PROVIDER_KEY
: import.meta.env.VITE_INFURA_KEY;
// const PROVIDER_KEY =
// import.meta.env.NODE_ENV === 'test'
// ? import.meta.env.PROVIDER_KEY
// : import.meta.env.VITE_INFURA_KEY;

const MAINNET_RPC_URL =
import.meta.env.VITE_MAINNET_RPC_URL !== undefined
? import.meta.env.VITE_MAINNET_RPC_URL
: 'https://ethereum-mainnet.core.chainstack.com/55818ec2ac63dfef6ff4d1a74cf14d72';

const chain = {
chainId: 1,
name: 'Ethereum',
currency: 'ETH',
rpcUrl: 'https://eth.llamarpc.com',
rpcUrl: MAINNET_RPC_URL,
explorerUrl: 'https://etherscan.io',
};

export const ethereumMainnet: NetworkIF = {
chainId: '0x1',
graphCacheUrl: GCGO_ETHEREUM_URL,
evmRpcUrl: 'https://mainnet.infura.io/v3/' + PROVIDER_KEY,
evmRpcUrl: MAINNET_RPC_URL,
// evmRpcUrl: 'https://mainnet.infura.io/v3/' + PROVIDER_KEY,
chain: chain,
shouldPollBlock: false,
marketData: '0x1',
Expand Down
29 changes: 18 additions & 11 deletions src/contexts/ChainDataContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
ALCHEMY_API_KEY,
BLOCK_POLLING_RPC_URL,
IS_LOCAL_ENV,
MAINNET_RPC_URL,
SCROLL_RPC_URL,
SHOULD_NON_CANDLE_SUBSCRIPTIONS_RECONNECT,
supportedNetworks,
Expand Down Expand Up @@ -121,17 +122,23 @@ export const ChainDataContextProvider = (props: {
const BLOCK_NUM_POLL_MS = isUserIdle ? 15000 : 5000; // poll for new block every 15 seconds when user is idle, every 5 seconds when user is active

async function pollBlockNum(): Promise<void> {
// if default RPC is Infura, use key from env variable
const nodeUrl =
chainData.nodeUrl.toLowerCase().includes('infura') &&
import.meta.env.VITE_INFURA_KEY
? chainData.nodeUrl.slice(0, -32) +
import.meta.env.VITE_INFURA_KEY
: ['0x13e31'].includes(chainData.chainId) // use blast env variable for blast network
? BLAST_RPC_URL
: ['0x82750'].includes(chainData.chainId) // use scroll env variable for scroll network
? SCROLL_RPC_URL
: blockPollingUrl;
const nodeUrl = ['0x1'].includes(chainData.chainId)
? MAINNET_RPC_URL
: ['0x13e31'].includes(chainData.chainId) // use blast env variable for blast network
? BLAST_RPC_URL
: ['0x82750'].includes(chainData.chainId) // use scroll env variable for scroll network
? SCROLL_RPC_URL
: blockPollingUrl;
// const nodeUrl =
// chainData.nodeUrl.toLowerCase().includes('infura') &&
// import.meta.env.VITE_INFURA_KEY
// ? chainData.nodeUrl.slice(0, -32) +
// import.meta.env.VITE_INFURA_KEY
// : ['0x13e31'].includes(chainData.chainId) // use blast env variable for blast network
// ? BLAST_RPC_URL
// : ['0x82750'].includes(chainData.chainId) // use scroll env variable for scroll network
// ? SCROLL_RPC_URL
// : blockPollingUrl;
try {
const lastBlockNumber = await fetchBlockNumber(nodeUrl);
if (lastBlockNumber > 0) setLastBlockNumber(lastBlockNumber);
Expand Down
43 changes: 27 additions & 16 deletions src/contexts/CrocEnvContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
mainnetETH,
getDefaultPairForChain,
BLAST_RPC_URL,
MAINNET_RPC_URL,
SCROLL_RPC_URL,
} from '../ambient-utils/constants';
import { UserDataContext } from './UserDataContext';
Expand Down Expand Up @@ -60,13 +61,16 @@ interface CrocEnvContextIF {
export const CrocEnvContext = createContext<CrocEnvContextIF>(
{} as CrocEnvContextIF,
);
const mainnetProvider = new BatchedJsonRpcProvider(
`https://mainnet.infura.io/v3/${
import.meta.env.VITE_INFURA_KEY || '4741d1713bff4013bc3075ed6e7ce091'
}`,
1,
{ staticNetwork: true },
);
const mainnetProvider = new BatchedJsonRpcProvider(MAINNET_RPC_URL, 1, {
staticNetwork: true,
});
// const mainnetProvider = new BatchedJsonRpcProvider(
// `https://mainnet.infura.io/v3/${
// import.meta.env.VITE_INFURA_KEY || '4741d1713bff4013bc3075ed6e7ce091'
// }`,
// 1,
// { staticNetwork: true },
// );
const scrollProvider = new BatchedJsonRpcProvider(SCROLL_RPC_URL, 534352, {
staticNetwork: true,
});
Expand Down Expand Up @@ -166,15 +170,22 @@ export const CrocEnvContextProvider = (props: { children: ReactNode }) => {
const [defaultUrlParams, setDefaultUrlParams] =
useState<UrlRoutesTemplate>(initUrl);

const nodeUrl =
chainData.nodeUrl.toLowerCase().includes('infura') &&
import.meta.env.VITE_INFURA_KEY
? chainData.nodeUrl.slice(0, -32) + import.meta.env.VITE_INFURA_KEY
: ['0x13e31'].includes(chainData.chainId) // use blast env variable for blast network
? BLAST_RPC_URL
: ['0x82750'].includes(chainData.chainId) // use scroll env variable for scroll network
? SCROLL_RPC_URL
: chainData.nodeUrl;
const nodeUrl = ['0x1'].includes(chainData.chainId)
? MAINNET_RPC_URL
: ['0x13e31'].includes(chainData.chainId) // use blast env variable for blast network
? BLAST_RPC_URL
: ['0x82750'].includes(chainData.chainId) // use scroll env variable for scroll network
? SCROLL_RPC_URL
: chainData.nodeUrl;
// const nodeUrl =
// chainData.nodeUrl.toLowerCase().includes('infura') &&
// import.meta.env.VITE_INFURA_KEY
// ? chainData.nodeUrl.slice(0, -32) + import.meta.env.VITE_INFURA_KEY
// : ['0x13e31'].includes(chainData.chainId) // use blast env variable for blast network
// ? BLAST_RPC_URL
// : ['0x82750'].includes(chainData.chainId) // use scroll env variable for scroll network
// ? SCROLL_RPC_URL
// : chainData.nodeUrl;

const provider = useMemo(
() =>
Expand Down
1 change: 0 additions & 1 deletion src/contexts/TradeTokenContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ export const TradeTokenContextProvider = (props: {
useContext(CrocEnvContext);
const { lastBlockNumber } = useContext(ChainDataContext);
const { setTokenBalance } = useContext(TokenBalanceContext);

const { isEnabled: isChartEnabled } = useContext(ChartContext);
const { setSimpleRangeWidth } = useContext(RangeContext);
const { tokens } = useContext(TokenContext);
Expand Down

0 comments on commit 9c02cc3

Please sign in to comment.