import { Box, Typography } from '@material-ui/core' import { useSnackbar } from 'notistack' import { ReactElement, useContext, useEffect, useState } from 'react' import Check from 'remixicon-react/CheckLineIcon' import X from 'remixicon-react/CloseLineIcon' import { useNavigate } from 'react-router' import { Wallet } from 'ethers' import ExpandableListItem from '../../components/ExpandableListItem' import ExpandableListItemActions from '../../components/ExpandableListItemActions' 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 TopUpContext } from '../../providers/TopUp' import { createGiftWallet } from '../../utils/desktop' import { ResolvedWallet } from '../../utils/wallet' export default function Index(): ReactElement { const { giftWallets, addGiftWallet, provider } = useContext(TopUpContext) const { balance } = useContext(BeeContext) const [loading, setLoading] = useState(false) const [balances, setBalances] = useState([]) useEffect(() => { async function mapGiftWallets() { if (!provider) return const results = [] for (const giftWallet of giftWallets) { results.push(await ResolvedWallet.make(giftWallet, provider)) } setBalances(results) } mapGiftWallets() }, [giftWallets, provider]) const { enqueueSnackbar } = useSnackbar() const navigate = useNavigate() async function onCreate() { enqueueSnackbar('Sending funds to gift wallet...') setLoading(true) try { const wallet = Wallet.createRandom() addGiftWallet(wallet) await createGiftWallet(wallet.address) enqueueSnackbar('Succesfully funded gift wallet', { variant: 'success' }) } catch (error) { enqueueSnackbar(`Failed to fund gift wallet: ${error}`, { variant: 'error' }) } finally { setLoading(false) } } function onCancel() { navigate(-1) } if (!balance) { return } return ( <> Invite to Swarm... Generate and share a gift wallet that anyone can use to set-up their light node with Swarm Desktop. This will use 1 XDAI and 5 BZZ from your node wallet. {balances.map((x, i) => ( ))} Generate gift wallet Cancel ) }