@@ -10,14 +10,19 @@ import { EventNames } from '../../constants/events.js'
1010import type { Token } from '../../types/index.js'
1111import {
1212 faCircleCheck ,
13- faTriangleExclamation
13+ faTriangleExclamation ,
14+ faClipboard
1415} from '@fortawesome/free-solid-svg-icons'
1516import { AnchorButton } from '../primitives/Anchor.js'
1617import type { AdaptedWallet , RelayChain } from '@relayprotocol/relay-sdk'
1718import type { LinkedWallet } from '../../types/index.js'
1819import { truncateAddress } from '../../utils/truncate.js'
1920import { isValidAddress } from '../../utils/address.js'
2021import { ProviderOptionsContext } from '../../providers/RelayKitProvider.js'
22+ import {
23+ addCustomAddress ,
24+ getCustomAddresses
25+ } from '../../utils/localStorage.js'
2126
2227type Props = {
2328 open : boolean
@@ -50,6 +55,9 @@ export const CustomAddressModal: FC<Props> = ({
5055 const connectedAddress = useWalletAddress ( wallet , linkedWallets )
5156 const [ address , setAddress ] = useState ( '' )
5257 const [ input , setInput ] = useState ( '' )
58+ const [ recentCustomAddresses , setRecentCustomAddresses ] = useState < string [ ] > (
59+ [ ]
60+ )
5361 const providerOptionsContext = useContext ( ProviderOptionsContext )
5462 const connectorKeyOverrides = providerOptionsContext . vmConnectorKeyOverrides
5563
@@ -67,6 +75,14 @@ export const CustomAddressModal: FC<Props> = ({
6775 [ toChain , linkedWallets ]
6876 )
6977
78+ const filteredRecentCustomAddresses = useMemo (
79+ ( ) =>
80+ recentCustomAddresses . filter ( ( address ) =>
81+ isValidAddress ( toChain ?. vmType , address , toChain ?. id )
82+ ) ,
83+ [ recentCustomAddresses , toChain ]
84+ )
85+
7086 const connectedAddressSet =
7187 ( ! address && ! toAddress ) ||
7288 ( toAddress === connectedAddress && address === connectedAddress ) ||
@@ -81,6 +97,8 @@ export const CustomAddressModal: FC<Props> = ({
8197 setAddress ( toAddress ? toAddress : '' )
8298 setInput ( toAddress ? toAddress : '' )
8399 }
100+ // Load custom addresses when modal opens
101+ setRecentCustomAddresses ( getCustomAddresses ( ) )
84102 onAnalyticEvent ?.( EventNames . ADDRESS_MODAL_OPEN )
85103 }
86104 } , [ open ] )
@@ -210,38 +228,39 @@ export const CustomAddressModal: FC<Props> = ({
210228 )
211229 ) : null }
212230
213- { multiWalletSupportEnabled && availableWallets . length > 0 ? (
231+ { filteredRecentCustomAddresses . length > 0 ? (
214232 < >
215- < Text style = "subtitle2" > Use connected wallet address </ Text >
233+ < Text style = "subtitle2" > Recent addresses </ Text >
216234 < Flex css = { { gap : '2' , flexWrap : 'wrap' } } align = "center" >
217- { availableWallets . map ( ( wallet ) => (
235+ { filteredRecentCustomAddresses . map ( ( address ) => (
218236 < Pill
219- key = { wallet . address }
237+ key = { address }
220238 color = "transparent"
221239 bordered
222240 radius = "squared"
223241 css = { {
224242 display : 'flex' ,
225243 alignItems : 'center' ,
226244 gap : '6px' ,
227- cursor : 'pointer'
245+ cursor : 'pointer' ,
246+ px : '8px'
228247 } }
229248 onClick = { ( ) => {
230- onConfirmed ( wallet . address )
249+ onConfirmed ( address )
231250 onOpenChange ( false )
232251 onAnalyticEvent ?.( EventNames . ADDRESS_MODAL_CONFIRMED , {
233- address : wallet . address ,
234- context : 'linked_wallet '
252+ address : address ,
253+ context : 'custom_address '
235254 } )
236255 } }
237256 >
238- < img
239- src = { wallet . walletLogoUrl }
240- style = { { width : 16 , height : 16 , borderRadius : 4 } }
257+ < FontAwesomeIcon
258+ icon = { faClipboard }
259+ width = { 16 }
260+ height = { 16 }
261+ color = "#9CA3AF"
241262 />
242- < Text style = "subtitle2" >
243- { truncateAddress ( wallet . address ) }
244- </ Text >
263+ < Text style = "subtitle2" > { truncateAddress ( address ) } </ Text >
245264 </ Pill >
246265 ) ) }
247266 </ Flex >
@@ -254,6 +273,15 @@ export const CustomAddressModal: FC<Props> = ({
254273 css = { { justifyContent : 'center' } }
255274 onClick = { ( ) => {
256275 if ( isValidAddress ( toChain ?. vmType , address , toChain ?. id ) ) {
276+ // Save the address to custom addresses if it's not a connected wallet address
277+ const isConnectedWallet = availableWallets . some (
278+ ( wallet ) => wallet . address === address
279+ )
280+ if ( ! isConnectedWallet && address !== connectedAddress ) {
281+ addCustomAddress ( address )
282+ setRecentCustomAddresses ( getCustomAddresses ( ) )
283+ }
284+
257285 onConfirmed ( address )
258286 onAnalyticEvent ?.( EventNames . ADDRESS_MODAL_CONFIRMED , {
259287 address : address ,
0 commit comments