Skip to content

Commit 97c9277

Browse files
committed
clean up
1 parent 89e4851 commit 97c9277

File tree

5 files changed

+36
-20
lines changed

5 files changed

+36
-20
lines changed

demo/pages/ui/token/[[...params]].tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ import { isSolanaWallet } from '@dynamic-labs/solana'
2424
import { adaptSolanaWallet } from '@relayprotocol/relay-svm-wallet-adapter'
2525
import {
2626
adaptViemWallet,
27-
RelayChain,
2827
type AdaptedWallet,
2928
type ChainVM
3029
} from '@relayprotocol/relay-sdk'
30+
import type { RelayChain } from '@relayprotocol/relay-sdk'
3131
import { useWalletFilter } from 'context/walletFilter'
3232
import { adaptBitcoinWallet } from '@relayprotocol/relay-bitcoin-wallet-adapter'
3333
import { isBitcoinWallet } from '@dynamic-labs/bitcoin'
@@ -225,6 +225,10 @@ const TokenWidgetPage: NextPage = () => {
225225
return
226226
}
227227

228+
setFromToken(undefined)
229+
setToToken(undefined)
230+
setTokenNotFound(false)
231+
228232
// Update the URL with the new token params
229233
setUrlTokenAddress(normalizedAddress)
230234
setUrlTokenChainId(parsedChainId)
@@ -365,7 +369,7 @@ const TokenWidgetPage: NextPage = () => {
365369
}}
366370
>
367371
<TokenWidget
368-
key={`swap-widget-${singleChainMode ? 'single' : 'multi'}-chain`}
372+
key={`swap-widget-${singleChainMode ? 'single' : 'multi'}-chain-${urlTokenAddress}-${urlTokenChainId}`}
369373
lockChainId={singleChainMode ? 8453 : undefined}
370374
singleChainMode={singleChainMode}
371375
supportedWalletVMs={supportedWalletVMs}

packages/ui/src/components/common/TokenSelector/PaymentMethod.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,9 @@ const PaymentMethod: FC<PaymentMethodProps> = ({
571571
>
572572
<FontAwesomeIcon icon={faChevronLeft} width={20} height={20} />
573573
</Button>
574-
<Text style="subtitle2">{context === 'from' ? 'Pay with' : 'Sell to'}</Text>
574+
<Text style="subtitle2">
575+
{context === 'from' ? 'Pay with' : 'Sell to'}
576+
</Text>
575577
</Flex>
576578

577579
<Flex
@@ -948,11 +950,7 @@ const ChainSearchInput: FC<ChainSearchInputProps> = ({ value, onChange }) => (
948950
placeholder="Search for a chain"
949951
icon={
950952
<Box css={{ color: 'gray9' }}>
951-
<FontAwesomeIcon
952-
icon={faMagnifyingGlass}
953-
width={16}
954-
height={16}
955-
/>
953+
<FontAwesomeIcon icon={faMagnifyingGlass} width={16} height={16} />
956954
</Box>
957955
}
958956
containerCss={{

packages/ui/src/components/widgets/TokenWidget/BuyTabContent.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -415,11 +415,12 @@ const BuyTabContent: FC<BuyTabContentProps> = ({
415415
disablePasteWalletAddressOption={disablePasteWalletAddressOption}
416416
selectedWalletAddress={address}
417417
onSelect={(wallet) => {
418-
// Always clear payment token when switching wallets
419-
// Let auto-select choose the best token for the new wallet
420418
setOriginAddressOverride(wallet.address)
421-
handleSetFromToken(undefined)
422419
onSetPrimaryWallet?.(wallet.address)
420+
421+
if (wallet.address !== address) {
422+
handleSetFromToken(undefined)
423+
}
423424
}}
424425
chain={fromChain}
425426
disableWalletFiltering={true}
@@ -455,6 +456,9 @@ const BuyTabContent: FC<BuyTabContentProps> = ({
455456
fromChainWalletVMSupported={fromChainWalletVMSupported}
456457
supportedWalletVMs={supportedWalletVMs}
457458
linkedWallets={linkedWallets}
459+
multiWalletSupportEnabled={multiWalletSupportEnabled}
460+
context="from"
461+
autoSelectToken={false}
458462
setToken={(token) => {
459463
if (
460464
token?.address === toToken?.address &&
@@ -468,8 +472,6 @@ const BuyTabContent: FC<BuyTabContentProps> = ({
468472
handleSetFromToken(token)
469473
}
470474
}}
471-
context="from"
472-
multiWalletSupportEnabled={multiWalletSupportEnabled}
473475
lockedChainIds={lockedChainIds}
474476
chainIdsFilter={
475477
!fromChainWalletVMSupported && toToken

packages/ui/src/components/widgets/TokenWidget/hooks/useWalletGuards.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ import type { Dispatch, SetStateAction } from 'react'
33
import type { RelayChain } from '@relayprotocol/relay-sdk'
44
import type { LinkedWallet } from '../../../../types/index.js'
55
import type { RelayKitProviderProps } from '../../../../providers/RelayKitProvider.js'
6-
import { addressesEqual, findSupportedWallet } from '../../../../utils/address.js'
6+
import {
7+
addressesEqual,
8+
findSupportedWallet
9+
} from '../../../../utils/address.js'
710

811
type Params = {
912
multiWalletSupportEnabled: boolean
@@ -133,7 +136,11 @@ export const useWalletGuards = ({
133136
) {
134137
setDestinationAddressOverride(undefined)
135138
}
136-
}, [destinationAddressOverride, customToAddress, setDestinationAddressOverride])
139+
}, [
140+
destinationAddressOverride,
141+
customToAddress,
142+
setDestinationAddressOverride
143+
])
137144

138145
useEffect(() => {
139146
if (!multiWalletSupportEnabled) {
@@ -147,18 +154,22 @@ export const useWalletGuards = ({
147154
}
148155

149156
if (originAddressOverride) {
150-
const originMatches = linkedWallets?.some((wallet) =>
157+
const originExists = linkedWallets?.some((wallet) =>
151158
addressesEqual(wallet.vmType, wallet.address, originAddressOverride)
152159
)
153160

154-
if (!originMatches) {
161+
if (!originExists) {
155162
setOriginAddressOverride(undefined)
156163
}
157164
}
158165

159166
if (destinationAddressOverride) {
160167
const destinationMatches = linkedWallets?.some((wallet) =>
161-
addressesEqual(wallet.vmType, wallet.address, destinationAddressOverride)
168+
addressesEqual(
169+
wallet.vmType,
170+
wallet.address,
171+
destinationAddressOverride
172+
)
162173
)
163174

164175
if (!destinationMatches) {
@@ -171,7 +182,8 @@ export const useWalletGuards = ({
171182
originAddressOverride,
172183
destinationAddressOverride,
173184
setOriginAddressOverride,
174-
setDestinationAddressOverride
185+
setDestinationAddressOverride,
186+
allowUnsupportedOrigin
175187
])
176188
}
177189

packages/ui/src/components/widgets/TokenWidget/widget/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ const TokenWidget: FC<TokenWidgetProps> = ({
235235
if (activeTab === 'buy' && !toToken && !resolvedToToken) {
236236
setResolvedToToken(resolved)
237237
setToToken?.(resolved)
238-
} else {
238+
} else if (activeTab === 'sell') {
239239
setResolvedFromToken(resolved)
240240
setFromToken?.(resolved)
241241
}

0 commit comments

Comments
 (0)