Skip to content

Commit

Permalink
connect wallet prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
0xAlec committed Sep 5, 2024
1 parent 2542d60 commit 402135b
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/transaction/components/TransactionButton.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useCallback, useMemo } from 'react';
import { useAccount, useChainId } from 'wagmi';
import { useAccount, useChainId, useConnect } from 'wagmi';
import { useShowCallsStatus } from 'wagmi/experimental';
import { Spinner } from '../../internal/components/Spinner';
import { getChainExplorer } from '../../network/getChainExplorer';
Expand All @@ -26,13 +26,14 @@ export function TransactionButton({
} = useTransactionContext();

const { address } = useAccount();
const { connectAsync, connectors } = useConnect();

Check failure on line 29 in src/transaction/components/TransactionButton.tsx

View workflow job for this annotation

GitHub Actions / build (18.x)

src/transaction/components/TransactionButton.test.tsx > TransactionButton > renders correctly

Error: [vitest] No "useConnect" export is defined on the "wagmi" mock. Did you forget to return it from "vi.mock"? If you need to partially mock a module, you can use "importOriginal" helper inside: vi.mock("wagmi", async (importOriginal) => { const actual = await importOriginal() return { ...actual, // your mocked methods } }) ❯ TransactionButton src/transaction/components/TransactionButton.tsx:29:40 ❯ renderWithHooks node_modules/react-dom/cjs/react-dom.development.js:15486:18 ❯ mountIndeterminateComponent node_modules/react-dom/cjs/react-dom.development.js:20103:13 ❯ beginWork node_modules/react-dom/cjs/react-dom.development.js:21626:16 ❯ beginWork$1 node_modules/react-dom/cjs/react-dom.development.js:27465:14 ❯ performUnitOfWork node_modules/react-dom/cjs/react-dom.development.js:26599:12 ❯ workLoopSync node_modules/react-dom/cjs/react-dom.development.js:26505:5 ❯ renderRootSync node_modules/react-dom/cjs/react-dom.development.js:26473:7

Check failure on line 29 in src/transaction/components/TransactionButton.tsx

View workflow job for this annotation

GitHub Actions / build (18.x)

src/transaction/components/TransactionButton.test.tsx > TransactionButton > renders spinner correctly

Error: [vitest] No "useConnect" export is defined on the "wagmi" mock. Did you forget to return it from "vi.mock"? If you need to partially mock a module, you can use "importOriginal" helper inside: vi.mock("wagmi", async (importOriginal) => { const actual = await importOriginal() return { ...actual, // your mocked methods } }) ❯ TransactionButton src/transaction/components/TransactionButton.tsx:29:40 ❯ renderWithHooks node_modules/react-dom/cjs/react-dom.development.js:15486:18 ❯ mountIndeterminateComponent node_modules/react-dom/cjs/react-dom.development.js:20103:13 ❯ beginWork node_modules/react-dom/cjs/react-dom.development.js:21626:16 ❯ beginWork$1 node_modules/react-dom/cjs/react-dom.development.js:27465:14 ❯ performUnitOfWork node_modules/react-dom/cjs/react-dom.development.js:26599:12 ❯ workLoopSync node_modules/react-dom/cjs/react-dom.development.js:26505:5 ❯ renderRootSync node_modules/react-dom/cjs/react-dom.development.js:26473:7

Check failure on line 29 in src/transaction/components/TransactionButton.tsx

View workflow job for this annotation

GitHub Actions / build (18.x)

src/transaction/components/TransactionButton.test.tsx > TransactionButton > renders view txn text when receipt exists

Error: [vitest] No "useConnect" export is defined on the "wagmi" mock. Did you forget to return it from "vi.mock"? If you need to partially mock a module, you can use "importOriginal" helper inside: vi.mock("wagmi", async (importOriginal) => { const actual = await importOriginal() return { ...actual, // your mocked methods } }) ❯ TransactionButton src/transaction/components/TransactionButton.tsx:29:40 ❯ renderWithHooks node_modules/react-dom/cjs/react-dom.development.js:15486:18 ❯ mountIndeterminateComponent node_modules/react-dom/cjs/react-dom.development.js:20103:13 ❯ beginWork node_modules/react-dom/cjs/react-dom.development.js:21626:16 ❯ beginWork$1 node_modules/react-dom/cjs/react-dom.development.js:27465:14 ❯ performUnitOfWork node_modules/react-dom/cjs/react-dom.development.js:26599:12 ❯ workLoopSync node_modules/react-dom/cjs/react-dom.development.js:26505:5 ❯ renderRootSync node_modules/react-dom/cjs/react-dom.development.js:26473:7

Check failure on line 29 in src/transaction/components/TransactionButton.tsx

View workflow job for this annotation

GitHub Actions / build (18.x)

src/transaction/components/TransactionButton.test.tsx > TransactionButton > renders try again when error exists

Error: [vitest] No "useConnect" export is defined on the "wagmi" mock. Did you forget to return it from "vi.mock"? If you need to partially mock a module, you can use "importOriginal" helper inside: vi.mock("wagmi", async (importOriginal) => { const actual = await importOriginal() return { ...actual, // your mocked methods } }) ❯ TransactionButton src/transaction/components/TransactionButton.tsx:29:40 ❯ renderWithHooks node_modules/react-dom/cjs/react-dom.development.js:15486:18 ❯ mountIndeterminateComponent node_modules/react-dom/cjs/react-dom.development.js:20103:13 ❯ beginWork node_modules/react-dom/cjs/react-dom.development.js:21626:16 ❯ beginWork$1 node_modules/react-dom/cjs/react-dom.development.js:27465:14 ❯ performUnitOfWork node_modules/react-dom/cjs/react-dom.development.js:26599:12 ❯ workLoopSync node_modules/react-dom/cjs/react-dom.development.js:26505:5 ❯ renderRootSync node_modules/react-dom/cjs/react-dom.development.js:26473:7

Check failure on line 29 in src/transaction/components/TransactionButton.tsx

View workflow job for this annotation

GitHub Actions / build (18.x)

src/transaction/components/TransactionButton.test.tsx > TransactionButton > should have disabled attribute when isDisabled is true

Error: [vitest] No "useConnect" export is defined on the "wagmi" mock. Did you forget to return it from "vi.mock"? If you need to partially mock a module, you can use "importOriginal" helper inside: vi.mock("wagmi", async (importOriginal) => { const actual = await importOriginal() return { ...actual, // your mocked methods } }) ❯ TransactionButton src/transaction/components/TransactionButton.tsx:29:40 ❯ renderWithHooks node_modules/react-dom/cjs/react-dom.development.js:15486:18 ❯ mountIndeterminateComponent node_modules/react-dom/cjs/react-dom.development.js:20103:13 ❯ beginWork node_modules/react-dom/cjs/react-dom.development.js:21626:16 ❯ beginWork$1 node_modules/react-dom/cjs/react-dom.development.js:27465:14 ❯ performUnitOfWork node_modules/react-dom/cjs/react-dom.development.js:26599:12 ❯ workLoopSync node_modules/react-dom/cjs/react-dom.development.js:26505:5 ❯ renderRootSync node_modules/react-dom/cjs/react-dom.development.js:26473:7

Check failure on line 29 in src/transaction/components/TransactionButton.tsx

View workflow job for this annotation

GitHub Actions / build (18.x)

src/transaction/components/TransactionButton.test.tsx > TransactionButton > should have disabled attribute when txn is in progress

Error: [vitest] No "useConnect" export is defined on the "wagmi" mock. Did you forget to return it from "vi.mock"? If you need to partially mock a module, you can use "importOriginal" helper inside: vi.mock("wagmi", async (importOriginal) => { const actual = await importOriginal() return { ...actual, // your mocked methods } }) ❯ TransactionButton src/transaction/components/TransactionButton.tsx:29:40 ❯ renderWithHooks node_modules/react-dom/cjs/react-dom.development.js:15486:18 ❯ mountIndeterminateComponent node_modules/react-dom/cjs/react-dom.development.js:20103:13 ❯ beginWork node_modules/react-dom/cjs/react-dom.development.js:21626:16 ❯ beginWork$1 node_modules/react-dom/cjs/react-dom.development.js:27465:14 ❯ performUnitOfWork node_modules/react-dom/cjs/react-dom.development.js:26599:12 ❯ workLoopSync node_modules/react-dom/cjs/react-dom.development.js:26505:5 ❯ renderRootSync node_modules/react-dom/cjs/react-dom.development.js:26473:7

Check failure on line 29 in src/transaction/components/TransactionButton.tsx

View workflow job for this annotation

GitHub Actions / build (18.x)

src/transaction/components/TransactionButton.test.tsx > TransactionButton > should have disabled when contracts are missing

Error: [vitest] No "useConnect" export is defined on the "wagmi" mock. Did you forget to return it from "vi.mock"? If you need to partially mock a module, you can use "importOriginal" helper inside: vi.mock("wagmi", async (importOriginal) => { const actual = await importOriginal() return { ...actual, // your mocked methods } }) ❯ TransactionButton src/transaction/components/TransactionButton.tsx:29:40 ❯ renderWithHooks node_modules/react-dom/cjs/react-dom.development.js:15486:18 ❯ mountIndeterminateComponent node_modules/react-dom/cjs/react-dom.development.js:20103:13 ❯ beginWork node_modules/react-dom/cjs/react-dom.development.js:21626:16 ❯ beginWork$1 node_modules/react-dom/cjs/react-dom.development.js:27465:14 ❯ performUnitOfWork node_modules/react-dom/cjs/react-dom.development.js:26599:12 ❯ workLoopSync node_modules/react-dom/cjs/react-dom.development.js:26505:5 ❯ renderRootSync node_modules/react-dom/cjs/react-dom.development.js:26473:7

Check failure on line 29 in src/transaction/components/TransactionButton.tsx

View workflow job for this annotation

GitHub Actions / build (18.x)

src/transaction/components/TransactionButton.test.tsx > TransactionButton > should call showCallsStatus when receipt and transactionId exist

Error: [vitest] No "useConnect" export is defined on the "wagmi" mock. Did you forget to return it from "vi.mock"? If you need to partially mock a module, you can use "importOriginal" helper inside: vi.mock("wagmi", async (importOriginal) => { const actual = await importOriginal() return { ...actual, // your mocked methods } }) ❯ TransactionButton src/transaction/components/TransactionButton.tsx:29:40 ❯ renderWithHooks node_modules/react-dom/cjs/react-dom.development.js:15486:18 ❯ mountIndeterminateComponent node_modules/react-dom/cjs/react-dom.development.js:20103:13 ❯ beginWork node_modules/react-dom/cjs/react-dom.development.js:21626:16 ❯ beginWork$1 node_modules/react-dom/cjs/react-dom.development.js:27465:14 ❯ performUnitOfWork node_modules/react-dom/cjs/react-dom.development.js:26599:12 ❯ workLoopSync node_modules/react-dom/cjs/react-dom.development.js:26505:5 ❯ renderRootSync node_modules/react-dom/cjs/react-dom.development.js:26473:7

Check failure on line 29 in src/transaction/components/TransactionButton.tsx

View workflow job for this annotation

GitHub Actions / build (18.x)

src/transaction/components/TransactionButton.test.tsx > TransactionButton > should enable button when not in progress, not missing props, and not waiting for receipt

Error: [vitest] No "useConnect" export is defined on the "wagmi" mock. Did you forget to return it from "vi.mock"? If you need to partially mock a module, you can use "importOriginal" helper inside: vi.mock("wagmi", async (importOriginal) => { const actual = await importOriginal() return { ...actual, // your mocked methods } }) ❯ TransactionButton src/transaction/components/TransactionButton.tsx:29:40 ❯ renderWithHooks node_modules/react-dom/cjs/react-dom.development.js:15486:18 ❯ mountIndeterminateComponent node_modules/react-dom/cjs/react-dom.development.js:20103:13 ❯ beginWork node_modules/react-dom/cjs/react-dom.development.js:21626:16 ❯ beginWork$1 node_modules/react-dom/cjs/react-dom.development.js:27465:14 ❯ performUnitOfWork node_modules/react-dom/cjs/react-dom.development.js:26599:12 ❯ workLoopSync node_modules/react-dom/cjs/react-dom.development.js:26505:5 ❯ renderRootSync node_modules/react-dom/cjs/react-dom.development.js:26473:7

Check failure on line 29 in src/transaction/components/TransactionButton.tsx

View workflow job for this annotation

GitHub Actions / build (18.x)

src/transaction/components/TransactionButton.test.tsx > TransactionButton > should open transaction link when only receipt exists

Error: [vitest] No "useConnect" export is defined on the "wagmi" mock. Did you forget to return it from "vi.mock"? If you need to partially mock a module, you can use "importOriginal" helper inside: vi.mock("wagmi", async (importOriginal) => { const actual = await importOriginal() return { ...actual, // your mocked methods } }) ❯ TransactionButton src/transaction/components/TransactionButton.tsx:29:40 ❯ renderWithHooks node_modules/react-dom/cjs/react-dom.development.js:15486:18 ❯ mountIndeterminateComponent node_modules/react-dom/cjs/react-dom.development.js:20103:13 ❯ beginWork node_modules/react-dom/cjs/react-dom.development.js:21626:16 ❯ beginWork$1 node_modules/react-dom/cjs/react-dom.development.js:27465:14 ❯ performUnitOfWork node_modules/react-dom/cjs/react-dom.development.js:26599:12 ❯ workLoopSync node_modules/react-dom/cjs/react-dom.development.js:26505:5 ❯ renderRootSync node_modules/react-dom/cjs/react-dom.development.js:26473:7

const accountChainId = chainId ?? useChainId();
const { showCallsStatus } = useShowCallsStatus();

const isInProgress =
lifeCycleStatus.statusName === 'transactionPending' || isLoading;
const isMissingProps = !contracts || !address;
const isMissingProps = !contracts;
const isWaitingForReceipt = !!transactionId || !!transactionHash;

const isDisabled =
Expand All @@ -59,7 +60,10 @@ export function TransactionButton({
return buttonText;
}, [buttonText, errorMessage, receipt]);

const handleSubmit = useCallback(() => {
const handleSubmit = useCallback(async () => {
if (!address) {
await connectAsync({ connector: connectors[0] });
}
// SW will have txn id so open in wallet
if (receipt && transactionId) {
showCallsStatus({ id: transactionId });
Expand All @@ -76,7 +80,9 @@ export function TransactionButton({
onSubmit();
}
}, [
address,
accountChainId,
connectAsync,
onSubmit,
receipt,
showCallsStatus,
Expand Down

0 comments on commit 402135b

Please sign in to comment.