11"use client" ;
22import { ChevronLeftIcon } from "@radix-ui/react-icons" ;
3- import { useEffect , useRef , useState } from "react" ;
3+ import { useEffect , useMemo , useRef , useState } from "react" ;
44import type { Chain } from "../../../../chains/types.js" ;
55import type { ThirdwebClient } from "../../../../client/client.js" ;
66import type { InjectedSupportedWalletIds } from "../../../../wallets/__generated__/wallet-ids.js" ;
@@ -19,6 +19,7 @@ import {
1919import { useSetSelectionData } from "../../providers/wallet-ui-states-provider.js" ;
2020import { sortWallets } from "../../utils/sortWallets.js" ;
2121import InAppWalletSelectionUI from "../../wallets/in-app/InAppWalletSelectionUI.js" ;
22+ import { LAST_USED_BADGE_VERTICAL_RESERVED_SPACE } from "../components/badge.js" ;
2223import {
2324 Container ,
2425 Line ,
@@ -38,6 +39,7 @@ import { OutlineWalletIcon } from "./icons/OutlineWalletIcon.js";
3839import type { ConnectLocale } from "./locale/types.js" ;
3940import { SmartConnectUI } from "./Modal/SmartWalletConnectUI.js" ;
4041import { useScreenContext } from "./Modal/screen.js" ;
42+ import { getLastUsedWalletId } from "./Modal/storage.js" ;
4143import { TOS } from "./Modal/TOS.js" ;
4244import { PoweredByThirdweb } from "./PoweredByTW.js" ;
4345import { WalletButtonEl , WalletEntryButton } from "./WalletEntryButton.js" ;
@@ -136,6 +138,7 @@ const WalletSelectorInner: React.FC<WalletSelectorProps> = (props) => {
136138 const [ approvedTOS , setApprovedTOS ] = useState ( false ) ;
137139
138140 const installedWallets = getInstalledWallets ( ) ;
141+ const lastUsedWalletId = useMemo ( ( ) => getLastUsedWalletId ( ) , [ ] ) ;
139142 const propsWallets = props . wallets ;
140143 let _wallets : Wallet [ ] = [ ...propsWallets ] ;
141144
@@ -219,6 +222,11 @@ const WalletSelectorInner: React.FC<WalletSelectorProps> = (props) => {
219222 const connectAWallet = (
220223 < WalletTypeRowButton
221224 className = "tw-select-connect-a-wallet-button"
225+ lastUsedBadge = {
226+ ! ! lastUsedWalletId &&
227+ lastUsedWalletId !== "inApp" &&
228+ ! lastUsedWalletId . startsWith ( "ecosystem." )
229+ }
222230 client = { props . client }
223231 disabled = { props . meta . requireApproval && ! approvedTOS }
224232 icon = { OutlineWalletIcon }
@@ -497,7 +505,7 @@ const WalletSelectorInner: React.FC<WalletSelectorProps> = (props) => {
497505 >
498506 { /* Header */ }
499507 { showHeader && (
500- < Container p = "lg" >
508+ < Container px = "lg" pt = "lg" pb = "xs ">
501509 { isWalletGroupExpanded ? (
502510 < ModalHeader
503511 onBack = { ( ) => {
@@ -514,41 +522,42 @@ const WalletSelectorInner: React.FC<WalletSelectorProps> = (props) => {
514522 { /* Body */ }
515523 < Container
516524 expand
517- px = "md"
518525 scrollY
519526 style = {
520527 ! showHeader
521528 ? {
522- paddingTop : spacing . lg ,
529+ paddingTop : spacing . md ,
523530 }
524531 : {
525532 paddingTop : "2px" ,
526533 }
527534 }
528535 >
529536 { ! showHeader && isWalletGroupExpanded && (
530- < Container
531- center = "y"
532- flex = "row"
533- style = { {
534- padding : spacing . sm ,
535- paddingTop : 0 ,
536- } }
537- >
538- < IconButton
539- onClick = { ( ) => {
540- setIsWalletGroupExpanded ( false ) ;
541- } }
537+ < Container px = "md" >
538+ < Container
539+ center = "y"
540+ flex = "row"
542541 style = { {
543- gap : spacing . xxs ,
544- paddingBlock : spacing . xxs ,
545- paddingRight : spacing . xs ,
546- transform : `translateX(-${ spacing . xs } )` ,
542+ padding : spacing . sm ,
543+ paddingTop : 0 ,
547544 } }
548545 >
549- < ChevronLeftIcon height = { iconSize . sm } width = { iconSize . sm } />
550- { props . connectLocale . goBackButton }
551- </ IconButton >
546+ < IconButton
547+ onClick = { ( ) => {
548+ setIsWalletGroupExpanded ( false ) ;
549+ } }
550+ style = { {
551+ gap : spacing . xxs ,
552+ paddingBlock : spacing . xxs ,
553+ paddingRight : spacing . xs ,
554+ transform : `translateX(-${ spacing . xs } )` ,
555+ } }
556+ >
557+ < ChevronLeftIcon height = { iconSize . sm } width = { iconSize . sm } />
558+ { props . connectLocale . goBackButton }
559+ </ IconButton >
560+ </ Container >
552561 </ Container >
553562 ) }
554563
@@ -602,11 +611,16 @@ const WalletSelection: React.FC<{
602611 const wallets = sortWallets ( props . wallets , props . recommendedWallets ) ;
603612 const { screen } = useScreenContext ( ) ;
604613 const setSelectionData = useSetSelectionData ( ) ;
614+
615+ const lastUsedWalletId = useMemo ( ( ) => getLastUsedWalletId ( ) , [ ] ) ;
616+
605617 return (
606618 < WalletList
607619 style = { {
608620 maxHeight : "370px" ,
609621 minHeight : "100%" ,
622+ paddingTop :
623+ props . size === "wide" ? 0 : LAST_USED_BADGE_VERTICAL_RESERVED_SPACE ,
610624 } }
611625 >
612626 { wallets . map ( ( wallet ) => {
@@ -634,7 +648,7 @@ const WalletSelection: React.FC<{
634648 ) : (
635649 < WalletEntryButton
636650 className = "tw-wallet-select-wallet-button"
637- badge = { undefined }
651+ badge = { lastUsedWalletId === wallet . id ? "Last used" : undefined }
638652 client = { props . client }
639653 connectLocale = { props . connectLocale }
640654 isActive = { isActive }
@@ -730,7 +744,7 @@ const WalletList = /* @__PURE__ */ StyledUl({
730744 margin : "-2px" ,
731745 marginBottom : 0 ,
732746 // to show the box-shadow of inputs that overflows
733- padding : "2px" ,
747+ paddingInline : spacing . md ,
734748 paddingBottom : spacing . lg ,
735749} ) ;
736750
0 commit comments