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

Avoid setting state for unmounted component #145

Closed
wants to merge 11 commits into from
Closed
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
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = {
parser: '@typescript-eslint/parser',
extends: ['plugin:@typescript-eslint/recommended', 'prettier/@typescript-eslint', 'plugin:prettier/recommended'],
extends: ['plugin:@typescript-eslint/recommended', 'plugin:prettier/recommended', 'react-app'],
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module',
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12.x]
node-version: [14.x]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ dist
.idea
.vscode
lerna-debug.log
yalc.lock
yalc.lock
build
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,5 @@ lerna run --scope @gnosis.pm/safe-apps-sdk build --stream

## Useful links

- [Start a new project using the Safe App React template](https://github.com/gnosis/safe-app-template)
- [Start a new project using the Safe App React template](/packages/cra-template-safe-app)
- [Video introduction to Building with Safe Apps SDK & Contract Proxy Kit](https://www.youtube.com/watch?v=YGw8WfBw5OI)
22 changes: 10 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
"node": ">=12.x"
},
"scripts": {
"start:dev-ui": "lerna run --scope @gnosis.pm/safe-apps-developer-ui start --stream",
"build:dev-ui": "lerna run --scope @gnosis.pm/safe-apps-developer-ui build --stream",
"build:sdk": "lerna run --scope @gnosis.pm/safe-apps-sdk build --stream",
"test:sdk": "lerna run --scope @gnosis.pm/safe-apps-sdk test --stream"
},
Expand All @@ -14,20 +16,16 @@
]
},
"dependencies": {
"lerna": "^3.22.1"
"lerna": "^4.0.0"
},
"devDependencies": {
"@types/react": "^17.0.1",
"@types/react-dom": "^17.0.0",
"@typescript-eslint/eslint-plugin": "^4.15.0",
"@typescript-eslint/parser": "^4.15.0",
"eslint": "7.19.0",
"eslint-config-prettier": "^7.2.0",
"@typescript-eslint/eslint-plugin": "^4.17.0",
"@typescript-eslint/parser": "^4.17.0",
"eslint": "7.23.0",
"eslint-config-prettier": "^8.1.0",
"eslint-plugin-prettier": "^3.3.1",
"eslint-plugin-react": "^7.22.0",
"eslint-plugin-react-hooks": "^4.2.0",
"jest": "^26.6.3",
"ts-jest": "^26.5.1",
"typescript": "^4.1.5"
"jest": "26.6.0",
"ts-jest": "^26.5.3",
"typescript": "^4.2.3"
}
}
2 changes: 1 addition & 1 deletion packages/cra-template-safe-app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gnosis.pm/cra-template-safe-app",
"version": "3.2.0",
"version": "3.3.0",
"description": "Gnosis Safe App Starter",
"author": "Gnosis (https://gnosis.pm)",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/cra-template-safe-app/template.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"package": {
"homepage": "./",
"dependencies": {
"@gnosis.pm/safe-apps-react-sdk": "2.2.0",
"@gnosis.pm/safe-apps-react-sdk": "2.3.0",
"@gnosis.pm/safe-react-components": "^0.3.0",
"@material-ui/core": "^4.11.0",
"@testing-library/jest-dom": "^5.11.4",
Expand Down
46 changes: 46 additions & 0 deletions packages/safe-apps-developer-ui/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Getting Started with Create React App

This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).

## Available Scripts

In the project directory, you can run:

### `yarn start`

Runs the app in the development mode.\
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.

The page will reload if you make edits.\
You will also see any lint errors in the console.

### `yarn test`

Launches the test runner in the interactive watch mode.\
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.

### `yarn build`

Builds the app for production to the `build` folder.\
It correctly bundles React in production mode and optimizes the build for the best performance.

The build is minified and the filenames include the hashes.\
Your app is ready to be deployed!

See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.

### `yarn eject`

**Note: this is a one-way operation. Once you `eject`, you can’t go back!**

If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.

Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.

You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.

## Learn More

You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).

To learn React, check out the [React documentation](https://reactjs.org/).
60 changes: 60 additions & 0 deletions packages/safe-apps-developer-ui/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"name": "@gnosis.pm/safe-apps-developer-ui",
"version": "0.1.0",
"private": true,
"dependencies": {
"@gnosis.pm/safe-apps-sdk": "^2.3.0",
"@gnosis.pm/safe-contracts": "1.1.1-dev.2",
"@material-ui/core": "^4.11.3",
"@material-ui/icons": "^4.11.2",
"@testing-library/jest-dom": "^5.11.10",
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^13.0.16",
"@types/styled-components": "^5.1.9",
"@walletconnect/web3-provider": "^1.4.0",
"clsx": "^1.1.1",
"ethereum-blockies-base64": "^1.0.2",
"ethers": "^5.0.32",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-router": "^5.2.0",
"react-router-dom": "^5.2.0",
"react-scripts": "4.0.3",
"styled-components": "^5.2.1",
"web3modal": "1.9.3",
"zustand": "^3.3.3"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --passWithNoTests",
"eject": "react-scripts eject"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"@types/jest": "^26.0.22",
"@types/node": "^14.14.37",
"@types/react": "^17.0.3",
"@types/react-dom": "^17.0.3",
"@types/react-router": "^5.1.13",
"@types/react-router-dom": "^5.1.7",
"eslint-config-react-app": "^6.0.0",
"eslint-plugin-flowtype": "^5.4.0",
"eslint-plugin-import": "^2.22.0",
"eslint-plugin-jsx-a11y": "^6.3.1",
"eslint-plugin-react": "^7.23.1",
"eslint-plugin-react-hooks": "^4.2.0",
"web-vitals": "^1.1.1"
}
}
Binary file not shown.
40 changes: 40 additions & 0 deletions packages/safe-apps-developer-ui/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<!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 Developer</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>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions packages/safe-apps-developer-ui/public/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"short_name": "React App",
"name": "Create React App Sample",
"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 packages/safe-apps-developer-ui/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:
23 changes: 23 additions & 0 deletions packages/safe-apps-developer-ui/src/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { BrowserRouter as Router, Redirect, Route, Switch } from 'react-router-dom';
import Header from 'src/components/Header';
import { WelcomePage } from './pages/Welcome';
import { SafePage } from './pages/safes';

function App(): React.ReactElement {
return (
<Router>
<Header />
<Switch>
<Route exact path="/">
<WelcomePage />
</Route>
<Route path="/safes/:safeAddress">
<SafePage />
</Route>
<Redirect to="/" />
</Switch>
</Router>
);
}

export default App;
53 changes: 53 additions & 0 deletions packages/safe-apps-developer-ui/src/api/provider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import Web3Modal, { IProviderOptions } from 'web3modal';
import WalletConnectProvider from '@walletconnect/web3-provider';

const WALLET_PROVIDER = {
SAFE: 'SAFE',
METAMASK: 'METAMASK',
REMOTE: 'REMOTE',
TORUS: 'TORUS',
PORTIS: 'PORTIS',
FORTMATIC: 'FORTMATIC',
SQUARELINK: 'SQUARELINK',
WALLETCONNECT: 'WALLETCONNECT',
OPERA: 'OPERA',
WALLETLINK: 'WALLETLINK',
AUTHEREUM: 'AUTHEREUM',
LEDGER: 'LEDGER',
TREZOR: 'TREZOR',
LATTICE: 'LATTICE',
UNKNOWN: 'UNKNOWN',
};

enum ETHEREUM_NETWORK_TO_ID {
MAINNET = 1,
MORDEN = 2,
ROPSTEN = 3,
RINKEBY = 4,
GOERLI = 5,
KOVAN = 42,
XDAI = 100,
ENERGY_WEB_CHAIN = 246,
VOLTA = 73799,
UNKNOWN = 0,
LOCAL = 4447,
}

const providerOptions: IProviderOptions = {
walletconnect: {
package: WalletConnectProvider,
options: {
infuraId: '82b8340f4bd146a2bfc606609ffbec41',
},
},
};

const web3Modal = new Web3Modal({ network: 'rinkeby', providerOptions, cacheProvider: true });

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const connectToProvider = async (): Promise<any> => {
const provider = await web3Modal.connect();
return provider;
};

export { WALLET_PROVIDER, ETHEREUM_NETWORK_TO_ID, connectToProvider };
34 changes: 34 additions & 0 deletions packages/safe-apps-developer-ui/src/api/safeContracts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import GnosisSafeSol from '@gnosis.pm/safe-contracts/build/contracts/GnosisSafe.json';
import ProxyFactorySol from '@gnosis.pm/safe-contracts/build/contracts/GnosisSafeProxyFactory.json';
import FallbackHandlerSol from '@gnosis.pm/safe-contracts/build/contracts/FallbackManager.json';
import { JsonRpcSigner } from '@ethersproject/providers';
import { Contract, ContractFactory } from 'ethers';

const getProxyFactoryContract = (address: string, signer: JsonRpcSigner): Contract =>
new Contract(address, ProxyFactorySol.abi, signer);

const getSafeContract = (address: string, signer: JsonRpcSigner): Contract =>
new Contract(address, GnosisSafeSol.abi, signer);

const deployMasterCopy = async (signer: JsonRpcSigner): Promise<Contract> => {
const factory = new ContractFactory(GnosisSafeSol.abi, GnosisSafeSol.bytecode, signer);
const masterCopy = await factory.deploy();

return masterCopy;
};

const deployProxyFactory = async (signer: JsonRpcSigner): Promise<Contract> => {
const factory = new ContractFactory(ProxyFactorySol.abi, ProxyFactorySol.bytecode, signer);
const proxyFactory = await factory.deploy();

return proxyFactory;
};

const deployFallbackHandler = async (signer: JsonRpcSigner): Promise<Contract> => {
const factory = new ContractFactory(FallbackHandlerSol.abi, FallbackHandlerSol.bytecode, signer);
const fallbackHandler = await factory.deploy();

return fallbackHandler;
};

export { deployProxyFactory, deployFallbackHandler, deployMasterCopy, getSafeContract, getProxyFactoryContract };
Binary file not shown.
Binary file not shown.
Loading