334 lines
9.2 KiB
TypeScript
334 lines
9.2 KiB
TypeScript
import { _decorator, Component, Label, Node, Sprite, Vec3, Color } from "cc";
|
|
import li_BaseView from "../../../Main/Common/li_BaseView";
|
|
import Utils from "../../../Main/Common/Utils";
|
|
import { GButton } from "../../../Main/Common/GButton";
|
|
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";
|
|
import { QRCodeGenerator } from "db://assets/utils/qrcodeGenerator";
|
|
import { TipsPanel } from "./TipsPanel";
|
|
import { SDKManager } from "../../../Main/Channel/SDKManager";
|
|
import LanguageUtils from "../../../Main/Common/LanguageUtils";
|
|
|
|
const { ccclass, property } = _decorator;
|
|
|
|
@ccclass("Web3PopPanel")
|
|
export class Web3PopPanel extends li_BaseView {
|
|
private _nodeTab: any = {};
|
|
|
|
private amount: Label;
|
|
private coinIcon: Sprite;
|
|
private coinText: Label;
|
|
private address: Label;
|
|
private expireTimeText: Label;
|
|
private selection: Node;
|
|
|
|
private qrCode: Sprite;
|
|
private curType: proto.cs.EnmNetworkType;
|
|
|
|
private orderId;
|
|
private payType;
|
|
private networkType: proto.cs.EnmNetworkType;
|
|
private goodId: number;
|
|
|
|
private base: PurchasePanel;
|
|
|
|
private countdownTimer: any;
|
|
private remainingSeconds: number = 0;
|
|
private isCountingDown: boolean = false;
|
|
openUIDataCT(data: any): void {
|
|
this.refreshData(data);
|
|
this.base.web3PopPanel = this;
|
|
}
|
|
|
|
onLoadCT(): void {
|
|
Utils.parseNode(this.node, this._nodeTab);
|
|
|
|
this.amount = this._nodeTab.chargeAmount.getComponent(Label);
|
|
this.selection = this._nodeTab.Selection;
|
|
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);
|
|
this.qrCode = this._nodeTab.qrCode.getComponent(Sprite);
|
|
this.registerListener();
|
|
|
|
this.selection.setScale(new Vec3(1, 0, 1));
|
|
|
|
this.refreshView();
|
|
}
|
|
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(
|
|
this._nodeTab.ENT_TRON,
|
|
() => {
|
|
this.onClickCoinType(proto.cs.EnmNetworkType.ENT_TRON);
|
|
},
|
|
this
|
|
);
|
|
GButton.BandClick(
|
|
this._nodeTab.ENT_TON,
|
|
() => {
|
|
this.onClickCoinType(proto.cs.EnmNetworkType.ENT_TON);
|
|
},
|
|
this
|
|
);
|
|
GButton.BandClick(
|
|
this._nodeTab.ENT_BEP,
|
|
() => {
|
|
this.onClickCoinType(proto.cs.EnmNetworkType.ENT_BEP);
|
|
},
|
|
this
|
|
);
|
|
GButton.BandClick(
|
|
this._nodeTab.ENT_ETH,
|
|
() => {
|
|
this.onClickCoinType(proto.cs.EnmNetworkType.ENT_ETH);
|
|
},
|
|
this
|
|
);
|
|
}
|
|
|
|
refreshData(data: any): void {
|
|
this.orderId = data.orderId;
|
|
this.payType = data.payType;
|
|
this.goodId = data.goodId;
|
|
this.curType =
|
|
data.networkType != undefined ? data.networkType : this.curType;
|
|
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);
|
|
// const retCode = OrderData.getRetCodeById(this.orderId);
|
|
// if (retCode != 0) {
|
|
// TipsPanel.show(LanguageUtils.getText("error_code_"+retCode));
|
|
// return;
|
|
// }
|
|
|
|
this.stopCountdown();
|
|
|
|
this.resetButtonStates();
|
|
|
|
if (expireTime > 0) {
|
|
this.startCountdown(expireTime);
|
|
} else {
|
|
this.expireTimeText.string = "已过期";
|
|
this.expireTimeText.color = new Color(128, 128, 128, 255);
|
|
this.disableButtons();
|
|
}
|
|
this.amount.string = amount;
|
|
this.address.string = walletUrl;
|
|
switch (this.curType) {
|
|
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;
|
|
}
|
|
|
|
//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");
|
|
}
|
|
}
|
|
);
|
|
}
|
|
|
|
updateSelectNetwork() {}
|
|
|
|
onClickCoinTypeSelectBtn() {
|
|
this.selection.scale = new Vec3(1, 1, 1);
|
|
}
|
|
|
|
onClickCoinType(type: proto.cs.EnmNetworkType) {
|
|
this.curType = type;
|
|
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;
|
|
}
|
|
this.base.startPayment(this.goodId, proto.cs.EnmPayType.EPT_WEB3_USD, type);
|
|
|
|
this.selection.scale = new Vec3(1, 0, 1);
|
|
}
|
|
|
|
onClickCopy() {
|
|
const stringToCopy = this.address.string;
|
|
|
|
SDKManager.copyToClipboard(stringToCopy, (success: boolean) => {
|
|
if (success) {
|
|
TipsPanel.show("地址已复制到剪贴板");
|
|
} else {
|
|
TipsPanel.show("复制失败,请手动复制地址");
|
|
}
|
|
});
|
|
}
|
|
|
|
onDestroy() {
|
|
this.stopCountdown();
|
|
super.onDestroy();
|
|
}
|
|
|
|
onClickClose() {
|
|
this.stopCountdown();
|
|
this.base.web3PopPanel = null;
|
|
this.close();
|
|
}
|
|
|
|
private formatCountdownTime(seconds: number): string {
|
|
if (seconds <= 0) {
|
|
return "已过期";
|
|
}
|
|
|
|
const hours = Math.floor(seconds / 3600);
|
|
const minutes = Math.floor((seconds % 3600) / 60);
|
|
const secs = seconds % 60;
|
|
|
|
if (hours > 0) {
|
|
return `${Utils.padStart(hours.toString(), 2)}:${Utils.padStart(
|
|
minutes.toString(),
|
|
2
|
|
)}:${Utils.padStart(secs.toString(), 2)}`;
|
|
} else {
|
|
return `${Utils.padStart(minutes.toString(), 2)}:${Utils.padStart(
|
|
secs.toString(),
|
|
2
|
|
)}`;
|
|
}
|
|
}
|
|
|
|
private startCountdown(totalSeconds: number): void {
|
|
this.stopCountdown();
|
|
|
|
this.remainingSeconds = totalSeconds;
|
|
this.isCountingDown = true;
|
|
|
|
this.updateCountdownDisplay();
|
|
|
|
this.countdownTimer = this.schedule(() => {
|
|
this.remainingSeconds--;
|
|
this.updateCountdownDisplay();
|
|
|
|
if (this.remainingSeconds <= 0) {
|
|
this.stopCountdown();
|
|
this.onCountdownExpired();
|
|
}
|
|
}, 1);
|
|
}
|
|
|
|
private stopCountdown(): void {
|
|
if (this.countdownTimer) {
|
|
this.unschedule(this.countdownTimer);
|
|
this.countdownTimer = null;
|
|
}
|
|
this.isCountingDown = false;
|
|
}
|
|
|
|
private updateCountdownDisplay(): void {
|
|
if (!this.expireTimeText) return;
|
|
|
|
const timeText = this.formatCountdownTime(this.remainingSeconds);
|
|
this.expireTimeText.string = timeText;
|
|
|
|
if (this.remainingSeconds <= 30 && this.remainingSeconds > 0) {
|
|
this.expireTimeText.color = new Color(255, 0, 0, 255);
|
|
} else if (this.remainingSeconds <= 0) {
|
|
this.expireTimeText.color = new Color(128, 128, 128, 255);
|
|
} else {
|
|
this.expireTimeText.color = new Color(255, 255, 255, 255);
|
|
}
|
|
}
|
|
|
|
private resetButtonStates(): void {
|
|
const copyBtn = this._nodeTab.CopyBtn;
|
|
if (copyBtn) {
|
|
const btnComponent = copyBtn.getComponent("Button");
|
|
if (btnComponent) {
|
|
btnComponent.interactable = true;
|
|
}
|
|
}
|
|
|
|
const coinTypeSelectBtn = this._nodeTab.CoinTypeSelectBtn;
|
|
if (coinTypeSelectBtn) {
|
|
const btnComponent = coinTypeSelectBtn.getComponent("Button");
|
|
if (btnComponent) {
|
|
btnComponent.interactable = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
private disableButtons(): void {
|
|
const copyBtn = this._nodeTab.CopyBtn;
|
|
if (copyBtn) {
|
|
const btnComponent = copyBtn.getComponent("Button");
|
|
if (btnComponent) {
|
|
btnComponent.interactable = false;
|
|
}
|
|
}
|
|
|
|
const coinTypeSelectBtn = this._nodeTab.CoinTypeSelectBtn;
|
|
if (coinTypeSelectBtn) {
|
|
const btnComponent = coinTypeSelectBtn.getComponent("Button");
|
|
if (btnComponent) {
|
|
btnComponent.interactable = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
private onCountdownExpired(): void {
|
|
console.log("Web3支付倒计时已过期");
|
|
this.disableButtons();
|
|
TipsPanel.show("支付时间已过期,请重新发起支付");
|
|
}
|
|
}
|