1
+ import { ChevronDownIcon } from "@radix-ui/react-icons" ;
1
2
import { useQuery , useQueryClient } from "@tanstack/react-query" ;
2
3
import { useCallback , useMemo , useState } from "react" ;
3
4
import type { Chain } from "../../../../../../chains/types.js" ;
@@ -10,11 +11,13 @@ import type { GetBuyWithCryptoQuoteParams } from "../../../../../../pay/buyWithC
10
11
import type { BuyWithCryptoStatus } from "../../../../../../pay/buyWithCrypto/getStatus.js" ;
11
12
import type { BuyWithFiatStatus } from "../../../../../../pay/buyWithFiat/getStatus.js" ;
12
13
import { isSwapRequiredPostOnramp } from "../../../../../../pay/buyWithFiat/isSwapRequiredPostOnramp.js" ;
14
+ import type { FiatProvider } from "../../../../../../pay/utils/commonTypes.js" ;
13
15
import { formatNumber } from "../../../../../../utils/formatNumber.js" ;
14
16
import type { Account } from "../../../../../../wallets/interfaces/wallet.js" ;
15
17
import type { WalletId } from "../../../../../../wallets/wallet-types.js" ;
16
18
import {
17
19
type Theme ,
20
+ iconSize ,
18
21
spacing ,
19
22
} from "../../../../../core/design-system/index.js" ;
20
23
import type {
@@ -27,6 +30,7 @@ import { useBuyWithFiatQuote } from "../../../../../core/hooks/pay/useBuyWithFia
27
30
import { useActiveAccount } from "../../../../../core/hooks/wallets/useActiveAccount.js" ;
28
31
import { invalidateWalletBalance } from "../../../../../core/providers/invalidateWalletBalance.js" ;
29
32
import type { SupportedTokens } from "../../../../../core/utils/defaultTokens.js" ;
33
+ import { PREFERRED_FIAT_PROVIDER_STORAGE_KEY } from "../../../../../core/utils/storage.js" ;
30
34
import { ErrorState } from "../../../../wallets/shared/ErrorState.js" ;
31
35
import { LoadingScreen } from "../../../../wallets/shared/LoadingScreen.js" ;
32
36
import type { PayEmbedConnectOptions } from "../../../PayEmbed.js" ;
@@ -56,6 +60,7 @@ import { PayWithCreditCard } from "./PayWIthCreditCard.js";
56
60
import { TransactionModeScreen } from "./TransactionModeScreen.js" ;
57
61
import { CurrencySelection } from "./fiat/CurrencySelection.js" ;
58
62
import { FiatFlow } from "./fiat/FiatFlow.js" ;
63
+ import { Providers } from "./fiat/Providers.js" ;
59
64
import type { CurrencyMeta } from "./fiat/currencies.js" ;
60
65
import type { SelectedScreen } from "./main/types.js" ;
61
66
import {
@@ -1255,9 +1260,22 @@ function FiatScreenContent(props: {
1255
1260
const receiverAddress =
1256
1261
defaultRecipientAddress || props . payer . account . address ;
1257
1262
const { drawerRef, drawerOverlayRef, isOpen, setIsOpen } = useDrawer ( ) ;
1258
- const [ drawerScreen , setDrawerScreen ] = useState < "fees" > ( "fees" ) ;
1263
+ const [ drawerScreen , setDrawerScreen ] = useState < "fees" | "providers" > (
1264
+ "fees" ,
1265
+ ) ;
1259
1266
1260
1267
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
+ ) ;
1261
1279
1262
1280
const fiatQuoteQuery = useBuyWithFiatQuote (
1263
1281
buyWithFiatOptions !== false && tokenAmount
@@ -1273,7 +1291,7 @@ function FiatScreenContent(props: {
1273
1291
isTestMode : buyWithFiatOptions ?. testMode ,
1274
1292
purchaseData : props . payOptions . purchaseData ,
1275
1293
fromAddress : payer . account . address ,
1276
- preferredProvider : buyWithFiatOptions ?. preferredProvider ,
1294
+ preferredProvider : preferredProvider ,
1277
1295
}
1278
1296
: undefined ,
1279
1297
) ;
@@ -1314,6 +1332,11 @@ function FiatScreenContent(props: {
1314
1332
setIsOpen ( true ) ;
1315
1333
}
1316
1334
1335
+ function showProviders ( ) {
1336
+ setDrawerScreen ( "providers" ) ;
1337
+ setIsOpen ( true ) ;
1338
+ }
1339
+
1317
1340
const disableSubmit = ! fiatQuoteQuery . data ;
1318
1341
1319
1342
const errorMsg =
@@ -1337,6 +1360,28 @@ function FiatScreenContent(props: {
1337
1360
< FiatFees quote = { fiatQuoteQuery . data } />
1338
1361
</ div >
1339
1362
) }
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
+ ) }
1340
1385
</ Drawer >
1341
1386
</ >
1342
1387
) }
@@ -1349,6 +1394,35 @@ function FiatScreenContent(props: {
1349
1394
currency = { selectedCurrency }
1350
1395
onSelectCurrency = { showCurrencySelector }
1351
1396
/>
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 >
1352
1426
{ /* Estimated time + View fees button */ }
1353
1427
< EstimatedTimeAndFees
1354
1428
quoteIsLoading = { fiatQuoteQuery . isLoading }
0 commit comments