Skip to content

Commit 33fa31a

Browse files
committed
address comments
1 parent b3fe76a commit 33fa31a

File tree

11 files changed

+78
-59
lines changed

11 files changed

+78
-59
lines changed
Lines changed: 8 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,4 @@
1-
const CURRENCIES = [
2-
"USD",
3-
"EUR",
4-
"GBP",
5-
"JPY",
6-
"KRW",
7-
"CNY",
8-
"INR",
9-
"NOK",
10-
"SEK",
11-
"CHF",
12-
"AUD",
13-
"CAD",
14-
"NZD",
15-
"MXN",
16-
"BRL",
17-
"CLP",
18-
"CZK",
19-
"DKK",
20-
"HKD",
21-
"HUF",
22-
"IDR",
23-
"ILS",
24-
"ISK",
25-
] as const;
26-
27-
export type SupportedFiatCurrency = (typeof CURRENCIES)[number] | (string & {});
28-
29-
export function getFiatSymbol(showBalanceInFiat: SupportedFiatCurrency) {
30-
if (currencySymbol[showBalanceInFiat]) {
31-
return currencySymbol[showBalanceInFiat];
32-
}
33-
return "$";
34-
}
35-
36-
const currencySymbol: Record<SupportedFiatCurrency, string> = {
1+
const currencySymbol = {
372
USD: "$",
383
EUR: "€",
394
GBP: "£",
@@ -57,4 +22,10 @@ const currencySymbol: Record<SupportedFiatCurrency, string> = {
5722
IDR: "Rp",
5823
ILS: "₪",
5924
ISK: "kr",
60-
};
25+
} as const;
26+
27+
export type SupportedFiatCurrency = keyof typeof currencySymbol;
28+
29+
export function getFiatSymbol(showBalanceInFiat: SupportedFiatCurrency) {
30+
return currencySymbol[showBalanceInFiat] || "$";
31+
}

packages/thirdweb/src/react/web/ui/Bridge/payment-selection/FiatProviderSelection.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ export function FiatProviderSelection({
159159
style={{ fontWeight: 500 }}
160160
>
161161
{formatCurrencyAmount(
162-
currency || "US",
162+
currency || "USD",
163163
quote.currencyAmount,
164164
)}
165165
</Text>

packages/thirdweb/src/react/web/ui/Bridge/swap-widget/SwapWidget.tsx

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -155,18 +155,6 @@ export type SwapWidgetProps = {
155155
};
156156
};
157157

158-
export function SwapWidget(props: SwapWidgetProps) {
159-
return (
160-
<SwapWidgetContainer
161-
theme={props.theme}
162-
style={props.style}
163-
className={props.className}
164-
>
165-
<SwapWidgetContent {...props} />
166-
</SwapWidgetContainer>
167-
);
168-
}
169-
170158
/**
171159
* A widget for swapping tokens with cross-chain support
172160
*
@@ -237,7 +225,21 @@ export function SwapWidget(props: SwapWidgetProps) {
237225
* }} />
238226
* ```
239227
*
240-
* @returns
228+
*/
229+
export function SwapWidget(props: SwapWidgetProps) {
230+
return (
231+
<SwapWidgetContainer
232+
theme={props.theme}
233+
style={props.style}
234+
className={props.className}
235+
>
236+
<SwapWidgetContent {...props} />
237+
</SwapWidgetContainer>
238+
);
239+
}
240+
241+
/**
242+
* @internal
241243
*/
242244
export function SwapWidgetContainer(props: {
243245
theme: SwapWidgetProps["theme"];

packages/thirdweb/src/react/web/ui/Bridge/swap-widget/select-chain.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ type SelectBuyTokenProps = {
2323
selectedChain: BridgeChain | undefined;
2424
};
2525

26+
/**
27+
* @internal
28+
*/
2629
export function SelectBridgeChain(props: SelectBuyTokenProps) {
2730
const chainQuery = useBridgeChains(props.client);
2831

@@ -36,6 +39,9 @@ export function SelectBridgeChain(props: SelectBuyTokenProps) {
3639
);
3740
}
3841

42+
/**
43+
* @internal
44+
*/
3945
export function SelectBridgeChainUI(
4046
props: SelectBuyTokenProps & {
4147
isPending: boolean;

packages/thirdweb/src/react/web/ui/Bridge/swap-widget/select-token-ui.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ import {
3232
useTokens,
3333
} from "./use-tokens.js";
3434

35+
/**
36+
* @internal
37+
*/
3538
type SelectTokenUIProps = {
3639
onBack: () => void;
3740
client: ThirdwebClient;
@@ -47,6 +50,9 @@ function getDefaultSelectedChain(
4750
return chains.find((chain) => chain.chainId === (activeChainId || 1));
4851
}
4952

53+
/**
54+
* @internal
55+
*/
5056
export function SelectToken(props: SelectTokenUIProps) {
5157
const chainQuery = useBridgeChains(props.client);
5258
const [search, setSearch] = useState("");
@@ -267,8 +273,10 @@ function SelectTokenUI(
267273
client={props.client}
268274
onSelect={props.setSelectedToken}
269275
isSelected={
270-
props.selectedToken?.tokenAddress.toLowerCase() ===
271-
token.token_address.toLowerCase()
276+
!!props.selectedToken &&
277+
props.selectedToken.tokenAddress.toLowerCase() ===
278+
token.token_address.toLowerCase() &&
279+
token.chain_id === props.selectedToken.chainId
272280
}
273281
/>
274282
))}

packages/thirdweb/src/react/web/ui/Bridge/swap-widget/swap-ui.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ function useTokenPrice(options: {
108108
});
109109
}
110110

111+
/**
112+
* @internal
113+
*/
111114
export function SwapUI(props: SwapUIProps) {
112115
const [modalState, setModalState] = useState<
113116
"select-buy-token" | "select-sell-token" | undefined

packages/thirdweb/src/react/web/ui/Bridge/swap-widget/types.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ import type { SiweAuthOptions } from "../../../../core/hooks/auth/useSiweAuth.js
99
import type { ConnectButton_connectModalOptions } from "../../../../core/hooks/connection/ConnectButtonProps.js";
1010

1111
/**
12-
* Connection options for the `BuyWidget` component
12+
* Connection options for the `SwapWidget` component
1313
*
1414
* @example
1515
* ```tsx
16-
* <BuyWidget client={client} connectOptions={{
16+
* <SwapWidget client={client} connectOptions={{
1717
* connectModal: {
1818
* size: 'compact',
1919
* title: "Sign in",
@@ -61,7 +61,6 @@ export type SwapWidgetConnectOptions = {
6161
* If you want to disable autoConnect, set this prop to `false`.
6262
*
6363
* If you want to customize the timeout, you can assign an object with a `timeout` key to this prop.
64-
* ```
6564
*/
6665
autoConnect?:
6766
| {
@@ -134,12 +133,18 @@ export type SwapWidgetConnectOptions = {
134133
auth?: SiweAuthOptions;
135134
};
136135

136+
/**
137+
* @internal
138+
*/
137139
export type ActiveWalletInfo = {
138140
activeChain: Chain;
139141
activeWallet: Wallet;
140142
activeAccount: Account;
141143
};
142144

145+
/**
146+
* @internal
147+
*/
143148
export type TokenSelection = {
144149
tokenAddress: string;
145150
chainId: number;

packages/thirdweb/src/react/web/ui/Bridge/swap-widget/use-tokens.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export function useTokens(options: {
4040
export type TokenBalance = {
4141
balance: string;
4242
chain_id: number;
43-
decimals: 1;
43+
decimals: number;
4444
name: string;
4545
icon_uri: string;
4646
price_data: {

packages/thirdweb/src/react/web/ui/ConnectWallet/icons/WalletDotIcon.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import type { IconFC } from "./types.js";
22

3+
/**
4+
* @internal
5+
*/
36
export const WalletDotIcon: IconFC = (props) => {
47
return (
58
<svg

packages/thirdweb/src/react/web/ui/components/Img.tsx

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"use client";
2-
import { useState } from "react";
2+
import { useEffect, useRef, useState } from "react";
33
import type { ThirdwebClient } from "../../../../client/client.js";
44
import { resolveScheme } from "../../../../utils/ipfs.js";
55
import { radius, type Theme } from "../../../core/design-system/index.js";
@@ -25,6 +25,7 @@ export const Img: React.FC<{
2525
const [_status, setStatus] = useState<"pending" | "fallback" | "loaded">(
2626
"pending",
2727
);
28+
const imgRef = useRef<HTMLImageElement>(null);
2829

2930
const propSrc = props.src;
3031

@@ -52,6 +53,26 @@ export const Img: React.FC<{
5253

5354
const isLoaded = status === "loaded";
5455

56+
useEffect(() => {
57+
const imgEl = imgRef.current;
58+
if (!imgEl) {
59+
return;
60+
}
61+
if (imgEl.complete) {
62+
setStatus("loaded");
63+
} else {
64+
function handleLoad() {
65+
setStatus("loaded");
66+
}
67+
imgEl.addEventListener("load", handleLoad);
68+
return () => {
69+
imgEl.removeEventListener("load", handleLoad);
70+
};
71+
}
72+
73+
return;
74+
}, []);
75+
5576
return (
5677
<div
5778
style={{

0 commit comments

Comments
 (0)