This commit is contained in:
fmtabbara
2022-02-16 11:10:15 +00:00
parent be9d3a48bb
commit b269cdae31
3 changed files with 10 additions and 10 deletions
+2 -6
View File
@@ -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={{
+3 -2
View File
@@ -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
+5 -2
View File
@@ -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}