diff --git a/assets/eco-scripts/activity_localStorage.js b/assets/eco-scripts/activity_localStorage.js new file mode 100644 index 00000000..438527ba --- /dev/null +++ b/assets/eco-scripts/activity_localStorage.js @@ -0,0 +1,34 @@ +function getActivitiesFromLocalStorage() { + var actitiviesRelayedTxs = getLocalStorage("myactivities"); + if (actitiviesRelayedTxs) + return JSON.parse(actitiviesRelayedTxs) + + return new []; +} + +function storeActivitiesToLocalStorage() { + setLocalStorage("myactivities", JSON.stringify(RELAYED_TXS)); +} + +function restoreRelayedTxsFromLocalStorage() { + RELAYED_TXS = getActivitiesFromLocalStorage(); + drawRelayedTXs(); +} + +function cleanAllRelayedTxs() { + swal({ + title: "Delete all Relayed Txs activity?", + text: "This is permanent and you won't be able to retrieve it.", + icon: "warning", + buttons: ["Cancel", "Delete it!"], + dangerMode: true, + }).then((willDelete) => { + if (willDelete) { + RELAYED_TXS = []; + storeActivitiesToLocalStorage(); + drawRelayedTXs(); + } else { + swal("Safe! Relayed TXs are preserved."); + } + }); +} \ No newline at end of file diff --git a/assets/eco-scripts/contracts.js b/assets/eco-scripts/contracts.js index 26122964..95d2fa77 100644 --- a/assets/eco-scripts/contracts.js +++ b/assets/eco-scripts/contracts.js @@ -370,7 +370,7 @@ function deleteLocalContract() { }); } -function invokeFunctionWithParams(contractHash, method, params, relay = false) { +function invokeFunctionWithParams(contractHash, method, params, relay) { if (!checkIfWalletIsConnected()) return; @@ -443,7 +443,8 @@ function invokeFunction() { params.push(parameter); } - invokeFunctionWithParams(CONTRACTS_TO_LIST[getCurrentSelectedContract()].hash, method.name, params); + var autoRelay = false; + invokeFunctionWithParams(CONTRACTS_TO_LIST[getCurrentSelectedContract()].hash, method.name, params, autoRelay); } function findNetworkFee() { @@ -527,7 +528,8 @@ function deployContract() { var expectedContractHash = Neon.experimental.getContractHash(sender, checkSum, LOCAL_CONTRACTS[contractToDeployID].manifest.name); PENDING_CONTRACTS.push(expectedContractHash); - invokeFunctionWithParams(contractManagementHash, "deploy", params) + var autoRelay = false; + invokeFunctionWithParams(contractManagementHash, "deploy", params, autoRelay) } function getNep17HashByName(name) { diff --git a/assets/eco-scripts/rawRpc.js b/assets/eco-scripts/rawRpc.js index c6faf3fb..7545340a 100644 --- a/assets/eco-scripts/rawRpc.js +++ b/assets/eco-scripts/rawRpc.js @@ -26,15 +26,17 @@ function rawRpcCall(fillRealTx = false, saveID = -1, relay = false, blinkRelay = fillRealTxFromInvokeFunction(); if (saveID != -1) + { + // updates saved tx with input RELAYED_TXS[saveID].push(data); + storeActivitiesToLocalStorage(); + } if (relay) { - signAndRelay(false); + signAndRelay(); } else { if (blinkRelay && fillRealTx) { - $('#signAndRelayDivCollapse').collapse('show'); - $("#relay_btn")[0].disabled = false; - addBlinkToElement("#relay_btn"); + enableSignRelayAndBlink(); } else { $("#relay_btn")[0].disabled = true; $('#signAndRelayDivCollapse').collapse('hide'); @@ -47,6 +49,12 @@ function rawRpcCall(fillRealTx = false, saveID = -1, relay = false, blinkRelay = }); //End of POST for search } +function enableSignRelayAndBlink() { + $('#signAndRelayDivCollapse').collapse('show'); + $("#relay_btn")[0].disabled = false; + addBlinkToElement("#relay_btn"); +} + function drawSigners() { var table = document.createElement("tbody"); var headerRow = document.createElement('tr'); @@ -110,10 +118,11 @@ function cleanRealTxInvoke() { document.getElementById("tableSigners").innerHTML = ""; } -function signAndRelay(blinkRelay = true) { +function signAndRelay() { if (!checkIfWalletIsConnected()) return; + //Network fee should be passed to DAPI var netFee = Math.ceil(getFixed8Integer($("#net_fee")[0].value)); //============================================ //This is dapi call from parameters @@ -133,8 +142,6 @@ function signAndRelay(blinkRelay = true) { //============================================ var sysFee = Math.ceil(getFixed8Integer($("#sys_fee")[0].value)); - //var sysFee = getFixed8Integer(500); - //var netFee = getFixed8Integer(600); var validUntil = Number($("#valid_until")[0].value); var script = $("#tx_script")[0].value; @@ -161,29 +168,32 @@ function signAndRelay(blinkRelay = true) { invokeFunction: $("#txtRPCJson").val(), invokeFunctionOut: $("#txtRPCJsonOut").val() }); + + // Create Field for TXs RELAYED_TXS.push(relayedTX); + storeActivitiesToLocalStorage(); - - console.log(tx) - console.log(tx.serialize(true)) + //console.log(tx) + //console.log(tx.serialize(true)) var rawTX = Neon.u.hex2base64(tx.serialize(true)); - var jsonForInvokingFunction = { "jsonrpc": "2.0", "id": 2, "method": "sendrawtransaction", "params": [rawTX] }; - var jsonToCallStringified = JSON.stringify(jsonForInvokingFunction); + $("#txtRPCJson").val(jsonToCallStringified); - rawRpcCall(false, RELAYED_TXS.length - 1, false, blinkRelay); - //var client = new Neon.rpc.RPCClient(BASE_PATH_CLI); - //RELAYED_TXS.push(client.sendRawTransaction(tx)); + var fillRealTx = false; + var autoRelay = false; + var autoBlink = false; + var savedTXID = RELAYED_TXS.length - 1; + rawRpcCall(fillRealTx, savedTXID, autoRelay, autoBlink); } -function signTx(tx){ +function signTx(tx) { if (isMultiSig(CONNECTED_WALLET_ID)) { var publicKeys = Neon.wallet.getPublicKeysFromVerificationScript(Neon.u.base642hex(ECO_WALLET[CONNECTED_WALLET_ID].account.contract.script)) var threshold = Neon.wallet.getSigningThresholdFromVerificationScript(Neon.u.base642hex(ECO_WALLET[CONNECTED_WALLET_ID].account.contract.script)) diff --git a/assets/eco-scripts/relayed_txs.js b/assets/eco-scripts/relayed_txs.js index 9b518118..d0ef5650 100644 --- a/assets/eco-scripts/relayed_txs.js +++ b/assets/eco-scripts/relayed_txs.js @@ -179,8 +179,9 @@ function removeRelayedTX(idToRemove) { //=============================================================== function restoreTX(idToRestore) { + console.log(idToRestore) var txToRestore = RELAYED_TXS[idToRestore]; - //console.log(txToRestore); + console.log(txToRestore); document.getElementById("tableSigners").appendChild(txToRestore[0].signers); $("#sys_fee")[0].value = txToRestore[0].sysfee; @@ -191,5 +192,8 @@ function restoreTX(idToRestore) { $("#txtRPCJsonOut")[0].value = txToRestore[0].invokeFunctionOut; goToTabAndClick("nav-rpc"); + + if (checkIfWalletIsConnected()) + enableSignRelayAndBlink(); } //=============================================================== diff --git a/assets/eco-scripts/wallet_center.js b/assets/eco-scripts/wallet_center.js index 787a4123..f98dcc08 100644 --- a/assets/eco-scripts/wallet_center.js +++ b/assets/eco-scripts/wallet_center.js @@ -783,7 +783,8 @@ function createNep17Tx() { var contractHash = getNep17HashByName($("#labelForTransferAsset")[0].textContent); var method = "transfer"; - invokeFunctionWithParams(contractHash, method, params); + var autoRelay = false; + invokeFunctionWithParams(contractHash, method, params, autoRelay); swal({ icon: "success", diff --git a/index.html b/index.html index 020b5191..348f744c 100644 --- a/index.html +++ b/index.html @@ -574,7 +574,7 @@