feat: add wallet endpoint and display blockchain name (#492)

This commit is contained in:
Vojtech Simetka
2022-07-26 10:18:27 +02:00
committed by GitHub
parent 186d0352cf
commit fd11f0166d
3 changed files with 44 additions and 0 deletions
+3
View File
@@ -14,6 +14,7 @@ import { useIsBeeDesktop, useNewBeeDesktopVersion } from '../../hooks/apiHooks'
import { BEE_DESKTOP_LATEST_RELEASE_PAGE } from '../../utils/desktop' import { BEE_DESKTOP_LATEST_RELEASE_PAGE } from '../../utils/desktop'
import config from '../../config' import config from '../../config'
import NodeInfoCard from './NodeInfoCard' import NodeInfoCard from './NodeInfoCard'
import { chainIdToName } from '../../utils/chain'
export default function Status(): ReactElement { export default function Status(): ReactElement {
const { const {
@@ -25,6 +26,7 @@ export default function Status(): ReactElement {
nodeInfo, nodeInfo,
balance, balance,
chequebookBalance, chequebookBalance,
wallet,
} = useContext(BeeContext) } = useContext(BeeContext)
const isBeeDesktop = config.BEE_DESKTOP_ENABLED const isBeeDesktop = config.BEE_DESKTOP_ENABLED
const { beeDesktopVersion } = useIsBeeDesktop() const { beeDesktopVersion } = useIsBeeDesktop()
@@ -147,6 +149,7 @@ export default function Status(): ReactElement {
} }
/> />
<ExpandableListItem label="Mode" value={nodeInfo?.beeMode} /> <ExpandableListItem label="Mode" value={nodeInfo?.beeMode} />
{wallet && <ExpandableListItem label="Blockchain network" value={chainIdToName(wallet.chainID)} />}
</div> </div>
) )
} }
+11
View File
@@ -8,6 +8,7 @@ import {
NodeInfo, NodeInfo,
Peer, Peer,
Topology, Topology,
WalletBalance,
} 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'
@@ -65,6 +66,7 @@ interface ContextInterface {
peerCheques: LastChequesResponse | null peerCheques: LastChequesResponse | null
settlements: Settlements | null settlements: Settlements | null
chainState: ChainState | null chainState: ChainState | null
wallet: WalletBalance | null
latestBeeRelease: LatestBeeRelease | null latestBeeRelease: LatestBeeRelease | null
isLoading: boolean isLoading: boolean
lastUpdate: number | null lastUpdate: number | null
@@ -102,6 +104,7 @@ const initialValues: ContextInterface = {
peerCheques: null, peerCheques: null,
settlements: null, settlements: null,
chainState: null, chainState: null,
wallet: null,
latestBeeRelease: null, latestBeeRelease: null,
isLoading: true, isLoading: true,
lastUpdate: null, lastUpdate: null,
@@ -204,6 +207,7 @@ export function Provider({ children }: Props): ReactElement {
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 [walletAddress, setWalletAddress] = useState<WalletAddress | null>(initialValues.balance) const [walletAddress, setWalletAddress] = useState<WalletAddress | null>(initialValues.balance)
const [wallet, setWallet] = useState<WalletBalance | null>(null)
const { latestBeeRelease } = useLatestBeeRelease() const { latestBeeRelease } = useLatestBeeRelease()
@@ -356,6 +360,12 @@ export function Provider({ children }: Props): ReactElement {
.then(setChainState) .then(setChainState)
.catch(() => setChainState(null)), .catch(() => setChainState(null)),
// Wallet
beeDebugApi
.getWalletBalance({ timeout: TIMEOUT })
.then(setWallet)
.catch(() => setWallet(null)),
// Chequebook balance // Chequebook balance
chequeBalanceWrapper() chequeBalanceWrapper()
.then(setChequebookBalance) .then(setChequebookBalance)
@@ -446,6 +456,7 @@ export function Provider({ children }: Props): ReactElement {
peerCheques, peerCheques,
settlements, settlements,
chainState, chainState,
wallet,
latestBeeRelease, latestBeeRelease,
isLoading, isLoading,
lastUpdate, lastUpdate,
+30
View File
@@ -0,0 +1,30 @@
const chains = [
{
name: 'Ethereum Mainnet',
chainId: 1,
},
{
name: 'Ropsten Testnet',
chainId: 3,
},
{
name: 'Rinkeby Testnet',
chainId: 4,
},
{
name: 'Görli Testnet',
chainId: 5,
},
{
name: 'Kovan Testnet',
chainId: 42,
},
{
name: 'Gnosis Chain',
chainId: 100,
},
]
export function chainIdToName(chainId: number): string {
return chains.find(record => record.chainId === chainId)?.name || 'Unknown'
}