增加chain tab读取配置
This commit is contained in:
parent
eb879b834c
commit
61d282678d
287
assets/comp/wallet/prefab/chianBtn.prefab
Normal file
287
assets/comp/wallet/prefab/chianBtn.prefab
Normal file
@ -0,0 +1,287 @@
|
||||
[
|
||||
{
|
||||
"__type__": "cc.Prefab",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"_native": "",
|
||||
"data": {
|
||||
"__id__": 1
|
||||
},
|
||||
"optimizationPolicy": 0,
|
||||
"asyncLoadAssets": false
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Node",
|
||||
"_name": "chianBtn",
|
||||
"_objFlags": 0,
|
||||
"_parent": null,
|
||||
"_children": [
|
||||
{
|
||||
"__id__": 2
|
||||
}
|
||||
],
|
||||
"_active": true,
|
||||
"_level": 1,
|
||||
"_components": [
|
||||
{
|
||||
"__id__": 5
|
||||
},
|
||||
{
|
||||
"__id__": 6
|
||||
},
|
||||
{
|
||||
"__id__": 7
|
||||
}
|
||||
],
|
||||
"_prefab": {
|
||||
"__id__": 8
|
||||
},
|
||||
"_opacity": 255,
|
||||
"_color": {
|
||||
"__type__": "cc.Color",
|
||||
"r": 0,
|
||||
"g": 255,
|
||||
"b": 0,
|
||||
"a": 255
|
||||
},
|
||||
"_contentSize": {
|
||||
"__type__": "cc.Size",
|
||||
"width": 58.23,
|
||||
"height": 40
|
||||
},
|
||||
"_anchorPoint": {
|
||||
"__type__": "cc.Vec2",
|
||||
"x": 0.5,
|
||||
"y": 0.5
|
||||
},
|
||||
"_position": {
|
||||
"__type__": "cc.Vec3",
|
||||
"x": -200,
|
||||
"y": 0,
|
||||
"z": 0
|
||||
},
|
||||
"_scale": {
|
||||
"__type__": "cc.Vec3",
|
||||
"x": 1,
|
||||
"y": 1,
|
||||
"z": 1
|
||||
},
|
||||
"_rotationX": 0,
|
||||
"_rotationY": 0,
|
||||
"_quat": {
|
||||
"__type__": "cc.Quat",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"z": 0,
|
||||
"w": 1
|
||||
},
|
||||
"_skewX": 0,
|
||||
"_skewY": 0,
|
||||
"groupIndex": 0,
|
||||
"_id": ""
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Node",
|
||||
"_name": "titleLabel",
|
||||
"_objFlags": 0,
|
||||
"_parent": {
|
||||
"__id__": 1
|
||||
},
|
||||
"_children": [],
|
||||
"_active": true,
|
||||
"_level": 4,
|
||||
"_components": [
|
||||
{
|
||||
"__id__": 3
|
||||
}
|
||||
],
|
||||
"_prefab": {
|
||||
"__id__": 4
|
||||
},
|
||||
"_opacity": 255,
|
||||
"_color": {
|
||||
"__type__": "cc.Color",
|
||||
"r": 0,
|
||||
"g": 255,
|
||||
"b": 0,
|
||||
"a": 255
|
||||
},
|
||||
"_contentSize": {
|
||||
"__type__": "cc.Size",
|
||||
"width": 42.23,
|
||||
"height": 40
|
||||
},
|
||||
"_anchorPoint": {
|
||||
"__type__": "cc.Vec2",
|
||||
"x": 0.5,
|
||||
"y": 0.5
|
||||
},
|
||||
"_position": {
|
||||
"__type__": "cc.Vec3",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"z": 0
|
||||
},
|
||||
"_scale": {
|
||||
"__type__": "cc.Vec3",
|
||||
"x": 1,
|
||||
"y": 1,
|
||||
"z": 1
|
||||
},
|
||||
"_rotationX": 0,
|
||||
"_rotationY": 0,
|
||||
"_quat": {
|
||||
"__type__": "cc.Quat",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"z": 0,
|
||||
"w": 1
|
||||
},
|
||||
"_skewX": 0,
|
||||
"_skewY": 0,
|
||||
"groupIndex": 0,
|
||||
"_id": ""
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Label",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": {
|
||||
"__id__": 2
|
||||
},
|
||||
"_enabled": true,
|
||||
"_useOriginalSize": false,
|
||||
"_string": "KCC",
|
||||
"_N$string": "KCC",
|
||||
"_fontSize": 20,
|
||||
"_lineHeight": 40,
|
||||
"_enableWrapText": true,
|
||||
"_N$file": null,
|
||||
"_isSystemFontUsed": true,
|
||||
"_spacingX": 0,
|
||||
"_batchAsBitmap": false,
|
||||
"_N$horizontalAlign": 1,
|
||||
"_N$verticalAlign": 1,
|
||||
"_N$fontFamily": "Arial",
|
||||
"_N$overflow": 0,
|
||||
"_N$cacheMode": 0,
|
||||
"_id": ""
|
||||
},
|
||||
{
|
||||
"__type__": "cc.PrefabInfo",
|
||||
"root": {
|
||||
"__id__": 1
|
||||
},
|
||||
"asset": {
|
||||
"__uuid__": "0c374587-de82-47c2-89ba-6219ee24d576"
|
||||
},
|
||||
"fileId": "9e4MadT4xKM7M8NoajRX1a",
|
||||
"sync": false
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Sprite",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": {
|
||||
"__id__": 1
|
||||
},
|
||||
"_enabled": true,
|
||||
"_srcBlendFactor": 770,
|
||||
"_dstBlendFactor": 771,
|
||||
"_spriteFrame": {
|
||||
"__uuid__": "13d3eb87-b218-4fb7-b7c2-31e8a58b67bc"
|
||||
},
|
||||
"_type": 1,
|
||||
"_sizeMode": 0,
|
||||
"_fillType": 0,
|
||||
"_fillCenter": {
|
||||
"__type__": "cc.Vec2",
|
||||
"x": 0,
|
||||
"y": 0
|
||||
},
|
||||
"_fillStart": 0,
|
||||
"_fillRange": 0,
|
||||
"_isTrimmedMode": true,
|
||||
"_state": 0,
|
||||
"_atlas": null,
|
||||
"_id": ""
|
||||
},
|
||||
{
|
||||
"__type__": "7b631hG5VxEu6deSSqBp4B1",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": {
|
||||
"__id__": 1
|
||||
},
|
||||
"_enabled": true,
|
||||
"titleLabel": {
|
||||
"__id__": 3
|
||||
},
|
||||
"border": {
|
||||
"__id__": 1
|
||||
},
|
||||
"title": "KCC",
|
||||
"selected": false,
|
||||
"colors": [
|
||||
{
|
||||
"__type__": "cc.Color",
|
||||
"r": 127,
|
||||
"g": 127,
|
||||
"b": 127,
|
||||
"a": 255
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Color",
|
||||
"r": 0,
|
||||
"g": 255,
|
||||
"b": 0,
|
||||
"a": 255
|
||||
}
|
||||
],
|
||||
"_id": ""
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Layout",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": {
|
||||
"__id__": 1
|
||||
},
|
||||
"_enabled": true,
|
||||
"_layoutSize": {
|
||||
"__type__": "cc.Size",
|
||||
"width": 58.23,
|
||||
"height": 40
|
||||
},
|
||||
"_resize": 1,
|
||||
"_N$layoutType": 0,
|
||||
"_N$padding": 0,
|
||||
"_N$cellSize": {
|
||||
"__type__": "cc.Size",
|
||||
"width": 40,
|
||||
"height": 40
|
||||
},
|
||||
"_N$startAxis": 0,
|
||||
"_N$paddingLeft": 8,
|
||||
"_N$paddingRight": 8,
|
||||
"_N$paddingTop": 0,
|
||||
"_N$paddingBottom": 0,
|
||||
"_N$spacingX": 0,
|
||||
"_N$spacingY": 0,
|
||||
"_N$verticalDirection": 1,
|
||||
"_N$horizontalDirection": 0,
|
||||
"_N$affectedByScale": false,
|
||||
"_id": ""
|
||||
},
|
||||
{
|
||||
"__type__": "cc.PrefabInfo",
|
||||
"root": {
|
||||
"__id__": 1
|
||||
},
|
||||
"asset": {
|
||||
"__uuid__": "0c374587-de82-47c2-89ba-6219ee24d576"
|
||||
},
|
||||
"fileId": "2fe9QtYFlIdpJ68VPYSw6a",
|
||||
"sync": false
|
||||
}
|
||||
]
|
7
assets/comp/wallet/prefab/chianBtn.prefab.meta
Normal file
7
assets/comp/wallet/prefab/chianBtn.prefab.meta
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"ver": "1.0.1",
|
||||
"uuid": "0c374587-de82-47c2-89ba-6219ee24d576",
|
||||
"optimizationPolicy": "AUTO",
|
||||
"asyncLoadAssets": false,
|
||||
"subMetas": {}
|
||||
}
|
@ -2,12 +2,24 @@ import { singleton } from "./decorator/singleton.decorator";
|
||||
import Web3 = require('./lib/web3.min');
|
||||
import sth = require("./lib/ethSigUtil");
|
||||
import { ZError } from "./common/ZError";
|
||||
import { AllChains } from './data/allchain';
|
||||
|
||||
export interface IChainData {
|
||||
name: string,
|
||||
type: string,
|
||||
rpc: string,
|
||||
id: number,
|
||||
symbol: string,
|
||||
explorerurl: string
|
||||
}
|
||||
@singleton
|
||||
export default class JCWallet {
|
||||
web3: Web3 = null
|
||||
wallet: any = null
|
||||
password: string = '111111'
|
||||
chainSet: Set<number> = new Set()
|
||||
chainMap: Map<number, IChainData> = new Map()
|
||||
private _currentChain: IChainData
|
||||
|
||||
constructor() {
|
||||
this.web3 = new Web3('https://rpc-testnet.kcc.network')
|
||||
@ -20,7 +32,29 @@ export default class JCWallet {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public init({chains}: {chains: number[]}) {
|
||||
for (let chain of chains) {
|
||||
this.chainSet.add(chain)
|
||||
if (!this.chainMap.has(chain)) {
|
||||
let data = AllChains.find(o => o.id === chain)
|
||||
if (data) {
|
||||
this.chainMap.set(chain, data);
|
||||
if (!this._currentChain) {
|
||||
this._currentChain = data
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
get currentChain() {
|
||||
return this._currentChain
|
||||
}
|
||||
|
||||
get chainList() {
|
||||
return [...this.chainMap.values()]
|
||||
}
|
||||
|
||||
public saveLocal() {
|
||||
|
||||
}
|
||||
|
@ -97,7 +97,7 @@ export const AllChains = [
|
||||
explorerurl: 'https://hooscan.com'
|
||||
},
|
||||
{
|
||||
name: 'Binance Smart Chain Testnet RPC',
|
||||
name: 'Binance Testnet',
|
||||
type: 'Testnet',
|
||||
rpc: 'https://data-seed-prebsc-1-s1.binance.org:8545/',
|
||||
id: 97,
|
||||
|
@ -7,7 +7,7 @@ export default class ButtonGroup extends WalletBase {
|
||||
@property({
|
||||
type: [TextBtn]
|
||||
})
|
||||
btns: TextBtn[];
|
||||
btns: TextBtn[] = [];
|
||||
|
||||
// LIFE-CYCLE CALLBACKS:
|
||||
|
||||
|
45
assets/comp/wallet/scripts/ui/ChainTab.ts
Normal file
45
assets/comp/wallet/scripts/ui/ChainTab.ts
Normal file
@ -0,0 +1,45 @@
|
||||
import JCWallet from "../JCWallet";
|
||||
import ButtonGroup from "./ButtonGroup";
|
||||
import TextBtn from "./TextBtn";
|
||||
|
||||
const {ccclass, property} = cc._decorator;
|
||||
|
||||
@ccclass
|
||||
export default class ChainTab extends cc.Component {
|
||||
private wallet: JCWallet
|
||||
|
||||
@property({
|
||||
type: ButtonGroup
|
||||
})
|
||||
btnGroup: ButtonGroup = null
|
||||
|
||||
@property({
|
||||
type: cc.Prefab
|
||||
})
|
||||
btnPreb: cc.Prefab = null
|
||||
// LIFE-CYCLE CALLBACKS:
|
||||
|
||||
// onLoad () {}
|
||||
|
||||
start () {
|
||||
this.wallet = new JCWallet()
|
||||
this.updateChains()
|
||||
}
|
||||
|
||||
// update (dt) {}
|
||||
|
||||
updateChains() {
|
||||
const chains = this.wallet.chainList
|
||||
if (!chains || chains.length === 0) {
|
||||
return;
|
||||
}
|
||||
this.node.removeAllChildren()
|
||||
for (const chain of chains) {
|
||||
const btn = cc.instantiate(this.btnPreb)
|
||||
const btnM: TextBtn = btn.getComponent(TextBtn)
|
||||
this.node.addChild(btn)
|
||||
btnM.title = chain.name
|
||||
btnM.selected = this.wallet.currentChain.id === chain.id
|
||||
}
|
||||
}
|
||||
}
|
9
assets/comp/wallet/scripts/ui/ChainTab.ts.meta
Normal file
9
assets/comp/wallet/scripts/ui/ChainTab.ts.meta
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "1.0.5",
|
||||
"uuid": "aa36f363-287c-40d3-a011-ced42a21eb6d",
|
||||
"isPlugin": false,
|
||||
"loadPluginInWeb": true,
|
||||
"loadPluginInNative": true,
|
||||
"loadPluginInEditor": false,
|
||||
"subMetas": {}
|
||||
}
|
@ -1,16 +1,24 @@
|
||||
import JCWallet from "../JCWallet";
|
||||
import ChainTab from "./ChainTab";
|
||||
import WalletBase from "./WallerBase";
|
||||
|
||||
const {ccclass, property} = cc._decorator;
|
||||
|
||||
@ccclass
|
||||
export default class WalletMainPanel extends WalletBase {
|
||||
private wallet: JCWallet
|
||||
|
||||
@property({
|
||||
type: ChainTab
|
||||
})
|
||||
chainTab: ChainTab = null
|
||||
|
||||
// LIFE-CYCLE CALLBACKS:
|
||||
|
||||
// onLoad () {}
|
||||
|
||||
start () {
|
||||
|
||||
this.wallet = new JCWallet()
|
||||
}
|
||||
|
||||
// update (dt) {}
|
||||
@ -18,4 +26,14 @@ export default class WalletMainPanel extends WalletBase {
|
||||
hideWallet() {
|
||||
this.node.active = false
|
||||
}
|
||||
|
||||
updateChainList() {
|
||||
const chains = this.wallet.chainList
|
||||
if (!chains || chains.length === 0) {
|
||||
return;
|
||||
}
|
||||
for (const chain of chains) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -25,6 +25,10 @@ export default class WalletController extends cc.Component {
|
||||
start () {
|
||||
this.walletNode.active = false;
|
||||
this.wallet = new JCWallet();
|
||||
let chains = CC_DEBUG ? [322, 97] : [321, 56]
|
||||
this.wallet.init({
|
||||
chains
|
||||
})
|
||||
console.log(this.wallet.currentAccount());
|
||||
}
|
||||
|
||||
@ -71,7 +75,7 @@ export default class WalletController extends cc.Component {
|
||||
console.log(`target address: ${resultAddress}`)
|
||||
console.log(`is same: ${account.address.toLowerCase() == resultAddress}`)
|
||||
let loginUrlBase = 'https://market.cebg.games/webapp/index.php?c=Market&a=auth'
|
||||
let loginUrl = `${loginUrlBase}&account=${account.address}&nonce=${nonce}&signature=${result}&tips=${tips.replaceAll('\ ', '+')}&net_id=322`
|
||||
let loginUrl = `${loginUrlBase}&account=${account.address}&nonce=${nonce}&signature=${result}&tips=${tips.replace(/\ /g, '+')}&net_id=322`
|
||||
let resLogin = await GET(loginUrl);
|
||||
console.log(resLogin);
|
||||
}
|
||||
|
@ -1,10 +1,11 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [ "dom", "es5", "es2015.promise" ],
|
||||
"lib": [ "dom", "es5", "es2015", "es2015.promise" ],
|
||||
"target": "es5",
|
||||
"experimentalDecorators": true,
|
||||
"skipLibCheck": true
|
||||
"skipLibCheck": true,
|
||||
"downlevelIteration": true
|
||||
},
|
||||
"exclude": [
|
||||
"node_modules",
|
||||
|
Loading…
x
Reference in New Issue
Block a user