增加hash icon

This commit is contained in:
cebgcontract 2022-06-21 12:59:07 +08:00
parent 98f299ce0d
commit 3e30c18d2f
16 changed files with 317 additions and 147 deletions

View File

@ -23,24 +23,24 @@
"__id__": 6
},
{
"__id__": 9
"__id__": 10
},
{
"__id__": 12
"__id__": 13
}
],
"_active": true,
"_level": 1,
"_components": [
{
"__id__": 15
"__id__": 16
},
{
"__id__": 16
"__id__": 17
}
],
"_prefab": {
"__id__": 17
"__id__": 18
},
"_opacity": 255,
"_color": {
@ -230,10 +230,13 @@
"_components": [
{
"__id__": 7
},
{
"__id__": 8
}
],
"_prefab": {
"__id__": 8
"__id__": 9
},
"_opacity": 255,
"_color": {
@ -250,13 +253,13 @@
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
"x": 0,
"y": 0
},
"_position": {
"__type__": "cc.Vec3",
"x": -181,
"y": 0,
"x": -200,
"y": -20,
"z": 0
},
"_scale": {
@ -280,31 +283,44 @@
"_id": ""
},
{
"__type__": "cc.Sprite",
"__type__": "c5608gXK6JJrLX5LYUMj20m",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 6
},
"_enabled": true,
"_srcBlendFactor": 770,
"_dstBlendFactor": 771,
"_spriteFrame": {
"__uuid__": "8cdb44ac-a3f6-449f-b354-7cd48cf84061"
"ctx": {
"__id__": 8
},
"_type": 0,
"_sizeMode": 0,
"_fillType": 0,
"_fillCenter": {
"__type__": "cc.Vec2",
"x": 0,
"y": 0
"_id": ""
},
{
"__type__": "cc.Graphics",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 6
},
"_fillStart": 0,
"_fillRange": 0,
"_isTrimmedMode": true,
"_state": 0,
"_atlas": null,
"_enabled": true,
"_lineWidth": 1,
"_strokeColor": {
"__type__": "cc.Color",
"r": 0,
"g": 0,
"b": 0,
"a": 255
},
"_lineJoin": 2,
"_lineCap": 0,
"_fillColor": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_miterLimit": 10,
"_id": ""
},
{
@ -330,11 +346,11 @@
"_level": 5,
"_components": [
{
"__id__": 10
"__id__": 11
}
],
"_prefab": {
"__id__": 11
"__id__": 12
},
"_opacity": 255,
"_color": {
@ -385,7 +401,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 9
"__id__": 10
},
"_enabled": true,
"_useOriginalSize": false,
@ -428,11 +444,11 @@
"_level": 5,
"_components": [
{
"__id__": 13
"__id__": 14
}
],
"_prefab": {
"__id__": 14
"__id__": 15
},
"_opacity": 255,
"_color": {
@ -483,7 +499,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 12
"__id__": 13
},
"_enabled": true,
"_useOriginalSize": false,
@ -551,10 +567,10 @@
},
"_enabled": true,
"symbolLabel": {
"__id__": 10
"__id__": 11
},
"countLabel": {
"__id__": 13
"__id__": 14
},
"icon": {
"__id__": 7

View File

@ -1,5 +1,5 @@
const {ccclass, property} = cc._decorator;
import TextBtn, { TEXTBTN_CLICKED } from "./TextBtn";
import TextBtn, { TEXTBTN_CLICKED } from "./comp/TextBtn";
import WalletBase from "./WallerBase";
export const BTN_SELECT_INDEX_CHANGE = 'btn_select_index_change'

View File

@ -1,7 +1,6 @@
import { ZError } from "../common/ZError";
import JCWallet from "../JCWallet";
import ButtonGroup, { BTN_SELECT_INDEX_CHANGE } from "./ButtonGroup";
import TextBtn from "./TextBtn";
import TextBtn from "./comp/TextBtn";
import WalletBase from "./WallerBase";
const {ccclass, property} = cc._decorator;

View File

@ -1,5 +1,6 @@
import { IToken } from "../data/DataModel";
import { renderFromTokenMinimalUnit } from "../util/number.util";
import HashIcon from "./comp/HashIcon";
import WalletBase from "./WallerBase";
const {ccclass, property} = cc._decorator;
@ -14,8 +15,8 @@ export default class OneToken extends WalletBase {
@property(cc.Label)
countLabel: cc.Label = null;
@property(cc.Sprite)
icon: cc.Sprite = null;
@property(HashIcon)
icon: HashIcon = null;
data: IToken = null
// LIFE-CYCLE CALLBACKS:
@ -38,6 +39,7 @@ export default class OneToken extends WalletBase {
} else {
// TODO: get from remote
}
this.icon.init(this.data.address)
if (this.data.decimal === undefined && this.data.type !== ETH_TYPE) {
// get from chain
this.wallet.erc20Standard.getTokenDecimals(this.data.address)

View File

@ -1,8 +1,7 @@
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";
import TextBtn from "./TextBtn";
import TextBtn from "./comp/TextBtn";
import WalletBase from "./WallerBase";
const {ccclass, property} = cc._decorator;

View File

@ -3,6 +3,7 @@ import { WALLET_CHAIN_CHANGE } from "../common/WalletEvent";
import { Bind } from "../decorator/AutoUpdateUI";
import JCWallet, { IChainData } from "../JCWallet";
import { renderFromTokenMinimalUnit } from "../util/number.util";
import HashIcon from "./comp/HashIcon";
import WalletBase from "./WallerBase";
@ -20,6 +21,9 @@ export default class WalletInfo extends WalletBase {
@property(cc.Node)
qrNode: cc.Node = null;
@property(HashIcon)
avatar: HashIcon = null;
accountId: string = '';
balance: string = ''
@ -41,6 +45,7 @@ export default class WalletInfo extends WalletBase {
super.updateUI()
this.addressLabel.string = this.formatAddress()
this.balanceLabel.string = this.formatMoney()
this.avatar.init(this.accountId)
}
formatAddress() {

View File

@ -0,0 +1,7 @@
{
"ver": "1.0.1",
"uuid": "3ca7afd5-e423-4e9f-a287-f334ccf18286",
"isSubpackage": false,
"subpackageName": "",
"subMetas": {}
}

View File

@ -0,0 +1,114 @@
const { ccclass, property } = cc._decorator;
const randseed = new Array(4); // Xorshift: [x, y, z, w] 32 bit values
function seedrand(seed) {
for (var i = 0; i < randseed.length; i++) {
randseed[i] = 0;
}
for (var i = 0; i < seed.length; i++) {
randseed[i % 4] =
(randseed[i % 4] << 5) - randseed[i % 4] + seed.charCodeAt(i);
}
}
function rand() {
// based on Java's String.hashCode(), expanded to 4 32bit values
const t = randseed[0] ^ (randseed[0] << 11);
randseed[0] = randseed[1];
randseed[1] = randseed[2];
randseed[2] = randseed[3];
randseed[3] = randseed[3] ^ (randseed[3] >> 19) ^ t ^ (t >> 8);
return (randseed[3] >>> 0) / ((1 << 31) >>> 0);
}
function createImageData(size) {
const width = size; // Only support square icons for now
const height = size;
const dataWidth = Math.ceil(width / 2);
const mirrorWidth = width - dataWidth;
const data = [];
for (let y = 0; y < height; y++) {
let row = [];
for (let x = 0; x < dataWidth; x++) {
// this makes foreground and background color to have a 43% (1/2.3) probability
// spot color has 13% chance
row[x] = Math.floor(rand() * 2.3);
}
const r = row.slice(0, mirrorWidth);
r.reverse();
row = row.concat(r);
for (let i = 0; i < row.length; i++) {
data.push(row[i]);
}
}
return data;
}
function createColor() {
const r = Math.floor(rand() * 255);
const g = Math.floor(rand() * 255);
const b = Math.floor(rand() * 255);
return new cc.Color(r, g, b, 255);
}
function buildOpts(opts) {
if (!opts.seed) {
throw new Error("No seed provided");
}
seedrand(opts.seed);
return Object.assign(
{
size: 8,
scale: 2,
color: createColor(),
bgcolor: createColor(),
spotcolor: createColor(),
},
opts
);
}
@ccclass
export default class HashIcon extends cc.Component {
@property(cc.Graphics)
ctx: cc.Graphics = null;
// onLoad () {}
start() {}
// update (dt) {}
init(address: string) {
const size = 8;
const scale = this.node.width / size;
const opts = buildOpts({ seed: address.toLowerCase(), size, scale });
const imageData = createImageData(opts.size);
const width = Math.sqrt(imageData.length);
for (let i = 0; i < imageData.length; i++) {
const row = Math.floor(i / width);
const col = i % width;
// if data is 0, leave the background
if (imageData[i]) {
// if data is 2, choose spot color, if 1 choose foreground
const pngColor = imageData[i] == 1 ? opts.color : opts.spotcolor;
this.ctx.fillColor = pngColor
this.ctx.fillRect(
col * opts.scale,
row * opts.scale,
opts.scale,
opts.scale
);
}
}
}
}

View File

@ -0,0 +1,9 @@
{
"ver": "1.0.5",
"uuid": "c5608817-2ba2-49ac-b5f9-2d850c8f6d26",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}

View File

@ -1,5 +1,5 @@
const {ccclass, property} = cc._decorator;
import { QR } from '../lib/qrcode';
import { QR } from '../../lib/qrcode';
@ccclass
export default class QRCodeComp extends cc.Component {

View File

@ -1,6 +1,6 @@
import { Watch } from "../decorator/AutoUpdateUI";
import WalletBase from "./WallerBase";
import { Watch } from "../../decorator/AutoUpdateUI";
import WalletBase from "../WallerBase";
const {ccclass, property} = cc._decorator;

View File

@ -17,7 +17,7 @@
"__id__": 2
},
{
"__id__": 215
"__id__": 216
}
],
"_active": false,
@ -44,8 +44,8 @@
},
"_scale": {
"__type__": "cc.Vec3",
"x": 0.625,
"y": 0.625,
"x": 0.780609130859375,
"y": 0.780609130859375,
"z": 1
},
"_quat": {
@ -86,14 +86,14 @@
"_active": true,
"_level": 1,
"_components": [
{
"__id__": 212
},
{
"__id__": 213
},
{
"__id__": 216
"__id__": 214
},
{
"__id__": 217
}
],
"_prefab": null,
@ -4647,20 +4647,20 @@
"__id__": 145
},
{
"__id__": 187
"__id__": 188
}
],
"_active": true,
"_level": 1,
"_components": [
{
"__id__": 209
},
{
"__id__": 210
},
{
"__id__": 211
},
{
"__id__": 212
}
],
"_prefab": null,
@ -6345,20 +6345,20 @@
"__id__": 172
},
{
"__id__": 174
"__id__": 175
},
{
"__id__": 176
"__id__": 177
}
],
"_active": true,
"_level": 2,
"_components": [
{
"__id__": 185
"__id__": 186
},
{
"__id__": 186
"__id__": 187
}
],
"_prefab": null,
@ -7554,6 +7554,9 @@
"_components": [
{
"__id__": 173
},
{
"__id__": 174
}
],
"_prefab": null,
@ -7572,13 +7575,13 @@
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
"x": 0,
"y": 0
},
"_position": {
"__type__": "cc.Vec3",
"x": -433,
"y": 75,
"x": -466,
"y": 53,
"z": 0
},
"_scale": {
@ -7602,32 +7605,45 @@
"_id": "5eQSFlHW9JNYYEPqu8C9ik"
},
{
"__type__": "cc.Sprite",
"__type__": "cc.Graphics",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 172
},
"_enabled": true,
"_srcBlendFactor": 770,
"_dstBlendFactor": 771,
"_spriteFrame": {
"__uuid__": "8cdb44ac-a3f6-449f-b354-7cd48cf84061"
"_lineWidth": 1,
"_strokeColor": {
"__type__": "cc.Color",
"r": 0,
"g": 0,
"b": 0,
"a": 255
},
"_type": 0,
"_sizeMode": 0,
"_fillType": 0,
"_fillCenter": {
"__type__": "cc.Vec2",
"x": 0,
"y": 0
"_lineJoin": 2,
"_lineCap": 0,
"_fillColor": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_fillStart": 0,
"_fillRange": 0,
"_isTrimmedMode": true,
"_state": 0,
"_atlas": null,
"_id": "b1a5xbMoFG94xONysJ30CI"
"_miterLimit": 10,
"_id": "c2JbC6RMJO9r2vLjaebqLU"
},
{
"__type__": "c5608gXK6JJrLX5LYUMj20m",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 172
},
"_enabled": true,
"ctx": {
"__id__": 173
},
"_id": "93to1VnftD2LgtNEbvXRbk"
},
{
"__type__": "cc.Node",
@ -7641,7 +7657,7 @@
"_level": 3,
"_components": [
{
"__id__": 175
"__id__": 176
}
],
"_prefab": null,
@ -7694,7 +7710,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 174
"__id__": 175
},
"_enabled": true,
"_useOriginalSize": false,
@ -7723,17 +7739,17 @@
},
"_children": [
{
"__id__": 177
"__id__": 178
},
{
"__id__": 182
"__id__": 183
}
],
"_active": false,
"_level": 3,
"_components": [
{
"__id__": 184
"__id__": 185
}
],
"_prefab": null,
@ -7786,20 +7802,20 @@
"_name": "New Sprite(Splash)",
"_objFlags": 0,
"_parent": {
"__id__": 176
"__id__": 177
},
"_children": [],
"_active": true,
"_level": 4,
"_components": [
{
"__id__": 178
},
{
"__id__": 179
},
{
"__id__": 180
},
{
"__id__": 181
}
],
"_prefab": null,
@ -7852,7 +7868,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 177
"__id__": 178
},
"_enabled": true,
"_srcBlendFactor": 770,
@ -7880,7 +7896,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 177
"__id__": 178
},
"_enabled": true,
"alignMode": 1,
@ -7907,14 +7923,14 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 177
"__id__": 178
},
"_enabled": true,
"duration": 0.1,
"zoomScale": 1.2,
"clickEvents": [
{
"__id__": 181
"__id__": 182
}
],
"_N$interactable": true,
@ -7987,14 +8003,14 @@
"_name": "qrImgNode",
"_objFlags": 0,
"_parent": {
"__id__": 176
"__id__": 177
},
"_children": [],
"_active": true,
"_level": 4,
"_components": [
{
"__id__": 183
"__id__": 184
}
],
"_prefab": null,
@ -8047,7 +8063,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 182
"__id__": 183
},
"_enabled": true,
"lightColor": {
@ -8071,7 +8087,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 176
"__id__": 177
},
"_enabled": true,
"alignMode": 1,
@ -8135,7 +8151,10 @@
"__id__": 151
},
"qrNode": {
"__id__": 176
"__id__": 177
},
"avatar": {
"__id__": 174
},
"_id": "8bO0XBvlFDPJ87FOgdOxUH"
},
@ -8148,35 +8167,35 @@
},
"_children": [
{
"__id__": 188
"__id__": 189
},
{
"__id__": 192
"__id__": 193
},
{
"__id__": 194
"__id__": 195
},
{
"__id__": 196
"__id__": 197
},
{
"__id__": 198
"__id__": 199
},
{
"__id__": 200
"__id__": 201
},
{
"__id__": 204
"__id__": 205
}
],
"_active": false,
"_level": 2,
"_components": [
{
"__id__": 207
"__id__": 208
},
{
"__id__": 208
"__id__": 209
}
],
"_prefab": null,
@ -8229,20 +8248,20 @@
"_name": "New Sprite(Splash)",
"_objFlags": 0,
"_parent": {
"__id__": 187
"__id__": 188
},
"_children": [],
"_active": true,
"_level": 3,
"_components": [
{
"__id__": 189
},
{
"__id__": 190
},
{
"__id__": 191
},
{
"__id__": 192
}
],
"_prefab": null,
@ -8295,7 +8314,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 188
"__id__": 189
},
"_enabled": true,
"_srcBlendFactor": 770,
@ -8323,7 +8342,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 188
"__id__": 189
},
"_enabled": true,
"alignMode": 1,
@ -8350,7 +8369,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 188
"__id__": 189
},
"_enabled": true,
"_id": "d5s8l9cvFDWo/fNwOpa2aV"
@ -8360,14 +8379,14 @@
"_name": "bg-blue",
"_objFlags": 0,
"_parent": {
"__id__": 187
"__id__": 188
},
"_children": [],
"_active": false,
"_level": 3,
"_components": [
{
"__id__": 193
"__id__": 194
}
],
"_prefab": null,
@ -8420,7 +8439,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 192
"__id__": 193
},
"_enabled": true,
"_srcBlendFactor": 770,
@ -8448,14 +8467,14 @@
"_name": "bar-black",
"_objFlags": 0,
"_parent": {
"__id__": 187
"__id__": 188
},
"_children": [],
"_active": true,
"_level": 3,
"_components": [
{
"__id__": 195
"__id__": 196
}
],
"_prefab": null,
@ -8508,7 +8527,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 194
"__id__": 195
},
"_enabled": true,
"_srcBlendFactor": 770,
@ -8536,14 +8555,14 @@
"_name": "bar-black",
"_objFlags": 0,
"_parent": {
"__id__": 187
"__id__": 188
},
"_children": [],
"_active": true,
"_level": 3,
"_components": [
{
"__id__": 197
"__id__": 198
}
],
"_prefab": null,
@ -8596,7 +8615,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 196
"__id__": 197
},
"_enabled": true,
"_srcBlendFactor": 770,
@ -8624,14 +8643,14 @@
"_name": "menuPanel",
"_objFlags": 0,
"_parent": {
"__id__": 187
"__id__": 188
},
"_children": [],
"_active": true,
"_level": 3,
"_components": [
{
"__id__": 199
"__id__": 200
}
],
"_prefab": null,
@ -8684,7 +8703,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 198
"__id__": 199
},
"_enabled": true,
"_srcBlendFactor": 770,
@ -8712,17 +8731,17 @@
"_name": "close",
"_objFlags": 0,
"_parent": {
"__id__": 187
"__id__": 188
},
"_children": [],
"_active": true,
"_level": 3,
"_components": [
{
"__id__": 201
"__id__": 202
},
{
"__id__": 202
"__id__": 203
}
],
"_prefab": null,
@ -8775,7 +8794,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 200
"__id__": 201
},
"_enabled": true,
"_srcBlendFactor": 770,
@ -8803,14 +8822,14 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 200
"__id__": 201
},
"_enabled": true,
"duration": 0.1,
"zoomScale": 1.2,
"clickEvents": [
{
"__id__": 203
"__id__": 204
}
],
"_N$interactable": true,
@ -8871,7 +8890,7 @@
{
"__type__": "cc.ClickEvent",
"target": {
"__id__": 187
"__id__": 188
},
"component": "",
"_componentId": "f2e85abZ1NDc58oBSrPm057",
@ -8883,17 +8902,17 @@
"_name": "contentNode",
"_objFlags": 0,
"_parent": {
"__id__": 187
"__id__": 188
},
"_children": [],
"_active": true,
"_level": 3,
"_components": [
{
"__id__": 205
"__id__": 206
},
{
"__id__": 206
"__id__": 207
}
],
"_prefab": null,
@ -8946,7 +8965,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 204
"__id__": 205
},
"_enabled": true,
"_srcBlendFactor": 770,
@ -8974,7 +8993,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 204
"__id__": 205
},
"_enabled": true,
"_layoutSize": {
@ -9007,7 +9026,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 187
"__id__": 188
},
"_enabled": true,
"alignMode": 1,
@ -9034,14 +9053,14 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 187
"__id__": 188
},
"_enabled": true,
"btnPreb": {
"__uuid__": "edefc8c1-62a6-49f9-8610-13865e5b0e32"
},
"contentNode": {
"__id__": 204
"__id__": 205
},
"icons": [
{
@ -9135,7 +9154,7 @@
"__id__": 143
},
"menuPanel": {
"__id__": 187
"__id__": 188
},
"_id": "a8YbO7l9lF95gWk3JRycGs"
},
@ -9165,7 +9184,7 @@
},
"_enabled": true,
"webview": {
"__id__": 214
"__id__": 215
},
"debugText": {
"__id__": 6
@ -9178,7 +9197,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 215
"__id__": 216
},
"_enabled": true,
"_useOriginalSize": false,
@ -9198,7 +9217,7 @@
"_level": 1,
"_components": [
{
"__id__": 214
"__id__": 215
}
],
"_prefab": null,