Skip to content

Commit 43a0383

Browse files
authored
Stabilised ens resolution & wallet selection (#876)
* fix ens resolution * prioritise active wallets
1 parent d45f6be commit 43a0383

File tree

2 files changed

+26
-15
lines changed

2 files changed

+26
-15
lines changed

packages/ui/src/components/common/MultiWalletDropdown.tsx

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,20 @@ export const MultiWalletDropdown: FC<MultiWalletDropdownProps> = ({
101101

102102
const showDropdown = context !== 'origin' || filteredWallets.length > 0
103103

104+
const isEnsCapableVmType =
105+
chain?.vmType === 'evm' ||
106+
chain?.vmType === 'hypevm' ||
107+
selectedWallet?.vmType === 'evm' ||
108+
selectedWallet?.vmType === 'hypevm'
109+
110+
const shouldResolveEns = isEnsCapableVmType && isSupportedSelectedWallet
111+
104112
const { displayName } = useENSResolver(selectedWalletAddress, {
105-
enabled:
106-
(chain?.vmType === 'evm' || chain?.vmType === 'hypevm') &&
107-
isSupportedSelectedWallet
113+
enabled: shouldResolveEns
108114
})
109115

116+
const shouldShowEns = isEnsCapableVmType && Boolean(displayName)
117+
110118
return (
111119
<Dropdown
112120
open={showDropdown ? open : false}
@@ -174,8 +182,7 @@ export const MultiWalletDropdown: FC<MultiWalletDropdownProps> = ({
174182
{isSupportedSelectedWallet &&
175183
selectedWalletAddress &&
176184
selectedWalletAddress != ''
177-
? displayName &&
178-
(chain?.vmType === 'evm' || chain?.vmType === 'hypevm')
185+
? shouldShowEns
179186
? displayName
180187
: truncateAddress(selectedWalletAddress)
181188
: 'Select wallet'}

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

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import type { DebouncedState } from 'usehooks-ts'
3535
import type { AdaptedWallet } from '@relayprotocol/relay-sdk'
3636
import type { LinkedWallet } from '../../../../types/index.js'
3737
import {
38+
addressesEqual,
3839
addressWithFallback,
3940
isValidAddress
4041
} from '../../../../utils/address.js'
@@ -293,22 +294,25 @@ const TokenWidgetRenderer: FC<TokenWidgetRendererProps> = ({
293294
return defaultAddress
294295
}
295296

296-
// Find the first wallet that supports the target chain's VM type
297-
const compatibleWallet = linkedWallets.find((wallet) => {
298-
// Check if wallet VM matches chain VM
299-
if (wallet.vmType !== targetChain.vmType) {
300-
return false
301-
}
302-
303-
// Additional validation for specific chains
304-
return isValidAddress(
297+
const isCompatibleWallet = (wallet: LinkedWallet) =>
298+
wallet.vmType === targetChain.vmType &&
299+
isValidAddress(
305300
targetChain.vmType,
306301
wallet.address,
307302
targetChain.id,
308303
wallet.connector,
309304
connectorKeyOverrides
310305
)
311-
})
306+
307+
const activeLinkedWallet = linkedWallets.find((wallet) =>
308+
addressesEqual(wallet.vmType, wallet.address, defaultAddress)
309+
)
310+
311+
if (activeLinkedWallet && isCompatibleWallet(activeLinkedWallet)) {
312+
return activeLinkedWallet.address
313+
}
314+
315+
const compatibleWallet = linkedWallets.find(isCompatibleWallet)
312316

313317
return compatibleWallet?.address || defaultAddress
314318
}, [

0 commit comments

Comments
 (0)