Skip to content

Commit

Permalink
gets init
Browse files Browse the repository at this point in the history
  • Loading branch information
skuhlmann committed Feb 22, 2023
1 parent 5634e95 commit ecf097b
Show file tree
Hide file tree
Showing 11 changed files with 792 additions and 134 deletions.
4 changes: 4 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
VITE_RIVET_KEY=
VITE_EXPLORER_KEY=
VITE_GRAPH_API_KEY_MAINNET=
VITE_TARGET_KEY=
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ dist-ssr
*.sw?

.env
dev/
64 changes: 64 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# DAOhaus: V3 Vite Starter

## Development

### 1. project setup

```bash
git clone [email protected]:HausDAO/moloch-v3-vite-starter.git

cd moloch-v3-vite-starter

yarn
```

### 2. env setup

```bash
cp .env.sample .env
```

```md
VITE_RIVET_KEY

get a free rivet key [here](https://rivet.cloud/)

VITE_EXPLORER_KEY

get etherscan explorer api key [here](https://etherscan.io/apis)

VITE_GRAPH_API_KEY_MAINNET

if deeveloping for mainnet or gnosis chain you can get an api key [here](https://thegraph.com/explorer/subgraph?id=GfHFdFmiSwW1PKtnDhhcxhArwtTjVuMnXxQ5XcETF1bP&view=Overview). Ignore this one if not worried about mainnet or gnosis chain yet.

VITE_TARGET_KEY

This will be the target address for your DAO you are developing the app for.
```

### 3. target dao set up

[Summon a DAO here](https://summon.daohaus.club)

Edit src/targetDao.ts

- add your DAO's data
- Put the dao address in the .env variable mentioned above VITE_TARGET_KEY
- You can add multiple DAOs as new object in targetDao.ts and toggle with this env variable
- You can add otehr variables to targetDao.ts as needed

### 4. run the development server

```bash
yarn dev
```

## Reference

### editing the theme

tbd

### router example for multi-dao app

tbd
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>DAOhaus React Vite Starter</title>
<title>DAOhaus v3 React Vite Starter</title>
</head>
<body>
<div id="root"></div>
<script>
<script>
window.global = window;
</script>
<script type="module" src="/src/main.tsx"></script>
Expand Down
15 changes: 10 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
{
"name": "daohaus-vite-starter",
"private": true,
"version": "0.0.0",
"version": "0.1.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"preview": "vite preview"
},
"dependencies": {
"@daohaus/connect": "^0.1.3",
"@daohaus/form-builder": "^0.1.3",
"@daohaus/tx-builder": "^0.1.3",
"@daohaus/ui": "^0.1.3",
"@daohaus/connect": "^0.1.20",
"@daohaus/contract-utils": "^0.1.20",
"@daohaus/form-builder": "^0.1.20",
"@daohaus/moloch-v3-hooks": "^0.0.5",
"@daohaus/moloch-v3-macro-ui": "^0.0.3",
"@daohaus/tx-builder": "^0.1.20",
"@daohaus/ui": "^0.1.20",
"@daohaus/utils": "^0.1.20",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-query": "^3.39.3",
"react-router-dom": "^6.4.5"
},
"devDependencies": {
Expand Down
28 changes: 12 additions & 16 deletions src/Routes.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
import { DHLayout } from '@daohaus/connect';
import { Routes as Router, Route, useLocation } from 'react-router-dom';
import { FormTest } from './pages/FormTest';
import { Home } from './pages/Home';
import { Routes as Router, Route, useLocation } from "react-router-dom";
import { FormTest } from "./pages/FormTest";
import { Home } from "./pages/Home";
import HomeContainer from "./components/HomeContainer";

export const Routes = () => {
const { pathname } = useLocation();
return (
<DHLayout
pathname={pathname}
navLinks={[
{ label: 'Home', href: '/' },
{ label: 'Form Test', href: '/formtest' },
]}
>
<Router>
<Route path="/" element={<Home />} />
<Route path="/formtest" element={<FormTest />} />
</Router>
</DHLayout>
<Router>
<Route path="/" element={<HomeContainer />}>
<Route index element={<Home />} />
{/* <Route path="proposals/" element={<Proposals />} /> */}
{/* <Route path="members/" element={<Members />} /> */}
<Route path="form-test/" element={<FormTest />} />
</Route>
</Router>
);
};
52 changes: 52 additions & 0 deletions src/components/HomeContainer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { DHLayout, useDHConnect } from "@daohaus/connect";
import { HAUS_RPC } from "@daohaus/keychain-utils";
import { TXBuilder } from "@daohaus/tx-builder";
import { H4 } from "@daohaus/ui";
import { Outlet, useLocation } from "react-router-dom";
import { TARGET_DAO } from "../targetDao";
import { useDaoData } from "@daohaus/moloch-v3-hooks";

export function HomeContainer() {
const location = useLocation();
const { provider, address } = useDHConnect();
const { dao } = useDaoData({
daoId: TARGET_DAO[import.meta.env.VITE_TARGET_KEY].ADDRESS,
daoChain: TARGET_DAO[import.meta.env.VITE_TARGET_KEY].CHAIN_ID,
});

return (
<DHLayout
pathname={location.pathname}
navLinks={[{ label: "Home", href: `/` }]}
leftNav={<H4>{dao?.name}</H4>}
>
<TXBuilder
provider={provider}
chainId={TARGET_DAO[import.meta.env.VITE_TARGET_KEY].CHAIN_ID}
daoId={TARGET_DAO[import.meta.env.VITE_TARGET_KEY].ADDRESS}
safeId={TARGET_DAO[import.meta.env.VITE_TARGET_KEY].SAFE_ADDRESS}
appState={{ dao, memberAddress: address }}
rpcs={{
"0x1": `https://${
import.meta.env.VITE_RIVET_KEY
}.eth.rpc.rivet.cloud/`,
"0x5": `https://${
import.meta.env.VITE_RIVET_KEY
}.goerli.rpc.rivet.cloud/`,
"0x64": HAUS_RPC["0x64"],
}}
explorerKeys={{
"0x1": import.meta.env.VITE_EXPLORER_KEY,
"0x5": import.meta.env.VITE_EXPLORER_KEY,
}}
graphApiKeys={{
"0x1": import.meta.env.VITE_GRAPH_API_KEY_MAINNET,
}}
>
<Outlet />
</TXBuilder>
</DHLayout>
);
}

export default HomeContainer;
31 changes: 20 additions & 11 deletions src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
import { DHConnectProvider } from '@daohaus/connect';
import { HausThemeProvider } from '@daohaus/ui';
import React from 'react';
import ReactDOM from 'react-dom/client';
import { HashRouter } from 'react-router-dom';
import { Routes } from './Routes';
import React from "react";
import ReactDOM from "react-dom/client";
import { HashRouter } from "react-router-dom";
import { QueryClient, QueryClientProvider } from "react-query";
import { DHConnectProvider } from "@daohaus/connect";
import { HausThemeProvider } from "@daohaus/ui";

ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render(
import { Routes } from "./Routes";
import { TARGET_DAO } from "./targetDao";

const queryClient = new QueryClient();

ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render(
<React.StrictMode>
<HashRouter>
<HausThemeProvider>
<DHConnectProvider>
<Routes />
<QueryClientProvider client={queryClient}>
<DHConnectProvider
daoChainId={TARGET_DAO[import.meta.env.VITE_TARGET_KEY].CHAIN_ID}
>
<HausThemeProvider>
<Routes />
</HausThemeProvider>
</DHConnectProvider>
</HausThemeProvider>
</QueryClientProvider>
</HashRouter>
</React.StrictMode>
);
15 changes: 15 additions & 0 deletions src/targetDao.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { ValidNetwork } from "@daohaus/keychain-utils";

export const TARGET_DAO: {
[key: string]: {
ADDRESS: string;
SAFE_ADDRESS: string;
CHAIN_ID: ValidNetwork;
};
} = {
"0x3dea7058a19bf6854bb63384707139636efb99ea": {
ADDRESS: "0x3dea7058a19bf6854bb63384707139636efb99ea",
SAFE_ADDRESS: "0x47f327bdde3c92d82872d686bb6d7a994c22b4a5",
CHAIN_ID: "0x5",
},
};
27 changes: 18 additions & 9 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';

import { defineConfig, loadEnv } from "vite";
import react from "@vitejs/plugin-react";
// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
define: {
'process.env': {},
},
});
export default ({ mode }) => {
Object.assign(process.env, loadEnv(mode, process.cwd()));

return defineConfig({
plugins: [react()],
define: {
"process.env": {
NX_RIVET_KEY: process.env.VITE_RIVET_KEY,
NX_GRAPH_API_KEY_MAINNET: process.env.VITE_GRAPH_API_KEY_MAINNET,
NX_INFURA_PROJECT_ID: process.env.VITE_INFURA_PROJECT_ID,
NX_ETHERSCAN_KEY: process.env.VITE_ETHERSCAN_KEY,
NODE_ENV: "16.6.0",
},
},
});
};
Loading

0 comments on commit ecf097b

Please sign in to comment.