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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState } from "react";
import { useMemo, useState } from "react";
import type { Chain as BridgeChain } from "../../../../../bridge/index.js";
import type { ThirdwebClient } from "../../../../../client/client.js";
import {
Expand Down Expand Up @@ -53,7 +53,22 @@ export function SelectBridgeChainUI(
},
) {
const [search, setSearch] = useState("");
const filteredChains = props.chains.filter((chain) => {
const [initiallySelectedChain] = useState(props.selectedChain);

// put the initially selected chain first
const sortedChains = useMemo(() => {
if (initiallySelectedChain) {
return [
initiallySelectedChain,
...props.chains.filter(
(chain) => chain.chainId !== initiallySelectedChain.chainId,
),
];
}
return props.chains;
}, [props.chains, initiallySelectedChain]);

const filteredChains = sortedChains.filter((chain) => {
return chain.name.toLowerCase().includes(search.toLowerCase());
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import { tokenAmountFormatter } from "./utils.js";
* @internal
*/
type SelectTokenUIProps = {
onBack: () => void;
onClose: () => void;
client: ThirdwebClient;
selectedToken: TokenSelection | undefined;
setSelectedToken: (token: TokenSelection) => void;
Expand Down Expand Up @@ -182,6 +182,7 @@ function SelectTokenUI(
});
}, [otherTokens]);

// desktop
if (!isMobile) {
return (
<Container
Expand All @@ -205,7 +206,10 @@ function SelectTokenUI(
</LeftContainer>
<Container flex="column" relative scrollY>
<TokenSelectionScreen
onSelectToken={props.setSelectedToken}
onSelectToken={(token) => {
props.setSelectedToken(token);
props.onClose();
}}
isMobile={false}
selectedToken={props.selectedToken}
isFetching={props.isFetching}
Expand All @@ -226,7 +230,10 @@ function SelectTokenUI(
if (screen === "select-token") {
return (
<TokenSelectionScreen
onSelectToken={props.setSelectedToken}
onSelectToken={(token) => {
props.setSelectedToken(token);
props.onClose();
}}
selectedToken={props.selectedToken}
isFetching={props.isFetching}
ownedTokens={props.ownedTokens}
Expand Down Expand Up @@ -581,8 +588,10 @@ function TokenSelectionScreen(props: {
client={props.client}
onSelect={props.onSelectToken}
isSelected={
props.selectedToken?.tokenAddress.toLowerCase() ===
token.address.toLowerCase()
!!props.selectedToken &&
props.selectedToken.tokenAddress.toLowerCase() ===
token.address.toLowerCase() &&
token.chainId === props.selectedToken.chainId
}
/>
))}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,20 +235,16 @@ export function SwapUI(props: SwapUIProps) {
{modalState.screen === "select-buy-token" && (
<SelectToken
activeWalletInfo={props.activeWalletInfo}
onBack={() =>
onClose={() => {
setModalState((v) => ({
...v,
isOpen: false,
}))
}
}));
}}
client={props.client}
selectedToken={props.buyToken}
setSelectedToken={(token) => {
props.setBuyToken(token);
setModalState((v) => ({
...v,
isOpen: false,
}));
// if buy token is same as sell token, unset sell token
if (
props.sellToken &&
Expand All @@ -264,20 +260,16 @@ export function SwapUI(props: SwapUIProps) {

{modalState.screen === "select-sell-token" && (
<SelectToken
onBack={() =>
onClose={() => {
setModalState((v) => ({
...v,
isOpen: false,
}))
}
}));
}}
client={props.client}
selectedToken={props.sellToken}
setSelectedToken={(token) => {
props.setSellToken(token);
setModalState((v) => ({
...v,
isOpen: false,
}));
// if sell token is same as buy token, unset buy token
if (
props.buyToken &&
Expand Down
Loading