Skip to content

Commit

Permalink
Developer UI: Header, connect a provider (#134)
Browse files Browse the repository at this point in the history
* signer wip

* signer wip

* signer wip

* wip

* da mvp

* dep bump

* Signer wip

* ethers signer

* remove yalc from signer

* remove console.logs

* change ethersprovider version

* add docs

* type fixes

* utils/poll: remove double increment

* dep updatE

* doc fix

* remove jsonrpc error check logic in checkError

* ui: hello world

* safe dev ui: hello world

* pin jest version to the one required by react-scripts

* test script fix

* dep bump

* use jest 26.6.0

* bootstrapping

* wip

* wip

* wip

* dep bump

* wip

* trying to make header work

* got this thing to render

* logo alignment

* a battle with changing default font family in mui

* a battle with font scaling

* header

* header battle continues

* material ui warning fixes

* Fix web3modal

* provider store wip

* provider store wip

* provider details wip

* provider details wip

* wip:

* connected account details

* connect/disconnect provider

* change node version for tesT

* dep update

* dep update

* import casing fix

* remove test

* Eslint fix

* remove unused stuff

* remove unused stuff

* add props to provider
  • Loading branch information
mmv08 authored Apr 22, 2021
1 parent ff96562 commit d2e86c6
Show file tree
Hide file tree
Showing 55 changed files with 15,395 additions and 7,981 deletions.
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
22 changes: 12 additions & 10 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,20 @@
]
},
"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",
"@types/react": "^17.0.3",
"@types/react-dom": "^17.0.1",
"@typescript-eslint/eslint-plugin": "^4.16.1",
"@typescript-eslint/parser": "^4.16.1",
"eslint": "7.21.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.2",
"typescript": "^4.2.3"
}
}
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/).
59 changes: 59 additions & 0 deletions packages/safe-apps-developer-ui/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"name": "@gnosis.pm/safe-apps-developer-ui",
"version": "0.1.0",
"private": true,
"dependencies": {
"@gnosis.pm/safe-apps-react-sdk": "2.1.0",
"@material-ui/core": "^4.11.3",
"@material-ui/icons": "^4.11.2",
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.8.3",
"@types/styled-components": "^5.1.7",
"@walletconnect/web3-provider": "^1.3.6",
"clsx": "^1.1.1",
"ethereum-blockies-base64": "^1.0.2",
"ethers": "^5.0.32",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"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.15",
"@types/node": "^14.14.33",
"@types/react": "^17.0.3",
"@types/react-dom": "^17.0.2",
"@types/react-router": "^5.1.12",
"@types/react-router-dom": "^5.1.7",
"eslint-config-react-app": "^6.0.0",
"eslint-plugin-flowtype": "^5.3.1",
"eslint-plugin-import": "^2.22.0",
"eslint-plugin-jsx-a11y": "^6.3.1",
"eslint-plugin-react": "^7.22.0",
"eslint-plugin-react-hooks": "^4.2.0",
"web-vitals": "^1.0.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:
14 changes: 14 additions & 0 deletions packages/safe-apps-developer-ui/src/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { BrowserRouter as Router } from 'react-router-dom';
import Header from 'src/components/Header';

function App(): React.ReactElement {
return (
<Router>
<div className="App">
<Header />
</div>
</Router>
);
}

export default App;
54 changes: 54 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,54 @@
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 });

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

export { WALLET_PROVIDER, ETHEREUM_NETWORK_TO_ID, connectToProvider };
Binary file not shown.
Binary file not shown.
30 changes: 30 additions & 0 deletions packages/safe-apps-developer-ui/src/components/ConnectButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import React from 'react';
import styled from 'styled-components';
import { Web3Provider } from '@ethersproject/providers';

import Button from '@material-ui/core/Button';
import { connectToProvider } from '../api/provider';
import { useProviderStore } from 'src/stores/provider';

const SButton = styled(Button)`
min-width: 140px;
`;

const ConnectButton = (): React.ReactElement => {
const fetchAndSetProvider = useProviderStore((state) => state.fetchAndSetProvider);

const handleClick = async () => {
const connection = await connectToProvider();
const provider = new Web3Provider(connection);

fetchAndSetProvider(provider);
};

return (
<SButton color="primary" type="button" onClick={handleClick} variant="contained">
Connect
</SButton>
);
};

export default ConnectButton;
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.
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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
type Props = {
className: string;
};

const CircleDot = (props: Props): React.ReactElement => (
<div className={props.className}>
<svg xmlns="http://www.w3.org/2000/svg" width="10" height="10" viewBox="0 0 10 10">
<circle
cx="208"
cy="203"
r="3"
fill="none"
fillRule="evenodd"
stroke="#FF685E"
strokeWidth="3"
transform="translate(-203 -198)"
/>
</svg>
</div>
);

export { CircleDot };
Loading

0 comments on commit d2e86c6

Please sign in to comment.