@@ -11,7 +11,7 @@ import { Divider } from '@relayprotocol/relay-design-system/jsx'
1111import { MultiWalletDropdown } from '../../common/MultiWalletDropdown.js'
1212import PaymentMethod from '../../common/TokenSelector/PaymentMethod.js'
1313import { PaymentMethodTrigger } from '../../common/TokenSelector/triggers/PaymentMethodTrigger.js'
14- import { useMemo , useRef } from 'react'
14+ import { useMemo , useRef , useEffect } from 'react'
1515import type { Dispatch , FC , SetStateAction } from 'react'
1616import type { TradeType , ChildrenProps } from './widget/TokenWidgetRenderer.js'
1717import type { Token , LinkedWallet } from '../../../types/index.js'
@@ -242,7 +242,48 @@ const SellTabContent: FC<SellTabContentProps> = ({
242242 const toTokenRef = useRef ( toToken )
243243 toTokenRef . current = toToken
244244
245- // Use ctaCopy for wallet/address prompts, override transaction operations to "Sell"
245+ const hasAutoSelectedDestination = useRef ( false )
246+
247+ // Auto-select the user's primary wallet as the destination for selling
248+ useEffect ( ( ) => {
249+ if (
250+ ! hasAutoSelectedDestination . current &&
251+ multiWalletSupportEnabled &&
252+ address &&
253+ isValidFromAddress &&
254+ ! recipient
255+ ) {
256+ setDestinationAddressOverride ( address )
257+ hasAutoSelectedDestination . current = true
258+ }
259+ } , [
260+ multiWalletSupportEnabled ,
261+ address ,
262+ isValidFromAddress ,
263+ recipient ,
264+ setDestinationAddressOverride
265+ ] )
266+
267+ // Smart auto-selection for destination token when selling to same wallet
268+ useEffect ( ( ) => {
269+ if (
270+ recipient === address &&
271+ fromToken &&
272+ ! toToken &&
273+ isValidToAddress &&
274+ multiWalletSupportEnabled
275+ ) {
276+ // let user manually select the destination token
277+ }
278+ } , [
279+ recipient ,
280+ address ,
281+ fromToken ,
282+ toToken ,
283+ isValidToAddress ,
284+ multiWalletSupportEnabled
285+ ] )
286+
246287 const displayCta = [
247288 'Swap' ,
248289 'Confirm' ,
@@ -444,13 +485,21 @@ const SellTabContent: FC<SellTabContentProps> = ({
444485 >
445486 { ( ( ) => {
446487 const displayToken = fromToken || toToken
447- const displayBalance = fromToken ? fromBalance : toBalance
488+ const displayBalance = fromToken
489+ ? fromBalance
490+ : toToken && recipient !== address
491+ ? fromBalance
492+ : toBalance
448493 const displayBalancePending = fromToken
449494 ? fromBalancePending
450- : toBalancePending
495+ : toToken && recipient !== address
496+ ? fromBalancePending
497+ : toBalancePending
451498 const isLoadingDisplayBalance = fromToken
452499 ? isLoadingFromBalance
453- : isLoadingToBalance
500+ : toToken && recipient !== address
501+ ? isLoadingFromBalance
502+ : isLoadingToBalance
454503
455504 return displayToken ? (
456505 < BalanceDisplay
@@ -564,7 +613,6 @@ const SellTabContent: FC<SellTabContentProps> = ({
564613 onSelect : ( wallet ) => {
565614 setDestinationAddressOverride ( wallet . address )
566615 setCustomToAddress ( undefined )
567- // Always reset payment method when switching wallets (like buy tab)
568616 handleSetToToken ( undefined )
569617 } ,
570618 chain : toChain ,
@@ -627,19 +675,16 @@ const SellTabContent: FC<SellTabContentProps> = ({
627675 chainIdsFilter = { chainIdsFilterForDestination }
628676 linkedWallets = { linkedWallets }
629677 context = "to"
630- autoSelectToken = { false }
678+ autoSelectToken = { true }
631679 setToken = { ( token ) => {
632680 if (
633681 token ?. address === fromToken ?. address &&
634682 token ?. chainId === fromToken ?. chainId &&
635- recipient === address &&
636- ( ! lockFromToken || ! toToken )
683+ recipient === address
637684 ) {
638- handleSetToToken ( fromToken )
639- handleSetFromToken ( toToken )
640- } else {
641- handleSetToToken ( token )
685+ return
642686 }
687+ handleSetToToken ( token )
643688 } }
644689 trigger = {
645690 < div style = { { width : 'max-content' } } >
0 commit comments