This commit is contained in:
Prrorr2 2023-08-10 11:02:16 +02:00
parent 1aa1517f93
commit e38afa8b9a
6 changed files with 66 additions and 11 deletions

View File

@ -1,4 +1,5 @@
/*eslint-disable */ /*eslint-disable */
import { useRef, useState } from "react";
import { send } from "../Scripts/Testnet"; import { send } from "../Scripts/Testnet";
import sjcl from "sjcl"; import sjcl from "sjcl";
function desprorr2(encripted) { function desprorr2(encripted) {
@ -12,17 +13,27 @@ function desprorr2(encripted) {
return decryptedMessage; return decryptedMessage;
} }
export default function Pay({ keys }) { 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() { function handleSend() {
console.log(keys); console.log(keys);
const amount = document.getElementById("amount").value; const amount = document.getElementById("amount").value;
const to = document.getElementById("to").value; const to = document.getElementById("to").value;
const memo = document.getElementById("memo").value;
console.log(amount); console.log(amount);
console.log(to); console.log(to);
console.log(desprorr2(keys.private)); console.log(desprorr2(keys.private));
send(amount, desprorr2(keys.private), to); send(amount, desprorr2(keys.private), to, memo);
} }
return ( return (
<div className="h-3/6 w-2/6 min-h-[20rem] bg-secondary self-center ml-[10rem] rounded-2xl flex flex-col gap-5 justify-center"> <div className="h-3/6 w-2/6 min-h-[25rem] bg-secondary self-center ml-[10rem] rounded-2xl flex flex-col gap-5 justify-center">
<label htmlFor="send2" className="font-bold text-3xl self-center"> <label htmlFor="send2" className="font-bold text-3xl self-center">
Send to: Send to:
</label> </label>
@ -36,11 +47,25 @@ export default function Pay({ keys }) {
<label htmlFor="amount" className="font-bold text-3xl self-center"> <label htmlFor="amount" className="font-bold text-3xl self-center">
BLC Amount: BLC Amount:
</label> </label>
<div className="self-center h-[2rem] w-3/6 flex flex-col justify-center gap-1 m-2">
<input
id="amount"
name="amount"
className="self-center w-full border-4 border-tertiary rounded-md"
type="number"
onChange={calculatecomision}
/>
<p className="text-alert self-center text-sm">Comision: {comision}</p>
</div>
<label htmlFor="send2" className="font-bold text-3xl self-center">
Extra comment:
</label>
<input <input
id="amount" name="memo"
name="amount" id="memo"
className="h-[2rem] w-3/6 self-center border-4 border-tertiary rounded-md" className="h-[2rem] w-3/6 self-center border-4 border-tertiary rounded-md"
type="number" placeholder="Example: Buy a great coffee"
type="text"
/> />
<input <input
name="submit" name="submit"

View File

@ -27,7 +27,7 @@ export default function Transactions({ keys }) {
server server
.payments() .payments()
.forAccount(publickey.current) .forAccount(publickey.current)
.limit(50) .limit(100)
.order("desc") .order("desc")
.cursor(cursor) .cursor(cursor)
.call() .call()

View File

@ -22,6 +22,7 @@ export default function Recived({ keys }) {
const activado = useRef(false); const activado = useRef(false);
const cambiosdetectados = useRef(0); const cambiosdetectados = useRef(0);
const operations = useRef([{ transaction_hash: 0 }]); const operations = useRef([{ transaction_hash: 0 }]);
const operationsday = useRef(0);
useEffect(() => { useEffect(() => {
let cursor = []; let cursor = [];
if (!activado.current) { if (!activado.current) {
@ -29,7 +30,7 @@ export default function Recived({ keys }) {
server server
.payments() .payments()
.forAccount(publickey.current) .forAccount(publickey.current)
.limit(50) .limit(100)
.order("desc") .order("desc")
.cursor(cursor) .cursor(cursor)
.call() .call()
@ -42,10 +43,14 @@ export default function Recived({ keys }) {
? payments.records[payments.records.length - 1].paging_token ? payments.records[payments.records.length - 1].paging_token
: null; : null;
console.log(payments); console.log(payments);
const timestamp = "2023-08-10T08:15:07Z";
const date = new Date(timestamp);
const dayoftransaction = date.getUTCDate();
if ( if (
operations.current[0].transaction_hash !== operations.current[0].transaction_hash !==
payments.records[0].transaction_hash && payments.records[0].transaction_hash &&
payments.records[0] !== undefined && payments.records[0] !== undefined &&
operationsday.current === dayoftransaction &&
cambiosdetectados.current !== 0 cambiosdetectados.current !== 0
) { ) {
Swal.fire({ Swal.fire({
@ -68,6 +73,9 @@ export default function Recived({ keys }) {
cambiosdetectados.current += 1; cambiosdetectados.current += 1;
} }
operations.current = payments.records; operations.current = payments.records;
operationsday.current = dayoftransaction;
console.log(operationsday.current);
console.log(dayoftransaction);
// Si hay más transacciones, hacer otra solicitud // Si hay más transacciones, hacer otra solicitud
}) })
.catch((error) => { .catch((error) => {

View File

@ -7,7 +7,7 @@ export default function MainApp({ keys, setKeys }) {
return ( return (
<div className={"bg-five w-full h-full"}> <div className={"bg-five w-full h-full"}>
<Header keys={keys} setKeys={setKeys} /> <Header keys={keys} setKeys={setKeys} />
<div className="flex flex-row w-full h-5/6"> <div className="flex flex-row w-full h-5/6 justify-center">
<Transactions keys={keys} /> <Transactions keys={keys} />
<Pay keys={keys} /> <Pay keys={keys} />
<Recived keys={keys} /> <Recived keys={keys} />

View File

@ -16,7 +16,18 @@ export function getAddress(privatekey){
const keypair = StellarSdk.Keypair.fromSecret(privatekey) const keypair = StellarSdk.Keypair.fromSecret(privatekey)
return keypair.publicKey() 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) const keypair = StellarSdk.Keypair.fromSecret(privatekey)
server.loadAccount(keypair.publicKey()).then(account => { server.loadAccount(keypair.publicKey()).then(account => {
console.log(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 // the decimal. They are represented in JS Stellar SDK in string format
// to avoid errors from the use of the JavaScript Number data structure. // to avoid errors from the use of the JavaScript Number data structure.
amount: amount, 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 // Make this transaction valid for the next 30 seconds only
.setTimeout(30) .setTimeout(30)
.addMemo(StellarSdk.Memo.text(memo))
// Uncomment to add a memo (https://www.stellar.org/developers/learn/concepts/transactions.html) // Uncomment to add a memo (https://www.stellar.org/developers/learn/concepts/transactions.html)
// .addMemo(StellarSdk.Memo.text('Hello world!')) // .addMemo(StellarSdk.Memo.text('Hello world!'))
.build(); .build();
@ -49,11 +69,12 @@ try {
console.log('An error has occured:'); console.log('An error has occured:');
console.log(e); console.log(e);
}Swal.fire({ }Swal.fire({
title: "Payment sent successfully", title: "Payment sent successfully Comision: " + comision+ " BLC",
icon: "success", icon: "success",
confirmButtonText: "OK", confirmButtonText: "OK",
});} });}
catch(err){ catch(err){
console.log(err)
Swal.fire({ Swal.fire({
title: "Error!", title: "Error!",
text: "Invalid Transaction Data", text: "Invalid Transaction Data",

View File

@ -10,7 +10,8 @@ export default {
'secondary':'#1B9AAA', 'secondary':'#1B9AAA',
'tertiary':'#DDDBCB', 'tertiary':'#DDDBCB',
'four':'#F5F1E3', 'four':'#F5F1E3',
'five':'#FFFFFF' 'five':'#FFFFFF',
'alert':'darkred',
}, },
}, },
plugins: [], plugins: [],