Skip to content
This repository has been archived by the owner on Jan 15, 2021. It is now read-only.

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Velenir committed Jan 27, 2020
2 parents 7c77cfa + efe2db4 commit 6efc2af
Show file tree
Hide file tree
Showing 88 changed files with 5,429 additions and 1,806 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,4 @@ If you use Visual Studio Code, it's recommended to install [Prettier - Code form
## Testnet faucets

In order to get testing tokens, read up the information here:
[faucet](./src/docs/faucet-info.md)
[faucet](./docs/faucet-info.md)
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"@fortawesome/free-solid-svg-icons": "^5.11.2",
"@fortawesome/react-fontawesome": "^0.1.4",
"@gnosis.pm/dapp-ui": "^0.5.3",
"@gnosis.pm/dex-js": "0.1.5-RC.3",
"@gnosis.pm/dex-js": "0.1.7",
"@hot-loader/react-dom": "^16.8.6",
"@types/react": "^16.9.13",
"@types/react-select": "^3.0.5",
Expand All @@ -69,6 +69,7 @@
"combine-reducers": "^1.0.0",
"date-fns": "^2.8.1",
"modali": "^1.2.0",
"node-cache": "^5.1.0",
"polished": "^3.4.1",
"qrcode.react": "^1.0.0",
"react": "^16.8.6",
Expand Down Expand Up @@ -96,7 +97,7 @@
"@types/enzyme": "^3.10.3",
"@types/enzyme-adapter-react-16": "^1.0.5",
"@types/jest": "^24.0.18",
"@types/node": "^12.7.5",
"@types/node": "^13.1.4",
"@types/qrcode.react": "^1.0.0",
"@types/react-copy-to-clipboard": "^4.3.0",
"@types/react-dom": "^16.9.4",
Expand All @@ -108,6 +109,7 @@
"babel-jest": "^24.9.0",
"babel-loader": "^8.0.6",
"babel-plugin-styled-components": "^1.10.6",
"console-feed": "^2.8.11",
"coveralls": "^3.0.6",
"css-loader": "^3.2.0",
"dotenv": "^8.1.0",
Expand All @@ -129,7 +131,7 @@
"jest": "^24.9.0",
"jest-enzyme": "^7.1.1",
"prettier": "^1.18.2",
"react-dev-utils": "^9.0.1",
"react-dev-utils": "^10.0.0",
"react-test-renderer": "^16.9.0",
"rimraf": "^3.0.0",
"style-loader": "^1.0.0",
Expand Down
16 changes: 13 additions & 3 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,23 @@ import Wallet from 'pages/Wallet'
import SourceCode from 'pages/SourceCode'
import NotFound from 'pages/NotFound'
import ConnectWallet from 'pages/ConnectWallet'
import { walletApi } from 'api'

// Global State
import { withGlobalContext } from 'hooks/useGlobalState'
import { rootReducer, INITIAL_STATE } from 'reducers-actions'

import Web3Connect from 'web3connect'
import { useWalletConnection } from 'hooks/useWalletConnection'

const PrivateRoute: React.FC<RouteProps> = (props: RouteProps) => {
const isConnected = walletApi.isConnected()
const { pending, isConnected } = useWalletConnection()

const { component: Component, ...rest } = props

if (pending) {
return <Route {...rest} render={(): null => null} />
}

return (
<Route
{...rest}
Expand Down Expand Up @@ -66,7 +73,7 @@ const App: React.FC = () => (
<Switch>
<PrivateRoute path="/orders" exact component={Orders} />
<Route path="/trade/:sell-:buy" component={Trade} />
<PrivateRoute path="/strategies" exact component={Strategies} />
<PrivateRoute path="/liquidity" exact component={Strategies} />
<PrivateRoute path="/wallet" exact component={Wallet} />
<PrivateRoute path="/orders" exact component={Orders} />
<Route path="/about" exact component={About} />
Expand All @@ -77,6 +84,9 @@ const App: React.FC = () => (
</Switch>
</Layout>
</Router>
{process.env.NODE_ENV === 'development' &&
Web3Connect.isMobile() &&
React.createElement(require('./Console').default)}
</>
)

Expand Down
120 changes: 120 additions & 0 deletions src/Console.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
import React, { useState, useEffect, useRef } from 'react'
import { Hook, Unhook, Console, Message, Decode } from 'console-feed'
import styled from 'styled-components'

const ConsoleWrapper = styled.div`
position: fixed;
bottom: 0;
right: 0;
background-color: #242424;
max-height: 100%;
width: 100%;
overflow: auto;
z-index: 9999;
`
const ButtonGroup = styled.div`
position: fixed;
bottom: 0;
right: 0;
padding: 2em;
pointer-events: none;
> * {
pointer-events: initial;
}
`

const InputGroup = styled.div`
position: sticky;
bottom: 0.4em;
margin: 0;
margin-top: 5px;
display: flex;
input:focus {
border: inherit;
}
input {
margin: 0;
border-radius: 0;
}
button {
margin: 0;
border: none;
border-radius: 0;
}
`

const ConsoleFrame: React.FC = () => {
const [logs, setLogs] = useState<Message[]>([])
const [showConsole, setShowConsole] = useState(false)

const wrapper = useRef<HTMLDivElement>(null)
const input = useRef<HTMLInputElement>(null)

useEffect(() => {
const hookedConsole = Hook(window.console, (log: Message) => setLogs(logs => logs.concat(Decode(log))))

return (): void => {
Unhook(hookedConsole)
}
}, [])

const processCommand = (command?: string): void => {
if (!command) return

if (command.includes('await ')) {
eval(`
(async function() {
return ${command}
})()
`).then(console.log, console.error)
} else {
try {
console.log(eval(command))
} catch (error) {
console.error(error)
}
}

if (input.current) input.current.value = ''
setTimeout(() => {
if (wrapper.current) wrapper.current.scrollTop = wrapper.current.scrollHeight
}, 0)
}

const handleCommand = async (e: React.KeyboardEvent<HTMLInputElement>): Promise<void> => {
const command = e.currentTarget.value
if (e.key === 'Enter' && command) {
processCommand(command)
}
}

const handleClick = (): void => {
if (input.current && input.current.value) {
processCommand(input.current.value)
}
}

return (
<ConsoleWrapper ref={wrapper}>
{showConsole && (
<>
<Console logs={logs} variant="dark" />
<InputGroup>
<input type="text" onKeyPress={handleCommand} ref={input} />
<button onClick={handleClick}>{'>>'}</button>
</InputGroup>
</>
)}
<ButtonGroup>
{showConsole && logs.length > 0 && <button onClick={(): void => setLogs([])}>clear</button>}
<button onClick={(): void => setShowConsole(on => !on)}>{showConsole ? 'x' : '^'}</button>
</ButtonGroup>
</ConsoleWrapper>
)
}

export default ConsoleFrame
Loading

0 comments on commit 6efc2af

Please sign in to comment.