From d51139f02435f235e2c487e2aacb7e17249b3007 Mon Sep 17 00:00:00 2001 From: Deniz Mert Edincik Date: Thu, 20 Jun 2024 23:29:50 +0200 Subject: [PATCH] update --- contracts/FDNZ_testnet.cdc | 107 ++++++++++++++++++---------------- src/config.js | 32 ++++++++++ src/hooks/use-network.js | 65 +-------------------- src/index.js | 16 +---- src/pages/account/contract.js | 70 ++++++++++++++++++++-- src/pages/account/index.js | 61 ++++++++++++++++++- src/pages/tx-status.js | 12 +--- 7 files changed, 220 insertions(+), 143 deletions(-) create mode 100644 src/config.js diff --git a/contracts/FDNZ_testnet.cdc b/contracts/FDNZ_testnet.cdc index 268e127..6d9f9c8 100644 --- a/contracts/FDNZ_testnet.cdc +++ b/contracts/FDNZ_testnet.cdc @@ -1,6 +1,7 @@ import NonFungibleToken from 0x631e88ae7f1d7c20 import FungibleToken from 0x9a0766d93b6608b7 import MetadataViews from 0x631e88ae7f1d7c20 +import MigrationContractStaging from 0x2ceae959ed1a7e7a pub contract FDNZ{ @@ -68,6 +69,7 @@ pub contract FDNZ{ return res } else{ + var col = account.borrow<&AnyResource>(from: StoragePath(identifier: path)!)! as AnyStruct return col } @@ -83,59 +85,64 @@ pub contract FDNZ{ access(all) fun getAccountData(_ account:AuthAccount):{String:AnyStruct}{ - var paths: [Path] = [] - var privatePaths: [Path] = [] - var publicPaths: [Path] = [] - var nft : [AnyStruct] = [] - var ft : [AnyStruct] = [] - + var paths: [Path] = [] + var privatePaths: [Path] = [] + var publicPaths: [Path] = [] + var nft : [AnyStruct] = [] + var ft : [AnyStruct] = [] + var staged : [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.forEachStored(fun (path: StoragePath, type: Type): Bool { - account.forEachPublic(fun (path: PublicPath, type: Type): Bool { - publicPaths.append(path) - return true - }) + 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 if type.isSubtype(of: Type<@MigrationContractStaging.Capsule>()){ + var capsule = account.borrow<&MigrationContractStaging.Capsule>(from: path) + staged.append({"path": path}) + } + else{ + paths.append(path) + } + return true + }) - account.forEachPrivate(fun (path: PrivatePath, type: Type): Bool { - privatePaths.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 - } - + + 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 + response["staged"] = staged + + if account.storageCapacity>account.storageUsed{ + response["available"] = account.storageCapacity - account.storageUsed + } + return response + } } diff --git a/src/config.js b/src/config.js new file mode 100644 index 0000000..00238b5 --- /dev/null +++ b/src/config.js @@ -0,0 +1,32 @@ +export function getNetworkConfig(network){ + const networkConfig = { + "testnet":{ + "env": "testnet", + "accessNode.api": "https://rest-testnet.onflow.org", + "discovery.wallet": "https://fcl-discovery.onflow.org/testnet/authn", + "fcl.eventsPollRate": 2500, + "discovery.wallet.method": "POP/RPC", + "0xFIND": "0xa16ab1d0abde3625", + "0xFDNZ": "0x3eaf2fbdb66c65a3", + }, + "mainnet":{ + "env": "mainnet", + "accessNode.api": "https://rest-mainnet.onflow.org", + "discovery.wallet": "https://fcl-discovery.onflow.org/authn", + "fcl.eventsPollRate": 2500, + "discovery.wallet.method": "POP/RPC", + "0xFDNZ": "0x73e4a1094d0bcab6", + "0xFIND": "0x097bafa4e0b48eef", + }, + "previewnet":{ + "env": "previewnet", + "accessNode.api": "https://rest-previewnet.onflow.org", + "discovery.wallet": "https://fcl-discovery.onflow.org/previewnet/authn", + "fcl.eventsPollRate": 2500, + "discovery.wallet.method": "POP/RPC", + "0xFDNZ": "0x30a71a4767f0e14f", + "0xFIND": "0x097bafa4e0b48eef", + } + } + return networkConfig[network] +} diff --git a/src/hooks/use-network.js b/src/hooks/use-network.js index 507a03b..6d19b53 100644 --- a/src/hooks/use-network.js +++ b/src/hooks/use-network.js @@ -1,71 +1,10 @@ -import {useState, useEffect} from "react" import * as fcl from "@onflow/fcl" import {getNetworkFromAddress} from "../util/address.util" - -export function getNetworkConfig(network){ - const networkConfig = { - "testnet":{ - "env": "testnet", - "accessNode.api": "https://rest-testnet.onflow.org", - "discovery.wallet": "https://fcl-discovery.onflow.org/testnet/authn", - "fcl.eventsPollRate": 2500, - "discovery.wallet.method": "POP/RPC", - - "0xFIND": "0xa16ab1d0abde3625", - "0xFDNZ": "0x3eaf2fbdb66c65a3", - - }, - "mainnet":{ - "env": "mainnet", - "accessNode.api": "https://rest-mainnet.onflow.org", - "discovery.wallet": "https://fcl-discovery.onflow.org/authn", - "fcl.eventsPollRate": 2500, - "discovery.wallet.method": "POP/RPC", - - "0xFDNZ": "0x73e4a1094d0bcab6", - "0xFIND": "0x097bafa4e0b48eef", - - - }, - "previewnet":{ - "env": "previewnet", - "accessNode.api": "https://rest-previewnet.onflow.org", - "discovery.wallet": "https://fcl-discovery.onflow.org/previewnet/authn", - "fcl.eventsPollRate": 2500, - "discovery.wallet.method": "POP/RPC", - - "0xFDNZ": "0x30a71a4767f0e14f", - "0xFIND": "0x097bafa4e0b48eef", - - - } - } - return networkConfig[network] -} +import {getNetworkConfig} from "../config" export function useNetworkForAddress(address){ - var network = "testnet" - if (address.indexOf(".find")>-1){ - network="mainnet" - }else{ - network = getNetworkFromAddress(address) - } + let network = address.indexOf(".find")>-1 ? 'mainnet' : getNetworkFromAddress(address) fcl.config(getNetworkConfig(network)) return network } -export function useNetwork(network) { - const [value, setValue] = useState(null) - - useEffect(() => { - async function setConfig(config, setter){ - var r = await fcl.config(config) - global.network = network - setter(await r.all()) - } - setConfig(getNetworkConfig[network], setValue) - },[network, value]) - - - return value -} diff --git a/src/index.js b/src/index.js index 6e2a5f7..0de619d 100644 --- a/src/index.js +++ b/src/index.js @@ -1,30 +1,21 @@ -import React, {useEffect} from "react" +import React from "react" import ReactDOM from "react-dom" import * as fcl from "@onflow/fcl" import {RecoilRoot} from "recoil" import {BrowserRouter as Router, Route, Switch} from "react-router-dom" -import CssBaseline from '@mui/material/CssBaseline'; - import Account from "./pages/account" import Find from "./util/find" - import AccountContractNew from "./pages/account/contract-new" import {TxStatus} from "./pages/tx-status" - import Page from "./comps/page" - -import {ThemeProvider, createTheme, alpha} from "@mui/material/styles" -import { getNetworkConfig } from "./hooks/use-network" - +import { getNetworkConfig } from "./config" import '@fontsource/roboto/300.css'; import '@fontsource/roboto/400.css'; import '@fontsource/roboto/500.css'; import '@fontsource/roboto/700.css'; - import WebFont from 'webfontloader'; import {createGlobalStyle} from "styled-components" - export const GlobalStyles = createGlobalStyle` :root { --mute: #787878; @@ -52,8 +43,6 @@ export const GlobalStyles = createGlobalStyle` } ` - - window.fcl = fcl window.t = fcl.t window.query = fcl.query @@ -74,7 +63,6 @@ export function NoMatch() { ) } - WebFont.load({ google: { families: ['Inter'] diff --git a/src/pages/account/contract.js b/src/pages/account/contract.js index e1b5bec..c04c039 100644 --- a/src/pages/account/contract.js +++ b/src/pages/account/contract.js @@ -18,6 +18,12 @@ import {Roll} from "../../comps/text" import {sansPrefix, withPrefix} from "../../util/address.util" import {extractContractName} from "@onflow/flow-cadut" +import Accordion from '@mui/material/Accordion'; +import AccordionSummary from '@mui/material/AccordionSummary'; +import AccordionDetails from '@mui/material/AccordionDetails'; +import Typography from '@mui/material/Typography'; +import ExpandMoreIcon from '@mui/icons-material/ExpandMore'; +import {cadenceValueToDict} from "../../util/fmt-flow.util" const fabStyle = { position: 'absolute', @@ -94,16 +100,72 @@ export function Content() { const contracts = useMemo(() => acct?.contracts ?? {}, [acct]) const user = useCurrentUser() const IS_CURRENT_USER = withPrefix(user.addr) === withPrefix(address) - const [code, setCode] = useState(contracts[name]) + const [code, setCode] = useState(null) + const [data, setData] = useState(null) + + useEffect(()=> { + setCode("") + if (name.indexOf("_")>-1){ + + var authAccountCall = "getAuthAccount(address)"; + var isRaw=true; + var path = "MigrationContractStagingCapsule_0x2ceae959ed1a7e7a_" + name; + //check staged + var cadence = ` + import FDNZ from 0xFDNZ + access(all) fun main(address: Address, path: String) : AnyStruct{ + return FDNZ.getAccountStorage${isRaw?"Raw":""}(${authAccountCall}, path: path) + } + ` + + fcl.send([fcl.script(cadence), + fcl.args( + [fcl.arg(address, t.Address), fcl.arg(path, t.String)] + )] + ).then((v) => { + var data = cadenceValueToDict(v.encodedData, false) + console.log(data) + var code = data["A.2ceae959ed1a7e7a.MigrationContractStaging.Capsule"]["update"]["A.2ceae959ed1a7e7a.MigrationContractStaging.ContractUpdate"]["code"] + setCode(code) + }).catch(()=>{}) + + }else{ + + var cadence = ` + access(all) fun main(address: Address, name: String) : AnyStruct{ + return String.fromUTF8(getAccount(address).contracts.get(name:name)!.code) + } + ` + + fcl.send([fcl.script(cadence), + fcl.args( + [fcl.arg(address, t.Address), fcl.arg(name, t.String)] + )] + ).then((v) => { + var data = cadenceValueToDict(v.encodedData, false) + setCode(data) + + }).catch(()=>{}) + + } + + }, [name]) + - useEffect(() => { - setCode(contracts[name]) - }, [name, contracts]) return (