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:
commit
3bb33658a0
37
src/App.tsx
37
src/App.tsx
@ -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() {
|
||||
|
@ -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
|
||||
|
@ -9,5 +9,8 @@ export const User = React.createContext({
|
||||
ocean: {},
|
||||
startLogin: () => {
|
||||
/* empty */
|
||||
},
|
||||
requestFromFaucet: () => {
|
||||
/* empty */
|
||||
}
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user