2022-06-19 15:03:30 +08:00

55 lines
1.3 KiB
TypeScript

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.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)
node.getComponent('OneToken').init(data)
this.contentNode.addChild(node)
}
}