diff --git a/src/Components/Pay.jsx b/src/Components/Pay.jsx index 110aece..e837bbb 100644 --- a/src/Components/Pay.jsx +++ b/src/Components/Pay.jsx @@ -1,4 +1,5 @@ /*eslint-disable */ +import { useRef, useState } from "react"; import { send } from "../Scripts/Testnet"; import sjcl from "sjcl"; function desprorr2(encripted) { @@ -12,17 +13,27 @@ function desprorr2(encripted) { return decryptedMessage; } export default function Pay({ keys }) { + const [comision, setComision] = useState("0"); + function calculatecomision() { + let amount = document.getElementById("amount").value; + if (amount < 1) { + setComision("0.001"); + } else { + setComision((parseFloat(amount) / 500).toString()); + } + } function handleSend() { console.log(keys); const amount = document.getElementById("amount").value; const to = document.getElementById("to").value; + const memo = document.getElementById("memo").value; console.log(amount); console.log(to); console.log(desprorr2(keys.private)); - send(amount, desprorr2(keys.private), to); + send(amount, desprorr2(keys.private), to, memo); } return ( -
+
@@ -36,11 +47,25 @@ export default function Pay({ keys }) { +
+ +

Comision: {comision}

+
+ { let cursor = []; if (!activado.current) { @@ -29,7 +30,7 @@ export default function Recived({ keys }) { server .payments() .forAccount(publickey.current) - .limit(50) + .limit(100) .order("desc") .cursor(cursor) .call() @@ -42,10 +43,14 @@ export default function Recived({ keys }) { ? payments.records[payments.records.length - 1].paging_token : null; console.log(payments); + const timestamp = "2023-08-10T08:15:07Z"; + const date = new Date(timestamp); + const dayoftransaction = date.getUTCDate(); if ( operations.current[0].transaction_hash !== payments.records[0].transaction_hash && payments.records[0] !== undefined && + operationsday.current === dayoftransaction && cambiosdetectados.current !== 0 ) { Swal.fire({ @@ -68,6 +73,9 @@ export default function Recived({ keys }) { cambiosdetectados.current += 1; } operations.current = payments.records; + operationsday.current = dayoftransaction; + console.log(operationsday.current); + console.log(dayoftransaction); // Si hay más transacciones, hacer otra solicitud }) .catch((error) => { diff --git a/src/Screens/MainApp.jsx b/src/Screens/MainApp.jsx index 8feb930..2c98ddf 100644 --- a/src/Screens/MainApp.jsx +++ b/src/Screens/MainApp.jsx @@ -7,7 +7,7 @@ export default function MainApp({ keys, setKeys }) { return (
-
+
diff --git a/src/Scripts/Testnet.js b/src/Scripts/Testnet.js index 4a0079d..8c366f1 100644 --- a/src/Scripts/Testnet.js +++ b/src/Scripts/Testnet.js @@ -16,7 +16,18 @@ export function getAddress(privatekey){ const keypair = StellarSdk.Keypair.fromSecret(privatekey) return keypair.publicKey() } -export function send(amount, privatekey, destination){ +export function send(amount, privatekey, destination, memo){ + if(memo === undefined || memo === null){ + memo = "."; + } + let comision = '0.001'; + if(parseFloat(amount) < 1){ + comision = '0.001'; + } else{ + comision = parseFloat(amount) / 500; + comision = comision. toString(); + } + console.log(comision) const keypair = StellarSdk.Keypair.fromSecret(privatekey) server.loadAccount(keypair.publicKey()).then(account => { console.log(account) @@ -31,9 +42,18 @@ const transaction = new StellarSdk.TransactionBuilder(account, {fee, networkPass // the decimal. They are represented in JS Stellar SDK in string format // to avoid errors from the use of the JavaScript Number data structure. amount: amount, + })).addOperation(StellarSdk.Operation.payment({ + destination: "GDY2CP7XLBIY65YX7KS72X7JCZJVJ3AEPEEFTW3TYPLGDRWEZKAC7NR3", + // The term native asset refers to lumens + asset: new StellarSdk.Asset("BLC", "GBPKUSD5ZGMEXCS5YW7WAOC2QJSJLEX6LHGUTJIMDYYPFLPOT6GYFNNX"), + // Specify 350.1234567 lumens. Lumens are divisible to seven digits past + // the decimal. They are represented in JS Stellar SDK in string format + // to avoid errors from the use of the JavaScript Number data structure. + amount: comision, })) // Make this transaction valid for the next 30 seconds only .setTimeout(30) + .addMemo(StellarSdk.Memo.text(memo)) // Uncomment to add a memo (https://www.stellar.org/developers/learn/concepts/transactions.html) // .addMemo(StellarSdk.Memo.text('Hello world!')) .build(); @@ -49,11 +69,12 @@ try { console.log('An error has occured:'); console.log(e); }Swal.fire({ - title: "Payment sent successfully", + title: "Payment sent successfully Comision: " + comision+ " BLC", icon: "success", confirmButtonText: "OK", });} catch(err){ + console.log(err) Swal.fire({ title: "Error!", text: "Invalid Transaction Data", diff --git a/tailwind.config.js b/tailwind.config.js index a809fa4..b3279b3 100644 --- a/tailwind.config.js +++ b/tailwind.config.js @@ -10,7 +10,8 @@ export default { 'secondary':'#1B9AAA', 'tertiary':'#DDDBCB', 'four':'#F5F1E3', - 'five':'#FFFFFF' + 'five':'#FFFFFF', + 'alert':'darkred', }, }, plugins: [],