import { WALLET_ACCOUNT_CHANGE } from "../common/WalletEvent"; import { DEFALUT_TOKENS } from "../config/chain_config"; import { IToken } from "../data/DataModel"; import WalletBase from "./WallerBase"; const {ccclass, property} = cc._decorator; @ccclass export default class TokenList extends WalletBase { @property(cc.Prefab) tokenPreb: cc.Prefab = null @property(cc.Node) contentNode: cc.Node = null // LIFE-CYCLE CALLBACKS: // onLoad () {} start () { super.start() this.wallet.mainHandlers.on(WALLET_ACCOUNT_CHANGE, this.updateList.bind(this)) this.updateList() } // update (dt) {} updateList() { this.contentNode.removeAllChildren() const accountData =this.wallet.currentAccountData if (!accountData) { return } if (accountData.tokens.length == 0) { let tokens = this.currentTokens() for (let token of tokens) { accountData.tokens.push(token) } } for (let data of accountData.tokens) { this.addOneToken(data) } } currentTokens() { const chain = this.wallet.currentChain.id return DEFALUT_TOKENS[chain] || [] } addOneToken(data: IToken) { let node = cc.instantiate(this.tokenPreb) this.contentNode.addChild(node) node.getComponent('OneToken').init(data) } onClickAddToken() { } }