import { INFT, initNFT } from "../data/DataModel"; import JCWallet from "../JCWallet"; import WalletBase from "./WallerBase"; const {ccclass, property} = cc._decorator; @ccclass export default class NftList extends WalletBase { @property(cc.Prefab) tokenPreb: cc.Prefab = null @property(cc.Node) contentNode: cc.Node = null public address: string = '' public type: string = '' // LIFE-CYCLE CALLBACKS: // onLoad () {} start () { super.start() } // update (dt) {} async updateList() { const account = this.wallet.currentAccount().address const amount = await this.wallet.erc721Standard.getBalance(this.address, account) const nfts = this.wallet.currentAccountData[`${this.type}s`] let refresh = false if (nfts.length !== amount) { refresh = true } this.contentNode.removeAllChildren() if (refresh) { nfts.length = 0 for (let i = 0; i < amount; i++) { const nftData = initNFT(this.address, i) nfts.push(nftData) this.addOneNft(nftData, true) } } else { for (let nftData of nfts) { this.addOneNft(nftData, false) } } } addOneNft(data: INFT, refresh: boolean) { let node = cc.instantiate(this.tokenPreb) node.getComponent('OneNFT').init(data, refresh) this.contentNode.addChild(node) } }