1
0
mirror of https://github.com/oceanprotocol/commons.git synced 2023-03-15 18:03:00 +01:00

Merge pull request #24 from oceanprotocol/feature/faucet-request

faucet request function
This commit is contained in:
Matthias Kretschmann 2019-02-26 14:40:42 +01:00 committed by GitHub
commit 3bb33658a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 2 deletions

View File

@ -10,7 +10,14 @@ import Routes from './Routes'
import './styles/global.scss'
import styles from './App.module.scss'
import { nodeHost, nodePort, nodeScheme } from './config'
import {
nodeHost,
nodePort,
nodeScheme,
faucetHost,
faucetPort,
faucetScheme
} from './config'
declare global {
interface Window {
@ -37,6 +44,31 @@ class App extends Component<{}, AppState> {
this.startLoginProcess()
}
private requestFromFaucet = async () => {
if (this.state.account !== '') {
try {
await fetch(
`${faucetScheme}://${faucetHost}:${faucetPort}/faucet`,
{
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
address: this.state.account,
agent: 'commons-marketplace'
})
}
)
} catch (error) {
// show error
}
} else {
// no account found
}
}
public state = {
isLogged: false,
isLoading: true,
@ -48,7 +80,8 @@ class App extends Component<{}, AppState> {
),
account: '',
ocean: {},
startLogin: this.startLogin
startLogin: this.startLogin,
requestFromFaucet: this.requestFromFaucet
}
public async componentDidMount() {

View File

@ -22,4 +22,8 @@ export const threshold = 0
export const password = 'node0'
export const address = '0x00bd138abd70e2f00903268f3db08f2d25677c9e'
export const faucetScheme = 'http'
export const faucetHost = 'localhost'
export const faucetPort = 3001
export const verbose = true

View File

@ -9,5 +9,8 @@ export const User = React.createContext({
ocean: {},
startLogin: () => {
/* empty */
},
requestFromFaucet: () => {
/* empty */
}
})