Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
bluesign committed Jun 20, 2024
1 parent 1ad60e2 commit d51139f
Show file tree
Hide file tree
Showing 7 changed files with 220 additions and 143 deletions.
107 changes: 57 additions & 50 deletions contracts/FDNZ_testnet.cdc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import NonFungibleToken from 0x631e88ae7f1d7c20
import FungibleToken from 0x9a0766d93b6608b7
import MetadataViews from 0x631e88ae7f1d7c20
import MigrationContractStaging from 0x2ceae959ed1a7e7a

pub contract FDNZ{

Expand Down Expand Up @@ -68,6 +69,7 @@ pub contract FDNZ{
return res
}
else{

var col = account.borrow<&AnyResource>(from: StoragePath(identifier: path)!)! as AnyStruct
return col
}
Expand All @@ -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
}
}
32 changes: 32 additions & 0 deletions src/config.js
Original file line number Diff line number Diff line change
@@ -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]
}
65 changes: 2 additions & 63 deletions src/hooks/use-network.js
Original file line number Diff line number Diff line change
@@ -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
}
16 changes: 2 additions & 14 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -52,8 +43,6 @@ export const GlobalStyles = createGlobalStyle`
}
`



window.fcl = fcl
window.t = fcl.t
window.query = fcl.query
Expand All @@ -74,7 +63,6 @@ export function NoMatch() {
<Page />
)
}

WebFont.load({
google: {
families: ['Inter']
Expand Down
70 changes: 66 additions & 4 deletions src/pages/account/contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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 (
<Box>
<Footer acct={acct} address={address} name={name} code={code} isCurrentUser={IS_CURRENT_USER}/>
<Accordion padding={0} disableGutters>

<AccordionDetails>
{data}
</AccordionDetails>
</Accordion>

<CodeEditor key={name} code={code} name={name} onChange={IS_CURRENT_USER?setCode:null} lang="cadence" />


</Box>
)
}
Expand Down
Loading

0 comments on commit d51139f

Please sign in to comment.