1+ import { ChevronDownIcon } from "@radix-ui/react-icons" ;
12import { useQuery , useQueryClient } from "@tanstack/react-query" ;
23import { useCallback , useMemo , useState } from "react" ;
34import type { Chain } from "../../../../../../chains/types.js" ;
@@ -10,11 +11,13 @@ import type { GetBuyWithCryptoQuoteParams } from "../../../../../../pay/buyWithC
1011import type { BuyWithCryptoStatus } from "../../../../../../pay/buyWithCrypto/getStatus.js" ;
1112import type { BuyWithFiatStatus } from "../../../../../../pay/buyWithFiat/getStatus.js" ;
1213import { isSwapRequiredPostOnramp } from "../../../../../../pay/buyWithFiat/isSwapRequiredPostOnramp.js" ;
14+ import type { FiatProvider } from "../../../../../../pay/utils/commonTypes.js" ;
1315import { formatNumber } from "../../../../../../utils/formatNumber.js" ;
1416import type { Account } from "../../../../../../wallets/interfaces/wallet.js" ;
1517import type { WalletId } from "../../../../../../wallets/wallet-types.js" ;
1618import {
1719 type Theme ,
20+ iconSize ,
1821 spacing ,
1922} from "../../../../../core/design-system/index.js" ;
2023import type {
@@ -27,6 +30,7 @@ import { useBuyWithFiatQuote } from "../../../../../core/hooks/pay/useBuyWithFia
2730import { useActiveAccount } from "../../../../../core/hooks/wallets/useActiveAccount.js" ;
2831import { invalidateWalletBalance } from "../../../../../core/providers/invalidateWalletBalance.js" ;
2932import type { SupportedTokens } from "../../../../../core/utils/defaultTokens.js" ;
33+ import { PREFERRED_FIAT_PROVIDER_STORAGE_KEY } from "../../../../../core/utils/storage.js" ;
3034import { ErrorState } from "../../../../wallets/shared/ErrorState.js" ;
3135import { LoadingScreen } from "../../../../wallets/shared/LoadingScreen.js" ;
3236import type { PayEmbedConnectOptions } from "../../../PayEmbed.js" ;
@@ -56,6 +60,7 @@ import { PayWithCreditCard } from "./PayWIthCreditCard.js";
5660import { TransactionModeScreen } from "./TransactionModeScreen.js" ;
5761import { CurrencySelection } from "./fiat/CurrencySelection.js" ;
5862import { FiatFlow } from "./fiat/FiatFlow.js" ;
63+ import { Providers } from "./fiat/Providers.js" ;
5964import type { CurrencyMeta } from "./fiat/currencies.js" ;
6065import type { SelectedScreen } from "./main/types.js" ;
6166import {
@@ -1255,9 +1260,22 @@ function FiatScreenContent(props: {
12551260 const receiverAddress =
12561261 defaultRecipientAddress || props . payer . account . address ;
12571262 const { drawerRef, drawerOverlayRef, isOpen, setIsOpen } = useDrawer ( ) ;
1258- const [ drawerScreen , setDrawerScreen ] = useState < "fees" > ( "fees" ) ;
1263+ const [ drawerScreen , setDrawerScreen ] = useState < "fees" | "providers" > (
1264+ "fees" ,
1265+ ) ;
12591266
12601267 const buyWithFiatOptions = props . payOptions . buyWithFiat ;
1268+ const [ preferredProvider , setPreferredProvider ] = useState <
1269+ FiatProvider | undefined
1270+ > (
1271+ buyWithFiatOptions !== false
1272+ ? buyWithFiatOptions ?. preferredProvider ||
1273+ ( ( localStorage . getItem (
1274+ PREFERRED_FIAT_PROVIDER_STORAGE_KEY ,
1275+ ) as FiatProvider | null ) ??
1276+ undefined )
1277+ : undefined ,
1278+ ) ;
12611279
12621280 const fiatQuoteQuery = useBuyWithFiatQuote (
12631281 buyWithFiatOptions !== false && tokenAmount
@@ -1273,7 +1291,7 @@ function FiatScreenContent(props: {
12731291 isTestMode : buyWithFiatOptions ?. testMode ,
12741292 purchaseData : props . payOptions . purchaseData ,
12751293 fromAddress : payer . account . address ,
1276- preferredProvider : buyWithFiatOptions ?. preferredProvider ,
1294+ preferredProvider : preferredProvider ,
12771295 }
12781296 : undefined ,
12791297 ) ;
@@ -1314,6 +1332,11 @@ function FiatScreenContent(props: {
13141332 setIsOpen ( true ) ;
13151333 }
13161334
1335+ function showProviders ( ) {
1336+ setDrawerScreen ( "providers" ) ;
1337+ setIsOpen ( true ) ;
1338+ }
1339+
13171340 const disableSubmit = ! fiatQuoteQuery . data ;
13181341
13191342 const errorMsg =
@@ -1337,6 +1360,28 @@ function FiatScreenContent(props: {
13371360 < FiatFees quote = { fiatQuoteQuery . data } />
13381361 </ div >
13391362 ) }
1363+ { drawerScreen === "providers" && (
1364+ < div >
1365+ < Text size = "lg" color = "primaryText" >
1366+ Providers
1367+ </ Text >
1368+ < Spacer y = "lg" />
1369+ < Providers
1370+ preferredProvider = {
1371+ preferredProvider || fiatQuoteQuery . data ?. provider
1372+ }
1373+ onSelect = { ( provider ) => {
1374+ setPreferredProvider ( provider ) ;
1375+ // save the pref in local storage
1376+ localStorage . setItem (
1377+ PREFERRED_FIAT_PROVIDER_STORAGE_KEY ,
1378+ provider ,
1379+ ) ;
1380+ setIsOpen ( false ) ;
1381+ } }
1382+ />
1383+ </ div >
1384+ ) }
13401385 </ Drawer >
13411386 </ >
13421387 ) }
@@ -1349,6 +1394,35 @@ function FiatScreenContent(props: {
13491394 currency = { selectedCurrency }
13501395 onSelectCurrency = { showCurrencySelector }
13511396 />
1397+ < Container
1398+ bg = "tertiaryBg"
1399+ flex = "row"
1400+ borderColor = "borderColor"
1401+ style = { {
1402+ paddingLeft : spacing . md ,
1403+ justifyContent : "space-between" ,
1404+ alignItems : "center" ,
1405+ borderWidth : "1px" ,
1406+ borderStyle : "solid" ,
1407+ borderBottom : "none" ,
1408+ } }
1409+ >
1410+ < Text size = "xs" color = "secondaryText" >
1411+ Provider
1412+ </ Text >
1413+ < Button variant = "ghost" onClick = { showProviders } >
1414+ < Container flex = "row" center = "y" gap = "xxs" color = "secondaryText" >
1415+ < Text size = "xs" >
1416+ { preferredProvider
1417+ ? `${ preferredProvider . charAt ( 0 ) . toUpperCase ( ) + preferredProvider . slice ( 1 ) . toLowerCase ( ) } `
1418+ : fiatQuoteQuery . data ?. provider
1419+ ? `${ fiatQuoteQuery . data ?. provider . charAt ( 0 ) . toUpperCase ( ) + fiatQuoteQuery . data ?. provider . slice ( 1 ) . toLowerCase ( ) } `
1420+ : "" }
1421+ </ Text >
1422+ < ChevronDownIcon width = { iconSize . sm } height = { iconSize . sm } />
1423+ </ Container >
1424+ </ Button >
1425+ </ Container >
13521426 { /* Estimated time + View fees button */ }
13531427 < EstimatedTimeAndFees
13541428 quoteIsLoading = { fiatQuoteQuery . isLoading }
0 commit comments