YEW descentralized app with js callback

This commit is contained in:
itzelot01 2024-01-22 21:48:10 +00:00
parent 35bc3d5ed4
commit d43f6ab02b
6 changed files with 3 additions and 96 deletions

View File

@ -11,9 +11,8 @@ categories = ["gui", "wasm", "web-programming"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
ipfs-car = "1.1.0"
js-sys = "0.3.66" js-sys = "0.3.66"
once_cell = "1.18.0" once_cell = "1.18.0"
wasm-bindgen = "0.2.89" wasm-bindgen = "0.2.90"
wasm-bindgen-futures = "0.4.39" wasm-bindgen-futures = "0.4.39"
yew = { version="0.20", features=["csr"] } yew = { version="0.20", features=["csr"] }

View File

@ -4,6 +4,6 @@
<meta charset="utf-8" /> <meta charset="utf-8" />
<title>DECA NFTs</title> <title>DECA NFTs</title>
<script scr = "/js/script.js"></script> <script scr = "/js/script.js"></script>
<link data-trunk rel="sass" href="index.scss" /> <link data-trunk rel="sass" href="index.scss">
</head> </head>
</html> </html>

View File

@ -1,47 +0,0 @@
/* eslint-env browser */
import varint from 'varint'
import { encode as cborEncode } from '@ipld/dag-cbor'
/**
* @param {import('multiformats').UnknownLink[]} roots
* @returns {Uint8Array}
*/
function encodeHeader (roots) {
const headerBytes = cborEncode({ version: 1, roots })
const varintBytes = varint.encode(headerBytes.length)
const header = new Uint8Array(varintBytes.length + headerBytes.length)
header.set(varintBytes, 0)
header.set(headerBytes, varintBytes.length)
return header
}
/**
* @param {import('@ipld/unixfs').Block} block
* @returns {Uint8Array}
*/
function encodeBlock (block) {
const varintBytes = varint.encode(block.cid.bytes.length + block.bytes.length)
const bytes = new Uint8Array(varintBytes.length + block.cid.bytes.length + block.bytes.length)
bytes.set(varintBytes)
bytes.set(block.cid.bytes, varintBytes.length)
bytes.set(block.bytes, varintBytes.length + block.cid.bytes.length)
return bytes
}
/**
* @extends {TransformStream<import('@ipld/unixfs').Block, Uint8Array>}
*/
export class CAREncoderStream extends TransformStream {
/** @param {import('multiformats').UnknownLink[]} roots */
constructor (roots = []) {
super({
start: (controller) => controller.enqueue(encodeHeader(roots)),
transform: (block, controller) => {
controller.enqueue(encodeBlock(block))
this.finalBlock = block
}
})
/** @type {import('@ipld/unixfs').Block?} */
this.finalBlock = null
}
}

View File

@ -1,35 +0,0 @@
export async function getObj(i) {
let url = 'https://gateway.decentralizedscience.org/ipfs/bafybeiai4g5mluuwr4ds34jkqi4kojsrqxrcetntkp5tf76jhx6mccrybu/'+i+'.json';
let obj = await (await fetch(url)).json();
//console.log(obj);
return obj;
}
var tags;
export async function createDiv() {
for (var i=1; i<=68; i++) {
tags = await get(i);
var divTag = document.createElement("div");
divTag.id = "div"+i;
divTag.className = "responsive";
divTag.innerHTML = "<div class='gallery'>"+
"<a target='_blank' href='"+tags.image+"'>"+
"<img src='"+tags.image+"' alt='"+tags.name+"' width='256' height='256'>"+
"</a>"+
"<div class='name'>"+tags.name+"</div>"+
"<div class='desc'>"+tags.description+"</div>"+
"<div class='properties'>"+
"<details class='details-example'>"+
"<summary>Properties</summary>"+
"<ul>"+
"<li>"+tags.attributes[0].trait_type+": <b>"+tags.attributes[0].value+"</b></li>"+
"<li>"+tags.attributes[1].trait_type+": <b>"+tags.attributes[1].value+"</b></li>"+
"<li>"+tags.attributes[2].trait_type+": <b>"+tags.attributes[2].value+"</b></li>"+
"</ul>"+
"</details>"+
"</div>"+
"</div>";
document.body.appendChild(divTag);
}
}

View File

@ -1,6 +0,0 @@
{
"dependencies": {
"helia": "^3.0.1",
"ipfs-car": "^1.1.0"
}
}

View File

@ -5,7 +5,3 @@ extern "C" {
#[wasm_bindgen] #[wasm_bindgen]
pub fn get_now_date() -> String; pub fn get_now_date() -> String;
} }
#[wasm_bindgen(module = "/js/index.js")]
extern "C"{
}