From 899128a57c3938bd246ac8f7965991d9900b581f Mon Sep 17 00:00:00 2001 From: Fabian Zeiher Date: Sat, 16 Dec 2023 09:33:17 +0100 Subject: [PATCH 1/4] moved contract into top component --- app/src/App.svelte | 14 +++++++++++--- app/src/lib/Create.svelte | 11 ++--------- app/src/lib/Passport.svelte | 9 +-------- app/src/lib/PassportList.svelte | 0 4 files changed, 14 insertions(+), 20 deletions(-) create mode 100644 app/src/lib/PassportList.svelte diff --git a/app/src/App.svelte b/app/src/App.svelte index 3e58ee8..0b8188c 100644 --- a/app/src/App.svelte +++ b/app/src/App.svelte @@ -9,9 +9,17 @@ import Home from "./lib/Home.svelte"; import { writable } from "svelte/store"; import Create from "./lib/Create.svelte"; + import { Web3 } from "web3"; + import ABI from "./assets/ABI.json"; const activeAcc = writable(""); + const web3 = new Web3(window.ethereum); + const contract = new web3.eth.Contract( + ABI, + "0xC63B8240EA75622Db719792f69FED0bf160c58d8", + ); + async function connect() { if (!window.ethereum) { alert("Please install MetaMask!"); @@ -82,13 +90,13 @@
- + - + - +
diff --git a/app/src/lib/Create.svelte b/app/src/lib/Create.svelte index 9f4d7cd..6a733b5 100644 --- a/app/src/lib/Create.svelte +++ b/app/src/lib/Create.svelte @@ -1,10 +1,9 @@
-

Your digital passport for your physical items

- - - -

Create a new Item Passport now!

+

Your digital passport for your physical items

+ + + +

Create a new Item Passport now!

- - - + +{#if activeAcc} +

You created these items:

+ {#await contract.methods.getCreatedItemTokens(activeAcc).call() then tokenList} + {#each tokenList as tokenId} + + + + + + {/each} + {/await} +{/if} \ No newline at end of file + } + .notlink { + color: whitesmoke; + } + diff --git a/app/src/lib/Passport.svelte b/app/src/lib/Passport.svelte index f991378..8862952 100644 --- a/app/src/lib/Passport.svelte +++ b/app/src/lib/Passport.svelte @@ -2,6 +2,7 @@ import PassportCard from "./PassportCard.svelte"; import PassportForm from "./PassportForm.svelte"; import QRCode from 'qrcode' + import PassportLoader from "./PassportLoader.svelte"; export let tokenId; export let activeAcc; @@ -11,14 +12,6 @@ let params = new URL(document.location).searchParams; let qrcode = params.get("qrcode") == "true" ? true : false; - async function getItemData(uri) { - const response = await fetch(uri); - console.log(response); - const data = await response.json(); - console.log(data); - return data; - } - async function updatePassport(updated) { // we are deliberatly not doing any error handling here as it will be done in the form component if (!activeAcc) { @@ -35,9 +28,7 @@ } -{#await contract.methods.getPassport(tokenId).call()} -
loading nft data
-{:then data} + {#if edit}
Edit the item
@@ -50,7 +41,7 @@ {/if} -{/await} +
diff --git a/app/src/lib/PassportCard.svelte b/app/src/lib/PassportCard.svelte index f23430e..0975f2c 100644 --- a/app/src/lib/PassportCard.svelte +++ b/app/src/lib/PassportCard.svelte @@ -14,7 +14,9 @@ thumbnail {/if}

{desc}

- Item Website + {#if url} + Item Website + {/if}
{family}
diff --git a/app/src/lib/PassportLoader.svelte b/app/src/lib/PassportLoader.svelte new file mode 100644 index 0000000..11c4ea7 --- /dev/null +++ b/app/src/lib/PassportLoader.svelte @@ -0,0 +1,10 @@ + + +{#await contract.methods.getPassport(tokenId).call()} +
loading nft data
+{:then data} + +{/await} \ No newline at end of file diff --git a/contract/src/ItemBlocks.sol b/contract/src/ItemBlocks.sol index 0c9fa37..94da082 100644 --- a/contract/src/ItemBlocks.sol +++ b/contract/src/ItemBlocks.sol @@ -15,10 +15,10 @@ contract ItemBlocks is ERC721, Ownable { mapping (uint256 => Passport) public itemPassports; mapping (uint256 => address[]) public allItemOwners; - mapping (address => uint256[]) public userItems; + mapping (address => uint256[]) public createdItems; constructor(address initialOwner) - ERC721("ItemBlocksTest6", "IB6") + ERC721("ItemBlocksTest8", "IB8") Ownable(initialOwner) {} @@ -69,6 +69,8 @@ contract ItemBlocks is ERC721, Ownable { function updateOwnership(address currentOwnerAddress, address nextOwnerAddress, uint256 tokenId) public{ if (allItemOwners[tokenId].length == 0){ allItemOwners[tokenId].push(nextOwnerAddress); + createdItems[nextOwnerAddress].push(tokenId); + }else{ safeTransferFrom(currentOwnerAddress, nextOwnerAddress, tokenId); allItemOwners[tokenId].push(nextOwnerAddress); @@ -81,8 +83,7 @@ contract ItemBlocks is ERC721, Ownable { return allItemOwners[tokenId]; } - function getUserItemTokens(address userAddress) public view returns(uint256[] memory) { - - return userItems[userAddress]; + function getCreatedItemTokens(address userAddress) public view returns(uint256[] memory) { + return createdItems[userAddress]; } -} \ No newline at end of file +} From bb0a0ef2fd7b111ca73b7317012e24024c9545e3 Mon Sep 17 00:00:00 2001 From: Fabian Zeiher Date: Sat, 16 Dec 2023 11:56:41 +0100 Subject: [PATCH 3/4] added ownership history --- app/src/lib/Passport.svelte | 41 +++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/app/src/lib/Passport.svelte b/app/src/lib/Passport.svelte index 8862952..2ac60cc 100644 --- a/app/src/lib/Passport.svelte +++ b/app/src/lib/Passport.svelte @@ -1,16 +1,18 @@ + +
+ + + + + {#if errorMsg}{errorMsg}{/if} +
+ +