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/dirty-bananas-fall.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"thirdweb": patch
---

Use new BuyWidget in wallet details modal
5 changes: 0 additions & 5 deletions packages/thirdweb/src/insight/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,3 @@ export async function assertInsightEnabled(chains: Chain[]) {
);
}
}

export async function isInsightEnabled(chain: Chain) {
const chainIds = await getInsightEnabledChainIds();
return chainIds.includes(chain.id);
}
5 changes: 0 additions & 5 deletions packages/thirdweb/src/pay/buyWithCrypto/getStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,6 @@ export type BuyWithCryptoStatus =
purchaseData?: PurchaseData;
};

export type ValidBuyWithCryptoStatus = Exclude<
BuyWithCryptoStatus,
{ status: "NOT_FOUND" }
>;

/**
* Gets the status of a buy with crypto transaction
* @param buyWithCryptoTransaction - Object of type [`BuyWithCryptoTransaction`](https://portal.thirdweb.com/references/typescript/v5/BuyWithCryptoTransaction)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { getAddress } from "../../utils/address.js";
import type { PayTokenInfo } from "../utils/commonTypes.js";
import type { BuyWithFiatQuote } from "./getQuote.js";

/**
Expand Down Expand Up @@ -28,58 +27,3 @@ export function isSwapRequiredPostOnramp(

return !(sameChain && sameToken);
}

export function getOnRampSteps(
buyWithFiatQuote: BuyWithFiatQuote,
): OnRampStep[] {
const isSwapRequired = isSwapRequiredPostOnramp(buyWithFiatQuote);

if (!isSwapRequired) {
return [
{
action: "buy",
amount: buyWithFiatQuote.estimatedToAmountMin,
token: buyWithFiatQuote.toToken,
},
];
}

if (buyWithFiatQuote.routingToken) {
return [
{
action: "buy",
amount: buyWithFiatQuote.onRampToken.amount,
token: buyWithFiatQuote.onRampToken.token,
},
{
action: "swap",
amount: buyWithFiatQuote.routingToken.amount,
token: buyWithFiatQuote.routingToken.token,
},
{
action: "bridge",
amount: buyWithFiatQuote.estimatedToAmountMin,
token: buyWithFiatQuote.toToken,
},
];
}

return [
{
action: "buy",
amount: buyWithFiatQuote.onRampToken.amount,
token: buyWithFiatQuote.onRampToken.token,
},
{
action: "swap",
amount: buyWithFiatQuote.estimatedToAmountMin,
token: buyWithFiatQuote.toToken,
},
];
}

export type OnRampStep = {
action: "buy" | "swap" | "bridge";
token: PayTokenInfo;
amount: string;
};
2 changes: 1 addition & 1 deletion packages/thirdweb/src/pay/utils/commonTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ export type PayOnChainTransactionDetails = {

export type FiatProvider = (typeof FiatProviders)[number];

export const FiatProviders = ["coinbase", "stripe", "transak"] as const;
const FiatProviders = ["coinbase", "stripe", "transak"] as const;
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,18 @@
limit: 100,
maxSteps: 3,
originChainId: chainId,
sortBy: "popularity",
});

// Add all origin tokens from this chain's routes
for (const route of routesForChain) {
// Skip if the origin token is the same as the destination token, will be added later only if includeDestinationToken is true
if (
route.originToken.chainId === destinationToken.chainId &&
route.originToken.address.toLowerCase() ===
destinationToken.address.toLowerCase()
) {
continue;
}

Check warning on line 155 in packages/thirdweb/src/react/core/hooks/usePaymentMethods.ts

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/core/hooks/usePaymentMethods.ts#L149-L155

Added lines #L149 - L155 were not covered by tests
const tokenKey = `${route.originToken.chainId}-${route.originToken.address.toLowerCase()}`;
allValidOriginTokens.set(tokenKey, route.originToken);
}
Expand Down
1 change: 0 additions & 1 deletion packages/thirdweb/src/react/core/utils/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type { AsyncStorage } from "../../../utils/storage/AsyncStorage.js";
import type { AuthArgsType } from "../../../wallets/in-app/core/authentication/types.js";

export const LAST_AUTH_PROVIDER_STORAGE_KEY = "lastAuthProvider";
export const PREFERRED_FIAT_PROVIDER_STORAGE_KEY = "preferredFiatProvider";

export async function setLastAuthProvider(
authProvider: AuthArgsType["strategy"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,10 @@
<ErrorBanner
client={client}
error={state.context.currentError}
onCancel={onCancel}
onCancel={() => {
send({ type: "RESET" });
onCancel?.();
}}

Check warning on line 233 in packages/thirdweb/src/react/web/ui/Bridge/BridgeOrchestrator.tsx

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/Bridge/BridgeOrchestrator.tsx#L230-L233

Added lines #L230 - L233 were not covered by tests
onRetry={handleRetry}
/>
)}
Expand Down
95 changes: 52 additions & 43 deletions packages/thirdweb/src/react/web/ui/ConnectWallet/Details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
} from "react";
import { trackPayEvent } from "../../../../analytics/track/pay.js";
import type { Chain } from "../../../../chains/types.js";
import { getCachedChain } from "../../../../chains/utils.js";
import type { ThirdwebClient } from "../../../../client/client.js";
import { getContract } from "../../../../contract/contract.js";
import type { SupportedFiatCurrency } from "../../../../pay/convert/type.js";
Expand Down Expand Up @@ -61,7 +62,10 @@
ConnectButtonProps,
PayUIOptions,
} from "../../../core/hooks/connection/ConnectButtonProps.js";
import { useChainFaucets } from "../../../core/hooks/others/useChainQuery.js";
import {
useChainFaucets,
useChainMetadata,
} from "../../../core/hooks/others/useChainQuery.js";
import { useActiveAccount } from "../../../core/hooks/wallets/useActiveAccount.js";
import { useActiveWallet } from "../../../core/hooks/wallets/useActiveWallet.js";
import { useActiveWalletChain } from "../../../core/hooks/wallets/useActiveWalletChain.js";
Expand All @@ -80,6 +84,7 @@
} from "../../../core/utils/defaultTokens.js";
import { useWalletInfo } from "../../../core/utils/wallet.js";
import { WalletUIStatesProvider } from "../../providers/wallet-ui-states-provider.js";
import { BuyWidget } from "../Bridge/BuyWidget.js";
import { Container, Line } from "../components/basic.js";
import { Button, IconButton } from "../components/buttons.js";
import { ChainActiveDot } from "../components/ChainActiveDot.js";
Expand Down Expand Up @@ -116,7 +121,6 @@
NetworkSelectorContent,
type NetworkSelectorProps,
} from "./NetworkSelector.js";
import { LazyBuyScreen } from "./screens/Buy/LazyBuyScreen.js";
import { WalletManagerScreen } from "./screens/Details/WalletManagerScreen.js";
import { LinkedProfilesScreen } from "./screens/LinkedProfilesScreen.js";
import { LinkProfileScreen } from "./screens/LinkProfileScreen.js";
Expand Down Expand Up @@ -390,6 +394,7 @@

const activeWallet = useActiveWallet();
const chainFaucetsQuery = useChainFaucets(walletChain);
const chainMetadataQuery = useChainMetadata(walletChain);

const disableSwitchChain = !activeWallet?.switchChain;

Expand Down Expand Up @@ -622,33 +627,35 @@
</Button>
)}

{!hideBuyFunds && (
<Button
onClick={() => {
trackPayEvent({
client: client,
event: "details_modal_buy_click",
walletAddress: activeAccount?.address,
walletType: activeWallet?.id,
});
setScreen("buy");
}}
style={{
alignItems: "center",
display: "flex",
flex: 1,
fontSize: fontSize.sm,
gap: spacing.xs,
padding: spacing.sm,
}}
variant="outline"
>
<Container center="both" color="secondaryText" flex="row">
<PlusIcon height={iconSize.sm} width={iconSize.sm} />
</Container>
{locale.buy}
</Button>
)}
{!hideBuyFunds &&
chainMetadataQuery.data &&
!chainMetadataQuery.data.testnet && (
<Button
onClick={() => {
trackPayEvent({
client: client,
event: "details_modal_buy_click",
walletAddress: activeAccount?.address,
walletType: activeWallet?.id,
});
setScreen("buy");
}}
style={{
alignItems: "center",
display: "flex",
flex: 1,
fontSize: fontSize.sm,
gap: spacing.xs,
padding: spacing.sm,
}}
variant="outline"

Check warning on line 651 in packages/thirdweb/src/react/web/ui/ConnectWallet/Details.tsx

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/ConnectWallet/Details.tsx#L633-L651

Added lines #L633 - L651 were not covered by tests
>
<Container center="both" color="secondaryText" flex="row">
<PlusIcon height={iconSize.sm} width={iconSize.sm} />
</Container>
{locale.buy}
</Button>

Check warning on line 657 in packages/thirdweb/src/react/web/ui/ConnectWallet/Details.tsx

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/ConnectWallet/Details.tsx#L653-L657

Added lines #L653 - L657 were not covered by tests
)}
</Container>
</Container>

Expand Down Expand Up @@ -956,23 +963,26 @@

// thirdweb pay
else if (screen === "buy") {
const requestedChainId =
props.detailsModal?.payOptions?.prefillBuy?.chain?.id ||
walletChain?.id ||
props.chains[0]?.id ||
1;

Check warning on line 970 in packages/thirdweb/src/react/web/ui/ConnectWallet/Details.tsx

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/ConnectWallet/Details.tsx#L966-L970

Added lines #L966 - L970 were not covered by tests
content = (
<LazyBuyScreen
<BuyWidget
amount={props.detailsModal?.payOptions?.prefillBuy?.amount || "0.01"}
chain={getCachedChain(requestedChainId)}

Check warning on line 974 in packages/thirdweb/src/react/web/ui/ConnectWallet/Details.tsx

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/ConnectWallet/Details.tsx#L972-L974

Added lines #L972 - L974 were not covered by tests
client={client}
connectLocale={locale}
connectOptions={undefined}
hiddenWallets={props.detailsModal?.hiddenWallets}
isEmbed={false}
onBack={() => setScreen("main")}
onDone={closeModal}
payOptions={
props.detailsModal?.payOptions || {
mode: "fund_wallet",
}
}
locale={locale.id}
onCancel={() => setScreen("main")}
onSuccess={() => setScreen("main")}

Check warning on line 979 in packages/thirdweb/src/react/web/ui/ConnectWallet/Details.tsx

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/ConnectWallet/Details.tsx#L977-L979

Added lines #L977 - L979 were not covered by tests
supportedTokens={props.supportedTokens}
theme={typeof props.theme === "string" ? props.theme : props.theme.type}
title={locale.buy}
tokenAddress={
props.displayBalanceToken?.[Number(requestedChainId)] as

Check warning on line 982 in packages/thirdweb/src/react/web/ui/ConnectWallet/Details.tsx

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/ConnectWallet/Details.tsx#L981-L982

Added lines #L981 - L982 were not covered by tests
| `0x${string}`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Address type

| undefined
}
/>
);
}
Expand Down Expand Up @@ -1143,7 +1153,6 @@
transition: "background 250ms ease",
},
alignItems: "center",
all: "unset",
animation: `${fadeInAnimation} 300ms ease`,
background: theme.colors.connectedButtonBg,
border: `1px solid ${theme.colors.borderColor}`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export const MenuButton = /* @__PURE__ */ StyledButton((_) => {
cursor: "not-allowed",
},
alignItems: "center",
all: "unset",
backgroundColor: "transparent",
borderRadius: radius.md,
// border: `1px solid ${theme.colors.borderColor}`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -690,12 +690,10 @@ export const ChainButton = /* @__PURE__ */ memo(function ChainButton(props: {
)}
</Container>
{confirming || switchingFailed ? (
<div
style={{
display: "flex",
flexDirection: "column",
gap: spacing.xs,
}}
<Container
flex="column"
gap="3xs"
style={{ alignItems: "flex-start", width: "100%" }}
>
<ChainName
loadingComponent={<Skeleton height="20px" width="150px" />}
Expand All @@ -718,7 +716,7 @@ export const ChainButton = /* @__PURE__ */ memo(function ChainButton(props: {
</Container>
)}
</Container>
</div>
</Container>
) : (
<ChainName
className="tw-chain-icon-none-confirming"
Expand All @@ -741,7 +739,6 @@ export const TabButton = /* @__PURE__ */ (() =>
background: theme.colors.secondaryButtonBg,
color: theme.colors.primaryText,
},
all: "unset",
borderRadius: radius.lg,
color: theme.colors.secondaryText,
cursor: "pointer",
Expand Down Expand Up @@ -787,7 +784,6 @@ export const NetworkButton = /* @__PURE__ */ StyledButton((_) => {
background: theme.colors.secondaryButtonBg,
},
alignItems: "center",
all: "unset",
borderRadius: radius.md,
boxSizing: "border-box",
color: theme.colors.primaryText,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,6 @@ const ShowAllWalletsIcon = /* @__PURE__ */ StyledDiv(() => {
});

const WalletList = /* @__PURE__ */ StyledUl({
all: "unset",
boxSizing: "border-box",
display: "flex",
flex: 1,
Expand Down
Loading
Loading