Files
18xchat/assets/Scripts/chat18x/ui/panels/Web3PopPanel.ts
T

207 lines
5.9 KiB
TypeScript
Raw Normal View History

2025-09-18 14:06:53 +08:00
import { _decorator, Component, Label, Node, Sprite, Vec3 } from "cc";
import li_BaseView from "../../../Main/Common/li_BaseView";
import Utils from "../../../Main/Common/Utils";
import { GButton } from "../../../Main/Common/GButton";
2025-09-18 22:27:02 +08:00
import { DataId, DataManager } from "../../data/DataManager";
import { OrderData } from "../../data/OrderData";
import proto from "db://assets/Scripts/proto/proto.pb.js";
import ResManager from "../../../Main/Manager/ResManager";
import { PurchasePanel } from "./PurchasePanel";
2025-09-18 23:33:06 +08:00
import { QRCodeGenerator } from "db://assets/utils/qrcodeGenerator";
import { TipsPanel } from "./TipsPanel";
import { SDKManager } from "../../../Main/Channel/SDKManager";
2025-09-19 11:10:20 +08:00
import LanguageUtils from "../../../Main/Common/LanguageUtils";
2025-09-18 22:27:02 +08:00
2025-09-18 14:06:53 +08:00
const { ccclass, property } = _decorator;
@ccclass("Web3PopPanel")
export class Web3PopPanel extends li_BaseView {
private _nodeTab: any = {};
2025-09-18 22:27:02 +08:00
private amount: Label;
2025-09-18 14:06:53 +08:00
private coinIcon: Sprite;
private coinText: Label;
2025-09-18 22:27:02 +08:00
private address: Label;
private expireTimeText: Label;
2025-09-18 14:06:53 +08:00
private selection: Node;
2025-09-18 23:33:06 +08:00
private qrCode: Sprite;
2025-09-18 22:27:02 +08:00
private curType: proto.cs.EnmNetworkType;
private orderId;
private payType;
private networkType: proto.cs.EnmNetworkType;
private goodId: number;
private base: PurchasePanel;
openUIDataCT(data: any): void {
this.refreshData(data);
this.base.web3PopPanel = this;
}
2025-09-18 14:06:53 +08:00
onLoadCT(): void {
Utils.parseNode(this.node, this._nodeTab);
2025-09-18 22:27:02 +08:00
this.amount = this._nodeTab.chargeAmount.getComponent(Label);
2025-09-18 14:06:53 +08:00
this.selection = this._nodeTab.Selection;
2025-09-18 22:27:02 +08:00
this.coinIcon = this._nodeTab.SelectedCoinIcon.getComponent(Sprite);
this.coinText = this._nodeTab.SelectedCoinText.getComponent(Label);
this.address = this._nodeTab.addressText.getComponent(Label);
this.expireTimeText = this._nodeTab.expireTimeText.getComponent(Label);
2025-09-18 23:33:06 +08:00
this.qrCode = this._nodeTab.qrCode.getComponent(Sprite);
2025-09-18 14:06:53 +08:00
this.registerListener();
this.selection.setScale(new Vec3(1, 0, 1));
2025-09-18 22:27:02 +08:00
this.refreshView();
2025-09-18 14:06:53 +08:00
}
registerListener() {
GButton.BandClick(this._nodeTab.closeBtn, this.onClickClose, this);
GButton.BandClick(
this._nodeTab.CoinTypeSelectBtn,
this.onClickCoinTypeSelectBtn,
this
);
GButton.BandClick(this._nodeTab.CopyBtn, this.onClickCopy, this);
GButton.BandClick(
2025-09-18 22:27:02 +08:00
this._nodeTab.ENT_TRON,
2025-09-18 14:06:53 +08:00
() => {
2025-09-18 22:27:02 +08:00
this.onClickCoinType(proto.cs.EnmNetworkType.ENT_TRON);
2025-09-18 14:06:53 +08:00
},
this
);
GButton.BandClick(
2025-09-18 22:27:02 +08:00
this._nodeTab.ENT_TON,
2025-09-18 14:06:53 +08:00
() => {
2025-09-18 22:27:02 +08:00
this.onClickCoinType(proto.cs.EnmNetworkType.ENT_TON);
2025-09-18 14:06:53 +08:00
},
this
);
GButton.BandClick(
2025-09-18 22:27:02 +08:00
this._nodeTab.ENT_BEP,
2025-09-18 14:06:53 +08:00
() => {
2025-09-18 22:27:02 +08:00
this.onClickCoinType(proto.cs.EnmNetworkType.ENT_BEP);
},
this
);
GButton.BandClick(
this._nodeTab.ENT_ETH,
() => {
this.onClickCoinType(proto.cs.EnmNetworkType.ENT_ETH);
2025-09-18 14:06:53 +08:00
},
this
);
}
2025-09-18 22:27:02 +08:00
refreshData(data: any): void {
this.orderId = data.orderId;
this.payType = data.payType;
this.goodId = data.goodId;
2025-09-19 00:50:31 +08:00
this.curType =
data.networkType != undefined ? data.networkType : this.curType;
2025-09-18 22:27:02 +08:00
this.base = data.base;
}
refreshView() {
const OrderData = DataManager.I.getDataById<OrderData>(DataId.Order);
const amount = OrderData.getAmountById(this.orderId);
const walletUrl = OrderData.getWalletById(this.orderId);
const expireTime = OrderData.getExpireById(this.orderId);
2025-09-19 11:10:20 +08:00
// const retCode = OrderData.getRetCodeById(this.orderId);
// if (retCode != 0) {
// TipsPanel.show(LanguageUtils.getText("error_code_"+retCode));
// return;
// }
2025-09-18 23:33:06 +08:00
this.expireTimeText.string = expireTime.toString();
2025-09-18 22:27:02 +08:00
this.amount.string = amount;
this.address.string = walletUrl;
2025-09-19 00:50:31 +08:00
switch (this.curType) {
2025-09-18 22:27:02 +08:00
case proto.cs.EnmNetworkType.ENT_TRON:
ResManager.I.changeResourceSpriteFrame(
this.coinIcon,
"ui/web3pop/coinIcon/ENT_TRON"
);
this.coinText.string = "ENT_TRON";
break;
case proto.cs.EnmNetworkType.ENT_TON:
ResManager.I.changeResourceSpriteFrame(
this.coinIcon,
"ui/web3pop/coinIcon/ENT_TON"
);
this.coinText.string = "ENT_TON";
break;
case proto.cs.EnmNetworkType.ENT_ETH:
ResManager.I.changeResourceSpriteFrame(
this.coinIcon,
"ui/web3pop/coinIcon/ENT_ETH"
);
this.coinText.string = "ENT_ETH";
break;
case proto.cs.EnmNetworkType.ENT_BEP:
ResManager.I.changeResourceSpriteFrame(
this.coinIcon,
"ui/web3pop/coinIcon/ENT_BEP"
);
this.coinText.string = "ENT_BEP";
break;
}
2025-09-18 23:33:06 +08:00
//this.address.string = "asdasdasd";
//refreshQRcode
QRCodeGenerator.generateQRCodeSpriteFrame(
this.address.string,
320,
4,
(spriteframe) => {
if (spriteframe) {
this.qrCode.spriteFrame = spriteframe;
} else {
TipsPanel.show("qrcode generation fail, please copy url");
}
}
);
2025-09-18 14:06:53 +08:00
}
updateSelectNetwork() {}
onClickCoinTypeSelectBtn() {
this.selection.scale = new Vec3(1, 1, 1);
}
2025-09-18 22:27:02 +08:00
onClickCoinType(type: proto.cs.EnmNetworkType) {
2025-09-18 14:06:53 +08:00
this.curType = type;
2025-09-18 22:27:02 +08:00
switch (type) {
case proto.cs.EnmNetworkType.ENT_TRON:
break;
case proto.cs.EnmNetworkType.ENT_TON:
break;
case proto.cs.EnmNetworkType.ENT_ETH:
break;
case proto.cs.EnmNetworkType.ENT_BEP:
break;
2025-09-18 14:06:53 +08:00
}
2025-09-18 22:27:02 +08:00
this.base.startPayment(this.goodId, proto.cs.EnmPayType.EPT_WEB3_USD, type);
2025-09-18 14:06:53 +08:00
this.selection.scale = new Vec3(1, 0, 1);
}
onClickCopy() {
2025-09-18 23:33:06 +08:00
const stringToCopy = this.address.string;
SDKManager.copyToClipboard(stringToCopy, (success: boolean) => {
if (success) {
TipsPanel.show("地址已复制到剪贴板");
} else {
TipsPanel.show("复制失败,请手动复制地址");
}
});
2025-09-18 14:06:53 +08:00
}
onClickClose() {
2025-09-19 00:50:31 +08:00
this.base.web3PopPanel = null;
2025-09-18 14:06:53 +08:00
this.close();
}
}