Skip to content

Commit

Permalink
[Dashboard] Fix: Nebula send transaction params (#5744)
Browse files Browse the repository at this point in the history
<!-- start pr-codex -->

## PR-Codex overview
This PR enhances the `SendTransactionButton` component in `Chats.tsx` by introducing improved transaction handling and validation through the addition of a blockchain `chain` context and the `sendTransaction` method.

### Detailed summary
- Added import for `sendTransaction` from `thirdweb`.
- Introduced `chain` variable using `useV5DashboardChain`.
- Updated transaction validation to check for both `txData` and `chain`.
- Refactored transaction sending logic to use `sendTransaction` with detailed parameters.

> ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}`

<!-- end pr-codex -->
  • Loading branch information
gregfromstl committed Dec 15, 2024
1 parent f91f631 commit 0ddc123
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions apps/dashboard/src/app/nebula-app/(app)/components/Chats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ import {
import { useState } from "react";
import { toast } from "sonner";
import type { ThirdwebClient } from "thirdweb";
import { sendTransaction } from "thirdweb";
import { useActiveAccount } from "thirdweb/react";
import type { Account } from "thirdweb/wallets";
import { getThirdwebClient } from "../../../../@/constants/thirdweb.server";
import { TransactionButton } from "../../../../components/buttons/TransactionButton";
import { MarkdownRenderer } from "../../../../components/contract-components/published-contract/markdown-renderer";
import { useV5DashboardChain } from "../../../../lib/v5-adapter";
import { submitFeedback } from "../api/feedback";
import { NebulaIcon } from "../icons/NebulaIcon";

Expand Down Expand Up @@ -241,16 +244,28 @@ function SendTransactionButton(props: {
twAccount: TWAccount;
}) {
const account = useActiveAccount();
const chain = useV5DashboardChain(props.txData?.chainId);

const sendTxMutation = useMutation({
mutationFn: () => {
if (!account) {
throw new Error("No active account");
}

if (!props.txData) {
if (!props.txData || !chain) {
throw new Error("Invalid transaction");
}
return account.sendTransaction(props.txData);

return sendTransaction({
account,
transaction: {
...props.txData,
nonce: Number(props.txData.nonce),
to: props.txData.to || undefined, // Get rid of the potential null value
chain,
client: getThirdwebClient(),
},
});
},
});

Expand Down

0 comments on commit 0ddc123

Please sign in to comment.