@@ -5,6 +5,7 @@ import type { ThirdwebClient } from "../../../../../../client/client.js";
55import { NATIVE_TOKEN_ADDRESS } from "../../../../../../constants/addresses.js" ;
66import type { BuyWithCryptoStatus } from "../../../../../../pay/buyWithCrypto/getStatus.js" ;
77import type { BuyWithFiatStatus } from "../../../../../../pay/buyWithFiat/getStatus.js" ;
8+ import { formatNumber } from "../../../../../../utils/formatNumber.js" ;
89import type { Account } from "../../../../../../wallets/interfaces/wallet.js" ;
910import type { WalletId } from "../../../../../../wallets/wallet-types.js" ;
1011import {
@@ -56,6 +57,7 @@ import { FiatValue } from "./swap/FiatValue.js";
5657import { PaymentSelectionScreen } from "./swap/PaymentSelectionScreen.js" ;
5758import { SwapFlow } from "./swap/SwapFlow.js" ;
5859import { SwapScreenContent } from "./swap/SwapScreenContent.js" ;
60+ import { TokenSelectorScreen } from "./swap/TokenSelectorScreen.js" ;
5961import { TransferFlow } from "./swap/TransferFlow.js" ;
6062import {
6163 type SupportedChainAndTokens ,
@@ -453,30 +455,39 @@ function BuyScreenContent(props: BuyScreenContentProps) {
453455 }
454456
455457 return (
456- < TokenSelector
458+ < TokenSelectorScreen
457459 onBack = { goBack }
458- tokenList = { (
459- ( fromChain ?. id ? sourceSupportedTokens [ fromChain . id ] : undefined ) ||
460- [ ]
461- ) . filter ( ( x ) => x . address !== NATIVE_TOKEN_ADDRESS ) }
462- onTokenSelect = { ( tokenInfo ) => {
463- setFromToken ( tokenInfo ) ;
460+ onConnect = { ( ) => {
461+ setScreen ( {
462+ id : "connect-payer-wallet" ,
463+ backScreen : screen ,
464+ } ) ;
465+ } }
466+ modalTitle = "Available tokens"
467+ connectLocale = { props . connectLocale }
468+ client = { props . client }
469+ sourceTokens = { sourceSupportedTokens }
470+ sourceSupportedTokens = { sourceSupportedTokens }
471+ toChain = { toChain }
472+ toToken = { toToken }
473+ tokenAmount = { tokenAmount }
474+ fromChain = { fromChain }
475+ fromToken = { fromToken }
476+ mode = { payOptions . mode }
477+ hiddenWallets = { props . hiddenWallets }
478+ onSelect = { ( w , token , chain ) => {
479+ const account = w . getAccount ( ) ;
480+ if ( account ) {
481+ setPayer ( {
482+ account,
483+ chain,
484+ wallet : w ,
485+ } ) ;
486+ setFromToken ( token ) ;
487+ setFromChain ( chain ) ;
488+ }
464489 goBack ( ) ;
465490 } }
466- chain = { fromChain }
467- chainSelection = {
468- // hide chain selection if it's disabled
469- payOptions . buyWithCrypto !== false &&
470- payOptions . buyWithCrypto ?. prefillSource ?. allowEdits ?. chain !== false
471- ? {
472- chains : supportedSourcesQuery . data . map ( ( x ) => x . chain ) ,
473- select : ( c ) => setFromChain ( c ) ,
474- }
475- : undefined
476- }
477- connectLocale = { connectLocale }
478- client = { client }
479- modalTitle = "Pay with"
480491 />
481492 ) ;
482493 }
@@ -550,23 +561,23 @@ function BuyScreenContent(props: BuyScreenContentProps) {
550561 payWithFiatEnabled = { props . payOptions . buyWithFiat !== false }
551562 toChain = { toChain }
552563 toToken = { toToken }
564+ fromToken = { fromToken }
565+ fromChain = { fromChain }
553566 tokenAmount = { tokenAmount }
554- onSelect = { ( w , token , chain ) => {
555- const account = w . getAccount ( ) ;
556- if ( account ) {
557- setPayer ( {
558- account,
559- chain,
560- wallet : w ,
561- } ) ;
562- setFromToken ( token ) ;
563- setFromChain ( chain ) ;
564- setScreen ( { id : "buy-with-crypto" } ) ;
565- }
567+ onContinue = { ( ) => {
568+ setScreen ( { id : "buy-with-crypto" } ) ;
566569 } }
567570 onSelectFiat = { ( ) => {
568571 setScreen ( { id : "buy-with-fiat" } ) ;
569572 } }
573+ onPickToken = { ( ) => {
574+ setScreen ( {
575+ id : "select-from-token" ,
576+ backScreen : {
577+ id : "select-payment-method" ,
578+ } ,
579+ } ) ;
580+ } }
570581 showAllWallets = { ! ! props . connectOptions ?. showAllWallets }
571582 wallets = { props . connectOptions ?. wallets }
572583 onBack = { ( ) => {
@@ -659,8 +670,9 @@ function SelectedTokenInfo(props: {
659670 disabled ?: boolean ;
660671} ) {
661672 const getWidth = ( ) => {
662- let chars = props . tokenAmount . replace ( "." , "" ) . length ;
663- const hasDot = props . tokenAmount . includes ( "." ) ;
673+ const amount = formatNumber ( Number ( props . tokenAmount ) , 5 ) . toString ( ) ;
674+ let chars = amount . replace ( "." , "" ) . length ;
675+ const hasDot = amount . includes ( "." ) ;
664676 if ( hasDot ) {
665677 chars += 0.3 ;
666678 }
@@ -685,7 +697,11 @@ function SelectedTokenInfo(props: {
685697 placeholder = "0"
686698 type = "text"
687699 data-placeholder = { props . tokenAmount === "" }
688- value = { props . tokenAmount || "0" }
700+ value = {
701+ props . tokenAmount
702+ ? formatNumber ( Number ( props . tokenAmount ) , 5 )
703+ : "0"
704+ }
689705 disabled = { props . disabled }
690706 onClick = { ( e ) => {
691707 // put cursor at the end of the input
@@ -885,7 +901,7 @@ function MainScreen(props: {
885901 client = { props . client }
886902 />
887903
888- < Spacer y = "xl " />
904+ < Spacer y = "md " />
889905
890906 { /* Continue */ }
891907 < Container flex = "column" gap = "sm" >
0 commit comments