@@ -11,7 +11,10 @@ import { FLAG_LOGO_URL } from '../../constants/CdnConstants'
1111import { COUNTRY_CODES , FIAT_COUNTRY } from '../../constants/CountryConstants'
1212import { useHandler } from '../../hooks/useHandler'
1313import { useRampQuotes } from '../../hooks/useRampQuotes'
14- import { useSupportedPlugins } from '../../hooks/useSupportedPlugins'
14+ import {
15+ type SupportedPluginResult ,
16+ useSupportedPlugins
17+ } from '../../hooks/useSupportedPlugins'
1518import { useWatch } from '../../hooks/useWatch'
1619import { lstrings } from '../../locales/strings'
1720import type { RampQuoteRequest } from '../../plugins/ramps/rampPluginTypes'
@@ -49,6 +52,47 @@ export interface TradeCreateParams {
4952
5053interface Props extends BuyTabSceneProps < 'pluginListBuy' > { }
5154
55+ // Helper function to determine which input types should be disabled
56+ interface AmountTypeSupport {
57+ fiatInputDisabled : boolean
58+ cryptoInputDisabled : boolean
59+ }
60+
61+ function getAmountTypeSupport (
62+ supportedPlugins : SupportedPluginResult [ ]
63+ ) : AmountTypeSupport {
64+ if ( supportedPlugins . length === 0 ) {
65+ return { fiatInputDisabled : false , cryptoInputDisabled : false }
66+ }
67+
68+ // Collect all supported amount types from all plugins
69+ const allSupportedTypes = new Set < 'fiat' | 'crypto' > ( )
70+
71+ for ( const { supportResult } of supportedPlugins ) {
72+ if ( supportResult . supportedAmountTypes != null ) {
73+ for ( const type of supportResult . supportedAmountTypes ) {
74+ allSupportedTypes . add ( type )
75+ }
76+ } else {
77+ // If a plugin doesn't specify supported types, assume both are supported
78+ allSupportedTypes . add ( 'fiat' )
79+ allSupportedTypes . add ( 'crypto' )
80+ }
81+ }
82+
83+ // If all plugins only support fiat, disable crypto input
84+ const onlyFiat =
85+ allSupportedTypes . has ( 'fiat' ) && ! allSupportedTypes . has ( 'crypto' )
86+ // If all plugins only support crypto, disable fiat input
87+ const onlyCrypto =
88+ allSupportedTypes . has ( 'crypto' ) && ! allSupportedTypes . has ( 'fiat' )
89+
90+ return {
91+ fiatInputDisabled : onlyCrypto ,
92+ cryptoInputDisabled : onlyFiat
93+ }
94+ }
95+
5296export const TradeCreateScene = ( props : Props ) : React . ReactElement => {
5397 const { navigation, route } = props
5498 const { regionCode : initialRegionCode , forcedWalletResult } =
@@ -223,13 +267,17 @@ export const TradeCreateScene = (props: Props): React.ReactElement => {
223267 } = useRampQuotes ( {
224268 rampQuoteRequest,
225269 plugins : Object . fromEntries (
226- supportedPlugins . map ( plugin => [ plugin . pluginId , plugin ] )
270+ supportedPlugins . map ( result => [ result . plugin . pluginId , result . plugin ] )
227271 )
228272 } )
229273
230274 // Get the best quote
231275 const bestQuote = sortedQuotes [ 0 ]
232276
277+ // Determine which input types should be disabled
278+ const { fiatInputDisabled, cryptoInputDisabled } =
279+ getAmountTypeSupport ( supportedPlugins )
280+
233281 // Calculate exchange rate from best quote
234282 const quoteExchangeRate = React . useMemo ( ( ) => {
235283 if ( ! bestQuote ?. cryptoAmount || ! bestQuote . fiatAmount ) return 0
@@ -516,6 +564,7 @@ export const TradeCreateScene = (props: Props): React.ReactElement => {
516564 keyboardType = "decimal-pad"
517565 numeric
518566 showSpinner = { isFetchingQuotes && lastUsedInput === 'crypto' }
567+ disabled = { fiatInputDisabled }
519568 />
520569 </ InputContainer >
521570 </ InputRow >
@@ -545,6 +594,7 @@ export const TradeCreateScene = (props: Props): React.ReactElement => {
545594 keyboardType = "decimal-pad"
546595 numeric
547596 showSpinner = { isFetchingQuotes && lastUsedInput === 'fiat' }
597+ disabled = { cryptoInputDisabled }
548598 />
549599 { /* MAX Button */ }
550600 < MaxButton active = { isMaxAmount } onPress = { handleMaxPress } >
0 commit comments