Skip to content

Commit

Permalink
Merge pull request #51 from algovado/main
Browse files Browse the repository at this point in the history
fix ipfs cid version and metadata
  • Loading branch information
LoafPickleWW authored Jul 5, 2024
2 parents c3f5512 + 0fc27d4 commit c733625
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 35 deletions.
2 changes: 1 addition & 1 deletion src/pages/CollectionSnapshotComponent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ export function CollectionSnapshot() {
Just works with 1/1 ASAs.
</p>
<button
className="mb-2 bg-secondary-green/80 hover:bg-secondary-green text-white text-base font-semibold rounded py-2 w-fit px-2 mx-auto mt-1 hover:scale-95 duration-700"
className="mb-2 bg-secondary-green/80 hover:bg-secondary-green text-black text-base font-semibold rounded py-2 w-fit px-2 mx-auto mt-1 hover:scale-95 duration-700"
onClick={getCollectionData}
>
Get Holders Data
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Download19CollectionData.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ export function Download19CollectionData() {
onChange={(e) => setCreatorWallet(e.target.value)}
/>
<button
className="mb-2 bg-secondary-green/80 hover:bg-secondary-green text-white text-base font-semibold rounded py-2 w-fit px-2 mx-auto mt-1 hover:scale-95 duration-700"
className="mb-2 bg-secondary-green/80 hover:bg-secondary-green text-black text-base font-semibold rounded py-2 w-fit px-2 mx-auto mt-1 hover:scale-95 duration-700"
onClick={getCollectionData}
>
Get Collection Data
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Download69CollectionData.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export function Download69CollectionData() {
onChange={(e) => setCreatorWallet(e.target.value)}
/>
<button
className="mb-2 bg-secondary-green/80 hover:bg-secondary-green text-white text-base font-semibold rounded py-2 w-fit px-2 mx-auto mt-1 hover:scale-95 duration-700"
className="mb-2 bg-secondary-green/80 hover:bg-secondary-green text-black text-base font-semibold rounded py-2 w-fit px-2 mx-auto mt-1 hover:scale-95 duration-700"
onClick={getCollectionData}
>
Get Collection Data
Expand Down
2 changes: 1 addition & 1 deletion src/pages/DownloadCollectionData.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export function DownloadCollectionData() {
onChange={(e) => setCreatorWallet(e.target.value)}
/>
<button
className="mb-2 bg-secondary-green/80 hover:bg-secondary-green text-white text-base font-semibold rounded py-2 w-fit px-2 mx-auto mt-1 hover:scale-95 duration-700"
className="mb-2 bg-secondary-green/80 hover:bg-secondary-green text-black text-base font-semibold rounded py-2 w-fit px-2 mx-auto mt-1 hover:scale-95 duration-700"
onClick={getCollectionData}
>
Get Collection Data
Expand Down
2 changes: 1 addition & 1 deletion src/pages/MultimintAssetHolders.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ export function MultimintAssetHolders() {
</div>
</div>
<button
className="mb-2 bg-secondary-green/80 hover:bg-secondary-green text-white text-base font-semibold rounded py-2 w-fit px-2 mx-auto mt-1 hover:scale-95 duration-700"
className="mb-2 bg-secondary-green/80 hover:bg-secondary-green text-black text-base font-semibold rounded py-2 w-fit px-2 mx-auto mt-1 hover:scale-95 duration-700"
onClick={getAssetHolders}
>
Get Asset Holders
Expand Down
2 changes: 1 addition & 1 deletion src/pages/SimpleBatchMint.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,7 @@ export function SimpleBatchMint() {
</p>
<button
id="create_transactions_id"
className="rounded bg-secondary-green hover:bg-secondary-green/80 transition text-white/90 font-semibold px-4 py-1 mt-2"
className="rounded bg-secondary-green hover:bg-secondary-green/80 transition text-black/90 font-semibold px-4 py-1 mt-2"
onClick={() => {
sendTransaction();
}}
Expand Down
9 changes: 6 additions & 3 deletions src/pages/SimpleMint.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,7 @@ export function SimpleMint() {
return;
}
toast.info("Uploading the image to IPFS...");
imageURL =
"ipfs://" + (await pinImageToPinata(token, formData.image));
imageURL = "ipfs://" + (await pinImageToPinata(token, formData.image));
}
const nodeURL = getNodeURL();

Expand Down Expand Up @@ -245,6 +244,10 @@ export function SimpleMint() {
toast.error("Invalid ARC format");
return;
}
if (unsignedAssetTransaction.length === 0) {
toast.error("Something went wrong while creating transactions");
return;
}
setTransaction(unsignedAssetTransaction);
toast.info("Please sign the transaction");
setProcessStep(2);
Expand Down Expand Up @@ -686,7 +689,7 @@ export function SimpleMint() {
</p>
<button
id="create_transactions_id"
className="rounded bg-secondary-green hover:bg-secondary-green/80 transition text-white/90 font-semibold px-4 py-1 mt-2"
className="rounded bg-secondary-green hover:bg-secondary-green/80 transition text-black/90 font-semibold px-4 py-1 mt-2"
onClick={() => {
sendTransaction();
}}
Expand Down
16 changes: 9 additions & 7 deletions src/pages/SimpleUpdate.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ export function SimpleUpdate() {
}
}
}
console.log(Object.keys(metadata).includes("filters"))
console.log(Object.keys(metadata).includes("extras"))
setFormData({
...formData,
name: assetData.params["name"],
Expand All @@ -199,14 +201,14 @@ export function SimpleUpdate() {
category: key,
name: metadata.traits[key],
})),
filters: Object.keys(assetMetadata).includes("filters")
? Object.keys(assetMetadata.filters).map((key, index) => ({
filters: Object.keys(metadata).includes("filters")
? Object.keys(metadata.filters).map((key, index) => ({
id: index,
category: key,
name: assetMetadata.filters[key],
name: metadata.filters[key],
}))
: [],
extras: Object.keys(assetMetadata).includes("extras")
extras: Object.keys(metadata).includes("extras")
? Object.keys(metadata.extras).map((key, index) => ({
id: index,
category: key,
Expand Down Expand Up @@ -398,7 +400,7 @@ export function SimpleUpdate() {
<>
<div className="flex flex-col md:flex-row justify-between">
<button
className="rounded bg-secondary-green hover:bg-secondary-green/80 text-white px-4 py-1 mt-2"
className="rounded bg-secondary-green hover:bg-secondary-green/80 text-black px-4 py-1 mt-2"
onClick={() => {
window.location.reload();
}}
Expand Down Expand Up @@ -735,7 +737,7 @@ export function SimpleUpdate() {
</p>
<button
id="create_transactions_id"
className="rounded bg-secondary-green hover:bg-secondary-green/80 transition text-white/90 font-semibold px-4 py-1 mt-2"
className="rounded bg-secondary-green hover:bg-secondary-green/80 transition text-black font-semibold px-4 py-1 mt-2"
onClick={() => {
sendTransaction();
}}
Expand All @@ -753,7 +755,7 @@ export function SimpleUpdate() {
</div>
) : (
<button
className="rounded bg-secondary-green hover:bg-secondary-green/80 transition text-white/90 font-semibold px-4 py-1 mt-2"
className="rounded bg-secondary-green hover:bg-secondary-green/80 transition text-black font-semibold px-4 py-1 mt-2"
onClick={update}
>
Update
Expand Down
2 changes: 1 addition & 1 deletion src/pages/WalletHoldings.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ export function WalletHoldings() {
</label>
</div>
<button
className="mb-2 bg-secondary-green/80 hover:bg-secondary-green text-white text-base font-semibold rounded py-2 w-fit px-2 mx-auto mt-1 hover:scale-95 duration-700"
className="mb-2 bg-secondary-green/80 hover:bg-secondary-green text-black text-base font-semibold rounded py-2 w-fit px-2 mx-auto mt-1 hover:scale-95 duration-700"
onClick={getWalletData}
>
Get Wallet Assets
Expand Down
34 changes: 16 additions & 18 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -381,10 +381,7 @@ export async function createARC3AssetMintArray(data_for_txns, nodeURL, token) {
return txnsArray;
}

export async function createARC19AssetMintArray(
data_for_txns,
nodeURL,
token) {
export async function createARC19AssetMintArray(data_for_txns, nodeURL, token) {
const wallet = localStorage.getItem("wallet");
if (wallet === "" || wallet === undefined) {
throw new Error("Wallet not found");
Expand Down Expand Up @@ -444,11 +441,7 @@ export async function createARC19AssetMintArray(
return txnsArray;
}

export async function updateARC19AssetMintArray(
data_for_txns,
nodeURL,
token
) {
export async function updateARC19AssetMintArray(data_for_txns, nodeURL, token) {
const wallet = localStorage.getItem("wallet");
if (wallet === "" || wallet === undefined) {
throw new Error("Wallet not found");
Expand Down Expand Up @@ -960,10 +953,6 @@ export function createReserveAddressFromIpfsCid(ipfsCid) {
const version = decoded.version;
const codec = codeToCodec(decoded.code);

if (version === 0) {
throw new Error("CID version 0 does not support directories");
}

const assetURL = `template-ipfs://{ipfscid:${version}:${codec}:reserve:sha2-256}`;

const reserveAddress = encodeAddress(
Expand Down Expand Up @@ -1155,18 +1144,24 @@ export async function getARC19AssetMetadataData(url, reserve) {

export async function pinJSONToPinata(token, json) {
try {
const data = JSON.stringify({
pinataContent: JSON.parse(json),
pinataMetadata: {
name: "metadata"
},
cidVersion: 1,
});
const response = await axios.post(
"https://api.pinata.cloud/pinning/pinJSONToIPFS",
json,
data,
{
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${token.trim()}`,
},
}
);
const cid = CID.parse(response.data.IpfsHash).toV1()
return cid;
return response.data.IpfsHash;
} catch (error) {
throw new Error("IPFS pinning failed");
}
Expand All @@ -1176,6 +1171,10 @@ export async function pinImageToPinata(token, image) {
try {
const data = new FormData();
data.append("file", image);
const options = JSON.stringify({
cidVersion: 1,
});
data.append("pinataOptions", options);
const response = await axios.post(
"https://api.pinata.cloud/pinning/pinFileToIPFS",
data,
Expand All @@ -1185,8 +1184,7 @@ export async function pinImageToPinata(token, image) {
},
}
);
const cid = CID.parse(response.data.IpfsHash).toV1()
return cid;
return response.data.IpfsHash;
} catch (error) {
throw new Error("IPFS pinning failed");
}
Expand Down

0 comments on commit c733625

Please sign in to comment.