212 lines
6.4 KiB
JavaScript
212 lines
6.4 KiB
JavaScript
System.register(["__unresolved_0", "cc", "web3/dist/web3.min.js", "__unresolved_1", "__unresolved_2", "__unresolved_3"], function (_export, _context) {
|
|
"use strict";
|
|
|
|
var _reporterNs, _cclegacy, Web3, EventBus, usdtAbi, nftAbi, NoEthereumProviderError, TBG, _crd, web3;
|
|
|
|
function parseSendReturn(sendReturn) {
|
|
return sendReturn.hasOwnProperty("result") ? sendReturn.result : sendReturn;
|
|
}
|
|
|
|
function _reportPossibleCrUseOfWeb(extras) {
|
|
_reporterNs.report("Web3", "web3/dist/web3.min.js", _context.meta, extras);
|
|
}
|
|
|
|
function _reportPossibleCrUseOfEventBus(extras) {
|
|
_reporterNs.report("EventBus", "./eventBus", _context.meta, extras);
|
|
}
|
|
|
|
function _reportPossibleCrUseOfusdtAbi(extras) {
|
|
_reporterNs.report("usdtAbi", "./abi/usdtAbi", _context.meta, extras);
|
|
}
|
|
|
|
function _reportPossibleCrUseOfnftAbi(extras) {
|
|
_reporterNs.report("nftAbi", "./abi/nftAbi", _context.meta, extras);
|
|
}
|
|
|
|
_export({
|
|
NoEthereumProviderError: void 0,
|
|
TBG: void 0
|
|
});
|
|
|
|
return {
|
|
setters: [function (_unresolved_) {
|
|
_reporterNs = _unresolved_;
|
|
}, function (_cc) {
|
|
_cclegacy = _cc.cclegacy;
|
|
}, function (_web3DistWeb3MinJs) {
|
|
Web3 = _web3DistWeb3MinJs.default;
|
|
}, function (_unresolved_2) {
|
|
EventBus = _unresolved_2.default;
|
|
}, function (_unresolved_3) {
|
|
usdtAbi = _unresolved_3.default;
|
|
}, function (_unresolved_4) {
|
|
nftAbi = _unresolved_4.default;
|
|
}],
|
|
execute: function () {
|
|
_crd = true;
|
|
|
|
_cclegacy._RF.push({}, "e3aeaE7l21OioLmOiYtZ4CG", "tbg", undefined);
|
|
|
|
web3 = new (_crd && Web3 === void 0 ? (_reportPossibleCrUseOfWeb({
|
|
error: Error()
|
|
}), Web3) : Web3)((_crd && Web3 === void 0 ? (_reportPossibleCrUseOfWeb({
|
|
error: Error()
|
|
}), Web3) : Web3).givenProvider);
|
|
|
|
_export("NoEthereumProviderError", NoEthereumProviderError = class NoEthereumProviderError extends Error {
|
|
constructor() {
|
|
super();
|
|
this.name = this.constructor.name;
|
|
this.message = "No Ethereum provider was found on window.ethereum.";
|
|
}
|
|
|
|
});
|
|
|
|
_export("TBG", TBG = class TBG extends (_crd && EventBus === void 0 ? (_reportPossibleCrUseOfEventBus({
|
|
error: Error()
|
|
}), EventBus) : EventBus) {
|
|
constructor(params) {
|
|
super();
|
|
this.handleAddListener();
|
|
}
|
|
|
|
handleAddListener() {
|
|
if (window.ethereum.on) {
|
|
window.ethereum.on("chainChanged", this.handleChainChanged.bind(this));
|
|
window.ethereum.on("accountsChanged", this.handleAccountsChanged.bind(this));
|
|
window.ethereum.on("close", this.handleClose.bind(this));
|
|
window.ethereum.on("networkChanged", this.handleNetworkChanged.bind(this));
|
|
}
|
|
}
|
|
|
|
handleNetworkChanged() {
|
|
this.emit("networkChanged");
|
|
}
|
|
|
|
handleChainChanged() {
|
|
this.emit("chainChanged");
|
|
}
|
|
|
|
handleAccountsChanged(accounts) {
|
|
this.emit("accountsChanged", accounts);
|
|
}
|
|
|
|
handleClose() {
|
|
this.emit("close");
|
|
}
|
|
|
|
async login() {
|
|
if (!window.ethereum) {
|
|
throw new NoEthereumProviderError();
|
|
}
|
|
|
|
if (window.ethereum.isMetaMask) {
|
|
window.ethereum.autoRefreshOnNetworkChange = false;
|
|
}
|
|
|
|
let account;
|
|
|
|
try {
|
|
account = await window.ethereum.request({
|
|
method: "eth_requestAccounts"
|
|
}).then(sendReturn => parseSendReturn(sendReturn)[0]);
|
|
return account;
|
|
} catch (error) {
|
|
if (error.code === 4001) {// throw new UserRejectedRequestError()
|
|
}
|
|
} // if unsuccessful, try enable
|
|
|
|
|
|
if (!account) {
|
|
// if enable is successful but doesn't return accounts, fall back to getAccount (not happy i have to do this...)
|
|
account = await window.ethereum.enable().then(sendReturn => sendReturn && parseSendReturn(sendReturn)[0]);
|
|
return account;
|
|
}
|
|
}
|
|
|
|
logout() {
|
|
if (window.ethereum && window.ethereum.removeListener) {
|
|
window.ethereum.removeListener("chainChanged", this.handleChainChanged);
|
|
window.ethereum.removeListener("accountsChanged", this.handleAccountsChanged);
|
|
window.ethereum.removeListener("close", this.handleClose);
|
|
window.ethereum.removeListener("networkChanged", this.handleNetworkChanged);
|
|
}
|
|
}
|
|
|
|
async sign(randomKey) {
|
|
const rawData = web3.utils.fromUtf8(randomKey);
|
|
const {
|
|
result
|
|
} = await window.ethereum.send("personal_sign", [rawData, window.ethereum.selectedAddress.toLowerCase()]);
|
|
return {
|
|
raw: rawData,
|
|
sign: result
|
|
};
|
|
} // async createNft({ contract, from, assetId, signature }) {
|
|
|
|
|
|
async createNft({
|
|
contract,
|
|
from,
|
|
assetId
|
|
}) {
|
|
const nftContract = new web3.eth.Contract(_crd && nftAbi === void 0 ? (_reportPossibleCrUseOfnftAbi({
|
|
error: Error()
|
|
}), nftAbi) : nftAbi, contract);
|
|
return await nftContract.methods.Mint(from).send({
|
|
from
|
|
});
|
|
}
|
|
|
|
async transferNft({
|
|
contract,
|
|
to,
|
|
from,
|
|
tokenId
|
|
}) {
|
|
const nftContract = new web3.eth.Contract(_crd && nftAbi === void 0 ? (_reportPossibleCrUseOfnftAbi({
|
|
error: Error()
|
|
}), nftAbi) : nftAbi, contract);
|
|
return nftContract.methods.Transfer(from, to, tokenId).send({
|
|
from
|
|
});
|
|
}
|
|
|
|
async sendTransaction({
|
|
from,
|
|
to,
|
|
value
|
|
}) {
|
|
return web3.eth.sendTransaction({
|
|
from,
|
|
to,
|
|
value
|
|
});
|
|
} // "0xaC893B498E2005Af4cb8b03D710F187EC23a8f5f";
|
|
|
|
|
|
async sendUsdtTransaction({
|
|
from,
|
|
contract,
|
|
to,
|
|
value
|
|
}) {
|
|
const usdtContract = new web3.eth.Contract(_crd && usdtAbi === void 0 ? (_reportPossibleCrUseOfusdtAbi({
|
|
error: Error()
|
|
}), usdtAbi) : usdtAbi, contract);
|
|
return usdtContract.methods.transfer(to, value).send({
|
|
from
|
|
});
|
|
}
|
|
|
|
});
|
|
|
|
_export("default", TBG);
|
|
|
|
_cclegacy._RF.pop();
|
|
|
|
_crd = false;
|
|
}
|
|
};
|
|
});
|
|
//# sourceMappingURL=5da128f68c2d76708d5a8170f493a7ed66631545.js.map
|