From 09f84962b8cba9f0f92dbeab7a68da0c0c0def84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Ribeiro?= Date: Tue, 28 May 2024 22:23:35 -0300 Subject: [PATCH] fix ts errors in homewrapper --- apps/cow-amm-deployer/next.config.js | 3 - .../src/app/amms/[id]/page.tsx | 4 +- .../src/components/HomeWrapper.tsx | 77 +++++++++---------- .../src/hooks/useStandaloneAmm/index.ts | 36 ++++----- 4 files changed, 53 insertions(+), 67 deletions(-) diff --git a/apps/cow-amm-deployer/next.config.js b/apps/cow-amm-deployer/next.config.js index 42af79bbe..04bc9cc9e 100644 --- a/apps/cow-amm-deployer/next.config.js +++ b/apps/cow-amm-deployer/next.config.js @@ -18,9 +18,6 @@ const moduleExports = { }, ]; }, - experimental: { - reactCompiler: true, - }, transpilePackages: ["@bleu/gql"], reactStrictMode: true, /** diff --git a/apps/cow-amm-deployer/src/app/amms/[id]/page.tsx b/apps/cow-amm-deployer/src/app/amms/[id]/page.tsx index b23145b9e..3c50039c9 100644 --- a/apps/cow-amm-deployer/src/app/amms/[id]/page.tsx +++ b/apps/cow-amm-deployer/src/app/amms/[id]/page.tsx @@ -59,7 +59,7 @@ export default function Page({ params }: { params: { id: `0x${string}` } }) { 2, "decimal", "compact", - 0.01, + 0.01 )} @@ -75,7 +75,7 @@ export default function Page({ params }: { params: { id: `0x${string}` } }) { buildAccountCowExplorerUrl({ chainId: safe.chainId as ChainId, address: safe.safeAddress as Address, - }), + }) ) } rel="noreferrer noopener" diff --git a/apps/cow-amm-deployer/src/components/HomeWrapper.tsx b/apps/cow-amm-deployer/src/components/HomeWrapper.tsx index a0c7db80c..f05379e56 100644 --- a/apps/cow-amm-deployer/src/components/HomeWrapper.tsx +++ b/apps/cow-amm-deployer/src/components/HomeWrapper.tsx @@ -10,46 +10,41 @@ import { } from "@bleu/ui"; import { formatDate } from "@bleu/utils"; import { useSafeAppsSDK } from "@gnosis.pm/safe-apps-react-sdk"; +import { graphql } from "gql.tada"; +import request from "graphql-request"; import Image from "next/image"; import Link from "next/link"; import useSWR from "swr"; -import gql from "#/lib/gql"; +import { NEXT_PUBLIC_API_URL } from "#/lib/ponderApi"; import { Button } from "./Button"; import Fathom from "./Fathom"; import { LinkComponent } from "./Link"; -const CREATED_AMMS_FOR_USER_QUERY = ` -query($userId: String!) { - constantProductDatas( - where: { - userId:$userId, - version:"Standalone" - } - ){ - items { - id - disabled - token0 { - address - decimals - symbol - } - token1 { - address - decimals - symbol - } - order { - blockTimestamp +const CREATED_AMMS_FOR_USER_QUERY = graphql(` + query ($userId: String!) { + constantProductDatas(where: { userId: $userId, version: "Standalone" }) { + items { + id + disabled + token0 { + address + decimals + symbol + } + token1 { + address + decimals + symbol + } + order { + blockTimestamp + } } } } -} -`; - -const API_URL = "http://localhost:42069"; +`); export function HomeWrapper({ goToSafe = false }: { goToSafe?: boolean }) { const title = goToSafe ? "Open App in Safe" : "Create a CoW AMM"; @@ -57,21 +52,20 @@ export function HomeWrapper({ goToSafe = false }: { goToSafe?: boolean }) { const { safe } = useSafeAppsSDK(); const userId = `${safe.safeAddress}-${safe.chainId}`; - const { data } = useSWR(CREATED_AMMS_FOR_USER_QUERY, (query) => - gql(API_URL, query, { userId }), + const { data, isLoading } = useSWR(CREATED_AMMS_FOR_USER_QUERY, (query) => + request(NEXT_PUBLIC_API_URL, query, { userId }) ); - const rows = (data?.data?.constantProductDatas?.items ?? []).map( - // @ts-expect-error - (item) => ({ - id: item.id, - token0: item.token0.symbol, - token1: item.token1.symbol, - state: item.disabled ? "Stopped" : "Running", - link: `/amms/${item.id}`, - createdAt: new Date(item.order.blockTimestamp * 1000), - }), - ); + if (isLoading || !data) return <>Loading...; + + const rows = data.constantProductDatas.items.map((item) => ({ + id: item.id, + token0: item.token0.symbol, + token1: item.token1.symbol, + state: item.disabled ? "Stopped" : "Running", + link: `/amms/${item.id}`, + createdAt: new Date((item.order.blockTimestamp as number) * 1000), + })); return (
@@ -128,7 +122,6 @@ export function HomeWrapper({ goToSafe = false }: { goToSafe?: boolean }) { {rows?.length ? ( - // @ts-expect-error rows.map((row, index) => { return ( - request(NEXT_PUBLIC_API_URL, AMM_QUERY, { ammId }), + request(NEXT_PUBLIC_API_URL, AMM_QUERY, { ammId }) ); const token0SubgraphData = subgraphData?.constantProductData?.token0; @@ -55,16 +55,14 @@ export function useStandaloneAMM(ammId: Address) { error: balancesError, isLoading: isBalancesLoading, } = useSWR( - token0SubgraphData && token1SubgraphData && chainId - ? [ - "balances", - chainId as ChainId, - ammAddress, - token0SubgraphData as IToken, - token1SubgraphData as IToken, - ] - : null, - getBalancesFromContract, + [ + "balances", + chainId as ChainId, + ammAddress, + token0SubgraphData as IToken, + token1SubgraphData as IToken, + ], + getBalancesFromContract ); const { @@ -72,15 +70,13 @@ export function useStandaloneAMM(ammId: Address) { error: pricesError, isLoading: isPricesLoading, } = useSWR( - token0SubgraphData && token1SubgraphData && chainId - ? [ - "prices", - chainId as ChainId, - token0SubgraphData as IToken, - token1SubgraphData as IToken, - ] - : null, - getTokensExternalPrices, + [ + "prices", + chainId as ChainId, + token0SubgraphData as IToken, + token1SubgraphData as IToken, + ], + getTokensExternalPrices ); if (