Skip to content

Commit

Permalink
fix: wallet connect out dah box
Browse files Browse the repository at this point in the history
  • Loading branch information
0xBunzy committed Oct 31, 2024
1 parent 2e7244b commit 11f329c
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 0 deletions.
65 changes: 65 additions & 0 deletions src/bin/script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,71 @@ async function run() {
shadcnInstall.on("close", (shadcnCode) => {
if (shadcnCode === 0) {
console.log("Shadcn installed successfully!");

// After successful Next.js project creation and shadcn installation
const installShadcnButton = spawn(
"npx",
["shadcn-ui@latest", "add", "button"],
{
cwd: projectPath,
stdio: "inherit",
}
);

installShadcnButton.on("close", (code) => {
if (code === 0) {
// Create components directory if it doesn't exist
const componentsDir = path.join(
projectPath,
"app/components"
);
if (!fs.existsSync(componentsDir)) {
fs.mkdirSync(componentsDir, { recursive: true });
}

// Move DefaultLayout.tsx and ConnectWallet.tsx to components folder
fs.renameSync(
path.join(projectPath, "app/DefaultLayout.tsx"),
path.join(componentsDir, "DefaultLayout.tsx")
);
fs.renameSync(
path.join(projectPath, "app/ConnectWallet.tsx"),
path.join(componentsDir, "ConnectWallet.tsx")
);

// Update import in ConnectWallet.tsx to use the correct button path
const connectWalletPath = path.join(
componentsDir,
"ConnectWallet.tsx"
);
let connectWalletContent = fs.readFileSync(
connectWalletPath,
"utf8"
);
connectWalletContent = connectWalletContent.replace(
'import { Button } from "./ui/button"',
'import { Button } from "@/components/ui/button"'
);
fs.writeFileSync(
connectWalletPath,
connectWalletContent
);

// Update layout.tsx to import DefaultLayout from new location
const layoutPath = path.join(
projectPath,
"app/layout.tsx"
);
let layoutContent = fs.readFileSync(layoutPath, "utf8");
layoutContent = layoutContent.replace(
'import DefaultLayout from "./DefaultLayout"',
'import DefaultLayout from "./components/DefaultLayout"'
);
fs.writeFileSync(layoutPath, layoutContent);

console.log("✨ Components organized successfully!");
}
});
} else {
console.error(
`Shadcn installation exited with code ${shadcnCode}`
Expand Down
26 changes: 26 additions & 0 deletions src/templates/next/app/ConnectWallet.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/** @format */

import { useLaserEyes, UNISAT } from "@omnisat/lasereyes";
import { Button } from "./ui/button";

export function ConnectWallet() {
const { connect, disconnect, connected, address } = useLaserEyes();

const handleClick = () => {
if (connected) {
disconnect();
} else {
connect(UNISAT);
}
};

return (
<Button onClick={handleClick} variant="outline" size="lg">
{!connected ? (
"Connect Wallet"
) : (
<span className="truncate max-w-[200px]">{address}</span>
)}
</Button>
);
}

0 comments on commit 11f329c

Please sign in to comment.