vega-frontend-monorepo/apps/trading/pages/markets/index.page.tsx

46 lines
968 B
TypeScript
Raw Normal View History

2022-02-28 23:43:36 +00:00
import { gql, useQuery } from '@apollo/client';
2022-02-17 05:03:46 +00:00
import Link from 'next/link';
import { useRouter } from 'next/router';
2022-02-28 23:43:36 +00:00
import { Markets } from './__generated__/Markets';
const MARKETS_QUERY = gql`
query Markets {
markets {
id
}
}
`;
2022-02-17 05:03:46 +00:00
const Markets = () => {
const { pathname } = useRouter();
2022-02-28 23:43:36 +00:00
const { data, loading, error } = useQuery<Markets>(MARKETS_QUERY);
if (loading || !data) {
return <div>Loading...</div>;
}
2022-02-17 05:03:46 +00:00
return (
<div>
<h1>Markets</h1>
2022-02-28 23:43:36 +00:00
{error ? (
<div>Could not load markets {error.message}</div>
) : (
<ul>
{data.markets.map((m) => (
<li key={m.id}>
2022-03-01 22:14:33 +00:00
<Link
href={`${pathname}/${m.id}?portfolio=orders&trade='orderbook`}
passHref={true}
>
2022-02-28 23:43:36 +00:00
<a>View market: {m.id}</a>
</Link>
</li>
))}
</ul>
)}
2022-02-17 05:03:46 +00:00
</div>
);
};
export default Markets;