Skip to content

Commit 5a40c6a

Browse files
authored
1 parent 1698c40 commit 5a40c6a

File tree

3 files changed

+62
-50
lines changed

3 files changed

+62
-50
lines changed

.changeset/strong-onions-sing.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+
fix losing state when looking at transactions during pay

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -498,20 +498,6 @@ function BuyScreenContent(props: BuyScreenContentProps) {
498498
)}
499499

500500
<Container px="lg" flex="column" gap="sm">
501-
{account && (
502-
<Button
503-
variant="outline"
504-
fullWidth
505-
style={{
506-
padding: spacing.xs,
507-
fontSize: fontSize.sm,
508-
}}
509-
onClick={props.onViewPendingTx}
510-
>
511-
View all transactions
512-
</Button>
513-
)}
514-
515501
{!isExpanded && (
516502
<>
517503
{!account && props.connectButton ? (
@@ -528,6 +514,20 @@ function BuyScreenContent(props: BuyScreenContentProps) {
528514
)}
529515
</>
530516
)}
517+
518+
{account && (
519+
<Button
520+
variant="outline"
521+
fullWidth
522+
style={{
523+
padding: spacing.xs,
524+
fontSize: fontSize.sm,
525+
}}
526+
onClick={props.onViewPendingTx}
527+
>
528+
View all transactions
529+
</Button>
530+
)}
531531
</Container>
532532

533533
<Spacer y="lg" />

packages/thirdweb/src/react/web/ui/PayEmbed.tsx

Lines changed: 43 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"use client";
2+
13
import { useState } from "react";
24
import type { Chain } from "../../../chains/types.js";
35
import type { ThirdwebClient } from "../../../client/client.js";
@@ -165,47 +167,52 @@ export function PayEmbed(props: PayEmbedProps) {
165167
<Spinner size="xl" color="secondaryText" />
166168
</div>
167169
);
168-
} else if (screen === "tx-history") {
169-
content = (
170-
<BuyTxHistory
171-
client={props.client}
172-
onBack={() => {
173-
setScreen("buy");
174-
}}
175-
onDone={() => {
176-
// noop
177-
}}
178-
isBuyForTx={false}
179-
isEmbed={true}
180-
/>
181-
);
182170
} else {
171+
// show and hide screens with CSS to not lose state when switching between them
183172
content = (
184-
<BuyScreen
185-
isEmbed={true}
186-
supportedTokens={props.supportedTokens}
187-
theme={props.theme || "dark"}
188-
client={props.client}
189-
connectLocale={localeQuery.data}
190-
onViewPendingTx={() => {
191-
setScreen("tx-history");
192-
}}
193-
payOptions={props.payOptions || {}}
194-
onDone={() => {
195-
// noop
196-
}}
197-
connectButton={
198-
<ConnectButton
199-
{...props.connectOptions}
173+
<>
174+
<div style={{ display: screen === "tx-history" ? "none" : "inherit" }}>
175+
<BuyScreen
176+
isEmbed={true}
177+
supportedTokens={props.supportedTokens}
178+
theme={props.theme || "dark"}
179+
client={props.client}
180+
connectLocale={localeQuery.data}
181+
onViewPendingTx={() => {
182+
setScreen("tx-history");
183+
}}
184+
payOptions={props.payOptions || {}}
185+
onDone={() => {
186+
// noop
187+
}}
188+
connectButton={
189+
<ConnectButton
190+
{...props.connectOptions}
191+
client={props.client}
192+
connectButton={{
193+
style: {
194+
width: "100%",
195+
},
196+
}}
197+
/>
198+
}
199+
/>
200+
</div>
201+
{/* this does not need to persist so we can just show-hide it with JS */}
202+
{screen === "tx-history" && (
203+
<BuyTxHistory
200204
client={props.client}
201-
connectButton={{
202-
style: {
203-
width: "100%",
204-
},
205+
onBack={() => {
206+
setScreen("buy");
207+
}}
208+
onDone={() => {
209+
// noop
205210
}}
211+
isBuyForTx={false}
212+
isEmbed={true}
206213
/>
207-
}
208-
/>
214+
)}
215+
</>
209216
);
210217
}
211218

0 commit comments

Comments
 (0)