token type tab 添加对链切换事件的监听

This commit is contained in:
cebgcontract 2022-06-20 16:06:43 +08:00
parent 403a7944a9
commit ecd3818bc2
3 changed files with 11 additions and 5 deletions

View File

@ -19,4 +19,6 @@ export { createWalletEvents }
export const WALLET_CHAIN_CHANGE = 'wallet_chain_change'
export const WALLET_ACCOUNT_CHANGE = 'wallet_account_change'
export const WALLET_TOKEN_TYPE_CHANGE = 'wallet_token_type_change'

View File

@ -1,3 +1,4 @@
import { WALLET_CHAIN_CHANGE } from "../common/WalletEvent";
import { DEFAULT_NFT_TYPES } from "../config/chain_config";
import JCWallet from "../JCWallet";
import ButtonGroup, { BTN_SELECT_INDEX_CHANGE } from "./ButtonGroup";
@ -29,7 +30,8 @@ export default class TokenTab extends WalletBase {
this.btnGroup.resetBtns()
this.btnGroup.node.on(BTN_SELECT_INDEX_CHANGE,
this.onTokenTypeChange.bind(this))
this.showAllBtn();
this.updateAllBtn();
this.wallet.mainHandlers.on(WALLET_CHAIN_CHANGE, this.updateAllBtn.bind(this))
}
onDestroy() {
@ -37,7 +39,7 @@ export default class TokenTab extends WalletBase {
}
// update (dt) {}
showAllBtn() {
updateAllBtn() {
this.titles.length = 1
const chain = this.wallet.currentChain.id
let nftData: any = DEFAULT_NFT_TYPES[chain]
@ -46,12 +48,14 @@ export default class TokenTab extends WalletBase {
this.titles.push(key)
}
}
this.btnGroup.resetBtns()
console.log('show all token tab: ', this.titles)
for (let i = 0, l = this.titles.length; i < l; i++) {
const btn = cc.instantiate(this.btnPreb)
const btnM: TextBtn = btn.getComponent(TextBtn)
this.btnGroup.addBtn(btnM);
btnM.title = this.titles[i].replace(/^\S/, s => s.toUpperCase())
// btnM.title = this.titles[i].replace(/^\S/, s => s.toUpperCase())
btnM.title = this.titles[i].toUpperCase()
btnM.index = i
btnM.selected = i === 0
}

View File

@ -7400,7 +7400,7 @@
},
"_position": {
"__type__": "cc.Vec3",
"x": -358,
"x": -433,
"y": 75,
"z": 0
},
@ -7488,7 +7488,7 @@
},
"_position": {
"__type__": "cc.Vec3",
"x": -317,
"x": -392,
"y": 64,
"z": 0
},