diff --git a/apps/web/components/request-form.tsx b/apps/web/components/request-form.tsx index 0d95ff784..63fac3ba9 100644 --- a/apps/web/components/request-form.tsx +++ b/apps/web/components/request-form.tsx @@ -148,6 +148,7 @@ export const RequestForm: FC = ({ isOutOfCELO, network }) => { /> CELO Only + {/* @ts-ignore */} setTimeout(resolve, time)) } -const tokens = { - alfajores: [ - { - symbol: 'cEUR', - address: '0x10c892A6EC43a53E45D0B916B4b7D383B1b78C0F', - }, - { - symbol: 'cREAL', - address: '0xE4D517785D091D3c54818832dB6094bcc2744545', - }, - { - symbol: 'cUSD', - address: '0x874069Fa1Eb16D44d622F2e0Ca25eeA172369bC1', - }, - ], - cannoli: [ - { - symbol: 'cEUR', - address: '0x6ede0baedEb76CdF45B40f79bb466759B9EfF1a0', - }, - { - symbol: 'cREAL', - address: '0xAa6ba7cFB47C2FC36Cc842eEf67889519ebEF9a7', - }, - { - symbol: 'cUSD', - address: '0x2Bece2F1e31237085A0da4BB12F091D38d832431', - }, - ], -} - interface TokenParams { type: 'ERC20' options: { @@ -143,22 +113,3 @@ interface EthProvider { ): this removeAllListeners(event?: string | symbol): this } - -const CHAIN_PARAMS = { - alfajores: { - chainId: '0xaef3', - chainName: 'Alfajores Testnet', - nativeCurrency: { name: 'Alfajores Celo', symbol: 'A-CELO', decimals: 18 }, - rpcUrls: ['https://alfajores-forno.celo-testnet.org'], - blockExplorerUrls: ['https://explorer.celo.org/alfajores'], - iconUrls: ['future'], - }, - cannoli: { - chainId: '0x43ab', - chainName: 'Cannoli Testnet', - nativeCurrency: { name: 'Cannoli Celo', symbol: 'C-CELO', decimals: 18 }, - rpcUrls: ['https://forno.cannoli.celo-testnet.org'], - blockExplorerUrls: ['https://explorer.celo.org/cannoli'], - iconUrls: ['future'], - }, -} diff --git a/apps/web/config/chains.ts b/apps/web/config/chains.ts new file mode 100644 index 000000000..9be7f4914 --- /dev/null +++ b/apps/web/config/chains.ts @@ -0,0 +1,47 @@ +import { Network } from 'types' + +interface ChainParams { + chainId: `0x${string}` + chainName: string + nativeCurrency: { + name: string + symbol: string + decimals: number + } + rpcUrls: string[] + blockExplorerUrls: string[] + iconUrls: string[] +} + +export const CHAIN_PARAMS: Record = { + alfajores: { + chainId: '0xaef3', + chainName: 'Alfajores Testnet', + nativeCurrency: { name: 'Alfajores Celo', symbol: 'A-CELO', decimals: 18 }, + rpcUrls: ['https://alfajores-forno.celo-testnet.org'], + blockExplorerUrls: ['https://explorer.celo.org/alfajores'], + iconUrls: ['future'], + }, +} + +interface Token { + symbol: string + address: `0x${string}` +} + +export const tokens: Record = { + alfajores: [ + { + symbol: 'cEUR', + address: '0x10c892A6EC43a53E45D0B916B4b7D383B1b78C0F', + }, + { + symbol: 'cREAL', + address: '0xE4D517785D091D3c54818832dB6094bcc2744545', + }, + { + symbol: 'cUSD', + address: '0x874069Fa1Eb16D44d622F2e0Ca25eeA172369bC1', + }, + ], +} diff --git a/apps/web/package.json b/apps/web/package.json index 6526badd6..453963f1b 100644 --- a/apps/web/package.json +++ b/apps/web/package.json @@ -3,6 +3,7 @@ "version": "0.1.0", "private": true, "scripts": { + "setup": "vercel env pull", "dev": "next dev", "build": "next build", "start": "next start", diff --git a/apps/web/pages/[chain].tsx b/apps/web/pages/[chain].tsx index 0b27a6d0c..31567f803 100644 --- a/apps/web/pages/[chain].tsx +++ b/apps/web/pages/[chain].tsx @@ -17,7 +17,8 @@ interface Props { const Home: NextPage = ({ isOutOfCELO, network }: Props) => { const networkCapitalized = capitalize(network) - const otherNetwork = network === 'alfajores' ? 'cannoli' : 'alfajores' + const otherNetwork = + networks.indexOf(network) === 0 ? networks[1] : networks[0] return ( <> @@ -36,9 +37,11 @@ const Home: NextPage = ({ isOutOfCELO, network }: Props) => {

{networkCapitalized} Token Faucet

- - Switch to {capitalize(otherNetwork)} - + {networks.length > 1 && ( + + Switch to {capitalize(otherNetwork)} + + )}
diff --git a/apps/web/types/index.ts b/apps/web/types/index.ts index 59c7d0995..640fe9513 100644 --- a/apps/web/types/index.ts +++ b/apps/web/types/index.ts @@ -1,17 +1,15 @@ export type Address = string export type E164Number = string -export const networks = ['alfajores', 'cannoli'] -export type Network = 'alfajores' | 'cannoli' +export const networks = ['alfajores'] +export type Network = 'alfajores' export enum FaucetAddress { alfajores = '0x22579CA45eE22E2E16dDF72D955D6cf4c767B0eF', - cannoli = '0x29954EC661f0c829587ac4527825B7E8C663d0b6', } export enum ChainId { alfajores = 44787, - cannoli = 17323, } export enum RequestStatus { diff --git a/readme.md b/readme.md index e61dbd4d8..390f33d3f 100644 --- a/readme.md +++ b/readme.md @@ -1,14 +1,23 @@ - # Welcome to Alfajores Faucet app This Repo contains the code for the alfajores faucet. This is contained in 2 apps. -* The firebase app contains functions which do the actual fauceting. +- The firebase app contains functions which do the actual fauceting. -* The web app contains a UI for making requests. +- The web app contains a UI for making requests. The web app deploys automatically to vercel. -To setup the web app to run locally set the vercel project to clabs/faucet and the env variables from vercel with `vercel env pull` then run `yarn dev` +To setup the web app to run locally set the vercel project to clabs/faucet and the env variables from vercel with `vercel env pull` then run `yarn dev` + +## Adding chains + +### Web + +- Add the chain config and token info to `config/chains.ts`. + +- Add chain name to the networks array, and `ChainId` and `FaucetAddress` to enums in `types/index.ts`. +### Firebase +In the `apps/firebase` project run `yarn cli config:set` with the relevant params.