增加切换列表功能

This commit is contained in:
cebgcontract 2022-06-19 15:03:30 +08:00
parent 05356feb23
commit e38ab3e150
28 changed files with 1730 additions and 1866 deletions

View File

@ -0,0 +1,534 @@
[
{
"__type__": "cc.Prefab",
"_name": "",
"_objFlags": 0,
"_native": "",
"data": {
"__id__": 1
},
"optimizationPolicy": 0,
"asyncLoadAssets": false
},
{
"__type__": "cc.Node",
"_name": "NftList",
"_objFlags": 0,
"_parent": null,
"_children": [
{
"__id__": 2
}
],
"_active": true,
"_level": 1,
"_components": [
{
"__id__": 13
},
{
"__id__": 14
},
{
"__id__": 15
}
],
"_prefab": {
"__id__": 16
},
"_opacity": 255,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_contentSize": {
"__type__": "cc.Size",
"width": 450,
"height": 400
},
"_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.Node",
"_name": "content",
"_objFlags": 0,
"_parent": {
"__id__": 1
},
"_children": [
{
"__id__": 3
}
],
"_active": true,
"_level": 3,
"_components": [
{
"__id__": 11
}
],
"_prefab": {
"__id__": 12
},
"_opacity": 255,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_contentSize": {
"__type__": "cc.Size",
"width": 450,
"height": 120
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 1
},
"_position": {
"__type__": "cc.Vec3",
"x": 0,
"y": 200,
"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": "OneNFT",
"_objFlags": 0,
"_parent": {
"__id__": 2
},
"_children": [
{
"__id__": 4
},
{
"__id__": 7
}
],
"_active": true,
"_level": 4,
"_components": [],
"_prefab": {
"__id__": 10
},
"_opacity": 255,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_contentSize": {
"__type__": "cc.Size",
"width": 100,
"height": 120
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_position": {
"__type__": "cc.Vec3",
"x": -175,
"y": -60,
"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": "New Sprite",
"_objFlags": 0,
"_parent": {
"__id__": 3
},
"_children": [],
"_active": true,
"_level": 5,
"_components": [
{
"__id__": 5
}
],
"_prefab": {
"__id__": 6
},
"_opacity": 255,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_contentSize": {
"__type__": "cc.Size",
"width": 100,
"height": 100
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_position": {
"__type__": "cc.Vec3",
"x": 0,
"y": 10,
"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.Sprite",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 4
},
"_enabled": true,
"_srcBlendFactor": 770,
"_dstBlendFactor": 771,
"_spriteFrame": {
"__uuid__": "8cdb44ac-a3f6-449f-b354-7cd48cf84061"
},
"_type": 0,
"_sizeMode": 0,
"_fillType": 0,
"_fillCenter": {
"__type__": "cc.Vec2",
"x": 0,
"y": 0
},
"_fillStart": 0,
"_fillRange": 0,
"_isTrimmedMode": true,
"_state": 0,
"_atlas": null,
"_id": ""
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"asset": {
"__uuid__": "e64be85b-3d9f-4109-8e7d-48847666bf2c"
},
"fileId": "d60oW7FvtHeYQMK3B9YDtO",
"sync": false
},
{
"__type__": "cc.Node",
"_name": "idLabel",
"_objFlags": 0,
"_parent": {
"__id__": 3
},
"_children": [],
"_active": true,
"_level": 5,
"_components": [
{
"__id__": 8
}
],
"_prefab": {
"__id__": 9
},
"_opacity": 255,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_contentSize": {
"__type__": "cc.Size",
"width": 48.94,
"height": 40
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0,
"y": 0.5
},
"_position": {
"__type__": "cc.Vec3",
"x": -50,
"y": -45,
"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__": 7
},
"_enabled": true,
"_useOriginalSize": false,
"_string": "Label",
"_N$string": "Label",
"_fontSize": 20,
"_lineHeight": 40,
"_enableWrapText": true,
"_N$file": null,
"_isSystemFontUsed": true,
"_spacingX": 0,
"_batchAsBitmap": false,
"_N$horizontalAlign": 0,
"_N$verticalAlign": 1,
"_N$fontFamily": "Arial",
"_N$overflow": 0,
"_N$cacheMode": 0,
"_id": ""
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"asset": {
"__uuid__": "e64be85b-3d9f-4109-8e7d-48847666bf2c"
},
"fileId": "fdPjhkyMBEwZHA5g8nn6Bd",
"sync": false
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"asset": {
"__uuid__": "e64be85b-3d9f-4109-8e7d-48847666bf2c"
},
"fileId": "d8aF0PaVNDOojtyTIMdXbp",
"sync": false
},
{
"__type__": "cc.Layout",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 2
},
"_enabled": true,
"_layoutSize": {
"__type__": "cc.Size",
"width": 450,
"height": 120
},
"_resize": 1,
"_N$layoutType": 3,
"_N$padding": 0,
"_N$cellSize": {
"__type__": "cc.Size",
"width": 40,
"height": 40
},
"_N$startAxis": 0,
"_N$paddingLeft": 0,
"_N$paddingRight": 0,
"_N$paddingTop": 0,
"_N$paddingBottom": 0,
"_N$spacingX": 10,
"_N$spacingY": 10,
"_N$verticalDirection": 1,
"_N$horizontalDirection": 0,
"_N$affectedByScale": false,
"_id": ""
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"asset": {
"__uuid__": "e64be85b-3d9f-4109-8e7d-48847666bf2c"
},
"fileId": "6e2xzjh/1GC5AU8a/D8Qwk",
"sync": false
},
{
"__type__": "cc.ScrollView",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 1
},
"_enabled": true,
"horizontal": false,
"vertical": true,
"inertia": true,
"brake": 0.5,
"elastic": true,
"bounceDuration": 1,
"scrollEvents": [],
"cancelInnerEvents": true,
"_N$content": {
"__id__": 2
},
"content": {
"__id__": 2
},
"_id": ""
},
{
"__type__": "cc.Mask",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 1
},
"_enabled": true,
"_spriteFrame": null,
"_type": 0,
"_segments": 64,
"_N$alphaThreshold": 0,
"_N$inverted": false,
"_id": ""
},
{
"__type__": "d8e744LBIpBeKlOm9Kvb6W7",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 1
},
"_enabled": true,
"tokenPreb": {
"__uuid__": "259e752f-837f-4d16-b21f-3c886e3a7a7e"
},
"contentNode": {
"__id__": 2
},
"_id": ""
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"asset": {
"__uuid__": "e64be85b-3d9f-4109-8e7d-48847666bf2c"
},
"fileId": "edJmq9HR5CfZdb8CAuqySi",
"sync": false
}
]

View File

@ -0,0 +1,7 @@
{
"ver": "1.0.1",
"uuid": "e64be85b-3d9f-4109-8e7d-48847666bf2c",
"optimizationPolicy": "AUTO",
"asyncLoadAssets": false,
"subMetas": {}
}

View File

@ -0,0 +1,286 @@
[
{
"__type__": "cc.Prefab",
"_name": "",
"_objFlags": 0,
"_native": "",
"data": {
"__id__": 1
},
"optimizationPolicy": 0,
"asyncLoadAssets": false
},
{
"__type__": "cc.Node",
"_name": "OneNFT",
"_objFlags": 0,
"_parent": null,
"_children": [
{
"__id__": 2
},
{
"__id__": 5
}
],
"_active": true,
"_level": 4,
"_components": [],
"_prefab": {
"__id__": 8
},
"_opacity": 255,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_contentSize": {
"__type__": "cc.Size",
"width": 100,
"height": 120
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_position": {
"__type__": "cc.Vec3",
"x": -175,
"y": -60,
"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": "New Sprite",
"_objFlags": 0,
"_parent": {
"__id__": 1
},
"_children": [],
"_active": true,
"_level": 5,
"_components": [
{
"__id__": 3
}
],
"_prefab": {
"__id__": 4
},
"_opacity": 255,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_contentSize": {
"__type__": "cc.Size",
"width": 100,
"height": 100
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_position": {
"__type__": "cc.Vec3",
"x": 0,
"y": 10,
"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.Sprite",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 2
},
"_enabled": true,
"_srcBlendFactor": 770,
"_dstBlendFactor": 771,
"_spriteFrame": {
"__uuid__": "8cdb44ac-a3f6-449f-b354-7cd48cf84061"
},
"_type": 0,
"_sizeMode": 0,
"_fillType": 0,
"_fillCenter": {
"__type__": "cc.Vec2",
"x": 0,
"y": 0
},
"_fillStart": 0,
"_fillRange": 0,
"_isTrimmedMode": true,
"_state": 0,
"_atlas": null,
"_id": ""
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"asset": {
"__id__": 0
},
"fileId": "d60oW7FvtHeYQMK3B9YDtO",
"sync": false
},
{
"__type__": "cc.Node",
"_name": "idLabel",
"_objFlags": 0,
"_parent": {
"__id__": 1
},
"_children": [],
"_active": true,
"_level": 5,
"_components": [
{
"__id__": 6
}
],
"_prefab": {
"__id__": 7
},
"_opacity": 255,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_contentSize": {
"__type__": "cc.Size",
"width": 48.94,
"height": 40
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0,
"y": 0.5
},
"_position": {
"__type__": "cc.Vec3",
"x": -50,
"y": -45,
"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__": 5
},
"_enabled": true,
"_useOriginalSize": false,
"_string": "Label",
"_N$string": "Label",
"_fontSize": 20,
"_lineHeight": 40,
"_enableWrapText": true,
"_N$file": null,
"_isSystemFontUsed": true,
"_spacingX": 0,
"_batchAsBitmap": false,
"_N$horizontalAlign": 0,
"_N$verticalAlign": 1,
"_N$fontFamily": "Arial",
"_N$overflow": 0,
"_N$cacheMode": 0,
"_id": ""
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"asset": {
"__id__": 0
},
"fileId": "fdPjhkyMBEwZHA5g8nn6Bd",
"sync": false
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"asset": {
"__id__": 0
},
"fileId": "d8aF0PaVNDOojtyTIMdXbp",
"sync": false
}
]

View File

@ -0,0 +1,7 @@
{
"ver": "1.0.1",
"uuid": "259e752f-837f-4d16-b21f-3c886e3a7a7e",
"optimizationPolicy": "AUTO",
"asyncLoadAssets": false,
"subMetas": {}
}

View File

@ -27,14 +27,17 @@
} }
], ],
"_active": true, "_active": true,
"_level": 4, "_level": 1,
"_components": [ "_components": [
{ {
"__id__": 11 "__id__": 11
},
{
"__id__": 12
} }
], ],
"_prefab": { "_prefab": {
"__id__": 12 "__id__": 13
}, },
"_opacity": 255, "_opacity": 255,
"_color": { "_color": {
@ -176,7 +179,7 @@
"__id__": 1 "__id__": 1
}, },
"asset": { "asset": {
"__id__": 0 "__uuid__": "e4b00542-5961-4a6a-8ae5-c19d30ac84a2"
}, },
"fileId": "1a8x2zZmNOU6glyFKwUfHp", "fileId": "1a8x2zZmNOU6glyFKwUfHp",
"sync": false "sync": false
@ -274,7 +277,7 @@
"__id__": 1 "__id__": 1
}, },
"asset": { "asset": {
"__id__": 0 "__uuid__": "e4b00542-5961-4a6a-8ae5-c19d30ac84a2"
}, },
"fileId": "7efChFqAdDMrznOWA5RJF0", "fileId": "7efChFqAdDMrznOWA5RJF0",
"sync": false "sync": false
@ -372,7 +375,7 @@
"__id__": 1 "__id__": 1
}, },
"asset": { "asset": {
"__id__": 0 "__uuid__": "e4b00542-5961-4a6a-8ae5-c19d30ac84a2"
}, },
"fileId": "65w39W/ddIsLb50QRubYhg", "fileId": "65w39W/ddIsLb50QRubYhg",
"sync": false "sync": false
@ -405,13 +408,32 @@
"_atlas": null, "_atlas": null,
"_id": "" "_id": ""
}, },
{
"__type__": "6b4b9CWT+hI3JIHIxZt7fsM",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 1
},
"_enabled": true,
"symbolLabel": {
"__id__": 6
},
"countLabel": {
"__id__": 9
},
"icon": {
"__id__": 3
},
"_id": ""
},
{ {
"__type__": "cc.PrefabInfo", "__type__": "cc.PrefabInfo",
"root": { "root": {
"__id__": 1 "__id__": 1
}, },
"asset": { "asset": {
"__id__": 0 "__uuid__": "e4b00542-5961-4a6a-8ae5-c19d30ac84a2"
}, },
"fileId": "adoQSiLjZG56t5GXVWQvlL", "fileId": "adoQSiLjZG56t5GXVWQvlL",
"sync": false "sync": false

View File

@ -4,9 +4,11 @@ import sth = require("./lib/ethSigUtil");
import('./lib/fetch'); import('./lib/fetch');
import { ZError } from "./common/ZError"; import { ZError } from "./common/ZError";
import { AllChains } from "./data/allchain"; import { AllChains } from "./data/allchain";
import { createWalletEvents, WALLET_CHAIN_CHANGE } from "./common/WalletEvent"; import { createWalletEvents, WALLET_CHAIN_CHANGE, WALLET_TOKEN_TYPE_CHANGE } from "./common/WalletEvent";
import { ERC20Standard } from "./standards/ERC20Standard"; import { ERC20Standard } from "./standards/ERC20Standard";
import { ERC721Standard } from "./standards/ERC721Standard"; import { ERC721Standard } from "./standards/ERC721Standard";
import { IAccount, initAccount } from "./data/DataModel";
import { DataManage } from "./manage/DataManage";
var global = var global =
(typeof globalThis !== 'undefined' && globalThis) || (typeof globalThis !== 'undefined' && globalThis) ||
@ -42,6 +44,8 @@ export default class JCWallet {
public erc20Standard: ERC20Standard public erc20Standard: ERC20Standard
public erc721Standard: ERC721Standard public erc721Standard: ERC721Standard
public mainHandlers = createWalletEvents() public mainHandlers = createWalletEvents()
private dataManage = new DataManage()
public data: IAccount[] = []
constructor() { constructor() {
this.web3 = new Web3('https://rpc-testnet.kcc.network') this.web3 = new Web3('https://rpc-testnet.kcc.network')
@ -55,6 +59,7 @@ export default class JCWallet {
this.web3.eth.accounts.wallet.save(this.password); this.web3.eth.accounts.wallet.save(this.password);
} }
window.jc = window.jc || {wallet: this}; window.jc = window.jc || {wallet: this};
this.data = this.dataManage.loadData()
} }
public init({chains}: {chains: number[]}) { public init({chains}: {chains: number[]}) {
@ -76,11 +81,27 @@ export default class JCWallet {
return this._currentChain return this._currentChain
} }
get currentAccountData() {
let address = this.currentAccount().address;
const chain = this.currentChain.id
let data = this.data.find(o => o.address === address && o.chain === chain)
if (data) {
return data
}
data = initAccount(address, chain)
return data
}
updateCurrentChain(chainId: number) { updateCurrentChain(chainId: number) {
const chainData = this.chainMap.get(chainId) const chainData = this.chainMap.get(chainId)
this._currentChain = chainData this._currentChain = chainData
this.web3.eth.setProvider(chainData.rpc) this.web3.eth.setProvider(chainData.rpc)
this.mainHandlers.emit(WALLET_CHAIN_CHANGE, chainData) this.mainHandlers.emit(WALLET_CHAIN_CHANGE, chainData)
this.updateListType('tokens')
}
updateListType(type: string) {
this.mainHandlers.emit(WALLET_TOKEN_TYPE_CHANGE, type)
} }
get chainList() { get chainList() {

View File

@ -18,3 +18,5 @@ let createWalletEvents = () => ({
export { createWalletEvents } export { createWalletEvents }
export const WALLET_CHAIN_CHANGE = 'wallet_chain_change' export const WALLET_CHAIN_CHANGE = 'wallet_chain_change'
export const WALLET_TOKEN_TYPE_CHANGE = 'wallet_token_type_change'

View File

@ -0,0 +1,7 @@
{
"ver": "1.0.1",
"uuid": "172fb670-118a-47d0-889f-9b8ffc5bd786",
"isSubpackage": false,
"subpackageName": "",
"subMetas": {}
}

View File

@ -0,0 +1,71 @@
export const DEFALUT_TOKENS = {
321: [
{
type: 'eth',
address: 'eth',
symbol: 'KCS',
decimal: 18
},
{
type: 'erc20',
address: '0xcaA011E902103752435AC98657B046B282E36509',
symbol: 'CEC',
decimal: 18
},
{
type: 'erc20',
address: '0xBE023C9D294A4668f0d510E2570CB81B4536cE77',
symbol: 'CEG',
decimal: 18
}
],
322: [
{
type: 'eth',
address: 'eth',
symbol: 'tKCS',
decimal: 18
},
{
type: 'erc20',
address: '0xdb6D4bB22E2C12686Efff25a79EC78f9f078fe7D',
symbol: 'CEC',
decimal: 18
},
{
type: 'erc20',
address: '0xC5Cd606b3e9B80b758e8274B198c76D929aA094A',
symbol: 'CEG',
decimal: 18
}
],
97: [
{
type: 'eth',
address: 'eth',
symbol: 'BNB',
decimal: 18
}
],
56: [
{
type: 'eth',
address: 'eth',
symbol: 'BNB',
decimal: 18
}
]
}
export const DEFAULT_NFT_TYPES = {
321: {
hero: '0x0EB362BD40F2288fF25A6Ee1b487cB0cb4638e0D',
weapon: '0x29F67A372AC1c6AcF478A564992D421FE20F2cc8',
chip: '0x54B6ED7EDe9355b471985439421Aa1DC7Da6Dc20'
},
322: {
hero: '0x52917087cd4E48bDb5f336012E677f471f9E1C2D',
weapon: '0x500AD8A4D50d71Af5cA8eA3b12B914f7aE5466f7',
chip: '0x0640958BDb4D7956e1452FacEBD550C6Cf42aC94'
}
}

View File

@ -0,0 +1,9 @@
{
"ver": "1.0.5",
"uuid": "cfb5ceb5-31ef-4881-b740-3d50b184247d",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}

View File

@ -0,0 +1,43 @@
export interface IToken {
address: string
type: 'eth'|'erc20'
default: boolean
symbol?: string
balance?: number
decimal: number
image?: string
last?: number
}
export interface INFT {
address: string
tokenId: string
image?: string
name?: string
desc?: string
last?: number
}
export interface IAccount {
address: string
chain: number
nickname?: string
avatar?: string
tokens: IToken[]
heros: INFT[]
weapons: INFT[]
chips: INFT[]
}
export function initAccount(address: string, chain: number): IAccount {
let data: IAccount = {
address,
chain,
tokens: [],
heros: [],
weapons: [],
chips: []
}
//TODO: add default tokens
return data
}

View File

@ -0,0 +1,9 @@
{
"ver": "1.0.5",
"uuid": "26cf8ea3-578a-449c-a7c3-f68f517f7399",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}

View File

@ -1,12 +1,9 @@
export function GET(url: string) { import('./fetch')
return new Promise((resolve, reject) => {
let xhr = new XMLHttpRequest(); export async function GET(url: string) {
xhr.onreadystatechange = function () { return fetch(url)
if (xhr.readyState == 4 && (xhr.status >= 200 && xhr.status < 400)) { }
resolve && resolve(xhr.responseText);
} export async function GET_JSON(url: string) {
}; return fetch(url).then(res => {return res.json()})
xhr.open("GET", url, true);
xhr.send();
})
} }

View File

@ -0,0 +1,7 @@
{
"ver": "1.0.1",
"uuid": "50e7e584-3477-4c9f-88a6-c5db79e582ad",
"isSubpackage": false,
"subpackageName": "",
"subMetas": {}
}

View File

@ -0,0 +1,24 @@
import { IAccount } from "../data/DataModel";
import { singleton } from "../decorator/singleton.decorator";
const LOCAL_ACCOUNT_DATAS = 'local_account_datas'
@singleton
export class DataManage{
public loadData(){
const dataStr = localStorage.getItem(LOCAL_ACCOUNT_DATAS)
let result: IAccount[] = []
if (dataStr) {
try {
result = JSON.parse(dataStr)
} catch (err) {
console.log('load local data error')
}
}
return result
}
public saveData(datas: IAccount[]) {
const dataStr = JSON.stringify(datas)
localStorage.setItem(LOCAL_ACCOUNT_DATAS, dataStr)
}
}

View File

@ -0,0 +1,9 @@
{
"ver": "1.0.5",
"uuid": "839e90e9-67f8-4e33-b7fb-fd23fcd31938",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}

View File

@ -0,0 +1,58 @@
import { WALLET_TOKEN_TYPE_CHANGE } from "../common/WalletEvent";
import { ZError } from "../common/ZError";
import { DEFAULT_NFT_TYPES } from "../config/chain_config";
import WalletBase from "./WallerBase";
const {ccclass, property} = cc._decorator;
@ccclass
export default class ListNode extends WalletBase {
@property(cc.Prefab)
nftListPreb: cc.Prefab = null
@property(cc.Node)
tokenNode: cc.Node = null
otherNode: Map<string, cc.Node> = new Map()
// LIFE-CYCLE CALLBACKS:
// onLoad () {}
start () {
super.start()
this.wallet.mainHandlers.on(WALLET_TOKEN_TYPE_CHANGE, this.onTokenTypeChange.bind(this))
}
// update (dt) {}
initOneNftList(type: string) {
if (this.otherNode.has(type)) {
return this.otherNode.get(type)
}
const chain = this.wallet.currentChain.id
let nftData: any = DEFAULT_NFT_TYPES[chain]
if (!nftData) {
throw new ZError(10, 'no nft data found')
}
let node = cc.instantiate(this.nftListPreb)
node.active = false
node.getComponent('NftList').address = nftData[type]
this.node.addChild(node)
this.otherNode.set(type, node)
return node
}
onTokenTypeChange(type: string) {
console.log('on token type change: ', type)
for (let key of this.otherNode.keys()) {
this.otherNode.get(key).active = key === type
}
if (type === 'tokens') {
this.tokenNode.active = true
this.tokenNode.getComponent('TokenList').updateList()
} else {
this.tokenNode.active = false
this.initOneNftList(type).active = true
}
}
}

View File

@ -0,0 +1,9 @@
{
"ver": "1.0.5",
"uuid": "7646c450-7ab1-45be-9aff-cd98a567ce0e",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}

View File

@ -5,11 +5,13 @@ const {ccclass, property} = cc._decorator;
@ccclass @ccclass
export default class NftList extends WalletBase { export default class NftList extends WalletBase {
@property(cc.Label) @property(cc.Prefab)
label: cc.Label = null; tokenPreb: cc.Prefab = null
@property @property(cc.Node)
text: string = 'hello'; contentNode: cc.Node = null
public address: string = ''
// LIFE-CYCLE CALLBACKS: // LIFE-CYCLE CALLBACKS:

View File

@ -0,0 +1,26 @@
import { INFT } from "../data/DataModel";
import WalletBase from "./WallerBase";
const {ccclass, property} = cc._decorator;
@ccclass
export default class OneNFT extends WalletBase {
@property(cc.Label)
nftIDlabel: cc.Label = null;
@property(cc.Sprite)
icon: cc.Sprite = null;
data: INFT = null
// LIFE-CYCLE CALLBACKS:
// onLoad () {}
start () {
}
// update (dt) {}
}

View File

@ -0,0 +1,9 @@
{
"ver": "1.0.5",
"uuid": "bb92d263-508f-4bc8-a9a8-324c8bf51f0e",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}

View File

@ -0,0 +1,43 @@
import { IToken } from "../data/DataModel";
import WalletBase from "./WallerBase";
const {ccclass, property} = cc._decorator;
@ccclass
export default class OneToken extends WalletBase {
@property(cc.Label)
symbolLabel: cc.Label = null;
@property(cc.Label)
countLabel: cc.Label = null;
@property(cc.Sprite)
icon: cc.Sprite = null;
data: IToken = null
// LIFE-CYCLE CALLBACKS:
// onLoad () {}
start () {
}
// update (dt) {}
init(_data: IToken) {
this.data = _data
if (this.data.symbol) {
this.symbolLabel.string = this.data.symbol
} else {
// TODO: get from remote
}
if (this.data.balance !== undefined) {
this.countLabel.string = this.data.balance + ''
} else {
this.countLabel.string = '-'
//TODO: get from remote
}
}
}

View File

@ -0,0 +1,9 @@
{
"ver": "1.0.5",
"uuid": "6b4b9096-4fe8-48dc-9207-23166dedfb0c",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}

View File

@ -1,21 +1,54 @@
import { DEFALUT_TOKENS } from "../config/chain_config";
import { IToken } from "../data/DataModel";
import WalletBase from "./WallerBase";
const {ccclass, property} = cc._decorator; const {ccclass, property} = cc._decorator;
@ccclass @ccclass
export default class TokenList extends cc.Component { export default class TokenList extends WalletBase {
@property(cc.Label) @property(cc.Prefab)
label: cc.Label = null; tokenPreb: cc.Prefab = null
@property @property(cc.Node)
text: string = 'hello'; contentNode: cc.Node = null
// LIFE-CYCLE CALLBACKS: // LIFE-CYCLE CALLBACKS:
// onLoad () {} // onLoad () {}
start () { start () {
super.start()
this.updateList()
} }
// update (dt) {} // 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)
}
} }

View File

@ -1,3 +1,4 @@
import { DEFAULT_NFT_TYPES } from "../config/chain_config";
import JCWallet from "../JCWallet"; import JCWallet from "../JCWallet";
import ButtonGroup, { BTN_SELECT_INDEX_CHANGE } from "./ButtonGroup"; import ButtonGroup, { BTN_SELECT_INDEX_CHANGE } from "./ButtonGroup";
import TextBtn from "./TextBtn"; import TextBtn from "./TextBtn";
@ -21,7 +22,7 @@ export default class TokenTab extends WalletBase {
// LIFE-CYCLE CALLBACKS: // LIFE-CYCLE CALLBACKS:
// onLoad () {} // onLoad () {}
private titles = ['Tokens', 'Hero', 'Weapon', 'Chip'] private titles = ['tokens']
start () { start () {
super.start() super.start()
@ -37,7 +38,15 @@ export default class TokenTab extends WalletBase {
// update (dt) {} // update (dt) {}
showAllBtn() { showAllBtn() {
console.log('show all token tab') this.titles.length = 1
const chain = this.wallet.currentChain.id
let nftData: any = DEFAULT_NFT_TYPES[chain]
if (nftData) {
for (let key in nftData) {
this.titles.push(key)
}
}
console.log('show all token tab: ', this.titles)
for (let i = 0, l = this.titles.length; i < l; i++) { for (let i = 0, l = this.titles.length; i < l; i++) {
const btn = cc.instantiate(this.btnPreb) const btn = cc.instantiate(this.btnPreb)
const btnM: TextBtn = btn.getComponent(TextBtn) const btnM: TextBtn = btn.getComponent(TextBtn)
@ -50,5 +59,7 @@ export default class TokenTab extends WalletBase {
onTokenTypeChange(data: {index: number}) { onTokenTypeChange(data: {index: number}) {
console.log('on token change: ', JSON.stringify(data)) console.log('on token change: ', JSON.stringify(data))
let type = this.titles[data.index]
this.wallet.updateListType(type)
} }
} }

View File

@ -1,5 +1,6 @@
import JCWallet from "../JCWallet"; import JCWallet from "../JCWallet";
import ChainTab from "./ChainTab"; import ChainTab from "./ChainTab";
import ListNode from "./ListNode";
import WalletBase from "./WallerBase"; import WalletBase from "./WallerBase";
const {ccclass, property} = cc._decorator; const {ccclass, property} = cc._decorator;
@ -12,6 +13,11 @@ export default class WalletMainPanel extends WalletBase {
}) })
chainTab: ChainTab = null chainTab: ChainTab = null
@property({
type: ListNode
})
listNode: ListNode = null
// LIFE-CYCLE CALLBACKS: // LIFE-CYCLE CALLBACKS:
// onLoad () {} // onLoad () {}

File diff suppressed because it is too large Load Diff

View File

@ -2,7 +2,7 @@ import { WALLET_CHAIN_CHANGE } from "../../comp/wallet/scripts/common/WalletEven
import JCWallet, { IChainData } from "../../comp/wallet/scripts/JCWallet"; import JCWallet, { IChainData } from "../../comp/wallet/scripts/JCWallet";
import sth = require("../../comp/wallet/scripts/lib/ethSigUtil"); import sth = require("../../comp/wallet/scripts/lib/ethSigUtil");
import('../../comp/wallet/scripts/lib/fetch'); import('../../comp/wallet/scripts/lib/fetch');
import { GET } from "../../comp/wallet/scripts/lib/Http"; import { GET, GET_JSON } from "../../comp/wallet/scripts/lib/Http";
import { renderFromTokenMinimalUnit, renderFromWei } from "../../comp/wallet/scripts/util/number.util"; import { renderFromTokenMinimalUnit, renderFromWei } from "../../comp/wallet/scripts/util/number.util";
const {ccclass, property} = cc._decorator; const {ccclass, property} = cc._decorator;
@ -53,11 +53,9 @@ export default class WalletController extends cc.Component {
let account = this.wallet.currentAccount() let account = this.wallet.currentAccount()
let nonceUrlBase = this.apiBase + '/webapp/index.php?c=Market&a=getNonce' let nonceUrlBase = this.apiBase + '/webapp/index.php?c=Market&a=getNonce'
let nonceUrl = `${nonceUrlBase}&account=${account.address}&net_id=322` let nonceUrl = `${nonceUrlBase}&account=${account.address}&net_id=322`
let res = await GET(nonceUrl); let obj: any = await GET_JSON(nonceUrl);
let obj: any = {}
obj = JSON.parse(res as string);
const nonce = obj.nonce; const nonce = obj.nonce;
console.log(res); console.log(obj);
const tips:string = 'signrequest' const tips:string = 'signrequest'
const signMsg = { const signMsg = {
tips, tips,
@ -89,7 +87,7 @@ export default class WalletController extends cc.Component {
console.log(`is same: ${account.address.toLowerCase() == resultAddress}`) console.log(`is same: ${account.address.toLowerCase() == resultAddress}`)
let loginUrlBase = this.apiBase + '/webapp/index.php?c=Market&a=auth' let loginUrlBase = this.apiBase + '/webapp/index.php?c=Market&a=auth'
let loginUrl = `${loginUrlBase}&account=${account.address}&nonce=${nonce}&signature=${result}&tips=${tips.replace(/\ /g, '+')}&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); let resLogin = await GET_JSON(loginUrl);
console.log(resLogin); console.log(resLogin);
} }