fix: provider is by default null and account page redirect to provider setup (#437)
This commit is contained in:
+28
-26
@@ -1,6 +1,6 @@
|
|||||||
import { Divider, Drawer, Grid, Link as MUILink, List } from '@material-ui/core'
|
import { Divider, Drawer, Grid, Link as MUILink, List } from '@material-ui/core'
|
||||||
import { createStyles, makeStyles, Theme } from '@material-ui/core/styles'
|
import { createStyles, makeStyles, Theme } from '@material-ui/core/styles'
|
||||||
import { ReactElement } from 'react'
|
import { ReactElement, useContext } from 'react'
|
||||||
import { Link } from 'react-router-dom'
|
import { Link } from 'react-router-dom'
|
||||||
import FilesIcon from 'remixicon-react/ArrowUpDownLineIcon'
|
import FilesIcon from 'remixicon-react/ArrowUpDownLineIcon'
|
||||||
import DocsIcon from 'remixicon-react/BookOpenLineIcon'
|
import DocsIcon from 'remixicon-react/BookOpenLineIcon'
|
||||||
@@ -8,6 +8,7 @@ import ExternalLinkIcon from 'remixicon-react/ExternalLinkLineIcon'
|
|||||||
import HomeIcon from 'remixicon-react/Home3LineIcon'
|
import HomeIcon from 'remixicon-react/Home3LineIcon'
|
||||||
import SettingsIcon from 'remixicon-react/Settings2LineIcon'
|
import SettingsIcon from 'remixicon-react/Settings2LineIcon'
|
||||||
import AccountIcon from 'remixicon-react/Wallet3LineIcon'
|
import AccountIcon from 'remixicon-react/Wallet3LineIcon'
|
||||||
|
import { Context as TopUpContext } from '../providers/TopUp'
|
||||||
import DashboardLogo from '../assets/dashboard-logo.svg'
|
import DashboardLogo from '../assets/dashboard-logo.svg'
|
||||||
import DesktopLogo from '../assets/desktop-logo.svg'
|
import DesktopLogo from '../assets/desktop-logo.svg'
|
||||||
import { config } from '../config'
|
import { config } from '../config'
|
||||||
@@ -17,31 +18,6 @@ import Feedback from './Feedback'
|
|||||||
import SideBarItem from './SideBarItem'
|
import SideBarItem from './SideBarItem'
|
||||||
import SideBarStatus from './SideBarStatus'
|
import SideBarStatus from './SideBarStatus'
|
||||||
|
|
||||||
const navBarItems = [
|
|
||||||
{
|
|
||||||
label: 'Info',
|
|
||||||
path: ROUTES.INFO,
|
|
||||||
icon: HomeIcon,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: 'Files',
|
|
||||||
path: ROUTES.UPLOAD,
|
|
||||||
icon: FilesIcon,
|
|
||||||
pathMatcherSubstring: '/files/',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: 'Account',
|
|
||||||
path: ROUTES.ACCOUNT_WALLET,
|
|
||||||
icon: AccountIcon,
|
|
||||||
pathMatcherSubstring: '/account/',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: 'Settings',
|
|
||||||
path: ROUTES.SETTINGS,
|
|
||||||
icon: SettingsIcon,
|
|
||||||
},
|
|
||||||
]
|
|
||||||
|
|
||||||
const drawerWidth = 300
|
const drawerWidth = 300
|
||||||
|
|
||||||
const useStyles = makeStyles((theme: Theme) =>
|
const useStyles = makeStyles((theme: Theme) =>
|
||||||
@@ -91,6 +67,32 @@ const useStyles = makeStyles((theme: Theme) =>
|
|||||||
export default function SideBar(): ReactElement {
|
export default function SideBar(): ReactElement {
|
||||||
const classes = useStyles()
|
const classes = useStyles()
|
||||||
const { isBeeDesktop } = useIsBeeDesktop()
|
const { isBeeDesktop } = useIsBeeDesktop()
|
||||||
|
const { providerUrl } = useContext(TopUpContext)
|
||||||
|
|
||||||
|
const navBarItems = [
|
||||||
|
{
|
||||||
|
label: 'Info',
|
||||||
|
path: ROUTES.INFO,
|
||||||
|
icon: HomeIcon,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Files',
|
||||||
|
path: ROUTES.UPLOAD,
|
||||||
|
icon: FilesIcon,
|
||||||
|
pathMatcherSubstring: '/files/',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Account',
|
||||||
|
path: providerUrl === null ? ROUTES.WALLET : ROUTES.ACCOUNT_WALLET,
|
||||||
|
icon: AccountIcon,
|
||||||
|
pathMatcherSubstring: '/account/',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Settings',
|
||||||
|
path: ROUTES.SETTINGS,
|
||||||
|
icon: SettingsIcon,
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Drawer className={classes.drawer} variant="permanent" anchor="left" classes={{ paper: classes.drawerPaper }}>
|
<Drawer className={classes.drawer} variant="permanent" anchor="left" classes={{ paper: classes.drawerPaper }}>
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ export default function Index(): ReactElement {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
async function mapGiftWallets() {
|
async function mapGiftWallets() {
|
||||||
|
if (!provider) return
|
||||||
const results = []
|
const results = []
|
||||||
for (const giftWallet of giftWallets) {
|
for (const giftWallet of giftWallets) {
|
||||||
results.push(await ResolvedWallet.make(giftWallet, provider))
|
results.push(await ResolvedWallet.make(giftWallet, provider))
|
||||||
|
|||||||
@@ -19,6 +19,8 @@ export default function Index(): ReactElement {
|
|||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
|
|
||||||
async function onSubmit() {
|
async function onSubmit() {
|
||||||
|
if (!localProviderUrl) return
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await Rpc.eth_getBlockByNumber(new providers.JsonRpcProvider(localProviderUrl))
|
await Rpc.eth_getBlockByNumber(new providers.JsonRpcProvider(localProviderUrl))
|
||||||
enqueueSnackbar('Connected to RPC provider successfully.', { variant: 'success' })
|
enqueueSnackbar('Connected to RPC provider successfully.', { variant: 'success' })
|
||||||
@@ -54,7 +56,7 @@ export default function Index(): ReactElement {
|
|||||||
name="rpc-endpoint"
|
name="rpc-endpoint"
|
||||||
label="RPC Endpoint"
|
label="RPC Endpoint"
|
||||||
onChange={event => setLocalProviderUrl(event.target.value)}
|
onChange={event => setLocalProviderUrl(event.target.value)}
|
||||||
defaultValue={providerUrl}
|
defaultValue={providerUrl || ''}
|
||||||
/>
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
<SwarmButton iconType={Check} onClick={onSubmit}>
|
<SwarmButton iconType={Check} onClick={onSubmit}>
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ export function GiftCardFund(): ReactElement {
|
|||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!privateKeyString) {
|
if (!privateKeyString || !provider) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,7 +43,7 @@ export function GiftCardFund(): ReactElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function onFund() {
|
async function onFund() {
|
||||||
if (!wallet || !nodeAddresses) {
|
if (!wallet || !nodeAddresses || !providerUrl) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,8 @@ export function GiftCardTopUpIndex(): ReactElement {
|
|||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
|
|
||||||
async function onProceed() {
|
async function onProceed() {
|
||||||
|
if (!provider) return
|
||||||
|
|
||||||
setLoading(true)
|
setLoading(true)
|
||||||
try {
|
try {
|
||||||
const wallet = new Wallet(giftCode, provider)
|
const wallet = new Wallet(giftCode, provider)
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ export function Swap({ header }: Props): ReactElement {
|
|||||||
const bzzAfterSwap = new BzzToken(daiToSwap.toBigNumber.dividedToIntegerBy(200))
|
const bzzAfterSwap = new BzzToken(daiToSwap.toBigNumber.dividedToIntegerBy(200))
|
||||||
|
|
||||||
async function onSwap() {
|
async function onSwap() {
|
||||||
if (hasSwapped) {
|
if (hasSwapped || !providerUrl) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
setLoading(true)
|
setLoading(true)
|
||||||
|
|||||||
@@ -242,7 +242,7 @@ export function Provider({ children }: Props): ReactElement {
|
|||||||
}, [beeDebugApi]) // eslint-disable-line react-hooks/exhaustive-deps
|
}, [beeDebugApi]) // eslint-disable-line react-hooks/exhaustive-deps
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (nodeAddresses?.ethereum) {
|
if (nodeAddresses?.ethereum && provider) {
|
||||||
WalletAddress.make(nodeAddresses.ethereum, provider).then(setWalletAddress)
|
WalletAddress.make(nodeAddresses.ethereum, provider).then(setWalletAddress)
|
||||||
}
|
}
|
||||||
}, [nodeAddresses, provider])
|
}, [nodeAddresses, provider])
|
||||||
|
|||||||
+10
-6
@@ -10,16 +10,18 @@ const LocalStorageKeys = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface ContextInterface {
|
interface ContextInterface {
|
||||||
providerUrl: string
|
providerUrl: string | null
|
||||||
provider: providers.JsonRpcProvider
|
provider: providers.JsonRpcProvider | null
|
||||||
giftWallets: Wallet[]
|
giftWallets: Wallet[]
|
||||||
setProviderUrl: (providerUrl: string) => void
|
setProviderUrl: (providerUrl: string) => void
|
||||||
addGiftWallet: (wallet: Wallet) => void
|
addGiftWallet: (wallet: Wallet) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const providerUrl = localStorage.getItem('json-rpc-provider') || null
|
||||||
|
|
||||||
const initialValues: ContextInterface = {
|
const initialValues: ContextInterface = {
|
||||||
providerUrl: '',
|
providerUrl,
|
||||||
provider: new providers.JsonRpcProvider(),
|
provider: providerUrl ? new providers.JsonRpcProvider(providerUrl) : null,
|
||||||
giftWallets: [],
|
giftWallets: [],
|
||||||
setProviderUrl: () => {}, // eslint-disable-line
|
setProviderUrl: () => {}, // eslint-disable-line
|
||||||
addGiftWallet: () => {}, // eslint-disable-line
|
addGiftWallet: () => {}, // eslint-disable-line
|
||||||
@@ -33,11 +35,13 @@ interface Props {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function Provider({ children }: Props): ReactElement {
|
export function Provider({ children }: Props): ReactElement {
|
||||||
const [providerUrl, setProviderUrl] = useState(localStorage.getItem('json-rpc-provider') || initialValues.providerUrl)
|
const [providerUrl, setProviderUrl] = useState(initialValues.providerUrl)
|
||||||
const [provider, setProvider] = useState(new providers.JsonRpcProvider(providerUrl))
|
const [provider, setProvider] = useState(initialValues.provider)
|
||||||
const [giftWallets, setGiftWallets] = useState(initialValues.giftWallets)
|
const [giftWallets, setGiftWallets] = useState(initialValues.giftWallets)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
if (provider === null) return
|
||||||
|
|
||||||
const existingGiftWallets = localStorage.getItem(LocalStorageKeys.giftWallets)
|
const existingGiftWallets = localStorage.getItem(LocalStorageKeys.giftWallets)
|
||||||
|
|
||||||
if (existingGiftWallets) {
|
if (existingGiftWallets) {
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import axios from 'axios'
|
|
||||||
import { getJson, postJson, sendRequest } from './net'
|
import { getJson, postJson, sendRequest } from './net'
|
||||||
|
|
||||||
interface DesktopStatus {
|
interface DesktopStatus {
|
||||||
@@ -16,10 +15,6 @@ export async function getDesktopStatus(): Promise<DesktopStatus> {
|
|||||||
return response as DesktopStatus
|
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> {
|
export async function upgradeToLightNode(rpcProvider: string): Promise<void> {
|
||||||
await updateDesktopConfiguration({
|
await updateDesktopConfiguration({
|
||||||
'chain-enable': true,
|
'chain-enable': true,
|
||||||
|
|||||||
Reference in New Issue
Block a user