Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: pdate setup for node rpc #194

Merged
merged 3 commits into from
Feb 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion apps/staking/.env.development
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
NEXT_PUBLIC_ENVIRONMENT=development
NEXT_PUBLIC_UNLEASH_PROXY_HOST=https://preview.unleash.cartesi.io/proxy
NEXT_PUBLIC_UNLEASH_PROXY_CLIENT_KEY=bc1b71da9932b90ccd788d75203fb598c3640cabed3ccccdffd024f341a79d72
NEXT_PUBLIC_PROJECT_ID=YOUR_INFURA_PROJECT_ID
NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID=YOUR_WALLETCONNECT_PROJECT_ID
NEXT_PUBLIC_MAINNET_GRAPHQL_URL=YOUR_MAINNET_SUBGRAPH_GRAPHQL_ENDPOINT
NEXT_PUBLIC_SEPOLIA_GRAPHQL_URL=YOUR_SEPOLIA_SUBGRAPH_GRAPHQL_ENDPOINT
NEXT_PUBLIC_DAPP_URL=http://localhost:3000
NEXT_PUBLIC_RPC_URL_1=YOUR_MAINNET_RPC_NODE_ENDPOINT
NEXT_PUBLIC_RPC_URL_11155111=YOUR_SEPOLIA_RPC_NODE_ENDPOINT
NEXT_PUBLIC_RPC_URL_31337=http://localhost:8545
# SERVER SIDE
ENS_GRAPHQL_URL=YOUR_SUBGRAPH_ENS_GRAPHQL_ENDPOINT
# A ethereum mainnet RPC-NODE. Below is a free endpoint (rate-limiting may cause troubles)
Expand Down
5 changes: 4 additions & 1 deletion apps/staking/.env.production
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ NEXT_PUBLIC_ENVIRONMENT=production
NEXT_PUBLIC_UNLEASH_PROXY_HOST=https://unleash.cartesi.io/proxy
NEXT_PUBLIC_UNLEASH_PROXY_CLIENT_KEY=bc1b71da9932b90ccd788d75203fb598c3640cabed3ccccdffd024f341a79d72
NEXT_PUBLIC_GOOGLE_TAG_MANAGER_ID=GTM-MS89D9K
NEXT_PUBLIC_PROJECT_ID=YOUR_INFURA_PROJECT_ID
NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID=YOUR_WALLETCONNECT_PROJECT_ID
NEXT_PUBLIC_MAINNET_GRAPHQL_URL=YOUR_MAINNET_SUBGRAPH_GRAPHQL_ENDPOINT
NEXT_PUBLIC_SEPOLIA_GRAPHQL_URL=YOUR_SEPOLIA_SUBGRAPH_GRAPHQL_ENDPOINT
NEXT_PUBLIC_DAPP_URL=https://$NEXT_PUBLIC_VERCEL_URL
NEXT_PUBLIC_RPC_URL_1=YOUR_MAINNET_RPC_NODE_ENDPOINT
NEXT_PUBLIC_RPC_URL_11155111=YOUR_SEPOLIA_RPC_NODE_ENDPOINT
NEXT_PUBLIC_RPC_URL_31337=http://localhost:8545

# SERVER SIDE
ENS_GRAPHQL_URL=YOUR_SUBGRAPH_ENS_GRAPHQL_ENDPOINT
HTTP_MAINNET_NODE_RPC=YOUR_PAID_MAINNET_RPC_NODE
Expand Down
18 changes: 16 additions & 2 deletions apps/staking/additional.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,24 @@ declare namespace NodeJS {
NEXT_PUBLIC_UNLEASH_PROXY_HOST: string;
NEXT_PUBLIC_UNLEASH_PROXY_CLIENT_KEY: string;
NEXT_PUBLIC_GOOGLE_TAG_MANAGER_ID: string;
NEXT_PUBLIC_PROJECT_ID: string;
NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID: string;
NEXT_PUBLIC_MAINNET_GRAPHQL_URL: string;
NEXT_PUBLIC_SEPOLIA_GRAPHQL_URL: string;
/**
* the node-rpc endpoint to access ethereum mainnet network.
* Default to https://rpc.ankr.com/eth
*/
NEXT_PUBLIC_RPC_URL_1: string;
/**
* the node-rpc endpoint to access ethereum sepolia network.
* Default to 'https://rpc.ankr.com/eth_sepolia'
*/
NEXT_PUBLIC_RPC_URL_11155111: string;
/**
* the node-rpc endpoint to your local node (e.g. foundry).
* Default to http://localhost:8545
*/
NEXT_PUBLIC_RPC_URL_31337: string;
/**
* The fully-qualifies domain name of your deployed DAPP.
* @description It is strongly recommended to supply a dappUrl to the WalletConnect initial config
Expand All @@ -36,7 +50,7 @@ declare namespace NodeJS {
TURSO_AUTH_TOKEN?: string;

/**
* A node to fetch mainnet blockchain information. e.g. Alchemy / Infura.
* A node to fetch mainnet blockchain information. e.g. Alchemy / Infura. Not exposed to the client.
*/
HTTP_MAINNET_NODE_RPC: string;

Expand Down
21 changes: 15 additions & 6 deletions packages/wallet/src/useOnboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,22 @@ import { CartesiIcon, CartesiLogo } from './cartesi-images-as-string';
import { WalletType } from './definitions';
import { UnsupportedNetworkError } from './errors/UnsupportedNetworkError';

type NetworkName = keyof typeof Network;

const SELECTED_WALLETS = 'SELECTED_WALLETS_V2';
const PROJECT_ID = process.env.NEXT_PUBLIC_PROJECT_ID;
const dappUrl = process.env.NEXT_PUBLIC_DAPP_URL;
const WC_PROJECT_ID = process.env
.NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID as string;
const getRPC = (networkName: string): string =>
`https://${networkName}.infura.io/v3/${PROJECT_ID}`;

const rpcs = {
MAINNET: process.env.NEXT_PUBLIC_RPC_URL_1 || 'https://rpc.ankr.com/eth',
SEPOLIA:
process.env.NEXT_PUBLIC_RPC_URL_11155111 ||
'https://rpc.ankr.com/eth_sepolia',
LOCAL: process.env.NEXT_PUBLIC_RPC_URL_31337 || 'http://localhost:8545',
} as const;

const getRPC = (networkName: NetworkName): string => rpcs[networkName];

console.info(`dapp-url: ${dappUrl}`);

Expand Down Expand Up @@ -71,19 +80,19 @@ export const buildConfig = (
label: 'Ethereum Mainnet',
rpcUrl: ankrEnabled
? 'https://rpc.ankr.com/eth'
: getRPC('mainnet'),
: getRPC('MAINNET'),
},
{
id: `0x${convertToHex(Network.LOCAL)}`,
token: 'ETH',
label: 'localhost',
rpcUrl: 'http://localhost:8545',
rpcUrl: getRPC('LOCAL'),
},
{
id: `0x${convertToHex(Network.SEPOLIA)}`,
token: 'ETH',
label: 'Sepolia Testnet',
rpcUrl: getRPC('sepolia'),
rpcUrl: getRPC('SEPOLIA'),
},
].filter((c) => chainIds.includes(c.id));

Expand Down
4 changes: 3 additions & 1 deletion turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
"NEXT_PUBLIC_UNLEASH_PROXY_HOST",
"NEXT_PUBLIC_UNLEASH_PROXY_CLIENT_KEY",
"NEXT_PUBLIC_GOOGLE_TAG_MANAGER_ID",
"NEXT_PUBLIC_PROJECT_ID",
"NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID",
"NEXT_PUBLIC_MAINNET_GRAPHQL_URL",
"NEXT_PUBLIC_SEPOLIA_GRAPHQL_URL",
"NEXT_PUBLIC_DAPP_URL",
"NEXT_PUBLIC_RPC_URL_1",
"NEXT_PUBLIC_RPC_URL_11155111",
"NEXT_PUBLIC_RPC_URL_31337",
"ENS_GRAPHQL_URL",
"ENS_ENTRY_TTL",
"TURSO_DATABASE_URL",
Expand Down