feat: add prerequisite checks before swap (#588)

* feat: add prerequisite checks before swap

* fix: add missing authentication on desktop config call

* refactor(wip): introduce swap error

* refactor: use wrapWithSwapError

* fix: log originalError instead of error

* fix: show snackbar when error is unexpected
This commit is contained in:
Cafe137
2022-11-23 14:20:55 +01:00
committed by GitHub
parent 1c53364fcd
commit 4e564dd5c0
5 changed files with 97 additions and 26 deletions
+21 -1
View File
@@ -2,7 +2,23 @@ import axios from 'axios'
import { BEE_DESKTOP_LATEST_RELEASE_PAGE_API } from '../constants'
import { DaiToken } from '../models/DaiToken'
import { Token } from '../models/Token'
import { postJson } from './net'
import { getJson, postJson } from './net'
export interface BeeConfig {
'api-addr': string
'debug-api-addr': string
'debug-api-enable': boolean
password: string
'swap-enable': boolean
'swap-initial-deposit': bigint
mainnet: boolean
'full-node': boolean
'cors-allowed-origins': string
'resolver-options': string
'use-postage-snapshot': boolean
'data-dir': string
'swap-endpoint'?: string
}
export async function getBzzPriceAsDai(desktopUrl: string): Promise<Token> {
const response = await axios.get(`${desktopUrl}/price`)
@@ -23,6 +39,10 @@ export async function setJsonRpcInDesktop(desktopUrl: string, value: string): Pr
})
}
export function getDesktopConfiguration(desktopUrl: string): Promise<BeeConfig> {
return getJson(`${desktopUrl}/config`)
}
async function updateDesktopConfiguration(desktopUrl: string, values: Record<string, unknown>): Promise<void> {
await postJson(`${desktopUrl}/config`, values)
}