Keep common hook for checking balance in IFrame component
This commit is contained in:
parent
604f9181c5
commit
e7cd642242
@ -7,7 +7,7 @@ import {
|
|||||||
VITE_WALLET_IFRAME_URL,
|
VITE_WALLET_IFRAME_URL,
|
||||||
} from 'utils/constants';
|
} from 'utils/constants';
|
||||||
|
|
||||||
const IFrameModal = ({
|
const ApproveTransactionModal = ({
|
||||||
setAccount,
|
setAccount,
|
||||||
setIsDataReceived,
|
setIsDataReceived,
|
||||||
isVisible,
|
isVisible,
|
||||||
@ -29,7 +29,9 @@ const IFrameModal = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
setAccount(event.data.data[0].address);
|
setAccount(event.data.data[0].address);
|
||||||
} else if (event.data.type === 'ERROR') {
|
}
|
||||||
|
|
||||||
|
if (event.data.type === 'ERROR') {
|
||||||
console.error('Error from wallet:', event.data.message);
|
console.error('Error from wallet:', event.data.message);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -91,4 +93,4 @@ const IFrameModal = ({
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default IFrameModal;
|
export default ApproveTransactionModal;
|
@ -1,14 +1,26 @@
|
|||||||
|
import { useEffect } from "react";
|
||||||
|
|
||||||
import { Modal } from "@mui/material";
|
import { Modal } from "@mui/material";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
VITE_WALLET_IFRAME_URL,
|
VITE_WALLET_IFRAME_URL,
|
||||||
} from 'utils/constants';
|
} from 'utils/constants';
|
||||||
|
import useCheckBalance from '../../../hooks/useCheckBalance';
|
||||||
|
|
||||||
|
const CheckBalanceIframe = ({ setIsSufficient }: { setIsSufficient: (isSufficient: boolean | undefined) => void }) => {
|
||||||
|
const { checkBalance, isBalanceSufficient } = useCheckBalance(
|
||||||
|
'1',
|
||||||
|
'checkBalanceIframe'
|
||||||
|
);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setIsSufficient(isBalanceSufficient);
|
||||||
|
}, [isBalanceSufficient]);
|
||||||
|
|
||||||
const CheckBalanceIframe = ({ onLoad }: { onLoad: () => void }) => {
|
|
||||||
return (
|
return (
|
||||||
<Modal open={false} disableEscapeKeyDown keepMounted>
|
<Modal open={false} disableEscapeKeyDown keepMounted>
|
||||||
<iframe
|
<iframe
|
||||||
onLoad={onLoad}
|
onLoad={checkBalance}
|
||||||
id="checkBalanceIframe"
|
id="checkBalanceIframe"
|
||||||
src={VITE_WALLET_IFRAME_URL}
|
src={VITE_WALLET_IFRAME_URL}
|
||||||
width="100%"
|
width="100%"
|
||||||
|
@ -20,7 +20,7 @@ import { Button } from '../../shared/Button';
|
|||||||
import { Input } from 'components/shared/Input';
|
import { Input } from 'components/shared/Input';
|
||||||
import { useToast } from 'components/shared/Toast';
|
import { useToast } from 'components/shared/Toast';
|
||||||
import { useGQLClient } from '../../../context/GQLClientContext';
|
import { useGQLClient } from '../../../context/GQLClientContext';
|
||||||
import IFrameModal from './IFrameModal';
|
import ApproveTransactionModal from './ApproveTransactionModal';
|
||||||
import EnvironmentVariablesForm from 'pages/org-slug/projects/id/settings/EnvironmentVariablesForm';
|
import EnvironmentVariablesForm from 'pages/org-slug/projects/id/settings/EnvironmentVariablesForm';
|
||||||
import { EnvironmentVariablesFormValues } from 'types/types';
|
import { EnvironmentVariablesFormValues } from 'types/types';
|
||||||
import {
|
import {
|
||||||
@ -642,7 +642,6 @@ const Configure = () => {
|
|||||||
? 'Deploying'
|
? 'Deploying'
|
||||||
: 'Deploy'}
|
: 'Deploy'}
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
{isAccountsDataReceived && isBalanceSufficient !== undefined ? (
|
{isAccountsDataReceived && isBalanceSufficient !== undefined ? (
|
||||||
!selectedAccount || !isBalanceSufficient ? (
|
!selectedAccount || !isBalanceSufficient ? (
|
||||||
<div className="flex items-center gap-4">
|
<div className="flex items-center gap-4">
|
||||||
@ -679,7 +678,7 @@ const Configure = () => {
|
|||||||
</form>
|
</form>
|
||||||
</FormProvider>
|
</FormProvider>
|
||||||
|
|
||||||
<IFrameModal
|
<ApproveTransactionModal
|
||||||
setAccount={setSelectedAccount}
|
setAccount={setSelectedAccount}
|
||||||
setIsDataReceived={setIsAccountsDataReceived}
|
setIsDataReceived={setIsAccountsDataReceived}
|
||||||
isVisible={isFrameVisible}
|
isVisible={isFrameVisible}
|
||||||
|
@ -1,22 +1,17 @@
|
|||||||
import { useEffect } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate } from 'react-router-dom';
|
||||||
import { useMediaQuery } from 'usehooks-ts';
|
import { useMediaQuery } from 'usehooks-ts';
|
||||||
|
|
||||||
import { Button } from 'components/shared';
|
import { Button } from 'components/shared';
|
||||||
import CheckBalanceIframe from 'components/projects/create/CheckBalanceIframe';
|
import CheckBalanceIframe from 'components/projects/create/CheckBalanceIframe';
|
||||||
import useCheckBalance from '../hooks/useCheckBalance';
|
|
||||||
|
|
||||||
const BuyPrepaidService = () => {
|
const BuyPrepaidService = () => {
|
||||||
|
const [isBalanceSufficient, setIsBalanceSufficient] = useState<boolean>();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
const isTabletView = useMediaQuery('(min-width: 720px)'); // md:
|
const isTabletView = useMediaQuery('(min-width: 720px)'); // md:
|
||||||
const buttonSize = isTabletView ? { size: 'lg' as const } : {};
|
const buttonSize = isTabletView ? { size: 'lg' as const } : {};
|
||||||
|
|
||||||
const { isBalanceSufficient, checkBalance } = useCheckBalance(
|
|
||||||
'1',
|
|
||||||
'checkBalanceIframe'
|
|
||||||
);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isBalanceSufficient === true) {
|
if (isBalanceSufficient === true) {
|
||||||
navigate('/');
|
navigate('/');
|
||||||
@ -33,7 +28,7 @@ const BuyPrepaidService = () => {
|
|||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<CheckBalanceIframe onLoad={checkBalance} />
|
<CheckBalanceIframe setIsSufficient={setIsBalanceSufficient} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -6,20 +6,16 @@ import { Heading, Badge, Button } from 'components/shared';
|
|||||||
import { PlusIcon } from 'components/shared/CustomIcon';
|
import { PlusIcon } from 'components/shared/CustomIcon';
|
||||||
import { useGQLClient } from 'context/GQLClientContext';
|
import { useGQLClient } from 'context/GQLClientContext';
|
||||||
import { Project } from 'gql-client';
|
import { Project } from 'gql-client';
|
||||||
import useCheckBalance from '../../hooks/useCheckBalance';
|
|
||||||
import CheckBalanceIframe from 'components/projects/create/CheckBalanceIframe';
|
import CheckBalanceIframe from 'components/projects/create/CheckBalanceIframe';
|
||||||
|
|
||||||
const Projects = () => {
|
const Projects = () => {
|
||||||
|
const [isBalanceSufficient, setIsBalanceSufficient] = useState<boolean>();
|
||||||
|
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const client = useGQLClient();
|
const client = useGQLClient();
|
||||||
const { orgSlug } = useParams();
|
const { orgSlug } = useParams();
|
||||||
const [projects, setProjects] = useState<Project[]>([]);
|
const [projects, setProjects] = useState<Project[]>([]);
|
||||||
|
|
||||||
const { isBalanceSufficient, checkBalance } = useCheckBalance(
|
|
||||||
'1',
|
|
||||||
'checkBalanceIframe'
|
|
||||||
);
|
|
||||||
|
|
||||||
const fetchProjects = useCallback(async () => {
|
const fetchProjects = useCallback(async () => {
|
||||||
const { projectsInOrganization } = await client.getProjectsInOrganization(
|
const { projectsInOrganization } = await client.getProjectsInOrganization(
|
||||||
orgSlug!,
|
orgSlug!,
|
||||||
@ -64,7 +60,7 @@ const Projects = () => {
|
|||||||
})}
|
})}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<CheckBalanceIframe onLoad={checkBalance} />
|
<CheckBalanceIframe setIsSufficient={setIsBalanceSufficient} />
|
||||||
</section>
|
</section>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user