Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add example #17

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.build
build
web_modules
node_modules
10 changes: 10 additions & 0 deletions example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Connect React − Intro

A simple demo that displays the apps of an organization.

## How to run

```console
yarn
yarn start
```
3 changes: 3 additions & 0 deletions example/babel.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "@snowpack/app-scripts-react/babel.config.json"
}
22 changes: 22 additions & 0 deletions example/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "example",
"private": true,
"version": "1.0.0",
"scripts": {
"start": "snowpack dev",
"build": "snowpack build"
},
"dependencies": {
"@1hive/connect-react": "^0.8.6",
"@commonsswarm/connect-hatch": "file:.yalc/@commonsswarm/connect-hatch",
"react": "^16.13.0",
"react-dom": "^16.13.0"
},
"devDependencies": {
"@snowpack/app-scripts-react": "^1.6.0-alpha.0",
"@types/react": "^16.9.35",
"@types/react-dom": "^16.9.8",
"snowpack": "^2.6.4",
"typescript": "^3.8.0"
}
}
Binary file added example/public/favicon.ico
Binary file not shown.
50 changes: 50 additions & 0 deletions example/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Connect React − Intro</title>
<style>
body,
button {
font: 16px/1.5 monospace;
}
body {
margin: 0;
padding: 40px;
color: #333;
background: #e5ffff;
}
button {
display: block;
width: auto;
padding: 5px;
color: #fff;
background: #a5aaaa;
border: 0;
border-radius: 3px;
cursor: pointer;
font-size: 14px;
}
h1 {
display: flex;
align-items: center;
margin: 30px 0 10px;
font-weight: 400;
font-size: 22px;
}
h1 button {
margin-left: 10px;
}
section h1 {
font-size: 18px;
}
</style>
</head>
<body>
<div id="root"></div>
<noscript>You need to enable JavaScript to run this app.</noscript>
<script type="module" src="/_dist_/index.js"></script>
</body>
</html>
3 changes: 3 additions & 0 deletions example/public/robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# https://www.robotstxt.org/robotstxt.html
User-agent: *
Disallow:
3 changes: 3 additions & 0 deletions example/snowpack.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "@snowpack/app-scripts-react"
}
17 changes: 17 additions & 0 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from 'react'
import { Connect } from '@1hive/connect-react'
import Info from './Info'

function App() {
return (
<Connect
location="0x610f47Ece09Da2367f295950E5E4Aea581Bc7A23"
connector="thegraph"
options={{ network: 100 }}
>
<Info />
</Connect>
)
}

export default App
98 changes: 98 additions & 0 deletions example/src/Info.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import React from 'react'
import { useOrganization, useApps, useApp } from '@1hive/connect-react'
import connectHatch from '@commonsswarm/connect-hatch'
import LogButton from './LogButton'

export default function Info() {
const [org] = useOrganization()
const [apps] = useApps()
const [hatchConnector, setHatchConnector] = React.useState(null)
const [contributors, setContributors] = React.useState(null)
const [hatchApp] = useApp('marketplace-hatch')

React.useEffect(() => {
if (!hatchApp) {
return
}

let cancelled = false

const fetchHatchConnector = async () => {
try {
const hatchConnector = await connectHatch(hatchApp)

if (!cancelled) {
setHatchConnector(hatchConnector)
}
} catch (err) {
console.error(`Error fetching hatch connector: ${err}`)
}
}

fetchHatchConnector()

return () => {
cancelled = true
}
}, [hatchApp])

React.useEffect(() => {
let cancelled = false

const fetchContributors = async () => {
try {
const contributors = await hatchConnector.contributors({
first: 100,
skip: 50,
orderBy: 'totalValue',
orderDirection: 'asc',
})

if (!cancelled) {
setContributors(contributors)
}
} catch (err) {
console.error(`Error fetching hatch connector: ${err}`)
}
}

if (!hatchConnector) {
return
}

fetchContributors()

return () => {
cancelled = true
}
}, [hatchConnector])

if (!org) {
return <div>Loading…</div>
}

return (
<>
<h1>Organization</h1>
<div>location: {org.location}</div>
<div>address: {org.address}</div>

<h1>Apps</h1>
{apps?.map((app: any) => (
<section key={app.address}>
<h1>
{app.name} <LogButton value={app} />
</h1>
<div>address: {app.address}</div>
{app.version && <div>version: {app.version}</div>}
</section>
))}
<h1>Contributors</h1>
{contributors?.map((contributor: any) => (
<section key={contributor.address}>
<div>address: {contributor.address}</div>
</section>
))}
</>
)
}
7 changes: 7 additions & 0 deletions example/src/LogButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import React from 'react'

function LogButton({ value }: any) {
return <button onClick={() => console.log(value)}>log()</button>
}

export default LogButton
16 changes: 16 additions & 0 deletions example/src/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React from 'react'
import ReactDOM from 'react-dom'
import App from './App'

ReactDOM.render(
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById('root')
)

// Hot Module Replacement (HMR) - Remove this snippet to remove HMR.
// Learn more: https://www.snowpack.dev/#hot-module-replacement
if (import.meta.hot) {
import.meta.hot.accept()
}
14 changes: 14 additions & 0 deletions example/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"extends": "@snowpack/app-scripts-react/tsconfig.base.json",
"compilerOptions": {
"outDir": "./dist",
"rootDir": "src",
"jsx": "react",
"target": "ESNext",
"baseUrl": "./",
"paths": { "*": ["web_modules/.types/*"] }
},
"include": ["src", "types"],
"exclude": ["node_modules"],
"references": [{ "path": "../tsconfig.json" }]
}
8 changes: 8 additions & 0 deletions example/types/import.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// ESM-HMR Interface: `import.meta.hot`

interface ImportMeta {
// TODO: Import the exact .d.ts files from "esm-hmr"
// https://github.com/pikapkg/esm-hmr
hot: any;
env: Record<string, any>;
}
32 changes: 32 additions & 0 deletions example/types/static.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* Use this file to declare any custom file extensions for importing */
/* Use this folder to also add/extend a package d.ts file, if needed. */

declare module '*.css';
declare module '*.svg' {
const ref: string;
export default ref;
}
declare module '*.bmp' {
const ref: string;
export default ref;
}
declare module '*.gif' {
const ref: string;
export default ref;
}
declare module '*.jpg' {
const ref: string;
export default ref;
}
declare module '*.jpeg' {
const ref: string;
export default ref;
}
declare module '*.png' {
const ref: string;
export default ref;
}
declare module '*.webp' {
const ref: string;
export default ref;
}
10 changes: 10 additions & 0 deletions example/yalc.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"version": "v1",
"packages": {
"@commonsswarm/connect-hatch": {
"signature": "55c67d2cd43470c2d3b73bd749e9b206",
"file": true,
"replaced": "^0.0.1"
}
}
}