feat: add loading state to wallet balance (#508)
* feat: add loading state to wallet balance * refactor: extract the wallet balance into a provider
This commit is contained in:
@@ -13,13 +13,15 @@ import { SwarmButton } from '../../../components/SwarmButton'
|
||||
import TroubleshootConnectionCard from '../../../components/TroubleshootConnectionCard'
|
||||
import { CheckState, Context as BeeContext } from '../../../providers/Bee'
|
||||
import { Context as SettingsContext } from '../../../providers/Settings'
|
||||
import { Context as BalanceProvider } from '../../../providers/WalletBalance'
|
||||
import { ROUTES } from '../../../routes'
|
||||
import { AccountNavigation } from '../AccountNavigation'
|
||||
import { Header } from '../Header'
|
||||
|
||||
export function AccountWallet(): ReactElement {
|
||||
const { balance, nodeAddresses, nodeInfo, status } = useContext(BeeContext)
|
||||
const { nodeAddresses, nodeInfo, status } = useContext(BeeContext)
|
||||
const { isBeeDesktop } = useContext(SettingsContext)
|
||||
const { balance } = useContext(BalanceProvider)
|
||||
|
||||
const navigate = useNavigate()
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ import ExpandableListItemKey from '../../components/ExpandableListItemKey'
|
||||
import { HistoryHeader } from '../../components/HistoryHeader'
|
||||
import { Loading } from '../../components/Loading'
|
||||
import { SwarmButton } from '../../components/SwarmButton'
|
||||
import { Context as BeeContext } from '../../providers/Bee'
|
||||
import { Context as BalanceProvider } from '../../providers/WalletBalance'
|
||||
import { Context as TopUpContext } from '../../providers/TopUp'
|
||||
import { Context as SettingsContext } from '../../providers/Settings'
|
||||
import { createGiftWallet } from '../../utils/desktop'
|
||||
@@ -24,7 +24,7 @@ const GIFT_WALLET_FUND_BZZ_AMOUNT = Token.fromDecimal('0.5', 16)
|
||||
export default function Index(): ReactElement {
|
||||
const { giftWallets, addGiftWallet } = useContext(TopUpContext)
|
||||
const { provider } = useContext(SettingsContext)
|
||||
const { balance } = useContext(BeeContext)
|
||||
const { balance } = useContext(BalanceProvider)
|
||||
|
||||
const [loading, setLoading] = useState(false)
|
||||
const [balances, setBalances] = useState<ResolvedWallet[]>([])
|
||||
|
||||
@@ -6,6 +6,7 @@ import Upload from 'remixicon-react/UploadLineIcon'
|
||||
|
||||
import { Context as BeeContext } from '../../providers/Bee'
|
||||
import { Context as SettingsContext } from '../../providers/Settings'
|
||||
import { Context as BalanceProvider } from '../../providers/WalletBalance'
|
||||
import Card from '../../components/Card'
|
||||
import Map from '../../components/Map'
|
||||
import ExpandableListItem from '../../components/ExpandableListItem'
|
||||
@@ -24,15 +25,24 @@ export default function Status(): ReactElement {
|
||||
latestBeeVersionUrl,
|
||||
topology,
|
||||
nodeInfo,
|
||||
balance,
|
||||
chequebookBalance,
|
||||
wallet,
|
||||
chainId,
|
||||
} = useContext(BeeContext)
|
||||
const { isBeeDesktop } = useContext(SettingsContext)
|
||||
const { balance, error } = useContext(BalanceProvider)
|
||||
const { beeDesktopVersion } = useIsBeeDesktop()
|
||||
const { newBeeDesktopVersion } = useNewBeeDesktopVersion(isBeeDesktop)
|
||||
const navigate = useNavigate()
|
||||
|
||||
let balanceText = 'Loading...'
|
||||
|
||||
if (error) {
|
||||
balanceText = 'Could not load...'
|
||||
console.error(error) // eslint-disable-line
|
||||
} else if (balance) {
|
||||
balanceText = `${balance.bzz.toSignificantDigits(4)} xBZZ | ${balance.dai.toSignificantDigits(4)} xDAI`
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'stretch', alignContent: 'stretch' }}>
|
||||
@@ -46,7 +56,7 @@ export default function Status(): ReactElement {
|
||||
onClick: () => navigate(ROUTES.ACCOUNT_WALLET),
|
||||
}}
|
||||
icon={<Wallet />}
|
||||
title={`${balance?.bzz.toSignificantDigits(4)} xBZZ | ${balance?.dai.toSignificantDigits(4)} xDAI`}
|
||||
title={balanceText}
|
||||
subtitle="Current wallet balance."
|
||||
status="ok"
|
||||
/>
|
||||
@@ -89,7 +99,7 @@ export default function Status(): ReactElement {
|
||||
icon={<ExchangeFunds />}
|
||||
title={
|
||||
chequebookBalance?.availableBalance
|
||||
? `${chequebookBalance.availableBalance.toFixedDecimal(4)} xBZZ`
|
||||
? `${chequebookBalance.availableBalance.toSignificantDigits(4)} xBZZ`
|
||||
: 'No available balance.'
|
||||
}
|
||||
subtitle="Chequebook not setup."
|
||||
@@ -149,7 +159,7 @@ export default function Status(): ReactElement {
|
||||
}
|
||||
/>
|
||||
<ExpandableListItem label="Mode" value={nodeInfo?.beeMode} />
|
||||
{wallet && <ExpandableListItem label="Blockchain network" value={chainIdToName(wallet.chainID)} />}
|
||||
{chainId && <ExpandableListItem label="Blockchain network" value={chainIdToName(chainId)} />}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import { Loading } from '../../components/Loading'
|
||||
import { SwarmButton } from '../../components/SwarmButton'
|
||||
import { SwarmDivider } from '../../components/SwarmDivider'
|
||||
import { Context } from '../../providers/Bee'
|
||||
import { Context as BalanceProvider } from '../../providers/WalletBalance'
|
||||
import { TopUpProgressIndicator } from './TopUpProgressIndicator'
|
||||
|
||||
const MINIMUM_XDAI = '0.5'
|
||||
@@ -21,7 +22,8 @@ interface Props {
|
||||
}
|
||||
|
||||
export default function Index({ header, title, p, next }: Props): ReactElement {
|
||||
const { nodeAddresses, balance } = useContext(Context)
|
||||
const { nodeAddresses } = useContext(Context)
|
||||
const { balance } = useContext(BalanceProvider)
|
||||
const navigate = useNavigate()
|
||||
|
||||
if (!balance || !nodeAddresses) {
|
||||
|
||||
@@ -13,6 +13,7 @@ import { SwarmButton } from '../../components/SwarmButton'
|
||||
import { SwarmDivider } from '../../components/SwarmDivider'
|
||||
import { Context as BeeContext } from '../../providers/Bee'
|
||||
import { Context as SettingsContext } from '../../providers/Settings'
|
||||
import { Context as BalanceProvider } from '../../providers/WalletBalance'
|
||||
import { ROUTES } from '../../routes'
|
||||
import { sleepMs } from '../../utils'
|
||||
import { restartBeeNode, upgradeToLightNode } from '../../utils/desktop'
|
||||
@@ -20,9 +21,9 @@ import { ResolvedWallet } from '../../utils/wallet'
|
||||
import { BeeModes } from '@ethersphere/bee-js'
|
||||
|
||||
export function GiftCardFund(): ReactElement {
|
||||
const { isBeeDesktop } = useContext(SettingsContext)
|
||||
const { nodeAddresses, balance, nodeInfo } = useContext(BeeContext)
|
||||
const { provider, providerUrl } = useContext(SettingsContext)
|
||||
const { nodeAddresses, nodeInfo } = useContext(BeeContext)
|
||||
const { isBeeDesktop, provider, providerUrl } = useContext(SettingsContext)
|
||||
const { balance } = useContext(BalanceProvider)
|
||||
|
||||
const [loading, setLoading] = useState(false)
|
||||
const [wallet, setWallet] = useState<ResolvedWallet | null>(null)
|
||||
|
||||
@@ -16,6 +16,7 @@ import { SwarmDivider } from '../../components/SwarmDivider'
|
||||
import { SwarmTextInput } from '../../components/SwarmTextInput'
|
||||
import { BzzToken } from '../../models/BzzToken'
|
||||
import { DaiToken } from '../../models/DaiToken'
|
||||
import { Context as BalanceProvider } from '../../providers/WalletBalance'
|
||||
import { Context as BeeContext } from '../../providers/Bee'
|
||||
import { Context as SettingsContext } from '../../providers/Settings'
|
||||
import { ROUTES } from '../../routes'
|
||||
@@ -36,9 +37,9 @@ export function Swap({ header }: Props): ReactElement {
|
||||
const [userInputSwap, setUserInputSwap] = useState<string | null>(null)
|
||||
const [price, setPrice] = useState(DaiToken.fromDecimal('0.6', 18))
|
||||
|
||||
const { providerUrl } = useContext(SettingsContext)
|
||||
const { balance, nodeAddresses, nodeInfo } = useContext(BeeContext)
|
||||
const { isBeeDesktop } = useContext(SettingsContext)
|
||||
const { providerUrl, isBeeDesktop } = useContext(SettingsContext)
|
||||
const { nodeAddresses, nodeInfo } = useContext(BeeContext)
|
||||
const { balance } = useContext(BalanceProvider)
|
||||
|
||||
const navigate = useNavigate()
|
||||
const { enqueueSnackbar } = useSnackbar()
|
||||
|
||||
@@ -12,6 +12,7 @@ import { SwarmButton } from '../../components/SwarmButton'
|
||||
import { ROUTES } from '../../routes'
|
||||
import { CheckState, Context as BeeContext } from '../../providers/Bee'
|
||||
import { Context as SettingsContext } from '../../providers/Settings'
|
||||
import { Context as BalanceProvider } from '../../providers/WalletBalance'
|
||||
import { BeeModes } from '@ethersphere/bee-js'
|
||||
import { restartBeeNode, upgradeToLightNode } from '../../utils/desktop'
|
||||
import { Loading } from '../../components/Loading'
|
||||
@@ -39,7 +40,8 @@ export default function TopUp(): ReactElement {
|
||||
const navigate = useNavigate()
|
||||
const styles = useStyles()
|
||||
const { isBeeDesktop } = useContext(SettingsContext)
|
||||
const { balance, nodeInfo, status } = useContext(BeeContext)
|
||||
const { nodeInfo, status } = useContext(BeeContext)
|
||||
const { balance } = useContext(BalanceProvider)
|
||||
const { providerUrl } = useContext(SettingsContext)
|
||||
const [loading, setLoading] = useState(false)
|
||||
const { enqueueSnackbar } = useSnackbar()
|
||||
|
||||
Reference in New Issue
Block a user