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:
parent
88083bebf1
commit
e5ede49971
37
src/App.tsx
37
src/App.tsx
@ -10,7 +10,14 @@ import Routes from './Routes'
|
|||||||
import './styles/global.scss'
|
import './styles/global.scss'
|
||||||
import styles from './App.module.scss'
|
import styles from './App.module.scss'
|
||||||
|
|
||||||
import { nodeHost, nodePort, nodeScheme } from './config'
|
import {
|
||||||
|
nodeHost,
|
||||||
|
nodePort,
|
||||||
|
nodeScheme,
|
||||||
|
faucetHost,
|
||||||
|
faucetPort,
|
||||||
|
faucetScheme
|
||||||
|
} from './config'
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
interface Window {
|
interface Window {
|
||||||
@ -37,6 +44,31 @@ class App extends Component<{}, AppState> {
|
|||||||
this.startLoginProcess()
|
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 = {
|
public state = {
|
||||||
isLogged: false,
|
isLogged: false,
|
||||||
isLoading: true,
|
isLoading: true,
|
||||||
@ -48,7 +80,8 @@ class App extends Component<{}, AppState> {
|
|||||||
),
|
),
|
||||||
account: '',
|
account: '',
|
||||||
ocean: {},
|
ocean: {},
|
||||||
startLogin: this.startLogin
|
startLogin: this.startLogin,
|
||||||
|
requestFromFaucet: this.requestFromFaucet
|
||||||
}
|
}
|
||||||
|
|
||||||
public async componentDidMount() {
|
public async componentDidMount() {
|
||||||
|
@ -9,5 +9,8 @@ export const User = React.createContext({
|
|||||||
ocean: {},
|
ocean: {},
|
||||||
startLogin: () => {
|
startLogin: () => {
|
||||||
/* empty */
|
/* empty */
|
||||||
|
},
|
||||||
|
requestFromFaucet: () => {
|
||||||
|
/* empty */
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user