198 lines
6.0 KiB
JavaScript
198 lines
6.0 KiB
JavaScript
System.register(["__unresolved_0", "cc", "__unresolved_1", "__unresolved_2"], function (_export, _context) {
|
|
"use strict";
|
|
|
|
var _reporterNs, _cclegacy, EventBus, web3, NoEthereumProviderError, TBG, _crd;
|
|
|
|
// import { SendReturnResult, SendReturn, Send, SendOld } from "./types";
|
|
// const web3 = new Web3(Web3.givenProvider);
|
|
// const myContract = new web3.eth.Contract(ercAbi, ETH_CONTRACT);
|
|
function parseSendReturn(sendReturn) {
|
|
return sendReturn.hasOwnProperty("result") ? sendReturn.result : sendReturn;
|
|
}
|
|
|
|
function _reportPossibleCrUseOfEventBus(extras) {
|
|
_reporterNs.report("EventBus", "./eventBus", _context.meta, extras);
|
|
}
|
|
|
|
function _reportPossibleCrUseOfweb(extras) {
|
|
_reporterNs.report("web3", "./web3", _context.meta, extras);
|
|
}
|
|
|
|
_export({
|
|
NoEthereumProviderError: void 0,
|
|
TBG: void 0
|
|
});
|
|
|
|
return {
|
|
setters: [function (_unresolved_) {
|
|
_reporterNs = _unresolved_;
|
|
}, function (_cc) {
|
|
_cclegacy = _cc.cclegacy;
|
|
}, function (_unresolved_2) {
|
|
EventBus = _unresolved_2.default;
|
|
}, function (_unresolved_3) {
|
|
web3 = _unresolved_3.web3;
|
|
}],
|
|
execute: function () {
|
|
_crd = true;
|
|
|
|
_cclegacy._RF.push({}, "e3aeaE7l21OioLmOiYtZ4CG", "tbg", undefined);
|
|
|
|
_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));
|
|
}
|
|
}
|
|
|
|
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]);
|
|
console.log(account);
|
|
return account;
|
|
} catch (error) {
|
|
if (error.code === 4001) {// throw new UserRejectedRequestError()
|
|
}
|
|
|
|
console.warn(false, "eth_requestAccounts was unsuccessful, falling back to enable");
|
|
} // 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({
|
|
hash
|
|
}) {
|
|
// const res: any = await getData({});
|
|
// const data = '1234';
|
|
// const res = "123";
|
|
const rawData = (_crd && web3 === void 0 ? (_reportPossibleCrUseOfweb({
|
|
error: Error()
|
|
}), web3) : web3).utils.fromUtf8(hash);
|
|
const {
|
|
result
|
|
} = await window.ethereum.send("personal_sign", [rawData, window.ethereum.selectedAddress.toLowerCase()]);
|
|
return {
|
|
raw: hash,
|
|
sign: result
|
|
};
|
|
}
|
|
|
|
async bigNumber({
|
|
num
|
|
}) {
|
|
// const number = await web3.bigNumber(num);
|
|
num = num.toString();
|
|
var number = await (_crd && web3 === void 0 ? (_reportPossibleCrUseOfweb({
|
|
error: Error()
|
|
}), web3) : web3).toWei(num, "ether");
|
|
return number;
|
|
}
|
|
|
|
async createNft({
|
|
abi,
|
|
contract,
|
|
toAddress
|
|
}) {
|
|
const nftContract = new (_crd && web3 === void 0 ? (_reportPossibleCrUseOfweb({
|
|
error: Error()
|
|
}), web3) : web3).eth.Contract(abi, contract);
|
|
return await nftContract.methods.Mint(toAddress).send({
|
|
from: toAddress
|
|
});
|
|
}
|
|
|
|
async sendTransaction({
|
|
from,
|
|
to,
|
|
value
|
|
}) {
|
|
await (_crd && web3 === void 0 ? (_reportPossibleCrUseOfweb({
|
|
error: Error()
|
|
}), web3) : web3).eth.sendTransaction({
|
|
from,
|
|
to,
|
|
value
|
|
});
|
|
}
|
|
|
|
handleNetworkChanged() {
|
|
console.log("handleNetworkChanged");
|
|
}
|
|
|
|
handleChainChanged() {
|
|
console.log("handleChainChanged");
|
|
}
|
|
|
|
handleAccountsChanged(accounts) {
|
|
console.log(accounts);
|
|
|
|
if (accounts.length === 0) {// this.emitDeactivate()
|
|
} else {// this.emitUpdate({ account: accounts[0] })
|
|
}
|
|
|
|
this.emit("accountChange");
|
|
}
|
|
|
|
handleClose() {
|
|
console.log("handleClose");
|
|
}
|
|
|
|
update(deltaTime) {}
|
|
|
|
});
|
|
|
|
_export("default", TBG);
|
|
|
|
_cclegacy._RF.pop();
|
|
|
|
_crd = false;
|
|
}
|
|
};
|
|
});
|
|
//# sourceMappingURL=28e85e55900c0e87ffc0887edda0fdee969eaea6.js.map
|