Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add indexing error modal #32

Merged
merged 2 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/collator/_hooks/collator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export const useCreateCollator = ({
abi: hubAbi,
address: hubAddress,
functionName: 'assetsToVotes',
args: [stakedOf ?? 0n, commission],
args: [commission, stakedOf ?? 0n],
query: {
enabled: isEnabled && !!stakedOf && enabled
}
Expand Down
12 changes: 11 additions & 1 deletion src/components/waiting-indexing/context.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { createContext, useState, ReactNode } from 'react';
import WaitingIndexing from '@/components/waiting-indexing';
import IndexingErrorModal from '@/components/waiting-indexing/error-modal'; // Assuming this component exists

interface WaitingIndexingContextProps {
isOpen: boolean;
open: () => void;
close: () => void;
openError: () => void;
closeError: () => void;
isErrorOpen: boolean;
}

export const WaitingIndexingContext = createContext<WaitingIndexingContextProps | undefined>(
Expand All @@ -13,14 +17,20 @@ export const WaitingIndexingContext = createContext<WaitingIndexingContextProps

export function WaitingIndexingProvider({ children }: { children: ReactNode }) {
const [isOpen, setIsOpen] = useState(false);
const [isErrorOpen, setIsErrorOpen] = useState(false);

const open = () => setIsOpen(true);
const close = () => setIsOpen(false);
const openError = () => setIsErrorOpen(true);
const closeError = () => setIsErrorOpen(false);

return (
<WaitingIndexingContext.Provider value={{ isOpen, open, close }}>
<WaitingIndexingContext.Provider
value={{ isOpen, open, close, isErrorOpen, openError, closeError }}
>
{children}
<WaitingIndexing isOpen={isOpen} onClose={close} />
<IndexingErrorModal isOpen={isErrorOpen} onClose={closeError} />
</WaitingIndexingContext.Provider>
);
}
43 changes: 43 additions & 0 deletions src/components/waiting-indexing/error-modal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import React from 'react';
import { Modal, ModalBody, ModalContent, ModalHeader } from '@nextui-org/modal';
import { CircleAlert } from 'lucide-react';

interface IndexingErrorModalProps {
isOpen: boolean;
onClose: () => void;
}

const IndexingErrorModal: React.FC<IndexingErrorModalProps> = ({ isOpen, onClose }) => {
return (
<Modal
isOpen={isOpen}
onClose={onClose}
placement="center"
className="bg-background"
size="sm"
backdrop="opaque"
>
<ModalContent className="">
<ModalHeader className="flex items-center gap-2 text-[1.125rem] text-foreground">
<CircleAlert />
Indexing Service Error
</ModalHeader>
<ModalBody>
<div className="pb-4 font-normal text-foreground">
Indexing service error, please report it at{' '}
<a
href="https://github.com/darwinia-network/collator-staking-ui-v2/issues/new"
target="_blank"
rel="noreferrer"
className="text-primary"
>
https://github.com/darwinia-network/collator-staking-ui-v2/issues/new
</a>
</div>
</ModalBody>
</ModalContent>
</Modal>
);
};

export default IndexingErrorModal;
12 changes: 8 additions & 4 deletions src/hooks/useWaitingIndexing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import useWalletStatus from './useWalletStatus';

function useCheckWaitingIndexing() {
const { currentChainId } = useWalletStatus();
const { open } = useWaitingIndexing();
const { open, openError } = useWaitingIndexing();
const [isLoading, setIsLoading] = useState(false);

const checkWaitingIndexing = useCallback(async () => {
Expand All @@ -25,7 +25,11 @@ function useCheckWaitingIndexing() {
}),
fetchDeploymentMeta(currentChainId)
]);

if (!deploymentMeta?._meta?.block?.timestamp) {
openError();
setIsLoading(false);
return { isDeployed: false, error: null };
}
if (deploymentMeta?._meta?.block?.timestamp) {
const contractTimestamp = updateTimeStamp ? BigInt(updateTimeStamp.toString()) : 0n;
const indexedTimestamp = BigInt(deploymentMeta._meta.block.timestamp);
Expand All @@ -36,7 +40,7 @@ function useCheckWaitingIndexing() {
return { isDeployed, error: null };
}

return { isDeployed: false, error: null };
return { isDeployed: false, error: new Error('Indexing service error') };
} catch (error) {
return {
isDeployed: false,
Expand All @@ -45,7 +49,7 @@ function useCheckWaitingIndexing() {
} finally {
setIsLoading(false);
}
}, [currentChainId, open]);
}, [currentChainId, open, openError]);

return { checkWaitingIndexing, isLoading };
}
Expand Down
Loading