Skip to content
This repository has been archived by the owner on Jun 29, 2021. It is now read-only.

Commit

Permalink
feat(init): Initialize project with default template
Browse files Browse the repository at this point in the history
  • Loading branch information
edsonayllon committed Nov 21, 2020
1 parent dbf4d01 commit d4b59d7
Show file tree
Hide file tree
Showing 21 changed files with 11,985 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# dhedge-gnosis-safe-app
Interface for Gnosis Safe integration

[Getting Started](app/README.md).
3 changes: 3 additions & 0 deletions app/.env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
PORT=3000
HTTPS=true
REACT_APP_INFURA_ID=
24 changes: 24 additions & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
51 changes: 51 additions & 0 deletions app/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# My Safe App

## Getting Started

Install dependencies and start a local dev server.

```
yarn install
cp .env.sample .env
yarn start
```

Then:

- If HTTPS is used (by default enabled)
- Open your Safe app locally (by default via https://localhost:3000/) and accept the SSL error.
- Go to Safe Multisig web interface
- [Mainnet](https://app.gnosis-safe.io)
- [Rinkeby](https://rinkeby.gnosis-safe.io/app)
- Create your test safe
- Go to Apps -> Manage Apps -> Add Custom App
- Paste your localhost URL, default is https://localhost:3000/
- You should see Safe App Starter as a new app
- Develop your app from there

## Features

Gnosis Safe App Starter combines recommendations described in the following repositories:

- [Safe Apps SDK](https://github.com/gnosis/safe-apps-sdk)
- [safe-react-components](https://github.com/gnosis/safe-react-components)

You can use the `useSafe` React hook to interact with the Safe Apps SDK

```
const safe = useSafe();
console.log(safe.info);
```

Safe React Components are also integrated and ready to use. [See all components](https://components.gnosis-safe.io/).

## Dependencies

### Included
- [`@gnosis.pm/safe-react-components`](https://github.com/gnosis/safe-react-components) (UI components themed for the Safe Multisig interface)
- [`@rmeissner/safe-apps-react-sdk`](https://github.com/rmeissner/safe-sdks-js/tree/master/safe-apps-react-sdk) (React hook for the Safe Apps SDK)

### Recommended
- [`ethers`](https://github.com/ethers-io/ethers.js) (Library for interacting with Ethereum)
- [`web3`](https://github.com/ethereum/web3.js/) (Library for interacting with Ethereum)
- [`@studydefi/money-legos`](https://github.com/studydefi/money-legos) (Library for DeFi interactions)
25 changes: 25 additions & 0 deletions app/config-overrides.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module.exports = {
webpack: function (config, env) {
return config;
},
jest: function (config) {
return config;
},
devServer: function (configFunction) {
return function (proxy, allowedHost) {
const config = configFunction(proxy, allowedHost);

config.headers = {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET",
"Access-Control-Allow-Headers":
"X-Requested-With, content-type, Authorization",
};

return config;
};
},
paths: function (paths, env) {
return paths;
},
};
53 changes: 53 additions & 0 deletions app/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"name": "app",
"version": "0.1.0",
"private": true,
"dependencies": {
"@gnosis.pm/safe-apps-sdk": "^0.3.1",
"@gnosis.pm/safe-react-components": "^0.2.0",
"@material-ui/core": "^4.11.0",
"@rmeissner/safe-apps-react-sdk": "0.4.0",
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^10.4.9",
"@testing-library/user-event": "^12.1.3",
"@types/jest": "^26.0.10",
"@types/node": "^14.6.2",
"@types/react": "^16.9.0",
"@types/react-dom": "^16.9.0",
"@types/styled-components": "^5.1.2",
"react": "^16.13.1",
"react-app-rewired": "^2.1.6",
"react-dom": "^16.13.1",
"react-scripts": "3.4.3",
"styled-components": "^5.1.1",
"typescript": "~4.0.2"
},
"scripts": {
"start": "react-app-rewired start",
"build": "react-app-rewired build",
"test": "react-app-rewired test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"plugin:jsx-a11y/recommended"
],
"plugins": [
"jsx-a11y"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"homepage": "./"
}
Binary file added app/public/favicon.ico
Binary file not shown.
43 changes: 43 additions & 0 deletions app/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>Gnosis Safe App</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>
7 changes: 7 additions & 0 deletions app/public/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/public/logo192.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/public/logo512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 27 additions & 0 deletions app/public/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"short_name": "Safe App",
"name": "Gnosis Safe App Starter",
"description": "Describe your Safe App here",
"iconPath": "logo.svg",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
},
{
"src": "logo192.png",
"type": "image/png",
"sizes": "192x192"
},
{
"src": "logo512.png",
"type": "image/png",
"sizes": "512x512"
}
],
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}
3 changes: 3 additions & 0 deletions app/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:
51 changes: 51 additions & 0 deletions app/src/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import React, { useCallback, useState } from 'react';
import styled from "styled-components";
import { Button, Loader, Title } from "@gnosis.pm/safe-react-components";
import { useSafe } from '@rmeissner/safe-apps-react-sdk';

const Container = styled.form`
margin-bottom: 2rem;
width: 100%;
max-width: 480px;
display: grid;
grid-template-columns: 1fr;
grid-column-gap: 1rem;
grid-row-gap: 1rem;
`;

const App: React.FC = () => {
const safe = useSafe()
const [submitting, setSubmitting] = useState(false)
const submitTx = useCallback(async () => {
setSubmitting(true)
try {
const safeTxHash = await safe.sendTransactions([
{
"to": safe.info.safeAddress,
"value": "0",
"data": "0x"
}
])
console.log({safeTxHash})
const safeTx = await safe.loadSafeTransaction(safeTxHash)
console.log({safeTx})
} catch (e) {
console.error(e)
}
setSubmitting(false)
}, [safe])
return <Container>
<Title size="md">{safe.info.safeAddress}</Title>
{submitting ?
<>
<Loader size="md" /><br/>
<Button size="lg" color="secondary" onClick={() => {setSubmitting(false)}}>Cancel</Button>
</>
:
<Button size="lg" color="primary" onClick={submitTx}>Submit</Button>
}
</Container>
};

export default App;
34 changes: 34 additions & 0 deletions app/src/GlobalStyle.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { createGlobalStyle } from "styled-components";
import avertaFont from "@gnosis.pm/safe-react-components/dist/fonts/averta-normal.woff2";
import avertaBoldFont from "@gnosis.pm/safe-react-components/dist/fonts/averta-bold.woff2";

const GlobalStyle = createGlobalStyle`
html {
height: 100%
}
body {
height: 100%;
margin: 0px;
padding: 0px;
}
#root {
height: 100%;
padding-right: 0.5rem;
}
.MuiFormControl-root,
.MuiInputBase-root {
width: 100% !important;
}
@font-face {
font-family: 'Averta';
src: local('Averta'), local('Averta Bold'),
url(${avertaFont}) format('woff2'),
url(${avertaBoldFont}) format('woff');
}
`;

export default GlobalStyle;
2 changes: 2 additions & 0 deletions app/src/fonts.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare module "*.woff";
declare module "*.woff2";
27 changes: 27 additions & 0 deletions app/src/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React from "react";
import ReactDOM from "react-dom";
import { ThemeProvider } from "styled-components";
import { theme } from "@gnosis.pm/safe-react-components";
import { Loader, Title } from "@gnosis.pm/safe-react-components";
import SafeProvider from '@rmeissner/safe-apps-react-sdk';


import GlobalStyle from "./GlobalStyle";
import App from "./App";

ReactDOM.render(
<React.StrictMode>
<ThemeProvider theme={theme}>
<GlobalStyle />
<SafeProvider loading={(
<>
<Title size="md">Waiting for Safe...</Title>
<Loader size="md" />
</>
)}>
<App />
</SafeProvider>
</ThemeProvider>
</React.StrictMode>,
document.getElementById("root")
);
1 change: 1 addition & 0 deletions app/src/react-app-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="react-scripts" />
5 changes: 5 additions & 0 deletions app/src/setupTests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// jest-dom adds custom jest matchers for asserting on DOM nodes.
// allows you to do things like:
// expect(element).toHaveTextContent(/react/i)
// learn more: https://github.com/testing-library/jest-dom
import '@testing-library/jest-dom/extend-expect';
21 changes: 21 additions & 0 deletions app/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"noFallthroughCasesInSwitch": false,
"jsx": "react"
},
"include": ["src"],
"exclude": ["node_modules"]
}
Loading

0 comments on commit d4b59d7

Please sign in to comment.