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

Fixes PayEmbed error state appearing on certain errors
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import { useActiveAccount } from "../../../../../core/hooks/wallets/useActiveAccount.js";
import { invalidateWalletBalance } from "../../../../../core/providers/invalidateWalletBalance.js";
import type { SupportedTokens } from "../../../../../core/utils/defaultTokens.js";
import { ErrorState } from "../../../../wallets/shared/ErrorState.js";
import { LoadingScreen } from "../../../../wallets/shared/LoadingScreen.js";
import type { PayEmbedConnectOptions } from "../../../PayEmbed.js";
import { ChainName } from "../../../components/ChainName.js";
Expand Down Expand Up @@ -105,6 +106,24 @@
isTestMode,
);

if (supportedDestinationsQuery.isError) {
return (
<Container
style={{
minHeight: "350px",
}}
fullHeight
flex="row"
center="both"

Check warning on line 117 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#L109-L117

Added lines #L109 - L117 were not covered by tests
>
<ErrorState
title="Something went wrong"
onTryAgain={supportedDestinationsQuery.refetch}
/>
</Container>

Check warning on line 123 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#L119-L123

Added lines #L119 - L123 were not covered by tests
);
}

Check warning on line 125 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#L125

Added line #L125 was not covered by tests

if (!supportedDestinationsQuery.data) {
return <LoadingScreen />;
}
Expand Down Expand Up @@ -137,9 +156,11 @@
*/
function BuyScreenContent(props: BuyScreenContentProps) {
const { client, supportedDestinations, connectLocale, payOptions } = props;
console.log("BuyScreenContent");

Check warning on line 159 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#L159

Added line #L159 was not covered by tests

const activeAccount = useActiveAccount();
const { payer, setPayer } = usePayerSetup();
console.log("payer", payer);

Check warning on line 163 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#L163

Added line #L163 was not covered by tests
Comment on lines +159 to +163
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove the console.log statements on lines 159 and 162. These appear to be debugging statements that were inadvertently committed. The codebase should remain free of development logging in production.

Spotted by Graphite Reviewer

Is this helpful? React 👍 or 👎 to let us know.


const [screen, setScreen] = useState<SelectedScreen>({
id: "main",
Expand Down Expand Up @@ -477,6 +498,8 @@
);
}

console.log("SCREEN", screen.id);

Check warning on line 501 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#L501

Added line #L501 was not covered by tests

return (
<Container animate="fadein">
<div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import { useActiveAccount } from "../../../../../core/hooks/wallets/useActiveAccount.js";
import { useActiveWallet } from "../../../../../core/hooks/wallets/useActiveWallet.js";
import { hasSponsoredTransactionsEnabled } from "../../../../../core/utils/wallet.js";
import { ErrorState } from "../../../../wallets/shared/ErrorState.js";
import { LoadingScreen } from "../../../../wallets/shared/LoadingScreen.js";
import type { PayEmbedConnectOptions } from "../../../PayEmbed.js";
import { ChainIcon } from "../../../components/ChainIcon.js";
Expand Down Expand Up @@ -54,9 +55,19 @@
supportedDestinations,
onContinue,
} = props;
const { data: chainData } = useChainMetadata(payUiOptions.transaction.chain);
const {
data: chainData,
error: chainDataError,
isLoading: chainDataLoading,
refetch: chainDataRefetch,
} = useChainMetadata(payUiOptions.transaction.chain);

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

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/TransactionModeScreen.tsx#L58-L63

Added lines #L58 - L63 were not covered by tests
const metadata = payUiOptions.metadata;
const { data: transactionCostAndData } = useTransactionCostAndData({
const {
data: transactionCostAndData,
error: transactionCostAndDataError,
isLoading: transactionCostAndDataLoading,
refetch: transactionCostAndDataRefetch,
} = useTransactionCostAndData({

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

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/TransactionModeScreen.tsx#L65-L70

Added lines #L65 - L70 were not covered by tests
transaction: payUiOptions.transaction,
account: payerAccount,
supportedDestinations,
Expand All @@ -80,6 +91,36 @@
},
);

if (transactionCostAndDataLoading || chainDataLoading) {
return <LoadingScreen />;
}

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

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/TransactionModeScreen.tsx#L94-L96

Added lines #L94 - L96 were not covered by tests

if (transactionCostAndDataError || chainDataError) {
return (
<Container
style={{
minHeight: "350px",
}}
fullHeight
flex="row"
center="both"

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

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/TransactionModeScreen.tsx#L98-L106

Added lines #L98 - L106 were not covered by tests
>
<ErrorState
title={
transactionCostAndDataError?.message ||
chainDataError?.message ||
"Something went wrong"

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

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/TransactionModeScreen.tsx#L108-L112

Added lines #L108 - L112 were not covered by tests
}
onTryAgain={
transactionCostAndDataError
? transactionCostAndDataRefetch
: chainDataRefetch

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

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/TransactionModeScreen.tsx#L114-L117

Added lines #L114 - L117 were not covered by tests
}
/>
</Container>

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

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/TransactionModeScreen.tsx#L119-L120

Added lines #L119 - L120 were not covered by tests
);
}

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

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/TransactionModeScreen.tsx#L122

Added line #L122 was not covered by tests

if (!transactionCostAndData || !chainData) {
return <LoadingScreen />;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
],
queryFn: async () => {
if (!account) {
throw new Error("No account");
throw new Error("No payer account found");

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

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/main/useBuyTxStates.ts#L61

Added line #L61 was not covered by tests
}

const erc20Value = await resolvePromisedValue(transaction.erc20Value);
Expand Down Expand Up @@ -112,7 +112,6 @@
getChainMetadata(transaction.chain),
getTransactionGasCost(transaction, account?.address),
]);

const walletBalance = nativeWalletBalance;
const transactionValueWei =
(await resolvePromisedValue(transaction.value)) || 0n;
Expand All @@ -129,7 +128,7 @@
transactionValueWei,
} satisfies TransactionCostAndData;
},
enabled: !!transaction && !!account && !!txQueryKey,
enabled: !!transaction && !!txQueryKey,

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

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/main/useBuyTxStates.ts#L131

Added line #L131 was not covered by tests
refetchInterval: () => {
if (transaction.erc20Value) {
// if erc20 value is set, we don't need to poll
Expand Down
Loading