Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/pink-guests-agree.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"thirdweb": patch
---

New PayEmbed UI for token selection
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import { NATIVE_TOKEN_ADDRESS } from "../../../../../../constants/addresses.js";
import type { BuyWithCryptoStatus } from "../../../../../../pay/buyWithCrypto/getStatus.js";
import type { BuyWithFiatStatus } from "../../../../../../pay/buyWithFiat/getStatus.js";
import { formatNumber } from "../../../../../../utils/formatNumber.js";
import type { Account } from "../../../../../../wallets/interfaces/wallet.js";
import type { WalletId } from "../../../../../../wallets/wallet-types.js";
import {
Expand Down Expand Up @@ -56,6 +57,7 @@
import { PaymentSelectionScreen } from "./swap/PaymentSelectionScreen.js";
import { SwapFlow } from "./swap/SwapFlow.js";
import { SwapScreenContent } from "./swap/SwapScreenContent.js";
import { TokenSelectorScreen } from "./swap/TokenSelectorScreen.js";
import { TransferFlow } from "./swap/TransferFlow.js";
import {
type SupportedChainAndTokens,
Expand Down Expand Up @@ -453,30 +455,39 @@
}

return (
<TokenSelector
<TokenSelectorScreen

Check warning on line 458 in packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.tsx

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.tsx#L458

Added line #L458 was not covered by tests
onBack={goBack}
tokenList={(
(fromChain?.id ? sourceSupportedTokens[fromChain.id] : undefined) ||
[]
).filter((x) => x.address !== NATIVE_TOKEN_ADDRESS)}
onTokenSelect={(tokenInfo) => {
setFromToken(tokenInfo);
onConnect={() => {
setScreen({
id: "connect-payer-wallet",
backScreen: screen,
});
}}
modalTitle="Available tokens"
connectLocale={props.connectLocale}
client={props.client}
sourceTokens={sourceSupportedTokens}
sourceSupportedTokens={sourceSupportedTokens}
toChain={toChain}
toToken={toToken}
tokenAmount={tokenAmount}
fromChain={fromChain}
fromToken={fromToken}
mode={payOptions.mode}
hiddenWallets={props.hiddenWallets}
onSelect={(w, token, chain) => {
const account = w.getAccount();
if (account) {
setPayer({
account,
chain,
wallet: w,
});
setFromToken(token);
setFromChain(chain);
}

Check warning on line 488 in packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.tsx

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.tsx#L460-L488

Added lines #L460 - L488 were not covered by tests
goBack();
}}
chain={fromChain}
chainSelection={
// hide chain selection if it's disabled
payOptions.buyWithCrypto !== false &&
payOptions.buyWithCrypto?.prefillSource?.allowEdits?.chain !== false
? {
chains: supportedSourcesQuery.data.map((x) => x.chain),
select: (c) => setFromChain(c),
}
: undefined
}
connectLocale={connectLocale}
client={client}
modalTitle="Pay with"
/>
);
}
Expand Down Expand Up @@ -550,23 +561,23 @@
payWithFiatEnabled={props.payOptions.buyWithFiat !== false}
toChain={toChain}
toToken={toToken}
fromToken={fromToken}
fromChain={fromChain}

Check warning on line 565 in packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.tsx

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.tsx#L564-L565

Added lines #L564 - L565 were not covered by tests
tokenAmount={tokenAmount}
onSelect={(w, token, chain) => {
const account = w.getAccount();
if (account) {
setPayer({
account,
chain,
wallet: w,
});
setFromToken(token);
setFromChain(chain);
setScreen({ id: "buy-with-crypto" });
}
onContinue={() => {
setScreen({ id: "buy-with-crypto" });

Check warning on line 568 in packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.tsx

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.tsx#L567-L568

Added lines #L567 - L568 were not covered by tests
}}
onSelectFiat={() => {
setScreen({ id: "buy-with-fiat" });
}}
onPickToken={() => {
setScreen({
id: "select-from-token",
backScreen: {
id: "select-payment-method",
},
});
}}

Check warning on line 580 in packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.tsx

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.tsx#L573-L580

Added lines #L573 - L580 were not covered by tests
showAllWallets={!!props.connectOptions?.showAllWallets}
wallets={props.connectOptions?.wallets}
onBack={() => {
Expand Down Expand Up @@ -659,8 +670,9 @@
disabled?: boolean;
}) {
const getWidth = () => {
let chars = props.tokenAmount.replace(".", "").length;
const hasDot = props.tokenAmount.includes(".");
const amount = formatNumber(Number(props.tokenAmount), 5).toString();
let chars = amount.replace(".", "").length;
const hasDot = amount.includes(".");

Check warning on line 675 in packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.tsx

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.tsx#L673-L675

Added lines #L673 - L675 were not covered by tests
if (hasDot) {
chars += 0.3;
}
Expand All @@ -685,7 +697,11 @@
placeholder="0"
type="text"
data-placeholder={props.tokenAmount === ""}
value={props.tokenAmount || "0"}
value={
props.tokenAmount
? formatNumber(Number(props.tokenAmount), 5)
: "0"

Check warning on line 703 in packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.tsx

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.tsx#L700-L703

Added lines #L700 - L703 were not covered by tests
}
disabled={props.disabled}
onClick={(e) => {
// put cursor at the end of the input
Expand Down Expand Up @@ -885,7 +901,7 @@
client={props.client}
/>

<Spacer y="xl" />
<Spacer y="md" />

Check warning on line 904 in packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.tsx

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.tsx#L904

Added line #L904 was not covered by tests

{/* Continue */}
<Container flex="column" gap="sm">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ import {
NATIVE_TOKEN,
isNativeToken,
} from "../nativeToken.js";
import { WalletRow } from "./WalletSelectorButton.js";
import { useTransactionCostAndData } from "./main/useBuyTxStates.js";
import { WalletRow } from "./swap/TokenSelectorScreen.js";
import type { SupportedChainAndTokens } from "./swap/useSwapSupportedChains.js";

export function TransactionModeScreen(props: {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@

// --------------------------------------------------------------------------
const firstSupportedSource = supportedSources?.length
? supportedSources[0]
? supportedSources.length === 1
? supportedSources[0]
: supportedSources.find((x) => x.chain.id !== 1) // dont use mainnet as a default source, unless its the only source

Check warning on line 85 in packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/main/useUISelectionStates.ts

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/main/useUISelectionStates.ts#L83-L85

Added lines #L83 - L85 were not covered by tests
: undefined;

// Source token and chain selection ---------------------------------------------------
Expand Down
Loading
Loading