From 710851c00305678149ff571c6440043259b53beb Mon Sep 17 00:00:00 2001 From: brightiron Date: Thu, 21 Dec 2023 20:02:54 -0600 Subject: [PATCH] cleanup. docs. env vars. one click deploy --- .env.example | 25 +--- README.md | 8 ++ .../environment/Environment/Environment.ts | 12 -- .../Environment/Environment.unit.test.ts | 7 -- src/hooks/useZapTokenBalances.ts | 109 ------------------ src/hooks/useZeroExSwap.ts | 3 +- 6 files changed, 15 insertions(+), 149 deletions(-) delete mode 100644 src/hooks/useZapTokenBalances.ts diff --git a/.env.example b/.env.example index d1c2189e10..9630759c9a 100644 --- a/.env.example +++ b/.env.example @@ -1,17 +1,9 @@ -# Required -# Covalent (https://www.covalenthq.com/) -VITE_COVALENT_API_KEY="" - -# Optional -# Toggle to "true" to use Olympus Give features -VITE_GIVE_ENABLED="true" -# This should be toggled to "true" if you need to use the mock sOHM contract -# (which allows for on-demand rebasing) -VITE_MOCK_SOHM_ENABLED="false" # Optional # Google Analytics (https://analytics.google.com/) VITE_GOOGLE_ANALYTICS_API_KEY="" +# Google Analytics 4 API Key +VITE_GA_4_API_KEY="" # Optional # If you run your own node, you can provide connection url(s) to that node. @@ -25,14 +17,6 @@ VITE_FANTOM_TESTNET_NODE_URL="" VITE_POLYGON_NODE_URL="" VITE_POLYGON_TESTNET_NODE_URL="" -# Olympus Give -# These 2 settings should be toggled to "true" if you want to use Olympus Give features -VITE_GIVE_ENABLED="true" -VITE_GIVE_GRANTS_ENABLED="true" - -# This should be toggled to "true" if you need to use the mock sOHM contract -# (which allows for on-demand rebasing) -VITE_MOCK_SOHM_ENABLED="false" VITE_ARBITRUM_NODE_URL="" VITE_ARBITRUM_TESTNET_NODE_URL="" @@ -41,4 +25,7 @@ VITE_AVALANCHE_NODE_URL="" VITE_AVALANCHE_TESTNET_NODE_URL="" # Get a wallet connect project id here: https://cloud.walletconnect.com -VITE_WALLETCONNECT_PROJECT_ID="" \ No newline at end of file +VITE_WALLETCONNECT_PROJECT_ID="" + +#Subgraph URL for Protocol Metrics. If not set Protocol Metrics will not be displayed. +VITE_WG_PUBLIC_NODE_URL="" diff --git a/README.md b/README.md index 8d12c379d3..5f96f8b8b0 100644 --- a/README.md +++ b/README.md @@ -229,3 +229,11 @@ If editing the production content, opt to create a new branch and pull request, ## 🗣 Community and Contributions - [Join our Discord](https://discord.gg/OlympusDAO) and ask how you can get involved with the DAO! + + + +## Deploy Your Own Frontend + +[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2FOlympusDAO%2Folympus-frontend&env=VITE_WALLETCONNECT_PROJECT_ID&envDescription=Please%20see%20.env.example%20for%20all%20other%20optional%20ENV%20variables&envLink=https%3A%2F%2Fgithub.com%2FOlympusDAO%2Folympus-frontend%2Fblob%2Fdevelop%2F.env.example) +[![Deploy to Netlify](https://www.netlify.com/img/deploy/button.svg)](https://app.netlify.com/start/deploy?repository=https://github.com/OlympusDAO/olympus-frontend) + diff --git a/src/helpers/environment/Environment/Environment.ts b/src/helpers/environment/Environment/Environment.ts index a1aaa1a736..7637567b84 100644 --- a/src/helpers/environment/Environment/Environment.ts +++ b/src/helpers/environment/Environment/Environment.ts @@ -37,14 +37,6 @@ export class Environment { err: "Please provide an Google Analytics 4 API key in your .env file", }); - public static getZapperApiKey = () => - this._get({ - first: true, - key: "VITE_ZAPPER_API", - // NOTE: default Zapper API key. Won't work in production with any real volume of usage. - fallback: "96e0cc51-a62e-42ca-acee-910ea7d2a241", - }); - public static getWundergraphNodeUrl = (): string | undefined => this._get({ first: true, @@ -136,8 +128,4 @@ export class Environment { }); } }; - - public static isWalletNewsEnabled() { - return this.env.VITE_DISABLE_NEWS !== "true"; - } } diff --git a/src/helpers/environment/Environment/Environment.unit.test.ts b/src/helpers/environment/Environment/Environment.unit.test.ts index f550f6765f..4fe5f68a17 100644 --- a/src/helpers/environment/Environment/Environment.unit.test.ts +++ b/src/helpers/environment/Environment/Environment.unit.test.ts @@ -44,13 +44,6 @@ describe("Environment", () => { }); }); - describe("Zapper", () => { - it("should return a Zapper API key", () => { - import.meta.env.VITE_ZAPPER_API = "somekey"; - expect(Environment.getZapperApiKey()).toEqual("somekey"); - }); - }); - describe("StagingEnv", () => { it("should return a StagingEnv", () => { import.meta.env.VITE_STAGING_ENV = "false"; diff --git a/src/hooks/useZapTokenBalances.ts b/src/hooks/useZapTokenBalances.ts deleted file mode 100644 index 21c2d14a52..0000000000 --- a/src/hooks/useZapTokenBalances.ts +++ /dev/null @@ -1,109 +0,0 @@ -import { useQuery } from "@tanstack/react-query"; -import { BigNumber, ethers } from "ethers"; -import { Environment } from "src/helpers/environment/Environment/Environment"; -import { useAccount } from "wagmi"; - -interface ZapperResponse { - [key: string]: ZapperAddress; -} - -interface ZapperAddress { - products: ZapperProduct[]; -} - -interface ZapperProduct { - assets: ZapperToken[]; - label: string; -} - -export interface ZapperToken { - address: string; - decimals: number; - hide: boolean; - displayProps: { - images: string[]; - label: string; - }; - symbol: string; - price: number; - network: string; - balance: number; - balanceRaw: string; - balanceUSD: number; - tokens: []; -} - -export interface ZapHelperBalancesResponse { - balances: { [key: string]: ZapperToken }; -} - -export const zapTokenBalancesKey = (address: string) => ["zapTokenBalances", address]; - -/** - * Asynchronously fetches the token balances for the current wallet. - * - * This hook uses react-query to fetch the token balances via the Zapper API. - * The Zapper API is used as it returns an exhaustive list of the tokens in - * the wallet, along with the balances and USD value. Doing this manually would - * require querying balances for an exhaustive list of token contracts, so the Zapper - * API is quicker. - * - * Caveats: - * - The Zapper API supports Ethereum mainnet only, which makes it difficult to conduct testing. - * - * @returns react-query result - */ -export const useZapTokenBalances = () => { - const { address = "", isConnected } = useAccount(); - - const key = zapTokenBalancesKey(address); - return useQuery( - [key], - async () => { - // TODO handle missing API key - const apiKey = Environment.getZapperApiKey(); - try { - const addressLower = address.toLowerCase(); - console.debug("Refetching Zap token balances"); - const response = await fetch( - `https://api.zapper.fi/v2/apps/tokens/balances?api_key=${apiKey}&addresses%5B%5D=${addressLower}&newBalances=true`, - ); - const responseJson = await response.json(); - if (response.ok) { - return parseResponse(responseJson.balances, addressLower); - } else { - throw Error(JSON.stringify(responseJson)); - } - } catch (e) { - console.error(e); - throw e; - } - }, - { enabled: !!address && !!isConnected }, - ); -}; - -/** - * This function formats the `ZapperResponse`. - * - * @param response JSON-formatted response from Zapper - * @param address wallet address (lowercase) - * @returns ZapHelperBalancesResponse object - */ -const parseResponse = (response: ZapperResponse, address: string): ZapHelperBalancesResponse => { - const parsed = response[address].products.find(product => product.label === "Tokens"); - const arr = parsed?.assets.map(token => [token.symbol.toLowerCase(), token]) ?? null; - const result = { balances: arr == null ? {} : Object.fromEntries(arr) }; - - if (result.balances["ohm"]) { - result.balances["ohm"].hide = true; - } - - for (const key in result.balances) { - const balance = result.balances[key]; - const balanceRaw = balance.balanceRaw; - const balanceBigNumber = BigNumber.from(balanceRaw); - balance.balanceRaw = ethers.utils.formatUnits(balanceBigNumber, balance.decimals); - } - return result; -}; diff --git a/src/hooks/useZeroExSwap.ts b/src/hooks/useZeroExSwap.ts index c77dca032a..20d42cc3f5 100644 --- a/src/hooks/useZeroExSwap.ts +++ b/src/hooks/useZeroExSwap.ts @@ -6,7 +6,6 @@ import { DAO_TREASURY_ADDRESSES, GOHM_ADDRESSES } from "src/constants/addresses" import { SOHM_ADDRESSES } from "src/constants/addresses"; import { trackGAEvent } from "src/helpers/analytics/trackGAEvent"; import { balanceQueryKey } from "src/hooks/useBalance"; -import { zapTokenBalancesKey } from "src/hooks/useZapTokenBalances"; import { EthersError } from "src/lib/EthersTypes"; import { useAccount, useSigner } from "wagmi"; @@ -41,7 +40,7 @@ export const useZeroExSwap = () => { const client = useQueryClient(); const { data: signer } = useSigner(); const { address = "" } = useAccount(); - + const zapTokenBalancesKey = (address: string) => ["zapTokenBalances", address]; return useMutation( /** * Ideally the parameters to this async function should be the slippage, etc.