forked from circlecloud/tera
953 lines
34 KiB
JavaScript
953 lines
34 KiB
JavaScript
/*
|
||
* @project: TERA
|
||
* @version: Development (beta)
|
||
* @license: MIT (not for evil)
|
||
* @copyright: Yuriy Ivanov (Vtools) 2017-2019 [progr76@gmail.com]
|
||
* Web: https://terafoundation.org
|
||
* Twitter: https://twitter.com/terafoundation
|
||
* Telegram: https://t.me/terafoundation
|
||
*/
|
||
|
||
var SaveIdArr = ["idAccount", "idTo", "idSumSend", "idDescription", "idCurTabName", "idViewBlockNum", "idViewAccountNum", "idViewDappNum",
|
||
"idLang"];
|
||
var CONFIG_DATA = { PRICE_DAO: { NewAccount: 10 }, MaxNumBlockDB: 0, MaxAccID: 0, MaxDappsID: 0 };
|
||
var CountViewRows = 20;
|
||
var DefAccounts = { BlockName: "idPaginationAccount", NumName: "idViewAccountNum", TabName: "explorer_accounts", APIName: "GetAccountList" };
|
||
var DefBlock = { BlockName: "idPaginationBlock", NumName: "idViewBlockNum", TabName: "explorer_blocks", APIName: "GetBlockList" };
|
||
var DefDapps = {
|
||
BlockName: "idPaginationDapps", NumName: "idViewDappNum", TabName: "dapps_list", APIName: "GetDappList", CountViewRows: 10,
|
||
FilterName: "idCategory"
|
||
};
|
||
|
||
function SetImg() {
|
||
};
|
||
var CONNECT_STATUS = 0;
|
||
var NotModalClose = 0;
|
||
window.onload = function() {
|
||
InitAccountsCard();
|
||
DoLangScript();
|
||
InitWalletKeyName();
|
||
if (Storage.getItem("NETWORK") || IsLocalClient()) {
|
||
OnLoad();
|
||
}
|
||
else {
|
||
GetData("/GetCurrentInfo", {}, function(Data) {
|
||
if (Data && Data.result) {
|
||
Storage.setItem("NETWORK", Data.NETWORK);
|
||
console.log("Default network: " + Data.NETWORK);
|
||
OnLoad();
|
||
}
|
||
});
|
||
}
|
||
var HasPassword = IsLockedWallet();
|
||
if (HasPassword) {
|
||
NotModalClose = 1;
|
||
openModal('password-modal-enter');
|
||
}
|
||
else {
|
||
OpenWalletKey();
|
||
}
|
||
SetUsePassword(HasPassword);
|
||
window.onkeydown = function(e) {
|
||
if (e.keyCode === 27) {
|
||
if (IsVisibleBlock("overlay"))
|
||
closeModal();
|
||
}
|
||
};
|
||
$("idAccountsList").addEventListener("click", MyToggleList);
|
||
};
|
||
|
||
function OnLoad() {
|
||
if (Storage.getItem("NETWORK")) {
|
||
NETWORK = Storage.getItem("NETWORK");
|
||
}
|
||
$("idCurNetwork").value = NETWORK;
|
||
LoadValues();
|
||
InitDappsCard();
|
||
StartWebWallet();
|
||
UpdatesExplorerData();
|
||
UpdatesAccountsData();
|
||
setInterval(UpdatesExplorerData, 1000);
|
||
setInterval(UpdatesAccountsData, 1000);
|
||
DoStableScroll();
|
||
window.onmousemove = function(event) {
|
||
SetDiagramMouseX(event);
|
||
};
|
||
if (window.location.hash) {
|
||
var LocationPath = window.location.hash.substr(1);
|
||
if (LocationPath) {
|
||
SelectTab(LocationPath);
|
||
}
|
||
}
|
||
};
|
||
|
||
function ChangeNetwork() {
|
||
CONNECT_STATUS = 0;
|
||
NETWORK = $("idCurNetwork").value;
|
||
Storage.setItem("NETWORK", NETWORK);
|
||
StartWebWallet();
|
||
UpdatesExplorerData();
|
||
UpdatesAccountsData();
|
||
};
|
||
|
||
function OnFindServer() {
|
||
if (!MainServer) {
|
||
CONNECT_STATUS = - 1;
|
||
SetStatus("Server not found");
|
||
Storage.setItem("MainServer", undefined);
|
||
return;
|
||
}
|
||
CONNECT_STATUS = 2;
|
||
Storage.setItem("MainServer", JSON.stringify({ ip: MainServer.ip, port: MainServer.port }));
|
||
FillCurrencyAsync("idAccountCur");
|
||
};
|
||
|
||
function LoadValues() {
|
||
var StrDelList = localStorage["DelList"];
|
||
if (StrDelList)
|
||
DelList = JSON.parse(StrDelList);
|
||
if (LoadValuesByArr(SaveIdArr)) {
|
||
ChangeLang();
|
||
}
|
||
InitPrivKey();
|
||
};
|
||
|
||
function SaveValues() {
|
||
SaveValuesByArr(SaveIdArr);
|
||
localStorage["DelList"] = JSON.stringify(DelList);
|
||
};
|
||
var TabArr = [{ name: "TabWelcome" }, { name: "TabWalletSet" }, { name: "TabKeySet" }, { name: "TabAccounts" }, { name: "TabSend" }, { name: "TabDapps" },
|
||
{ name: "TabExplorer" }, { name: "TabLogo" }];
|
||
|
||
function SelectTab(name) {
|
||
SetStatus("");
|
||
$("idCurTabName").value = name;
|
||
SetVisibleTab();
|
||
SaveValues();
|
||
OnSelectTab(name);
|
||
if (name && history.pushState)
|
||
history.pushState(null, null, "#" + name);
|
||
};
|
||
|
||
function OnSelectTab(name) {
|
||
if (!GetPrivKey()) {
|
||
GenerateKeyNew();
|
||
SetPrivKey($("idPrivKeyEdit").value.trim());
|
||
InitPrivKey();
|
||
}
|
||
if (name === "TabDapps") {
|
||
ViewDapps();
|
||
}
|
||
};
|
||
|
||
function SetVisibleTab() {
|
||
var CurTabName = $("idCurTabName").value;
|
||
if (!CurTabName || CurTabName === "undefined")
|
||
CurTabName = TabArr[0].name;
|
||
var str;
|
||
for (var i = 0; i < TabArr.length; i++) {
|
||
var name = TabArr[i].name;
|
||
var Item = $(name);
|
||
if (!Item)
|
||
continue;
|
||
if (CurTabName === name) {
|
||
Item.style.display = 'block';
|
||
str = "active";
|
||
}
|
||
else {
|
||
Item.style.display = 'none';
|
||
str = "";
|
||
}
|
||
var ItemM = $("M" + name);
|
||
if (ItemM) {
|
||
if (str) {
|
||
ItemM.classList.add(str);
|
||
}
|
||
else {
|
||
ItemM.classList.remove("active");
|
||
}
|
||
}
|
||
}
|
||
};
|
||
|
||
function IsPrivateMode() {
|
||
var PrivKeyStr = GetPrivKey();
|
||
if (PrivKeyStr && PrivKeyStr.length === 64)
|
||
return 1;
|
||
else
|
||
return 0;
|
||
};
|
||
|
||
function SetVisiblePrivKey() {
|
||
if (bShowPrivKey)
|
||
$("idPrivKeyStatic").innerText = GetPrivKey();
|
||
else
|
||
$("idPrivKeyStatic").innerText = "••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••";
|
||
};
|
||
var bShowPrivKey = 0;
|
||
|
||
function OnVisiblePrivKey() {
|
||
bShowPrivKey = !bShowPrivKey;
|
||
SetVisiblePrivKey();
|
||
};
|
||
|
||
function SetPubKeyHTML() {
|
||
$("idPubKeyStatic").innerText = GetPubKey();
|
||
};
|
||
|
||
function GenerateKeyNew() {
|
||
var arr = new Uint8Array(32);
|
||
window.crypto.getRandomValues(arr);
|
||
var Str = GetHexFromArr(sha3(arr));
|
||
$("idPrivKeyEdit").value = Str;
|
||
};
|
||
|
||
function OnGenerateKeyNew() {
|
||
GenerateKeyNew();
|
||
};
|
||
|
||
function OnEditPrivKey() {
|
||
};
|
||
|
||
function OnPrivKeyOK() {
|
||
SetPrivKey($("idPrivKeyEdit").value.trim());
|
||
InitPrivKey();
|
||
SelectTab('TabKeySet');
|
||
ClearSend();
|
||
};
|
||
|
||
function OnPrivKeyCancel() {
|
||
InitPrivKey();
|
||
SelectTab('TabKeySet');
|
||
};
|
||
var FirstAccountsData = 1;
|
||
var AccountsCount = - 1;
|
||
|
||
function UpdatesAccountsData() {
|
||
if (IsVisibleClass(".accounts-info__add"))
|
||
return;
|
||
if (!CONNECT_STATUS)
|
||
return;
|
||
var Str = GetPubKey();
|
||
if (!Str) {
|
||
return;
|
||
}
|
||
GetData("/GetAccountListByKey", { Key: Str, AllData: FirstAccountsData }, function(Data, responseText) {
|
||
if (!Data || !Data.result || !Data.arr)
|
||
return;
|
||
if (AccountsCount === Data.arr.length) {
|
||
if (IsVisibleClass(".accounts-info__add2"))
|
||
return;
|
||
}
|
||
AccountsCount = Data.arr.length;
|
||
SetVisibleClass(".accounts-info__acc-list", AccountsCount);
|
||
SetVisibleClass(".accounts-info__empty", !AccountsCount);
|
||
SetVisibleClass(".accounts-info__add2", 0);
|
||
if (AccountsCount) {
|
||
SetAccountsCard(Data, responseText);
|
||
}
|
||
else {
|
||
if (FirstAccountsData && !Data.arr.length) {
|
||
SelectTab('TabAccounts');
|
||
}
|
||
}
|
||
FirstAccountsData = 0;
|
||
});
|
||
};
|
||
|
||
function ViewAddAccount(Visible) {
|
||
SetVisibleClass(".accounts-info__add", Visible);
|
||
SetVisibleClass(".accounts-info__acc-list", !Visible);
|
||
SetVisibleClass(".accounts-info__empty", 0);
|
||
};
|
||
|
||
function OnViewAddAccount() {
|
||
OnChangeAccName();
|
||
ViewAddAccount(1);
|
||
$("idAccountName").focus();
|
||
};
|
||
|
||
function CancelAddAccount() {
|
||
ViewAddAccount(0);
|
||
};
|
||
|
||
function OnChangeAccName() {
|
||
$("idBtAddAccount").disabled = !($("idAccountName").value.length);
|
||
};
|
||
|
||
function CancelCreateAccount() {
|
||
};
|
||
|
||
function OnAddAccount() {
|
||
var Name = $("idAccountName").value;
|
||
if (!Name) {
|
||
SetError("Enter the account name");
|
||
return;
|
||
}
|
||
var Smart = 0;
|
||
var Currency = ParseNum($("idAccountCur").value);
|
||
SetStatus("Calculate Tx, wait pls ...");
|
||
SendTrCreateAccWait(Currency, GetPubKey(), Name, Smart);
|
||
SetVisibleClass(".accounts-info__add", 0);
|
||
SetVisibleClass(".accounts-info__add2", 1);
|
||
};
|
||
var WasAccountsDataStr;
|
||
var StrAccCardTemplate;
|
||
|
||
function InitAccountsCard() {
|
||
if ($("AccCardTemplate")) {
|
||
StrAccCardTemplate = $("AccCardTemplate").outerHTML;
|
||
$("AccCardTemplate").outerHTML = "";
|
||
}
|
||
};
|
||
|
||
function SetAccountsCard(Data, AccountsDataStr) {
|
||
if (!Data || !Data.result) {
|
||
return;
|
||
}
|
||
if (AccountsDataStr === WasAccountsDataStr)
|
||
return;
|
||
WasAccountsDataStr = AccountsDataStr;
|
||
var arr = [];
|
||
for (var i = 0; Data.arr && i < Data.arr.length; i++) {
|
||
var Item = Data.arr[i];
|
||
if (!DelList[Item.Num]) {
|
||
arr.push(Item);
|
||
}
|
||
}
|
||
var Select = $("idAccount");
|
||
if (arr.length !== Select.options.length) {
|
||
var options = Select.options;
|
||
options.length = arr.length;
|
||
}
|
||
MaxBlockNum = GetCurrentBlockNumByTime();
|
||
$("idListCount").innerText = arr.length;
|
||
var StrList = "";
|
||
var ListTotal = {};
|
||
for (var i = 0; arr && i < arr.length; i++) {
|
||
var Item = arr[i];
|
||
Item.MyAccount = true;
|
||
var Num = ParseNum(Item.Num);
|
||
if (!MapAccounts[Num])
|
||
MapAccounts[Num] = {};
|
||
CopyObjKeys(MapAccounts[Num], Item);
|
||
var option = Select.options[i];
|
||
var StrText = GetAccountText(Item, Num, 1);
|
||
if (option.text !== StrText)
|
||
CheckNameAccTo();
|
||
option.value = Num;
|
||
option.text = StrText;
|
||
var Str = StrAccCardTemplate;
|
||
Str = Str.replace("AccCardTemplate", "idCard" + Item.Num);
|
||
Str = Str.replace(/{Item.Num}/g, Item.Num);
|
||
Str = Str.replace("{Value.SumCOIN}", Item.Value.SumCOIN);
|
||
Str = Str.replace("{Value.SumCENT}", Item.Value.SumCENT);
|
||
Str = Str.replace("{Value.CurrencyName}", CurrencyName(Item.Currency));
|
||
var CurrencyObj = Item.CurrencyObj;
|
||
if (!CurrencyObj)
|
||
CurrencyObj = { IconBlockNum: 0, Num: 0 };
|
||
Str = Str.replace("{Value.CurrencyIconPath}", RetIconPath(CurrencyObj, 1));
|
||
var CurrencyPath = RetIconPath(CurrencyObj);
|
||
if (CurrencyPath.substr(0, 6) !== "/file/")
|
||
Str = Str.replace("prod-card__currency--with-dot", "");
|
||
Str = Str.replace("{Item.Name}", escapeHtml(Item.Name));
|
||
var SmartObj = Item.SmartObj;
|
||
if (!SmartObj)
|
||
SmartObj = { Name: "", Num: 0 };
|
||
SmartObj.IconPath = RetIconPath(SmartObj, 0);
|
||
Str = Str.replace("{SmartObj.IconPath}", SmartObj.IconPath);
|
||
Str = Str.replace("{SmartObj.Name}", escapeHtml(SmartObj.Name));
|
||
Str = Str.replace(/{SmartObj.Num}/g, SmartObj.Num);
|
||
if (SmartObj.Num) {
|
||
Str = Str.replace("prod-card__link--connect", "myhidden");
|
||
}
|
||
else {
|
||
Str = Str.replace("prod-card__link--dapp", "myhidden");
|
||
Str = Str.replace("prod-card__dropdown", "prod-card__dropdown nodapp");
|
||
}
|
||
StrList += Str;
|
||
Str = "";
|
||
var Total = ListTotal[Item.Currency];
|
||
if (!Total) {
|
||
Total = { SumCOIN: 0, SumCENT: 0, Name: CurrencyName(Item.Currency) };
|
||
ListTotal[Item.Currency] = Total;
|
||
}
|
||
ADD(Total, Item.Value);
|
||
}
|
||
$("idAccountsList").innerHTML = StrList;
|
||
StrList = "";
|
||
var StrTotal = "";
|
||
for (var key in ListTotal) {
|
||
var Total = ListTotal[key];
|
||
StrTotal += '<div class="total-info__item"><dt>' + Total.Name + '</dt><dd>' + STRING_FROM_COIN(Total) + '</dd></div>';
|
||
}
|
||
$("idTotalList").innerHTML = StrTotal;
|
||
var CurentValue = LoadMapAfter["idAccount"];
|
||
if (CurentValue) {
|
||
Select.value = CurentValue;
|
||
delete LoadMapAfter["idAccount"];
|
||
}
|
||
};
|
||
|
||
function ConnectSmart(NumAccount) {
|
||
ChangeSmart(NumAccount, 0);
|
||
};
|
||
|
||
function SetSmart(NumAccount, WasSmart) {
|
||
ChangeSmart(NumAccount, WasSmart);
|
||
};
|
||
|
||
function DelSmart(NumAccount, WasSmart) {
|
||
SetSmartToAccount(NumAccount, 0);
|
||
};
|
||
|
||
function DelAccount(NumAccount) {
|
||
DelList[NumAccount] = 1;
|
||
AccountsCount = 0;
|
||
WasAccountsDataStr = "";
|
||
SaveValues();
|
||
};
|
||
|
||
function RestoreAllAccounts() {
|
||
DelList = {};
|
||
DelAccount(0);
|
||
};
|
||
|
||
function UpdatesExplorerData() {
|
||
var WasSendTr = 0;
|
||
for (var key in MapSendTransaction) {
|
||
var Item = MapSendTransaction[key];
|
||
if (!Item.WasProcess && !Item.final) {
|
||
WasSendTr = 1;
|
||
break;
|
||
}
|
||
}
|
||
GetData("GetCurrentInfo", { Diagram: IsVisibleBlock("idStatBlock") ? 1 : 0, ArrLog: WasSendTr }, function(Data) {
|
||
if (!Data || !Data.result)
|
||
return;
|
||
SetExplorerData(Data);
|
||
SetBlockChainConstant(Data);
|
||
var arr = Data.arr;
|
||
for (var i = 0; arr && i < arr.length; i++) {
|
||
var ItemServer = arr[i];
|
||
var ItemClient = DiagramMap[ItemServer.name];
|
||
if (!ItemClient || ItemClient.Extern)
|
||
continue;
|
||
ItemClient.arr = ItemServer.arr;
|
||
ItemClient.AvgValue = ItemServer.AvgValue;
|
||
ItemClient.steptime = ItemServer.steptime;
|
||
ItemClient.fillStyle = "white";
|
||
DrawDiagram(ItemClient);
|
||
}
|
||
});
|
||
};
|
||
var FirstCallDiagram = 1;
|
||
|
||
function SetExplorerData(Data) {
|
||
if (!Data || !Data.result)
|
||
return;
|
||
CONFIG_DATA = Data;
|
||
window.FIRST_TIME_BLOCK = Data.FIRST_TIME_BLOCK;
|
||
if (FirstCallDiagram) {
|
||
ViewEnd(DefAccounts, CONFIG_DATA.MaxAccID, 1);
|
||
ViewEnd(DefBlock, CONFIG_DATA.MaxNumBlockDB, 1);
|
||
InitDiagram();
|
||
}
|
||
FirstCallDiagram = 0;
|
||
var StrVersion = " 0." + Data.VersionNum;
|
||
$("idBHeight").innerText = Data.MaxNumBlockDB;
|
||
$("idBCurrent").innerText = Data.CurBlockNum;
|
||
$("idBVersion").innerText = StrVersion;
|
||
SetArrLog(Data.ArrLog);
|
||
};
|
||
|
||
function SetArrLog(arr) {
|
||
if (!arr)
|
||
return;
|
||
for (var i = 0; i < arr.length; i++) {
|
||
var Item = arr[i];
|
||
if (!Item.final)
|
||
continue;
|
||
var TR = MapSendTransaction[Item.key];
|
||
if (TR && !TR.WasProcess && Item.final) {
|
||
TR.WasProcess = 1;
|
||
SetStatus(Item.text);
|
||
if (Item.text.indexOf("Add to blockchain") >= 0) {
|
||
if (TR.Run) {
|
||
TR.Run(TR);
|
||
TR.Run = undefined;
|
||
}
|
||
}
|
||
var Account = MapCheckTransaction[Item.key];
|
||
if (Account) {
|
||
delete MapCheckTransaction[Item.key];
|
||
Account.NextSendTime = 0;
|
||
}
|
||
}
|
||
}
|
||
CheckSending();
|
||
};
|
||
var DiagramArr = [{ name: "MAX:ALL_NODES", text: "All nodes count", value: 0, red: "#1d506b", MouseText: " nodes" }, {
|
||
name: "MAX:HASH_RATE_B",
|
||
text: "HashRate, Tera hash/s", value: 0, red: "#286b16", MathPow: 2, MathDiv: 1024 * 1024 * 1024 * 1024, KPrecision: 10, NoTextMax: 1,
|
||
MouseText: " T h/s"
|
||
},];
|
||
|
||
function InitDiagram() {
|
||
InitDiagramByArr(DiagramArr, 1120);
|
||
};
|
||
|
||
function ViewCounters(This) {
|
||
var BlockName = "idStatBlock";
|
||
var element = $(BlockName);
|
||
var bVisible = IsVisibleBlock(BlockName);
|
||
if (!bVisible)
|
||
MoveUp(element);
|
||
SetVisibleBlock(BlockName, !bVisible);
|
||
var ResVisible = IsVisibleBlock(BlockName);
|
||
if (This && This.className) {
|
||
This.className = This.className.replace("btpress", "");
|
||
if (ResVisible)
|
||
This.className += " btpress";
|
||
}
|
||
};
|
||
setInterval(CheckSending, 1000);
|
||
|
||
function OpenAddressBook() {
|
||
return;
|
||
var bVisible = IsVisibleBlock("idAddressBook");
|
||
SetVisibleBlock("idAddressBook", !bVisible);
|
||
};
|
||
|
||
function CloaseAddressBook() {
|
||
OpenAddressBook();
|
||
};
|
||
|
||
function ClearSend() {
|
||
$("idAccount").value = "";
|
||
$("idTo").value = "";
|
||
$("idSumSend").value = "";
|
||
$("idDescription").value = "";
|
||
$("idNameTo2").innerText = "";
|
||
};
|
||
|
||
function downloadKey(fieldID) {
|
||
var text = document.getElementById(fieldID).value;
|
||
var blob = new Blob([text], { type: "text/plain" });
|
||
var anchor = document.createElement("a");
|
||
anchor.download = "tera-key.txt";
|
||
anchor.href = window.URL.createObjectURL(blob);
|
||
anchor.target = "_blank";
|
||
anchor.style.display = "none";
|
||
document.body.appendChild(anchor);
|
||
anchor.click();
|
||
document.body.removeChild(anchor);
|
||
};
|
||
|
||
function openModal(id) {
|
||
var modal = document.querySelector("#" + id);
|
||
var overlay = document.querySelector("#overlay");
|
||
modal.style.display = "block";
|
||
overlay.style.display = "block";
|
||
};
|
||
|
||
function closeModal() {
|
||
if (NotModalClose)
|
||
return;
|
||
var modals = document.querySelectorAll(".modal");
|
||
var overlay = document.querySelector("#overlay");
|
||
modals.forEach(function(item) {
|
||
item.style.display = "none";
|
||
});
|
||
overlay.style.display = "none";
|
||
};
|
||
|
||
function showMenu(Num) {
|
||
var menu = document.querySelector("#idBt" + Num);
|
||
if (menu.style.display === "none") {
|
||
menu.style.display = "block";
|
||
}
|
||
else {
|
||
menu.style.display = "none";
|
||
}
|
||
};
|
||
|
||
function closeMenu(Num) {
|
||
var menu = document.querySelector("#idBt" + Num);
|
||
setTimeout(function() {
|
||
menu.style.display = "none";
|
||
}, 115);
|
||
};
|
||
|
||
function UploadKey(id) {
|
||
var file = $(id).files[0];
|
||
var reader = new FileReader();
|
||
reader.onload = function() {
|
||
if (reader.result.byteLength !== 64)
|
||
SetError("Error file length (" + reader.result.byteLength + ")");
|
||
else {
|
||
var view = new Uint8Array(reader.result);
|
||
var Key = Utf8ArrayToStr(view);
|
||
SetStatus("OK");
|
||
ToLog("Result: " + Key);
|
||
SetPrivKey(Key);
|
||
InitPrivKey();
|
||
$(id).value = "";
|
||
}
|
||
};
|
||
reader.readAsArrayBuffer(file);
|
||
};
|
||
|
||
function InitPrivKey() {
|
||
$("idPrivKeyEdit").value = GetPrivKey();
|
||
SetPubKeyHTML();
|
||
SetVisiblePrivKey();
|
||
$("idSave2").disabled = !IsPrivateMode();
|
||
};
|
||
|
||
function SendMobileBefore() {
|
||
if ($("idSendButton").disabled)
|
||
return;
|
||
var FromID = ParseNum($("idAccount").value);
|
||
var Item = MapAccounts[FromID];
|
||
if (!Item) {
|
||
SetError("Error FROM ID");
|
||
return;
|
||
}
|
||
$("idConfirmFromID").innerText = Item.Num;
|
||
$("idConfirmFromName").innerText = Item.Name + " (" + STRING_FROM_COIN(Item.Value) + " " + CurrencyNameItem(Item) + ")";
|
||
var ToID = ParseNum($("idTo").value);
|
||
var Item2 = MapAccounts[ToID];
|
||
if (!Item2) {
|
||
SetError("Error TO ID");
|
||
return;
|
||
}
|
||
$("idConfirmToID").innerText = Item2.Num;
|
||
$("idConfirmToName").innerText = Item2.Name + " (" + STRING_FROM_COIN(Item2.Value) + " " + CurrencyNameItem(Item2) + ")";
|
||
var CoinAmount = COIN_FROM_FLOAT($("idSumSend").value);
|
||
$("idConfirmAmount").innerText = STRING_FROM_COIN(CoinAmount);
|
||
$("idConfirmCurrency").innerText = CurrencyNameItem(Item);
|
||
$("idConfirmDescription").innerText = $("idDescription").value;
|
||
SetVisibleClass(".send-page__setting", 0);
|
||
SetVisibleClass(".send-page__confirm", 1);
|
||
SetStatus("");
|
||
};
|
||
|
||
function OKSend() {
|
||
SendMoney();
|
||
$("idSumSend").value = 0;
|
||
CancelSend();
|
||
};
|
||
|
||
function CancelSend() {
|
||
SetVisibleClass(".send-page__setting", 1);
|
||
SetVisibleClass(".send-page__confirm", 0);
|
||
};
|
||
|
||
function SetNewPassword() {
|
||
var Str1 = $("Password1").value.trim();
|
||
var Str2 = $("Password2").value.trim();
|
||
if (Str1 !== Str2) {
|
||
SetError("Wrong passwords");
|
||
return;
|
||
}
|
||
var Key = GetPrivKey();
|
||
SetWalletPassword(Str1);
|
||
SetPrivKey(Key);
|
||
SetPubKeyHTML();
|
||
closeModal();
|
||
$("Password1").value = "";
|
||
$("Password2").value = "";
|
||
if (Str1)
|
||
SetStatus("Password changed successfully");
|
||
else
|
||
SetStatus("Password has been reset successfully");
|
||
SetUsePassword(Str1);
|
||
};
|
||
var MultipleMode = 0;
|
||
|
||
function MyOpenWallet(bCheck) {
|
||
var Str = $("Password").value.trim();
|
||
if (!Str) {
|
||
SetError("Type password, pls");
|
||
return;
|
||
}
|
||
$("Password").value = "";
|
||
if (Str.substr(0, 11) === "--subwallet") {
|
||
Str = Str.substr(11);
|
||
if (Str === " off") {
|
||
Storage.setItem("USESUBWALLET", 0);
|
||
SetStatus("Set off subwallet mode");
|
||
}
|
||
else {
|
||
Storage.setItem("USESUBWALLET", 1);
|
||
SetStatus("Set subwallet mode");
|
||
}
|
||
SetUsePassword(1);
|
||
return;
|
||
}
|
||
if (Str === "--reset") {
|
||
SetWalletPassword("");
|
||
OpenWalletKey();
|
||
SetUsePassword(0);
|
||
NotModalClose = 0;
|
||
closeModal();
|
||
return;
|
||
}
|
||
SetWalletPassword(Str);
|
||
OpenWalletKey();
|
||
SetStatus("");
|
||
if (bCheck) {
|
||
var WasPubKey = Storage.getItem("WALLET_PUB_KEY_MAIN");
|
||
var PrivKey = GetArrFromHex(GetPrivKey());
|
||
var TestPubKey = GetHexFromArr(SignLib.publicKeyCreate(PrivKey, 1));
|
||
if (WasPubKey !== TestPubKey) {
|
||
SetWalletPassword("");
|
||
SetError("Wrong password");
|
||
return;
|
||
}
|
||
SetStatus("Password ok");
|
||
MultipleMode = 0;
|
||
SetVisibleBlock("idKeyEdit", 1);
|
||
SetVisibleBlock("idLoad2", 1);
|
||
SetVisibleBlock("idPasswordEdit", 1);
|
||
}
|
||
else {
|
||
MultipleMode = 1;
|
||
SetVisibleBlock("idKeyEdit", 0);
|
||
SetVisibleBlock("idLoad2", 0);
|
||
SetVisibleBlock("idPasswordEdit", 0);
|
||
}
|
||
NotModalClose = 0;
|
||
closeModal();
|
||
InitPrivKey();
|
||
SetPubKeyHTML();
|
||
SetUsePassword(1);
|
||
};
|
||
|
||
function SetUsePassword(bUse) {
|
||
document.documentElement.style.setProperty('--fill--password', bUse ? 'blue' : 'black');
|
||
SetVisibleBlock("idWalletExit", !!bUse);
|
||
SetVisibleBlock("idEntrance", Storage.getItem("USESUBWALLET") === "1");
|
||
};
|
||
|
||
function DoExitWallet() {
|
||
ClearSend();
|
||
NotModalClose = 1;
|
||
$("Password").value = "";
|
||
SetWalletPassword("");
|
||
OpenWalletKey();
|
||
openModal('password-modal-enter');
|
||
};
|
||
var StrDappCardTemplate;
|
||
var StrDappRowCardTemplate;
|
||
var CardMapList = {};
|
||
|
||
function InitDappsCard() {
|
||
if ($("DappRowCardTemplate")) {
|
||
StrDappRowCardTemplate = $("DappRowCardTemplate").outerHTML;
|
||
$("DappRowCardTemplate").outerHTML = "";
|
||
}
|
||
if ($("DappCardTemplate")) {
|
||
StrDappCardTemplate = $("DappCardTemplate").outerHTML;
|
||
}
|
||
};
|
||
|
||
function ViewDapps() {
|
||
ViewCurrent(DefDapps);
|
||
GetData("/GetDappCategory", {}, function(Data) {
|
||
if (Data && Data.result && Data.arr) {
|
||
var arr = Data.arr;
|
||
for (var i = 0; i < arr.length; i++) {
|
||
var key = arr[i];
|
||
arr[i] = { sort: MapCategory[key].toUpperCase(), text: MapCategory[key], value: key };
|
||
}
|
||
arr.push({ sort: "-", text: "Choose the category", value: 0 });
|
||
FillCategoryAndSort("idCategory", arr);
|
||
}
|
||
});
|
||
};
|
||
|
||
function FillDappCard(Str, Item) {
|
||
CardMapList[Item.Num] = Item;
|
||
Str = Str.replace(/{Item.Num}/g, Item.Num);
|
||
Str = Str.replace("{Item.Name}", escapeHtml(Item.Name));
|
||
Str = Str.replace("{Item.Description}", escapeHtml(Item.Description));
|
||
Str = Str.replace("{Item.Owner}", Item.Owner);
|
||
if (!Item.TokenGenerate)
|
||
Str = Str.replace("dapp-modal__ok-token", "myhidden");
|
||
Str = Str.replace("{Item.IconPath}", RetIconPath(Item, 0));
|
||
return Str;
|
||
};
|
||
|
||
function RetDappCard(Item) {
|
||
var Str = FillDappCard(StrDappRowCardTemplate, Item);
|
||
Str = Str.replace("DappRowCardTemplate", "idCard" + Item.Num);
|
||
return Str;
|
||
};
|
||
|
||
function OpenDappCard(Num) {
|
||
var Item = CardMapList[Num];
|
||
if (!Item)
|
||
return;
|
||
var Str = FillDappCard(StrDappCardTemplate, Item);
|
||
Str = Str.replace("{Item.Account}", RetBaseAccount(Item));
|
||
Str = Str.replace("{Item.BlockNum}", RetOpenBlock(Item.BlockNum, 2));
|
||
Str = FillDappCategory(Str, Item, 1);
|
||
Str = FillDappCategory(Str, Item, 2);
|
||
Str = FillDappCategory(Str, Item, 3);
|
||
$("DappCardTemplate").outerHTML = Str;
|
||
openModal('DappCardTemplate');
|
||
};
|
||
|
||
function OpenDapp(Num) {
|
||
OpenDapps(Num);
|
||
closeModal();
|
||
};
|
||
|
||
function FillDappCategory(Str, Item, Num) {
|
||
var Value = Item["Category" + Num];
|
||
if (Value && MapCategory[Value]) {
|
||
Str = Str.replace("{Item.Category" + Num + "}", MapCategory[Value]);
|
||
}
|
||
else {
|
||
Str = Str.replace("dappcategory" + Num, "myhidden");
|
||
}
|
||
return Str;
|
||
};
|
||
|
||
function MyToggleList(e) {
|
||
var item = e.target;
|
||
while (true) {
|
||
if (!item)
|
||
break;
|
||
if (!item.classList)
|
||
break;
|
||
if (item.onclick && item.onclick !== MyToggleList)
|
||
break;
|
||
if (item.classList.contains("find--switch")) {
|
||
if (item.classList.contains("prod-card--switch")) {
|
||
item.classList.add("prod-card--active");
|
||
item.classList.add("prod-card--toggle");
|
||
item.classList.remove("prod-card--switch");
|
||
}
|
||
else {
|
||
item.classList.remove("prod-card--active");
|
||
item.classList.remove("prod-card--toggle");
|
||
item.classList.add("prod-card--switch");
|
||
}
|
||
break;
|
||
}
|
||
item = item.parentNode;
|
||
}
|
||
};
|
||
var LangItems = [];
|
||
|
||
function InitLangItems() {
|
||
var tags = ["TITLE", "BUTTON", "DIV", "INPUT", "TH", "TD", "SPAN", "A", "H1", "H2", "H3", "H4", "H5", "P", "DT"];
|
||
var Map2 = {};
|
||
for (var n = 0; n < tags.length; n++) {
|
||
var tagname = tags[n];
|
||
var elems = document.getElementsByTagName(tagname);
|
||
for (var elem, i = 0; elem = elems[i++];) {
|
||
var Text = elem.innerText;
|
||
if (elem.innerHTML !== Text)
|
||
continue;
|
||
if (!Text)
|
||
continue;
|
||
if (Text.substr(0, 1) === "{")
|
||
continue;
|
||
if (Text.toUpperCase() == Text.toLowerCase())
|
||
continue;
|
||
LangItems.push({ key: Text, elem: elem });
|
||
}
|
||
}
|
||
};
|
||
|
||
function DoLangItems(Map) {
|
||
var Map2 = {};
|
||
for (var n = 0; n < LangItems.length; n++) {
|
||
var key = LangItems[n].key;
|
||
var elem = LangItems[n].elem;
|
||
if (Map) {
|
||
var TextNew = Map[key];
|
||
if (TextNew === undefined) {
|
||
ToLog("Not found translate for key: " + key);
|
||
Map[key] = key;
|
||
TextNew = key;
|
||
}
|
||
if (elem.innerText !== TextNew) {
|
||
elem.innerText = TextNew;
|
||
}
|
||
}
|
||
else {
|
||
Map2[key] = key;
|
||
}
|
||
}
|
||
return Map2;
|
||
};
|
||
|
||
function DoLangScript() {
|
||
InitLangItems();
|
||
LangMap["ENG"] = DoLangItems();
|
||
FillSelect("idLang", LangMap, "KEY");
|
||
};
|
||
|
||
function ChangeLang() {
|
||
var key = $("idLang").value;
|
||
if (!key) {
|
||
key = "ENG";
|
||
$("idLang").value = key;
|
||
}
|
||
DoLangItems(LangMap[key]);
|
||
SaveValues();
|
||
};
|
||
|
||
function GetNewLangItem() {
|
||
ToLog(JSON.stringify(LangMap["ENG"]));
|
||
};
|
||
var LangMap = {};
|
||
LangMap["ENG"] = {};
|
||
LangMap["RUS"] = {
|
||
"TERA WALLET": "TERA КОШЕЛЕК", "Generate key": "Сгенерировать ключ", "OK": "OK", "Cancel": "Отмена", "Edit": "Редактирование",
|
||
"Save key": "Сохран.", "+ CREATE A NEW ACCOUNT": "+ СОЗДАТЬ НОВЫЙ СЧЕТ", "Create account": "Создать счет", "Send": "Отправить",
|
||
"CONFIRM": "Подтверждение", "Accounts": "Счета", "Account(s)": "Счет(а,ов)", "Blocks and Tx": "Блоки и Транзакции", "Counters": "Показатели",
|
||
"Open DApp": "Открыть Дапп", "Back": "Назад", "Delete": "Удалить", "Save to book": "Сохранить в книгу", "Choose": "Выбрать", "RECONNECT": "КОННЕКТ",
|
||
"DApps": "ДАппс", "ID": "ИД", "Amount": "Величина", "Cur": "Вал", "Name": "Имя", "PubKey": "Пуб.ключ", "Operation": "Операция", "Smart": "Смарт",
|
||
"Block Num": "Ном блока", "Num": "Ном", "Date": "Дата", "Data Hash": "Хеш данных", "PowHash": "Хеш сложности", "Block Hash": "Хеш блока",
|
||
"Bytes": "Байт", "Pow": "Сложн", "Miner": "Майнер", "(secret)": "(секрет)", "Show": "Показать", "TERA": "TERA", "Blockchain height:": "Высота блокчейна:",
|
||
"Current create:": "Текущий блок:", "Protocol ver:": "Версия протокола:", "ID: {Item.Num}": "ИД: {Item.Num}", "Token generate": "Генерация токенов",
|
||
"ACCOUNTS": "СЧЕТА", "SEND": "ПОСЛАТЬ", "DAPPS": "ДАППС", "EXPLORER": "ПРОСМ", "ATTENTION: Before using the wallet, save the private key.": "ВНИМАНИЕ: Перед использованием кошелька сохраните приватный ключ",
|
||
"Web-site": "Веб-сайт", "Bitcointalk": "Bitcointalk", "Twitter": "Твиттер", "Telegram": "Телеграм", "Discord": "Дискорд", "QQchat": "QQchat",
|
||
"Buy/sell/mine TERA": "Купить/Продать", "+ CREATE NEW": "+ СОЗДАТЬ НОВЫЙ", "Confirm Transaction": "Подтверждение транзакции",
|
||
"CREATE DAPPS": "СОЗДАТЬ", "Set pass": "Установить пароль", "Unlock": "Разблокировать", "Entrance to sub-wallet": "Войти в под-кошелек",
|
||
"Public name": "Публичное имя", "Currency": "Валюта", "Pay to:": "Получатель:", "Amount:": "Сумма:", "Description:": "Описание:",
|
||
"Welcome to TERA Wallet": "Добропожаловать в кошелек TERA", "Edit your wallet": "Редактирование вашего кошелька", "Key settings": "Задание ключей",
|
||
"KEY SETTINGS": "ЗАДАНИЕ КЛЮЧЕЙ", "Create an account": "Создание счета", "Sending coins": "Отправка монет", "Decentralized applications (dApps)": "Децентрализованные приложения (Даппс)",
|
||
"Secure your wallet": "Безопасность вашего кошелька", "Wallet is secured": "Установлен пароль", "Total": "Всего", "Item.Name": "Item.Name",
|
||
"You have no accounts yet": "У вас нет ни одного счета", "Wait 10-15 sec": "Ждите 10-15 сек", "Creating your account": "Идет создание вашего счета",
|
||
"From:": "Отправитель:", "Set a password for protect entry": "Установите пароль для безопасности", "Enter password to unlock wallet": "Введите пароль для разблокировки кошелька",
|
||
"From ID:": "Отправитель:", "Pay to ID:": "Получатель:", "Account": "Счет", "Owner": "Владелец", "Block num": "Ном блока", "Private key (secret)": "Приватный ключ (секретно)",
|
||
"Load key": "Загруз.", "Create your first account and start using TERA": "Создайте свой первый счет и начните использовать TERA",
|
||
"0 Accounts": "0 Счетов", "OWNER: {Item.Owner}": "Владелец: {Item.Owner}", "More info": "Информация", "Public key": "Публичный ключ"
|
||
};
|
||
LangMap["简体中文"] = {
|
||
"TERA WALLET": "TERA 钱包", "Generate key": "生成私钥", "OK": "OK", "Cancel": "取消", "Edit": "编辑", "Save key": "保存私钥",
|
||
"+ CREATE A NEW ACCOUNT": "+ 新建账号", "Create account": "创建账号", "Send": "发送", "SEND": "转账", "CONFIRM": "确认", "Accounts": "账号", "Account(s)": "账号",
|
||
"Blocks and Tx": "区块和交易", "Counters": "状态统计", "Open DApp": "打开DApp", "Back": "返回", "Delete": "删除", "Save to book": "保存到地址本", "Choose": "选择",
|
||
"RECONNECT": "重连", "DApps": "DApps", "ID": "ID", "Amount": "余额", "Cur": "币种", "Name": "名称", "PubKey": "公钥", "Operation": "操作次数", "Smart": "DApp",
|
||
"Block Num": "区块编号", "Num": "编号", "Date": "日期", "Data Hash": "数据哈希", "PowHash": "Pow哈希", "Block Hash": "区块哈希", "Bytes": "字节", "Pow": "Pow",
|
||
"Miner": "矿工", "(secret)": "(机密)", "Show": "显示", "TERA": "TERA", "Blockchain height:": "区块高度:", "Current create:": "最近区块:", "Protocol ver:": "协议版本:",
|
||
"ID: {Item.Num}": "ID: {Item.Num}", "Token generate": "生成代币", "ACCOUNTS": "账号", "DAPPS": "DAPPS", "EXPLORER": "浏览器", "ATTENTION: Before using the wallet, save the private key.": "注意: 使用钱包前,务必保存好私钥。",
|
||
"Web-site": "官网", "Bitcointalk": "创世贴", "Twitter": "推特", "Telegram": "电报", "Discord": "Discord", "QQchat": "QQ群", "Buy/sell/mine TERA": "TERA 交易/挖矿",
|
||
"+ CREATE NEW": "+ 新建", "Confirm Transaction": "确认交易", "CREATE DAPPS": "创建DAPPS", "Set pass": "设置密码", "Unlock": "解锁", "Entrance to sub-wallet": "进入子钱包",
|
||
"Public name": "名称", "Currency": "币种", "Pay to:": "收款:", "Amount:": "金额:", "Description:": "描述:", "Welcome to TERA Wallet": "欢迎使用TERA钱包",
|
||
"Edit your wallet": "编辑钱包", "Key settings": "设置私钥", "KEY SETTINGS": "设置私钥", "Create an account": "创建账号", "Sending coins": "转账",
|
||
"Decentralized applications (dApps)": "去中心化应用 (DApps)", "Secure your wallet": "设置钱包密码", "Wallet is secured": "钱包密码已设置", "Total": "总计",
|
||
"Item.Name": "Item.Name", "You have no accounts yet": "你还没有账号", "Wait 10-15 sec": "等待10-15秒", "Creating your account": "创建你的账号",
|
||
"From:": "付款:", "Set a password for protect entry": "设置密码保护钱包", "Enter password to unlock wallet": "输入密码解锁钱包", "From ID:": "付款ID:",
|
||
"Pay to ID:": "收款ID:", "Account": "账号", "Owner": "拥有者", "Block num": "区块编号", "Private key (secret)": "私钥 (机密)", "Load key": "载入私钥",
|
||
"Create your first account and start using TERA": "创建你的第一个账号,开启TERA之旅", "0 Accounts": "0 账号", "OWNER: {Item.Owner}": "拥有者: {Item.Owner}",
|
||
"More info": "详情", "Public key": "公钥"
|
||
};
|