Skip to content

Commit c644463

Browse files
[SDK] Use new BuyWidget in wallet details modal (#7551)
1 parent 2136c7b commit c644463

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+81
-8027
lines changed

.changeset/dirty-bananas-fall.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"thirdweb": patch
3+
---
4+
5+
Use new BuyWidget in wallet details modal

packages/thirdweb/src/insight/common.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,3 @@ export async function assertInsightEnabled(chains: Chain[]) {
1414
);
1515
}
1616
}
17-
18-
export async function isInsightEnabled(chain: Chain) {
19-
const chainIds = await getInsightEnabledChainIds();
20-
return chainIds.includes(chain.id);
21-
}

packages/thirdweb/src/pay/buyWithCrypto/getStatus.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,6 @@ export type BuyWithCryptoStatus =
8484
purchaseData?: PurchaseData;
8585
};
8686

87-
export type ValidBuyWithCryptoStatus = Exclude<
88-
BuyWithCryptoStatus,
89-
{ status: "NOT_FOUND" }
90-
>;
91-
9287
/**
9388
* Gets the status of a buy with crypto transaction
9489
* @param buyWithCryptoTransaction - Object of type [`BuyWithCryptoTransaction`](https://portal.thirdweb.com/references/typescript/v5/BuyWithCryptoTransaction)
Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { getAddress } from "../../utils/address.js";
2-
import type { PayTokenInfo } from "../utils/commonTypes.js";
32
import type { BuyWithFiatQuote } from "./getQuote.js";
43

54
/**
@@ -28,58 +27,3 @@ export function isSwapRequiredPostOnramp(
2827

2928
return !(sameChain && sameToken);
3029
}
31-
32-
export function getOnRampSteps(
33-
buyWithFiatQuote: BuyWithFiatQuote,
34-
): OnRampStep[] {
35-
const isSwapRequired = isSwapRequiredPostOnramp(buyWithFiatQuote);
36-
37-
if (!isSwapRequired) {
38-
return [
39-
{
40-
action: "buy",
41-
amount: buyWithFiatQuote.estimatedToAmountMin,
42-
token: buyWithFiatQuote.toToken,
43-
},
44-
];
45-
}
46-
47-
if (buyWithFiatQuote.routingToken) {
48-
return [
49-
{
50-
action: "buy",
51-
amount: buyWithFiatQuote.onRampToken.amount,
52-
token: buyWithFiatQuote.onRampToken.token,
53-
},
54-
{
55-
action: "swap",
56-
amount: buyWithFiatQuote.routingToken.amount,
57-
token: buyWithFiatQuote.routingToken.token,
58-
},
59-
{
60-
action: "bridge",
61-
amount: buyWithFiatQuote.estimatedToAmountMin,
62-
token: buyWithFiatQuote.toToken,
63-
},
64-
];
65-
}
66-
67-
return [
68-
{
69-
action: "buy",
70-
amount: buyWithFiatQuote.onRampToken.amount,
71-
token: buyWithFiatQuote.onRampToken.token,
72-
},
73-
{
74-
action: "swap",
75-
amount: buyWithFiatQuote.estimatedToAmountMin,
76-
token: buyWithFiatQuote.toToken,
77-
},
78-
];
79-
}
80-
81-
export type OnRampStep = {
82-
action: "buy" | "swap" | "bridge";
83-
token: PayTokenInfo;
84-
amount: string;
85-
};

packages/thirdweb/src/pay/utils/commonTypes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ export type PayOnChainTransactionDetails = {
1919

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

22-
export const FiatProviders = ["coinbase", "stripe", "transak"] as const;
22+
const FiatProviders = ["coinbase", "stripe", "transak"] as const;

packages/thirdweb/src/react/core/hooks/usePaymentMethods.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,18 @@ export function usePaymentMethods(options: {
141141
limit: 100,
142142
maxSteps: 3,
143143
originChainId: chainId,
144-
sortBy: "popularity",
145144
});
146145

147146
// Add all origin tokens from this chain's routes
148147
for (const route of routesForChain) {
148+
// Skip if the origin token is the same as the destination token, will be added later only if includeDestinationToken is true
149+
if (
150+
route.originToken.chainId === destinationToken.chainId &&
151+
route.originToken.address.toLowerCase() ===
152+
destinationToken.address.toLowerCase()
153+
) {
154+
continue;
155+
}
149156
const tokenKey = `${route.originToken.chainId}-${route.originToken.address.toLowerCase()}`;
150157
allValidOriginTokens.set(tokenKey, route.originToken);
151158
}

packages/thirdweb/src/react/core/utils/storage.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import type { AsyncStorage } from "../../../utils/storage/AsyncStorage.js";
22
import type { AuthArgsType } from "../../../wallets/in-app/core/authentication/types.js";
33

44
export const LAST_AUTH_PROVIDER_STORAGE_KEY = "lastAuthProvider";
5-
export const PREFERRED_FIAT_PROVIDER_STORAGE_KEY = "preferredFiatProvider";
65

76
export async function setLastAuthProvider(
87
authProvider: AuthArgsType["strategy"],

packages/thirdweb/src/react/web/ui/Bridge/BridgeOrchestrator.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,10 @@ export function BridgeOrchestrator({
227227
<ErrorBanner
228228
client={client}
229229
error={state.context.currentError}
230-
onCancel={onCancel}
230+
onCancel={() => {
231+
send({ type: "RESET" });
232+
onCancel?.();
233+
}}
231234
onRetry={handleRetry}
232235
/>
233236
)}

packages/thirdweb/src/react/web/ui/ConnectWallet/Details.tsx

Lines changed: 52 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
} from "react";
2121
import { trackPayEvent } from "../../../../analytics/track/pay.js";
2222
import type { Chain } from "../../../../chains/types.js";
23+
import { getCachedChain } from "../../../../chains/utils.js";
2324
import type { ThirdwebClient } from "../../../../client/client.js";
2425
import { getContract } from "../../../../contract/contract.js";
2526
import type { SupportedFiatCurrency } from "../../../../pay/convert/type.js";
@@ -61,7 +62,10 @@ import type {
6162
ConnectButtonProps,
6263
PayUIOptions,
6364
} from "../../../core/hooks/connection/ConnectButtonProps.js";
64-
import { useChainFaucets } from "../../../core/hooks/others/useChainQuery.js";
65+
import {
66+
useChainFaucets,
67+
useChainMetadata,
68+
} from "../../../core/hooks/others/useChainQuery.js";
6569
import { useActiveAccount } from "../../../core/hooks/wallets/useActiveAccount.js";
6670
import { useActiveWallet } from "../../../core/hooks/wallets/useActiveWallet.js";
6771
import { useActiveWalletChain } from "../../../core/hooks/wallets/useActiveWalletChain.js";
@@ -80,6 +84,7 @@ import type {
8084
} from "../../../core/utils/defaultTokens.js";
8185
import { useWalletInfo } from "../../../core/utils/wallet.js";
8286
import { WalletUIStatesProvider } from "../../providers/wallet-ui-states-provider.js";
87+
import { BuyWidget } from "../Bridge/BuyWidget.js";
8388
import { Container, Line } from "../components/basic.js";
8489
import { Button, IconButton } from "../components/buttons.js";
8590
import { ChainActiveDot } from "../components/ChainActiveDot.js";
@@ -116,7 +121,6 @@ import {
116121
NetworkSelectorContent,
117122
type NetworkSelectorProps,
118123
} from "./NetworkSelector.js";
119-
import { LazyBuyScreen } from "./screens/Buy/LazyBuyScreen.js";
120124
import { WalletManagerScreen } from "./screens/Details/WalletManagerScreen.js";
121125
import { LinkedProfilesScreen } from "./screens/LinkedProfilesScreen.js";
122126
import { LinkProfileScreen } from "./screens/LinkProfileScreen.js";
@@ -390,6 +394,7 @@ export function DetailsModal(props: {
390394

391395
const activeWallet = useActiveWallet();
392396
const chainFaucetsQuery = useChainFaucets(walletChain);
397+
const chainMetadataQuery = useChainMetadata(walletChain);
393398

394399
const disableSwitchChain = !activeWallet?.switchChain;
395400

@@ -622,33 +627,35 @@ export function DetailsModal(props: {
622627
</Button>
623628
)}
624629

625-
{!hideBuyFunds && (
626-
<Button
627-
onClick={() => {
628-
trackPayEvent({
629-
client: client,
630-
event: "details_modal_buy_click",
631-
walletAddress: activeAccount?.address,
632-
walletType: activeWallet?.id,
633-
});
634-
setScreen("buy");
635-
}}
636-
style={{
637-
alignItems: "center",
638-
display: "flex",
639-
flex: 1,
640-
fontSize: fontSize.sm,
641-
gap: spacing.xs,
642-
padding: spacing.sm,
643-
}}
644-
variant="outline"
645-
>
646-
<Container center="both" color="secondaryText" flex="row">
647-
<PlusIcon height={iconSize.sm} width={iconSize.sm} />
648-
</Container>
649-
{locale.buy}
650-
</Button>
651-
)}
630+
{!hideBuyFunds &&
631+
chainMetadataQuery.data &&
632+
!chainMetadataQuery.data.testnet && (
633+
<Button
634+
onClick={() => {
635+
trackPayEvent({
636+
client: client,
637+
event: "details_modal_buy_click",
638+
walletAddress: activeAccount?.address,
639+
walletType: activeWallet?.id,
640+
});
641+
setScreen("buy");
642+
}}
643+
style={{
644+
alignItems: "center",
645+
display: "flex",
646+
flex: 1,
647+
fontSize: fontSize.sm,
648+
gap: spacing.xs,
649+
padding: spacing.sm,
650+
}}
651+
variant="outline"
652+
>
653+
<Container center="both" color="secondaryText" flex="row">
654+
<PlusIcon height={iconSize.sm} width={iconSize.sm} />
655+
</Container>
656+
{locale.buy}
657+
</Button>
658+
)}
652659
</Container>
653660
</Container>
654661

@@ -956,23 +963,26 @@ export function DetailsModal(props: {
956963

957964
// thirdweb pay
958965
else if (screen === "buy") {
966+
const requestedChainId =
967+
props.detailsModal?.payOptions?.prefillBuy?.chain?.id ||
968+
walletChain?.id ||
969+
props.chains[0]?.id ||
970+
1;
959971
content = (
960-
<LazyBuyScreen
972+
<BuyWidget
973+
amount={props.detailsModal?.payOptions?.prefillBuy?.amount || "0.01"}
974+
chain={getCachedChain(requestedChainId)}
961975
client={client}
962-
connectLocale={locale}
963-
connectOptions={undefined}
964976
hiddenWallets={props.detailsModal?.hiddenWallets}
965-
isEmbed={false}
966-
onBack={() => setScreen("main")}
967-
onDone={closeModal}
968-
payOptions={
969-
props.detailsModal?.payOptions || {
970-
mode: "fund_wallet",
971-
}
972-
}
977+
locale={locale.id}
978+
onCancel={() => setScreen("main")}
979+
onSuccess={() => setScreen("main")}
973980
supportedTokens={props.supportedTokens}
974-
theme={typeof props.theme === "string" ? props.theme : props.theme.type}
975-
title={locale.buy}
981+
tokenAddress={
982+
props.displayBalanceToken?.[Number(requestedChainId)] as
983+
| `0x${string}`
984+
| undefined
985+
}
976986
/>
977987
);
978988
}
@@ -1143,7 +1153,6 @@ const WalletInfoButton = /* @__PURE__ */ StyledButton((_) => {
11431153
transition: "background 250ms ease",
11441154
},
11451155
alignItems: "center",
1146-
all: "unset",
11471156
animation: `${fadeInAnimation} 300ms ease`,
11481157
background: theme.colors.connectedButtonBg,
11491158
border: `1px solid ${theme.colors.borderColor}`,

packages/thirdweb/src/react/web/ui/ConnectWallet/MenuButton.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ export const MenuButton = /* @__PURE__ */ StyledButton((_) => {
2525
cursor: "not-allowed",
2626
},
2727
alignItems: "center",
28-
all: "unset",
2928
backgroundColor: "transparent",
3029
borderRadius: radius.md,
3130
// border: `1px solid ${theme.colors.borderColor}`,

packages/thirdweb/src/react/web/ui/ConnectWallet/NetworkSelector.tsx

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -690,12 +690,10 @@ export const ChainButton = /* @__PURE__ */ memo(function ChainButton(props: {
690690
)}
691691
</Container>
692692
{confirming || switchingFailed ? (
693-
<div
694-
style={{
695-
display: "flex",
696-
flexDirection: "column",
697-
gap: spacing.xs,
698-
}}
693+
<Container
694+
flex="column"
695+
gap="3xs"
696+
style={{ alignItems: "flex-start", width: "100%" }}
699697
>
700698
<ChainName
701699
loadingComponent={<Skeleton height="20px" width="150px" />}
@@ -718,7 +716,7 @@ export const ChainButton = /* @__PURE__ */ memo(function ChainButton(props: {
718716
</Container>
719717
)}
720718
</Container>
721-
</div>
719+
</Container>
722720
) : (
723721
<ChainName
724722
className="tw-chain-icon-none-confirming"
@@ -741,7 +739,6 @@ export const TabButton = /* @__PURE__ */ (() =>
741739
background: theme.colors.secondaryButtonBg,
742740
color: theme.colors.primaryText,
743741
},
744-
all: "unset",
745742
borderRadius: radius.lg,
746743
color: theme.colors.secondaryText,
747744
cursor: "pointer",
@@ -787,7 +784,6 @@ export const NetworkButton = /* @__PURE__ */ StyledButton((_) => {
787784
background: theme.colors.secondaryButtonBg,
788785
},
789786
alignItems: "center",
790-
all: "unset",
791787
borderRadius: radius.md,
792788
boxSizing: "border-box",
793789
color: theme.colors.primaryText,

packages/thirdweb/src/react/web/ui/ConnectWallet/WalletSelector.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,6 @@ const ShowAllWalletsIcon = /* @__PURE__ */ StyledDiv(() => {
720720
});
721721

722722
const WalletList = /* @__PURE__ */ StyledUl({
723-
all: "unset",
724723
boxSizing: "border-box",
725724
display: "flex",
726725
flex: 1,

0 commit comments

Comments
 (0)