Compare commits

...

20 Commits

Author SHA1 Message Date
bee-worker 145ebc1232 chore(master): release 0.15.0 (#367) 2022-05-16 11:52:58 +02:00
Vojtech Simetka bfe38e96b4 ci: update release-please github action (#366) 2022-05-16 11:45:35 +02:00
Vojtech Simetka 86978b7e99 fix: nested directory upload preserves the directory structure (#365) 2022-05-16 10:39:00 +02:00
dependabot[bot] efd3158b2b build(deps-dev): bump ts-node from 10.4.0 to 10.7.0 (#360)
Bumps [ts-node](https://github.com/TypeStrong/ts-node) from 10.4.0 to 10.7.0.
- [Release notes](https://github.com/TypeStrong/ts-node/releases)
- [Commits](https://github.com/TypeStrong/ts-node/compare/v10.4.0...v10.7.0)

---
updated-dependencies:
- dependency-name: ts-node
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-05-03 18:14:13 +02:00
Vojtech Simetka 07561aaed2 fix: connection health indicator values to reflect the current network conditions (#353)
* fix: connection health indicator values to reflect the current network conditions

* fix: remove depth check as it seems the depth is always 0

* Revert "fix: remove depth check as it seems the depth is always 0"

This reverts commit 363ead8fba9bc79266abdf2d8c3f540d75da5b48.

* fix: updated the values according to the bee team advice
2022-05-03 18:07:37 +02:00
Vojtech Simetka 1e2face10e feat: wait for postage stamp to be usable when bying it (#352)
* feat: wait for postage stamp to be usable when bying it

* refactor: simplified the waitUntilStampUsable function
2022-04-29 13:42:29 +02:00
Vojtech Simetka b6b9914548 fix: remove restrictions on postage stamp label (#354) 2022-04-29 13:42:01 +02:00
Vojtech Simetka 87b0b71cc6 feat: add bee-desktop settings capabilities (#323)
* refactor: make the config readonly and extract endpoint calls to hook (+2 squashed commits)
Squashed commits:
[91ffe45] feat: add swap-endpoint
[e1d0c3a] feat: add bee-desktop settings capabilities

* feat: use the request mechanism that uses the bee-desktop API key

* fix: properly reset the error or on error set the config to null
2022-04-29 09:30:46 +02:00
dependabot[bot] 8114fa7d73 build(deps-dev): bump @babel/preset-react from 7.16.0 to 7.16.7 (#345)
Bumps [@babel/preset-react](https://github.com/babel/babel/tree/HEAD/packages/babel-preset-react) from 7.16.0 to 7.16.7.
- [Release notes](https://github.com/babel/babel/releases)
- [Changelog](https://github.com/babel/babel/blob/main/CHANGELOG.md)
- [Commits](https://github.com/babel/babel/commits/v7.16.7/packages/babel-preset-react)

---
updated-dependencies:
- dependency-name: "@babel/preset-react"
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-04-29 08:18:54 +02:00
dependabot[bot] e454a7eba0 build(deps-dev): bump eslint-config-prettier from 8.2.0 to 8.5.0 (#344)
Bumps [eslint-config-prettier](https://github.com/prettier/eslint-config-prettier) from 8.2.0 to 8.5.0.
- [Release notes](https://github.com/prettier/eslint-config-prettier/releases)
- [Changelog](https://github.com/prettier/eslint-config-prettier/blob/main/CHANGELOG.md)
- [Commits](https://github.com/prettier/eslint-config-prettier/compare/v8.2.0...v8.5.0)

---
updated-dependencies:
- dependency-name: eslint-config-prettier
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-04-29 08:17:32 +02:00
Vojtech Simetka 3784b29f14 feat: support for bzz.link cids when downloading files (#350)
* feat: detect and extract bzz.link cids into hash when downloading files

* test: add quite thorough testsuite
2022-04-25 20:38:36 +05:00
Vojtech Simetka a67be7a31e fix: app crash caused by inputing non-number characters (#347) 2022-04-24 21:40:52 +05:00
Vojtech Simetka 23dea07f6e feat: add aditional information to the stamps overview (#349) 2022-04-24 21:40:41 +05:00
Vojtech Simetka 906a457ae5 fix: show current postage stamp price per block (#348) 2022-04-24 21:40:31 +05:00
dependabot[bot] 0a69409077 build(deps-dev): bump @testing-library/jest-dom from 5.15.0 to 5.16.4 (#343)
Bumps [@testing-library/jest-dom](https://github.com/testing-library/jest-dom) from 5.15.0 to 5.16.4.
- [Release notes](https://github.com/testing-library/jest-dom/releases)
- [Changelog](https://github.com/testing-library/jest-dom/blob/main/CHANGELOG.md)
- [Commits](https://github.com/testing-library/jest-dom/compare/v5.15.0...v5.16.4)

---
updated-dependencies:
- dependency-name: "@testing-library/jest-dom"
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-04-22 18:58:06 +05:00
dependabot[bot] 9026e65b1f build(deps-dev): bump @types/react-router from 5.1.17 to 5.1.18 (#342)
Bumps [@types/react-router](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/react-router) from 5.1.17 to 5.1.18.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/react-router)

---
updated-dependencies:
- dependency-name: "@types/react-router"
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-04-22 18:57:34 +05:00
dependabot[bot] a21e60f2d8 build(deps): bump ethers from 5.6.1 to 5.6.4 (#341)
Bumps [ethers](https://github.com/ethers-io/ethers.js/tree/HEAD/packages/ethers) from 5.6.1 to 5.6.4.
- [Release notes](https://github.com/ethers-io/ethers.js/releases)
- [Changelog](https://github.com/ethers-io/ethers.js/blob/master/CHANGELOG.md)
- [Commits](https://github.com/ethers-io/ethers.js/commits/v5.6.4/packages/ethers)

---
updated-dependencies:
- dependency-name: ethers
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-04-22 18:57:03 +05:00
Vojtech Simetka 39f59fcc07 ci: allow longer commit messages in commitlint (#346) 2022-04-22 17:49:25 +05:00
Vojtech Simetka 75967b2bf5 ci: add dependabot (#335) 2022-04-21 19:33:15 +05:00
Cafe137 ecaf2054fc 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>
2022-04-21 16:29:50 +02:00
26 changed files with 1937 additions and 202 deletions
+13
View File
@@ -0,0 +1,13 @@
# See config in https://docs.github.com/en/code-security/supply-chain-security/keeping-your-dependencies-updated-automatically/configuration-options-for-dependency-updates
version: 2
updates:
# Enable version updates for npm
- package-ecosystem: 'npm'
# Look for `package.json` and `lock` files in the `root` directory
directory: '/'
# Check the npm registry for updates every day (weekdays)
schedule:
interval: 'weekly'
# Always increase the version in package.json as well (for patch versions by default only package-lock.json i updated)
versioning-strategy: increase
+2
View File
@@ -0,0 +1,2 @@
# Always validate the PR title, and ignore the commits
titleOnly: true
+1 -1
View File
@@ -11,7 +11,7 @@ jobs:
release-please: release-please:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: GoogleCloudPlatform/release-please-action@v2 - uses: GoogleCloudPlatform/release-please-action@v3
id: release id: release
with: with:
token: ${{ secrets.GHA_PAT_BASIC }} token: ${{ secrets.GHA_PAT_BASIC }}
+20
View File
@@ -1,5 +1,25 @@
# Changelog # Changelog
## [0.15.0](https://github.com/ethersphere/bee-dashboard/compare/v0.14.0...v0.15.0) (2022-05-16)
### Features
* add aditional information to the stamps overview ([#349](https://github.com/ethersphere/bee-dashboard/issues/349)) ([23dea07](https://github.com/ethersphere/bee-dashboard/commit/23dea07f6e53da91f87078749f07bd95c9e65983))
* add bee desktop toolkit ([#311](https://github.com/ethersphere/bee-dashboard/issues/311)) ([ecaf205](https://github.com/ethersphere/bee-dashboard/commit/ecaf2054fc5aaa5fa4f1d0b3fb2753af9d9b233e))
* add bee-desktop settings capabilities ([#323](https://github.com/ethersphere/bee-dashboard/issues/323)) ([87b0b71](https://github.com/ethersphere/bee-dashboard/commit/87b0b71cc63098a5d886ff47d52715c250d1b659))
* support for bzz.link cids when downloading files ([#350](https://github.com/ethersphere/bee-dashboard/issues/350)) ([3784b29](https://github.com/ethersphere/bee-dashboard/commit/3784b29f148b706d5bc40b69b5ae898efa2c1990))
* wait for postage stamp to be usable when bying it ([#352](https://github.com/ethersphere/bee-dashboard/issues/352)) ([1e2face](https://github.com/ethersphere/bee-dashboard/commit/1e2face10e93818f281526d8245f84834e5ecb86))
### Bug Fixes
* app crash caused by inputing non-number characters ([#347](https://github.com/ethersphere/bee-dashboard/issues/347)) ([a67be7a](https://github.com/ethersphere/bee-dashboard/commit/a67be7a31ec88e9ce9c7764ec4523496c157d08a))
* connection health indicator values to reflect the current network conditions ([#353](https://github.com/ethersphere/bee-dashboard/issues/353)) ([07561aa](https://github.com/ethersphere/bee-dashboard/commit/07561aaed2ce7f7ffd7ecfd8ae8b5190cc9893bc))
* nested directory upload preserves the directory structure ([#365](https://github.com/ethersphere/bee-dashboard/issues/365)) ([86978b7](https://github.com/ethersphere/bee-dashboard/commit/86978b7e999584173b082eef86074af698523752))
* remove restrictions on postage stamp label ([#354](https://github.com/ethersphere/bee-dashboard/issues/354)) ([b6b9914](https://github.com/ethersphere/bee-dashboard/commit/b6b9914548a0ac00ed293ea35490ce38e9d6adaa))
* show current postage stamp price per block ([#348](https://github.com/ethersphere/bee-dashboard/issues/348)) ([906a457](https://github.com/ethersphere/bee-dashboard/commit/906a457ae5a8683f82d218759fd66dc1b7c9a220))
## [0.14.0](https://www.github.com/ethersphere/bee-dashboard/compare/v0.13.0...v0.14.0) (2022-04-14) ## [0.14.0](https://www.github.com/ethersphere/bee-dashboard/compare/v0.13.0...v0.14.0) (2022-04-14)
+6
View File
@@ -0,0 +1,6 @@
module.exports = {
extends: ['@commitlint/config-conventional'],
rules: {
'body-max-line-length': [0, 'always', Infinity], // disable commit body length restriction
},
}
+1356 -151
View File
File diff suppressed because it is too large Load Diff
+7 -6
View File
@@ -1,6 +1,6 @@
{ {
"name": "@ethersphere/bee-dashboard", "name": "@ethersphere/bee-dashboard",
"version": "0.14.0", "version": "0.15.0",
"description": "An app which helps users to setup their Bee node and do actions like cash out cheques", "description": "An app which helps users to setup their Bee node and do actions like cash out cheques",
"keywords": [ "keywords": [
"bee", "bee",
@@ -35,6 +35,7 @@
"axios": "0.24.0", "axios": "0.24.0",
"bignumber.js": "9.0.1", "bignumber.js": "9.0.1",
"ethereumjs-wallet": "^1.0.2", "ethereumjs-wallet": "^1.0.2",
"ethers": "^5.6.4",
"file-saver": "^2.0.5", "file-saver": "^2.0.5",
"formik": "2.2.9", "formik": "2.2.9",
"formik-material-ui": "3.0.1", "formik-material-ui": "3.0.1",
@@ -59,10 +60,10 @@
"@babel/plugin-proposal-class-properties": "7.16.0", "@babel/plugin-proposal-class-properties": "7.16.0",
"@babel/plugin-transform-runtime": "7.16.4", "@babel/plugin-transform-runtime": "7.16.4",
"@babel/preset-env": "7.16.4", "@babel/preset-env": "7.16.4",
"@babel/preset-react": "7.16.0", "@babel/preset-react": "7.16.7",
"@babel/preset-typescript": "7.16.0", "@babel/preset-typescript": "7.16.0",
"@commitlint/config-conventional": "14.1.0", "@commitlint/config-conventional": "14.1.0",
"@testing-library/jest-dom": "5.15.0", "@testing-library/jest-dom": "5.16.4",
"@testing-library/react": "12.1.2", "@testing-library/react": "12.1.2",
"@testing-library/react-hooks": "^8.0.0", "@testing-library/react-hooks": "^8.0.0",
"@types/cors": "^2.8.12", "@types/cors": "^2.8.12",
@@ -73,7 +74,7 @@
"@types/react": "17.0.34", "@types/react": "17.0.34",
"@types/react-copy-to-clipboard": "5.0.2", "@types/react-copy-to-clipboard": "5.0.2",
"@types/react-dom": "17.0.11", "@types/react-dom": "17.0.11",
"@types/react-router": "5.1.17", "@types/react-router": "5.1.18",
"@types/react-router-dom": "5.3.2", "@types/react-router-dom": "5.3.2",
"@types/react-syntax-highlighter": "13.5.2", "@types/react-syntax-highlighter": "13.5.2",
"@types/semver": "7.3.9", "@types/semver": "7.3.9",
@@ -86,7 +87,7 @@
"cors": "^2.8.5", "cors": "^2.8.5",
"depcheck": "^1.4.3", "depcheck": "^1.4.3",
"eslint": "7.24.0", "eslint": "7.24.0",
"eslint-config-prettier": "8.2.0", "eslint-config-prettier": "8.5.0",
"eslint-config-react-app": "6.0.0", "eslint-config-react-app": "6.0.0",
"eslint-plugin-flowtype": "5.10.0", "eslint-plugin-flowtype": "5.10.0",
"eslint-plugin-import": "2.25.2", "eslint-plugin-import": "2.25.2",
@@ -100,7 +101,7 @@
"file-loader": "6.2.0", "file-loader": "6.2.0",
"prettier": "2.4.1", "prettier": "2.4.1",
"react-scripts": "4.0.3", "react-scripts": "4.0.3",
"ts-node": "^10.4.0", "ts-node": "^10.7.0",
"typescript": "4.4.4", "typescript": "4.4.4",
"web-vitals": "2.1.2", "web-vitals": "2.1.2",
"webpack": "4.44.2", "webpack": "4.44.2",
+4 -2
View File
@@ -55,7 +55,7 @@ interface Props {
confirmLabelDisabled?: boolean confirmLabelDisabled?: boolean
loading?: boolean loading?: boolean
onChange?: (value: string) => void onChange?: (value: string) => void
onConfirm: (value: string) => void onConfirm?: (value: string) => void
mapperFn?: (value: string) => string mapperFn?: (value: string) => string
locked?: boolean locked?: boolean
} }
@@ -138,7 +138,9 @@ export default function ExpandableListItemKey({
} }
loading={loading} loading={loading}
iconType={Search} iconType={Search}
onClick={() => onConfirm(inputValue)} onClick={() => {
if (onConfirm) onConfirm(inputValue)
}}
> >
{confirmLabel || 'Save'} {confirmLabel || 'Save'}
</SwarmButton> </SwarmButton>
+1
View File
@@ -1,3 +1,4 @@
export const META_FILE_NAME = '.swarmgatewaymeta.json' export const META_FILE_NAME = '.swarmgatewaymeta.json'
export const PREVIEW_FILE_NAME = '.swarmgatewaypreview.jpeg' export const PREVIEW_FILE_NAME = '.swarmgatewaypreview.jpeg'
export const PREVIEW_DIMENSIONS = { maxWidth: 250, maxHeight: 175 } export const PREVIEW_DIMENSIONS = { maxWidth: 250, maxHeight: 175 }
export const BZZ_LINK_DOMAIN = process.env.REACT_APP_BZZ_LINK_DOMAIN || 'bzz.link'
+49
View File
@@ -1,6 +1,7 @@
import axios from 'axios' import axios from 'axios'
import { useEffect, useState } from 'react' import { useEffect, useState } from 'react'
import { config } from '../config' import { config } from '../config'
import { getJson } from '../utils/net'
export interface LatestBeeReleaseHook { export interface LatestBeeReleaseHook {
latestBeeRelease: LatestBeeRelease | null latestBeeRelease: LatestBeeRelease | null
@@ -44,6 +45,54 @@ export const useIsBeeDesktop = (conf: Config = config): IsBeeDesktopHook => {
return { isBeeDesktop, isLoading } return { isBeeDesktop, isLoading }
} }
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
'chain-enable': boolean
'cors-allowed-origins': string
'resolver-options': string
'use-postage-snapshot': boolean
'data-dir': string
transaction: string
'block-hash': string
'swap-endpoint'?: string
}
export interface GetBeeConfig {
config: BeeConfig | null
isLoading: boolean
error: Error | null
}
export const useGetBeeConfig = (conf: Config = config): GetBeeConfig => {
const [beeConfig, setBeeConfig] = useState<BeeConfig | null>(null)
const [isLoading, setLoading] = useState<boolean>(true)
const [error, setError] = useState<Error | null>(null)
useEffect(() => {
getJson<BeeConfig>(`${conf.BEE_DESKTOP_URL}/config`)
.then(beeConf => {
setBeeConfig(beeConf)
setError(null)
})
.catch((err: Error) => {
setError(err)
setBeeConfig(null)
})
.finally(() => {
setLoading(false)
})
}, [conf])
return { config: beeConfig, isLoading, error }
}
export const useLatestBeeRelease = (): LatestBeeReleaseHook => { export const useLatestBeeRelease = (): LatestBeeReleaseHook => {
const [latestBeeRelease, setLatestBeeRelease] = useState<LatestBeeRelease | null>(null) const [latestBeeRelease, setLatestBeeRelease] = useState<LatestBeeRelease | null>(null)
const [isLoadingLatestBeeRelease, setLoading] = useState<boolean>(false) const [isLoadingLatestBeeRelease, setLoading] = useState<boolean>(false)
+1 -15
View File
@@ -8,7 +8,7 @@ import { History } from '../../components/History'
import { Context, defaultUploadOrigin } from '../../providers/File' import { Context, defaultUploadOrigin } from '../../providers/File'
import { Context as SettingsContext } from '../../providers/Settings' import { Context as SettingsContext } from '../../providers/Settings'
import { ROUTES } from '../../routes' import { ROUTES } from '../../routes'
import { extractSwarmHash } from '../../utils' import { recognizeSwarmHash } from '../../utils'
import { determineHistoryName, HISTORY_KEYS, putHistory } from '../../utils/local-storage' import { determineHistoryName, HISTORY_KEYS, putHistory } from '../../utils/local-storage'
import { FileNavigation } from './FileNavigation' import { FileNavigation } from './FileNavigation'
@@ -71,20 +71,6 @@ export function Download(): ReactElement {
} }
} }
function recognizeSwarmHash(value: string) {
if (value.length < 64) {
return value
}
const hash = extractSwarmHash(value)
if (hash) {
return hash
}
return value
}
return ( return (
<> <>
<FileNavigation active="DOWNLOAD" /> <FileNavigation active="DOWNLOAD" />
+3 -3
View File
@@ -71,7 +71,7 @@ export function Upload(): ReactElement {
return return
} }
let fls = files.map(packageFile) // Apart from packaging, this is needed to not modify the original files array as it can trigger effects let fls: FilePath[] = files.map(f => packageFile(f)) // Apart from packaging, this is needed to not modify the original files array as it can trigger effects
let indexDocument: string | undefined = undefined // This means we assume it's folder let indexDocument: string | undefined = undefined // This means we assume it's folder
if (files.length === 1) indexDocument = files[0].name if (files.length === 1) indexDocument = files[0].name
@@ -84,10 +84,10 @@ export function Upload(): ReactElement {
if (idx.commonPrefix) { if (idx.commonPrefix) {
const substrStart = idx.commonPrefix.length const substrStart = idx.commonPrefix.length
indexDocument = idx.indexPath.substr(substrStart) indexDocument = idx.indexPath.substr(substrStart)
fls = fls.map(f => { fls = files.map(f => {
const path = (f.path as string).substr(substrStart) const path = (f.path as string).substr(substrStart)
return { ...f, path, webkitRelativePath: path, fullPath: path } return packageFile(f, path)
}) })
} else { } else {
// The website is not packed in a directory // The website is not packed in a directory
+28 -2
View File
@@ -1,10 +1,36 @@
import CircularProgress from '@material-ui/core/CircularProgress'
import { ReactElement, useContext } from 'react' import { ReactElement, useContext } from 'react'
import ExpandableList from '../../components/ExpandableList' import ExpandableList from '../../components/ExpandableList'
import ExpandableListItemInput from '../../components/ExpandableListItemInput' import ExpandableListItemInput from '../../components/ExpandableListItemInput'
import { Context as SettingsContext } from '../../providers/Settings' import { Context as SettingsContext } from '../../providers/Settings'
export default function Settings(): ReactElement { export default function SettingsPage(): ReactElement {
const { apiUrl, apiDebugUrl, setApiUrl, setDebugApiUrl, lockedApiSettings } = useContext(SettingsContext) const { apiUrl, apiDebugUrl, setApiUrl, setDebugApiUrl, lockedApiSettings, config, isLoading } =
useContext(SettingsContext)
if (isLoading) {
return (
<div style={{ textAlign: 'center', width: '100%' }}>
<CircularProgress />
</div>
)
}
// Run within Bee Desktop, display read only config
if (config) {
return (
<ExpandableList label="Bee Desktop Settings" defaultOpen>
<ExpandableListItemInput label="Bee API" value={config['api-addr']} locked />
<ExpandableListItemInput label="Bee Debug API" value={config['debug-api-addr']} locked />
<ExpandableListItemInput label="CORS" value={config['cors-allowed-origins']} locked />
<ExpandableListItemInput label="Data DIR" value={config['data-dir']} locked />
<ExpandableListItemInput label="ENS resolver URL" value={config['resolver-options']} locked />
{config['swap-endpoint'] && (
<ExpandableListItemInput label="SWAP endpoint" value={config['swap-endpoint']} locked />
)}
</ExpandableList>
)
}
return ( return (
<ExpandableList label="API Settings" defaultOpen> <ExpandableList label="API Settings" defaultOpen>
+4 -1
View File
@@ -9,10 +9,13 @@ interface Props {
} }
export function PostageStamp({ stamp, shorten }: Props): ReactElement { export function PostageStamp({ stamp, shorten }: Props): ReactElement {
const batchId = shorten ? stamp.batchID.slice(0, 8) : stamp.batchID
const label = `${batchId}${stamp.label ? ` - ${stamp.label}` : ''}`
return ( return (
<Box p={2} width="100%"> <Box p={2} width="100%">
<Grid container justifyContent="space-between" alignItems="center" direction="row"> <Grid container justifyContent="space-between" alignItems="center" direction="row">
<Typography variant="subtitle2">{shorten ? stamp.batchID.slice(0, 8) : stamp.batchID}</Typography> <Typography variant="subtitle2">{label}</Typography>
<Capacity width="100px" usage={stamp.usage} /> <Capacity width="100px" usage={stamp.usage} />
</Grid> </Grid>
</Box> </Box>
+22 -10
View File
@@ -9,7 +9,13 @@ import { SwarmTextInput } from '../../components/SwarmTextInput'
import { Context as BeeContext } from '../../providers/Bee' import { Context as BeeContext } from '../../providers/Bee'
import { Context as SettingsContext } from '../../providers/Settings' import { Context as SettingsContext } from '../../providers/Settings'
import { Context as StampsContext } from '../../providers/Stamps' import { Context as StampsContext } from '../../providers/Stamps'
import { calculateStampPrice, convertAmountToSeconds, convertDepthToBytes, secondsToTimeString } from '../../utils' import {
calculateStampPrice,
convertAmountToSeconds,
convertDepthToBytes,
secondsToTimeString,
waitUntilStampUsable,
} from '../../utils'
import { getHumanReadableFileSize } from '../../utils/file' import { getHumanReadableFileSize } from '../../utils/file'
interface FormValues { interface FormValues {
@@ -52,7 +58,9 @@ export function PostageStampCreation({ onFinished }: Props): ReactElement {
const pricePerBlock = Number.parseInt(chainState.currentPrice, 10) const pricePerBlock = Number.parseInt(chainState.currentPrice, 10)
return `${secondsToTimeString(convertAmountToSeconds(amount, pricePerBlock))} (with price of 0 per block)` return `${secondsToTimeString(
convertAmountToSeconds(amount, pricePerBlock),
)} (with price of ${pricePerBlock.toFixed(0)} per block)`
} }
function getPrice(depth: number, amount: bigint): string { function getPrice(depth: number, amount: bigint): string {
@@ -80,7 +88,8 @@ export function PostageStampCreation({ onFinished }: Props): ReactElement {
const amount = BigInt(values.amount) const amount = BigInt(values.amount)
const depth = Number.parseInt(values.depth) const depth = Number.parseInt(values.depth)
const options = values.label ? { label: values.label } : undefined const options = values.label ? { label: values.label } : undefined
await beeDebugApi.createPostageBatch(amount.toString(), depth, options) const batch = await beeDebugApi.createPostageBatch(amount.toString(), depth, options)
await waitUntilStampUsable(batch, beeDebugApi)
actions.resetForm() actions.resetForm()
await refresh() await refresh()
onFinished() onFinished()
@@ -111,20 +120,17 @@ export function PostageStampCreation({ onFinished }: Props): ReactElement {
else if (amount.isLessThanOrEqualTo(0)) errors.amount = 'Amount must be greater than 0' else if (amount.isLessThanOrEqualTo(0)) errors.amount = 'Amount must be greater than 0'
} }
// Label
if (values.label && !/^[0-9a-z]*$/i.test(values.label)) errors.label = 'Label must be an alphanumeric string'
return errors return errors
}} }}
> >
{({ submitForm, isValid, isSubmitting, values }) => ( {({ submitForm, isValid, isSubmitting, values, errors }) => (
<Form> <Form>
<Box mb={2}> <Box mb={2}>
<SwarmTextInput name="depth" label="Depth" formik /> <SwarmTextInput name="depth" label="Depth" formik />
<Box mt={0.25} sx={{ bgcolor: '#f6f6f6' }} p={2}> <Box mt={0.25} sx={{ bgcolor: '#f6f6f6' }} p={2}>
<Grid container justifyContent="space-between"> <Grid container justifyContent="space-between">
<Typography>Corresponding file size</Typography> <Typography>Corresponding file size</Typography>
<Typography>{getFileSize(parseInt(values.depth || '0', 10))}</Typography> <Typography>{!errors.depth && values.depth ? getFileSize(parseInt(values.depth, 10)) : '-'}</Typography>
</Grid> </Grid>
</Box> </Box>
</Box> </Box>
@@ -133,7 +139,9 @@ export function PostageStampCreation({ onFinished }: Props): ReactElement {
<Box mt={0.25} sx={{ bgcolor: '#f6f6f6' }} p={2}> <Box mt={0.25} sx={{ bgcolor: '#f6f6f6' }} p={2}>
<Grid container justifyContent="space-between"> <Grid container justifyContent="space-between">
<Typography>Corresponding TTL (Time to live)</Typography> <Typography>Corresponding TTL (Time to live)</Typography>
<Typography>{getTtl(Number.parseInt(values.amount || '0', 10))}</Typography> <Typography>
{!errors.amount && values.amount ? getTtl(Number.parseInt(values.amount, 10)) : '-'}
</Typography>
</Grid> </Grid>
</Box> </Box>
</Box> </Box>
@@ -143,7 +151,11 @@ export function PostageStampCreation({ onFinished }: Props): ReactElement {
<Box mb={4} sx={{ bgcolor: '#fcf2e8' }} p={2}> <Box mb={4} sx={{ bgcolor: '#fcf2e8' }} p={2}>
<Grid container justifyContent="space-between"> <Grid container justifyContent="space-between">
<Typography>Indicative Price</Typography> <Typography>Indicative Price</Typography>
<Typography>{getPrice(parseInt(values.depth || '0', 10), BigInt(values.amount || '0'))}</Typography> <Typography>
{!errors.amount && !errors.depth && values.amount && values.depth
? getPrice(parseInt(values.depth, 10), BigInt(values.amount))
: '-'}
</Typography>
</Grid> </Grid>
</Box> </Box>
<SwarmButton <SwarmButton
+9
View File
@@ -4,6 +4,7 @@ import ExpandableList from '../../components/ExpandableList'
import ExpandableListItem from '../../components/ExpandableListItem' import ExpandableListItem from '../../components/ExpandableListItem'
import ExpandableListItemKey from '../../components/ExpandableListItemKey' import ExpandableListItemKey from '../../components/ExpandableListItemKey'
import { EnrichedPostageBatch } from '../../providers/Stamps' import { EnrichedPostageBatch } from '../../providers/Stamps'
import { secondsToTimeString } from '../../utils'
import { getHumanReadableFileSize } from '../../utils/file' import { getHumanReadableFileSize } from '../../utils/file'
import { PostageStamp } from './PostageStamp' import { PostageStamp } from './PostageStamp'
@@ -30,6 +31,14 @@ function StampsTable({ postageStamps }: Props): ReactElement | null {
)}`} )}`}
/> />
<ExpandableListItem label="Amount" value={parseInt(stamp.amount, 10).toLocaleString()} /> <ExpandableListItem label="Amount" value={parseInt(stamp.amount, 10).toLocaleString()} />
<ExpandableListItem
label="Expires in"
value={stamp.batchTTL === -1 ? 'does not expire' : `${secondsToTimeString(stamp.batchTTL)}`}
/>
<ExpandableListItem label="Label" value={stamp.label} />
<ExpandableListItem label="Usable" value={stamp.usable ? 'yes' : 'no'} />
<ExpandableListItem label="Exists" value={stamp.exists ? 'yes' : 'no'} />
<ExpandableListItem label="Purchase Block Number" value={stamp.blockNumber} />
</> </>
} }
> >
+34 -1
View File
@@ -1,4 +1,5 @@
import { import {
BeeModes,
ChainState, ChainState,
ChequebookAddressResponse, ChequebookAddressResponse,
Health, Health,
@@ -7,7 +8,6 @@ import {
NodeInfo, NodeInfo,
Peer, Peer,
Topology, Topology,
BeeModes,
} from '@ethersphere/bee-js' } from '@ethersphere/bee-js'
import { createContext, ReactChild, ReactElement, useContext, useEffect, useState } from 'react' import { createContext, ReactChild, ReactElement, useContext, useEffect, useState } from 'react'
import semver from 'semver' import semver from 'semver'
@@ -15,8 +15,14 @@ import { engines } from '../../package.json'
import { useLatestBeeRelease } from '../hooks/apiHooks' import { useLatestBeeRelease } from '../hooks/apiHooks'
import { Token } from '../models/Token' import { Token } from '../models/Token'
import type { Balance, ChequebookBalance, Settlements } from '../types' import type { Balance, ChequebookBalance, Settlements } from '../types'
import { Rpc } from '../utils/rpc'
import { Context as SettingsContext } from './Settings' import { Context as SettingsContext } from './Settings'
interface RpcBalance {
bzz: Token
xdai: Token
}
export enum CheckState { export enum CheckState {
OK = 'OK', OK = 'OK',
WARNING = 'Warning', WARNING = 'Warning',
@@ -40,6 +46,7 @@ interface Status {
interface ContextInterface { interface ContextInterface {
status: Status status: Status
balance: RpcBalance
latestPublishedVersion?: string latestPublishedVersion?: string
latestUserVersion?: string latestUserVersion?: string
latestUserVersionExact?: string latestUserVersionExact?: string
@@ -77,6 +84,10 @@ const initialValues: ContextInterface = {
topology: { isEnabled: false, checkState: CheckState.ERROR }, topology: { isEnabled: false, checkState: CheckState.ERROR },
chequebook: { isEnabled: false, checkState: CheckState.ERROR }, chequebook: { isEnabled: false, checkState: CheckState.ERROR },
}, },
balance: {
bzz: new Token('0', 16),
xdai: new Token('0', 18),
},
latestPublishedVersion: undefined, latestPublishedVersion: undefined,
latestUserVersion: undefined, latestUserVersion: undefined,
latestUserVersionExact: undefined, latestUserVersionExact: undefined,
@@ -193,6 +204,8 @@ export function Provider({ children }: Props): ReactElement {
const [peerCheques, setPeerCheques] = useState<LastChequesResponse | null>(null) const [peerCheques, setPeerCheques] = useState<LastChequesResponse | null>(null)
const [settlements, setSettlements] = useState<Settlements | null>(null) const [settlements, setSettlements] = useState<Settlements | null>(null)
const [chainState, setChainState] = useState<ChainState | null>(null) const [chainState, setChainState] = useState<ChainState | null>(null)
const [bzz, setBzz] = useState<Token>(initialValues.balance.bzz)
const [xdai, setXdai] = useState<Token>(initialValues.balance.xdai)
const { latestBeeRelease } = useLatestBeeRelease() const { latestBeeRelease } = useLatestBeeRelease()
@@ -232,6 +245,22 @@ export function Provider({ children }: Props): ReactElement {
refresh() refresh()
}, [beeDebugApi]) // eslint-disable-line react-hooks/exhaustive-deps }, [beeDebugApi]) // eslint-disable-line react-hooks/exhaustive-deps
useEffect(() => {
if (nodeAddresses?.ethereum) {
// debounced calls
const xdai = Rpc.eth_getBalance(nodeAddresses.ethereum)
const bzz = Rpc.eth_getBalanceERC20(nodeAddresses.ethereum)
if (xdai?.then) {
xdai.then(balance => setXdai(new Token(balance, 18)))
}
if (bzz?.then) {
bzz.then(balance => setBzz(new Token(balance, 16)))
}
}
}, [nodeAddresses])
const refresh = async () => { const refresh = async () => {
// Don't want to refresh when already refreshing // Don't want to refresh when already refreshing
if (isRefreshing) return if (isRefreshing) return
@@ -388,6 +417,10 @@ export function Provider({ children }: Props): ReactElement {
chequebookBalance, chequebookBalance,
error, error,
), ),
balance: {
xdai,
bzz,
},
latestUserVersion, latestUserVersion,
latestUserVersionExact, latestUserVersionExact,
latestPublishedVersion, latestPublishedVersion,
+28 -2
View File
@@ -1,6 +1,7 @@
import { Bee, BeeDebug } from '@ethersphere/bee-js' import { Bee, BeeDebug } from '@ethersphere/bee-js'
import { createContext, ReactChild, ReactElement, useEffect, useState } from 'react' import { createContext, ReactChild, ReactElement, useEffect, useState } from 'react'
import { config } from '../config' import { config } from '../config'
import { BeeConfig, useGetBeeConfig } from '../hooks/apiHooks'
interface ContextInterface { interface ContextInterface {
apiUrl: string apiUrl: string
@@ -10,6 +11,10 @@ interface ContextInterface {
setApiUrl: (url: string) => void setApiUrl: (url: string) => void
setDebugApiUrl: (url: string) => void setDebugApiUrl: (url: string) => void
lockedApiSettings: boolean lockedApiSettings: boolean
desktopApiKey: string
config: BeeConfig | null
isLoading: boolean
error: Error | null
} }
const initialValues: ContextInterface = { const initialValues: ContextInterface = {
@@ -20,6 +25,10 @@ const initialValues: ContextInterface = {
setApiUrl: () => {}, // eslint-disable-line setApiUrl: () => {}, // eslint-disable-line
setDebugApiUrl: () => {}, // eslint-disable-line setDebugApiUrl: () => {}, // eslint-disable-line
lockedApiSettings: false, lockedApiSettings: false,
desktopApiKey: '',
config: null,
isLoading: true,
error: null,
} }
export const Context = createContext<ContextInterface>(initialValues) export const Context = createContext<ContextInterface>(initialValues)
@@ -43,9 +52,22 @@ export function Provider({
const [beeApi, setBeeApi] = useState<Bee | null>(null) const [beeApi, setBeeApi] = useState<Bee | null>(null)
const [beeDebugApi, setBeeDebugApi] = useState<BeeDebug | null>(null) const [beeDebugApi, setBeeDebugApi] = useState<BeeDebug | null>(null)
const [lockedApiSettings] = useState<boolean>(Boolean(extLockedApiSettings)) const [lockedApiSettings] = useState<boolean>(Boolean(extLockedApiSettings))
const [desktopApiKey, setDesktopApiKey] = useState<string>(initialValues.desktopApiKey)
const { config, isLoading, error } = useGetBeeConfig()
const url = beeApiUrl || apiUrl const url = config?.['api-addr'] || beeApiUrl || apiUrl
const debugUrl = beeDebugApiUrl || apiDebugUrl const debugUrl = config?.['debug-api-addr'] || beeDebugApiUrl || apiDebugUrl
useEffect(() => {
const urlSearchParams = new URLSearchParams(window.location.search)
const newApiKey = urlSearchParams.get('v')
if (newApiKey) {
localStorage.setItem('apiKey', newApiKey)
window.location.search = ''
setDesktopApiKey(newApiKey)
}
}, [])
useEffect(() => { useEffect(() => {
try { try {
@@ -75,6 +97,10 @@ export function Provider({
setApiUrl, setApiUrl,
setDebugApiUrl, setDebugApiUrl,
lockedApiSettings, lockedApiSettings,
desktopApiKey,
config,
isLoading,
error,
}} }}
> >
{children} {children}
+5
View File
@@ -0,0 +1,5 @@
import axios from 'axios'
export async function requestBzz(address: string): Promise<void> {
await axios.post(`https://xbzz-faucet.apyos.dev/xbzz/${address}`)
}
+39
View File
@@ -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
}
+2 -2
View File
@@ -87,8 +87,8 @@ export function getPath(file: FilePath): string {
/** /**
* Utility function that is needed to have correct directory structure as webkitRelativePath is read only * Utility function that is needed to have correct directory structure as webkitRelativePath is read only
*/ */
export function packageFile(file: FilePath): FilePath { export function packageFile(file: FilePath, pathOverwrite?: string): FilePath {
const path = getPath(file) const path = pathOverwrite || getPath(file)
return { return {
path: path, path: path,
+138
View File
@@ -0,0 +1,138 @@
import { extractSwarmHash, extractSwarmCid, recognizeSwarmHash } from './index'
interface TestObject {
input: string
expectedOutput: string | undefined
}
const correctHashes: TestObject[] = [
// non-encrypted
{
input: 'b7e53783114e4555384d7fd7154eb8c2e3f7c749c176dcb8f4015b08161b3d3f',
expectedOutput: 'b7e53783114e4555384d7fd7154eb8c2e3f7c749c176dcb8f4015b08161b3d3f',
},
{
input: 'http://gateway.org/bzz/b7e53783114e4555384d7fd7154eb8c2e3f7c749c176dcb8f4015b08161b3d3f',
expectedOutput: 'b7e53783114e4555384d7fd7154eb8c2e3f7c749c176dcb8f4015b08161b3d3f',
},
{
input: 'https://gateway.org/b7e53783114e4555384d7fd7154eb8c2e3f7c749c176dcb8f4015b08161b3d3f',
expectedOutput: 'b7e53783114e4555384d7fd7154eb8c2e3f7c749c176dcb8f4015b08161b3d3f',
},
{
input: 'http://gateway.org/bzz/b7e53783114e4555384d7fd7154eb8c2e3f7c749c176dcb8f4015b08161b3d3f/',
expectedOutput: 'b7e53783114e4555384d7fd7154eb8c2e3f7c749c176dcb8f4015b08161b3d3f',
},
{
input: 'https://gateway.org/b7e53783114e4555384d7fd7154eb8c2e3f7c749c176dcb8f4015b08161b3d3f/',
expectedOutput: 'b7e53783114e4555384d7fd7154eb8c2e3f7c749c176dcb8f4015b08161b3d3f',
},
// encrypted
{
input:
'b7e53783114e4555384d7fd7154eb8c2e3f7c749c176dcb8f4015b08161b3d3fb7e53783114e4555384d7fd7154eb8c2e3f7c749c176dcb8f4015b08161b3d3f',
expectedOutput:
'b7e53783114e4555384d7fd7154eb8c2e3f7c749c176dcb8f4015b08161b3d3fb7e53783114e4555384d7fd7154eb8c2e3f7c749c176dcb8f4015b08161b3d3f',
},
{
input:
'http://gateway.org/bzz/b7e53783114e4555384d7fd7154eb8c2e3f7c749c176dcb8f4015b08161b3d3fb7e53783114e4555384d7fd7154eb8c2e3f7c749c176dcb8f4015b08161b3d3f',
expectedOutput:
'b7e53783114e4555384d7fd7154eb8c2e3f7c749c176dcb8f4015b08161b3d3fb7e53783114e4555384d7fd7154eb8c2e3f7c749c176dcb8f4015b08161b3d3f',
},
{
input:
'https://gateway.org/b7e53783114e4555384d7fd7154eb8c2e3f7c749c176dcb8f4015b08161b3d3fb7e53783114e4555384d7fd7154eb8c2e3f7c749c176dcb8f4015b08161b3d3f',
expectedOutput:
'b7e53783114e4555384d7fd7154eb8c2e3f7c749c176dcb8f4015b08161b3d3fb7e53783114e4555384d7fd7154eb8c2e3f7c749c176dcb8f4015b08161b3d3f',
},
{
input:
'http://gateway.org/bzz/b7e53783114e4555384d7fd7154eb8c2e3f7c749c176dcb8f4015b08161b3d3fb7e53783114e4555384d7fd7154eb8c2e3f7c749c176dcb8f4015b08161b3d3f/',
expectedOutput:
'b7e53783114e4555384d7fd7154eb8c2e3f7c749c176dcb8f4015b08161b3d3fb7e53783114e4555384d7fd7154eb8c2e3f7c749c176dcb8f4015b08161b3d3f',
},
{
input:
'https://gateway.org/b7e53783114e4555384d7fd7154eb8c2e3f7c749c176dcb8f4015b08161b3d3fb7e53783114e4555384d7fd7154eb8c2e3f7c749c176dcb8f4015b08161b3d3f/',
expectedOutput:
'b7e53783114e4555384d7fd7154eb8c2e3f7c749c176dcb8f4015b08161b3d3fb7e53783114e4555384d7fd7154eb8c2e3f7c749c176dcb8f4015b08161b3d3f',
},
]
const wrongHashes: string[] = [
// one character too long
'b7e53783114e4555384d7fd7154eb8c2e3f7c749c176dcb8f4015b08161b3d3fa',
'http://gateway.org/bzz/b7e53783114e4555384d7fd7154eb8c2e3f7c749c176dcb8f4015b08161b3d3fa',
'https://gateway.org/b7e53783114e4555384d7fd7154eb8c2e3f7c749c176dcb8f4015b08161b3d3fa',
'http://gateway.org/bzz/b7e53783114e4555384d7fd7154eb8c2e3f7c749c176dcb8f4015b08161b3d3fa/',
'https://gateway.org/b7e53783114e4555384d7fd7154eb8c2e3f7c749c176dcb8f4015b08161b3d3fa/',
// a bit shorter
'b7e53783114e4555384d7fd7154eb8c2e3f7c749c176dcb8f4015b08161b3d',
]
describe('extractSwarmHash', () => {
test('should correctly extract hash', () => {
correctHashes.forEach(({ input, expectedOutput }) => {
const hash = extractSwarmHash(input)
expect(hash).toBe(expectedOutput)
})
})
test('should not extract hash from incorrect inputs', () => {
wrongHashes.forEach(input => {
const hash = extractSwarmHash(input)
expect(hash).toBe(undefined)
})
})
})
const correctCids: TestObject[] = [
{
input: 'https://bah5acgza5afd34lfvo7sowxfjahj4ujeduxgg2ge5u3zo4kcjlzjzi23fhka.bzz.link',
expectedOutput: 'e80a3df165abbf275ae5480e9e51241d2e6368c4ed379771424af29ca35b29d4',
},
{
input: 'https://bah5acgza2lzgtqfztvn3xtnzhv7qvbmblljd7bi52l5jiueretcad55vookq.bzz.link',
expectedOutput: 'd2f269c0b99d5bbbcdb93d7f0a85815ad23f851dd2fa94509124c401f7b57395',
},
]
const wrongCids: string[] = [
'https://bah5acgza5afd34lfvo7sowxfjahj4ujeduxgg2ge5u3zo4kcjlzjzi23fhka.another.domain',
'http://bah5acgza2lzgtqfztvn3xtnzhv7qvbmblljd7bi52l5jiueretcad55vookq.bzz.link',
'https://not_cid.bzz.link',
'https://bah5acgza5afd34lfvo7sowxfjahj4ujeduxgg2ge5u3zo4kcjlzjzi23fhka.subdomain.bzz.link',
'https://bah5acgza5afd34lfvo7sowxfjahj4ujeduxgg2ge5u3zo4kcjlzjzi23fhka.subdomain.bzz.link',
'https://bah5acgza2lzgtqfztvn3xtnzhv7qvbmblljd7bi52l5jiueretcad55vook.bzz.link',
'https://aah5acgza2lzgtqfztvn3xtnzhv7qvbmblljd7bi52l5jiueretcad55vookq.bzz.link',
]
describe('extractSwarmCid', () => {
test('should correctly extract hash', () => {
correctCids.forEach(({ input, expectedOutput }) => {
const hash = extractSwarmCid(input)
expect(hash).toBe(expectedOutput)
})
})
test('should not extract cid from incorrect urls', () => {
wrongCids.forEach(url => {
const hash = extractSwarmCid(url)
expect(hash).toBe(undefined)
})
})
})
describe('recognizeSwarmHash', () => {
test('should correctly extract hash', () => {
;[...correctHashes, ...correctCids].forEach(({ input, expectedOutput }) => {
const hash = recognizeSwarmHash(input)
expect(hash).toBe(expectedOutput)
})
})
test('should not extract hash from incorrect inputs but instead return them', () => {
;[...wrongHashes, ...wrongCids].forEach(url => {
const hash = recognizeSwarmHash(url)
expect(hash).toBe(url)
})
})
})
+63 -3
View File
@@ -1,5 +1,8 @@
import { BigNumber } from 'bignumber.js' import { BigNumber } from 'bignumber.js'
import { Token } from '../models/Token' import { Token } from '../models/Token'
import { decodeCid } from '@ethersphere/swarm-cid'
import { BZZ_LINK_DOMAIN } from '../constants'
import { BatchId, BeeDebug, PostageBatch } from '@ethersphere/bee-js'
/** /**
* Test if value is an integer * Test if value is an integer
@@ -108,10 +111,41 @@ export function makeRetriablePromise<T>(fn: () => Promise<T>, maxRetries = 3, de
}) })
} }
export function extractSwarmHash(string: string): string | null { // Matches exactly 64 or 128 caracters alphanumeric characters that are surrounded by non-alpha num characters
const matches = string.match(/[a-fA-F0-9]{64,128}/) const regexpMatchHash = /(?:^|[^a-f0-9]+)([a-f0-9]{64}|[a-f0-9]{128})(?:$|[^a-f0-9]+)/i
return (matches && matches[0]) || null export function extractSwarmHash(string: string): string | undefined {
const matches = string.match(regexpMatchHash)
return (matches && matches[1]) || undefined
}
// Matches the CID from bzz-link subdomain
const regexpMatchCID = new RegExp(`https://(bah5acgza[a-z0-9]{52})\\.${BZZ_LINK_DOMAIN}`, 'i')
export function extractSwarmCid(s: string): string | undefined {
const matches = s.match(regexpMatchCID)
if (!matches || !matches[1]) {
return
}
const cid = matches[1]
try {
const decodeResult = decodeCid(cid)
if (!decodeResult.type) {
return
}
return decodeResult.reference
} catch (e) {
return
}
}
export function recognizeSwarmHash(value: string): string {
return extractSwarmHash(value) || extractSwarmCid(value) || value
} }
export function uuidV4(): string { export function uuidV4(): string {
@@ -183,3 +217,29 @@ export function shortenText(text: string, length = 20, separator = '[…]'): str
return `${text.slice(0, length)}${separator}${text.slice(-length)}` return `${text.slice(0, length)}${separator}${text.slice(-length)}`
} }
const DEFAULT_POLLING_FREQUENCY = 1_000
const DEFAULT_STAMP_USABLE_TIMEOUT = 120_000
interface Options {
pollingFrequency?: number
timeout?: number
}
export async function waitUntilStampUsable(
batchId: BatchId,
beeDebug: BeeDebug,
options?: Options,
): Promise<PostageBatch> {
const timeout = options?.timeout || DEFAULT_STAMP_USABLE_TIMEOUT
const pollingFrequency = options?.pollingFrequency || DEFAULT_POLLING_FREQUENCY
for (let i = 0; i < timeout; i += pollingFrequency) {
const stamp = await beeDebug.getPostageBatch(batchId)
if (stamp.usable) return stamp
await sleepMs(pollingFrequency)
}
throw new Error('Wait until stamp usable timeout has been reached')
}
+33
View File
@@ -0,0 +1,33 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import axios from 'axios'
export function getJson<T extends Record<string, any>>(url: string): Promise<T> {
return sendRequest(url, 'GET') as Promise<T>
}
export function postJson(url: string, data?: Record<string, any>): Promise<Record<string, unknown>> {
return sendRequest(url, 'POST', data)
}
async function sendRequest(
url: string,
method: 'GET' | 'POST',
data?: Record<string, unknown>,
): Promise<Record<string, any>> {
const authorization = localStorage.getItem('apiKey')
if (!authorization) {
throw Error('API key not found in local storage')
}
const headers = {
authorization,
}
const response = await axios(url, {
method,
headers,
data,
})
return response.data
}
+66
View File
@@ -0,0 +1,66 @@
import { debounce } from '@material-ui/core'
import axios from 'axios'
import { Contract, providers } from 'ethers'
const PROVIDER = 'https://gno.getblock.io/mainnet/?api_key=d7b92d96-9784-49a8-a800-b3edd1647fc7'
async function eth_getBalance(address: string): Promise<string> {
if (!address.startsWith('0x')) {
address = `0x${address}`
}
const response = await axios(PROVIDER, {
method: 'POST',
headers: {
'content-type': 'application/json',
},
data: {
jsonrpc: '2.0',
method: 'eth_getBalance',
params: [address, 'latest'],
id: 1,
},
})
return response.data.result
}
const partialERC20tokenABI = [
{
constant: true,
inputs: [
{
name: '_owner',
type: 'address',
},
],
name: 'balanceOf',
outputs: [
{
name: 'balance',
type: 'uint256',
},
],
payable: false,
type: 'function',
},
]
const provider = new providers.JsonRpcProvider(PROVIDER)
async function eth_getBalanceERC20(
address: string,
tokenAddress = '0xdbf3ea6f5bee45c02255b2c26a16f300502f68da',
): Promise<string> {
if (!address.startsWith('0x')) {
address = `0x${address}`
}
const contract = new Contract(tokenAddress, partialERC20tokenABI, provider)
const balance = await contract.balanceOf(address)
return balance.toString()
}
export const Rpc = {
eth_getBalance: debounce(eth_getBalance, 1_000),
eth_getBalanceERC20: debounce(eth_getBalanceERC20, 1_000),
}
+3 -3
View File
@@ -1,6 +1,6 @@
const OPTIMAL_CONNECTED_PEERS = 200 const OPTIMAL_CONNECTED_PEERS = 100
const OPTIMAL_POPULATION = 100000 const OPTIMAL_POPULATION = 1000
const OPTIMAL_DEPTH = 12 const OPTIMAL_DEPTH = 4
interface Threshold { interface Threshold {
minimumValue: number minimumValue: number