refactor
This commit is contained in:
@@ -4,12 +4,8 @@ import { GlobalContext } from '../context'
|
||||
import { CancelOutlined, CheckCircleOutline } from '@mui/icons-material'
|
||||
|
||||
export const Balance = () => {
|
||||
const { balance, hasMadePreviousRequest, getBalance } =
|
||||
useContext(GlobalContext)
|
||||
|
||||
const tokensAreAvailable =
|
||||
!hasMadePreviousRequest || (balance && +balance < 101)
|
||||
|
||||
const { tokensAreAvailable, balance } = useContext(GlobalContext)
|
||||
console.log(balance)
|
||||
return (
|
||||
<Card
|
||||
sx={{
|
||||
|
||||
@@ -32,7 +32,8 @@ export const Form = ({ withInputField }: { withInputField?: boolean }) => {
|
||||
defaultValues: { address: '', amount: '101' },
|
||||
})
|
||||
|
||||
const { requestTokens, loadingState, error } = useContext(GlobalContext)
|
||||
const { requestTokens, loadingState, error, tokensAreAvailable } =
|
||||
useContext(GlobalContext)
|
||||
|
||||
const resetForm = () => {
|
||||
setValue('address', '')
|
||||
@@ -91,7 +92,7 @@ export const Form = ({ withInputField }: { withInputField?: boolean }) => {
|
||||
<CircularProgress size={20} color="inherit" />
|
||||
)
|
||||
}
|
||||
disabled={loadingState.isLoading}
|
||||
disabled={loadingState.isLoading || !tokensAreAvailable}
|
||||
data-testid="request-token-button"
|
||||
>
|
||||
Request 101 NYMT
|
||||
|
||||
@@ -26,7 +26,7 @@ type TGlobalContext = {
|
||||
balance?: string
|
||||
tokenTransfer?: { address: string; amount: string }
|
||||
error?: string
|
||||
hasMadePreviousRequest: boolean
|
||||
tokensAreAvailable: boolean
|
||||
}
|
||||
|
||||
type TLoadingState = {
|
||||
@@ -124,6 +124,9 @@ export const GlobalContextProvider: React.FC = ({ children }) => {
|
||||
setLoadingState({ isLoading: false, requestType: undefined })
|
||||
}
|
||||
|
||||
const tokensAreAvailable =
|
||||
!hasMadePreviousRequest && Boolean(balance && +balance >= 101)
|
||||
|
||||
return (
|
||||
<GlobalContext.Provider
|
||||
value={{
|
||||
@@ -133,7 +136,7 @@ export const GlobalContextProvider: React.FC = ({ children }) => {
|
||||
balance,
|
||||
tokenTransfer,
|
||||
error,
|
||||
hasMadePreviousRequest,
|
||||
tokensAreAvailable,
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
|
||||
Reference in New Issue
Block a user