* MP-2801: fund new credit account * tidy: cleanup * tidy: refactor * feat: replaced all possible BN(0) & BN(1) occurrences with constants * fix: adjusted according to feedback * fix: adjustments according to feedback * fix: PR comment updates * fix: reduced complexity * feat: animated the wallet balance for the demo * fix: enhanced wallet connection to select first account * fix: adjusted the calculations and added USD as displayCurrency * fix: adjusted according to feedback * feat: added TFM bridge * fix: changed forceFetchPrice --------- Co-authored-by: Yusuf Seyrek <yusuf@delphilabs.io>
49 lines
1.6 KiB
TypeScript
49 lines
1.6 KiB
TypeScript
import { useCallback, useEffect } from 'react'
|
|
import { useLocation, useNavigate } from 'react-router-dom'
|
|
|
|
import AccountFundFirst from 'components/Account/AccountFund'
|
|
import FullOverlayContent from 'components/FullOverlayContent'
|
|
import WalletSelect from 'components/Wallet/WalletSelect'
|
|
import useToggle from 'hooks/useToggle'
|
|
import useStore from 'store'
|
|
import { hardcodedFee } from 'utils/constants'
|
|
import { getPage, getRoute } from 'utils/route'
|
|
|
|
export default function AccountCreateFirst() {
|
|
const navigate = useNavigate()
|
|
const { pathname } = useLocation()
|
|
const address = useStore((s) => s.address)
|
|
const createAccount = useStore((s) => s.createAccount)
|
|
const [isCreating, setIsCreating] = useToggle(false)
|
|
|
|
useEffect(() => {
|
|
if (!address) useStore.setState({ focusComponent: <WalletSelect /> })
|
|
}, [address])
|
|
|
|
const handleClick = useCallback(async () => {
|
|
setIsCreating(true)
|
|
const accountId = await createAccount({ fee: hardcodedFee })
|
|
setIsCreating(false)
|
|
if (accountId) {
|
|
navigate(getRoute(getPage(pathname), address, accountId))
|
|
useStore.setState({ focusComponent: <AccountFundFirst /> })
|
|
}
|
|
}, [createAccount, navigate, pathname, address, setIsCreating])
|
|
|
|
return (
|
|
<FullOverlayContent
|
|
title='Mint your account'
|
|
copy="We'll require you to authorise a transaction in your wallet in order to begin."
|
|
button={{
|
|
className: 'mt-4 w-full',
|
|
text: 'Approve transaction',
|
|
color: 'tertiary',
|
|
showProgressIndicator: isCreating,
|
|
onClick: handleClick,
|
|
size: 'lg',
|
|
}}
|
|
docs='account'
|
|
/>
|
|
)
|
|
}
|