Skip to content

Commit

Permalink
feat: oeth app uses shared components library, APY components, Histor…
Browse files Browse the repository at this point in the history
…y tab
  • Loading branch information
dcodes05 committed Aug 23, 2023
1 parent a0e14d9 commit 0828aef
Show file tree
Hide file tree
Showing 24 changed files with 860 additions and 42 deletions.
11 changes: 9 additions & 2 deletions apps/oeth/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
Expand All @@ -7,7 +7,14 @@

<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
<link rel="stylesheet" href="/src/styles.css" />
<!-- Inter font -->
<link rel="preconnect" href="https://rsms.me/" />
<link rel="stylesheet" href="https://rsms.me/inter/inter.css" />
<!-- -->
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/typeface-sailec@1.0.0/index.min.css"
/>
</head>
<body>
<div id="root"></div>
Expand Down
17 changes: 17 additions & 0 deletions apps/oeth/src/components/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { HistoryView, SwapView, WrapView } from '@origin/defi/oeth';
import { Route, Routes } from 'react-router-dom';

import { Layout } from './Layout';

export function App() {
return (
<Routes>
<Route path="/" element={<Layout />}>
<Route index element={<SwapView />} />
<Route path="wrap" element={<WrapView />} />
<Route path="history" element={<HistoryView />} />
<Route path="swap" element={<SwapView />} />
</Route>
</Routes>
);
}
39 changes: 39 additions & 0 deletions apps/oeth/src/components/Layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { Container } from '@mui/material';
import { TopNav } from '@origin/shared/components';
import { useIntl } from 'react-intl';
import { Outlet } from 'react-router-dom';

export function Layout() {
const intl = useIntl();

return (
<>
<TopNav
logo="https://app.oeth.com/images/origin-ether-logo.svg"
tabs={[
intl.formatMessage({ defaultMessage: 'Swap' }),
intl.formatMessage({ defaultMessage: 'Wrap' }),
intl.formatMessage({ defaultMessage: 'History' }),
]}
selected={0}
connected={false}
ipfsLink={'https://oeth.on.fleek.co/'}
/>
<Container
sx={{
mt: {
xs: 3,
md: 5,
paddingInline: {
xs: 2,
md: 0,
},
},
}}
maxWidth="sm"
>
<Outlet />
</Container>
</>
);
}
1 change: 1 addition & 0 deletions apps/oeth/src/components/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './App';
4 changes: 0 additions & 4 deletions apps/oeth/src/index.tsx

This file was deleted.

4 changes: 2 additions & 2 deletions apps/oeth/src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { StrictMode } from 'react';
import * as ReactDOM from 'react-dom/client';
import { BrowserRouter } from 'react-router-dom';
import { OethRoot } from './views/root';
import { QueryClientProvider } from '@tanstack/react-query';
import { queryClient } from '@origin/shared/data-access';
import { theme } from '@origin/shared/theme';
Expand All @@ -11,6 +10,7 @@ import {
} from '@mui/material';
import { IntlProvider } from 'react-intl';
import { en } from './lang';
import { App } from './components';

const root = ReactDOM.createRoot(
document.getElementById('root') as HTMLElement
Expand All @@ -22,7 +22,7 @@ root.render(
<QueryClientProvider client={queryClient}>
<CssVarsProvider theme={theme} defaultMode="dark">
<CssBaseline />
<OethRoot />
<App />
</CssVarsProvider>
</QueryClientProvider>
</BrowserRouter>
Expand Down
13 changes: 0 additions & 13 deletions apps/oeth/src/views/root/index.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion apps/oeth/tsconfig.app.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@
"src/**/*.spec.jsx",
"src/**/*.test.jsx"
],
"include": ["src/**/*.js", "src/**/*.jsx", "src/**/*.ts", "src/**/*.tsx"]
"include": ["src/**/*.js", "src/**/*.jsx", "src/**/*.ts", "src/**/*.tsx", "../../libs/defi/oeth/src/components/TopNav.tsx"]
}
15 changes: 14 additions & 1 deletion apps/oeth/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
/// <reference types="vitest" />
import { defineConfig } from 'vite';
/// <reference types="vite-plugin-svgr/client" />
import react from '@vitejs/plugin-react';
import path from 'path';
import { defineConfig } from 'vite';
import { viteStaticCopy } from 'vite-plugin-static-copy';
import svgr from 'vite-plugin-svgr';
import viteTsConfigPaths from 'vite-tsconfig-paths';

export default defineConfig({
Expand All @@ -17,6 +21,7 @@ export default defineConfig({
},

plugins: [
svgr(),
react({
babel: {
plugins: [
Expand All @@ -33,6 +38,14 @@ export default defineConfig({
viteTsConfigPaths({
root: '../../',
}),
viteStaticCopy({
targets: [
{
src: path.resolve(__dirname, '../../libs/shared/assets/files/*'),
dest: './images',
},
],
}),
],

// Uncomment this if you are using workers.
Expand Down
3 changes: 1 addition & 2 deletions apps/ousd/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
Expand All @@ -7,7 +7,6 @@

<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
<link rel="stylesheet" href="/src/styles.css" />
</head>
<body>
<div id="root"></div>
Expand Down
30 changes: 30 additions & 0 deletions libs/defi/oeth/src/components/History/HistoryButton.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { HistoryFilterButton } from './HistoryButton';

import type { Meta, StoryObj } from '@storybook/react';

const meta: Meta<typeof HistoryFilterButton> = {
component: HistoryFilterButton,
title: 'History/History filter button',
args: {
circle: false,
children: 'Test',
},
render: (args) => <HistoryFilterButton {...args} />,
};

export default meta;

export const Primary: StoryObj<typeof HistoryFilterButton> = {};

export const WithCircle: StoryObj<typeof HistoryFilterButton> = {
args: {
circle: true,
},
};

export const Selected: StoryObj<typeof HistoryFilterButton> = {
args: {
circle: true,
selected: true,
},
};
69 changes: 69 additions & 0 deletions libs/defi/oeth/src/components/History/HistoryButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { alpha, Box, Button } from '@mui/material';

import type { ButtonProps, SxProps } from '@mui/material';
import type { Theme } from '@origin/shared/theme';

interface Props extends ButtonProps {
circle?: boolean;
selected?: boolean;
}

export function HistoryFilterButton({
children,
circle = false,
onClick,
selected = false,
sx,
...rest
}: Props) {
return (
<Button
variant="contained"
onClick={onClick}
sx={{
background: (theme) => alpha(theme.palette.common.white, 0.1),
color: selected ? 'primary.contrastText' : 'text.primary',
display: 'flex',
alignItems: 'center',
backgroundImage: 'none',
gap: 1.5,
borderRadius: 14,
paddingInline: 2,
paddingBlock: 0.5,
fontSize: (theme) => theme.typography.pxToRem(12),
'&:hover': {
background: (theme) => alpha(theme.palette.common.white, 0.1),
},
...sx,
}}
{...rest}
>
{children}
{circle ? (
<Circle
// @ts-expect-error theme types
sx={{
background: (theme: Theme) =>
selected
? theme.palette.background.gradient3
: theme.palette.background.paper,
}}
/>
) : undefined}
</Button>
);
}

function Circle({ sx }: { sx: SxProps }) {
return (
<Box
sx={{
backgroundColor: (theme) => theme.palette.background.default,
height: '0.5rem',
width: '0.5rem',
borderRadius: '100%',
...sx,
}}
/>
);
}
83 changes: 83 additions & 0 deletions libs/defi/oeth/src/components/History/HistoryCard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import { useState } from 'react';

import { Box, Button, Stack, Typography } from '@mui/material';
import { Card } from '@origin/shared/components';
import { useIntl } from 'react-intl';

import { HistoryFilterButton } from './HistoryButton';
import { HistoryTable } from './HistoryTable';

import type { ColumnFilter } from '@tanstack/react-table';

export function HistoryCard() {
const [isConnected, setConnectionState] = useState(false);
const intl = useIntl();
const [filter, setFilter] = useState<ColumnFilter>({
id: 'type',
value: [],
});

function filterRows(value: string) {
setFilter((prev) => {
if ((prev.value as string[]).includes(value)) {
return {
...prev,
value: [...(prev.value as string[]).filter((val) => val !== value)],
};
} else {
return {
...prev,
value: [...(prev.value as string[]), value],
};
}
});
}
return (
<Card
sx={{ mt: 3 }}
title={
<Stack
direction="row"
sx={{ alignItems: 'center', justifyContent: 'space-between' }}
>
<Typography color="primary.contrastText">History</Typography>
<Stack direction="row" gap={2} sx={{ marginInline: 'auto' }}>
{[
intl.formatMessage({ defaultMessage: 'Received' }),
intl.formatMessage({ defaultMessage: 'Sent' }),
intl.formatMessage({ defaultMessage: 'Swap' }),
intl.formatMessage({ defaultMessage: 'Yield' }),
].map((label) => (
<HistoryFilterButton
key={label}
circle
selected={(filter.value as string[]).includes(
label.toLowerCase(),
)}
onClick={() => filterRows(label.toLowerCase())}
>
{label}
</HistoryFilterButton>
))}
</Stack>
<HistoryFilterButton>
{intl.formatMessage({ defaultMessage: 'Export CSV' })}
</HistoryFilterButton>
</Stack>
}
>
{isConnected ? (
<HistoryTable rows={[]} isLoading={false} filter={filter} />
) : (
<Box sx={{ height: '15rem', display: 'grid', placeContent: 'center' }}>
<Typography>
{intl.formatMessage({
defaultMessage: 'Connect your wallet to see your history',
})}
</Typography>
<Button onClick={() => setConnectionState(true)}>Connect</Button>
</Box>
)}
</Card>
);
}
Loading

0 comments on commit 0828aef

Please sign in to comment.