Skip to content

Commit

Permalink
fix ts errors in homewrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
ribeirojose committed May 29, 2024
1 parent c3028db commit 09f8496
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 67 deletions.
3 changes: 0 additions & 3 deletions apps/cow-amm-deployer/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ const moduleExports = {
},
];
},
experimental: {
reactCompiler: true,
},
transpilePackages: ["@bleu/gql"],
reactStrictMode: true,
/**
Expand Down
4 changes: 2 additions & 2 deletions apps/cow-amm-deployer/src/app/amms/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export default function Page({ params }: { params: { id: `0x${string}` } }) {
2,
"decimal",
"compact",
0.01,
0.01
)}
</span>
</div>
Expand All @@ -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"
Expand Down
77 changes: 35 additions & 42 deletions apps/cow-amm-deployer/src/components/HomeWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,68 +10,62 @@ 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";

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 (
<div className="flex size-full justify-center">
Expand Down Expand Up @@ -128,7 +122,6 @@ export function HomeWrapper({ goToSafe = false }: { goToSafe?: boolean }) {
</TableHeader>
<TableBody>
{rows?.length ? (
// @ts-expect-error
rows.map((row, index) => {
return (
<TableRow
Expand Down
36 changes: 16 additions & 20 deletions apps/cow-amm-deployer/src/hooks/useStandaloneAmm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export function useStandaloneAMM(ammId: Address) {
error: subgraphError,
isLoading: isSubgraphLoading,
} = useSWR(ammId, (ammId) =>
request(NEXT_PUBLIC_API_URL, AMM_QUERY, { ammId }),
request(NEXT_PUBLIC_API_URL, AMM_QUERY, { ammId })
);

const token0SubgraphData = subgraphData?.constantProductData?.token0;
Expand All @@ -55,32 +55,28 @@ 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 {
data: pricesData,
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 (
Expand Down

0 comments on commit 09f8496

Please sign in to comment.