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

feat: Fail to load quote modal #240

Merged
merged 1 commit into from
Jan 3, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,10 @@ export const setIsRoutesModalOpen = createAction<ITransferState['isRoutesModalOp
export const setIsManuallyReload = createAction<ITransferState['isManuallyReload']>(
'transfer/setIsManuallyReload',
);

export const setIsFailedGetQuoteModalOpen = createAction<
ITransferState['isFailedGetQuoteModalOpen']
>('transfer/setIsFailedGetQuoteModalOpen');
export const setIsSummaryModalOpen = createAction<ITransferState['isSummaryModalOpen']>(
'transfer/setIsSummaryModalOpen',
);
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,21 @@ import { WalletButtonWrapper } from '@/modules/transfer/components/Button/Wallet
import { TransactionSummaryModal } from '@/modules/transfer/components/Modal/TransactionSummaryModal';
import { TransferWarningMessage } from '@/modules/transfer/components/TransferWarningMessage';
import { MIN_SOL_TO_ENABLED_TX } from '@/core/constants';
import { FailedToGetQuoteModal } from '@/modules/transfer/components/Modal/FailedToGetQuoteModal';
import { useFailGetQuoteModal } from '@/modules/transfer/hooks/modal/useFailGetQuoteModal';
import { useAppSelector } from '@/modules/store/StoreProvider';
import { useSummaryModal } from '@/modules/transfer/hooks/modal/useSummaryModal';

export const TransferButtonGroup = () => {
const [hash, setHash] = useState<string | null>(null);
const [chosenBridge, setChosenBridge] = useState<string | null>(null);
const { formatMessage } = useIntl();

const isFailedGetQuoteModalOpen = useAppSelector(
(state) => state.transfer.isFailedGetQuoteModalOpen,
);
const isSummaryModalOpen = useAppSelector((state) => state.transfer.isSummaryModalOpen);

const {
isOpen: isSubmittedModalOpen,
onOpen: onOpenSubmittedModal,
Expand All @@ -36,12 +45,8 @@ export const TransferButtonGroup = () => {
onOpen: onOpenConfirmingModal,
onClose: onCloseConfirmingModal,
} = useDisclosure();
const {
isOpen: isSummaryModalOpen,
onOpen: onOpenSummaryModal,
onClose: onCloseSummaryModal,
} = useDisclosure();

const { onCloseFailedGetQuoteModal } = useFailGetQuoteModal();
const { onCloseSummaryModal, onOpenSummaryModal } = useSummaryModal();
return (
<>
<Flex
Expand Down Expand Up @@ -90,6 +95,10 @@ export const TransferButtonGroup = () => {
setHash={setHash}
setChosenBridge={setChosenBridge}
/>
<FailedToGetQuoteModal
isOpen={isFailedGetQuoteModalOpen}
onClose={onCloseFailedGetQuoteModal}
/>
</>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { useCallback } from 'react';

import { useAppDispatch } from '@/modules/store/StoreProvider';
import { setIsFailedGetQuoteModalOpen } from '@/modules/transfer/action';

export const useFailGetQuoteModal = () => {
const dispatch = useAppDispatch();

const onOpenFailedGetQuoteModal = useCallback(() => {
dispatch(setIsFailedGetQuoteModalOpen(true));
}, [dispatch]);

const onCloseFailedGetQuoteModal = useCallback(() => {
dispatch(setIsFailedGetQuoteModalOpen(false));
}, [dispatch]);
return {
onOpenFailedGetQuoteModal,
onCloseFailedGetQuoteModal,
};
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { useCallback } from 'react';

import { useAppDispatch } from '@/modules/store/StoreProvider';
import { setIsSummaryModalOpen } from '@/modules/transfer/action';

export const useSummaryModal = () => {
const dispatch = useAppDispatch();

const onOpenSummaryModal = useCallback(() => {
dispatch(setIsSummaryModalOpen(true));
}, [dispatch]);

const onCloseSummaryModal = useCallback(() => {
dispatch(setIsSummaryModalOpen(false));
}, [dispatch]);
return {
onOpenSummaryModal,
onCloseSummaryModal,
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import { useCallback } from 'react';
import { useAppDispatch, useAppSelector } from '@/modules/store/StoreProvider';
import { setTransferActionInfo } from '@/modules/transfer/action';
import { useCBridgeTransferParams } from '@/modules/aggregator/adapters/cBridge/hooks/useCBridgeTransferParams';
import { useFailGetQuoteModal } from '@/modules/transfer/hooks/modal/useFailGetQuoteModal';

export const usePreSelectRoute = () => {
const dispatch = useAppDispatch();
const { bridgeAddress: cBridgeAddress } = useCBridgeTransferParams();

const { onOpenFailedGetQuoteModal } = useFailGetQuoteModal();
const selectedToken = useAppSelector((state) => state.transfer.selectedToken);
const fromChain = useAppSelector((state) => state.transfer.fromChain);

Expand Down Expand Up @@ -63,6 +64,9 @@ export const usePreSelectRoute = () => {
bridgeAddress: fromChain?.meson?.raw?.address as `0x${string}`,
}),
);
} else {
// Can not find the route
onOpenFailedGetQuoteModal();
}
},
[
Expand All @@ -71,6 +75,7 @@ export const usePreSelectRoute = () => {
selectedToken?.stargate?.raw?.address,
cBridgeAddress,
fromChain,
onOpenFailedGetQuoteModal,
],
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ export interface ITransferState {
address?: string;
};
isRoutesModalOpen: boolean;
isFailedGetQuoteModalOpen: boolean;
isSummaryModalOpen: boolean;
}

const initStates: ITransferState = {
Expand All @@ -54,6 +56,8 @@ const initStates: ITransferState = {
},
isRoutesModalOpen: false,
isManuallyReload: false,
isFailedGetQuoteModalOpen: false,
isSummaryModalOpen: false,
};

export default createReducer(initStates, (builder) => {
Expand Down Expand Up @@ -143,4 +147,13 @@ export default createReducer(initStates, (builder) => {
...state,
isManuallyReload: payload,
}));

builder.addCase(actions.setIsFailedGetQuoteModalOpen, (state, { payload }) => ({
...state,
isFailedGetQuoteModalOpen: payload,
}));
builder.addCase(actions.setIsSummaryModalOpen, (state, { payload }) => ({
...state,
isSummaryModalOpen: payload,
}));
});
Loading