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

faucet request function

This commit is contained in:
Jernej Pregelj 2019-02-20 15:00:42 +01:00
parent 88083bebf1
commit e5ede49971
2 changed files with 38 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

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