-
Notifications
You must be signed in to change notification settings - Fork 453
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SDK] feat: Add fiat value display to buy token input
- Loading branch information
1 parent
6ec60f0
commit a4404f2
Showing
5 changed files
with
77 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"thirdweb": patch | ||
--- | ||
|
||
Show fiat amount in PayEmbed main screen |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/swap/FiatValue.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { useQuery } from "@tanstack/react-query"; | ||
import type { Chain } from "../../../../../../../chains/types.js"; | ||
import type { ThirdwebClient } from "../../../../../../../client/client.js"; | ||
import { convertCryptoToFiat } from "../../../../../../../pay/convert/cryptoToFiat.js"; | ||
import { formatNumber } from "../../../../../../../utils/formatNumber.js"; | ||
import { fontSize } from "../../../../../../core/design-system/index.js"; | ||
import { Skeleton } from "../../../../components/Skeleton.js"; | ||
import { Text } from "../../../../components/text.js"; | ||
import type { TextProps } from "../../../../components/text.js"; | ||
import { useDebouncedValue } from "../../../../hooks/useDebouncedValue.js"; | ||
import type { ERC20OrNativeToken } from "../../nativeToken.js"; | ||
import { getTokenAddress } from "../../nativeToken.js"; | ||
|
||
export function FiatValue( | ||
props: { | ||
tokenAmount: string; | ||
token: ERC20OrNativeToken; | ||
chain: Chain; | ||
client: ThirdwebClient; | ||
} & TextProps, | ||
) { | ||
const deferredTokenAmount = useDebouncedValue(props.tokenAmount, 500); | ||
const cryptoToFiatQuery = useQuery({ | ||
queryKey: [ | ||
"cryptoToFiat", | ||
props.chain.id, | ||
getTokenAddress(props.token), | ||
deferredTokenAmount, | ||
], | ||
queryFn: () => | ||
convertCryptoToFiat({ | ||
client: props.client, | ||
chain: props.chain, | ||
fromTokenAddress: getTokenAddress(props.token), | ||
fromAmount: Number(deferredTokenAmount), | ||
to: "USD", | ||
}), | ||
}); | ||
|
||
if (cryptoToFiatQuery.isLoading) { | ||
return <Skeleton width={"50px"} height={fontSize.lg} />; | ||
} | ||
|
||
return ( | ||
<Text {...props}> | ||
{cryptoToFiatQuery.data?.result | ||
? `$${formatNumber(cryptoToFiatQuery.data.result, 2)}` | ||
: "$0.00"} | ||
</Text> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters