Skip to content

Commit

Permalink
lucid
Browse files Browse the repository at this point in the history
  • Loading branch information
rchak007 committed Oct 7, 2023
1 parent 03bcd5a commit 3c2a5dd
Show file tree
Hide file tree
Showing 9 changed files with 1,818 additions and 11 deletions.
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"@babel/plugin-proposal-private-methods": "^7.18.6",
"@babel/plugin-proposal-private-property-in-object": "^7.18.6",
"@hyperionbt/helios": "^0.7.8",
"crypto-js": "^4.1.1",
"daisyui": "^2.31.0",
"easy-peasy": "^5.1.0",
"helios-api": "npm:@hyperionbt/helios@^0.13.21",
Expand Down
File renamed without changes.
1,730 changes: 1,730 additions & 0 deletions pages/crowdfund.tsx

Large diffs are not rendered by default.

53 changes: 49 additions & 4 deletions pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import initLucid from '../utils/lucid'
const Home: NextPage = () => {
const walletStore = useStoreState((state: any) => state.wallet)
const [nftList, setNftList] = useState([])
const [jsonData, setJsonData] = useState<any>(null);
const [secretData, setSecretData] = useState<any>(null);

useEffect(() => {
//const lucid = initLucid(walletStore.name)
Expand All @@ -20,6 +22,27 @@ const Home: NextPage = () => {
}
}, [walletStore.address])


const fetchData = async () => {
try {
const response = await fetch('/secret.json'); // This will automatically fetch from the public folder
const data = await response.json();
setJsonData(data);
} catch (error) {
console.error('Error fetching data:', error);
}
};

const fetchSecretData = async () => {
try {
const response = await fetch('/api/getData');
const data = await response.json();
setSecretData(data);
} catch (error) {
console.error('Error fetching secret data:', error);
}
};

return (
<div className="px-10">
<Head>
Expand All @@ -36,14 +59,36 @@ const Home: NextPage = () => {
</div>
</div>
<div>Address: {walletStore.address}</div>
<div>Your NFTs:</div>
<NftGrid nfts={nftList} />
<div className="mx-40 my-10">
<Link href="/helios">
<Link href="/crowdfund">
<button className="btn btn-primary m-5" >Smart Contract example</button>
</Link>
<div>Your NFTs:</div>
<NftGrid nfts={nftList} />
{/* <div>Your NFTs:</div>
<NftGrid nfts={nftList} /> */}
</div>
<div>
<button className="btn btn-secondary m-5" onClick={fetchData}>Fetch Data</button>
{/* <button className="btn btn-secondary m-5" onClick={() => { testCode() }}> testCode</button> */}
{jsonData && (
<div>
{/* <pre>{JSON.stringify(jsonData, null, 2)}</pre> // this gives the whole JSON file */}
<h2>Item 1 Description: {jsonData.items[0].description}</h2>
</div>
)}
</div>
<div>
<button className="btn btn-secondary m-5" onClick={fetchSecretData}>Fetch Secret Data</button>
{/* <button className="btn btn-secondary m-5" onClick={() => { testCode() }}> testCode</button> */}
{secretData && (
<div>
<pre>{JSON.stringify(secretData, null, 2)}</pre> // this gives the whole JSON file
<h2> {secretData.seed[0].name} : {secretData.seed[0].description}</h2>
</div>
)}
</div>
</div>
</div>
)
}

Expand Down
8 changes: 7 additions & 1 deletion utils/cardano.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import { fetchBlockFrostApi } from "./lucid"

export const getAssets = async (address: string) => {

const apiValue = await fetchBlockFrostApi();
var allNFTs: any = []
var addressInfo = { nfts: allNFTs, balance: 0 }
const data = await fetch(
`https://cardano-preprod.blockfrost.io/api/v0/addresses/${address}`,
{
headers: {
// Your Blockfrost API key
project_id: process.env.NEXT_PUBLIC_BLOCKFROST!,
// project_id: process.env.NEXT_PUBLIC_BLOCKFROST!,
// 'Content-Type': 'application/json'
project_id: apiValue.toString(),
'Content-Type': 'application/json'
}
}
Expand Down
20 changes: 17 additions & 3 deletions utils/lucid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ const initLucid = async (wallet: string) => {
const nami = await window.cardano.nami.enable();
// const eternl = window.cardano.eternl.enable();
// const gero = await window.cardano.gero.enable();

const apiValue = await fetchBlockFrostApi();

const lucid = await Lucid.new(
// new Blockfrost('https://cardano-preprod.blockfrost.io/api/v0', "preprodLT9nUTb22P26FiVH42jSFJU2IZaNxZVz") //process.env.NEXT_PUBLIC_BLOCKFROST as string),
// ,'Preprod');
new Blockfrost('https://cardano-preprod.blockfrost.io/api/v0', "preprod232JoxaAx9xRCqCdMJlweO5paor8jPfL") //process.env.NEXT_PUBLIC_BLOCKFROST as string),
new Blockfrost('https://cardano-preprod.blockfrost.io/api/v0', apiValue.toString()) //process.env.NEXT_PUBLIC_BLOCKFROST as string),
,'Preprod');
// const lucid = await Lucid.new(
// new Blockfrost("https://cardano-preview.blockfrost.io/api/v0", "previewY7wWn4mtcYHascUO7PyxeCXadkAkBVz2"),
Expand All @@ -29,5 +29,19 @@ const initLucid = async (wallet: string) => {
return lucid;
}

export const fetchBlockFrostApi = async () => {
try {
const response = await fetch('/api/getData');
const data = await response.json();
if (data.seed[0]) {
const blockfrostApi = data.seed[2].description;
console.log("api = ", blockfrostApi)
return blockfrostApi; // Return the value
}
} catch (error) {
console.error('Error fetching secret data:', error);
}
return null; // Return null if there was an error or no data was found
};

export default initLucid;
6 changes: 3 additions & 3 deletions utils/valueUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,6 @@ export {
Value
};

export type {
Value
}
// export type {
// Value
// }
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -863,6 +863,11 @@ cross-spawn@^7.0.2:
shebang-command "^2.0.0"
which "^2.0.1"

crypto-js@^4.1.1:
version "4.1.1"
resolved "https://registry.npmjs.org/crypto-js/-/crypto-js-4.1.1.tgz"
integrity sha512-o2JlM7ydqd3Qk9CA0L4NL6mTzU2sdx96a+oOfPu8Mkl/PK51vSyoi8/rQ8NknZtk44vq15lmhAj9CIAGwgeWKw==

css-selector-tokenizer@^0.8.0:
version "0.8.0"
resolved "https://registry.npmjs.org/css-selector-tokenizer/-/css-selector-tokenizer-0.8.0.tgz"
Expand Down

0 comments on commit 3c2a5dd

Please sign in to comment.