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 */
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 (
<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">
Send to:
</label>
@ -36,11 +47,25 @@ export default function Pay({ keys }) {
<label htmlFor="amount" className="font-bold text-3xl self-center">
BLC Amount:
</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
id="amount"
name="amount"
name="memo"
id="memo"
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
name="submit"

View File

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

View File

@ -22,6 +22,7 @@ export default function Recived({ keys }) {
const activado = useRef(false);
const cambiosdetectados = useRef(0);
const operations = useRef([{ transaction_hash: 0 }]);
const operationsday = useRef(0);
useEffect(() => {
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) => {

View File

@ -7,7 +7,7 @@ export default function MainApp({ keys, setKeys }) {
return (
<div className={"bg-five w-full h-full"}>
<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} />
<Pay keys={keys} />
<Recived keys={keys} />

View File

@ -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",

View File

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