Skip to content

Commit

Permalink
Merge pull request #245 from bnb-chain/feat/sendConfirmPopup1230
Browse files Browse the repository at this point in the history
Feat/send confirm popup1230
  • Loading branch information
Halibao-Lala authored Jan 6, 2025
2 parents 05c71d7 + dd76ecd commit 432c749
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .release/.changeset/hot-knives-pay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@bnb-chain/canonical-bridge-widget": patch
---

feat: Send confirm popup
11 changes: 11 additions & 0 deletions .release/.changeset/pre.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"mode": "pre",
"tag": "alpha",
"initialVersions": {
"@bnb-chain/canonical-bridge-sdk": "0.4.6",
"@bnb-chain/canonical-bridge-widget": "0.5.16"
},
"changesets": [
"hot-knives-pay"
]
}
6 changes: 6 additions & 0 deletions packages/canonical-bridge-widget/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @bnb-chain/canonical-bridge-widget

## 0.5.17-alpha.0

### Patch Changes

- feat: Send confirm popup

## 0.5.16

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/canonical-bridge-widget/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bnb-chain/canonical-bridge-widget",
"version": "0.5.16",
"version": "0.5.17-alpha.0",
"description": "canonical bridge widget",
"author": "bnb-chain",
"private": false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const WarningMessage = ({ text, ...restProps }: { text: React.ReactNode }
{...restProps}
>
<InfoIcon
transform={'rotate(180deg)'}
w={'16px'}
h={'16px'}
iconcolor={theme.colors[colorMode].text.warning}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { useAppDispatch, useAppSelector } from '@/modules/store/StoreProvider';
import {
setEstimatedAmount,
setIsGlobalFeeLoading,
setIsSummaryModalOpen,
setRouteError,
setRouteFees,
} from '@/modules/transfer/action';
Expand All @@ -34,6 +35,7 @@ import { formatNumber } from '@/core/utils/number';
import { useSolanaAccount } from '@/modules/wallet/hooks/useSolanaAccount';
import { useSolanaTransferInfo } from '@/modules/transfer/hooks/solana/useSolanaTransferInfo';
import { useIsWalletCompatible } from '@/modules/wallet/hooks/useIsWalletCompatible';
import { useFailGetQuoteModal } from '@/modules/transfer/hooks/modal/useFailGetQuoteModal';

let lastTime = Date.now();

Expand Down Expand Up @@ -77,6 +79,7 @@ export const useLoadingBridgeFees = () => {
layerZeroFeeSorting.current = _layerZeroFeeSorting;

const { mesonFeeSorting: _mesonFeeSorting } = useGetMesonFees();
const { onOpenFailedGetQuoteModal } = useFailGetQuoteModal();
const mesonFeeSorting = useRef(_mesonFeeSorting);
mesonFeeSorting.current = _mesonFeeSorting;

Expand All @@ -89,6 +92,7 @@ export const useLoadingBridgeFees = () => {
const toChain = useAppSelector((state) => state.transfer.toChain);
const max_slippage = useAppSelector((state) => state.transfer.slippage);
const toAccount = useAppSelector((state) => state.transfer.toAccount);
const isSummaryModalOpen = useAppSelector((state) => state.transfer.isSummaryModalOpen);

// Avoid `loadBridgeFees` to be repeatedly executed during toAccount input
const toAccountRef = useRef<string | undefined>(toAccount.address);
Expand All @@ -103,6 +107,9 @@ export const useLoadingBridgeFees = () => {
const selectedBridgeTypeRef = useRef<BridgeType | undefined>(transferActionInfo?.bridgeType);
selectedBridgeTypeRef.current = transferActionInfo?.bridgeType;

const isSummaryModalOpenRef = useRef(isSummaryModalOpen);
isSummaryModalOpenRef.current = isSummaryModalOpen;

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const publicClient = usePublicClient({ chainId: fromChain?.id }) as any;
const debouncedSendValue = useDebounce(sendValue, DEBOUNCE_DELAY);
Expand Down Expand Up @@ -407,12 +414,27 @@ export const useLoadingBridgeFees = () => {
dispatch(setEstimatedAmount({ layerZero: undefined }));
}

// Check if pre select route is failed
if (
selectedBridgeTypeRef.current &&
valueArr.length === 0 &&
isSummaryModalOpenRef.current === true
) {
dispatch(setIsSummaryModalOpen(false));
onOpenFailedGetQuoteModal();
}

// pre-select best route
if (valueArr.length > 0) {
const lastValue = valueArr.find(
(e) => !e.isDisplayError && e.type === selectedBridgeTypeRef.current,
);

// eslint-disable-next-line no-console
console.log('lastValue', lastValue);
if (lastValue?.type === 'stargate' && isSummaryModalOpenRef.current === true) {
dispatch(setIsSummaryModalOpen(false));
onOpenFailedGetQuoteModal();
}
const highestValue = valueArr.reduce(
(max, entry) =>
Number(entry['value']) > Number(max['value']) &&
Expand Down Expand Up @@ -460,6 +482,7 @@ export const useLoadingBridgeFees = () => {
isWalletCompatible,
nativeToken,
preSelectRoute,
onOpenFailedGetQuoteModal,
],
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@ 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 @@ -64,9 +62,6 @@ export const usePreSelectRoute = () => {
bridgeAddress: fromChain?.meson?.raw?.address as `0x${string}`,
}),
);
} else {
// Can not find the route
onOpenFailedGetQuoteModal();
}
},
[
Expand All @@ -75,7 +70,6 @@ export const usePreSelectRoute = () => {
selectedToken?.stargate?.raw?.address,
cBridgeAddress,
fromChain,
onOpenFailedGetQuoteModal,
],
);

Expand Down

0 comments on commit 432c749

Please sign in to comment.