-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0e94e11
commit 0613541
Showing
16 changed files
with
145 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
/node_modules | ||
/docs/dist | ||
/generated |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { Sandpack } from "@codesandbox/sandpack-react"; | ||
import { staticRequestAccounts, staticRequestAccountsScript } from "../../../generated/sandpackFiles"; | ||
|
||
export default function RequestAccountsHTML() { | ||
return ( | ||
<Sandpack | ||
template="static" | ||
files={{ | ||
"index.html": staticRequestAccounts, | ||
"app.js": staticRequestAccountsScript, | ||
}} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 2 additions & 4 deletions
6
docs/codeStrings/react/config.ts → ...components/sandpack/files/react/config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,8 @@ | ||
const config = `import { CoinbaseWalletSDK } from "@coinbase/wallet-sdk"; | ||
import { CoinbaseWalletSDK } from "@coinbase/wallet-sdk"; | ||
|
||
const baseSepoliaChainId = 84532; | ||
|
||
export const sdk = new CoinbaseWalletSDK({ | ||
appName: "My App Name", | ||
appChainIds: [baseSepoliaChainId], | ||
})`; | ||
|
||
export default config; | ||
}); |
17 changes: 17 additions & 0 deletions
17
docs/components/sandpack/files/static/requestAccounts.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Connect to Coinbase Wallet</title> | ||
<script src="app.js" type="module"></script> | ||
</head> | ||
<body> | ||
<div id="app"> | ||
<button id="connectButton">Connect</button> | ||
<p id="connectedAddress" style="display: none;"> | ||
Connected address: <span id="address"></span> | ||
</p> | ||
</div> | ||
</body> | ||
</html> |
32 changes: 32 additions & 0 deletions
32
docs/components/sandpack/files/static/requestAccountsScript.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import CoinbaseWalletSDK from "https://esm.sh/@coinbase/wallet-sdk"; | ||
|
||
document.addEventListener("DOMContentLoaded", () => { | ||
const baseSepoliaChainId = 84532; | ||
|
||
const coinbaseWallet = new CoinbaseWalletSDK({ | ||
appName: "My App Name", | ||
appChainIds: [baseSepoliaChainId], // Replace with your chain IDs if needed | ||
}); | ||
|
||
const provider = coinbaseWallet.makeWeb3Provider({ options: "smartWalletOnly" }); | ||
|
||
const connectButton = document.getElementById("connectButton"); | ||
const connectedAddressParagraph = document.getElementById("connectedAddress"); | ||
const addressSpan = document.getElementById("address"); | ||
|
||
// Event listener for the connect button | ||
connectButton.addEventListener("click", async () => { | ||
try { | ||
// Request accounts from the provider | ||
const accounts = await provider.request({ method: "eth_requestAccounts" }); | ||
if (accounts.length > 0) { | ||
// Update the UI to show the connected address | ||
addressSpan.textContent = accounts[0]; | ||
connectedAddressParagraph.style.display = "block"; | ||
connectButton.style.display = "none"; | ||
} | ||
} catch (error) { | ||
console.error("Error connecting to Coinbase Wallet:", error); | ||
} | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
Empty file.
This file was deleted.
Oops, something went wrong.
4 changes: 2 additions & 2 deletions
4
docs/pages/sdk/CoinbaseWalletProvider/request/eth_requestAccounts.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
const fs = require("fs"); | ||
const path = require("path"); | ||
|
||
const sandpackDir = path.join(__dirname, "docs", "components", "sandpack", "files"); | ||
const outputFile = path.join(__dirname, "generated", "sandpackFiles.ts"); | ||
|
||
function readDirectoryRecursively(dir) { | ||
const results = {}; | ||
const list = fs.readdirSync(dir); | ||
|
||
list.forEach(file => { | ||
const filePath = path.join(dir, file); | ||
const stat = fs.statSync(filePath); | ||
|
||
if (stat && stat.isDirectory()) { | ||
results[file] = readDirectoryRecursively(filePath); | ||
} else { | ||
results[file] = fs.readFileSync(filePath, "utf8"); | ||
} | ||
}); | ||
|
||
return results; | ||
} | ||
|
||
const sandpackExamples = readDirectoryRecursively(sandpackDir); | ||
|
||
// Generate TypeScript content | ||
let tsContent = `// This file is auto-generated. Do not edit manually.\n\n`; | ||
|
||
Object.entries(sandpackExamples).forEach(([framework, examples]) => { | ||
Object.entries(examples).forEach(([exampleName, files]) => { | ||
const name = exampleName.split(".")[0]; | ||
const varName = `${framework.split(".")[0]}${name.charAt(0).toUpperCase() + name.slice(1)}`; | ||
tsContent += `export const ${varName} = ${JSON.stringify(files, null, 2)};\n\n`; | ||
}); | ||
}); | ||
|
||
// Ensure the output directory exists | ||
const outputDir = path.dirname(outputFile); | ||
if (!fs.existsSync(outputDir)) { | ||
fs.mkdirSync(outputDir, { recursive: true }); | ||
} | ||
|
||
fs.writeFileSync(outputFile, tsContent); | ||
|
||
console.log("Sandpack examples TypeScript file generated successfully!"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters