feat: add bee desktop toolkit (#311)
* feat: add light node upgrade * refactor: improve upgrade page * feat: pretty print xdai and add xbzz faucets * feat: display xBZZ balance (#312) * refactor: change rpc provider * fix: remove version alert * fix: load really xBZZ balance instead of xDAI (#314) * feat: add bee desktop api key support * chore: remove dead code * chore: revert useless change * refactor: extract desktop utils module (#339) * refactor: extract desktop utils module * fix: add 0x prefix if it missing from address * refactor: extract BalanceProvider * fix: remove double finally * fix: remove token fallbacks * fix: reuse address and handle balance errors * chore: disable eslint for any * refactor: remove upgrade page * refactor: cleanup, debounce and axios * refactor: change fetch to axios * chore: remove dead code * chore: revert import ordering * refactor: use axios instead of fetch * refactor: use token instead of string Co-authored-by: Cafe137 <aron@aronsoos.com> Co-authored-by: Vojtech Simetka <vojtech@simetka.cz>
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
import axios from 'axios'
|
||||
import { getJson, postJson } from './net'
|
||||
|
||||
interface DesktopStatus {
|
||||
status: 0 | 1 | 2
|
||||
address: string | null
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
config: Record<string, any>
|
||||
}
|
||||
|
||||
export async function getDesktopStatus(): Promise<DesktopStatus> {
|
||||
const response = await getJson(`http://${getDesktopHost()}/status`)
|
||||
|
||||
return response as DesktopStatus
|
||||
}
|
||||
|
||||
export async function getGasFromFaucet(address: string): Promise<void> {
|
||||
await axios.post(`http://getxdai.co/${address}/0.1`)
|
||||
}
|
||||
|
||||
export async function upgradeToLightNode(rpcProvider: string): Promise<void> {
|
||||
await updateDesktopConfiguration({
|
||||
'chain-enable': true,
|
||||
'swap-enable': true,
|
||||
'swap-endpoint': rpcProvider,
|
||||
})
|
||||
}
|
||||
|
||||
async function updateDesktopConfiguration(values: Record<string, unknown>): Promise<void> {
|
||||
await postJson(`http://${getDesktopHost()}/config`, values)
|
||||
}
|
||||
|
||||
export async function restartBeeNode(): Promise<void> {
|
||||
await postJson(`http://${getDesktopHost()}/restart`)
|
||||
}
|
||||
|
||||
function getDesktopHost(): string {
|
||||
return window.location.host
|
||||
}
|
||||
Reference in New Issue
Block a user