Skip to content

Commit

Permalink
Merge pull request dapperlabs#12 from dapperlabs/qvvg/paths
Browse files Browse the repository at this point in the history
Qvvg/paths
  • Loading branch information
orodio authored Dec 23, 2020
2 parents 69142eb + e099a51 commit b563919
Show file tree
Hide file tree
Showing 10 changed files with 117 additions and 109 deletions.
23 changes: 10 additions & 13 deletions src/flow/fetch-account-item.script.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,17 @@ pub struct Item {
pub fun fetch(address: Address, id: UInt64): Item? {
let cap = getAccount(address)
.getCapability<&{NonFungibleToken.CollectionPublic}>(/public/KittyItemsCollection)!
.getCapability<&KittyItems.Collection{NonFungibleToken.CollectionPublic, KittyItems.KittyItemsCollectionPublic}>(KittyItems.CollectionPublicPath)!
return Item(id: id, type: 0)
// Waiting on future contract deployment
// if let collection = cap.borrow() {
// if let item = collection.borrowKittyItem(id: id) {
// return Item(id: id, type: item.typeID)
// } else {
// return nil
// }
// } else {
// return nil
// }
if let collection = cap.borrow() {
if let item = collection.borrowKittyItem(id: id) {
return Item(id: id, type: item.typeID)
} else {
return nil
}
} else {
return nil
}
}
pub fun main(keys: [String], addresses: [Address], ids: [UInt64]): {String: Item?} {
Expand Down
2 changes: 1 addition & 1 deletion src/flow/fetch-account-items.script.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const CODE = cdc`
pub fun main(address: Address): [UInt64] {
let cap = getAccount(address)
.getCapability<&{NonFungibleToken.CollectionPublic}>(/public/KittyItemsCollection)!
.getCapability<&KittyItems.Collection{NonFungibleToken.CollectionPublic, KittyItems.KittyItemsCollectionPublic}>(KittyItems.CollectionPublicPath)!
if let collection = cap.borrow() {
return collection.getIDs()
Expand Down
3 changes: 2 additions & 1 deletion src/flow/fetch-kibbles-balance.script.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import {Address} from "@onflow/types"

const CODE = cdc`
import FungibleToken from 0xFungibleToken
import Kibble from 0xKibble
pub fun main(address: Address): UFix64? {
let cap = getAccount(address)
.getCapability<&{FungibleToken.Balance}>(/public/KibbleBalance)!
.getCapability<&Kibble.Vault{FungibleToken.Balance}>(Kibble.BalancePublicPath)!
if let vault = cap.borrow() {
return vault.balance
Expand Down
71 changes: 45 additions & 26 deletions src/flow/initialize-account.tx.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,56 @@ const CODE = cdc`
import KittyItems from 0xKittyItems
import KittyItemsMarket from 0xKittyItemsMarket
pub fun hasKibble(_ address: Address): Bool {
let receiver = getAccount(address)
.getCapability<&Kibble.Vault{FungibleToken.Receiver}>(Kibble.ReceiverPublicPath)!
.check()
let balance = getAccount(address)
.getCapability<&Kibble.Vault{FungibleToken.Balance}>(Kibble.BalancePublicPath)!
.check()
return receiver && balance
}
pub fun hasItems(_ address: Address): Bool {
return getAccount(address)
.getCapability<&KittyItems.Collection{NonFungibleToken.CollectionPublic, KittyItems.KittyItemsCollectionPublic}>(KittyItems.CollectionPublicPath)!
.check()
}
pub fun hasMarket(_ address: Address): Bool {
return getAccount(address)
.getCapability<&KittyItemsMarket.Collection{KittyItemsMarket.CollectionPublic}>(KittyItemsMarket.CollectionPublicPath)!
.check()
}
transaction {
prepare(acct: AuthAccount) {
// Kibble
if acct.borrow<&Kibble.Vault>(from: /storage/KibbleVault) == nil {
let privatePath = /storage/KibbleVault
let receiverPath = /public/KibbleReceiver
let balancePath = /public/KibbleBalance
acct.save(<-Kibble.createEmptyVault(), to: privatePath)
acct.link<&Kibble.Vault{FungibleToken.Receiver}>(receiverPath, target: privatePath)
acct.link<&Kibble.Vault{FungibleToken.Balance}>(balancePath, target: privatePath)
if !hasKibble(acct.address) {
if acct.borrow<&Kibble.Vault>(from: /storage/KibbleVault) == nil {
acct.save(<-Kibble.createEmptyVault(), to: Kibble.VaultStoragePath)
}
acct.unlink(Kibble.ReceiverPublicPath)
acct.unlink(Kibble.BalancePublicPath)
acct.link<&Kibble.Vault{FungibleToken.Receiver}>(Kibble.ReceiverPublicPath, target: Kibble.VaultStoragePath)
acct.link<&Kibble.Vault{FungibleToken.Balance}>(Kibble.BalancePublicPath, target: Kibble.VaultStoragePath)
}
// KittyItems
if acct.borrow<&KittyItems.Collection>(from: /storage/KittyItemsCollection) == nil {
let privatePath = /storage/KittyItemsCollection
let providerPath = /private/KittyItemsCollectionProvider
let collectionPath = /public/KittyItemsCollection
acct.save(<-KittyItems.createEmptyCollection(), to: privatePath)
acct.link<&KittyItems.Collection{NonFungibleToken.Provider}>(providerPath, target: privatePath)
acct.link<&KittyItems.Collection{NonFungibleToken.CollectionPublic}>(collectionPath, target: privatePath)
if !hasItems(acct.address) {
if acct.borrow<&KittyItems.Collection>(from: /storage/KittyItemsCollection) == nil {
acct.save(<-KittyItems.createEmptyCollection(), to: KittyItems.CollectionStoragePath)
}
acct.unlink(KittyItems.CollectionPublicPath)
acct.link<&KittyItems.Collection{NonFungibleToken.CollectionPublic, KittyItems.KittyItemsCollectionPublic}>(KittyItems.CollectionPublicPath, target: KittyItems.CollectionStoragePath)
}
// KittyItemsMarket
if acct.borrow<&KittyItemsMarket.Collection>(from: /storage/KittyItemsMarketCollection) == nil {
let privatePath = /storage/KittyItemsMarketCollection
let collectionPath = /public/KittyItemsMarketCollection
acct.save(<-KittyItemsMarket.createEmptyCollection(), to: privatePath)
acct.link<&KittyItemsMarket.Collection{KittyItemsMarket.CollectionPublic}>(collectionPath, target: privatePath)
if !hasMarket(acct.address) {
if acct.borrow<&KittyItemsMarket.Collection>(from: /storage/KittyItemsMarketCollection) == nil {
acct.save(<-KittyItemsMarket.createEmptyCollection(), to: KittyItemsMarket.CollectionStoragePath)
}
acct.unlink(KittyItemsMarket.CollectionPublicPath)
acct.link<&KittyItemsMarket.Collection{KittyItemsMarket.CollectionPublic}>(KittyItemsMarket.CollectionPublicPath, target:KittyItemsMarket.CollectionStoragePath)
}
}
}
Expand All @@ -53,7 +72,7 @@ export async function initializeAccount(address, opts = {}) {
return tx(
[
transaction(CODE),
limit(45),
limit(70),
proposer(authz),
payer(authz),
authorizations([authz]),
Expand Down
14 changes: 10 additions & 4 deletions src/flow/is-account-initialized.script.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,26 @@ const CODE = cdc`
import KittyItemsMarket from 0xKittyItemsMarket
pub fun hasKibble(_ address: Address): Bool {
return getAccount(address)
.getCapability<&Kibble.Vault{FungibleToken.Balance}>(/public/KibbleBalance)!
let receiver: Bool = getAccount(address)
.getCapability<&Kibble.Vault{FungibleToken.Receiver}>(Kibble.ReceiverPublicPath)!
.check()
let balance: Bool = getAccount(address)
.getCapability<&Kibble.Vault{FungibleToken.Balance}>(Kibble.BalancePublicPath)!
.check()
return receiver && balance
}
pub fun hasKittyItems(_ address: Address): Bool {
return getAccount(address)
.getCapability<&KittyItems.Collection{NonFungibleToken.CollectionPublic}>(/public/KittyItemsCollection)!
.getCapability<&KittyItems.Collection{NonFungibleToken.CollectionPublic, KittyItems.KittyItemsCollectionPublic}>(KittyItems.CollectionPublicPath)!
.check()
}
pub fun hasKittyItemsMarket(_ address: Address): Bool {
return getAccount(address)
.getCapability<&KittyItemsMarket.Collection{KittyItemsMarket.CollectionPublic}>(/public/KittyItemsMarketCollection)!
.getCapability<&KittyItemsMarket.Collection{KittyItemsMarket.CollectionPublic}>(KittyItemsMarket.CollectionPublicPath)!
.check()
}
Expand Down
34 changes: 0 additions & 34 deletions src/flow/mint-kibbles.tx.js

This file was deleted.

9 changes: 5 additions & 4 deletions src/global/config.comp.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import {useEffect} from "react"
import {config} from "@onflow/fcl"

const CONTRACTS = "0xfcceff21d9532b58"

export function Config() {
useEffect(() => {
// prettier-ignore
Expand All @@ -10,10 +12,9 @@ export function Config() {
.put("challenge.handshake", "https://fcl-discovery.vercel.app/testnet/authn")
.put("0xFungibleToken", "0x9a0766d93b6608b7")
.put("0xNonFungibleToken", "0x631e88ae7f1d7c20")
.put("0xKibble", "0xf79ee844bfa76528")
.put("0xKittyItems", "0xf79ee844bfa76528")
.put("0xKittyItemsMarket", "0xf79ee844bfa76528")
.put("0xDietKibbles", "0x06f65a4f32bba850") // deprecated
.put("0xKibble", CONTRACTS)
.put("0xKittyItems", CONTRACTS)
.put("0xKittyItemsMarket", CONTRACTS)
}, [])
return null
}
20 changes: 0 additions & 20 deletions src/hooks/use-kibbles-balance.hook.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {atomFamily, selectorFamily, useRecoilState} from "recoil"
import {fetchKibblesBalance} from "../flow/fetch-kibbles-balance.script"
import {mintKibbles} from "../flow/mint-kibbles.tx"
import {IDLE, PROCESSING, SUCCESS, ERROR, IDLE_DELAY} from "../global/constants"
import {sleep} from "../util/sleep"
import {useFlowBalance} from "./use-flow-balance.hook"
Expand Down Expand Up @@ -33,24 +32,5 @@ export function useKibblesBalance(address) {
balance,
status,
refresh,
/* async mint() {
mintKibbles(address, {
onStart() {
setStatus(PROCESSING)
},
onSuccess() {
fetchKibblesBalance(address).then(setBalance)
flow.refresh()
setStatus(SUCCESS)
},
onError() {
setStatus(ERROR)
},
async onComplete() {
await sleep(IDLE_DELAY)
setStatus(IDLE)
},
})
}, */
}
}
8 changes: 2 additions & 6 deletions src/pages/wip/qvvg.page.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {Stack} from "../../display/stack.comp"
import {AuthCluster} from "../../parts/auth-cluster.comp"
import {useCurrentUser} from "../../hooks/use-current-user.hook"
import InitCluster from "../../parts/init-cluster.comp"
import ContractsCluster from "../../parts/contracts-cluster.comp"
import FlowBalanceCluster from "../../parts/flow-balance-cluster.comp"
import KibblesBalanceCluster from "../../parts/kibbles-balance-cluster.comp"
import AccountItemsCluster from "../../parts/account-items-cluster.comp"
Expand All @@ -12,17 +13,12 @@ export function Page() {
return (
<Base>
<Stack>
<ContractsCluster />
<AuthCluster />
<FlowBalanceCluster address={user.addr} />
<KibblesBalanceCluster address={user.addr} />
<InitCluster address={user.addr} />
<AccountItemsCluster address={user.addr} />
{user.addr && (
<>
<h3>Account with known items</h3>
<AccountItemsCluster address="0xf79ee844bfa76528" />
</>
)}
</Stack>
</Base>
)
Expand Down
42 changes: 42 additions & 0 deletions src/parts/contracts-cluster.comp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import {Bar, Label} from "../display/bar.comp"
import {useConfig} from "../hooks/use-config.hook"

const Link = ({address, name}) => {
const env = useConfig("env")

return (
<li>
{name}:{" "}
<a href={fvs(env, address, name)} target="_blank" rel="noreferrer">
{address}
</a>
</li>
)
}

export function ContractsCluster() {
const kibble = useConfig("0xKibble")
const items = useConfig("0xKittyItems")
const market = useConfig("0xKittyItemsMarket")

return (
<div>
<Bar>
<Label>Contracts</Label>
</Bar>
<ul>
<Link address={kibble} name="Kibble" />
<Link address={items} name="KittyItems" />
<Link address={market} name="KittyItemsMarket" />
</ul>
</div>
)
}

export default function WrappedContractsCluster() {
return <ContractsCluster />
}

function fvs(env, addr, contract) {
return `https://flow-view-source.com/${env}/account/${addr}/contract/${contract}`
}

0 comments on commit b563919

Please sign in to comment.