fix: provider is by default null and account page redirect to provider setup (#437)

This commit is contained in:
Vojtech Simetka
2022-06-24 14:03:37 +02:00
committed by GitHub
parent a756eedc49
commit 2e0eeb7a1b
9 changed files with 48 additions and 42 deletions
+1 -1
View File
@@ -242,7 +242,7 @@ export function Provider({ children }: Props): ReactElement {
}, [beeDebugApi]) // eslint-disable-line react-hooks/exhaustive-deps
useEffect(() => {
if (nodeAddresses?.ethereum) {
if (nodeAddresses?.ethereum && provider) {
WalletAddress.make(nodeAddresses.ethereum, provider).then(setWalletAddress)
}
}, [nodeAddresses, provider])
+10 -6
View File
@@ -10,16 +10,18 @@ const LocalStorageKeys = {
}
interface ContextInterface {
providerUrl: string
provider: providers.JsonRpcProvider
providerUrl: string | null
provider: providers.JsonRpcProvider | null
giftWallets: Wallet[]
setProviderUrl: (providerUrl: string) => void
addGiftWallet: (wallet: Wallet) => void
}
const providerUrl = localStorage.getItem('json-rpc-provider') || null
const initialValues: ContextInterface = {
providerUrl: '',
provider: new providers.JsonRpcProvider(),
providerUrl,
provider: providerUrl ? new providers.JsonRpcProvider(providerUrl) : null,
giftWallets: [],
setProviderUrl: () => {}, // eslint-disable-line
addGiftWallet: () => {}, // eslint-disable-line
@@ -33,11 +35,13 @@ interface Props {
}
export function Provider({ children }: Props): ReactElement {
const [providerUrl, setProviderUrl] = useState(localStorage.getItem('json-rpc-provider') || initialValues.providerUrl)
const [provider, setProvider] = useState(new providers.JsonRpcProvider(providerUrl))
const [providerUrl, setProviderUrl] = useState(initialValues.providerUrl)
const [provider, setProvider] = useState(initialValues.provider)
const [giftWallets, setGiftWallets] = useState(initialValues.giftWallets)
useEffect(() => {
if (provider === null) return
const existingGiftWallets = localStorage.getItem(LocalStorageKeys.giftWallets)
if (existingGiftWallets) {