From 1ad60e222baacd2384450a9fe987d48d6d460fd9 Mon Sep 17 00:00:00 2001 From: Deniz Mert Edincik Date: Wed, 20 Mar 2024 17:13:12 +0100 Subject: [PATCH] extras --- contracts/FDNZ.cdc | 141 +++++++++++++++++++++++++++++++++++ contracts/FDNZ1.cdc | 120 +++++++++++++++++++++++++++++ contracts/FDNZ_testnet.cdc | 141 +++++++++++++++++++++++++++++++++++ contracts/t.cdc | 32 ++++++++ src/comps/base.js | 1 + src/index.js | 4 + src/pages/account/index.js | 8 +- src/pages/account/storage.js | 20 +++-- 8 files changed, 454 insertions(+), 13 deletions(-) create mode 100644 contracts/FDNZ.cdc create mode 100644 contracts/FDNZ1.cdc create mode 100644 contracts/FDNZ_testnet.cdc create mode 100644 contracts/t.cdc diff --git a/contracts/FDNZ.cdc b/contracts/FDNZ.cdc new file mode 100644 index 0000000..5d056ad --- /dev/null +++ b/contracts/FDNZ.cdc @@ -0,0 +1,141 @@ +import NonFungibleToken from 0x1d7e57aa55817448 +import FungibleToken from 0xf233dcee88fe0abe +import MetadataViews from 0x1d7e57aa55817448 + +pub contract FDNZ{ + + access(all) fun getAccountLinks(_ account: AuthAccount, domain: String): [{String:AnyStruct}]{ + + var res : [{String:AnyStruct}] = [] + + if domain=="public"{ + account.forEachPublic(fun (path: PublicPath, type: Type): Bool { + res.append( { + "path" : path, + "borrowType" : type, + "target" : account.getLinkTarget(path) + }) + return true + }) + } + + if domain=="private"{ + account.forEachPrivate(fun (path: PrivatePath, type: Type): Bool { + res.append( { + "path" : path, + "borrowType" : type, + "target" : account.getLinkTarget(path) + }) + return true + }) + } + + return res + } + + access(all) fun getAccountStorageNFT(_ account: AuthAccount, path: String, uuid: UInt64) : AnyStruct{ + var obj = account.borrow(from: StoragePath(identifier: path)!)! + var meta = obj as? &AnyResource{MetadataViews.ResolverCollection} + + var res : {String:AnyStruct} = {} + + var vr = meta?.borrowViewResolver(id:uuid) + if let views = vr?.getViews(){ + for mdtype in views{ + if mdtype==Type() { + continue + } + if mdtype==Type() { + continue + } + res[mdtype.identifier]=vr?.resolveView(mdtype) + } + } + + return res + } + + access(all) fun getAccountStorage(_ account: AuthAccount, path: String): AnyStruct{ + + var obj = account.borrow(from: StoragePath(identifier: path)!)! + var meta = obj as? &AnyResource{MetadataViews.ResolverCollection} + + if meta!=nil && meta!.getIDs().length>0{ + var res : {UInt64:AnyStruct} = {} + for id in meta!.getIDs(){ + res[id] = meta!.borrowViewResolver(id:id).resolveView(Type())! + } + return res + } + else{ + var col = account.borrow<&AnyResource>(from: StoragePath(identifier: path)!)! as AnyStruct + return col + } + } + + access(all) fun getAccountStorageRaw(_ account: AuthAccount, path: String): AnyStruct{ + + var obj = account.borrow(from: StoragePath(identifier: path)!)! + + return obj + } + + + access(all) fun getAccountData(_ account:AuthAccount):{String:AnyStruct}{ + + var paths: [Path] = [] + var privatePaths: [Path] = [] + var publicPaths: [Path] = [] + var nft : [AnyStruct] = [] + var ft : [AnyStruct] = [] + + + account.forEachStored(fun (path: StoragePath, type: Type): Bool { + if type.isSubtype(of: Type<@NonFungibleToken.Collection>()){ + var collection = account.borrow<&NonFungibleToken.Collection>(from:path)! + nft.append({"path":path, "count":collection.getIDs().length}) + paths.append(path) + } + else if type.isSubtype(of: Type<@FungibleToken.Vault>()){ + var vault = account.borrow<&FungibleToken.Vault>(from:path)! + ft.append({"path":path, "balance":vault.balance}) + paths.append(path) + } + else{ + paths.append(path) + } + return true + }) + + account.forEachPublic(fun (path: PublicPath, type: Type): Bool { + publicPaths.append(path) + return true + }) + + account.forEachPrivate(fun (path: PrivatePath, type: Type): Bool { + privatePaths.append(path) + return true + }) + + + let response: {String: AnyStruct} = {} + + //find profile + var findProfile = account.borrow<&AnyResource>(from:/storage/findProfile) + response["find"] = findProfile + response["capacity"] = account.storageCapacity + response["used"] = account.storageUsed + response["available"] = 0 + response["paths"] = paths + response["public"] = publicPaths + response["private"] = privatePaths + response["nft"] = nft + response["ft"] = ft + + if account.storageCapacity>account.storageUsed{ + response["available"] = account.storageCapacity - account.storageUsed + } + return response + } + +} diff --git a/contracts/FDNZ1.cdc b/contracts/FDNZ1.cdc new file mode 100644 index 0000000..9f31f8b --- /dev/null +++ b/contracts/FDNZ1.cdc @@ -0,0 +1,120 @@ +import NonFungibleToken from 0xb6763b4399a888c8 +import FungibleToken from 0xa0225e7000ac82a9 +import MetadataViews from 0xb6763b4399a888c8 +import ViewResolver from 0xb6763b4399a888c8 + +access(all) contract FDNZ{ + + access(all) fun getAccountLinks(_ account: auth(Storage) &Account, domain: String): [{String:AnyStruct}]{ + + var res : [{String:AnyStruct}] = [] + + if domain=="public"{ + account.storage.forEachPublic(fun (path: PublicPath, type: Type): Bool { + res.append( { + "path" : path.toString(), + "borrowType" : type.toString(), + "target" : "" + }) + return true + }) + } + + + return res + } + + access(all) fun getAccountStorageNFT(_ account: auth(Storage) &Account, path: String, uuid: UInt64) : AnyStruct{ + var obj = account.storage.borrow<&AnyResource>(from: StoragePath(identifier: path)!)! + var meta = obj as? &{ViewResolver.ResolverCollection} + + var res : {String:AnyStruct} = {} + + var vr = meta?.borrowViewResolver(id:uuid)! + if let views = vr?.getViews(){ + for mdtype in views{ + if mdtype==Type() { + continue + } + if mdtype==Type() { + continue + } + res[mdtype.identifier]=vr?.resolveView(mdtype) + } + } + + return res + } + + access(all) fun getAccountStorage(_ account: auth(Storage) &Account, path: String): AnyStruct{ + + var obj = account.storage.borrow<&AnyResource>(from: StoragePath(identifier: path)!)! + var meta = obj as? &{ViewResolver.ResolverCollection} + + if meta!=nil && meta!.getIDs().length>0{ + var res : {UInt64:AnyStruct} = {} + for id in meta!.getIDs(){ + res[id] = meta!.borrowViewResolver(id:id)?.resolveView(Type())! + } + return res + } + else{ + var col = account.storage.borrow<&AnyResource>(from: StoragePath(identifier: path)!)! as AnyStruct + return col + } + } + + + + access(all) fun getAccountData(_ account: auth(Storage) &Account):{String:AnyStruct}{ + + var paths: [Path] = [] + var privatePaths: [Path] = [] + var publicPaths: [Path] = [] + var nft : [AnyStruct] = [] + var ft : [AnyStruct] = [] + + + account.storage.forEachStored(fun (path: StoragePath, type: Type): Bool { + if type.isSubtype(of: Type<@{NonFungibleToken.Collection}>()){ + var collection = account.storage.borrow<&{NonFungibleToken.Collection}>(from:path)! + nft.append({"path":path, "count":collection.getIDs().length}) + } + else if type.isSubtype(of: Type<@{FungibleToken.Vault}>()){ + var vault = account.storage.borrow<&{FungibleToken.Vault}>(from:path)! + ft.append({"path":path, "balance":vault.balance}) + } + else{ + paths.append(path) + } + return true + }) + + account.storage.forEachPublic(fun (path: PublicPath, type: Type): Bool { + publicPaths.append(path) + return true + }) + + + + let response: {String: AnyStruct} = {} + + //find profile + var findProfile = account.storage.borrow<&AnyResource>(from:/storage/findProfile) + response["find"] = findProfile + response["capacity"] = account.storage.capacity + response["used"] = account.storage.used + response["available"] = 0 + response["paths"] = paths + response["public"] = publicPaths + response["private"] = privatePaths + response["nft"] = nft + response["ft"] = ft + + if account.storage.capacity>account.storage.used{ + response["available"] = account.storage.capacity - account.storage.used + } + return response + } + +} diff --git a/contracts/FDNZ_testnet.cdc b/contracts/FDNZ_testnet.cdc new file mode 100644 index 0000000..268e127 --- /dev/null +++ b/contracts/FDNZ_testnet.cdc @@ -0,0 +1,141 @@ +import NonFungibleToken from 0x631e88ae7f1d7c20 +import FungibleToken from 0x9a0766d93b6608b7 +import MetadataViews from 0x631e88ae7f1d7c20 + +pub contract FDNZ{ + + access(all) fun getAccountLinks(_ account: AuthAccount, domain: String): [{String:AnyStruct}]{ + + var res : [{String:AnyStruct}] = [] + + if domain=="public"{ + account.forEachPublic(fun (path: PublicPath, type: Type): Bool { + res.append( { + "path" : path, + "borrowType" : type, + "target" : account.getLinkTarget(path) + }) + return true + }) + } + + if domain=="private"{ + account.forEachPrivate(fun (path: PrivatePath, type: Type): Bool { + res.append( { + "path" : path, + "borrowType" : type, + "target" : account.getLinkTarget(path) + }) + return true + }) + } + + return res + } + + access(all) fun getAccountStorageNFT(_ account: AuthAccount, path: String, uuid: UInt64) : AnyStruct{ + var obj = account.borrow(from: StoragePath(identifier: path)!)! + var meta = obj as? &AnyResource{MetadataViews.ResolverCollection} + + var res : {String:AnyStruct} = {} + + var vr = meta?.borrowViewResolver(id:uuid) + if let views = vr?.getViews(){ + for mdtype in views{ + if mdtype==Type() { + continue + } + if mdtype==Type() { + continue + } + res[mdtype.identifier]=vr?.resolveView(mdtype) + } + } + + return res + } + + access(all) fun getAccountStorage(_ account: AuthAccount, path: String): AnyStruct{ + + var obj = account.borrow(from: StoragePath(identifier: path)!)! + var meta = obj as? &AnyResource{MetadataViews.ResolverCollection} + + if meta!=nil && meta!.getIDs().length>0{ + var res : {UInt64:AnyStruct} = {} + for id in meta!.getIDs(){ + res[id] = meta!.borrowViewResolver(id:id).resolveView(Type())! + } + return res + } + else{ + var col = account.borrow<&AnyResource>(from: StoragePath(identifier: path)!)! as AnyStruct + return col + } + } + + access(all) fun getAccountStorageRaw(_ account: AuthAccount, path: String): AnyStruct{ + + var obj = account.borrow(from: StoragePath(identifier: path)!)! + + return obj + } + + + access(all) fun getAccountData(_ account:AuthAccount):{String:AnyStruct}{ + + var paths: [Path] = [] + var privatePaths: [Path] = [] + var publicPaths: [Path] = [] + var nft : [AnyStruct] = [] + var ft : [AnyStruct] = [] + + + account.forEachStored(fun (path: StoragePath, type: Type): Bool { + if type.isSubtype(of: Type<@NonFungibleToken.Collection>()){ + var collection = account.borrow<&NonFungibleToken.Collection>(from:path)! + nft.append({"path":path, "count":collection.getIDs().length}) + paths.append(path) + } + else if type.isSubtype(of: Type<@FungibleToken.Vault>()){ + var vault = account.borrow<&FungibleToken.Vault>(from:path)! + ft.append({"path":path, "balance":vault.balance}) + paths.append(path) + } + else{ + paths.append(path) + } + return true + }) + + account.forEachPublic(fun (path: PublicPath, type: Type): Bool { + publicPaths.append(path) + return true + }) + + account.forEachPrivate(fun (path: PrivatePath, type: Type): Bool { + privatePaths.append(path) + return true + }) + + + let response: {String: AnyStruct} = {} + + //find profile + var findProfile = account.borrow<&AnyResource>(from:/storage/findProfile) + response["find"] = findProfile + response["capacity"] = account.storageCapacity + response["used"] = account.storageUsed + response["available"] = 0 + response["paths"] = paths + response["public"] = publicPaths + response["private"] = privatePaths + response["nft"] = nft + response["ft"] = ft + + if account.storageCapacity>account.storageUsed{ + response["available"] = account.storageCapacity - account.storageUsed + } + return response + } + +} diff --git a/contracts/t.cdc b/contracts/t.cdc new file mode 100644 index 0000000..38b400c --- /dev/null +++ b/contracts/t.cdc @@ -0,0 +1,32 @@ +import FDNZ from 0x73e4a1094d0bcab6 +import NonFungibleToken from 0x1d7e57aa55817448 +import FungibleToken from 0xf233dcee88fe0abe +import MetadataViews from 0x1d7e57aa55817448 + access(all) fun main(address: Address): AnyStruct{ + + + var account=getAuthAccount(address) + var paths: [Path] = [] + var privatePaths: [Path] = [] + var publicPaths: [Path] = [] + var nft : [AnyStruct] = [] + var ft : [AnyStruct] = [] + + + account.forEachStored(fun (path: StoragePath, type: Type): Bool { + if type.isSubtype(of: Type<@NonFungibleToken.Collection>()){ + var collection = account.borrow<&NonFungibleToken.Collection>(from:path)! + nft.append({"path":path, "count":collection.ownedNFTs.length}) + } + else if type.isSubtype(of: Type<@FungibleToken.Vault>()){ + var vault = account.borrow<&FungibleToken.Vault>(from:path)! + ft.append({"path":path, "balance":vault.balance}) + } + else{ + paths.append(path) + } + return true + }) + + return [paths, nft, ft] + } diff --git a/src/comps/base.js b/src/comps/base.js index 25ae2d9..ebad3ef 100644 --- a/src/comps/base.js +++ b/src/comps/base.js @@ -49,6 +49,7 @@ export const Icon = ({icon}) => export const accountUrl = (addr) => `/${withPrefix(addr)}` export const keysUrl = (addr) => `/${withPrefix(addr)}/keys` export const contractUrl = (addr, name) => `${accountUrl(addr)}/${name}` +export const storageUrlRaw = (addr, domain, name) => `${accountUrl(addr)}/raw/${domain}/${name.replace("/","\\")}` export const storageUrl = (addr, domain, name) => `${accountUrl(addr)}/${domain}/${name.replace("/","\\")}` export const nftUrl = (addr, domain, name, id) => `${accountUrl(addr)}/${domain}/${name.replace("/","\\")}/${id}` diff --git a/src/index.js b/src/index.js index 4c74bec..6e2a5f7 100644 --- a/src/index.js +++ b/src/index.js @@ -99,6 +99,8 @@ ReactDOM.render( + + @@ -107,6 +109,8 @@ ReactDOM.render( + + diff --git a/src/pages/account/index.js b/src/pages/account/index.js index 18357c4..170b702 100644 --- a/src/pages/account/index.js +++ b/src/pages/account/index.js @@ -9,7 +9,7 @@ import {useCurrentUser} from "../../hooks/use-current-user" import {useNetworkForAddress } from "../../hooks/use-network"; import {withPrefix} from "../../util/address.util" import {getNetworkFromAddress} from "../../util/address.util" -import {contractUrl, storageUrl, Icon, accountUrl} from "../../comps/base" +import {contractUrl, storageUrlRaw, storageUrl, Icon, accountUrl} from "../../comps/base" import {Keys} from "./keys" import { Content as Contracts } from "./contract"; import Page from "../../comps/page" @@ -250,7 +250,7 @@ export function AccountSideBar() { Storage   {storageCapacity(accountStorage)} Capacity - {accountStorage && accountStorage?.paths.map(path => ( + {accountStorage && accountStorage?.paths.sort(function compareFn(a, b) { return a.identifier < b.identifier}).map(path => (
))} - -
diff --git a/src/pages/account/storage.js b/src/pages/account/storage.js index 72a8735..701504d 100644 --- a/src/pages/account/storage.js +++ b/src/pages/account/storage.js @@ -285,7 +285,10 @@ function Traits({view}) { Traits {view["traits"] && view["traits"].map(trait => { - const value = trait["MetadataViews.Trait"]["value"].toString() + var value = trait["MetadataViews.Trait"]["value"] + if (value){ + value = value.toString() + } const name = trait["MetadataViews.Trait"]["name"] return (
{name}: {value}
) @@ -299,7 +302,7 @@ function Traits({view}) { } export function Content() { - const {address, domain, path, uuid} = useParams() + const {address, domain, path, uuid, raw} = useParams() const [storage, setStorage] = useState(null) const [storageRaw, setStorageRaw] = useState(null) @@ -307,6 +310,7 @@ export function Content() { if (getNetworkFromAddress(address)=="previewnet"){ authAccountCall = "getAuthAccount(address)" } + const isRaw = raw == "raw" useEffect(() => { setStorage(null) @@ -317,7 +321,7 @@ export function Content() { var cadence = ` import FDNZ from 0xFDNZ access(all) fun main(address: Address, path: String) : AnyStruct{ - return FDNZ.getAccountStorage(${authAccountCall}, path: path) + return FDNZ.getAccountStorage${isRaw?"Raw":""}(${authAccountCall}, path: path) } ` @@ -418,14 +422,14 @@ export function Content() { - { link.target!="" && + { link.target && link.target!="" && - { link.target!="" && {link.target} } - - + + } }
@@ -452,7 +456,7 @@ export function Content() { } - {uuid == null && !hasCustomDisplay && storage && (domain === "storage") && + {uuid == null && (!hasCustomDisplay || isRaw) && storage && (domain === "storage") && } )