import { WALLET_HIDE_ACCOUNT_LIST } from "../common/WalletEvent"; import { IAccount, IToken } from "../data/DataModel"; import JCWallet from "../JCWallet"; import { renderFromTokenMinimalUnit } from "../util/number.util"; import { formatAddress } from "../util/wallet.util"; import HashIcon from "./comp/HashIcon"; import WalletBase from "./WallerBase"; const {ccclass, property} = cc._decorator; const ETH_TYPE = 'eth' @ccclass export default class OneToken extends WalletBase { @property(cc.Label) nameLabel: cc.Label = null; @property(cc.Label) addressLabel: cc.Label = null; @property(cc.Node) icon: cc.Node = null; @property(cc.Node) selectImg: cc.Node = null parentNode: cc.Node = null data: IAccount = null // LIFE-CYCLE CALLBACKS: // onLoad () {} start () { super.start() } // update (dt) {} init(_data: IAccount) { this.data = _data if (!this.wallet) { this.wallet = new JCWallet() } this.updateInfo() } private async updateInfo() { this.nameLabel.string = this.data.nickname this.addressLabel.string = formatAddress(this.data.address) // this.addressLabel.string = this.data.address.replace('0x', '') if (this.wallet.iconType === 'jazz') { this.icon.getComponent('JazzIcon').init(this.data.address) } else { this.icon.getComponent('HashIcon').init(this.data.address) } this.selectImg.active = this.wallet.currentAccount().address === this.data.address } onSelectAccount() { this.wallet.selectAccount(this.data.address) this.wallet.uiHandlers.emit(WALLET_HIDE_ACCOUNT_LIST) } }