Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: template require path and hello-world name #125

Merged
merged 2 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions src/template/offckb.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// this file is generated by offckb-cli

import path from 'path';

export type Network = 'devnet' | 'testnet' | 'mainnet';
export type AddressPrefix = 'ckb' | 'ckt';

Expand Down Expand Up @@ -95,7 +93,9 @@ export function readEnvNetwork(): Network {
const offCKBConfig: OffCKBConfig = {
version: '@offckb-update-version',
contractBinFolder: '../build/release',
contractInfoFolder: './offckb', // this folder record the script deployment information
// this folder record the script deployment information
// If you change this folder, you need to update the following get systemScripts and get myScripts method
contractInfoFolder: './offckb',
networks: {
devnet: {
rpc_url: 'http://127.0.0.1:8114',
Expand Down Expand Up @@ -128,16 +128,14 @@ const offCKBConfig: OffCKBConfig = {

get systemScripts() {
const network = readEnvNetwork();
const networkSystemScripts: NetworkSystemScripts = require(
path.resolve(this.contractInfoFolder, 'system-scripts.json'),
);
const networkSystemScripts: NetworkSystemScripts = require('./offckb/system-scripts.json');
const systemScripts = networkSystemScripts[network];
return systemScripts;
},

get myScripts() {
const network = readEnvNetwork();
const networkMyScripts: NetworkMyScripts = require(path.resolve(this.contractInfoFolder, 'my-scripts.json'));
const networkMyScripts: NetworkMyScripts = require('./offckb/my-scripts.json');
const myScripts = networkMyScripts[network];
return myScripts;
},
Expand Down
12 changes: 6 additions & 6 deletions templates/v3/next-js-template/frontend/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ccc } from '@ckb-ccc/connector-react';
import Wallet from './wallet';

export default function Home() {
const isScriptDeployed = offckb.myScripts != null;
const isScriptDeployed = offckb.myScripts['hello-world'] != null;
return (
<ccc.Provider>
<div className="max-w-screen-md mx-auto mt-10">
Expand Down Expand Up @@ -68,14 +68,14 @@ export default function Home() {
<div className="my-6">
<div className="text-xl font-semibold my-2">Smart Contract</div>
<div>
HELLO_WORLD Script{' '}
hello-world Script{' '}
{isScriptDeployed ? (
<div>
<li>code_hash: {offckb.myScripts['hello_world']?.codeHash}</li>
<li>hash_type: {offckb.myScripts['hello_world']?.hashType}</li>
<li>code_hash: {offckb.myScripts['hello-world']?.codeHash}</li>
<li>hash_type: {offckb.myScripts['hello-world']?.hashType}</li>
<li>
outpoint: {offckb.myScripts['hello_world']?.cellDeps[0].cellDep.outPoint.txHash}:
{offckb.myScripts['hello_world']?.cellDeps[0].cellDep.outPoint.index}
outpoint: {offckb.myScripts['hello-world']?.cellDeps[0].cellDep.outPoint.txHash}:
{offckb.myScripts['hello-world']?.cellDeps[0].cellDep.outPoint.index}
</li>
</div>
) : (
Expand Down
12 changes: 5 additions & 7 deletions templates/v3/next-js-template/frontend/offckb.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import path from 'path';

export type Network = 'devnet' | 'testnet' | 'mainnet';
export type AddressPrefix = 'ckb' | 'ckt';

Expand Down Expand Up @@ -93,7 +91,9 @@ export function readEnvNetwork(): Network {
const offCKBConfig: OffCKBConfig = {
version: '@offckb-update-version',
contractBinFolder: '../build/release',
contractInfoFolder: './offckb', // this folder record the script deployment information
// this folder record the script deployment information
// If you change this folder, you need to update the following get systemScripts and get myScripts method
contractInfoFolder: './offckb',
networks: {
devnet: {
rpc_url: 'http://127.0.0.1:8114',
Expand Down Expand Up @@ -126,16 +126,14 @@ const offCKBConfig: OffCKBConfig = {

get systemScripts() {
const network = readEnvNetwork();
const networkSystemScripts: NetworkSystemScripts = require(
path.resolve(this.contractInfoFolder, 'system-scripts.json'),
);
const networkSystemScripts: NetworkSystemScripts = require('./offckb/system-scripts.json');
const systemScripts = networkSystemScripts[network];
return systemScripts;
},

get myScripts() {
const network = readEnvNetwork();
const networkMyScripts: NetworkMyScripts = require(path.resolve(this.contractInfoFolder, 'my-scripts.json'));
const networkMyScripts: NetworkMyScripts = require('./offckb/my-scripts.json');
const myScripts = networkMyScripts[network];
return myScripts;
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ccc } from '@ckb-ccc/connector-react';
import offckb from 'offckb.config';

export default function Home() {
const isScriptDeployed = offckb.myScripts['hello_world'] != null;
const isScriptDeployed = offckb.myScripts['hello-world'] != null;
return (
<ccc.Provider>
<div className="max-w-screen-md mx-auto mt-10">
Expand Down Expand Up @@ -66,14 +66,14 @@ export default function Home() {
<div className="my-6">
<div className="text-xl font-semibold my-2">Smart Contract</div>
<div>
HELLO_WORLD Script{' '}
hello-world Script{' '}
{isScriptDeployed ? (
<div>
<li>code_hash: {offckb.myScripts['hello_world']?.codeHash}</li>
<li>hash_type: {offckb.myScripts['hello_world']?.hashType}</li>
<li>code_hash: {offckb.myScripts['hello-world']?.codeHash}</li>
<li>hash_type: {offckb.myScripts['hello-world']?.hashType}</li>
<li>
outpoint: {offckb.myScripts['hello_world']?.cellDeps[0].cellDep.outPoint.txHash}:
{offckb.myScripts['hello_world']?.cellDeps[0].cellDep.outPoint.index}
outpoint: {offckb.myScripts['hello-world']?.cellDeps[0].cellDep.outPoint.txHash}:
{offckb.myScripts['hello-world']?.cellDeps[0].cellDep.outPoint.index}
</li>
</div>
) : (
Expand Down
12 changes: 5 additions & 7 deletions templates/v3/remix-vite-template/frontend/offckb.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import path from 'path';

export type Network = 'devnet' | 'testnet' | 'mainnet';
export type AddressPrefix = 'ckb' | 'ckt';

Expand Down Expand Up @@ -97,7 +95,9 @@ export function readEnvNetwork(): Network {
const offCKBConfig: OffCKBConfig = {
version: '@offckb-update-version',
contractBinFolder: '../build/release',
contractInfoFolder: './offckb', // this folder record the script deployment information
// this folder record the script deployment information
// If you change this folder, you need to update the following get systemScripts and get myScripts method
contractInfoFolder: './offckb',
networks: {
devnet: {
rpc_url: 'http://127.0.0.1:8114',
Expand Down Expand Up @@ -130,16 +130,14 @@ const offCKBConfig: OffCKBConfig = {

get systemScripts() {
const network = readEnvNetwork();
const networkSystemScripts: NetworkSystemScripts = require(
path.resolve(this.contractInfoFolder, 'system-scripts.json'),
);
const networkSystemScripts: NetworkSystemScripts = require('./offckb/system-scripts.json');
const systemScripts = networkSystemScripts[network];
return systemScripts;
},

get myScripts() {
const network = readEnvNetwork();
const networkMyScripts: NetworkMyScripts = require(path.resolve(this.contractInfoFolder, 'my-scripts.json'));
const networkMyScripts: NetworkMyScripts = require('./offckb/my-scripts.json');
const myScripts = networkMyScripts[network];
return myScripts;
},
Expand Down
Loading