Skip to content

Commit

Permalink
Merge pull request #240 from bnb-chain/feat/sendConfirmPopup1230
Browse files Browse the repository at this point in the history
feat: Fail to load quote modal
  • Loading branch information
Halibao-Lala authored Jan 3, 2025
2 parents 28b1272 + f9cf504 commit 05c71d7
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 7 deletions.
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
13 changes: 13 additions & 0 deletions packages/canonical-bridge-widget/src/modules/transfer/reducer.ts
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,
}));
});

0 comments on commit 05c71d7

Please sign in to comment.