Skip to content

Commit 0fa68b2

Browse files
committed
Some small improvement for code execution sections
1 parent e95e232 commit 0fa68b2

File tree

5 files changed

+62
-18
lines changed

5 files changed

+62
-18
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ node_modules
33
.tool-versions
44
.DS_Store
55
public/.DS_Store
6-
.env
6+
.env
7+
.env.local
+24-11
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,35 @@
11
import dynamic from "next/dynamic";
22

33
const Sandpack = dynamic(() => import("@codesandbox/sandpack-react").then((mod) => mod.Sandpack), {
4-
ssr: false, // Disable server-side rendering for Sandpack
4+
ssr: false,
55
});
66

77
export default function InteractiveCode() {
8-
const token = process.env.CODESANDBOX_TOKEN;
8+
const token = process.env.NEXT_PUBLIC_CODESANDBOX_TOKEN;
99
const code = `
1010
import { account } from '@autonomys/auto-consensus';
1111
import { activate, parseTokenAmount} from '@autonomys/auto-utils';
1212
1313
(async () => {
14-
const api = await activate({ networkId: 'mainnet'});
15-
const accountData = await account(api, 'sub564FwrR9yL7NVG2gdvSVj3oped2mBSYC65TjVGMp4tCkDp');
14+
try {
15+
console.log('Connecting to network...');
16+
const api = await activate({ networkId: 'mainnet'});
17+
18+
console.log('Fetching account data...');
19+
const accountData = await account(api, 'sub564FwrR9yL7NVG2gdvSVj3oped2mBSYC65TjVGMp4tCkDp');
1620
17-
console.log(\`Nonce: \${accountData.nonce}\`);
18-
console.log(\`Free Balance: \${accountData.data.free} AI3\`);
19-
console.log(\`Reserved Balance: \${accountData.data.reserved} AI3\`);
21+
console.log(\`Nonce: \${accountData.nonce}\`);
22+
console.log(\`Free Balance: \${accountData.data.free} AI3\`);
23+
console.log(\`Reserved Balance: \${accountData.data.reserved} AI3\`);
2024
21-
await api.disconnect();
25+
// Clean disconnect
26+
await api.disconnect();
27+
} catch (error) {
28+
console.error('❌ Error:', error);
29+
if (api) {
30+
await api.disconnect();
31+
}
32+
}
2233
})();
2334
`;
2435

@@ -32,15 +43,17 @@ export default function InteractiveCode() {
3243
dependencies: {
3344
"@autonomys/auto-consensus": "^1.2.1",
3445
"@autonomys/auto-utils": "^1.2.1",
35-
},
46+
}
3647
}}
3748
options={{
3849
showConsole: true,
3950
editorHeight: 400,
51+
recompileMode: "delayed",
52+
recompileDelay: 1000
4053
}}
4154
codeSandboxOptions={{
42-
authToken: token,
55+
authToken: token
4356
}}
4457
/>
4558
);
46-
}
59+
}

next.config.mjs

+29-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import nextra from 'nextra'
2-
2+
33
const withNextra = nextra({
44
theme: 'nextra-theme-docs',
55
themeConfig: './theme.config.jsx',
@@ -8,8 +8,31 @@ const withNextra = nextra({
88
rehypePlugins: []
99
}
1010
})
11-
12-
export default withNextra()
13-
14-
// If you have other Next.js configurations, you can pass them as the parameter:
15-
// export default withNextra({ /* other next.js config */ })
11+
12+
// Configuration object with headers
13+
const nextConfig = {
14+
async headers() {
15+
return [
16+
{
17+
source: '/:path*',
18+
headers: [
19+
{
20+
key: 'Access-Control-Allow-Origin',
21+
value: '*'
22+
},
23+
{
24+
key: 'Access-Control-Allow-Methods',
25+
value: 'GET,OPTIONS,PATCH,DELETE,POST,PUT'
26+
},
27+
{
28+
key: 'Access-Control-Allow-Headers',
29+
value: 'X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version'
30+
}
31+
]
32+
}
33+
]
34+
}
35+
}
36+
37+
// Combine Nextra with the custom config
38+
export default withNextra(nextConfig)

package-lock.json

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"dependencies": {
33
"@codesandbox/sandpack-react": "^2.19.10",
4+
"@codesandbox/sandpack-themes": "^2.0.21",
45
"lucide-react": "^0.469.0",
56
"next": "^15.1.2",
67
"nextra": "^3.3.1",

0 commit comments

Comments
 (0)