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

Wallet Selector #4

Open
wants to merge 16 commits into
base: beta
Choose a base branch
from
Open
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: 2 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
},
"globals": {
"document": true,
"window": true,
"window": true
}
}
}
2 changes: 1 addition & 1 deletion .prettierrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"trailingComma": "all"
"trailingComma": "all"
}
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"@material-ui/core": "^3.1.2",
"@material-ui/icons": "^3.0.1",
"axios": "^0.18.0",
"eth-registry": "^1.2.0",
"ethjs": "^0.4.0",
"express": "^4.14.0",
"ipfs-mini": "^1.1.2",
Expand All @@ -42,7 +43,10 @@
"react-syntax-highlighter": "^8.0.1",
"react-typography": "^0.16.13",
"typography": "^0.16.17",
"typography-theme-github": "^0.15.10"
"typography-theme-github": "^0.15.10",
"walletconnect-qrcode-modal": "^0.7.28",
"walletconnect-web3-provider": "^0.7.28",
"web3": "^1.0.0-beta.36"
},
"devDependencies": {
"babel-eslint": "^10.0.1",
Expand Down
12 changes: 7 additions & 5 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import React, { Component } from "react";
import EthRegistry from "./js/metadata.js";
import Main from "./components/main.js";
import Header from "./components/Header";
import { MuiThemeProvider, createMuiTheme } from "@material-ui/core/styles";
import Typography from "typography";
import githubTheme from "typography-theme-github";
import EthRegistry from "eth-registry";
import Main from "./components/main";
import Header from "./components/Header";
import Footer from "./components/Footer";
import { MuiThemeProvider, createMuiTheme } from "@material-ui/core/styles";

githubTheme.headerFontFamily = ["Roboto", "sans-serif"];
githubTheme.bodyFontFamily = ["Roboto", "sans-serif"];
Expand Down Expand Up @@ -85,13 +86,14 @@ class App extends Component {
render() {
return (
<div className="App">
<Header ethregistry={ethregistry} />
<MuiThemeProvider theme={theme}>
<Header ethregistry={ethregistry} />
<Main
params={this.props.match.params}
location={this.props.location}
ethregistry={ethregistry}
/>
<Footer metadata={ethregistry} />
</MuiThemeProvider>
</div>
);
Expand Down
Binary file added src/assets/metamask.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 src/assets/walletconnect.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
189 changes: 116 additions & 73 deletions src/components/AccountManager.js
Original file line number Diff line number Diff line change
@@ -1,87 +1,130 @@
import React, { Component } from "react";
import Menu from "@material-ui/core/Menu";
import MenuItem from "@material-ui/core/MenuItem";
import React, { Component, Fragment } from "react";
import Avatar from "@material-ui/core/Avatar";
import EmptyAvatar from "../assets/empty_avatar.png";
import WalletSelector from "../components/WalletSelector";
import { getMetamaskAccounts } from "../js/metamask";
import {
walletConnectGetWeb3,
walletConnectCreateSession,
} from "../js/walletconnect";
import "../css/menu.css";

export default class AccountManager extends Component {
state = {
anchorEl: null,
};
state = {
web3Provider: null,
name: "",
anchorEl: null,
showWallets: false,
};

componentWillMount() {
if (
typeof window.web3 !== "undefined" &&
typeof window.web3.currentProvider !== "undefined"
) {
this.setState({ web3Provider: window.web3.currentProvider }, () =>
this.getProfile(),
);
}
getProfile = async accounts => {
const address = accounts[0];
console.log(address);
this.setState({ name: address });
let profile = await this.props.ethregistry.get(address);
if (profile && profile.data) {
console.log(profile);
this.setState({
profile: profile.data.metadata,
name: profile.data.metadata.name,
avatar: profile.data.metadata.logo,
});
}

getProfile = async () => {
console.log(this);
if (window.web3) console.log("getting");
const address = window.web3.eth.accounts[0];
console.log(address);
this.setState({ name: address });
let profile = await this.props.ethregistry.getAddressData(address);
if (profile && profile.data) {
console.log(profile);
this.setState({
profile: profile.data.metadata,
name: profile.data.metadata.name,
avatar: profile.data.metadata.logo,
});
}
try {
} catch (e) {}
};

try {
} catch (e) {}
};
handleClick = event => {
event.preventDefault();
this.setState({
anchorEl: event.currentTarget,
showWallets: !this.state.showWallets,
});
};

handleClick = event => {
this.setState({ anchorEl: event.currentTarget });
};
handleClose = () => {
this.setState({ anchorEl: null });
};

handleClose = () => {
this.setState({ anchorEl: null });
};
onMetamask = () =>
getMetamaskAccounts((accounts, error) => {
if (error) {
console.error(error);
return;
}
this.setState({ web3Provider: window.web3.currentProvider }, () =>
this.getProfile(accounts),
);
});

render() {
const { anchorEl } = this.state;
return (
<a
className="HeaderNavlink px-2 Account"
data-hotkey="g n"
aria-owns={anchorEl ? "simple-menu" : null}
aria-haspopup="true"
onClick={this.handleClick}
>
<ul
className="user-nav d-flex flex-items-center list-style-none"
id="user-links"
>
<li
className={
"name" + (this.state.profile ? " registered" : "")
}
>
{this.state.name}
</li>
<li>
<Avatar
src={this.state.avatar || EmptyAvatar}
style={{
width: 32,
height: 32,
// border: "4px solid black",
}}
/>
</li>
</ul>
</a>
);
onWalletConnect = async () => {
const network = "mainnet";
const web3 = await walletConnectGetWeb3(network);

try {
let accounts = await web3.eth.getAccounts();
if (!accounts || !accounts.length) {
accounts = await walletConnectCreateSession();
}
this.setState({ web3Provider: web3.currentProvider }, () =>
this.getProfile(accounts),
);
} catch (error) {
console.error(error);
}
};

onSelectWallet = selectedWallet => {
this.setState({ showWallets: false });
console.log(selectedWallet);

switch (selectedWallet) {
case "Metamask":
return this.onMetamask();
case "WalletConnect":
return this.onWalletConnect();
default:
return this.onMetamask();
}
};

render() {
const { anchorEl } = this.state;
return (
<Fragment>
<a
href="/"
className="HeaderNavlink px-2 Account"
data-hotkey="g n"
aria-owns={anchorEl ? "simple-menu" : null}
aria-haspopup="true"
onClick={this.handleClick}
>
<ul
className="user-nav d-flex flex-items-center list-style-none"
id="user-links"
>
<li className={"name" + (this.state.profile ? " registered" : "")}>
{this.state.name || "Connect Wallet"}
</li>
<li>
<Avatar
src={this.state.avatar || EmptyAvatar}
style={{
width: 32,
height: 32,
// border: "4px solid black",
}}
/>
</li>
</ul>
</a>
<WalletSelector
show={this.state.showWallets}
callback={this.onSelectWallet}
/>
</Fragment>
);
}
}
20 changes: 10 additions & 10 deletions src/components/AddressBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import React, { Component } from "react";
import Registry from "./Registry";

export default class AddressBar extends Component {
render() {
return (
<div class="monospace address">
<div class="barBadges">
<Registry type={this.props.badges} icon />;
</div>
<div class="barAddress">{this.props.address}</div>
</div>
);
}
render() {
return (
<div class="monospace address">
<div class="barBadges">
<Registry type={this.props.badges} icon />;
</div>
<div class="barAddress">{this.props.address}</div>
</div>
);
}
}
20 changes: 13 additions & 7 deletions src/components/Footer.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,21 @@ class FooterPage extends React.Component {
render() {
const { metadata } = this.props;
return (
<footer className="font-small pt-4 mt-4" style={{ flexGrow: 1 }}>
<Grid container spacing={16}>
<Grid item xs={2} sm={0} />
<Grid item xs={3} sm={3}>
<footer
className="font-small pt-4 mt-4"
style={{ flexGrow: 1, border: 0 }}
>
<Grid
id="footer-container"
container
spacing={24}
style={{ display: "flex", justifyContent: "center" }}
>
<Grid item sm={6} md={3}>
<h2>Recent Submissions</h2>
<Recent metadata={metadata} />
</Grid>
<Grid item xs={3} sm={3} style={{ marginRight: "3rem" }}>
<Grid item sm={6} md={3}>
<h2>Resources</h2>
<b>Metadata Contract:</b>{" "}
<p>
Expand Down Expand Up @@ -80,7 +87,7 @@ class FooterPage extends React.Component {
</code>
</p>
</Grid>
<Grid item xs={2} sm={3}>
<Grid item sm={6} md={3}>
<img src={LogoBanner} alt="logo" className="logo" />
<p className="disclaimer">
ETH Registry is an open-source tool for storing metadata on the
Expand Down Expand Up @@ -116,7 +123,6 @@ class FooterPage extends React.Component {
</p>
<p className="copyright">© 2018 Eth Registry</p>
</Grid>
<Grid item xs={2} sm={0} />
</Grid>
</footer>
);
Expand Down
3 changes: 1 addition & 2 deletions src/components/Form.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import React, { Component, PropTypes } from "react";
import React, { Component } from "react";
import Grid from "@material-ui/core/Grid";
import InputBase from "@material-ui/core/InputBase";
import InputAdornment from "@material-ui/core/InputAdornment";
import Edit from "@material-ui/icons/Edit";
import defaultsDeep from "lodash.defaultsdeep";
import isEqual from "lodash.isequal";

import FormComponent from "./FormComponent";
import LogoDrop from "./LogoDrop";
Expand Down
Loading