@@ -12,7 +12,10 @@ import { COUNTRY_CODES, FIAT_COUNTRY } from '../../constants/CountryConstants'
1212import { useHandler } from '../../hooks/useHandler'
1313import { useRampPlugins } from '../../hooks/useRampPlugins'
1414import { useRampQuotes } from '../../hooks/useRampQuotes'
15- import { useSupportedPlugins } from '../../hooks/useSupportedPlugins'
15+ import {
16+ type SupportedPluginResult ,
17+ useSupportedPlugins
18+ } from '../../hooks/useSupportedPlugins'
1619import { useWatch } from '../../hooks/useWatch'
1720import { lstrings } from '../../locales/strings'
1821import type {
@@ -53,6 +56,47 @@ export interface TradeCreateParams {
5356
5457interface Props extends BuyTabSceneProps < 'pluginListBuy' > { }
5558
59+ // Helper function to determine which input types should be disabled
60+ interface AmountTypeSupport {
61+ fiatInputDisabled : boolean
62+ cryptoInputDisabled : boolean
63+ }
64+
65+ function getAmountTypeSupport (
66+ supportedPlugins : SupportedPluginResult [ ]
67+ ) : AmountTypeSupport {
68+ if ( supportedPlugins . length === 0 ) {
69+ return { fiatInputDisabled : false , cryptoInputDisabled : false }
70+ }
71+
72+ // Collect all supported amount types from all plugins
73+ const allSupportedTypes = new Set < 'fiat' | 'crypto' > ( )
74+
75+ for ( const { supportResult } of supportedPlugins ) {
76+ if ( supportResult . supportedAmountTypes != null ) {
77+ for ( const type of supportResult . supportedAmountTypes ) {
78+ allSupportedTypes . add ( type )
79+ }
80+ } else {
81+ // If a plugin doesn't specify supported types, assume both are supported
82+ allSupportedTypes . add ( 'fiat' )
83+ allSupportedTypes . add ( 'crypto' )
84+ }
85+ }
86+
87+ // If all plugins only support fiat, disable crypto input
88+ const onlyFiat =
89+ allSupportedTypes . has ( 'fiat' ) && ! allSupportedTypes . has ( 'crypto' )
90+ // If all plugins only support crypto, disable fiat input
91+ const onlyCrypto =
92+ allSupportedTypes . has ( 'crypto' ) && ! allSupportedTypes . has ( 'fiat' )
93+
94+ return {
95+ fiatInputDisabled : onlyCrypto ,
96+ cryptoInputDisabled : onlyFiat
97+ }
98+ }
99+
56100export const TradeCreateScene : React . FC < Props > = ( props : Props ) => {
57101 const { navigation, route } = props
58102 const { regionCode : initialRegionCode , forcedWalletResult } =
@@ -189,6 +233,10 @@ export const TradeCreateScene: React.FC<Props> = (props: Props) => {
189233 return info ?. logoUrl ?? ''
190234 } , [ selectedFiatCurrencyCode ] )
191235
236+ // Determine which input types should be disabled
237+ const { fiatInputDisabled, cryptoInputDisabled } =
238+ getAmountTypeSupport ( supportedPlugins )
239+
192240 // Create rampQuoteRequest based on current form state
193241 const rampQuoteRequest : RampQuoteRequest | null = React . useMemo ( ( ) => {
194242 if (
@@ -201,6 +249,14 @@ export const TradeCreateScene: React.FC<Props> = (props: Props) => {
201249 return null
202250 }
203251
252+ // Guard against creating request with disabled input type
253+ if (
254+ ( lastUsedInput === 'fiat' && fiatInputDisabled ) ||
255+ ( lastUsedInput === 'crypto' && cryptoInputDisabled )
256+ ) {
257+ return null
258+ }
259+
204260 return {
205261 wallet : selectedWallet ,
206262 pluginId : selectedWallet . currencyInfo . pluginId ,
@@ -224,7 +280,9 @@ export const TradeCreateScene: React.FC<Props> = (props: Props) => {
224280 selectedFiatCurrencyCode ,
225281 lastUsedInput ,
226282 countryCode ,
227- stateProvinceCode
283+ stateProvinceCode ,
284+ fiatInputDisabled ,
285+ cryptoInputDisabled
228286 ] )
229287
230288 // Fetch quotes using the custom hook
@@ -236,7 +294,7 @@ export const TradeCreateScene: React.FC<Props> = (props: Props) => {
236294 } = useRampQuotes ( {
237295 rampQuoteRequest,
238296 plugins : Object . fromEntries (
239- supportedPlugins . map ( plugin => [ plugin . pluginId , plugin ] )
297+ supportedPlugins . map ( result => [ result . plugin . pluginId , result . plugin ] )
240298 )
241299 } )
242300
@@ -301,6 +359,9 @@ export const TradeCreateScene: React.FC<Props> = (props: Props) => {
301359
302360 // Derived state for display values
303361 const displayFiatAmount = React . useMemo ( ( ) => {
362+ // Don't show any value if fiat input is disabled
363+ if ( fiatInputDisabled ) return ''
364+
304365 if ( isMaxAmount && bestQuote != null ) {
305366 return bestQuote . fiatAmount
306367 }
@@ -312,9 +373,19 @@ export const TradeCreateScene: React.FC<Props> = (props: Props) => {
312373 // User entered crypto, convert to fiat only if we have a quote
313374 return convertCryptoToFiat ( userInput )
314375 }
315- } , [ userInput , lastUsedInput , convertCryptoToFiat , isMaxAmount , bestQuote ] )
376+ } , [
377+ userInput ,
378+ lastUsedInput ,
379+ convertCryptoToFiat ,
380+ isMaxAmount ,
381+ bestQuote ,
382+ fiatInputDisabled
383+ ] )
316384
317385 const displayCryptoAmount = React . useMemo ( ( ) => {
386+ // Don't show any value if crypto input is disabled
387+ if ( cryptoInputDisabled ) return ''
388+
318389 if ( isMaxAmount && bestQuote != null ) {
319390 return bestQuote . cryptoAmount
320391 }
@@ -326,7 +397,14 @@ export const TradeCreateScene: React.FC<Props> = (props: Props) => {
326397 // User entered fiat, convert to crypto only if we have a quote
327398 return convertFiatToCrypto ( userInput )
328399 }
329- } , [ userInput , lastUsedInput , convertFiatToCrypto , isMaxAmount , bestQuote ] )
400+ } , [
401+ userInput ,
402+ lastUsedInput ,
403+ convertFiatToCrypto ,
404+ isMaxAmount ,
405+ bestQuote ,
406+ cryptoInputDisabled
407+ ] )
330408
331409 //
332410 // Handlers
@@ -546,6 +624,7 @@ export const TradeCreateScene: React.FC<Props> = (props: Props) => {
546624 keyboardType = "decimal-pad"
547625 numeric
548626 showSpinner = { isFetchingQuotes && lastUsedInput === 'crypto' }
627+ disabled = { fiatInputDisabled }
549628 />
550629 </ InputContainer >
551630 </ InputRow >
@@ -573,6 +652,7 @@ export const TradeCreateScene: React.FC<Props> = (props: Props) => {
573652 keyboardType = "decimal-pad"
574653 numeric
575654 showSpinner = { isFetchingQuotes && lastUsedInput === 'fiat' }
655+ disabled = { cryptoInputDisabled }
576656 />
577657 { /* MAX Button */ }
578658 < MaxButton onPress = { handleMaxPress } >
@@ -656,7 +736,9 @@ export const TradeCreateScene: React.FC<Props> = (props: Props) => {
656736 isCheckingSupport ||
657737 supportedPlugins . length === 0 ||
658738 isLoadingQuotes ||
659- sortedQuotes . length === 0
739+ sortedQuotes . length === 0 ||
740+ ( lastUsedInput === 'fiat' && fiatInputDisabled ) ||
741+ ( lastUsedInput === 'crypto' && cryptoInputDisabled )
660742 }
661743 />
662744 </ >
0 commit comments