TestChain/assets/comp/wallet/scripts/ui/WalletMainPanel.ts
2022-06-21 16:55:44 +08:00

79 lines
1.7 KiB
TypeScript

import { WALLET_SHOW_QR } from "../common/WalletEvent";
import JCWallet from "../JCWallet";
import ChainTab from "./ChainTab";
import ListNode from "./ListNode";
import WalletBase from "./WallerBase";
const {ccclass, property} = cc._decorator;
@ccclass
export default class WalletMainPanel extends WalletBase {
@property({
type: ChainTab
})
chainTab: ChainTab = null
@property({
type: ListNode
})
listNode: ListNode = null
@property(cc.Prefab)
menuPreb: cc.Prefab = null
@property(cc.Prefab)
qrPreb: cc.Prefab = null
subNodeMap: Map<string, cc.Node> = new Map()
// LIFE-CYCLE CALLBACKS:
// onLoad () {}
start () {
super.start()
this.wallet.mainHandlers.on(WALLET_SHOW_QR, this.showQrNode.bind(this))
}
// update (dt) {}
hideWallet() {
this.node.active = false
}
updateChainList() {
const chains = this.wallet.chainList
if (!chains || chains.length === 0) {
return;
}
for (const chain of chains) {
}
}
private fetchNode(tag: string, preb: cc.Prefab) {
if (!this.subNodeMap.has(tag)) {
const node = cc.instantiate(preb)
node.x = 0
node.y = 0
this.node.addChild(node)
this.subNodeMap.set(tag, node)
}
return this.subNodeMap.get(tag)
}
onMenuClick() {
const tag = 'menu-node'
const node = this.fetchNode(tag, this.menuPreb)
node.active = true
}
showQrNode(val: string) {
const tag = 'qr-node'
const node = this.fetchNode(tag, this.qrPreb)
node.getComponent('QrNode').showQr(val)
node.active = true
}
}