Skip to content

Commit 03eafe3

Browse files
fix: resolve bugs (that I made)
1 parent 0408d72 commit 03eafe3

File tree

4 files changed

+95
-60
lines changed

4 files changed

+95
-60
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import { ChevronDownIcon } from "@radix-ui/react-icons";
2+
import type { FiatProvider } from "src/pay/utils/commonTypes.js";
3+
import { iconSize, spacing } from "../../../../../core/design-system/index.js";
4+
import { Container } from "../../../components/basic.js";
5+
import { Button } from "../../../components/buttons.js";
6+
import { Text } from "../../../components/text.js";
7+
import { uppercaseFirstLetter } from "./utils.js";
8+
9+
/**
10+
* Shows the selected payment provider based on the preferred provider OR the quoted provider.
11+
* @internal
12+
*/
13+
export const PayProviderSelection = (props: {
14+
onShowProviders: () => void;
15+
quotedProvider?: FiatProvider;
16+
preferredProvider?: FiatProvider;
17+
supportedProviders: FiatProvider[];
18+
}) => {
19+
const ProviderItem = (
20+
<Container
21+
flex="row"
22+
center="y"
23+
gap="xxs"
24+
color="secondaryText"
25+
style={{ padding: spacing.md }}
26+
>
27+
<Text size="xs">
28+
{uppercaseFirstLetter(
29+
props.preferredProvider ?? props.quotedProvider ?? "",
30+
)}
31+
</Text>
32+
{props.supportedProviders.length > 1 && (
33+
<ChevronDownIcon width={iconSize.sm} height={iconSize.sm} />
34+
)}
35+
</Container>
36+
);
37+
38+
return (
39+
<Container
40+
bg="tertiaryBg"
41+
flex="row"
42+
borderColor="borderColor"
43+
style={{
44+
paddingLeft: spacing.md,
45+
justifyContent: "space-between",
46+
alignItems: "center",
47+
borderWidth: "1px",
48+
borderStyle: "solid",
49+
borderBottom: "none",
50+
}}
51+
>
52+
<Text size="xs" color="secondaryText">
53+
Provider
54+
</Text>
55+
{props.supportedProviders.length > 1 ? (
56+
<Button
57+
variant="ghost"
58+
onClick={props.onShowProviders}
59+
style={{ padding: 0 }}
60+
>
61+
{ProviderItem}
62+
</Button>
63+
) : (
64+
ProviderItem
65+
)}
66+
</Container>
67+
);
68+
};

packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/fiat/FiatScreenContent.tsx

Lines changed: 10 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { ChevronDownIcon } from "@radix-ui/react-icons";
21
import { useState } from "react";
32
import { trackPayEvent } from "../../../../../../../analytics/track/pay.js";
43
import type { Chain } from "../../../../../../../chains/types.js";
@@ -8,11 +7,7 @@ import {
87
type FiatProvider,
98
FiatProviders,
109
} from "../../../../../../../pay/utils/commonTypes.js";
11-
import {
12-
type Theme,
13-
iconSize,
14-
spacing,
15-
} from "../../../../../../core/design-system/index.js";
10+
import type { Theme } from "../../../../../../core/design-system/index.js";
1611
import type { PayUIOptions } from "../../../../../../core/hooks/connection/ConnectButtonProps.js";
1712
import { useBuyWithFiatQuote } from "../../../../../../core/hooks/pay/useBuyWithFiatQuote.js";
1813
import { PREFERRED_FIAT_PROVIDER_STORAGE_KEY } from "../../../../../../core/utils/storage.js";
@@ -29,11 +24,11 @@ import { Button } from "../../../../components/buttons.js";
2924
import { Text } from "../../../../components/text.js";
3025
import { type ERC20OrNativeToken, isNativeToken } from "../../nativeToken.js";
3126
import { EstimatedTimeAndFees } from "../EstimatedTimeAndFees.js";
27+
import { PayProviderSelection } from "../PayProviderSelection.js";
3228
import { PayWithCreditCard } from "../PayWIthCreditCard.js";
3329
import type { SelectedScreen } from "../main/types.js";
3430
import { FiatFees } from "../swap/Fees.js";
3531
import type { PayerInfo } from "../types.js";
36-
import { uppercaseFirstLetter } from "../utils.js";
3732
import { Providers } from "./Providers.js";
3833
import type { CurrencyMeta } from "./currencies.js";
3934

@@ -89,7 +84,7 @@ export function FiatScreenContent(props: {
8984
);
9085

9186
const supportedProviders = (() => {
92-
if (!buyWithFiatOptions) return [];
87+
if (!buyWithFiatOptions) return [...FiatProviders];
9388
const options = buyWithFiatOptions?.supportedProviders ?? [];
9489
return options.length > 0 &&
9590
(!preferredProvider || options.includes(preferredProvider))
@@ -202,35 +197,13 @@ export function FiatScreenContent(props: {
202197
currency={selectedCurrency}
203198
onSelectCurrency={showCurrencySelector}
204199
/>
205-
<Container
206-
bg="tertiaryBg"
207-
flex="row"
208-
borderColor="borderColor"
209-
style={{
210-
paddingLeft: spacing.md,
211-
justifyContent: "space-between",
212-
alignItems: "center",
213-
borderWidth: "1px",
214-
borderStyle: "solid",
215-
borderBottom: "none",
216-
}}
217-
>
218-
<Text size="xs" color="secondaryText">
219-
Provider
220-
</Text>
221-
<Button variant="ghost" onClick={showProviders}>
222-
<Container flex="row" center="y" gap="xxs" color="secondaryText">
223-
<Text size="xs">
224-
{preferredProvider
225-
? `${uppercaseFirstLetter(preferredProvider)}`
226-
: fiatQuoteQuery.data?.provider
227-
? `${uppercaseFirstLetter(fiatQuoteQuery.data?.provider)}`
228-
: ""}
229-
</Text>
230-
<ChevronDownIcon width={iconSize.sm} height={iconSize.sm} />
231-
</Container>
232-
</Button>
233-
</Container>
200+
{/** Shows preferred or quoted provider and conditional selection */}
201+
<PayProviderSelection
202+
onShowProviders={showProviders}
203+
quotedProvider={fiatQuoteQuery.data?.provider}
204+
preferredProvider={preferredProvider}
205+
supportedProviders={supportedProviders}
206+
/>
234207
{/* Estimated time + View fees button */}
235208
<EstimatedTimeAndFees
236209
quoteIsLoading={fiatQuoteQuery.isLoading}

packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/fiat/Providers.tsx

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { FiatProvider } from "../../../../../../../pay/utils/commonTypes.js";
22
import { Container } from "../../../../components/basic.js";
33
import { Button } from "../../../../components/buttons.js";
4-
import { Link, Text } from "../../../../components/text.js";
4+
import { Link } from "../../../../components/text.js";
55
import { uppercaseFirstLetter } from "../utils.js";
66
/**
77
* @internal
@@ -30,29 +30,23 @@ export function Providers(props: {
3030
justifyContent: "space-between",
3131
}}
3232
>
33-
{props.supportedProviders.length > 0 ? (
34-
<Button
35-
fullWidth
36-
onClick={() => props.onSelect(provider)}
37-
variant={"link"}
33+
<Button
34+
fullWidth
35+
onClick={() => props.onSelect(provider)}
36+
variant={"link"}
37+
>
38+
<Link
39+
color={
40+
props.preferredProvider === provider
41+
? "primaryText"
42+
: "secondaryText"
43+
}
44+
size="sm"
45+
hoverColor="primaryText"
3846
>
39-
<Link
40-
color={
41-
props.preferredProvider === provider
42-
? "primaryText"
43-
: "secondaryText"
44-
}
45-
size="sm"
46-
hoverColor="primaryText"
47-
>
48-
{uppercaseFirstLetter(provider)}
49-
</Link>
50-
</Button>
51-
) : (
52-
<Text color="primaryText" size="sm">
5347
{uppercaseFirstLetter(provider)}
54-
</Text>
55-
)}
48+
</Link>
49+
</Button>
5650
</Container>
5751
))}
5852
</Container>

packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ export function getBuyTokenAmountFontSize(value: string) {
33
}
44

55
export function uppercaseFirstLetter(str: string) {
6-
return str.charAt(0).toUpperCase() + str.slice(1);
6+
return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase();
77
}

0 commit comments

Comments
 (0)