diff --git a/packages/kit/src/states/jotai/contexts/swap/actions.ts b/packages/kit/src/states/jotai/contexts/swap/actions.ts index afbc47bdccd..97ef5ce09c2 100644 --- a/packages/kit/src/states/jotai/contexts/swap/actions.ts +++ b/packages/kit/src/states/jotai/contexts/swap/actions.ts @@ -1250,9 +1250,27 @@ class ContentJotaiActionsSwap extends ContextJotaiActionsBase { type === ESwapDirectionType.FROM ? get(swapSelectFromTokenAtom()) : get(swapSelectToTokenAtom()); - const accountAddress = swapAddressInfo.address; - const accountNetworkId = swapAddressInfo.networkId; - const accountId = swapAddressInfo.accountInfo?.account?.id; + let accountAddress: string | undefined; + let accountNetworkId: string | undefined; + let accountId: string | undefined; + if (type === ESwapDirectionType.TO) { + // fetch to Token balance use FromAccount id + const toAccountInfos = + await backgroundApiProxy.serviceStaking.getEarnAccount({ + accountId: swapAddressInfo.accountInfo?.account?.id ?? '', + networkId: token?.networkId ?? '', + indexedAccountId: swapAddressInfo.accountInfo?.indexedAccount?.id, + }); + if (toAccountInfos) { + accountAddress = toAccountInfos.accountAddress; + accountNetworkId = toAccountInfos.networkId; + accountId = toAccountInfos.accountId; + } + } else { + accountAddress = swapAddressInfo.address; + accountNetworkId = swapAddressInfo.networkId; + accountId = swapAddressInfo.accountInfo?.account?.id; + } let balanceDisplay; if ( token && diff --git a/packages/kit/src/states/jotai/contexts/swap/atoms.ts b/packages/kit/src/states/jotai/contexts/swap/atoms.ts index 129985a54ae..5286c135419 100644 --- a/packages/kit/src/states/jotai/contexts/swap/atoms.ts +++ b/packages/kit/src/states/jotai/contexts/swap/atoms.ts @@ -299,6 +299,9 @@ export const { return manualSelectQuoteResult; } if (list?.length > 0) { + if (!manualSelectQuoteProviders?.unSupportReceiveAddressDifferent) { + return list.find((item) => !item.unSupportReceiveAddressDifferent); + } return list[0]; } return undefined; diff --git a/packages/kit/src/views/Swap/pages/components/SwapActionsState.tsx b/packages/kit/src/views/Swap/pages/components/SwapActionsState.tsx index b2fbda3e663..cb961178270 100644 --- a/packages/kit/src/views/Swap/pages/components/SwapActionsState.tsx +++ b/packages/kit/src/views/Swap/pages/components/SwapActionsState.tsx @@ -33,10 +33,7 @@ import { useSwapAddressInfo, useSwapRecipientAddressInfo, } from '../../hooks/useSwapAccount'; -import { - useSwapActionState, - useSwapQuoteLoading, -} from '../../hooks/useSwapState'; +import { useSwapActionState } from '../../hooks/useSwapState'; interface ISwapActionsStateProps { onBuildTx: () => void; diff --git a/packages/kit/src/views/Swap/pages/modal/SwapToAnotherAddressModal.tsx b/packages/kit/src/views/Swap/pages/modal/SwapToAnotherAddressModal.tsx index 620399f79d3..d9207f5d368 100644 --- a/packages/kit/src/views/Swap/pages/modal/SwapToAnotherAddressModal.tsx +++ b/packages/kit/src/views/Swap/pages/modal/SwapToAnotherAddressModal.tsx @@ -17,7 +17,11 @@ import { AccountSelectorProviderMirror } from '@onekeyhq/kit/src/components/Acco import type { IAddressInputValue } from '@onekeyhq/kit/src/components/AddressInput'; import { AddressInput } from '@onekeyhq/kit/src/components/AddressInput'; import useAppNavigation from '@onekeyhq/kit/src/hooks/useAppNavigation'; -import { useSwapToAnotherAccountAddressAtom } from '@onekeyhq/kit/src/states/jotai/contexts/swap'; +import { + useSwapManualSelectQuoteProvidersAtom, + useSwapQuoteCurrentSelectAtom, + useSwapToAnotherAccountAddressAtom, +} from '@onekeyhq/kit/src/states/jotai/contexts/swap'; import { useSettingsAtom } from '@onekeyhq/kit-bg/src/states/jotai/atoms'; import { ETranslations } from '@onekeyhq/shared/src/locale'; import type { @@ -52,6 +56,8 @@ const SwapToAnotherAddressPage = () => { const [, setSettings] = useSettingsAtom(); const [, setSwapToAddress] = useSwapToAnotherAccountAddressAtom(); + const [selectedQuote] = useSwapQuoteCurrentSelectAtom(); + const [, setSwapManualSelectQuote] = useSwapManualSelectQuoteProvidersAtom(); const intl = useIntl(); const form = useForm({ defaultValues: { @@ -91,9 +97,17 @@ const SwapToAnotherAddressPage = () => { networkId: activeAccount?.network?.id, accountInfo: activeAccount, })); + setSwapManualSelectQuote(selectedQuote); navigation.pop(); }, - [activeAccount, navigation, setSettings, setSwapToAddress], + [ + activeAccount, + navigation, + selectedQuote, + setSettings, + setSwapManualSelectQuote, + setSwapToAddress, + ], ); const handleOnCancel = useCallback(() => {