Skip to content

Commit 4f58247

Browse files
authored
Merge pull request #542 from ensdomains/dev
IPFS support and fix GA
2 parents 74ef8b7 + 3cda615 commit 4f58247

File tree

5 files changed

+52
-12
lines changed

5 files changed

+52
-12
lines changed

README.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,15 @@ yarn install
99
yarn start
1010
```
1111

12-
Open your browser at localhost:3000 and open metamask
12+
Open your browser at localhost:3000 and open metamask.
13+
14+
To start the ipfs-enabled build:
15+
16+
```bash
17+
yarn start:ipfs
18+
```
19+
20+
The main difference of the ipfs-build is that it uses HashRouter instead of BrowserRouter and makes sure all links are relative.
1321

1422
## Unit Testing
1523

@@ -112,7 +120,7 @@ ganache-cli
112120
yarn run preTest
113121
```
114122

115-
This runs the app in local ganache mode)
123+
This runs the app in local ganache mode:
116124

117125
```bash
118126
yarn start:test
@@ -122,6 +130,16 @@ yarn start:test
122130
yarn run cypress:open
123131
```
124132

133+
To test the ipfs-build use the respective ":ipfs"-variants of the scripts:
134+
135+
```bash
136+
yarn start:test:ipfs
137+
```
138+
139+
```bash
140+
yarn run cypress:open:ipfs
141+
```
142+
125143
## Setting up subgraph
126144

127145
Subgraph is used to list subdomains and all the names you have registered.

cypress_ipfs.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"env": {
3+
"ROOT": "http://localhost:3000/#",
4+
"TEST": "http://localhost:3000/#/Test",
5+
"NAME_ROOT": "http://localhost:3000/#/name"
6+
},
7+
"projectId": "rzedru"
8+
}

package.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,11 @@
5252
},
5353
"scripts": {
5454
"start": "react-scripts start",
55+
"start:ipfs": "REACT_APP_IPFS=True PUBLIC_URL='.' yarn start",
5556
"start:test": "REACT_APP_STAGE=local yarn start",
57+
"start:test:ipfs": "REACT_APP_STAGE=local yarn start:ipfs",
5658
"build": "CI=false react-scripts --max_old_space_size=4096 build",
59+
"build:ipfs": "REACT_APP_IPFS=True PUBLIC_URL='.' yarn build",
5760
"postbuild": "cp build/index.html build/200.html",
5861
"test": "react-scripts test --env=jsdom",
5962
"test:coverage": "npm test -- --coverage",
@@ -63,10 +66,15 @@
6366
"subgraph": "node scripts/subgraph.js",
6467
"advance": "node src/testing-utils/advance.js",
6568
"cypress:open": "yarn run cypress open",
66-
"cypress:record": "yarn run cypress run --record --key $CYPRESS_TOKEN",
69+
"cypress:open:ipfs": "yarn run cypress open --config-file cypress_ipfs.json",
70+
"cypress:record": "/bin/sh -c 'if [ -z ${CYPRESS_TOKEN+x} ]; then yarn run cypress run; else yarn run cypress run --record --key $CYPRESS_TOKEN; fi'",
71+
"cypress:record:ipfs": "/bin/sh -c 'if [ -z ${CYPRESS_TOKEN+x} ]; then yarn run cypress run --config-file cypress_ipfs.json; else yarn run cypress run --config-file cypress_ipfs.json --record --key $CYPRESS_TOKEN; fi'",
6772
"cypress:run-local": "yarn run cypress run",
73+
"cypress:run-local:ipfs": "yarn run cypress run --config-file cypress_ipfs.json",
6874
"cypress:run": "yarn preTest && start-server-and-test start:test http://localhost:3000 cypress:record",
75+
"cypress:run:ipfs": "yarn preTest && start-server-and-test start:test:ipfs http://localhost:3000 cypress:record:ipfs",
6976
"cypress:ci": "/bin/sh -c 'if [ \"$TRAVIS_PULL_REQUEST\" = \"true\" ]; then yarn cypress:run; else yarn cypress:run; fi'",
77+
"cypress:ci:ipfs": "/bin/sh -c 'if [ \"$TRAVIS_PULL_REQUEST\" = \"true\" ]; then yarn cypress:run:ipfs; else yarn cypress:run:ipfs; fi'",
7078
"deploy:dev": "npm run build && npm run postbuild && surge build ensappdev.surge.sh",
7179
"deploy": "npm run build && npm run postbuild && surge build app.ens.domains"
7280
},

src/App.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React, { Fragment } from 'react'
22
import {
3-
BrowserRouter as Router,
3+
HashRouter,
4+
BrowserRouter,
45
Route as DefaultRoute,
56
Switch
67
} from 'react-router-dom'
@@ -24,6 +25,10 @@ import { CONFIRM } from './modals'
2425
import DefaultLayout from './components/Layout/DefaultLayout'
2526
import Analytics from './utils/analytics'
2627

28+
// If we are targeting an IPFS build we need to use HashRouter
29+
const Router =
30+
process.env.REACT_APP_IPFS === 'True' ? HashRouter : BrowserRouter
31+
2732
const HomePageLayout = ({ children }) => <Fragment>{children}</Fragment>
2833

2934
const Route = ({

src/utils/analytics.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
1-
import ReactGA from 'react-ga';
1+
import ReactGA from 'react-ga'
22
const TrackingID = 'UA-138903307-1'
33

4-
function isProduction(){
5-
return window.location.host === 'manager.ens.domains'
4+
function isProduction() {
5+
return window.location.host === 'app.ens.domains'
66
}
77

88
export const setup = () => {
9-
if(isProduction()){
10-
ReactGA.initialize(TrackingID);
9+
if (isProduction()) {
10+
ReactGA.initialize(TrackingID)
1111
}
1212
}
1313

1414
export const pageview = () => {
1515
const page = window.location.pathname + window.location.search
16-
if(isProduction()){
17-
ReactGA.pageview(page);
16+
if (isProduction()) {
17+
ReactGA.pageview(page)
1818
}
1919
}
2020

2121
export default {
22-
setup, pageview
22+
setup,
23+
pageview
2324
}

0 commit comments

Comments
 (0)