@aelf-react/core
Version:
Please visit the [parent](https://github.com/mason-hz/aelf-react) [aelf-react](https://github.com/mason-hz/aelf-react) [repository](https://github.com/mason-hz/aelf-react) for documentation and details on this packge.
53 lines (52 loc) • 2.1 kB
JavaScript
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
let nightElfInstance = null;
let aelfInstanceByExtension = null;
class NightElfCheck {
constructor() {
let resolveTemp = null;
this.check = () => __awaiter(this, void 0, void 0, function* () {
return new Promise((resolve, reject) => {
// @ts-ignore
if (window.NightElf) {
console.log('There is NightElf');
resolve(true);
}
setTimeout(() => {
reject({
error: 200001,
message: 'timeout, please download and install the NightELF explorer extension',
});
}, 5000);
resolveTemp = resolve;
});
});
document.addEventListener('NightElf', () => {
resolveTemp(true);
});
}
static getInstance() {
if (nightElfInstance)
return nightElfInstance;
nightElfInstance = new NightElfCheck();
return nightElfInstance;
}
static initAelfInstanceByExtension(rpcUrl, appName) {
// @ts-ignore
aelfInstanceByExtension = new window.NightElf.AElf({
httpProvider: [rpcUrl],
appName,
});
return aelfInstanceByExtension;
}
}
exports.default = NightElfCheck;
;