From de9a82569a5276cffbb3e84c2ba35b62f7cd69b4 Mon Sep 17 00:00:00 2001 From: Enrique Souza Date: Mon, 3 May 2021 00:33:10 -0400 Subject: [PATCH 1/2] chat changes --- src/application/lib/sapi.js | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/src/application/lib/sapi.js b/src/application/lib/sapi.js index f66e3a9..b83fbcc 100644 --- a/src/application/lib/sapi.js +++ b/src/application/lib/sapi.js @@ -10,7 +10,7 @@ const LOCKED = 'pubkeyhashlocked'; //const OP_RETURN_DEFAULT = 'Sent from SmartHub.'; const MIN_FEE = 0.001; const MIN_AMOUNT_TO_SEND = 0.001; - +const SAPI_SERVERS_KEY = 'sapiServers'; const random = require('random'); const ping = (url, timeout = 2000) => { @@ -32,16 +32,16 @@ const ping = (url, timeout = 2000) => { export async function getEnabledNodes() { try { - const localServers = ipcRenderer.sendSync('getSapiServers'); - if (localServers) return JSON.parse(ipcRenderer.sendSync('getSapiServers')); + const localServers = window.sessionStorage.getItem(SAPI_SERVERS_KEY); + if (localServers) return JSON.parse(window.sessionStorage.getItem(SAPI_SERVERS_KEY)); const nodes = await request.get(`https://sapi.smartcash.cc/v1/smartnode/check/ENABLED`, { json: true, cache: true, }); const servers = nodes.map((node) => 'http://' + node.ip.replace(':9678', ':8080')); - ipcRenderer.send('setSapiServers', JSON.stringify(servers)); - return JSON.parse(ipcRenderer.sendSync('getSapiServers')); + window.sessionStorage.setItem(SAPI_SERVERS_KEY, JSON.stringify(servers)); + return JSON.parse(window.sessionStorage.getItem(SAPI_SERVERS_KEY)); } catch (err) { console.error(err); } @@ -740,7 +740,7 @@ export async function activateRewards(toAddress, unspentList, privateKey, passwo export async function sendTransaction(hex, isChat) { //Chat needs the same NODE always to get MEM POOL transactions - const url = isChat ? 'https://sapi.smartcash.cc' : await GetSapiUrl(); + const url = await GetSapiUrl(); var options = { method: 'POST', uri: `${url}/v1/transaction/send`, @@ -772,11 +772,10 @@ export async function sendTransaction(hex, isChat) { } export async function calculateChatFee({ messageOpReturn, unspentList, rsaKeyPairFromSender, rsaKeyPairFromRecipient }) { - -// This is needed if we expand past 450 characters for chat messages. -// let encryptedChatMessage = encryptTextWithRSAPublicKey(rsaKeyPairFromSender.rsaPublicKey, messageOpReturn) -// return await calculateFee(unspentList, encryptedChatMessage); - return 0.002 + // This is needed if we expand past 450 characters for chat messages. + // let encryptedChatMessage = encryptTextWithRSAPublicKey(rsaKeyPairFromSender.rsaPublicKey, messageOpReturn) + // return await calculateFee(unspentList, encryptedChatMessage); + return 0.002; } export async function calculateFee(listUnspent, messageOpReturn) { @@ -785,15 +784,7 @@ export async function calculateFee(listUnspent, messageOpReturn) { let newFee = 0.001 * - Math.round( - 1.27 + - (countUnspent * 148 + - 2 * 34 + - 10 + - 9 + - (messageOpReturn ? 34 + messageOpReturn.length : 0))/ - 1024 - ); + Math.round(1.27 + (countUnspent * 148 + 2 * 34 + 10 + 9 + (messageOpReturn ? 34 + messageOpReturn.length : 0)) / 1024); return newFee; } From f8887f1683548cfe7980230bde2e0db0a257937f Mon Sep 17 00:00:00 2001 From: Enrique Souza Date: Mon, 3 May 2021 00:46:37 -0400 Subject: [PATCH 2/2] chat changes --- src/application/lib/sapi.js | 29 +---------------------------- 1 file changed, 1 insertion(+), 28 deletions(-) diff --git a/src/application/lib/sapi.js b/src/application/lib/sapi.js index 294d4db..208b62c 100644 --- a/src/application/lib/sapi.js +++ b/src/application/lib/sapi.js @@ -773,41 +773,14 @@ export async function sendTransaction(hex, isChat) { } export async function calculateChatFee({ messageOpReturn, unspentList, rsaKeyPairFromSender, rsaKeyPairFromRecipient }) { - // This is needed if we expand past 450 characters for chat messages. -<<<<<<< HEAD - // let encryptedChatMessage = encryptTextWithRSAPublicKey(rsaKeyPairFromSender.rsaPublicKey, messageOpReturn) - // return await calculateFee(unspentList, encryptedChatMessage); - return 0.002; -======= -/* let encryptedChatMessage = encryptTextWithRSAPublicKey(rsaKeyPairFromRecipient.rsaPublicKey, messageOpReturn); - - if (!encryptedChatMessage || encryptedChatMessage.length === 0) return MIN_FEE_CHAT; - - return await calculateFee(unspentList, encryptedChatMessage);*/ return MIN_FEE_CHAT; ->>>>>>> 652661073756f81b847385f60f9f303fbcd59016 } export async function calculateFee(listUnspent, messageOpReturn) { -/* if (!listUnspent || listUnspent.length === 0) return MIN_FEE; - let countUnspent = listUnspent.length; - - let newFee = -<<<<<<< HEAD - 0.001 * - Math.round(1.27 + (countUnspent * 148 + 2 * 34 + 10 + 9 + (messageOpReturn ? 34 + messageOpReturn.length : 0)) / 1024); - - return newFee; -======= - MIN_FEE * - Math.round(1.27 + (countUnspent * 148 + 2 * 34 + 10 + 9 + (messageOpReturn ? 34 + messageOpReturn.length : 0)) / 1024); - - return newFee;*/ if (listUnspent.length < 4) return MIN_FEE; if (listUnspent.length < 20) return 0.002; if (listUnspent.length < 50) return 0.004; - return 0.010; ->>>>>>> 652661073756f81b847385f60f9f303fbcd59016 + return 0.01; } function roundUp(num, precision) {