Skip to content
This repository was archived by the owner on Mar 25, 2025. It is now read-only.

Commit 9111c74

Browse files
authored
merge: pull request #69 from TomAFrench/rc-1.5.0
merge v1.5.0 candidate into develop
2 parents 350af32 + 9e5b94e commit 9111c74

File tree

6 files changed

+91
-16
lines changed

6 files changed

+91
-16
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [1.5.0] - 2020-09-14
9+
10+
### Added
11+
12+
- Add simple integration of web3Modal to React templates, as per [pull request #63](https://github.com/PaulRBerg/create-eth-app/pull/63)
13+
814
## [1.4.1] - 2020-09-03
915

1016
### Fixed

handlebars/react/packages/react-app/package.json.hbs

+3-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"@testing-library/react": "^9.5.0",
2929
"@testing-library/user-event": "^7.2.1",
3030
"@types/react": "^16.9.19",
31+
"@walletconnect/web3-provider": "^1.2.2",
3132
"apollo-boost": "^0.4.7",
3233
"apollo-client": "^2.6.8",
3334
"apollo-utilities": "^1.3.3",
@@ -39,7 +40,8 @@
3940
"react": "16.12.0",
4041
"react-dom": "16.12.0",
4142
"react-scripts": "3.4.1",
42-
"styled-components": "^5.1.1"
43+
"styled-components": "^5.1.1",
44+
"web3modal": "^1.9.0"
4345
},
4446
"eslintConfig": {
4547
"extends": "react-app"

handlebars/react/packages/react-app/src/App.js.hbs

+41-12
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,54 @@
1-
import React from "react";
2-
import logo from "./ethereumLogo.png";
1+
import React, { useCallback, useEffect, useState } from "react";
32
import { Contract } from "@ethersproject/contracts";
4-
import { getDefaultProvider } from "@ethersproject/providers";
3+
import { Web3Provider, getDefaultProvider } from "@ethersproject/providers";
54
import { useQuery } from "@apollo/react-hooks";
65

7-
import { Body, Button, Image, Link } from "./components";
6+
import { Body, Button, Header, Image, Link } from "./components";
7+
import { web3Modal, logoutOfWeb3Modal } from './utils/web3Modal'
8+
import logo from "./ethereumLogo.png";
89

910
{{#each imports}}
1011
{{{ this }}}
1112
{{/each}}
1213

13-
1414
async function readOnChainData() {
1515
{{#each readOnChainData}}
1616
{{{ this }}}
1717
{{/each}}
1818
}
1919

20+
function WalletButton({ provider, loadWeb3Modal }) {
21+
return (
22+
<Button
23+
onClick={() => {
24+
if (!provider) {
25+
loadWeb3Modal();
26+
} else {
27+
logoutOfWeb3Modal();
28+
}
29+
}}
30+
>
31+
{!provider ? "Connect Wallet" : "Disconnect Wallet"}
32+
</Button>
33+
);
34+
}
35+
2036
function App() {
2137
const { loading, error, data } = useQuery({{ graphqlQueryName }});
38+
const [provider, setProvider] = useState();
39+
40+
/* Open wallet selection modal. */
41+
const loadWeb3Modal = useCallback(async () => {
42+
const newProvider = await web3Modal.connect();
43+
setProvider(new Web3Provider(newProvider));
44+
}, []);
45+
46+
/* If user has loaded a wallet before, load it automatically. */
47+
useEffect(() => {
48+
if (web3Modal.cachedProvider) {
49+
loadWeb3Modal();
50+
}
51+
}, [loadWeb3Modal]);
2252

2353
React.useEffect(() => {
2454
{{#each hooks.readData }}
@@ -28,13 +58,16 @@ function App() {
2858

2959
return (
3060
<div>
61+
<Header>
62+
<WalletButton provider={provider} loadWeb3Modal={loadWeb3Modal} />
63+
</Header>
3164
<Body>
3265
<Image src={logo} alt="react-logo" />
3366
<p>
3467
Edit <code>packages/react-app/src/App.js</code> and save to reload.
3568
</p>
3669
{/* Remove the "hidden" prop and open the JavaScript console in the browser to see what this function does */}
37-
<Button hidden onClick={() => readOnChainData()} >
70+
<Button hidden onClick={() => readOnChainData()}>
3871
{{ callToAction }}
3972
</Button>
4073
<Link
@@ -43,12 +76,8 @@ function App() {
4376
>
4477
Learn Ethereum
4578
</Link>
46-
<Link href="https://reactjs.org" >
47-
Learn React
48-
</Link>
49-
<Link href="{{ learnUrl }}" >
50-
Learn {{ whatToLearn }}
51-
</Link>
79+
<Link href="https://reactjs.org">Learn React</Link>
80+
<Link href="{{ learnUrl }}" >Learn {{ whatToLearn }}</Link>
5281
</Body>
5382
</div>
5483
);

handlebars/react/packages/react-app/src/components/index.js

+14-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
import styled from "styled-components";
22

3+
export const Header = styled.header`
4+
background-color: #282c34;
5+
min-height: 70px;
6+
display: flex;
7+
flex-direction: row;
8+
align-items: center;
9+
justify-content: flex-end;
10+
color: white;
11+
`;
12+
313
export const Body = styled.body`
414
align-items: center;
515
background-color: #282c34;
@@ -8,7 +18,7 @@ export const Body = styled.body`
818
flex-direction: column;
919
font-size: calc(10px + 2vmin);
1020
justify-content: center;
11-
min-height: 100vh;
21+
min-height: calc(100vh - 70px);
1222
`;
1323

1424
export const Image = styled.img`
@@ -37,7 +47,9 @@ export const Button = styled.button`
3747
margin: 0px 20px;
3848
padding: 12px 24px;
3949
40-
${props => props.hidden && "hidden"} :focus {
50+
${props => props.hidden && "hidden"}
51+
52+
:focus {
4153
border: none;
4254
outline: none;
4355
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import Web3Modal from "web3modal";
2+
import WalletConnectProvider from "@walletconnect/web3-provider";
3+
4+
// Enter a valid infura key here to avoid being rate limited
5+
// You can get a key for free at https://infura.io/register
6+
const INFURA_ID = "INVALID_INFURA_KEY";
7+
8+
// Web3Modal also supports many other wallets.
9+
// You can see other options at https://github.com/Web3Modal/web3modal
10+
export const web3Modal = new Web3Modal({
11+
network: "mainnet",
12+
cacheProvider: true,
13+
providerOptions: {
14+
walletconnect: {
15+
package: WalletConnectProvider,
16+
options: {
17+
infuraId: INFURA_ID,
18+
},
19+
},
20+
},
21+
});
22+
23+
export const logoutOfWeb3Modal = async function() {
24+
await web3Modal.clearCachedProvider();
25+
window.location.reload();
26+
};

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "create-eth-app",
33
"description": "Create Ethereum-powered apps with one command",
4-
"version": "1.4.1",
4+
"version": "1.5.0",
55
"bin": {
66
"create-eth-app": "./dist/index.js"
77
},

0 commit comments

Comments
 (0)